]> git.entuzijast.net Git - freeradius-dialup-admin.git/commitdiff
In user_state also take into account any open sessions when calculating daily/weekly...
authorkkalev <kkalev>
Mon, 9 Aug 2004 15:37:46 +0000 (15:37 +0000)
committerkkalev <kkalev>
Mon, 9 Aug 2004 15:37:46 +0000 (15:37 +0000)
Add two more lines in the output stating the number of current open sessions and the time used.

Changelog
README
htdocs/user_state.php3

index 710ce52110fcadf307569e47a0e7eba58e76b4f3..40111369f8531c5ff508ecb13df98031cdf3c44c 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -17,6 +17,8 @@ Ver 1.75:
 * Use lower cased row names in badusers page
 * Wrong foreach in show_groups and group_new.
 * Fix operator escaping in lib/sql/change_attrs.php3
+* In user_state also take into account any open sessions when calculating daily/weekly usage.
+  Add two more lines in the output stating the number of current open sessions and the time used.
 Ver 1.72:
 * Move the xlat function to a separate file in lib/xlat.php3
 * Add a lib/sql/nas_list.php3 to also get the nas list from sql (naslist.conf still works)
diff --git a/README b/README
index e5f08bdc750a1518a9e093d5c602a89986919268..2ea26788ff1289c414329295dfd7ed0fd6b5300b 100644 (file)
--- a/README
+++ b/README
@@ -84,7 +84,8 @@ htdocs:: user_state.php3 =>
        overview of the status of a user. It will return the following fields
        separated by new lines:
        account_status(active or inactive),lock message,weekly limit,daily limit,
-       weekly used,weekly connections,daily used,daily connections
+       weekly used,weekly connections,daily used,daily connections,
+       active sessions number,active sessions time
 htdocs:: user_finger.php3 =>
        It will finger the nas(es) and show the logged in users. If an argument server is passed then
        it will only show users for the specific access server.
index 233c19d298a209c50a99a46a6f7463b7ce28fea8..0e5ec318ddb94f1937bfa25f85df34c27ad09f2f 100644 (file)
@@ -25,6 +25,8 @@ $week = $now - date('w') * 86400;
 $now_str = date("$config[sql_date_format]",$now + 86400);
 $week_str = date("$config[sql_date_format]",$week);
 $today = date("$config[sql_date_format]",$now);
+$open_conns = $daily_conns = $weekly_conns = 0;
+$weekly_used = $daily_used = $online_time = time2strclock(0);
 
 $link = @da_sql_pconnect($config);
 if ($link){
@@ -33,24 +35,43 @@ if ($link){
        username = '$login' AND acctstoptime >= '$week_str' AND
        acctstoptime <= '$now_str';");
        if ($search){
-               $row = @da_sql_fetch_array($search,$config);
-               $weekly_used = time2strclock($row[sum_sess_time]);
-               $weekly_conns = $row[counter];
+               if ($row = @da_sql_fetch_array($search,$config)){
+                       $weekly_used = time2strclock($row[sum_sess_time]);
+                       $weekly_conns = $row[counter];
+               }
        }
        $search = @da_sql_query($link,$config,
        "SELECT COUNT(*) AS counter,sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE
        username = '$login' AND acctstoptime >= '$today 00:00:00'
        AND acctstoptime <= '$today 23:59:59';");
        if ($search){
-               $row = @da_sql_fetch_array($search,$config);
-               $daily_used = time2strclock($row[sum_sess_time]);
-               $daily_conns = $row[counter];
+               if ($row = @da_sql_fetch_array($search,$config)){
+                       $daily_used = time2strclock($row[sum_sess_time]);
+                       $daily_conns = $row[counter];
+               }
        }
+       $search = @da_sql_query($link,$config,
+       "SELECT COUNT(*) AS counter, unix_timestamp() - unix_timestamp(acctstarttime) as diff FROM
+       $config[sql_accounting_table] WHERE acctstoptime is null AND username = '$login'
+       GROUP BY username;");
+       if ($search){
+               if ($row = @da_sql_fetch_array($search,$config)){
+                       $open_conns = $row[counter];
+                       $online_time = $row[diff];
+                       $weekly_used += $online_time;
+                       $daily_used += $online_time;
+                       $daily_conns += $open_conns;
+                       $weekly_conns += $open_conns;
+                       $online_time = time2strclock($online_time);
+               }
+       }
+       $weekly_used = time2strclock($weekly_used);
+       $daily_used = time2strclock($daily_used);
 }
 
 
 foreach($vars as $val){
        echo "$val\n";
 }
-echo "$weekly_used\n$weekly_conns\n$daily_used\n$daily_conns";
+echo "$weekly_used\n$weekly_conns\n$daily_used\n$daily_conns\n$open_conns\n$online_time";
 ?>