Subversion Repositories ALCASAR

Rev

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