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

    how to get Captive Portal statistics from API?

    Scheduled Pinned Locked Moved Captive Portal
    3 Posts 2 Posters 455 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.
    • A
      ali550
      last edited by

      Hi everyone

      I have a question about captive portal. Is there any tools or API's I can get some information out of webconfigurator like online users, in/out statistics.

      Thanks

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

        @ali550

        No API in a strict sense.
        But its all 'PHP' so the info is available.

        You should read the 'book' : everything starts with /usr/local/captiveportal/index.php
        and /etc/inc/captiveportal.inc where everything is happening.

        I made myself this /root/captiveportal_count_online_users.php

        #!/usr/local/bin/php -q
        <?php
        /* $Id$ */
        /*
                captiveportal_gather_stats.php
                Copyright (C) 2011 Warren Baker
                All rights reserved.
        
                Redistribution and use in source and binary forms, with or without
                modification, are permitted provided that the following conditions are met:
        
                1. Redistributions of source code must retain the above copyright notice,
                   this list of conditions and the following disclaimer.
        
                2. Redistributions in binary form must reproduce the above copyright
                   notice, this list of conditions and the following disclaimer in the
                   documentation and/or other materials provided with the distribution.
        
                THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
                INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
                AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
                AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
                OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                POSSIBILITY OF SUCH DAMAGE.
        */
        
                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 for all zones */
        
                $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;
        ?>
        

        It doesn't do much : it counts the number of entries in the captive portal's database which gives me the number of connected users.
        You could read each record == a connected user and use any data base field for your own usage.
        /etc/inc/captiveportal.inc will tell you how to do so.

        The data base entries are updated every 60 seconds.

        No "help me" PM's please. Use the forum, the community will thank you.
        Edit : and where are the logs ??

        A 1 Reply Last reply Reply Quote 0
        • A
          ali550 @Gertjan
          last edited by

          @gertjan
          Thanks for your reply and help.
          I tested this PHP script and can get count online users.
          Do you know if I also can get each user downloaded/uploaded traffic and login start time ?

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