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

    How to list authenticated users from shell

    Captive Portal
    captive portal authentication reports
    4
    5
    1.2k
    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.
    • P
      prophet
      last edited by prophet

      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

      1 Reply Last reply Reply Quote 0
      • S
        skron
        last edited by skron

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

        P GertjanG 2 Replies Last reply Reply Quote 3
        • P
          prophet @skron
          last edited by

          @skron Very good.

          Iterating array elements i have been able to extract and display all kind of information available (usernames, IPs, MAC...)

          Thanks

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

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

            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
            • jimpJ
              jimp Rebel Alliance Developer Netgate
              last edited by

              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'

              Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

              Need help fast? Netgate Global Support!

              Do not Chat/PM for help!

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