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

    CP login via QR code

    Scheduled Pinned Locked Moved Captive Portal
    10 Posts 8 Posters 8.0k 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.
    • S
      sheepthief
      last edited by

      Apologies if this has already been covered - the only reference I've found to QR codes is a feature request (#1984) from 2011.

      I run a dozen CPs at various sites, for personal use. The majority of users are phone/tablet users, and we publish login details at each site and on our private intranet.

      It just occurred to me that it might be nice to offer a QR code to allow folk to login from. I can't think of any way to do this as neither password or voucher logins seem to work direct from a URL.

      Maybe there's a way that I've not thought of. Has anyone else achieved this?

      (I'm running 2.1.4)

      1 Reply Last reply Reply Quote 0
      • T
        Trel
        last edited by

        It would probably be doable with a custom php page.

        The php page would take an argument in the url like ?voucherid=xyz

        add it to a hidden field and the user sees something like

        Are you sure you want to use voucher: xyz
        [Yes] [No]

        Then the QR code would be: urltophppage.php?voucherid=voucher

        EDIT: example of what the QR code might look like

        EDIT2: also, if you're not using vouchers you could still bring them to a page with an "I accept button" with a valid user/password hardcoded in hidden form fields.

        voucher_example.png

        1 Reply Last reply Reply Quote 0
        • J
          jhochwald
          last edited by

          What I did for a friend:

          Create a seperate PHP Page in the CP an include this:

          $username = $_GET['username'];
          $password = $_GET['password'];
          ?>
          

          Here the Form part:

          Include the following in the URL:```
          ?username=MYUSER&password=MYPASSWORD

          
          In the example of Trel:
          

          $voucherid = $_GET['voucherid'];
          ?>

          
          That will capture the ?voucherid=voucher as mentioned by Trel.
          
          There is one problem: Some of the QR Reader Apps need internet access. A great idea to implement your own App ;-) You will find a great Framework at Coogle Code.
          Also at Google you will find some great examples how to automate the QR generation for your vouchers. It's just a URL ;-)
          
          If you like to capture the URL via JavaScript, you might want to try to include this (untested, but it should work!):
          

          function getUrlVars()
          {
              var vars = [], hash;
              var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

          for(var i = 0; i < hashes.length; i++)
                  {
                  hash = hashes[i].split('=');
                  vars.push(hash[0]);
                  vars[hash[0]] = hash[1];
                  }

          return vars;
          }

          var get = getUrlVars();[/i]

          Regards

          /JH

          1 Reply Last reply Reply Quote 0
          • S
            sheepthief
            last edited by

            Thanks for the replies folks - I'm encouraged that the answers are positive and that gives me good reason to investigate this further. Unfortunately I've just had a pile of work dumped on me so I'm not sure when I'll be able to get around to it, but I'll update this thread as and when I can…

            1 Reply Last reply Reply Quote 0
            • T
              tirsojrp
              last edited by

              I have been testing the same solution but has not been deployed.

              Word 2013 handles the QR code creation (word field barcode) using mail merge to get the vouchers from the exported csv file.

              1 Reply Last reply Reply Quote 0
              • M
                milocheri
                last edited by

                Hello all, what was the end of this, did it work ? i would like to do the same , but how ?

                1 Reply Last reply Reply Quote 0
                • GertjanG
                  Gertjan
                  last edited by

                  How ?
                  As stated above, it needs some PHP coding.

                  Think about upgrading to a less ancient pfSense version first ;)

                  No "help me" PM's please. Use the forum, the community will thank you.
                  Edit : and where are the logs ??

                  1 Reply Last reply Reply Quote 0
                  • M
                    milocheri
                    last edited by

                    Ok, as far as i understand, i need to create a php file, how shoul i name the file ? then include all of this

                    $username = $_GET['username'];
                    $password = $_GET['password'];
                    ?>
                    
                    ?username=MYUSER&password=MYPASSWORD
                    

                    Sorry for the noob questions, but i dont really know how to code

                    1 Reply Last reply Reply Quote 0
                    • P
                      pszafer
                      last edited by

                      Hi @milocheri,
                      I think it should work like this:

                      • generate QrCode with full link to your pfsense CP with login information in url e.g. https://pfsense:8000/login.php?voucher=aaa
                      • in php file you need to take param from get and put it in voucher

                      Your code should work, just with little changes to meet requirments of CP page content.

                      Upload an HTML/PHP file for the portal page here (leave blank to keep the current one). Make sure to include a form (POST to "$PORTAL_ACTION$") with a submit button (name="accept") and a hidden field with name="redirurl" and value="$PORTAL_REDIRURL$". Include the "auth_user" and "auth_pass" and/or "auth_voucher" input fields if authentication is enabled, otherwise it will always fail. Example code for the form:

                      Upload it as your CP custom login page.

                      1 Reply Last reply Reply Quote 0
                      • J
                        jdieu
                        last edited by

                        Hi,

                        I create qrcode with this link : http://xxxxxxxx.fr/ubhZKcJbY6a3 (replace xxxxxxxx.fr with other website, ubhZKcJbY6a3 is a voucher code)

                        When user scan qrcode, it will redirect to portal auth page and the voucher field will autofill.
                        If a user is redirected with other url, the voucher field will empty and he could authentificate with his credentials.

                        
                        									$URL = htmlspecialchars($_GET["redirurl"]);
                        					if (strpos($URL, 'http://xxxxxxxx.fr') !== false) {
                        						$Code = str_replace("http://xxxxxxxx.fr/", "", "$URL");
                        					} else {
                        						$Code = "";
                        					}
                        				?>
                        
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.