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

    Command to disconnect all logged on users?

    Scheduled Pinned Locked Moved Captive Portal
    9 Posts 5 Posters 4.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.
    • A
      AB
      last edited by

      Hello,

      I have a setup where multiple users are logging in on active portal using the same username created with Local User Manager.
      The password for this account will be changed daily at midnight, and at that time I need to disconnect all the users who are currently logged on with the old password.

      I have not been able to find any command line or GUI way of doing this, other than going to Status > Captive Portal and manually disconnecting each client one at a time. This is something that needs to be run automatically daily and therefor not something that can be done manually. Is there any command line way of doing this that can be incorporated into the script I have that changes password?

      1 Reply Last reply Reply Quote 0
      • D
        doktornotor Banned
        last edited by

        Hmm… and why don't you just set up vouchers valid for one day?

        1 Reply Last reply Reply Quote 0
        • A
          AB
          last edited by

          @doktornotor:

          Hmm… and why don't you just set up vouchers valid for one day?

          Because I found no information that said that multiple users can be logged in with the same voucher code. The wish from the client is that everyone uses the same password and that this password is changed daily. They also want a captive portal with guidelines etc.

          If this is doable with vouchers I could go that route.

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

            @AB:

            ….

            I have not been able to find any command line or GUI way of doing this, other than going to Status > Captive Portal and manually disconnecting each client one at a time. This is something that needs to be run automatically daily and therefor not something that can be done manually. Is there any command line way of doing this that can be incorporated into the script I have that changes password?

            When you use the Status > Captive Portal page, a list is shown with logged in users.
            Have a look at the PHP code that maks this list, as you we see, it's rather simple. A couple of lines using PHP makes this list. Add one line more that logs out every user it finds and your are nearly there.
            Make a cron task that runs you PHP script at midnight, and you're ok.

            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
            • DerelictD
              Derelict LAYER 8 Netgate
              last edited by

              Yes, multiple users can log in with a single voucher (Allow concurrent logins I think.)  Or you can limit it to one.  What you cannot do is limit it to, say, 10.

              If you have to kick everyone off, manually expire the voucher.

              Chattanooga, Tennessee, USA
              A comprehensive network diagram is worth 10,000 words and 15 conference calls.
              DO NOT set a source address/port in a port forward or firewall rule unless you KNOW you need it!
              Do Not Chat For Help! NO_WAN_EGRESS(TM)

              1 Reply Last reply Reply Quote 0
              • C
                chowtamah
                last edited by

                Hi,

                I had the same requirement and did little coding, which worked in 2.1 through cron. But, after upgrading to 2.2.2, if I run this code it gives error; Failed setsockopt.

                I do not know where to check! Code is below;

                
                ##|+PRIV
                ##|*IDENT=page-status-captiveportal
                ##|*NAME=Status: Captive portal page
                ##|*DESCR=Allow access to the 'Status: Captive portal' page.
                ##|*MATCH=status_captiveportal.php*
                ##|-PRIV
                
                require("captiveportal.inc");
                
                $cpzone = "wifi";
                
                ?>
                
                flush();
                
                function clientcmp($a, $b) {
                	global $order;
                	return strcmp($a[$order], $b[$order]);
                }
                
                if (!empty($cpzone)) {
                	$cpdb = captiveportal_read_db();	
                }
                
                // Load MAC-Manufacturer table
                $mac_man = load_mac_manufacturer_table();
                
                foreach ($cpdb as $cpent):
                  //echo $cpent[2]." - ".$cpent[3]." - ". $cpent[4]." - ".$cpent[0]." - ".$cpent[5];
                  //echo "Disconnecting...".$cpent[2]."-". $cpent[4]."
                ";
                  captiveportal_disconnect_client($cpent[5]);
                endforeach; 
                
                ?>
                
                

                2.0.2-RELEASE (amd64)  &  2.2.2-RELEASE (amd64)

                Always trying to learn!!

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

                  This snippet will disconnect ALL users from ALL zones (more then one can exist) :

                  
                  require("captiveportal.inc");
                  
                  if (!is_array($config['captiveportal'])) {
                  	$config['captiveportal'] = array();
                  }
                  
                  $a_cp =& $config['captiveportal'];
                  foreach ($a_cp as $captiveportalzone) {
                  	// set $cp_zone so the correct database will use used
                  	$cpzone = $captiveportalzone['zone'];
                  	// also surface the global $cpzoneid
                  	$cpzoneid = $captiveportalzone['zoneid'];
                  	// Read the corresponding database
                  	$cpdb = captiveportal_read_db();
                  	foreach ($cpdb as $cpent) {
                  		captiveportal_disconnect_client($cpent[5]);
                  	}
                  	unset($cpdb);
                  }
                  unset($a_cp);
                  
                  ?>
                  

                  Place this PHP file in … /root/zzz.php

                  Execute it like this:

                  /usr/local/bin/php -q /root/zzz.php
                  

                  Be carefull : running it WILL disconnect all users from the command line (wasn't this something that many were asking on this forum ??)

                  Up to you to put it in a cron which executes it at midnight.

                  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
                  • C
                    chowtamah
                    last edited by

                    Thank you Gertjan,

                    Your code disconnected all users without error, when executed from the command line.

                    Made the entry in cron. Thank you.

                    2.0.2-RELEASE (amd64)  &  2.2.2-RELEASE (amd64)

                    Always trying to learn!!

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

                      @chowtamah:

                      ….
                      if I run this code it gives error; Failed setsockopt.

                      Somewhere, deep down in /etc/inc/captiveportal.inc, the global variable "$cpzoneid" needs to have a valid value - related and like "$cpzone".
                      This part is handling that one:

                      	// also surface the global $cpzoneid
                      	$cpzoneid = $captiveportalzone['zoneid'];
                      

                      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.