Change WIFI password from commandline



  • Hi all ,
    I want to chang the wifi password on my pfsense box.
    I found in /conf the config.xml and edit the password ( see line <passphrase>XXXXXX</passphrase> )

    the password is changed but …the last I need to know is how to "apply" this option from the commandline
    if this step is not done the new password is not "active" for the wifi clients

    can please some one tell me how to "apply"  these changed setting(s) ???

    I cannot use the /etc/rc.reload_interfaces because then I have to reboot the whole pfsense box
    so .. is there a "small" or "easy" way to apply the changes to the config file without rebooting the pfsense box ???

    many thanks in advance
    Micheal



  • after a week trying i finally made a script to change the wifi password on my SG-2440 from the command line

    i know its a dirty script but it does do the job
    its syncs the pfsense graphical interface and its making a html file where the current password is stored.
    this script runs in the crontab every 23:59 and logs all command to my syslog machine (splunk)

    the code

    
    #!/bin/sh
    
    currconfigpwd="`/bin/cat /cf/conf/config.xml |/usr/bin/grep passphrase | /usr/bin/cut -f 2 -d\">\" | /usr/bin/cut -f 1 -d\"<\"`"
    newpwd="`/bin/cat /dev/urandom | /usr/bin/tr -dc 'a-zA-Z0-9' | /usr/bin/fold -w 8 | /usr/bin/head -n 1`"
    currwlanconfpwd="`/bin/cat /var/etc/hostapd_ath0_wlan0.conf |/usr/bin/grep wpa_passphrase |/usr/bin/cut -f 2 -d\"=\"`"
    
    /bin/echo "change-wifi-password : This script will update the wifi password with 6 random chars."
    /bin/echo "change-wifi-password : --------------------------------------------------------------"
    /bin/echo "change-wifi-password : Current wifi password in /cf/conf/config.xml : $currconfigpwd "
    /bin/echo "change-wifi-password : Current wifi password in /var/etc/hostapd_ath0_wlan0.conf : $currwlanconfpwd "
    
    if [ "$currconfigpwd" != "$currwlanconfpwd" ]
    then
    /bin/echo "change-wifi-password : Passwords are not equal ... exiting "
    /bin/echo "-- $currconfigpwd -- $currwlanconfpwd --"
    exit 1
    fi
    
    /bin/echo -n "change-wifi-password : Removing old /var/run/hostapd_ath0_wlan0.pid file ..."
    /bin/rm /var/run/hostapd_ath0_wlan0.pid
    /bin/echo "Done!"
    
    /bin/echo -n "change-wifi-password : Seting new password ($newpwd) in /var/etc/hostapd_ath0_wlan0.conf ..."
    /bin/cat /var/etc/hostapd_ath0_wlan0.conf | /usr/bin/sed "s/$currwlanconfpwd/$newpwd/" > /var/etc/hostapd_ath0_wlan0.conf.NEW
    /bin/mv /var/etc/hostapd_ath0_wlan0.conf.NEW /var/etc/hostapd_ath0_wlan0.conf
    /bin/echo "Done!"
    
    /bin/echo -n "change-wifi-password : Killing old hostapd_ath0_wlan0 daemon ..."
    #psnum="`/bin/ps aux |/usr/bin/grep \"/usr/sbin/hostapd -B -P /var/run/hostapd_ath0_wlan0.pid\" |/usr/bin/grep -v /usr/bin/grep | /usr/bin/awk '{print $2}'`"
    psnum="`/bin/ps -auxw |/usr/bin/grep hostapd_ath0_wlan0.pid|/usr/bin/grep -v /usr/bin/grep | /usr/bin/awk '{print $2}'`"
    /bin/echo -n "$psnum "
    /bin/kill $psnum
    /bin/echo "Done!"
    
    /bin/echo -n "change-wifi-password : Starting hostapd_ath0_wlan0 daemon ..."
    /usr/sbin/hostapd -B -P /var/run/hostapd_ath0_wlan0.pid /var/etc/hostapd_ath0_wlan0.conf >/dev/null
    /bin/echo "Done!"
    
    /bin/echo -n "change-wifi-password : Seting new password ($newpwd) in /cf/conf/config.xml ..."
    /bin/rm /cf/conf/config.xml.NEW
    /usr/bin/sed "s|$currconfigpwd|$newpwd|" /cf/conf/config.xml >/cf/conf/config.xml.NEW
    /bin/cp /cf/conf/config.xml.NEW /cf/conf/config.xml
    /bin/rm /tmp/config.cache
    /bin/sleep 1
    /usr/local/bin/php -f /root/write-apply.php
    /bin/echo "Done!"
    
    /bin/echo -n "change-wifi-password : Making intranet webpage passwordoftheday.html in /usr/local/www ..."
    /bin/echo "
    
    <center>" >/usr/local/www/passwordoftheday.html
    /bin/echo "
    
    **PASSWORD OF THE DAY WILL BE ACTIVE FOR 24 HOURS**
    
    ##### Generated on : `date` 
    
    " >>/usr/local/www/passwordoftheday.html
    /bin/echo "
    
    **PASSWORD : $newpwd**
    
    " >>/usr/local/www/passwordoftheday.html
    /bin/echo "Done!"
    
    and the write-apply.php file
    
    

    #!/usr/local/bin/php -q
    require_once('/etc/inc/pkg-utils.inc');
    require_once('/etc/inc/config.lib.inc');

    write_config();
    ?>

    
    have fun with it ;-)
    m </center>
    
    

Log in to reply