Subversion Repositories ALCASAR

Rev

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