Subversion Repositories ALCASAR

Rev

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