Subversion Repositories ALCASAR

Rev

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