Subversion Repositories ALCASAR

Rev

Rev 2817 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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