Subversion Repositories ALCASAR

Rev

Rev 1847 | Rev 2373 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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