Subversion Repositories ALCASAR

Rev

Rev 324 | Rev 2191 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 324 Rev 1831
Line 28... Line 28...
28
 
28
 
29
$stats_num = array();
29
$stats_num = array();
30
 
30
 
31
$date = strftime('%A, %e %B %Y, %T %Z');
31
$date = strftime('%A, %e %B %Y, %T %Z');
32
$now = time();
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
 
33
 
-
 
34
if (!isset($before))
-
 
35
{
-
 
36
	$before = date($config['sql_date_format'], $now + 86400);
-
 
37
}
-
 
38
if (!isset($after))
-
 
39
{
-
 
40
	$after = date($config['sql_date_format'], $now - 604800 );
-
 
41
}
37
$after_time = date2time($after);
42
$after_time = strtotime($after);
38
$before_time = date2time($before);
43
$before_time = strtotime($before);
39
$days[0] = $after;
44
$days[0] = $after;
40
$counter = $after_time + 86400;
45
$counter = $after_time + 86400;
41
$i = 1;
46
$i = 1;
42
while($counter < $before_time){
47
while($counter < $before_time){
43
	$days[$i++] = date($config[sql_date_format],$counter);	
48
	$days[$i++] = date($config['sql_date_format'],$counter);	
44
	$counter += 86400;
49
	$counter += 86400;
45
}
50
}
46
$days[$i] = $before;
51
$days[$i] = $before;
47
$num_days = $i;
52
$num_days = $i;
48
 
53
 
49
$column1 = ($column1 != '') ? "$column1" : 'sessions';
54
$column1 = (isset($column1)) ? "$column1" : 'sessions';
50
$column2 = ($column2 != '') ? "$column2" : 'usage';
-
 
51
$column3 = ($column3 != '') ? "$column3" : 'download';
-
 
52
$column[1] = "$column1";
55
$column[1] = "$column1";
53
$column[2] = "$column2";
-
 
54
$column[3] = "$column3";
-
 
55
$selected1["$column1"] = 'selected';
56
$selected1["$column1"] = 'selected';
-
 
57
 
-
 
58
$column2 = (isset($column2)) ? "$column2" : 'usage';
-
 
59
$column[2] = "$column2";
56
$selected2["$column2"] = 'selected';
60
$selected2["$column2"] = 'selected';
-
 
61
 
-
 
62
$column3 = (isset($column3)) ? "$column3" : 'download';
-
 
63
$column[3] = "$column3";
57
$selected3["$column3"] = 'selected';
64
$selected3["$column3"] = 'selected';
58
 
65
 
59
$message['sessions'] = 'sessions';
66
$message['sessions'] = 'sessions';
60
$message['usage'] = 'total usage time';
67
$message['usage'] = 'total usage time';
61
$message['usage'] = 'temps d\'utilisation total ';
68
$message['usage'] = 'temps d\'utilisation total ';
62
$message['upload'] = 'uploads';
69
$message['upload'] = 'uploads';
63
$message['download'] = 'downloads';
70
$message['download'] = 'downloads';
64
if ($config[general_stats_use_totacct] == 'yes'){
71
if ($config['general_stats_use_totacct'] == 'yes'){
65
	$sql_val['sessions'] = 'connnum';
72
	$sql_val['sessions'] = 'connnum';
66
	$sql_val['usage'] = 'conntotduration';
73
	$sql_val['usage'] = 'conntotduration';
67
	$sql_val['upload'] = 'inputoctets';
74
	$sql_val['upload'] = 'inputoctets';
68
	$sql_val['download'] = 'outputoctets';
75
	$sql_val['download'] = 'outputoctets';
69
}
76
}
70
else{
77
else{
71
	$sql_val['usage'] = 'acctsessiontime';
78
	$sql_val['usage'] = 'acctsessiontime';
72
	$sql_val['upload'] = 'acctinputoctets';
79
	$sql_val['upload'] = 'acctinputoctets';
73
	$sql_val['download'] = 'acctoutputoctets';
80
	$sql_val['download'] = 'acctoutputoctets';
74
}
81
}
75
$fun['sessions'] = nothing;
82
$fun['sessions'] = 'nothing';
76
$fun['usage'] = time2strclock;
83
$fun['usage'] = 'time2strclock';
77
$fun['upload'] = bytes2str;
84
$fun['upload'] = 'bytes2str';
78
$fun['download'] = bytes2str;
85
$fun['download'] = 'bytes2str';
79
$sql_val['user'] = ($login == '') ? "WHERE username LIKE '%'" : "WHERE username = '$login'";
86
$sql_val['user'] = (!isset($login) || $login == '' ) ? "WHERE username LIKE '%'" : "WHERE username = '$login'";
80
for ($j = 1; $j <= 3; $j++){
87
for ($j = 1; $j <= 3; $j++){
81
	$tmp = "{$sql_val[$column[$j]]}";
88
	$tmp = "{$sql_val[$column[$j]]}";
82
	$res[$j] = ($tmp == "") ? "COUNT(radacctid) AS res_$j" : "sum($tmp) AS res_$j";
89
	$res[$j] = (!isset($tmp)) ? "COUNT(radacctid) AS res_$j" : "sum($tmp) AS res_$j";
83
}
90
}
84
$i = 1;
91
$i = 1;
85
$servers[all] = 'all';
92
$servers['all'] = 'all';
86
foreach ($nas_list as $nas){
93
foreach ($nas_list as $nas){
87
	$name = $nas[name];
94
	$name = $nas['name'];
88
	if ($nas[ip] == '')
95
	if ($nas['ip'] == '')
89
		continue;
96
		continue;
90
	$servers[$name] = $nas[ip];
97
	$servers[$name] = $nas['ip'];
91
	$i++;
98
	$i++;
92
}
99
}
93
ksort($servers);
100
ksort($servers);
-
 
101
if(isset($server))
-
 
102
{
94
if ($server != 'all' && $server != ''){
103
	if ($server != 'all' && $server != ''){
95
	$server = da_sql_escape_string($server);
104
		$server = da_sql_escape_string($link,$server);
96
	$s = "AND nasipaddress = '$server'";
105
		$s = "AND nasipaddress = '$server'";
-
 
106
	}
97
}
107
}
98
$sql_extra_query = '';
108
$sql_extra_query = '';
99
if ($config[sql_accounting_extra_query] != '')
109
if (isset($config['sql_accounting_extra_query']))
-
 
110
{
100
	$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
111
	$sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
-
 
112
}
-
 
113
else
-
 
114
{
-
 
115
	$sql_extra_query = "";
-
 
116
}
101
 
117
 
102
$link = @da_sql_pconnect($config);
118
$link = @da_sql_pconnect($config);
103
if ($link){
119
if ($link)
-
 
120
{
-
 
121
	$data['sum'] = array();
-
 
122
	$data['sum'][1] = "";
-
 
123
	$data['sum'][2] = "";
-
 
124
	$data['sum'][3] = "";
-
 
125
 
-
 
126
	$stats_num[1] = "";
-
 
127
	$stats_num[2] = "";
-
 
128
	$stats_num[3] = "";
-
 
129
 
104
	for ($i = $num_days;$i > -1; $i--){
130
	for ($i = $num_days;$i > -1; $i--){
105
		$day = "$days[$i]";
131
		$day = "$days[$i]";
106
		if ($config[general_stats_use_totacct] == 'yes')
132
		if ($config['general_stats_use_totacct'] == 'yes')
107
			$search = @da_sql_query($link,$config,
133
			$search = @da_sql_query($link,$config,
108
			"SELECT $res[1],$res[2],$res[3] FROM $config[sql_total_accounting_table]
134
			"SELECT $res[1],$res[2],$res[3] FROM $config[sql_total_accounting_table]
109
			$sql_val[user] AND acctdate = '$day' $s $sql_extra_query;");
135
			$sql_val[user] AND acctdate = '$day' $s $sql_extra_query;");
110
		else
136
		else
111
			$search = @da_sql_query($link,$config,
137
			$search = @da_sql_query($link,$config,
112
			"SELECT $res[1],$res[2],$res[3] FROM $config[sql_accounting_table]
138
			"SELECT $res[1],$res[2],$res[3] FROM $config[sql_accounting_table]
113
			$sql_val[user] AND acctstoptime >= '$day 00:00:00' 
139
			$sql_val[user] AND acctstoptime >= '$day 00:00:00' 
114
			AND acctstoptime <= '$day 23:59:59' $s $sql_extra_query;");
140
			AND acctstoptime <= '$day 23:59:59' $s $sql_extra_query;");
115
		if ($search){
141
		if ($search){
116
			$row = @da_sql_fetch_array($search,$config);
142
			$row = @da_sql_fetch_array($search,$config);
117
			$data[$day][1] = $row[res_1];
143
			$data[$day][1] = $row['res_1'];
118
			$data[sum][1] += $row[res_1];
144
			$data['sum'][1] += $row['res_1'];
119
			$stats_num[1] = ($data[$day][1]) ? $stats_num[1] + 1 : $stats_num[1];
145
			$stats_num[1] = ($data[$day][1]) ? $stats_num[1] + 1 : $stats_num[1];
120
			$data[$day][2] = $row[res_2];
146
			$data[$day][2] = $row['res_2'];
121
			$data[sum][2] += $row[res_2];
147
			$data['sum'][2] += $row['res_2'];
122
			$stats_num[2] = ($data[$day][2]) ? $stats_num[2] + 1 : $stats_num[2];
148
			$stats_num[2] = ($data[$day][2]) ? $stats_num[2] + 1 : $stats_num[2];
123
			$data[$day][3] = $row[res_3];
149
			$data[$day][3] = $row['res_3'];
124
			$data[sum][3] += $row[res_3];
150
			$data['sum'][3] += $row['res_3'];
125
			$stats_num[3] = ($data[$day][3]) ? $stats_num[3] + 1 : $stats_num[3];
151
			$stats_num[3] = ($data[$day][3]) ? $stats_num[3] + 1 : $stats_num[3];
126
		}
152
		}
127
		else
153
		else
128
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
154
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
129
	}
155
	}
Line 145... Line 171...
145
 
171
 
146
$data['sum'][1] = $fun[$column[1]]($data['sum'][1]);
172
$data['sum'][1] = $fun[$column[1]]($data['sum'][1]);
147
$data['sum'][2] = $fun[$column[2]]($data['sum'][2]);
173
$data['sum'][2] = $fun[$column[2]]($data['sum'][2]);
148
$data['sum'][3] = $fun[$column[3]]($data['sum'][3]);
174
$data['sum'][3] = $fun[$column[3]]($data['sum'][3]);
149
 
175
 
-
 
176
$max[1] = 0;
-
 
177
$max[2] = 0;
-
 
178
$max[3] = 0;
-
 
179
 
150
for ($i = 0; $i <= $num_days; $i++){
180
for ($i = 0; $i <= $num_days; $i++){
151
	$day = "$days[$i]";
181
	$day = "$days[$i]";
152
	$max[1] = ($max[1] > $data[$day][1] ) ? $max[1] : $data[$day][1];
182
	$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];
183
	$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];
184
	$max[3] = ($max[3] > $data[$day][3] ) ? $max[3] : $data[$day][3];
Line 176... Line 206...
176
	$data[$day][1] = $fun[$column[1]]($data[$day][1]);
206
	$data[$day][1] = $fun[$column[1]]($data[$day][1]);
177
	$data[$day][2] = $fun[$column[2]]($data[$day][2]);
207
	$data[$day][2] = $fun[$column[2]]($data[$day][2]);
178
	$data[$day][3] = $fun[$column[3]]($data[$day][3]);
208
	$data[$day][3] = $fun[$column[3]]($data[$day][3]);
179
}
209
}
180
 
210
 
181
$data[max][1] = $fun[$column[1]]($max[1]);
211
$data['max'][1] = $fun[$column[1]]($max[1]);
182
$data[max][2] = $fun[$column[2]]($max[2]);
212
$data['max'][2] = $fun[$column[2]]($max[2]);
183
$data[max][3] = $fun[$column[3]]($max[3]);
213
$data['max'][3] = $fun[$column[3]]($max[3]);
184
 
214
 
185
require('../html/stats.html.php');
215
require('../html/stats.html.php');
186
?>
216
?>