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

    Number of port users logged in - 2.1-RELEASE

    Scheduled Pinned Locked Moved Captive Portal
    22 Posts 8 Posters 4.9k 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.
    • Y
      yanqian
      last edited by

      @Gertjan,
      Thanks for your script!

      I tried it in 2.3 release, I have 2 zones, one named "test1", the other named "test2", I changed the (hard code) "cpzone" to "test1" or "test2":

      $cpzone ="test1"; /* hard code */
      

      but it always get "0", actually we have about 20 users online for each zone.

      May I know if it still support 2.3?

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

        @yanqian:

        …..
        May I know if it still support 2.3?

        I'm still using the script as of today.

        I updated the script (look above), it counts now all users on all zones. No need to change anything.
        Btw : I repaired the link so you can check it out on my "Munin" page.

        2016-05-04 : 13h45m : I updated the script ones more.

        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
        • M
          myke
          last edited by

          Hello everyone,

          The scripts works like a charm directly in my pfsense box but when i try with my zabbix server i have this error message :

          PHP ERROR: Type: 1, File: /etc/inc/captiveportal.inc, Line: 1454, Message: Class 'SQLite3' not found

          the script is excecuted with root previlige.

          If someone hear my help :-)

          Thanks.

          Best Regards.
          Myke.

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

            @myke:

            PHP ERROR: Type: 1, File: /etc/inc/captiveportal.inc, Line: 1454, Message: Class 'SQLite3' not found

            This errors shows up when the date base with logged in users doesn't exists.
            This could be normal when the captive portal isn't running.
            Maybe the script should check if a given portal instance is actually enabled ( <enabled>) before trying to open the database.
            If it runs (= enabled) , the data base is created. The error comes from the portal code that handles the database.

            @myke:

            The scripts works like a charm directly in my pfsense box but when i try with my zabbix server i have this error message :

            What is a zabbix box ????
            The script was written for pfsense - it didn't work me when I put it in my Nespresso machine neither.

            edit : I will update the script to include the check.</enabled>

            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
            • M
              myke
              last edited by

              Hi, thanks for your answers.

              Quote from: myke on Yesterday at 10:43:00 am
              PHP ERROR: Type: 1, File: /etc/inc/captiveportal.inc, Line: 1454, Message: Class 'SQLite3' not found
              This errors shows up when the date base with logged in users doesn't exists.
              This could be normal when the captive portal isn't running.
              Maybe the script should check if a given portal instance is actually enabled ( <enabled>) before trying to open the database.
              If it runs (= enabled) , the data base is created. The error comes from the portal code that handles the database.</enabled>

              My captive portal is running and I don't have any issue when I execute the script directly in my pfsense box.

              The scripts works like a charm directly in my pfsense box but when i try with my zabbix server i have this error message :
              What is a zabbix box ????
              The script was written for pfsense - it didn't work me when I put it in my Nespresso machine neither.

              That a shame that your Nespresso can launch a script and I hope you don't buy your nespresso's machine for doing that  ;D

              I use zabbix agent on pfsense and  zabbix server give a parameter to launch the script like this :
              https://forum.pfsense.org/index.php?topic=111257.0

              And for test the connection with my zabbix, I write this command :

              zabbix_get -s "Wan" -p 10050 -k CP_users
              

              And return this error message :

              PHP ERROR: Type: 1, File: /etc/inc/captiveportal.inc, Line: 1454, Message: Class 'SQLite3' not found
              

              Thanks for your time Mr Gertjan

              Best Regards.
              Myke.

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

                @myke:

                zabbix_get -s "Wan" -p 10050 -k CP_users
                

                Ah, ok, didn't know what "zabbix" was. I figured it out https://fr.wikipedia.org/wiki/Zabbix

                Btw :
                SSH into your box.
                'cd' to the pace where you put your script ( mine is called captiveportal_count_online_users.php )
                Then:

                 php -q captiveportal_count_online_users.php
                

                Does it return a number like 0 or more, or the same error.

                While you are in there, check if the database really doesn't exist.
                It should be here :

                /var/db/captiveportal[zone-name].db

                where [zone-name] is the name of your captive portal zone.
                Other .db might exist.

                I have a file database file called : captiveportalcpzone1.db
                because my portal is running
                and
                the name is "cpzone1".

                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
                • M
                  myke
                  last edited by

                  Code: [Select]
                  php -q captiveportal_count_online_users.php
                  Does it return a number like 0 or more, or the same error.

                  php -q cptotaluser
                  

                  It gives me the right number of the connection of my captive portal.

                  And in the /var/db, my DB exists and it's call captiveportal2017.db

                  Update :
                  it's really weird cause i just test the script in 2 pfsense in 2.3.2-release . one of two works. it's the same script with same name and the zabbix agent is the same of course.

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

                    @myke:

                    Code: [Select]
                    php -q captiveportal_count_online_users.php
                    Does it return a number like 0 or more, or the same error.

                    php -q cptotaluser
                    

                    It gives me the right number of the connection of my captive portal.

                    Thus, the script works.

                    Btw :

                    				if (array_key_exists('enable', $config['captiveportal'][$cpkey])) {
                    

                    is already checking IF the captive portal instance is running.

                    Double check if your are running the script as super user  (= 'root')

                    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
                    • M
                      myke
                      last edited by

                      Btw :

                      				if (array_key_exists('enable', $config['captiveportal'][$cpkey])) {
                      

                      is already checking IF the captive portal instance is running.

                      Double check if your are running the script as super user  (= 'root')

                      i add "echo $USER" on the script  :

                      zabbix_get -s "Wan" -p 10050 -k CP_users
                      root
                      Fatal error: Class 'SQLite3' not found in /etc/inc/captiveportal.inc on line 1454
                      PHP ERROR: Type: 1, File: /etc/inc/captiveportal.inc, Line: 1454, Message: Class 'SQLite3' not found
                      root
                      
                      

                      so you can see the script is running with the user root.

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

                        @myke:

                        PHP ERROR: Type: 1, File: /etc/inc/captiveportal.inc, Line: 1454, Message: Class 'SQLite3' not found

                        Was reading this message again - and this time in the afternoon, so this time the caffeine worked.
                        The errors is "Class 'SQLite3' not found" which is (should be) part of the PHP install on pfSense.

                        Visit this page : https://your-pfsense-box/phpinfo.php
                        Does it have a section that says "sqlite3" is included ?

                        Also : when using a navigator, php is using this php.ini file : /usr/local/etc/php.ini
                        When using the CLI, it 'could' be another one - check that.
                        Run :

                        php -q /usr/local/www/phpinfo.php | grep 'sqlite'
                        

                        Does it say:

                        PDO drivers => sqlite
                        pdo_sqlite
                        sqlite3
                        sqlite3.extension_dir => no value => no value

                        It looks like you haven't the same version of pfSEnse as I do … (which is, of course, the latest 'stable' version)

                        edit : or whatever what could explain why the sqlite3 php extension isn't avaible.

                        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
                        • D
                          doktornotor Banned
                          last edited by

                          That extension hasn't been there for a while. Use /usr/local/bin/sqlite3 instead.

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

                            @doktornotor:

                            That extension hasn't been there for a while. Use /usr/local/bin/sqlite3 instead.

                            According to : /usr/local/etc/php/extensions.ini :

                            [2.3.2-RELEASE][admin@pfsense.brit-hotel-fumel.net]/root: cat /usr/local/etc/php/extensions.ini
                            ....
                            extension=pdo_sqlite.so
                            .....
                            extension=sqlite3.so
                            
                            

                            I have a clean

                            2.3.2-RELEASE-p1 (amd64)
                            built on Tue Sep 27 12:13:07 CDT 2016
                            FreeBSD 10.3-RELEASE-p9
                            

                            install.
                            I do have

                            /usr/local/bin/sqlite3
                            

                            But : does /etc/inc/captiveportal.inc use the 'extension' or the external binary ? If the external binary was used, I should have found a proof in the code.

                            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
                            • M
                              myke
                              last edited by

                              Hello Gentleman,

                              Visit this page : https://your-pfsense-box/phpinfo.php
                              Does it have a section that says "sqlite3" is included ?

                              I have an error : 404 Not Found so i can't tell you.

                              And

                              php -q /usr/local/www/phpinfo.php

                              I don't have any phpinfo.php on my whole pfsense…

                              Why the library missed when i used my zabbix server to launch the script on pfsense. and it's perfectly working on pfsense :-(

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

                                @myke:

                                Hello Gentleman,

                                Visit this page : https://your-pfsense-box/phpinfo.php
                                Does it have a section that says "sqlite3" is included ?

                                I have an error : 404 Not Found so i can't tell you.

                                And

                                php -q /usr/local/www/phpinfo.php

                                I don't have any phpinfo.php on my whole pfsense…

                                Stupid me.
                                Create a file called "phpinfo.php" in /usr/local/www/
                                an put this into it :

                                phpinfo();
                                ?>
                                

                                @myke:

                                Why the library missed when i used my zabbix server to launch the script on pfsense. and it's perfectly working on pfsense :-(

                                Dono.
                                I'm using a "munin plugin" like this :

                                
                                #!/bin/sh
                                #
                                # Plugin to monitor the number of captive portal users. 
                                #
                                # Parameters:
                                #
                                # 	config   (required)
                                # 	autoconf (optional - used by munin-config)
                                #
                                # Magick markers (optional - used by munin-config and som installation
                                # scripts):
                                #%# family=auto
                                #%# capabilities=autoconf
                                
                                if [ "$1" = "autoconf" ]; then
                                	echo yes 
                                	exit 0
                                fi
                                
                                if [ "$1" = "config" ]; then
                                
                                	echo 'graph_title Captive Portal Users'
                                	echo 'graph_args --base 1000 -l 0 '
                                	echo 'graph_vlabel Number of users'
                                	echo 'graph_category portalusers'
                                	echo 'graph_info This graph shows the number of portal users on the system.'
                                	echo 'portalusers.label users'
                                	echo 'portalusers.info The current number of users.'
                                	echo 'portalusers.draw LINE2'
                                	exit 0
                                fi
                                
                                echo -n "portalusers.value "
                                /usr/local/bin/php -q /root/captiveportal_count_online_users.php
                                

                                and it works well.

                                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
                                • M
                                  myke
                                  last edited by

                                  I just test with the new release of pfSense 2.3.3 and the script worked.
                                  hallelujah :-)

                                  Thanks for the help by the way  :)

                                  Best regards
                                  Myke

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

                                    Thanks, this still works (2.3.4)

                                    I implemented it differently, but using your script. I uploaded the script in the captive portal and my cacti-install gets the value via https from https://pfsensehost:8003/captiveportal-cpcount.php and graphs the output… works great! Finally CP count monitored.

                                    An OID for SNMP would be great though.

                                    graph_image.png
                                    graph_image.png_thumb

                                    1 Reply Last reply Reply Quote 0
                                    • N
                                      nilux17
                                      last edited by nilux17

                                      Hello, here is my version of the script :

                                      <?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'])) {
                                      		//only one zone
                                      		if(isset($_GET["cpzone"])){
                                      			$cpzone=$_GET["cpzone"];
                                      			$count_cpusers = count(captiveportal_read_db());
                                      		}
                                      		else {
                                      
                                      			/* 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;
                                      ?>
                                      
                                      

                                      Here is how i check it with centreon :

                                      #!/bin/bash
                                      url=$1
                                      libelle=$2
                                      warningvalue=$3
                                      criticalvalue=$4
                                      
                                      if [ $# -eq '4' ]	
                                      	then
                                      
                                              #get the value
                                      	value=$(curl -sk $url)
                                      
                                              # UNKNOWN
                                               if [ -z "$value" ]
                                               then
                                                      echo "UNKNOWN - unable to establish the value returned"
                                                      exit 3
                                      
                                              # OK
                                               elif [ $value -lt $warningvalue ]
                                      	 then
                                      		echo "OK  - $value $libelle| value=$value"
                                      		exit 0
                                      
                                              # WARNING
                                               elif [ $value -gt $warningvalue ] && [ $value -lt $criticalvalue ]
                                      	 then
                                      		echo "WARNING - $value $libelle| value=$value"
                                      		exit 1
                                      
                                      	#CRITICAL
                                      	 else
                                      	 	echo "CRITICAL - $value $libelle| value=$value"
                                      		exit 2
                                               fi
                                      
                                      
                                      else
                                      	echo "Usage $0 url \"description of the value\" warningvalue criticalvalue"
                                      	exit 1
                                      
                                      fi
                                      

                                      this script is used like this :

                                      check_http_value https://10.11.0.1:8005/captiveportal-count-online-users.php?cpzone=captive_portal_r "users connected" 150 200
                                      OK  - 127 users connected| value=127
                                      

                                      maybe it is possible to improve this with using the $HOSTADRESS$...

                                      and here is the final result in centreon :
                                      c72b9eb7-9918-4ca8-8ebb-dc293d957f71-image.png

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