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

How to list authenticated users from shell

Scheduled Pinned Locked Moved Captive Portal
captive portalauthenticationreports
5 Posts 4 Posters 1.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.
  • P
    prophet
    last edited by prophet Apr 8, 2019, 2:01 PM Apr 8, 2019, 1:44 PM

    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 Apr 9, 2019, 6:21 AM Apr 9, 2019, 4:56 AM

      <?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 G 2 Replies Last reply Apr 10, 2019, 12:40 PM Reply Quote 3
      • P
        prophet @skron
        last edited by Apr 10, 2019, 12:40 PM

        @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
        • G
          Gertjan @skron
          last edited by Apr 10, 2019, 1:06 PM

          @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
          • J
            jimp Rebel Alliance Developer Netgate
            last edited by Apr 11, 2019, 12:37 PM

            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
            5 out of 5
            • First post
              5/5
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
              This community forum collects and processes your personal information.
              consent.not_received