How to list authenticated users from shell
-
Hi everybody,
i'm looking for a way to programatically list authenticated users, in order to count them and make other reports with shell-based scripts.
Don't take me for lazy, when i tried to manually read Sqlite DBs very bad things happened, so i'm asking for a safer way to it (some API, custom PHP or whatever...)
Thank you
-
<?php require_once("/etc/inc/util.inc"); require_once("/etc/inc/functions.inc"); require_once("/etc/inc/captiveportal.inc"); /* read in captive portal db */ /* determine number of logged in users */ $count_cpusers = 0; /* Is portal activated ? */ if (is_array($config['captiveportal'])) /* For every zone, 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; /* Zone selected -> count users and add */ $count_cpusers += count(captiveportal_read_db()); } echo $count_cpusers; ?>
I use this PHP script for counting logged in users (graphing them out later). Found the code in the forum years ago, still works. Probably enough functions in the include files to get out logged in usernames or whatever you want. Good place to start looking would probably be the source code of the captive portal status page.
captiveportal_read_db() should list the users when the cpzone is set. -
@skron Very good.
Iterating array elements i have been able to extract and display all kind of information available (usernames, IPs, MAC...)
Thanks
-
@skron said in How to list authenticated users from shell:
still works
Yeah !
Years ago I wrote identical lines to count all connected users for statical reasons. -
If you just want a count, you can use the script that is there for RRD:
/usr/local/bin/php-cgi -q /usr/local/bin/captiveportal_gather_stats.php '<zone name>' 'loggedin'
/usr/local/bin/php-cgi -q /usr/local/bin/captiveportal_gather_stats.php '<zone name>' 'concurrent'