From: kkalev Date: Mon, 9 Aug 2004 15:37:46 +0000 (+0000) Subject: In user_state also take into account any open sessions when calculating daily/weekly... X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=9a11ce7f0fa309204f0bedf87718e82ebff471e3;p=freeradius-dialup-admin.git 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. --- diff --git a/Changelog b/Changelog index 710ce52..4011136 100644 --- 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 e5f08bd..2ea2678 100644 --- 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. diff --git a/htdocs/user_state.php3 b/htdocs/user_state.php3 index 233c19d..0e5ec31 100644 --- a/htdocs/user_state.php3 +++ b/htdocs/user_state.php3 @@ -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"; ?>