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