]> git.entuzijast.net Git - freeradius-dialup-admin.git/commitdiff
Add a configuration directive counter_monthly_calculate_usage to calculate the monthl...
authorkkalev <kkalev>
Sun, 5 Oct 2003 16:03:11 +0000 (16:03 +0000)
committerkkalev <kkalev>
Sun, 5 Oct 2003 16:03:11 +0000 (16:03 +0000)
it in user_admin if monthly_limit != 'none' or if this directive is set.
Based on a report by "apellido jr., wilfredo p"

Changelog
conf/admin.conf
htdocs/user_admin.php3

index 937c89a158859dd50e221a84da4ce833e41b4b34..9a61695e8c53e838f2e2eb848988a54352d718f2 100644 (file)
--- 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
index 73708f00c26081aa064b5b137e9cd0929e4a2113..4df7d4a4e8b16e0060b3f31f177067866304addc 100644 (file)
@@ -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
index 1be9a4263e393fb252d4ceef2e4ce66f44581088..e2eb392d748593aa21b4221d8d5311927f846282 100644 (file)
@@ -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 "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\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 "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\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 = "<font color=red>$weekly_used</font>";
 
+       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 = "<font color=red>$monthly_used</font>";
+       }
+
        $search = @da_sql_query($link,$config,
        "SELECT * FROM $config[sql_accounting_table]
        WHERE UserName = '$login' AND AcctStopTime IS NULL