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

    Captive portal manual logout page address

    Captive Portal
    15
    105
    57.1k
    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
      amitaussie
      last edited by

      Thanks Dear,

      I'll try to work it out.

      1 Reply Last reply Reply Quote 0
      • B
        brinch @Gertjan
        last edited by

        @Gertjan
        Hello Gertjan,

        I read all the thread with attention.
        I'm real bad in coding, i'm a network lad.

        You look to know very well php, and pfsense captive portal auth and co management.
        Sorry to dig out this old topic, but i have diffilculties to find the simple solution i'm looking for.

        So i ask for your help sir..

        All i need is a simple logout php or html page that send directly a logout command to the server and logs out the client that start that page. No action needed by the client (no click, nothing)

        I tried with the examples you gave but no success, i know sh** in php..

        Your help would be very much apreciated

        Regards

        F 1 Reply Last reply Reply Quote 0
        • F
          free4 Rebel Alliance @brinch
          last edited by free4

          when @brinch enjoy digging up burried threads a bit too much
          alt text

          could you please create a new thread ?

          1 Reply Last reply Reply Quote 1
          • B
            brinch
            last edited by

            :D
            I've done it already.
            But that guy mentioned is the one! @Gertjan

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

              Portal logout page :

              The thing is : browser got smarter these days.
              Cookies aren't stored or accisble by default any more.
              Browser do NOT accept popup, pages (any more) .....

              So, the logout page you push out when the user logs in doesn't get show up on the user's screen as a windows or tab where the user can logout.
              And you can not control the users browser settings ...

              When time is money : explain the user while he is logging in that the soft-timeout is set to a very low value, which means that without user activity, the user gets disconnected fast.
              Also : inform the user that he should de activated his Wifi connection on his side when he is done using your resources. If not : his credit time will get used .... So, when the user disconnects, the idle (soft) time will handle everything for you without any coding.

              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
              • B
                brinch
                last edited by

                Ok, i understand.

                But there me be a very easy way to write a simple php page that directly log out the user who launches it. No pop up, no confirmation button.

                http://mypfsense:8004/logout.php

                Just a function that get the session id and kill the current session.

                I tried to code something with the elements you gave, but it didn't work ...

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

                  @brinch said in Captive portal manual logout page address:

                  I tried to code something with the elements you gave, but it didn't work ...

                  You should :
                  Obtain user's IP and MAC (see /usr/local/captiveportal/index.php how to get the, it's easy.

                  Use this to get the session ID :

                  Use https://github.com/pfsense/pfsense/blob/fb249aefa378172d6c246e62d15a8da40d80c5b6/src/etc/inc/captiveportal.inc#L2834 to get the session entry.

                  $cpentry[5] should contain the session ID.

                  Now call https://github.com/pfsense/pfsense/blob/fb249aefa378172d6c246e62d15a8da40d80c5b6/src/etc/inc/captiveportal.inc#L1214 using this session ID.

                  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
                  • B
                    brinch
                    last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • GertjanG
                      Gertjan
                      last edited by Gertjan

                      This worked for me :

                      <?php
                      
                      require_once("captiveportal.inc");
                      require_once("auth.inc");
                      require_once("functions.inc");
                      
                      global $g, $config, $cpzone, $cpzoneid;
                      
                      /* Are there any portals  ? */
                      if (is_array($config['captiveportal'])) {
                      	/* For every portal (cpzone), do */
                      	foreach ($config['captiveportal'] as $cpkey => $cp)
                      		/* Sanity check */
                      		if (is_array($config['captiveportal'][$cpkey])) 
                      			/* Is zone enabled ? */
                      			if (array_key_exists('enable', $config['captiveportal'][$cpkey])) {
                      				$cpzone = $cpkey;
                      				$cpzoneid = $cp['zoneid'];
                      				$client_ip = $_SERVER['REMOTE_ADDR'];
                      				$cpentry = array();
                      				$cpentry = captiveportal_isip_logged($client_ip);
                      				if ( array_key_exists(5, $cpentry) ) {
                      				captiveportal_disconnect_client($cpentry[5], 1, "USER LOGOUT");
                      				}
                      			}
                      	}
                      ?>
                      

                      Note : the $cpzone should be set to the actual captive portal zone instance name !
                      ( I'll update this post later on so the code will scan over all active captive portal zone instances )

                      When I visited this /logout.php page, I was logged out.

                      edit : code updated.

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

                      B G 2 Replies Last reply Reply Quote 1
                      • B
                        brinch @Gertjan
                        last edited by

                        @Gertjan

                        Thank you very much, it does the trick.

                        Have a good day

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

                          I just updated the code ^^

                          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
                          • N
                            netx34
                            last edited by

                            any tutorial process to input this code? or edit and add
                            thanks in advance ive got this issue with my client users for how many months.

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

                              @netx34 said in Captive portal manual logout page address:

                              any tutorial process to input this code? or edit and add

                              Yep.

                              Place (create) it here : /usr/local/captiveportal
                              Call the file "logout.php".

                              Note : this is NOT a file you can upload into the pfSense Captive Pprtal's file manager !!

                              Now you can use
                              http://portal.mypfsense.tld:8004/logout.php
                              or
                              http://192.168.2.1:8004/logout.php

                              ( if 192.168.2.1 is the IP address of the captive portal's interface - or your set "portal.mypfsense.tld" as the FQDN to this IP using the Resolver.
                              "8004" is just an example, your port number might be different. )

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

                              N 1 Reply Last reply Reply Quote 0
                              • N
                                netx34 @Gertjan
                                last edited by

                                @Gertjan thank you,
                                im now test it before i deploy it to my exact pf serve,
                                great work and update.

                                update later after work.

                                1 Reply Last reply Reply Quote 0
                                • N
                                  netx34
                                  last edited by

                                  btw only the logout.php can apply FQDN for the domain name

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

                                    @netx34 said in Captive portal manual logout page address:

                                    btw only the logout.php can apply FQDN for the domain name

                                    What do you mean ?

                                    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
                                    • G
                                      guntery @Gertjan
                                      last edited by guntery

                                      When I visited this /logout.php page, I was logged out.

                                      So this code works great, thanks. I'm adding in a redirect at the end of the file - it works - but it takes around 20 seconds too load the login page - or any page

                                      Any ideas on a workaround? - I assume the portal is interfering somehow.

                                      <script>window.location.replace("http://example.com");</script>
                                      
                                      

                                      edit: weird, it a happened a few times, restored a backup and it now works fine..

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

                                        @guntery said in Captive portal manual logout page address:

                                        I'm adding in a redirect at the end of the file

                                        What are you talking about ?
                                        What file ? The script from above ? That a massive "log everybody out" script file.

                                        After throwing everybody out, why would you redirect yourself to http://example.com ? Why not the pfSense GUI ?

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

                                        G 1 Reply Last reply Reply Quote 0
                                        • G
                                          guntery @Gertjan
                                          last edited by

                                          Huh? It logs out the user who goes to that page not all users.

                                          the redirect goes to the splash page either way though right (it's an example), in this case I have 2 captive portals with differing IP's and 1 logout script so it was easier to use the domain redirect not the CP IP

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

                                            @guntery said in Captive portal manual logout page address:

                                            uh? It logs out the user who goes to that page not all users.

                                            I stand corrected.
                                            Had to review the script and true, the caller gets logged out.
                                            Sorry for the noise ^^

                                            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
                                            • First post
                                              Last post
                                            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.