Subversion Repositories ALCASAR

Rev

Rev 2264 | Rev 2854 | 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 2817 2020-05-09 09:35:56Z 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
?>
2222 richard 9
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
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";
2222 richard 53
} else {
54
	$l_title		= "Statistics of users connexions";
55
	$l_start_date		= "Start date";
56
	$l_end_date		= "End date";
57
	$l_number_result	= "Nb results / page";
58
	$l_order_by		= "Sorted by";
59
	$l_sorted_order		= "Sorted order";
60
	$l_all			= "All";
61
	$l_con_number		= "Connections number";
62
	$l_con_length		= "Connection length";
63
	$l_ascending		= "Ascending";
64
	$l_descending		= "Descending";
65
	$l_server		= "On server";
66
	$l_user			= "Filter for a user (let empty for all)";
67
	$l_show			= "Show";
68
	$l_from			= "From";
69
	$l_to			= "to";
2264 richard 70
	$l_server		= "Server";
71
	$l_login		= "Login";
72
	$l_user_edit		= "Edit user";
2222 richard 73
}
1831 raphael.pi 74
if (!isset($start) && !isset($stop)){
324 richard 75
	$now = time();
1831 raphael.pi 76
	$stop = date($config['sql_date_format'],$now);
324 richard 77
	$now -= 604800;
1831 raphael.pi 78
	$start = date($config['sql_date_format'],$now);
324 richard 79
}
1831 raphael.pi 80
$start = da_sql_escape_string($link,$start);
81
$stop = da_sql_escape_string($link,$stop);
324 richard 82
?>
83
<head>
2222 richard 84
<title><?php echo "$l_title";?></title>
2817 rexy 85
<link rel="stylesheet" href="/css/acc.css" type="text/css">
324 richard 86
</head>
87
<body>
88
<center>
1956 raphael.pi 89
<table width="100%" border="0" cellspacing="0" cellpadding="0">
2222 richard 90
	<tr><th>
91
	<font color="white"><?echo "$l_title";?></font>
92
	</th></tr>
1956 raphael.pi 93
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
94
</table>
2222 richard 95
<table width="100%" border="1" cellspacing="0" cellpadding="0">
324 richard 96
<?php
1831 raphael.pi 97
if(isset($pagesize))
98
{	
2264 richard 99
	echo <<<EOM
2222 richard 100
<tr align="center"><td colspan="9">
101
$l_from $start $l_to $stop
102
</td></tr>
103
<tr>
2264 richard 104
<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 105
</tr>
1831 raphael.pi 106
EOM;
2264 richard 107
	$pagesize = ($pagesize) ? $pagesize : 10;
108
	$selected[5] = "";
109
	$selected[10] = "";
110
	$selected[15] = "";
111
	$selected[20] = "";
112
	$selected[40] = "";
113
	$selected[80] = "";
114
	$selected['all'] = "";
115
	$selected['num'] = "";
116
	$selected['time'] = "";
117
	$selected['asc'] = "";
118
	$selected['desc'] = "";
119
	if (!is_numeric($pagesize) && $pagesize != 'all')
120
		$pagezise = 10;
121
	if ($pagesize > 100)
122
		$pagesize = 100;
123
	$limit = ($pagesize == 'all') ? '100' : "$pagesize";
124
	$selected[$pagesize] = 'selected';
125
	$order = ($order) ? $order : $config['general_accounting_info_order'];
126
	if ($order != 'desc' && $order != 'asc')
127
		$order = 'desc';
128
	if ($sortby != '')
129
		$order_attr = ($sortby == 'num') ? 'connnum' : 'conntotduration';
130
	else
131
		$order_attr = 'connnum';
132
	if ($server != '' && $server != 'all'){
133
		$server = da_sql_escape_string($link,$server);
134
		$server_str = "AND nasipaddress = '$server'";
135
	}
136
	else
137
	{
138
		$server_str = "";
139
	}
140
	$login_str = ($login) ? "AND username = '$login' " : '';
141
	$selected[$order] = 'selected';
142
	$selected[$sortby] = 'selected';
143
	$sql_extra_query = '';
144
	if (isset($config['sql_accounting_extra_query'])){
145
		$sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
146
		$sql_extra_query = da_sql_escape_string($link,$sql_extra_query);
147
	}
148
	unset($da_name_cache);
149
	if (isset($_SESSION['da_name_cache']))
150
		$da_name_cache = $_SESSION['da_name_cache'];
151
	$link = @da_sql_pconnect($config);
152
	if ($link){
153
		$num = 0;
154
		$search = @da_sql_query($link,$config,
155
		"SELECT " . da_sql_limit($limit,0,$config) . " * FROM $config[sql_total_accounting_table]
156
		WHERE acctdate >= '$start' AND acctdate <= '$stop' $server_str $login_str $sql_extra_query " . da_sql_limit($limit,1,$config)
157
		. " ORDER BY $order_attr $order " . da_sql_limit($limit,2,$config) . " ;");
158
		if ($search){
159
			while( $row = @da_sql_fetch_array($search,$config) ){
160
				$num++;
161
				$acct_login = $row['username'];
162
				if ($acct_login == '')
324 richard 163
				$acct_login = '-';
2264 richard 164
				else{
165
					$Acct_login = urlencode($acct_login);
166
					$acct_login = "<a href=\"user_admin.php?login=$Acct_login\" title=\"$l_user_edit $acct_login\">$acct_login</a>";
324 richard 167
				}
2264 richard 168
				$acct_time = $row['conntotduration'];
169
				$acct_time = time2str($acct_time);
170
				$acct_conn_num = $row['connnum'];
171
				$acct_date = $row['acctdate'];
172
				$acct_upload = $row['inputoctets'];
173
				$acct_download = $row['outputoctets'];
174
				$acct_upload = bytes2str($acct_upload);
175
				$acct_download = bytes2str($acct_download);
176
				if (!isset($acct_server)){
177
					$acct_server = @gethostbyaddr($row['nasipaddress']);
178
					if (!isset($da_name_cache) && $config['general_use_session'] == 'yes'){
179
						$da_name_cache[$row['nasipaddress']] = $acct_server;
180
						session_register('da_name_cache');
181
					}
324 richard 182
				else
1831 raphael.pi 183
					$da_name_cache[$row['nasipaddress']] = $acct_server;
2264 richard 184
				}
185
				if ($acct_server == '')
324 richard 186
				$acct_server = '-';
2264 richard 187
				echo <<<EOM
324 richard 188
			<tr align=center bgcolor="white">
189
				<td>$num</td>
190
				<td>$acct_login</td>
191
				<td>$acct_date</td>
192
				<td>$acct_server</td>
193
				<td>$acct_conn_num</td>
194
				<td>$acct_time</td>
195
				<td>$acct_upload</td>
196
				<td>$acct_download</td>
197
			</tr>
198
EOM;
2264 richard 199
			}
324 richard 200
		}
201
	}
2264 richard 202
	echo <<<EOM
203
</table>
324 richard 204
<hr>
2264 richard 205
<table width="100%" border="1" cellspacing="0" cellpadding="0">
1831 raphael.pi 206
EOM;
207
}
208
else
209
{
210
	//create dummy selected
211
	if(!isset($selected))	
212
	{
213
		$selected = array();
214
		$selected[5] = "";
215
		$selected[10] = "";
216
		$selected[15] = "";
217
		$selected[20] = "";
218
		$selected[40] = "";
219
		$selected[80] = "";
220
		$selected['all'] = "";
221
		$selected['num'] = "";
222
		$selected['time'] = "";
223
		$selected['asc'] = "";
224
		$selected['desc'] = "";
225
	}
226
 
227
 
228
}
229
echo <<<EOM
324 richard 230
<tr><td align="left">
2222 richard 231
<form action="user_stats.php" method="post" name="master">
232
		<table border="0">
233
		<tr valign="bottom" align="center">
234
		<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 235
	<tr valign="middle"><td>
236
<input type="hidden" name="show" value="0">
237
<input type="text" name="start" size="11" value="$start"></td>
238
<td><input type="text" name="stop" size="11" value="$stop"></td>
239
<td><select name="pagesize">
1831 raphael.pi 240
<option $selected[5] value="5" >5
324 richard 241
<option $selected[10] value="10">10
242
<option $selected[15] value="15">15
243
<option $selected[20] value="20">20
244
<option $selected[40] value="40">40
245
<option $selected[80] value="80">80
2222 richard 246
<option $selected[all] value="all">$l_all
324 richard 247
</select>
248
</td>
249
<td>
250
<select name="sortby">
2222 richard 251
<option $selected[num] value="num">$l_con_number
252
<option $selected[time] value="time">$l_con_length
324 richard 253
</select>
254
</td>
255
<td><select name="order">
2222 richard 256
<option $selected[asc] value="asc">$l_ascending
257
<option $selected[desc] value="desc">$l_descending
324 richard 258
</select>
259
</td>
260
EOM;
261
?>
2222 richard 262
	<td><input type="submit" class=button value="<?php echo "$l_show";?>"></td>
263
</tr>
264
<tr align="center">
265
<td><small><b><?php echo "$l_server";?></b></small></td>
266
<td><small><b><?php echo "$l_user";?></b></small></td>
267
</tr>
324 richard 268
<tr><td>
269
<select name="server">
270
<?php
271
foreach ($nas_list as $nas){
1831 raphael.pi 272
	$name = $nas['name'];
273
	if ($nas['ip'] == '')
324 richard 274
		continue;
2191 tom.houday 275
	$servers[$name] = $nas['ip'];
324 richard 276
}
277
ksort($servers);
278
foreach ($servers as $name => $ip){
2191 tom.houday 279
	if (isset($server) && ($server == $ip))
324 richard 280
		echo "<option selected value=\"$ip\">$name\n";
281
	else
282
		echo "<option value=\"$ip\">$name\n";
283
}
1831 raphael.pi 284
if (isset($server) && ($server == '' || $server == 'all'))
324 richard 285
	echo "<option selected value=\"all\">tous\n";
286
else
287
	echo "<option value=\"all\">tous\n";
288
?>
289
</select>
290
</td>
1831 raphael.pi 291
<td><input type="text" name="login" size="11" value="<?php if(!isset($login)){echo "";}else{ echo $login;} ?>"></td>
324 richard 292
</tr>
293
</table>
2222 richard 294
</form>
295
</td></tr></table>
324 richard 296
</body>
297
</html>