• 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

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



    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 !

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

  • On a popup / login page ?

    Same as :

    ( 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.

  • @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.