Subversion Repositories ALCASAR

Rev

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