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

    Custom logout page

    Scheduled Pinned Locked Moved Captive Portal
    6 Posts 3 Posters 1.2k 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.
    • B
      brinch
      last edited by

      Hello everyone,

      I'm looking for a way to disconnect a user via an url, so i'm searching for a php page or an html page that could log a user out from opening it.

      Something like http://mypfsense:8002/logout.html, and then user launching it is directy diconnected.

      I did some research throught the Web, but nothing could help me.
      I know bearly nothing in coding...

      So if someone has written such script and would give it to the community, it would be very much appreciate.

      Thank you for your help

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

        Thanks to @Gertjan
        Here is the code to have a proper logout.php page :

        <?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 !

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

          For reference : https://forum.netgate.com/topic/69307/captive-portal-manual-logout-page-address/94

          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
          • W
            walter_leon @brinch
            last edited by

            @brinch And how do I put the remaining time? For example, Time remaining: 23 minutes and 11 seconds, how do I do it?

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

              On a popup / login page ?

              Same as :

              659b8189-151b-455d-870f-8cd52c3ea657-image.png
              ( it's a running counter - activate the NTP Widget on the GUI dashboard to see it )

              When you build your page, you'll be needing this function : https://github.com/pfsense/pfsense/blob/c6220dcf7faf3492713c6c30bb86d3971b2772a9/src/etc/inc/voucher.inc#L281

              Time left returned will be expressed in minutes.

              And add some javascript on the logout page so it counts down as shown in the image above.

              Ready for some coding ? ( PHP, html and Java mixed ^^ )

              edit :
              Btw : when a vouchers is usable that last one hour = 60 minutes = 3600 seconds, it doesn't take rocket science , neither MIT graduate skils to know when it ties out : one hour after the login moment.
              There is a choix to be made :
              Or the vouchers users can do some simple math.
              Or you 'script' a solution together that show the time.

              The last solution has some drawbacks :
              Nearly no one accepts popup's these days (the logout page) so you better redirect to a local web page after login that shows the remaining voucher time - and print also : "Please keep this page open ". There is NO need to add a button for logout : the voucher time will keep running anyway.
              Or you mention an URL on the login page where the voucher was used so voucher users can use to check the remaining time (but hey, if they can copy + paste, they can do some math also ... normally)
              Or print the URL on the voucher - the paper you handed them over, if you use such a way to communicate the code.

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

              W 1 Reply Last reply Reply Quote 0
              • W
                walter_leon @Gertjan
                last edited by

                @Gertjan Hello, could you give me an example php, I am not really an expert in php and html, tried in all cases and I can not get it. I look forward to your help. Thank you.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.