Subversion Repositories ALCASAR

Rev

Rev 2222 | Rev 2817 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2222 Rev 2264
Line 1... Line 1...
1
<?php
1
<?php
2
# $Id: user_stats.php 2222 2017-05-14 06:54:33Z richard $
2
# $Id: user_stats.php 2264 2017-06-01 20:58:46Z richard $
3
 
3
 
4
require('/etc/freeradius-web/config.php');
4
require('/etc/freeradius-web/config.php');
5
require('../lib/functions.php');
5
require('../lib/functions.php');
6
require('../lib/sql/nas_list.php');
6
require('../lib/sql/nas_list.php');
7
require_once('../lib/xlat.php');
7
require_once('../lib/xlat.php');
Line 45... Line 45...
45
	$l_server		= "Sur le serveur";
45
	$l_server		= "Sur le serveur";
46
	$l_user			= "Filtrer pour un utilisateur (laissez vide pour tous)";
46
	$l_user			= "Filtrer pour un utilisateur (laissez vide pour tous)";
47
	$l_show			= "Montrer";
47
	$l_show			= "Montrer";
48
	$l_from			= "Du";
48
	$l_from			= "Du";
49
	$l_to			= "au";
49
	$l_to			= "au";
-
 
50
	$l_server		= "Serveur";
-
 
51
	$l_login		= "Identifiant";
-
 
52
	$l_user_edit		= "Éditer l'utilisateur";
50
} else {
53
} else {
51
	$l_title		= "Statistics of users connexions";
54
	$l_title		= "Statistics of users connexions";
52
	$l_start_date		= "Start date";
55
	$l_start_date		= "Start date";
53
	$l_end_date		= "End date";
56
	$l_end_date		= "End date";
54
	$l_number_result	= "Nb results / page";
57
	$l_number_result	= "Nb results / page";
Line 62... Line 65...
62
	$l_server		= "On server";
65
	$l_server		= "On server";
63
	$l_user			= "Filter for a user (let empty for all)";
66
	$l_user			= "Filter for a user (let empty for all)";
64
	$l_show			= "Show";
67
	$l_show			= "Show";
65
	$l_from			= "From";
68
	$l_from			= "From";
66
	$l_to			= "to";
69
	$l_to			= "to";
-
 
70
	$l_server		= "Server";
-
 
71
	$l_login		= "Login";
-
 
72
	$l_user_edit		= "Edit user";
67
}
73
}
68
if (!isset($start) && !isset($stop)){
74
if (!isset($start) && !isset($stop)){
69
	$now = time();
75
	$now = time();
70
	$stop = date($config['sql_date_format'],$now);
76
	$stop = date($config['sql_date_format'],$now);
71
	$now -= 604800;
77
	$now -= 604800;
Line 88... Line 94...
88
</table>
94
</table>
89
<table width="100%" border="1" cellspacing="0" cellpadding="0">
95
<table width="100%" border="1" cellspacing="0" cellpadding="0">
90
<?php
96
<?php
91
if(isset($pagesize))
97
if(isset($pagesize))
92
{	
98
{	
93
echo <<<EOM
99
	echo <<<EOM
94
<tr align="center"><td colspan="9">
100
<tr align="center"><td colspan="9">
95
$l_from $start $l_to $stop
101
$l_from $start $l_to $stop
96
</td></tr>
102
</td></tr>
97
<tr>
103
<tr>
98
<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>
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>
99
</tr>
105
</tr>
100
EOM;
106
EOM;
101
 
-
 
102
$pagesize = ($pagesize) ? $pagesize : 10;
107
	$pagesize = ($pagesize) ? $pagesize : 10;
103
 
-
 
104
 
-
 
105
$selected[5] = "";
108
	$selected[5] = "";
106
$selected[10] = "";
109
	$selected[10] = "";
107
$selected[15] = "";
110
	$selected[15] = "";
108
$selected[20] = "";
111
	$selected[20] = "";
109
$selected[40] = "";
112
	$selected[40] = "";
110
$selected[80] = "";
113
	$selected[80] = "";
111
$selected['all'] = "";
114
	$selected['all'] = "";
112
$selected['num'] = "";
115
	$selected['num'] = "";
113
$selected['time'] = "";
116
	$selected['time'] = "";
114
$selected['asc'] = "";
117
	$selected['asc'] = "";
115
$selected['desc'] = "";
118
	$selected['desc'] = "";
116
 
-
 
117
if (!is_numeric($pagesize) && $pagesize != 'all')
119
	if (!is_numeric($pagesize) && $pagesize != 'all')
118
	$pagezise = 10;
120
		$pagezise = 10;
119
if ($pagesize > 100)
121
	if ($pagesize > 100)
120
	$pagesize = 100;
122
		$pagesize = 100;
121
$limit = ($pagesize == 'all') ? '100' : "$pagesize";
123
	$limit = ($pagesize == 'all') ? '100' : "$pagesize";
122
$selected[$pagesize] = 'selected';
124
	$selected[$pagesize] = 'selected';
123
$order = ($order) ? $order : $config['general_accounting_info_order'];
125
	$order = ($order) ? $order : $config['general_accounting_info_order'];
124
if ($order != 'desc' && $order != 'asc')
126
	if ($order != 'desc' && $order != 'asc')
125
	$order = 'desc';
127
		$order = 'desc';
126
if ($sortby != '')
128
	if ($sortby != '')
127
	$order_attr = ($sortby == 'num') ? 'connnum' : 'conntotduration';
129
		$order_attr = ($sortby == 'num') ? 'connnum' : 'conntotduration';
128
else
130
	else
129
	$order_attr = 'connnum';
131
		$order_attr = 'connnum';
130
if ($server != '' && $server != 'all'){
132
	if ($server != '' && $server != 'all'){
131
	$server = da_sql_escape_string($link,$server);
133
		$server = da_sql_escape_string($link,$server);
132
	$server_str = "AND nasipaddress = '$server'";
134
		$server_str = "AND nasipaddress = '$server'";
133
}
135
	}
134
else
136
	else
135
{
137
	{
136
	$server_str = "";
138
		$server_str = "";
137
}
139
	}
138
$login_str = ($login) ? "AND username = '$login' " : '';
140
	$login_str = ($login) ? "AND username = '$login' " : '';
139
 
-
 
140
$selected[$order] = 'selected';
141
	$selected[$order] = 'selected';
141
$selected[$sortby] = 'selected';
142
	$selected[$sortby] = 'selected';
142
 
-
 
143
$sql_extra_query = '';
143
	$sql_extra_query = '';
144
if (isset($config['sql_accounting_extra_query'])){
144
	if (isset($config['sql_accounting_extra_query'])){
145
	$sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
145
		$sql_extra_query = xlat($config['sql_accounting_extra_query'],$login,$config);
146
	$sql_extra_query = da_sql_escape_string($link,$sql_extra_query);
146
		$sql_extra_query = da_sql_escape_string($link,$sql_extra_query);
147
}
147
	}
148
 
-
 
149
unset($da_name_cache);
148
	unset($da_name_cache);
150
if (isset($_SESSION['da_name_cache']))
149
	if (isset($_SESSION['da_name_cache']))
151
	$da_name_cache = $_SESSION['da_name_cache'];
150
		$da_name_cache = $_SESSION['da_name_cache'];
152
 
-
 
153
 
-
 
154
 
-
 
155
 
-
 
156
$link = @da_sql_pconnect($config);
151
	$link = @da_sql_pconnect($config);
157
if ($link){
152
	if ($link){
158
	$num = 0;
153
		$num = 0;
159
	$search = @da_sql_query($link,$config,
154
		$search = @da_sql_query($link,$config,
160
	"SELECT " . da_sql_limit($limit,0,$config) . " * FROM $config[sql_total_accounting_table]
155
		"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)
156
		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) . " ;");
157
		. " ORDER BY $order_attr $order " . da_sql_limit($limit,2,$config) . " ;");
163
 
-
 
164
	if ($search){
158
		if ($search){
165
		while( $row = @da_sql_fetch_array($search,$config) ){
159
			while( $row = @da_sql_fetch_array($search,$config) ){
166
			$num++;
160
				$num++;
167
			$acct_login = $row['username'];
161
				$acct_login = $row['username'];
168
			if ($acct_login == '')
162
				if ($acct_login == '')
169
				$acct_login = '-';
163
				$acct_login = '-';
170
			else{
164
				else{
171
				$Acct_login = urlencode($acct_login);
165
					$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>";
166
					$acct_login = "<a href=\"user_admin.php?login=$Acct_login\" title=\"$l_user_edit $acct_login\">$acct_login</a>";
173
			}
-
 
174
			$acct_time = $row['conntotduration'];
-
 
175
			$acct_time = time2str($acct_time);
-
 
176
			$acct_conn_num = $row['connnum'];
-
 
177
			$acct_date = $row['acctdate'];
-
 
178
			$acct_upload = $row['inputoctets'];
-
 
179
			$acct_download = $row['outputoctets'];
-
 
180
			$acct_upload = bytes2str($acct_upload);
-
 
181
			$acct_download = bytes2str($acct_download);
-
 
182
			if (!isset($acct_server)){
-
 
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;
-
 
186
					session_register('da_name_cache');
-
 
187
				}
167
				}
-
 
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
					}
188
				else
182
				else
189
					$da_name_cache[$row['nasipaddress']] = $acct_server;
183
					$da_name_cache[$row['nasipaddress']] = $acct_server;
190
			}
184
				}
191
			if ($acct_server == '')
185
				if ($acct_server == '')
192
				$acct_server = '-';
186
				$acct_server = '-';
193
			echo <<<EOM
187
				echo <<<EOM
194
			<tr align=center bgcolor="white">
188
			<tr align=center bgcolor="white">
195
				<td>$num</td>
189
				<td>$num</td>
196
				<td>$acct_login</td>
190
				<td>$acct_login</td>
197
				<td>$acct_date</td>
191
				<td>$acct_date</td>
198
				<td>$acct_server</td>
192
				<td>$acct_server</td>
199
				<td>$acct_conn_num</td>
193
				<td>$acct_conn_num</td>
200
				<td>$acct_time</td>
194
				<td>$acct_time</td>
201
				<td>$acct_upload</td>
195
				<td>$acct_upload</td>
202
				<td>$acct_download</td>
196
				<td>$acct_download</td>
203
				<td>$acct_server</td>
-
 
204
 
-
 
205
			</tr>
197
			</tr>
206
EOM;
198
EOM;
-
 
199
			}
207
		}
200
		}
208
	}
201
	}
209
 
-
 
210
}
-
 
211
echo <<<EOM
202
	echo <<<EOM
212
	</table>
203
</table>
213
<tr><td>
-
 
214
<hr>
204
<hr>
-
 
205
<table width="100%" border="1" cellspacing="0" cellpadding="0">
215
EOM;
206
EOM;
216
}
207
}
217
else
208
else
218
{
209
{
219
	//create dummy selected
210
	//create dummy selected