[SOLVED] Captive portal guest user scripted password change

  • We run a cluster of pfsense boxes to manage our guest/vendor wireless network captive portal.

    Our previous system used a captive portal with a single guest user, for which an expect script was run every Sunday morning at midnight to change the password.  A bash script executed the expect script to change the password to a random password from a file, and upon successful completion, to email the password to a distribution list.

    We are moving to pfsense to be the firewall border control for the VRF that controls all of the wireless networks, and intend to use the captive portal, but I need a solution to change the password from the cli.  Is this an easy task, or am I going to have to write a controller to manually change the password hash in the config file every time I want it changed?

  • Rebel Alliance Developer Netgate

    It will involve reading/writing the config but it probably isn't as hard as you expect. Just make the shell script a PHP script, look at some of the other shell php scripts in /etc/ that read/write bits from the config and it shouldn't be too hard to pull off.

    Have a look at auth.inc as well, the function to change a user's password is in there.

    Some pseudocode:

    require_once for config.inc and auth.inc and notices.inc
    read the password somehow (command line parameter or prompt, parameter is much easier)
    make sure the password is sane
    Call the function from auth.inc to set the user's password
    write_config("Updated portal user password"); to save the config, including the password
    Look in notices.inc at the smtp functions and figure out how to send an e-mail from there.

  • Thanks for the advice.  I built a small script to pull a random line from a predetermined list of passwords and set the password using local_user_set_password, but it is not working correctly.  Am I missing a step?

    bad code, don't use.

    It is echoing the password and the md5sum matches in the file, but I'm not sure if I need a chop or something in there for the crypt password.  I wouldn't think I do.

  • nevermind.  my assumptions were right.  I just trimmed the variable to remove the "\n" from the end of the string.  Md5sum didn't care, but crypt obviously did.

    Here is the completed password change (without notification) and it seems to work perfectly.

    #!/usr/local/bin/php -f
            $guestuser =& getUserEntryByUID(2001);
                    $lines = file("wireless.passwords");
                    $newpass = trim($lines[array_rand($lines)]);
                    echo $newpass;
                    local_user_set_password($guestuser, $newpass);
            write_config("Guest password changed from script.");

  • This looks great. Is there a tutorial to use this? or How can we use this?

  • Basically, I have a guest user that has a userid of 2001.  I put this script in the /etc folder as rc.password.guest and made a cron job to execute it weekly.  I have added a little bit to the end of the script that emails this guest password to a distribution list, so our conference room admins have the password every week.  They give it out to vendors and guests so they can use wireless in the conference rooms.