From: kkalev Date: Sun, 5 Oct 2003 16:03:11 +0000 (+0000) Subject: Add a configuration directive counter_monthly_calculate_usage to calculate the monthl... X-Git-Url: https://git.entuzijast.net/?a=commitdiff_plain;h=fb55cf65ed3368e39a081aacc132f38b3f9279c1;p=freeradius-dialup-admin.git Add a configuration directive counter_monthly_calculate_usage to calculate the monthly usage time. Calculate it in user_admin if monthly_limit != 'none' or if this directive is set. Based on a report by "apellido jr., wilfredo p" --- diff --git a/Changelog b/Changelog index 937c89a..9a61695 100644 --- a/Changelog +++ b/Changelog @@ -44,6 +44,9 @@ Ver 1.63: * Calculate weekly used time correctly (from Sunday 00:00:00) * Allow for defining the ldap_filter used when searching for a user. The filter supports dynamic variables like %u (username) and %U (username provided though http auth) +* Add a configuration directive counter_monthly_calculate_usage to calculate the monthly usage time. Calculate + it in user_admin if monthly_limit != 'none' or if this directive is set. + Based on a report by "apellido jr., wilfredo p" Ver 1.62: * Remove one sql query from user_admin which was not needed. * Instead of a query like "LIKE 'YYYY-MM-DD%'" use "AcctStopTime >= 'YYYY-MM-DD 00:00:00 AND AcctStopTime diff --git a/conf/admin.conf b/conf/admin.conf index 73708f0..4df7d4a 100644 --- a/conf/admin.conf +++ b/conf/admin.conf @@ -244,3 +244,8 @@ sql_connect_timeout: 3 counter_default_daily: 14400 counter_default_weekly: 72000 counter_default_monthly: none +# +# Since calculating monthly usage can be quite expensive we make +# it configurable +# This is not needed if the monthly limit is not none +#counter_monthly_calculate_usage: true diff --git a/htdocs/user_admin.php3 b/htdocs/user_admin.php3 index 1be9a42..e2eb392 100644 --- a/htdocs/user_admin.php3 +++ b/htdocs/user_admin.php3 @@ -64,6 +64,7 @@ $now_str = date("$config[sql_date_format]",$now + 86400); $week_str = date("$config[sql_date_format]",$week); $day = date('w'); $week_start = date($config[sql_date_format],$now - ($day)*86400); +$month_start = date($config[sql_date_format],$now - date('j')*86400); $today = $day; $now_tmp = $now; for ($i = $day; $i >-1; $i--){ @@ -112,6 +113,17 @@ if ($link){ } else echo "Database query failed: " . da_sql_error($link,$config) . "
\n"; + if ($monthly_limit != 'none' || $config[counter_monthly_calculate_usage] == 'true'){ + $search = @da_sql_query($link,$config, + "SELECT sum(AcctSessionTime) FROM $config[sql_accounting_table] WHERE UserName = '$login' + AND AcctStartTime >= '$month_start' AND AcctStartTime <= '$now_str';"); + if ($search){ + $row = @da_sql_fetch_array($search,$config); + $monthly_used = $row['sum(AcctSessionTime)']; + } + else + echo "Database query failed: " . da_sql_error($link,$config) . "
\n"; + } $search = @da_sql_query($link,$config, "SELECT COUNT(*) FROM $config[sql_accounting_table] WHERE UserName = '$login' AND AcctStopTime >= '$week_str' AND AcctStopTime <= '$now_str' @@ -172,6 +184,24 @@ if ($link){ if ($weekly_limit != 'none' && !$tmp) $weekly_used = "$weekly_used"; + if ($monthly_limit != 'none'){ + $tmp = $monthly_limit - $monthly_used; + if ($tmp <=0){ + $tmp = 0; + $extra_msg .= '(Out of monthly quota)'; + } + if (!is_numeric($remaining)) + $remaining = $tmp; + if ($remaining > $tmp) + $remaining = $tmp; + $log_color = ($remaining) ? 'green' : 'red'; + } + if ($config[counter_monthly_calculate_usage] == 'true'){ + $monthly_used = time2str($monthly_used); + if ($monthly_limit != 'none' && !$tmp) + $monthly_used = "$monthly_used"; + } + $search = @da_sql_query($link,$config, "SELECT * FROM $config[sql_accounting_table] WHERE UserName = '$login' AND AcctStopTime IS NULL