Using cron to disconnect all users at midnight
-
Hi all,
Is there a way to issue a command (perhaps wrapped via php) to disconnect all captive portal connected users at midnight via cron. Has anyone done this before?
I came through this, found it via google dated back in 2015:
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);
cat it to /root/test.php and run it like so:
/usr/local/bin/php -q /root/test.php
However to no avail. Would appreciate any pointers at all!
-
Dono who wrote that code snippet, but it's incomplete ;)
Here you have the entire file :
#!/usr/local/bin/php -q <?php /* Disconnect all clients on all captive portal instances */ require_once("/etc/inc/util.inc"); require_once("/etc/inc/functions.inc"); require_once("/etc/inc/captiveportal.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']; captiveportal_disconnect_all(); } } ?>
The file is updated, as portal 'code' evolved somewhat over the last 7 years.
Global variables have to be setup correctly.
The starting <?php is important.
And instead of the function captiveportal_disconnect_client() we have now captiveportal_disconnect_all() that removes all users from a portal instance.I tested it.
Thanks ;)
All my connected users (a hotel) were thrown of the portal. -
@gertjan Oh my .. sorry I haven't been able to get to this channel for quite some time .. I'll try this out and report back .. thank you, sir!
PS: I don't quite understand the global part .. should be descended from captiveportal.inc yes?
-
@gertjan I tried the code and it worked! .. and dropped it directly into cron .. thank you, sir!