Subversion Repositories ALCASAR

Rev

Rev 2817 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
324 richard 1
<?php
2191 tom.houday 2
# $Id: user_stats.php 2854 2020-07-20 22:08:05Z rexy $
3
 
324 richard 4
require('/etc/freeradius-web/config.php');
5
require('../lib/functions.php');
6
require('../lib/sql/nas_list.php');
7
require_once('../lib/xlat.php');
8
?>
2854 rexy 9
<!DOCTYPE html>
324 richard 10
<html>
11
<?php
12
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
13
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
14
else{
15
	echo <<<EOM
16
<title>Statistiques utilisateurs</title>
17
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
2817 rexy 18
<link rel="stylesheet" href="/css/acc.css">
324 richard 19
</head>
20
<body>
21
<center>
22
<b>Could not include SQL library functions. Aborting</b>
23
</body>
24
</html>
25
EOM;
26
	exit();
27
}
2222 richard 28
# Choice of language
29
$Language = 'en';
30
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
31
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
32
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
33
if($Language == 'fr'){
34
	$l_title		= "Statistiques de connexion des utilisateurs";
35
	$l_start_date		= "Dates de début";
36
	$l_end_date		= "Dates de fin";
37
	$l_number_result	= "Nb. résultat / page";
38
	$l_order_by		= "Trié par";
39
	$l_sorted_order		= "Classé par ordre";
40
	$l_all			= "Tous";
41
	$l_con_number		= "Nombre de connexions";
42
	$l_con_length		= "Durée de connexions";
43
	$l_ascending		= "Croissant";
44
	$l_descending		= "Décroissant";
45
	$l_server		= "Sur le serveur";
46
	$l_user			= "Filtrer pour un utilisateur (laissez vide pour tous)";
47
	$l_show			= "Montrer";
48
	$l_from			= "Du";
49
	$l_to			= "au";
2264 richard 50
	$l_server		= "Serveur";
51
	$l_login		= "Identifiant";
52
	$l_user_edit		= "Éditer l'utilisateur";
2854 rexy 53
} else if($Language == 'es') {
54
    $l_title		= "Estadísticas de conexiones de los Usuarios";
55
	$l_start_date		= "Desde fecha";
56
	$l_end_date		= "Hasta fecha";
57
	$l_number_result	= "Nro de resultados / páginas";
58
	$l_order_by		= "Ordenados por";
59
	$l_sorted_order		= "Ordenar resultados";
60
	$l_all			= "Todos";
61
	$l_con_number		= "Números de conexiones";
62
	$l_con_length		= "Duración de la conexión";
63
	$l_ascending		= "Ascendente";
64
	$l_descending		= "Descendente";
65
	$l_server		= "En el servidor";
66
	$l_user			= "Filtrar por usuario (en blanco para todos los usuarios)";
67
	$l_show			= "Mostrar";
68
	$l_from			= "Desde";
69
	$l_to			= "hasta";
70
	$l_server		= "Servidor";
71
	$l_login		= "Usuario";
72
	$l_user_edit		= "Modificar usuario";
2222 richard 73
} else {
74
	$l_title		= "Statistics of users connexions";
75
	$l_start_date		= "Start date";
76
	$l_end_date		= "End date";
77
	$l_number_result	= "Nb results / page";
78
	$l_order_by		= "Sorted by";
79
	$l_sorted_order		= "Sorted order";
80
	$l_all			= "All";
81
	$l_con_number		= "Connections number";
82
	$l_con_length		= "Connection length";
83
	$l_ascending		= "Ascending";
84
	$l_descending		= "Descending";
85
	$l_server		= "On server";
86
	$l_user			= "Filter for a user (let empty for all)";
87
	$l_show			= "Show";
88
	$l_from			= "From";
89
	$l_to			= "to";
2264 richard 90
	$l_server		= "Server";
91
	$l_login		= "Login";
92
	$l_user_edit		= "Edit user";
2222 richard 93
}
1831 raphael.pi 94
if (!isset($start) && !isset($stop)){
324 richard 95
	$now = time();
1831 raphael.pi 96
	$stop = date($config['sql_date_format'],$now);
324 richard 97
	$now -= 604800;
1831 raphael.pi 98
	$start = date($config['sql_date_format'],$now);
324 richard 99
}
1831 raphael.pi 100
$start = da_sql_escape_string($link,$start);
101
$stop = da_sql_escape_string($link,$stop);
324 richard 102
?>
103
<head>
2222 richard 104
<title><?php echo "$l_title";?></title>
2817 rexy 105
<link rel="stylesheet" href="/css/acc.css" type="text/css">
324 richard 106
</head>
107
<body>
2854 rexy 108
<div class="panel">
109
	<div class="panel-header"><?= $l_title ?></div>
110
	<div class="panel-row">
1956 raphael.pi 111
<table width="100%" border="0" cellspacing="0" cellpadding="0">
324 richard 112
<?php
1831 raphael.pi 113
if(isset($pagesize))
114
{	
2264 richard 115
	echo <<<EOM
2222 richard 116
<tr align="center"><td colspan="9">
117
$l_from $start $l_to $stop
118
</td></tr>
119
<tr>
2264 richard 120
<th>#</th><th>$l_login</th><th>Date</th><th>$l_server</th><th>$l_con_number</th><th>$l_con_length</th><th>Upload</th><th>Download</th>
2222 richard 121
</tr>
1831 raphael.pi 122
EOM;
2264 richard 123
	$pagesize = ($pagesize) ? $pagesize : 10;
124
	$selected[5] = "";
125
	$selected[10] = "";
126
	$selected[15] = "";
127
	$selected[20] = "";
128
	$selected[40] = "";
129
	$selected[80] = "";
130
	$selected['all'] = "";
131
	$selected['num'] = "";
132
	$selected['time'] = "";
133
	$selected['asc'] = "";
134
	$selected['desc'] = "";
135
	if (!is_numeric($pagesize) && $pagesize != 'all')
136
		$pagezise = 10;
137
	if ($pagesize > 100)
138
		$pagesize = 100;
139
	$limit = ($pagesize == 'all') ? '100' : "$pagesize";
140
	$selected[$pagesize] = 'selected';
141
	$order = ($order) ? $order : $config['general_accounting_info_order'];
142
	if ($order != 'desc' && $order != 'asc')
143
		$order = 'desc';
144
	if ($sortby != '')
145
		$order_attr = ($sortby == 'num') ? 'connnum' : 'conntotduration';
146
	else
147
		$order_attr = 'connnum';
148
	if ($server != '' && $server != 'all'){
149
		$server = da_sql_escape_string($link,$server);
150
		$server_str = "AND nasipaddress = '$server'";
151
	}
152
	else
153
	{
154
		$server_str = "";
155
	}
156
	$login_str = ($login) ? "AND username = '$login' " : '';
157
	$selected[$order] = 'selected';
158
	$selected[$sortby] = 'selected';
159
	$sql_extra_query = '';
160
	if (isset($config['sql_accounting_extra_query'])){
161
		$sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
162
		$sql_extra_query = da_sql_escape_string($link,$sql_extra_query);
163
	}
164
	unset($da_name_cache);
165
	if (isset($_SESSION['da_name_cache']))
166
		$da_name_cache = $_SESSION['da_name_cache'];
167
	$link = @da_sql_pconnect($config);
168
	if ($link){
169
		$num = 0;
170
		$search = @da_sql_query($link,$config,
171
		"SELECT " . da_sql_limit($limit,0,$config) . " * FROM $config[sql_total_accounting_table]
172
		WHERE acctdate >= '$start' AND acctdate <= '$stop' $server_str $login_str $sql_extra_query " . da_sql_limit($limit,1,$config)
173
		. " ORDER BY $order_attr $order " . da_sql_limit($limit,2,$config) . " ;");
174
		if ($search){
175
			while( $row = @da_sql_fetch_array($search,$config) ){
176
				$num++;
177
				$acct_login = $row['username'];
178
				if ($acct_login == '')
324 richard 179
				$acct_login = '-';
2264 richard 180
				else{
181
					$Acct_login = urlencode($acct_login);
182
					$acct_login = "<a href=\"user_admin.php?login=$Acct_login\" title=\"$l_user_edit $acct_login\">$acct_login</a>";
324 richard 183
				}
2264 richard 184
				$acct_time = $row['conntotduration'];
185
				$acct_time = time2str($acct_time);
186
				$acct_conn_num = $row['connnum'];
187
				$acct_date = $row['acctdate'];
188
				$acct_upload = $row['inputoctets'];
189
				$acct_download = $row['outputoctets'];
190
				$acct_upload = bytes2str($acct_upload);
191
				$acct_download = bytes2str($acct_download);
192
				if (!isset($acct_server)){
193
					$acct_server = @gethostbyaddr($row['nasipaddress']);
194
					if (!isset($da_name_cache) && $config['general_use_session'] == 'yes'){
195
						$da_name_cache[$row['nasipaddress']] = $acct_server;
196
						session_register('da_name_cache');
197
					}
324 richard 198
				else
1831 raphael.pi 199
					$da_name_cache[$row['nasipaddress']] = $acct_server;
2264 richard 200
				}
201
				if ($acct_server == '')
324 richard 202
				$acct_server = '-';
2264 richard 203
				echo <<<EOM
324 richard 204
			<tr align=center bgcolor="white">
205
				<td>$num</td>
206
				<td>$acct_login</td>
207
				<td>$acct_date</td>
208
				<td>$acct_server</td>
209
				<td>$acct_conn_num</td>
210
				<td>$acct_time</td>
211
				<td>$acct_upload</td>
212
				<td>$acct_download</td>
213
			</tr>
214
EOM;
2264 richard 215
			}
324 richard 216
		}
217
	}
2264 richard 218
	echo <<<EOM
219
</table>
324 richard 220
<hr>
2854 rexy 221
<table width="100%" border="0" cellspacing="0" cellpadding="0">
1831 raphael.pi 222
EOM;
223
}
224
else
225
{
226
	//create dummy selected
227
	if(!isset($selected))	
228
	{
229
		$selected = array();
230
		$selected[5] = "";
231
		$selected[10] = "";
232
		$selected[15] = "";
233
		$selected[20] = "";
234
		$selected[40] = "";
235
		$selected[80] = "";
236
		$selected['all'] = "";
237
		$selected['num'] = "";
238
		$selected['time'] = "";
239
		$selected['asc'] = "";
240
		$selected['desc'] = "";
241
	}
242
 
243
 
244
}
245
echo <<<EOM
324 richard 246
<tr><td align="left">
2222 richard 247
<form action="user_stats.php" method="post" name="master">
248
		<table border="0">
249
		<tr valign="bottom" align="center">
250
		<td><small><b>$l_start_date</b></small></td><td><small><b>$l_end_date</b></small></td><td><small><b>$l_number_result</b></small></td><td><small><b>$l_order_by</b></small></td><td><small><b>$l_sorted_order</b></small></td></tr>
324 richard 251
	<tr valign="middle"><td>
252
<input type="hidden" name="show" value="0">
253
<input type="text" name="start" size="11" value="$start"></td>
254
<td><input type="text" name="stop" size="11" value="$stop"></td>
255
<td><select name="pagesize">
1831 raphael.pi 256
<option $selected[5] value="5" >5
324 richard 257
<option $selected[10] value="10">10
258
<option $selected[15] value="15">15
259
<option $selected[20] value="20">20
260
<option $selected[40] value="40">40
261
<option $selected[80] value="80">80
2222 richard 262
<option $selected[all] value="all">$l_all
324 richard 263
</select>
264
</td>
265
<td>
266
<select name="sortby">
2222 richard 267
<option $selected[num] value="num">$l_con_number
268
<option $selected[time] value="time">$l_con_length
324 richard 269
</select>
270
</td>
271
<td><select name="order">
2222 richard 272
<option $selected[asc] value="asc">$l_ascending
273
<option $selected[desc] value="desc">$l_descending
324 richard 274
</select>
275
</td>
276
EOM;
277
?>
2222 richard 278
	<td><input type="submit" class=button value="<?php echo "$l_show";?>"></td>
279
</tr>
280
<tr align="center">
281
<td><small><b><?php echo "$l_server";?></b></small></td>
282
<td><small><b><?php echo "$l_user";?></b></small></td>
283
</tr>
324 richard 284
<tr><td>
285
<select name="server">
286
<?php
287
foreach ($nas_list as $nas){
1831 raphael.pi 288
	$name = $nas['name'];
289
	if ($nas['ip'] == '')
324 richard 290
		continue;
2191 tom.houday 291
	$servers[$name] = $nas['ip'];
324 richard 292
}
293
ksort($servers);
294
foreach ($servers as $name => $ip){
2191 tom.houday 295
	if (isset($server) && ($server == $ip))
324 richard 296
		echo "<option selected value=\"$ip\">$name\n";
297
	else
298
		echo "<option value=\"$ip\">$name\n";
299
}
1831 raphael.pi 300
if (isset($server) && ($server == '' || $server == 'all'))
324 richard 301
	echo "<option selected value=\"all\">tous\n";
302
else
303
	echo "<option value=\"all\">tous\n";
304
?>
305
</select>
306
</td>
1831 raphael.pi 307
<td><input type="text" name="login" size="11" value="<?php if(!isset($login)){echo "";}else{ echo $login;} ?>"></td>
324 richard 308
</tr>
309
</table>
2222 richard 310
</form>
311
</td></tr></table>
2854 rexy 312
	</div>
313
</div>
324 richard 314
</body>
315
</html>