Subversion Repositories ALCASAR

Rev

Rev 925 | Rev 1831 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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