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