• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

[SOLVED] Captive portal guest user scripted password change

Scheduled Pinned Locked Moved Captive Portal
6 Posts 3 Posters 6.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    alekm
    last edited by Aug 1, 2011, 6:07 PM Jul 27, 2011, 3:07 PM

    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?

    1 Reply Last reply Reply Quote 0
    • J
      jimp Rebel Alliance Developer Netgate
      last edited by Jul 28, 2011, 2:08 PM

      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.

      Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

      Need help fast? Netgate Global Support!

      Do not Chat/PM for help!

      1 Reply Last reply Reply Quote 0
      • A
        alekm
        last edited by Aug 1, 2011, 6:04 PM Aug 1, 2011, 5:58 PM

        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.

        1 Reply Last reply Reply Quote 0
        • A
          alekm
          last edited by Aug 1, 2011, 6:04 PM

          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
          
                  require_once("config.inc");
                  require_once("auth.inc");
          
                  $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.");
          
          ?>
          
          
          1 Reply Last reply Reply Quote 0
          • L
            lifeform08
            last edited by Aug 25, 2011, 2:05 AM

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

            1 Reply Last reply Reply Quote 0
            • A
              alekm
              last edited by Aug 25, 2011, 2:11 AM

              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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                This community forum collects and processes your personal information.
                consent.not_received