Subversion Repositories ALCASAR

Rev

Rev 907 | Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
324 richard 1
<?php
2
require('/etc/freeradius-web/config.php');
3
?>
4
<html>
5
<head>
6
<?php
7
require('../lib/functions.php');
8
require('../lib/defaults.php');
9
$date = strftime('%A, %e %B %Y, %T %Z');
10
 
11
if (is_file("../lib/$config[general_lib_type]/user_info.php")){
12
	include("../lib/$config[general_lib_type]/user_info.php");
13
	if ($user_exists == 'no'){
14
		echo <<<EOM
15
<title>Page d'information d'utilisateur</title>
16
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
17
<link rel="stylesheet" href="/css/style.css">
18
</head>
19
<body>
20
<center>
21
<form action="user_admin.php" method=get>
22
<b>User Name&nbsp;&nbsp;</b>
23
<input type="text" size=10 name="login" value="$login">
24
<b>&nbsp;&nbsp;does not exist</b><br>
25
<input type=submit class=button value="Show User">
26
</body>
27
</html>
28
EOM;
29
		exit();
30
	}
31
}
32
 
33
if (is_file("../lib/sql/drivers/$config[sql_type]/functions.php"))
34
	include_once("../lib/sql/drivers/$config[sql_type]/functions.php");
35
else{
36
	echo <<<EOM
37
<title>Page d'information d'utilisateur</title>
38
<meta http-equiv="Content-Type" content="text/html; charset=$config[general_charset]">
39
<link rel="stylesheet" href="style.css">
40
</head>
41
<body>
42
<center>
43
<b>Could not include SQL library functions. Aborting</b>
44
</body>
45
</html>
46
EOM;
47
	exit();
48
}
49
 
50
$monthly_limit = ($item_vals['Max-Monthly-Session'][0] != '') ? $item_vals['Max-Monthly-Session'][0] : $default_vals['Max-Monthly-Session'][0];
51
$monthly_limit = ($monthly_limit) ? $monthly_limit : $config[counter_default_monthly];
52
$weekly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'][0];
53
$weekly_limit = ($weekly_limit) ? $weekly_limit : $config[counter_default_weekly];
54
$daily_limit = ($item_vals['Max-Daily-Session'][0] != '') ? $item_vals['Max-Daily-Session'][0] : $default_vals['Max-Daily-Session'][0];
55
$daily_limit = ($daily_limit) ? $daily_limit : $config[counter_default_daily];
56
$session_limit = ($item_vals['Session-Timeout'][0] != '') ? $item_vals['Session-Timeout'][0] : $default_vals['Session-Timeout'][0];
57
$session_limit = ($session_limit) ? $session_limit : 'none';
58
$remaining = 'unlimited time';
59
$log_color = 'green';
60
 
61
$now = time();
62
$week = $now - 604800;
63
$now_str = date("$config[sql_date_format]",$now + 86400);
64
$week_str = date("$config[sql_date_format]",$week);
65
$day = date('w');
66
$week_start = date($config[sql_date_format],$now - ($day)*86400);
67
$month_start = date($config[sql_date_format],$now - date('j')*86400);
68
$today = $day;
69
$now_tmp = $now;
70
for ($i = $day; $i >-1; $i--){
71
	$days[$i] = date($config[sql_date_format],$now_tmp);
72
	$now_tmp -= 86400;
73
}
74
$day++;
75
//$now -= ($day * 86400);
76
$now -= 604800;
77
$now += 86400;
78
for ($i = $day; $i <= 6; $i++){
79
	$days[$i] = date($config[sql_date_format],$now);
80
//	$now -= 86400;
81
	$now += 86400;
82
}
83
 
84
$daily_used = $weekly_used = $monthly_used = $lastlog_session_time = '-';
85
$extra_msg = '';
86
$used = array('-','-','-','-','-','-','-');
87
 
88
$link = @da_sql_pconnect($config);
89
if ($link){
90
	$search = @da_sql_query($link,$config,
91
	"SELECT sum(acctsessiontime) AS sum_sess_time,
92
	sum(acctinputoctets) AS sum_in_octets,
93
	sum(acctoutputoctets) AS sum_out_octets,
94
	avg(acctsessiontime) AS avg_sess_time,
95
	avg(acctinputoctets) AS avg_in_octets,
96
	avg(acctoutputoctets) AS avg_out_octets,
97
	COUNT(*) as counter FROM
98
	$config[sql_accounting_table] WHERE username = '$login'
99
	AND acctstarttime >= '$week_str' AND acctstarttime <= '$now_str';");
100
	if ($search){
101
		$row = @da_sql_fetch_array($search,$config);
102
		$tot_time = time2str($row[sum_sess_time]);
103
		$tot_input = bytes2str($row[sum_in_octets]);
104
		$tot_output = bytes2str($row[sum_out_octets]);
105
		$avg_time = time2str($row[avg_sess_time]);
106
		$avg_input = bytes2str($row[avg_in_octets]);
107
		$avg_output = bytes2str($row[avg_out_octets]);
108
		$tot_conns = $row[counter];
109
	}
110
	else
111
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
112
	$search = @da_sql_query($link,$config,
113
	"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE username = '$login'
114
	AND acctstarttime >= '$week_start' AND acctstarttime <= '$now_str';");
115
	if ($search){
116
		$row = @da_sql_fetch_array($search,$config);
117
		$weekly_used = $row[sum_sess_time];
118
	}
119
	else
120
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
121
	if ($monthly_limit != 'none' || $config[counter_monthly_calculate_usage] == 'true'){
122
		$search = @da_sql_query($link,$config,
123
		"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE username = '$login'
124
		AND acctstarttime >= '$month_start' AND acctstarttime <= '$now_str';");
125
		if ($search){
126
			$row = @da_sql_fetch_array($search,$config);
127
			$monthly_used = $row[sum_sess_time];
128
		}
129
		else
130
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
131
	}
132
	$search = @da_sql_query($link,$config,
133
	"SELECT COUNT(*) AS counter FROM $config[sql_accounting_table] WHERE username = '$login'
134
	AND acctstoptime >= '$week_str' AND acctstoptime <= '$now_str'
135
	AND (acctterminatecause LIKE 'Login-Incorrect%' OR
136
	acctterminatecause LIKE 'Invalid-User%' OR
137
	acctterminatecause LIKE 'Multiple-Logins%');");
138
	if ($search){
139
		$row = @da_sql_fetch_array($search,$config);
140
		$tot_badlogins = $row[counter];
141
	}
142
	else
143
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
144
	for($i = 0; $i <=6; $i++){
145
		if ($days[$i] == '')
146
			continue;
147
		$search = @da_sql_query($link,$config,
148
		"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE
149
		username = '$login' AND acctstoptime >= '$days[$i] 00:00:00'
150
		AND acctstoptime <= '$days[$i] 23:59:59';");
151
		if ($search){
152
			$row = @da_sql_fetch_array($search,$config);
153
			$used[$i] = $row[sum_sess_time];
154
			if ($daily_limit != 'none' && $used[$i] > $daily_limit)
155
				$used[$i] = "<font color=red>" . time2str($used[$i]) . "</font>";
156
			else
157
				$used[$i] = time2str($used[$i]);
158
			if ($today == $i){
159
				$daily_used = $row[sum_sess_time];
160
				if ($daily_limit != 'none'){
161
					$remaining = $daily_limit - $daily_used;
162
					if ($remaining <=0)
163
						$remaining = 0;
164
					$log_color = ($remaining) ? 'green' : 'red';
165
					if (!$remaining)
166
						$extra_msg = '(Out of daily quota)';
167
				}
168
				$daily_used = time2str($daily_used);
169
				if ($daily_limit != 'none' && !$remaining)
170
					$daily_used = "<font color=red>$daily_used</font>";
171
			}
172
		}
173
		else
174
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
175
	}
176
	if ($weekly_limit != 'none'){
177
		$tmp = $weekly_limit - $weekly_used;
178
		if ($tmp <=0){
179
			$tmp = 0;
180
			$extra_msg .= '(Out of weekly quota)';
181
		}
182
		if (!is_numeric($remaining))
183
			$remaining = $tmp;
184
		if ($remaining > $tmp)
185
			$remaining = $tmp;
186
		$log_color = ($remaining) ? 'green' : 'red';
187
	}
188
	$weekly_used = time2str($weekly_used);
189
	if ($weekly_limit != 'none' && !$tmp)
190
		$weekly_used = "<font color=red>$weekly_used</font>";
191
 
192
	if ($monthly_limit != 'none'){
193
		$tmp = $monthly_limit - $monthly_used;
194
		if ($tmp <=0){
195
			$tmp = 0;
196
			$extra_msg .= '(Out of monthly quota)';
197
		}
198
		if (!is_numeric($remaining))
199
			$remaining = $tmp;
200
		if ($remaining > $tmp)
201
			$remaining = $tmp;
202
		$log_color = ($remaining) ? 'green' : 'red';
203
	}
204
	if ($monthly_limit != 'none' || $config[counter_monthly_calculate_usage] == 'true'){
205
		$monthly_used = time2str($monthly_used);
206
		if ($monthly_limit != 'none' && !$tmp)
207
			$monthly_used = "<font color=red>$monthly_used</font>";
208
	}
209
	if ($session_limit != 'none'){
210
		if (!is_numeric($remaining))
211
			$remaining = $session_limit;
212
		if ($remaining > $session_limit)
213
			$remaining = $session_limit;
214
	}
215
 
216
	$search = @da_sql_query($link,$config,
217
	"SELECT " . da_sql_limit(1,0,$config) . " * FROM $config[sql_accounting_table]
218
	WHERE username = '$login' AND acctstoptime IS NULL " . da_sql_limit(1,1,$config) . "
219
	 ORDER BY acctstarttime DESC " . da_sql_limit(1,2,$config). " ;");
220
	if ($search){
221
		if (@da_sql_num_rows($search,$config)){
222
			$logged_now = 1;
223
			$row = @da_sql_fetch_array($search,$config);
224
			$lastlog_time = $row['acctstarttime'];
225
			$lastlog_server_ip = $row['nasipaddress'];
226
			$lastlog_server_port = $row['nasportid'];
227
			$lastlog_session_time = date2timediv($lastlog_time,0);
228
			if ($daily_limit != 'none'){
229
				$remaining = $remaining - $lastlog_session_time;
230
				if ($remaining < 0)
231
					$remaining = 0;
232
				$log_color = ($remaining) ? 'green' : 'red'; 
233
			}
234
			$lastlog_session_time_jvs = 1000 * $lastlog_session_time;
235
			$lastlog_session_time = time2strclock($lastlog_session_time);
236
			$lastlog_client_ip = $row['framedipaddress'];	
237
			$lastlog_server_name = @gethostbyaddr($lastlog_server_ip);
238
			$lastlog_client_name = @gethostbyaddr($lastlog_client_ip);
239
			$lastlog_callerid = $row['callingstationid'];
240
			if ($lastlog_callerid == '')
241
				$lastlog_callerid = 'not available';
242
			$lastlog_input = $row['acctinputoctets'];
243
			if ($lastlog_input)
244
				$lastlog_input = bytes2str($lastlog_input);
245
			else
246
				$lastlog_input = 'not available';
247
			$lastlog_output = $row['acctoutputoctets'];
248
			if ($lastlog_output)
249
				$lastlog_output = bytes2str($lastlog_output);
250
			else
251
				$lastlog_output = 'not available';
252
		}
253
	}
254
	else
255
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
256
	if (! $logged_now){
257
		$search = @da_sql_query($link,$config,
258
		"SELECT " . da_sql_limit(1,0,$config) . " * FROM $config[sql_accounting_table]
259
		WHERE username = '$login' AND acctsessiontime != '0' " . da_sql_limit(1,1,$config) . "
260
		 ORDER BY acctstoptime DESC " . da_sql_limit(1,2,$config). " ;");
261
		if ($search){
262
			if (@da_sql_num_rows($search,$config)){
263
				$row = @da_sql_fetch_array($search,$config);
264
				$lastlog_time = $row['acctstarttime'];
265
				$lastlog_server_ip = $row['nasipaddress'];
266
				$lastlog_server_port = $row['nasportid'];
267
				$lastlog_session_time = time2str($row['acctsessiontime']);
268
				$lastlog_client_ip = $row['framedipaddress'];	
269
		$lastlog_server_name = ($lastlog_server_ip != '') ? @gethostbyaddr($lastlog_server_ip) : '-';
270
		$lastlog_client_name = ($lastlog_client_ip != '') ? @gethostbyaddr($lastlog_client_ip) : '-';
271
				$lastlog_callerid = $row['callingstationid'];
272
				if ($lastlog_callerid == '')
273
					$lastlog_callerid = 'not available';
274
				$lastlog_input = $row['acctinputoctets'];
275
				$lastlog_input = bytes2str($lastlog_input);
276
				$lastlog_output = $row['acctoutputoctets'];
277
				$lastlog_output = bytes2str($lastlog_output);
278
			}
279
			else
280
				$not_known = 1;
281
		}
282
		else
283
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
284
	}
285
}
286
else
287
	echo "<b>Could not connect to SQL database</b><br>\n";
288
 
289
$monthly_limit = (is_numeric($monthly_limit)) ? time2str($monthly_limit) : $monthly_limit;
290
$weekly_limit = (is_numeric($weekly_limit)) ? time2str($weekly_limit) : $weekly_limit;
291
$daily_limit = (is_numeric($daily_limit)) ? time2str($daily_limit) : $daily_limit;
292
$session_limit = (is_numeric($session_limit)) ? time2str($session_limit) : $session_limit;
293
$remaining = (is_numeric($remaining)) ? time2str($remaining) : $remaining;
294
 
295
if ($item_vals['Dialup-Access'][0] == 'FALSE' || (!isset($item_vals['Dialup-Access'][0]) && $attrmap['Dialup-Access'] != '' && $attrmap['Dialup-Access'] != 'none'))
296
	$msg =<<<EON
297
<font color=red><b> Le compte de l'utilisateur est verrouill&eacute; </b></font>
298
EON;
299
else
300
	$msg =<<<EON
301
L'utilisateur peut s'identifier pendant <font color="$log_color"> <b>$remaining $extra_msg</font>
302
EON;
303
$lock_msg = $item_vals['Dialup-Lock-Msg'][0];
304
if ($lock_msg != '')
305
	$descr =<<<EON
306
<font color=red><b>$lock_msg </b</font>
307
EON;
308
else
309
	$descr = '-';
310
 
311
$expiration = $default_vals['Expiration'][0];
312
if ($item_vals['Expiration'][0] != '')
313
	$expiration = $item_vals['Expiration'][0];
314
if ($expiration != ''){
315
	$expiration = strtotime($expiration);
316
	if ($expiration != -1 && $expiration < time())
317
		$descr = <<<EOM
318
<font color=red><b>Le compte de l'utilisateur a expir&eacute</b></font>
319
EOM;
320
}
321
 
322
require('../html/user_admin.html.php');
323
?>