Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
324 richard 1
<?php
2
require('/etc/freeradius-web/config.php');
3
require('../lib/functions.php');
4
require('../lib/sql/nas_list.php');
5
require_once('../lib/xlat.php');
6
?>
7
<html>
8
<?php
9
 
10
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
11
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
12
else{
13
	echo <<<EOM
14
<title>Statistiques utilisateurs</title>
15
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
16
<link rel="stylesheet" href="style.css">
17
</head>
18
<body>
19
<center>
20
<b>Could not include SQL library functions. Aborting</b>
21
</body>
22
</html>
23
EOM;
24
	exit();
25
}
26
 
1831 raphael.pi 27
if (!isset($start) && !isset($stop)){
28
//if($start == '' && $stop == ''){
324 richard 29
	$now = time();
1831 raphael.pi 30
	$stop = date($config['sql_date_format'],$now);
324 richard 31
	$now -= 604800;
1831 raphael.pi 32
	$start = date($config['sql_date_format'],$now);
324 richard 33
}
1831 raphael.pi 34
$start = da_sql_escape_string($link,$start);
35
$stop = da_sql_escape_string($link,$stop);
324 richard 36
 
37
 
38
?>
39
 
40
<head>
41
<title>Statistiques utilisateurs</title>
42
<link rel="stylesheet" href="style.css">
43
</head>
44
<body>
45
<center>
46
<table border=0 width=550 cellpadding=0 cellspacing=0>
47
<tr valign=top>
48
<!--<td align=center><img src="images/title2.gif"></td>-->
49
</tr>
50
</table>
51
<table border=0 width=400 cellpadding=0 cellspacing=2>
52
</table>
53
<br>
54
<table border=0 width=840 cellpadding=1 cellspacing=1>
55
<tr valign=top>
56
<td width=65%></td>
57
<td bgcolor="black" width=35%>
58
	<table border=0 width=100% cellpadding=2 cellspacing=0>
59
	<tr bgcolor="#907030" align=right valign=top><th>
60
	<font color="white">Statistiques utilisateurs</font>&nbsp;
61
	</th></tr>
62
	</table>
63
</td></tr>
64
<tr bgcolor="black" valign=top><td colspan=2>
65
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
66
	<tr><td>
67
<?php
1831 raphael.pi 68
if(isset($pagesize))
69
{	
324 richard 70
echo <<<EOM
71
De <b>$start</b> &agrave;  <b>$stop</b>
72
 
73
<p>
74
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
75
	<tr bgcolor="#d0ddb0">
1831 raphael.pi 76
	<th>#</th><th>Identifiant</th><th>Date</th><th>Serveur</th><th>Nombres de connections</th><th>Dur&eacute;e des connections</th><th>Upload</th><th>Download</th><th>Serveur</th>
324 richard 77
	</tr>
1831 raphael.pi 78
EOM;
324 richard 79
 
1831 raphael.pi 80
$pagesize = ($pagesize) ? $pagesize : 10;
81
 
82
 
83
$selected[5] = "";
84
$selected[10] = "";
85
$selected[15] = "";
86
$selected[20] = "";
87
$selected[40] = "";
88
$selected[80] = "";
89
$selected['all'] = "";
90
$selected['num'] = "";
91
$selected['time'] = "";
92
$selected['asc'] = "";
93
$selected['desc'] = "";
94
 
95
if (!is_numeric($pagesize) && $pagesize != 'all')
96
	$pagezise = 10;
97
if ($pagesize > 100)
98
	$pagesize = 100;
99
$limit = ($pagesize == 'all') ? '100' : "$pagesize";
100
$selected[$pagesize] = 'selected';
101
$order = ($order) ? $order : $config['general_accounting_info_order'];
102
if ($order != 'desc' && $order != 'asc')
103
	$order = 'desc';
104
if ($sortby != '')
105
	$order_attr = ($sortby == 'num') ? 'connnum' : 'conntotduration';
106
else
107
	$order_attr = 'connnum';
108
if ($server != '' && $server != 'all'){
109
	$server = da_sql_escape_string($link,$server);
110
	$server_str = "AND nasipaddress = '$server'";
111
}
112
else
113
{
114
	$server_str = "";
115
}
116
$login_str = ($login) ? "AND username = '$login' " : '';
117
 
118
$selected[$order] = 'selected';
119
$selected[$sortby] = 'selected';
120
 
121
$sql_extra_query = '';
122
if (isset($config['sql_accounting_extra_query'])){
123
	$sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
124
	$sql_extra_query = da_sql_escape_string($link,$sql_extra_query);
125
}
126
 
127
unset($da_name_cache);
128
if (isset($_SESSION['da_name_cache']))
129
	$da_name_cache = $_SESSION['da_name_cache'];
130
 
131
 
132
 
133
 
324 richard 134
$link = @da_sql_pconnect($config);
135
if ($link){
1831 raphael.pi 136
	$num = 0;
324 richard 137
	$search = @da_sql_query($link,$config,
138
	"SELECT " . da_sql_limit($limit,0,$config) . " * FROM $config[sql_total_accounting_table]
139
	WHERE acctdate >= '$start' AND acctdate <= '$stop' $server_str $login_str $sql_extra_query " . da_sql_limit($limit,1,$config)
140
	. " ORDER BY $order_attr $order " . da_sql_limit($limit,2,$config) . " ;");
141
 
142
	if ($search){
143
		while( $row = @da_sql_fetch_array($search,$config) ){
144
			$num++;
1831 raphael.pi 145
			$acct_login = $row['username'];
324 richard 146
			if ($acct_login == '')
147
				$acct_login = '-';
148
			else{
149
				$Acct_login = urlencode($acct_login);
150
				$acct_login = "<a href=\"user_admin.php?login=$Acct_login\" title=\"Editer l'utilisateur $acct_login\">$acct_login</a>";
151
			}
1831 raphael.pi 152
			$acct_time = $row['conntotduration'];
324 richard 153
			$acct_time = time2str($acct_time);
1831 raphael.pi 154
			$acct_conn_num = $row['connnum'];
155
			$acct_date = $row['acctdate'];
156
			$acct_upload = $row['inputoctets'];
157
			$acct_download = $row['outputoctets'];
324 richard 158
			$acct_upload = bytes2str($acct_upload);
159
			$acct_download = bytes2str($acct_download);
160
			if (!isset($acct_server)){
1831 raphael.pi 161
				$acct_server = @gethostbyaddr($row['nasipaddress']);
162
				if (!isset($da_name_cache) && $config['general_use_session'] == 'yes'){
163
					$da_name_cache[$row['nasipaddress']] = $acct_server;
324 richard 164
					session_register('da_name_cache');
165
				}
166
				else
1831 raphael.pi 167
					$da_name_cache[$row['nasipaddress']] = $acct_server;
324 richard 168
			}
169
			if ($acct_server == '')
170
				$acct_server = '-';
171
			echo <<<EOM
172
			<tr align=center bgcolor="white">
173
				<td>$num</td>
174
				<td>$acct_login</td>
175
				<td>$acct_date</td>
176
				<td>$acct_server</td>
177
				<td>$acct_conn_num</td>
178
				<td>$acct_time</td>
179
				<td>$acct_upload</td>
180
				<td>$acct_download</td>
1831 raphael.pi 181
				<td>$acct_server</td>
182
 
324 richard 183
			</tr>
184
EOM;
185
		}
186
	}
1831 raphael.pi 187
 
324 richard 188
}
189
echo <<<EOM
190
	</table>
191
<tr><td>
192
<hr>
1831 raphael.pi 193
EOM;
194
}
195
else
196
{
197
	//create dummy selected
198
	if(!isset($selected))	
199
	{
200
		$selected = array();
201
		$selected[5] = "";
202
		$selected[10] = "";
203
		$selected[15] = "";
204
		$selected[20] = "";
205
		$selected[40] = "";
206
		$selected[80] = "";
207
		$selected['all'] = "";
208
		$selected['num'] = "";
209
		$selected['time'] = "";
210
		$selected['asc'] = "";
211
		$selected['desc'] = "";
212
	}
213
 
214
 
215
}
216
echo <<<EOM
324 richard 217
<tr><td align="left">
218
	<form action="user_stats.php" method="post" name="master">
219
	<table border=0>
220
		<tr valign="bottom">
221
			<td><small><b>date d&eacute;but</td><td><small><b>date fin</td><td><small><b>nbr./page</td><td><small><b>tri&eacute; par</td><td><small><b>class&eacute; par ordre </td>
222
	<tr valign="middle"><td>
223
<input type="hidden" name="show" value="0">
224
<input type="text" name="start" size="11" value="$start"></td>
225
<td><input type="text" name="stop" size="11" value="$stop"></td>
226
<td><select name="pagesize">
1831 raphael.pi 227
 
228
<option $selected[5] value="5" >5
324 richard 229
<option $selected[10] value="10">10
230
<option $selected[15] value="15">15
231
<option $selected[20] value="20">20
232
<option $selected[40] value="40">40
233
<option $selected[80] value="80">80
234
<option $selected[all] value="all">tous
235
</select>
236
</td>
237
<td>
238
<select name="sortby">
239
<option $selected[num] value="num">Nombre de connexions
240
<option $selected[time] value="time">Dur&eacute;e des connexions
241
</select>
242
</td>
243
<td><select name="order">
244
<option $selected[asc] value="asc">croissant
245
<option $selected[desc] value="desc">d&eacute;croissant
246
</select>
247
</td>
248
EOM;
1831 raphael.pi 249
 
324 richard 250
?>
251
 
252
<td><input type="submit" class=button value="show"></td></tr>
253
<tr><td>
254
<b>Sur le serveur d'acc&egrave;s :</b>
255
</td>
256
<td><b>Utilisateur</b></td></tr>
257
<tr><td>
258
<select name="server">
259
<?php
260
foreach ($nas_list as $nas){
1831 raphael.pi 261
	$name = $nas['name'];
262
	if ($nas['ip'] == '')
324 richard 263
		continue;
264
	$servers[$name] = $nas[ip];
265
}
266
ksort($servers);
267
foreach ($servers as $name => $ip){
268
	if ($server == $ip)
269
		echo "<option selected value=\"$ip\">$name\n";
270
	else
271
		echo "<option value=\"$ip\">$name\n";
272
}
1831 raphael.pi 273
if (isset($server) && ($server == '' || $server == 'all'))
324 richard 274
	echo "<option selected value=\"all\">tous\n";
275
else
276
	echo "<option value=\"all\">tous\n";
277
?>
278
</select>
279
</td>
1831 raphael.pi 280
<td><input type="text" name="login" size="11" value="<?php if(!isset($login)){echo "";}else{ echo $login;} ?>"></td>
324 richard 281
</tr>
282
</table></td></tr></form>
283
</table>
284
</tr>
285
</table>
286
</body>
287
</html>