Subversion Repositories ALCASAR

Rev

Rev 1831 | Go to most recent revision | Details | Last modification | View Log

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