--- conf/accounting.attrs	2003-10-20 18:39:38.000000000 +0200
+++ accounting.attrs	2006-04-22 17:31:40.152836224 +0200
@@ -18,3 +18,4 @@
 7				server			yes		no		yes
 8				terminate cause		yes		no		yes
 9				callerid		yes		yes		yes
+10				total			yes		no		no
--- conf/admin.conf	2004-04-16 17:03:13.000000000 +0200
+++ conf/admin.conf	2006-04-22 21:09:18.197711664 +0200
@@ -303,3 +303,20 @@
 # it configurable
 # This is not needed if the monthly limit is not none
 #counter_monthly_calculate_usage: true
+
+#Define when the colors will turn into Orange
+acct_warning_perc: 80
+
+#
+# These are the attributes specified in sqlcounter.conf for volume limits
+max_total_volume_attr: Max-Octets
+max_upload_volume_attr: Max-Octets-Upload
+max_download_volume_attr: Max-Octets-Download
+
+#
+# Volume multiplier for volume limits
+# 1 = limit specified in bytes
+# 1024 = limit specified in kilobytes
+# 1048576 = limit specified in megabytes
+# Default is MB
+acct_volume_multiplier: 1048576
--- dialup_admin/htdocs/user_accounting.php3	2004-04-06 21:37:48.000000000 +0200
+++ /usr/share/freeradius-dialupadmin/htdocs/user_accounting.php3	2006-04-22 20:59:09.067313560 +0200
@@ -24,6 +24,10 @@
 	exit();
 }
 
+if (is_file("../lib/$config[general_lib_type]/user_info.php3")){
+        include("../lib/$config[general_lib_type]/user_info.php3");
+}
+
 $now = time();
 $now_str = ($now_str != '') ? "$now_str" : date($config[sql_date_format],$now + 86400);
 $prev_str = ($prev_str != '') ? "$prev_str" : date($config[sql_date_format], $now - 604800 );
@@ -39,6 +43,8 @@
 $selected[$order] = 'selected';
 $now_str = da_sql_escape_string($now_str);
 $prev_str = da_sql_escape_string($prev_str);
+$now_static = date($config[sql_date_format], mktime(0, 0, 0, date("m")+1, 1,  date("Y")));
+$month_prev_str = date($config[sql_date_format], mktime(0, 0, 0, date("m"), 1,  date("Y")));
 
 
 echo <<<EOM
@@ -59,6 +65,73 @@
 
 include("../html/user_toolbar.html.php3");
 
+$acct_warning_perc = $config[acct_warning_perc];
+$acct_vol_multi = $config[acct_volume_multiplier];
+$percenttot = '-';
+$percentdown = '-';
+$percentup = '-';
+//generate monthly usage stats
+$link = @da_sql_pconnect($config);
+if ($link){
+        $monthly = @da_sql_query($link,$config,
+        "SELECT * FROM $config[sql_accounting_table]
+        WHERE username = '$login' AND acctstarttime <= '$now_static'
+        AND acctstarttime >= '$month_prev_str' ORDER BY acctstarttime $order;");
+        if ($monthly){
+                while( $row = @da_sql_fetch_array($monthly,$config) ){
+                        $acct_monthly_upload = $row[acctinputoctets];
+                        $acct_monthly_upload_sum += $acct_monthly_upload;
+                        $acct_monthly_upload = bytes2str($acct_monthly_upload);
+                        $acct_monthly_download = $row[acctoutputoctets];
+                        $acct_monthly_download_sum += $acct_monthly_download;
+                        $acct_monthly_download = bytes2str($acct_monthly_download);
+                        }
+                $acct_limit_total = ($item_vals[$config[max_total_volume_attr]][0] != '') ? $item_vals[$config[max_total_volume_attr]][0] : $default_vals[$config[max_total_volume_attr]][0];
+                $acct_limit_total = $acct_vol_multi * $acct_limit_total;
+                $acct_limit_total = ($acct_limit_total) ? $acct_limit_total : '-';
+                $acct_limit_download = ($item_vals[$config[max_download_volume_attr]][0] != '') ? $item_vals[$config[max_download_volume_attr]][0] : $default_vals[$config[max_download_volume_attr]][0];
+                $acct_limit_download = $acct_vol_multi * $acct_limit_download;
+                $acct_limit_download = ($acct_limit_download) ? $acct_limit_download : '-';
+                $acct_limit_upload = ($item_vals[$config[max_upload_volume_attr]][0] != '') ? $item_vals[$config[max_upload_volume_attr]][0] : $default_vals[$config[max_upload_volume_attr]][0];
+                $acct_limit_upload = $acct_vol_multi * $acct_limit_upload;
+                $acct_limit_upload = ($acct_limit_upload) ? $acct_limit_upload : '-';
+                //Declare TOTAL SUM
+                $acct_monthly_total_sum = $acct_monthly_download_sum + $acct_monthly_upload_sum;
+                //Calculate if volume limits are reached
+                if ( $acct_limit_total != '-' ) {
+                        $percenttot = round(100 * ($acct_monthly_total_sum / $acct_limit_total),2);
+                                //Color scheme for volume stats
+                                if ( $percenttot < $acct_warning_perc ) { $volcoltot="green"; }
+                                elseif ( $percenttot >= 100 ) { $volcoltot="red"; }
+                                else { $volcoltot="orange";}
+                        $acct_limit_total = bytes2str($acct_limit_total);
+                }
+                if ( $acct_limit_download != '-' ) {
+                        $percentdownload = round(100 * ($acct_monthly_download_sum / $acct_limit_download),2);
+                                //Color scheme for volume stats
+                                if ( $percentdownload < $acct_warning_perc ) { $volcoldown="green"; }
+                                elseif ( $percentdownload >= 100 ) { $volcoldown="red"; }
+                                else { $volcoldown="orange"; }
+                        $acct_limit_download = bytes2str($acct_limit_download);
+                }
+               if ( $acct_limit_upload != '-' ) {
+                        $percentup = round(100 * ($acct_monthly_upload_sum / $acct_limit_upload),2);
+                                //Color scheme for volume stats
+                                if ( $percentup < $acct_warning_perc ) { $volcolup="green"; }
+                                elseif ( $percentup >= 100 ) { $volcolup="red"; }
+                                else { $volcolup="orange"; }
+                        $acct_limit_upload = bytes2str($acct_limit_upload);
+                }
+                // Changes vars into strings
+                $acct_monthly_total_sum = bytes2str($acct_monthly_total_sum);
+                $acct_monthly_upload_sum = bytes2str($acct_monthly_upload_sum);
+                $acct_monthly_download_sum = bytes2str($acct_monthly_download_sum);
+        }
+        else
+                echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
+}
+
+
 print <<<EOM
 </table>
 <br>
@@ -74,6 +147,38 @@
 </td></tr>
 <tr bgcolor="black" valign=top><td colspan=2>
 	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
+        <tr><td>
+        <b>Period overview from $month_prev_str up to $now_static</b>
+                                <table cellSpacing="1" cellPadding="8" bgColor="#cccccc" border="0" id="table2">
+                                                <tr>
+                                                <td bgColor="white">&nbsp;</td>
+                                                <td align="middle" bgColor="white">Maximum allowed volume<br></td>
+                                                <td align="middle" bgColor="white">Used</td>
+                                                <td align="middle" bgColor="white">% used</td>
+                                        </tr>
+                                         <tr>
+                                                <td align="right" bgColor="white">Download volume</td>
+                                                <td align="middle" bgColor="white"><b>$acct_limit_download</b></td>
+                                                <td align="middle" bgColor="white"><font color="$volcoldown"><b>$acct_monthly_download_sum</b></font></td>
+                                                <td align="middle" bgColor="white"><font color="$volcoldown"><b>$percentdown</b></font></td>
+                                        </tr>
+                                       <tr>
+                                                <td align="right" bgColor="white">Upstream volume</td>
+                                                <td align="middle" bgColor="white"><b>$acct_limit_upload</b></td>
+                                                <td align="middle" bgColor="white"><font color="$volcolup"><b>$acct_monthly_upload_sum</b></font></td>
+                                                <td align="middle" bgColor="white"><font color="$volcolup"><b>$percentup</b></font></td>
+                                        </tr>
+                                        <tr>
+                                                <td align="right" bgColor="white">Total volume</td>
+                                                <td align="middle" bgColor="white"><b>$acct_limit_total</b></td>
+                                                <td align="middle" bgColor="white"><font color="$volcoltot"><b>$acct_monthly_total_sum</b></font></td>
+                                                <td align="middle" bgColor="white"><font color="$volcoltot"><b>$percenttot</b></font></td>
+                                        </tr>
+
+                                </table>
+
+        </td></tr>
+
 	<tr><td>
 <b>$prev_str</b> up to <b>$now_str</b>
 EOM;
@@ -84,7 +189,7 @@
 	<tr bgcolor="#d0ddb0">
 	<th>#</th>
 <?php
-for($i=1;$i<=9;$i++){
+for($i=1;$i<=10;$i++){
 	if ($acct_attrs['ua']["$i"] != '')
 		echo "<th>" . $acct_attrs['ua']["$i"] . "</th>\n";
 }
@@ -95,7 +200,6 @@
 	</tr>
 
 <?php
-$link = @da_sql_pconnect($config);
 if ($link){
 	$search = @da_sql_query($link,$config,
 	"SELECT * FROM $config[sql_accounting_table]
@@ -121,6 +225,8 @@
 			$acct_download = $row[acctoutputoctets];
 			$acct_download_sum += $acct_download;
 			$acct_download = bytes2str($acct_download);
+			$acct_session_volume = $row[acctinputoctets] + $row[acctoutputoctets];
+			$acct_session_volume = bytes2str($acct_session_volume);
 			$acct_server = $row[nasipaddress];
 			if ($acct_server != ''){
 				$acct_server = $da_name_cache[$row[nasipaddress]];
@@ -159,11 +265,13 @@
 				if ($acct_attrs[ua][7] != '') echo "<td>$acct_server</td>\n";
 				if ($acct_attrs[ua][8] != '') echo "<td>$acct_terminate_cause</td>\n";
 				if ($acct_attrs[ua][9] != '') echo "<td>$acct_callerid</td>\n";
+				if ($acct_attrs[ua][10] != '') echo "<td>$acct_session_volume</td>\n";
 			echo "</tr>\n";
 		}
 		$acct_sessiontime_sum = time2str($acct_sessiontime_sum);
 		$acct_upload_sum = bytes2str($acct_upload_sum);
 		$acct_download_sum = bytes2str($acct_download_sum);
+		$acct_total_sum = bytes2str($acct_download_sum + $acct_upload_sum);
 	}
 	else
 		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
@@ -186,6 +294,7 @@
 				if ($acct_attrs[ua][7] != '') echo "<td>&nbsp;</td>\n";
 				if ($acct_attrs[ua][8] != '') echo "<td>&nbsp;</td>\n";
 				if ($acct_attrs[ua][9] != '') echo "<td>&nbsp;</td>\n";
+				if ($acct_attrs[ua][10] != '') echo "<td align=\"right\" nowrap><b>$acct_total_sum</b></td>\n";
 ?>
 				</tr>
 	</table>
