Subversion Repositories ALCASAR

Rev

Rev 910 | Rev 925 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 910 Rev 911
1
<?php
1
<?php
2
//gestion de la langue
2
//gestion de la langue
3
$origine='user_accounting';
-
 
4
if (is_file("../lib/langues.php"))
3
if (is_file("../lib/langues.php"))
5
	include("../lib/langues.php");
4
	include("../lib/langues.php");
6
require('/etc/freeradius-web/config.php');
5
require('/etc/freeradius-web/config.php');
7
require('../lib/functions.php');
6
require('../lib/functions.php');
8
require('../lib/sql/functions.php');
7
require('../lib/sql/functions.php');
9
require('../lib/attrshow.php');
8
require('../lib/attrshow.php');
10
if (is_file("../lib/$config[general_lib_type]/user_info.php"))
9
if (is_file("../lib/$config[general_lib_type]/user_info.php"))
11
	include("../lib/$config[general_lib_type]/user_info.php");
10
	include("../lib/$config[general_lib_type]/user_info.php");
12
 
11
 
13
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
12
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
14
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
13
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
15
else{
14
else{
16
	echo <<<EOM
15
	echo <<<EOM
17
<html>
16
<html>
18
<head>
17
<head>
19
<title>$l_title</title>
18
<title>User accounting</title>
20
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
19
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
21
<link rel="stylesheet" href="/css/style.css">
20
<link rel="stylesheet" href="/css/style.css">
22
</head>
21
</head>
23
<body>
22
<body>
24
<center>
23
<center>
25
<b>Could not include SQL library functions. Aborting</b>
24
<b>Could not include SQL library functions. Aborting</b>
26
</body>
25
</body>
27
</html>
26
</html>
28
EOM;
27
EOM;
29
	exit();
28
	exit();
30
}
29
}
31
 
30
 
32
$now = time();
31
$now = time();
33
$now_str = ($now_str != '') ? "$now_str" : date($config[sql_date_format],$now + 86400);
32
$now_str = ($now_str != '') ? "$now_str" : date($config[sql_date_format],$now + 86400);
34
$prev_str = ($prev_str != '') ? "$prev_str" : date($config[sql_date_format], $now - 604800 );
33
$prev_str = ($prev_str != '') ? "$prev_str" : date($config[sql_date_format], $now - 604800 );
35
$num = 0;
34
$num = 0;
36
$pagesize = ($pagesize) ? $pagesize : 10;
35
$pagesize = ($pagesize) ? $pagesize : 10;
37
if (!is_numeric($pagesize) && $pagesize != 'all')
36
if (!is_numeric($pagesize) && $pagesize != 'all')
38
	$pagesize = 10;
37
	$pagesize = 10;
39
$limit = ($pagesize == 'all') ? '' : "$pagesize";
38
$limit = ($pagesize == 'all') ? '' : "$pagesize";
40
$selected[$pagesize] = 'selected';
39
$selected[$pagesize] = 'selected';
41
$order = ($order != '') ? $order : $config[general_accounting_info_order];
40
$order = ($order != '') ? $order : $config[general_accounting_info_order];
42
if ($order != 'desc' && $order != 'asc')
41
if ($order != 'desc' && $order != 'asc')
43
	$order = 'desc';
42
	$order = 'desc';
44
$selected[$order] = 'selected';
43
$selected[$order] = 'selected';
45
$now_str = mysql_escape_string($now_str);
44
$now_str = mysql_escape_string($now_str);
46
$prev_str = mysql_escape_string($prev_str);
45
$prev_str = mysql_escape_string($prev_str);
47
//$now_str = da_sql_escape_string($now_str);
46
//$now_str = da_sql_escape_string($now_str);
48
//$prev_str = da_sql_escape_string($prev_str);
47
//$prev_str = da_sql_escape_string($prev_str);
49
 
48
 
50
unset($da_name_cache);
49
unset($da_name_cache);
51
if (isset($_SESSION['da_name_cache']))
50
if (isset($_SESSION['da_name_cache']))
52
	$da_name_cache = $_SESSION['da_name_cache'];
51
	$da_name_cache = $_SESSION['da_name_cache'];
53
 
52
 
54
 
53
 
55
echo <<<EOM
54
echo <<<EOM
56
<html>
55
<html>
57
<head>
56
<head>
58
<title>i$l_title</title>
57
<title>iUser accounting</title>
59
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
58
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
60
<link rel="stylesheet" href="/css/style.css">
59
<link rel="stylesheet" href="/css/style.css">
61
</head>
60
</head>
62
<body>
61
<body>
63
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
62
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
64
<tr><th>$l_frame_top</th></tr>
63
<tr><th>$l_users_managment</th></tr>
65
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" 
64
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" 
66
height="2"></td></tr>
65
height="2"></td></tr>
67
</TABLE>
66
</TABLE>
68
<TABLE width="100%" border=0 cellspacing=0 cellpadding=1>
67
<TABLE width="100%" border=0 cellspacing=0 cellpadding=1>
69
<tr bgcolor="#666666"><td>
68
<tr bgcolor="#666666"><td>
70
<TABLE width="100%" border=0 cellspacing=0 cellpadding=2>
69
<TABLE width="100%" border=0 cellspacing=0 cellpadding=2>
71
<tr><td valign="middle" align="left">
70
<tr><td valign="middle" align="left">
72
<center>
71
<center>
73
<table border=0 width=400 cellpadding=0 cellspacing=2>
72
<table border=0 width=400 cellpadding=0 cellspacing=2>
74
EOM;
73
EOM;
75
 
74
 
76
include("../html/user_toolbar.html.php");
75
include("../html/user_toolbar.html.php");
77
 
76
 
78
print <<<EOM
77
print <<<EOM
79
</table>
78
</table>
80
<br>
79
<br>
81
<table border=0 width=840 cellpadding=1 cellspacing=1>
80
<table border=0 width=840 cellpadding=1 cellspacing=1>
82
<tr valign=top>
81
<tr valign=top>
83
<td width=65%></td>
82
<td width=65%></td>
84
<td bgcolor="black" width=35%>
83
<td bgcolor="black" width=35%>
85
	<table border=0 width=100% cellpadding=2 cellspacing=0>
84
	<table border=0 width=100% cellpadding=2 cellspacing=0>
86
	<tr bgcolor="#907030" align=right valign=top><th>
85
	<tr bgcolor="#907030" align=right valign=top><th>
87
	<font color="white">$l_user : $login ($cn)</font>
86
	<font color="white">$l_user : $login ($cn)</font>
88
	</th></tr>
87
	</th></tr>
89
	</table>
88
	</table>
90
</td></tr>
89
</td></tr>
91
<tr bgcolor="black" valign=top><td colspan=2>
90
<tr bgcolor="black" valign=top><td colspan=2>
92
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
91
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#ffffd0" valign=top>
93
	<tr><td>
92
	<tr><td>
94
Dates : <b>$prev_str</b> to <b>$now_str</b>
93
Dates : <b>$prev_str</b> to <b>$now_str</b>
95
EOM;
94
EOM;
96
?>
95
?>
97
<p>
96
<p>
98
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
97
	<table border=1 bordercolordark=#ffffe0 bordercolorlight=#000000 width=100% cellpadding=2 cellspacing=0 bgcolor="#ffffe0" valign=top>
99
	<tr bgcolor="#d0ddb0">
98
	<tr bgcolor="#d0ddb0">
100
	<td><b>#</b></td>
99
	<td><b>#</b></td>
101
<?php
100
<?php
102
for($i=1;$i<=9;$i++){
101
for($i=1;$i<=9;$i++){
103
	if (($acct_attrs['ua']["$i"] != '') && ($acct_attrs['ua']["$i"] != 'server') && ($acct_attrs['ua']["$i"] != 'callerid'))
102
	if (($acct_attrs['ua']["$i"] != '') && ($acct_attrs['ua']["$i"] != 'server') && ($acct_attrs['ua']["$i"] != 'callerid'))
104
		echo "<td><b>" . $acct_attrs['ua']["$i"] . "</b></td>\n";
103
		echo "<td><b>" . $acct_attrs['ua']["$i"] . "</b></td>\n";
105
}
104
}
106
$sql_extra_query = '';
105
$sql_extra_query = '';
107
if ($config[sql_accounting_extra_query] != '')
106
if ($config[sql_accounting_extra_query] != '')
108
	$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
107
	$sql_extra_query = xlat($config[sql_accounting_extra_query],$login,$config);
109
?>
108
?>
110
	</tr>
109
	</tr>
111
 
110
 
112
<?php
111
<?php
113
$link = @da_sql_pconnect($config);
112
$link = @da_sql_pconnect($config);
114
if ($link){
113
if ($link){
115
	$search = @da_sql_query($link,$config,
114
	$search = @da_sql_query($link,$config,
116
	"SELECT " . da_sql_limit($limit,0,$config) . " * FROM $config[sql_accounting_table]
115
	"SELECT " . da_sql_limit($limit,0,$config) . " * FROM $config[sql_accounting_table]
117
	WHERE username = '$login' AND acctstarttime <= '$now_str'
116
	WHERE username = '$login' AND acctstarttime <= '$now_str'
118
	AND acctstarttime >= '$prev_str' $sql_extra_query " . da_sql_limit($limit,1,$config) .
117
	AND acctstarttime >= '$prev_str' $sql_extra_query " . da_sql_limit($limit,1,$config) .
119
	" ORDER BY acctstarttime $order " . da_sql_limit($limit,2,$config). " ;");
118
	" ORDER BY acctstarttime $order " . da_sql_limit($limit,2,$config). " ;");
120
	if ($search){
119
	if ($search){
121
		while( $row = @da_sql_fetch_array($search,$config) ){
120
		while( $row = @da_sql_fetch_array($search,$config) ){
122
			$num++;
121
			$num++;
123
			$acct_type = "$row[framedprotocol]/$row[nasporttype]";
122
			$acct_type = "$row[framedprotocol]/$row[nasporttype]";
124
			if ($acct_type == '')
123
			if ($acct_type == '')
125
				$acct_type = '-';
124
				$acct_type = '-';
126
			$acct_logedin = $row[acctstarttime];
125
			$acct_logedin = $row[acctstarttime];
127
			$acct_sessiontime = $row[acctsessiontime];
126
			$acct_sessiontime = $row[acctsessiontime];
128
			$acct_sessiontime_sum += $acct_sessiontime;
127
			$acct_sessiontime_sum += $acct_sessiontime;
129
			$acct_sessiontime = time2str($acct_sessiontime);
128
			$acct_sessiontime = time2str($acct_sessiontime);
130
			$acct_ip = $row[framedipaddress];
129
			$acct_ip = $row[framedipaddress];
131
			if ($acct_ip == '')
130
			if ($acct_ip == '')
132
				$acct_ip = '-';
131
				$acct_ip = '-';
133
			$acct_upload = $row[acctinputoctets];
132
			$acct_upload = $row[acctinputoctets];
134
			$acct_upload_sum += $acct_upload;
133
			$acct_upload_sum += $acct_upload;
135
			$acct_upload = bytes2str($acct_upload);
134
			$acct_upload = bytes2str($acct_upload);
136
			$acct_download = $row[acctoutputoctets];
135
			$acct_download = $row[acctoutputoctets];
137
			$acct_download_sum += $acct_download;
136
			$acct_download_sum += $acct_download;
138
			$acct_download = bytes2str($acct_download);
137
			$acct_download = bytes2str($acct_download);
139
			$acct_server = $row[nasipaddress];
138
			$acct_server = $row[nasipaddress];
140
			if ($acct_server != ''){
139
			if ($acct_server != ''){
141
				$acct_server = $da_name_cache[$row[nasipaddress]];
140
				$acct_server = $da_name_cache[$row[nasipaddress]];
142
				if (!isset($acct_server)){
141
				if (!isset($acct_server)){
143
					$acct_server = @gethostbyaddr($row[nasipaddress]);
142
					$acct_server = @gethostbyaddr($row[nasipaddress]);
144
					if (!isset($da_name_cache) && $config[general_use_session] == 'yes'){
143
					if (!isset($da_name_cache) && $config[general_use_session] == 'yes'){
145
						$da_name_cache[$row[nasipaddress]] = $acct_server;
144
						$da_name_cache[$row[nasipaddress]] = $acct_server;
146
						session_register('da_name_cache');
145
						session_register('da_name_cache');
147
					}
146
					}
148
					else
147
					else
149
						$da_name_cache[$row[nasipaddress]] = $acct_server;
148
						$da_name_cache[$row[nasipaddress]] = $acct_server;
150
				}
149
				}
151
			}
150
			}
152
			else
151
			else
153
				$acct_server = '-';
152
				$acct_server = '-';
154
			$acct_server = "$acct_server:$row[nasportid]";
153
			$acct_server = "$acct_server:$row[nasportid]";
155
			$acct_terminate_cause = "$row[acctterminatecause]";
154
			$acct_terminate_cause = "$row[acctterminatecause]";
156
			if ($acct_terminate_cause == '')
155
			if ($acct_terminate_cause == '')
157
				$acct_terminate_cause = '-';
156
				$acct_terminate_cause = '-';
158
			if (ereg('Login-Incorrect',$acct_terminate_cause) ||
157
			if (ereg('Login-Incorrect',$acct_terminate_cause) ||
159
				ereg('Multiple-Logins', $acct_terminate_cause) || ereg('Invalid-User',$acct_terminate_cause))
158
				ereg('Multiple-Logins', $acct_terminate_cause) || ereg('Invalid-User',$acct_terminate_cause))
160
			$acct_callerid = "$row[callingstationid]";
159
			$acct_callerid = "$row[callingstationid]";
161
			if ($acct_callerid == '')
160
			if ($acct_callerid == '')
162
				$acct_callerid = '-';
161
				$acct_callerid = '-';
163
			echo <<<EOM
162
			echo <<<EOM
164
			<tr align=center>
163
			<tr align=center>
165
				<td>$num</td>
164
				<td>$num</td>
166
EOM;
165
EOM;
167
				if ($acct_attrs[ua][1] != '') echo "<td>$acct_type</td>\n";
166
				if ($acct_attrs[ua][1] != '') echo "<td>$acct_type</td>\n";
168
				if ($acct_attrs[ua][2] != '') echo "<td>$acct_logedin</td>\n";
167
				if ($acct_attrs[ua][2] != '') echo "<td>$acct_logedin</td>\n";
169
				if ($acct_attrs[ua][3] != '') echo "<td>$acct_sessiontime</td>\n";
168
				if ($acct_attrs[ua][3] != '') echo "<td>$acct_sessiontime</td>\n";
170
				if ($acct_attrs[ua][4] != '') echo "<td>$acct_ip</td>\n";
169
				if ($acct_attrs[ua][4] != '') echo "<td>$acct_ip</td>\n";
171
				if ($acct_attrs[ua][5] != '') echo "<td>$acct_upload</td>\n";
170
				if ($acct_attrs[ua][5] != '') echo "<td>$acct_upload</td>\n";
172
				if ($acct_attrs[ua][6] != '') echo "<td>$acct_download</td>\n";
171
				if ($acct_attrs[ua][6] != '') echo "<td>$acct_download</td>\n";
173
//				if ($acct_attrs[ua][7] != '') echo "<td>$acct_server</td>\n";
172
//				if ($acct_attrs[ua][7] != '') echo "<td>$acct_server</td>\n";
174
				if ($acct_attrs[ua][8] != '') echo "<td>$acct_terminate_cause</td>\n";
173
				if ($acct_attrs[ua][8] != '') echo "<td>$acct_terminate_cause</td>\n";
175
//				if ($acct_attrs[ua][9] != '') echo "<td>$acct_callerid</td>\n";
174
//				if ($acct_attrs[ua][9] != '') echo "<td>$acct_callerid</td>\n";
176
			echo "</tr>\n";
175
			echo "</tr>\n";
177
		}
176
		}
178
		$acct_sessiontime_sum = time2str($acct_sessiontime_sum);
177
		$acct_sessiontime_sum = time2str($acct_sessiontime_sum);
179
		$acct_upload_sum = bytes2str($acct_upload_sum);
178
		$acct_upload_sum = bytes2str($acct_upload_sum);
180
		$acct_download_sum = bytes2str($acct_download_sum);
179
		$acct_download_sum = bytes2str($acct_download_sum);
181
	}
180
	}
182
	else
181
	else
183
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
182
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
184
}
183
}
185
else
184
else
186
	echo "<b>Could not connect to SQL database</b><br>\n";
185
	echo "<b>Could not connect to SQL database</b><br>\n";
187
$colspan = 3;
186
$colspan = 3;
188
if ($acct_attrs[ua][1] == '')
187
if ($acct_attrs[ua][1] == '')
189
	$colspan--;
188
	$colspan--;
190
if ($acct_attrs[ua][2] == '')
189
if ($acct_attrs[ua][2] == '')
191
	$colspan--;
190
	$colspan--;
192
echo <<<EOM
191
echo <<<EOM
193
			<tr bgcolor="lightyellow" align="center">
192
			<tr bgcolor="lightyellow" align="center">
194
			<td colspan=$colspan><b>Total</b></td>
193
			<td colspan=$colspan><b>Total</b></td>
195
EOM;
194
EOM;
196
				if ($acct_attrs[ua][3] != '') echo "<td><b>$acct_sessiontime_sum</td>\n";
195
				if ($acct_attrs[ua][3] != '') echo "<td><b>$acct_sessiontime_sum</b></td>\n";
197
				if ($acct_attrs[ua][4] != '') echo "<td>&nbsp;</td>\n";
196
				if ($acct_attrs[ua][4] != '') echo "<td>&nbsp;</td>\n";
198
				if ($acct_attrs[ua][5] != '') echo "<td><b>$acct_upload_sum</td>\n";
197
				if ($acct_attrs[ua][5] != '') echo "<td><b>$acct_upload_sum</b></td>\n";
199
				if ($acct_attrs[ua][6] != '') echo "<td><b>$acct_download_sum</td>\n";
198
				if ($acct_attrs[ua][6] != '') echo "<td><b>$acct_download_sum</b></td>\n";
200
//				if ($acct_attrs[ua][7] != '') echo "<td>&nbsp;</td>\n";
199
//				if ($acct_attrs[ua][7] != '') echo "<td>&nbsp;</td>\n";
201
				if ($acct_attrs[ua][8] != '') echo "<td>&nbsp;</td>\n";
200
				if ($acct_attrs[ua][8] != '') echo "<td>&nbsp;</td>\n";
202
//				if ($acct_attrs[ua][9] != '') echo "<td>&nbsp;</td>\n";
201
//				if ($acct_attrs[ua][9] != '') echo "<td>&nbsp;</td>\n";
203
?>
202
?>
204
				</tr>
203
				</tr>
205
	</table>
204
	</table>
206
<tr><td>
205
<tr><td>
207
<hr>
206
<hr>
208
<tr><td align="center">
207
<tr><td align="center">
209
	<form action="user_accounting.php" method="get" name="master">
208
	<form action="user_accounting.php" method="get" name="master">
210
	<table border=0>
209
	<table border=0>
211
		<tr><td colspan=6></td>
210
		<tr><td colspan=6></td>
212
		</tr>
211
		</tr>
213
		<tr valign="bottom">
212
		<tr valign="bottom">
214
		<td><small><b><?php echo "$l_user";?></td><td><small><b>from</td><td><small><b>to</td><td><small><b>nbr./page</td><td><b>order</td>
213
	<td><?php echo "$l_user";?></td><td>from</td><td>to</td><td>nbr./page</td><td>order</td>
215
	<tr valign="middle"><td>
214
	<tr valign="middle"><td>
216
<?php
215
<?php
217
	echo <<<EOM
216
	echo <<<EOM
218
<input type="text" name="login" size="11" value="$login"></td>
217
<input type="text" name="login" size="11" value="$login"></td>
219
<td><input type="text" name="prev_str" size="11" value="$prev_str"></td>
218
<td><input type="text" name="prev_str" size="11" value="$prev_str"></td>
220
<td><input type="text" name="now_str" size="11" value="$now_str"></td>
219
<td><input type="text" name="now_str" size="11" value="$now_str"></td>
221
<td><select name="pagesize">
220
<td><select name="pagesize">
222
<option $selected[5] value="5" >05
221
<option $selected[5] value="5" >05
223
<option $selected[10] value="10">10
222
<option $selected[10] value="10">10
224
<option $selected[15] value="15">15
223
<option $selected[15] value="15">15
225
<option $selected[20] value="20">20
224
<option $selected[20] value="20">20
226
<option $selected[40] value="40">40
225
<option $selected[40] value="40">40
227
<option $selected[80] value="80">80
226
<option $selected[80] value="80">80
228
<option $selected[all] value="all">tous
227
<option $selected[all] value="all">tous
229
</select>
228
</select>
230
</td>
229
</td>
231
<td><select name="order">
230
<td><select name="order">
232
<option $selected[asc] value="asc">older first
231
<option $selected[asc] value="asc">older first
233
<option $selected[desc] value="desc">recent first
232
<option $selected[desc] value="desc">recent first
234
</select>
233
</select>
235
</td>
234
</td>
236
EOM;
235
EOM;
237
?>
236
?>
238
 
237
 
239
<td><input type="submit" class=button value="show"></td></tr>
238
<td><input type="submit" class=button value="show"></td></tr>
240
</table></td></tr></form>
239
</table></td></tr></form>
241
</table>
240
</table>
242
</tr>
241
</tr>
243
</table>
242
</table>
244
</TD></TR>
243
</TD></TR>
245
</TABLE>
244
</TABLE>
246
</td></tr>
245
</td></tr>
247
</TABLE>
246
</TABLE>
248
</body>
247
</body>
249
</html>
248
</html>
250
 
249