/usr/share/freeradius-dialupadmin/htdocs/stats.php is in freeradius-dialupadmin 2.1.12+dfsg-1.2ubuntu8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | <?php
require('../conf/config.php');
require('../lib/sql/nas_list.php');
require_once('../lib/xlat.php');
?>
<html>
<head>
<title>account analysis</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $config[general_charset]?>">
<link rel="stylesheet" href="style.css">
</head>
<body>
<center>
<?php
require_once('../lib/functions.php');
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
else{
echo <<<EOM
<b>Could not include SQL library functions. Aborting</b>
</body>
</html>
EOM;
exit();
}
$stats_num = array();
$date = strftime('%A, %e %B %Y, %T %Z');
$now = time();
if ($before == '')
$before = date($config[sql_date_format], $now + 86400);
$after = ($after != '') ? "$after" : date($config[sql_date_format], $now - 604800 );
$after_time = date2time($after);
$before_time = date2time($before);
$days[0] = $after;
$counter = $after_time + 86400;
$i = 1;
while($counter < $before_time){
$days[$i++] = date($config[sql_date_format],$counter);
$counter += 86400;
}
$days[$i] = $before;
$num_days = $i;
$column1 = ($column1 != '') ? "$column1" : 'sessions';
$column2 = ($column2 != '') ? "$column2" : 'usage';
$column3 = ($column3 != '') ? "$column3" : 'download';
$column[1] = "$column1";
$column[2] = "$column2";
$column[3] = "$column3";
$selected1["$column1"] = 'selected';
$selected2["$column2"] = 'selected';
$selected3["$column3"] = 'selected';
$message['sessions'] = 'sessions';
$message['usage'] = 'total usage time';
$message['upload'] = 'uploads';
$message['download'] = 'downloads';
if ($config[general_stats_use_totacct] == 'yes'){
$sql_val['sessions'] = 'connnum';
$sql_val['usage'] = 'conntotduration';
$sql_val['upload'] = 'inputoctets';
$sql_val['download'] = 'outputoctets';
}
else{
$sql_val['usage'] = 'acctsessiontime';
$sql_val['upload'] = 'acctinputoctets';
$sql_val['download'] = 'acctoutputoctets';
}
$fun['sessions'] = nothing;
$fun['usage'] = time2strclock;
$fun['upload'] = bytes2str;
$fun['download'] = bytes2str;
$sql_val['user'] = ($login == '') ? "WHERE username LIKE '%'" : "WHERE username = '$login'";
for ($j = 1; $j <= 3; $j++){
$tmp = "{$sql_val[$column[$j]]}";
$res[$j] = ($tmp == "") ? "COUNT(radacctid) AS res_$j" : "sum($tmp) AS res_$j";
}
$i = 1;
$servers[all] = 'all';
foreach ($nas_list as $nas){
$name = $nas[name];
if ($nas[ip] == '')
continue;
$servers[$name] = $nas[ip];
$i++;
}
ksort($servers);
if ($server != 'all' && $server != ''){
$server = da_sql_escape_string($server);
$s = "AND nasipaddress = '$server'";
}
$sql_extra_query = '';
if ($config[sql_accounting_extra_query] != '')
$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
$link = @da_sql_pconnect($config);
if ($link){
for ($i = $num_days;$i > -1; $i--){
$day = "$days[$i]";
if ($config[general_stats_use_totacct] == 'yes')
$search = @da_sql_query($link,$config,
"SELECT $res[1],$res[2],$res[3] FROM $config[sql_total_accounting_table]
$sql_val[user] AND acctdate = '$day' $s $sql_extra_query;");
else
$search = @da_sql_query($link,$config,
"SELECT $res[1],$res[2],$res[3] FROM $config[sql_accounting_table]
$sql_val[user] AND acctstoptime >= '$day 00:00:00'
AND acctstoptime <= '$day 23:59:59' $s $sql_extra_query;");
if ($search){
$row = @da_sql_fetch_array($search,$config);
$data[$day][1] = $row[res_1];
$data[sum][1] += $row[res_1];
$stats_num[1] = ($data[$day][1]) ? $stats_num[1] + 1 : $stats_num[1];
$data[$day][2] = $row[res_2];
$data[sum][2] += $row[res_2];
$stats_num[2] = ($data[$day][2]) ? $stats_num[2] + 1 : $stats_num[2];
$data[$day][3] = $row[res_3];
$data[sum][3] += $row[res_3];
$stats_num[3] = ($data[$day][3]) ? $stats_num[3] + 1 : $stats_num[3];
}
else
echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
}
}
else
echo "<b>Could not connect to SQL database</b><br>\n";
$stats_num[1] = ($stats_num[1]) ? $stats_num[1] : 1;
$stats_num[2] = ($stats_num[2]) ? $stats_num[2] : 1;
$stats_num[3] = ($stats_num[3]) ? $stats_num[3] : 1;
$data['avg'][1] = ceil($data['sum'][1] / $stats_num[1]);
$data['avg'][2] = ceil($data['sum'][2] / $stats_num[2]);
$data['avg'][3] = ceil($data['sum'][3] / $stats_num[3]);
$data['avg'][1] = $fun[$column[1]]($data['avg'][1]);
$data['avg'][2] = $fun[$column[2]]($data['avg'][2]);
$data['avg'][3] = $fun[$column[3]]($data['avg'][3]);
$data['sum'][1] = $fun[$column[1]]($data['sum'][1]);
$data['sum'][2] = $fun[$column[2]]($data['sum'][2]);
$data['sum'][3] = $fun[$column[3]]($data['sum'][3]);
for ($i = 0; $i <= $num_days; $i++){
$day = "$days[$i]";
$max[1] = ($max[1] > $data[$day][1] ) ? $max[1] : $data[$day][1];
$max[2] = ($max[2] > $data[$day][2] ) ? $max[2] : $data[$day][2];
$max[3] = ($max[3] > $data[$day][3] ) ? $max[3] : $data[$day][3];
}
for ($i = 0; $i <= $num_days; $i++){
$day = "$days[$i]";
for ($j = 1; $j <= 3; $j++){
$tmp = $data[$day][$j];
if (!$max[$j])
$p = $w = $c = 0;
else{
$p = floor(100 * ($tmp / $max[$j]));
$w = floor(70 * ($tmp / $max[$j]));
$c = hexdec('f0e9e2') - (258 * $p);
$c = dechex($c);
}
if (!$w)
$w++;
$perc[$day][$j] = $p . "%";
$width[$day][$j] = $w;
$color[$day][$j] = $c;
}
$data[$day][1] = $fun[$column[1]]($data[$day][1]);
$data[$day][2] = $fun[$column[2]]($data[$day][2]);
$data[$day][3] = $fun[$column[3]]($data[$day][3]);
}
$data[max][1] = $fun[$column[1]]($max[1]);
$data[max][2] = $fun[$column[2]]($max[2]);
$data[max][3] = $fun[$column[3]]($max[3]);
require('../html/stats.html.php');
?>
|