Subversion Repositories ALCASAR

Rev

Rev 907 | Rev 1847 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 907 Rev 1805
Line 49... Line 49...
49
</html>
49
</html>
50
EOM;
50
EOM;
51
	exit();
51
	exit();
52
}
52
}
53
 
53
 
54
$monthly_limit = ($item_vals['Max-Monthly-Session'][0] != '') ? $item_vals['Max-Monthly-Session'][0] : $default_vals['Max-Monthly-Session'][0];
54
if(isset($item_vals['Max-Monthly-Session'][0]) && $item_vals['Max-Monthly-Session'][0] != ''){
-
 
55
	$monthly_limit = $item_vals['Max-Monthly-Session'][0];
-
 
56
} else if (isset($default_vals['Max-Monthly-Session'][0])){
-
 
57
	$monthly_limit = $default_vals['Max-Monthly-Session'][0];
-
 
58
} else {
-
 
59
	$monthly_limit = '';
-
 
60
}
55
$monthly_limit = ($monthly_limit) ? $monthly_limit : $config[counter_default_monthly];
61
$monthly_limit = ($monthly_limit) ? $monthly_limit : $config['counter_default_monthly'];
-
 
62
 
56
$weekly_limit = ($item_vals['Max-Weekly-Session'][0] != '') ? $item_vals['Max-Weekly-Session'][0] : $default_vals['Max-Weekly-Session'][0];
63
if(isset($item_vals['Max-Weekly-Session'][0]) && $item_vals['Max-Weekly-Session'][0] != ''){
-
 
64
	$weekly_limit = $item_vals['Max-Weekly-Session'][0];
-
 
65
} else if (isset($default_vals['Max-Weekly-Session'][0])){
-
 
66
	$weekly_limit = $default_vals['Max-Weekly-Session'][0];
-
 
67
} else {
-
 
68
	$weekly_limit = '';
-
 
69
}
57
$weekly_limit = ($weekly_limit) ? $weekly_limit : $config[counter_default_weekly];
70
$weekly_limit = ($weekly_limit) ? $weekly_limit : $config['counter_default_weekly'];
-
 
71
 
58
$daily_limit = ($item_vals['Max-Daily-Session'][0] != '') ? $item_vals['Max-Daily-Session'][0] : $default_vals['Max-Daily-Session'][0];
72
if(isset($item_vals['Max-Daily-Session'][0]) && $item_vals['Max-Daily-Session'][0] != ''){
-
 
73
	$daily_limit = $item_vals['Max-Daily-Session'][0];
-
 
74
} else if (isset($default_vals['Max-Daily-Session'][0])){
-
 
75
	$daily_limit = $default_vals['Max-Daily-Session'][0];
-
 
76
} else {
-
 
77
	$daily_limit = '';
-
 
78
}
59
$daily_limit = ($daily_limit) ? $daily_limit : $config[counter_default_daily];
79
$daily_limit = ($daily_limit) ? $daily_limit : $config['counter_default_daily'];
-
 
80
 
60
$session_limit = ($item_vals['Session-Timeout'][0] != '') ? $item_vals['Session-Timeout'][0] : $default_vals['Session-Timeout'][0];
81
if(isset($item_vals['Session-Timeout'][0]) && $item_vals['Session-Timeout'][0] != ''){
-
 
82
	$session_limit = $item_vals['Session-Timeout'][0];
-
 
83
} else if (isset($default_vals['Session-Timeout'][0])){
-
 
84
	$session_limit = $default_vals['Session-Timeout'][0];
-
 
85
} else {
-
 
86
	$session_limit = '';
-
 
87
}
61
$session_limit = ($session_limit) ? $session_limit : 'none';
88
$session_limit = ($session_limit) ? $session_limit : 'none';
-
 
89
 
62
$total_limit = ($item_vals['Max-All-Session'][0] != '') ? $item_vals['Max-All-Session'][0] : $default_vals['Max-All-Session'][0];
90
if(isset($item_vals['Max-All-Session'][0]) && $item_vals['Max-All-Session'][0] != ''){
-
 
91
	$total_limit = $item_vals['Max-All-Session'][0];
-
 
92
} else if (isset($default_vals['Max-All-Session'][0])){
-
 
93
	$total_limit = $default_vals['Max-All-Session'][0];
-
 
94
} else {
-
 
95
	$total_limit = '';
-
 
96
}
63
$total_limit = ($total_limit) ? $total_limit : 'none';
97
$total_limit = ($total_limit) ? $total_limit : 'none';
-
 
98
 
64
$remaining = 'unlimited time';
99
$remaining = 'unlimited time';
65
$log_color = 'green';
100
$log_color = 'green';
66
 
101
 
67
$now = time();
102
$now = time();
68
$week = $now - 604800;
103
$week = $now - 604800;
69
$now_str = date("$config[sql_date_format]",$now + 86400);
104
$now_str = date("$config[sql_date_format]",$now + 86400);
70
$week_str = date("$config[sql_date_format]",$week);
105
$week_str = date("$config[sql_date_format]",$week);
71
$day = date('w');
106
$day = date('w');
72
$week_start = date($config[sql_date_format],$now - ($day)*86400);
107
$week_start = date($config['sql_date_format'],$now - ($day)*86400);
73
$month_start = date($config[sql_date_format],$now - date('j')*86400);
108
$month_start = date($config['sql_date_format'],$now - date('j')*86400);
74
$today = $day;
109
$today = $day;
75
$now_tmp = $now;
110
$now_tmp = $now;
76
for ($i = $day; $i >-1; $i--){
111
for ($i = $day; $i >-1; $i--){
77
	$days[$i] = date($config[sql_date_format],$now_tmp);
112
	$days[$i] = date($config['sql_date_format'],$now_tmp);
78
	$now_tmp -= 86400;
113
	$now_tmp -= 86400;
79
}
114
}
80
$day++;
115
$day++;
81
//$now -= ($day * 86400);
116
//$now -= ($day * 86400);
82
$now -= 604800;
117
$now -= 604800;
83
$now += 86400;
118
$now += 86400;
84
for ($i = $day; $i <= 6; $i++){
119
for ($i = $day; $i <= 6; $i++){
85
	$days[$i] = date($config[sql_date_format],$now);
120
	$days[$i] = date($config['sql_date_format'],$now);
86
//	$now -= 86400;
121
//	$now -= 86400;
87
	$now += 86400;
122
	$now += 86400;
88
}
123
}
89
 
124
 
90
$daily_used = $weekly_used = $monthly_used = $lastlog_session_time = '-';
125
$daily_used = $weekly_used = $monthly_used = $lastlog_session_time = '-';
91
$extra_msg = '';
126
$extra_msg = '';
92
$used = array('-','-','-','-','-','-','-');
127
$used = array('-','-','-','-','-','-','-');
93
 
128
 
94
$link = @da_sql_pconnect($config);
129
$link = da_sql_pconnect($config);
95
if ($link){
130
if ($link){
96
	$search = @da_sql_query($link,$config,
131
	$search = da_sql_query($link,$config,
97
	"SELECT sum(acctsessiontime) AS sum_sess_time,
132
	"SELECT sum(acctsessiontime) AS sum_sess_time,
98
	sum(acctinputoctets) AS sum_in_octets,
133
	sum(acctinputoctets) AS sum_in_octets,
99
	sum(acctoutputoctets) AS sum_out_octets,
134
	sum(acctoutputoctets) AS sum_out_octets,
100
	avg(acctsessiontime) AS avg_sess_time,
135
	avg(acctsessiontime) AS avg_sess_time,
101
	avg(acctinputoctets) AS avg_in_octets,
136
	avg(acctinputoctets) AS avg_in_octets,
102
	avg(acctoutputoctets) AS avg_out_octets,
137
	avg(acctoutputoctets) AS avg_out_octets,
103
	COUNT(*) as counter FROM
138
	COUNT(*) as counter FROM
104
	$config[sql_accounting_table] WHERE username = '$login'
139
	$config[sql_accounting_table] WHERE username = '$login'
105
	AND acctstarttime >= '$week_str' AND acctstarttime <= '$now_str';");
140
	AND acctstarttime >= '$week_str' AND acctstarttime <= '$now_str';");
106
	if ($search){
141
	if ($search){
107
		$row = @da_sql_fetch_array($search,$config);
142
		$row = da_sql_fetch_array($search,$config);
108
		$tot_time = time2str($row[sum_sess_time]);
143
		$tot_time = time2str($row['sum_sess_time']);
109
		$tot_input = bytes2str($row[sum_in_octets]);
144
		$tot_input = bytes2str($row['sum_in_octets']);
110
		$tot_output = bytes2str($row[sum_out_octets]);
145
		$tot_output = bytes2str($row['sum_out_octets']);
111
		$avg_time = time2str($row[avg_sess_time]);
146
		$avg_time = time2str($row['avg_sess_time']);
112
		$avg_input = bytes2str($row[avg_in_octets]);
147
		$avg_input = bytes2str($row['avg_in_octets']);
113
		$avg_output = bytes2str($row[avg_out_octets]);
148
		$avg_output = bytes2str($row['avg_out_octets']);
114
		$tot_conns = $row[counter];
149
		$tot_conns = $row['counter'];
115
	}
150
	}
116
	else
151
	else
117
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
152
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
118
	$search = @da_sql_query($link,$config,
153
	$search = da_sql_query($link,$config,
119
	"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE username = '$login'
154
	"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE username = '$login'
120
	AND acctstarttime >= '$week_start' AND acctstarttime <= '$now_str';");
155
	AND acctstarttime >= '$week_start' AND acctstarttime <= '$now_str';");
121
	if ($search){
156
	if ($search){
122
		$row = @da_sql_fetch_array($search,$config);
157
		$row = da_sql_fetch_array($search,$config);
123
		$weekly_used = $row[sum_sess_time];
158
		$weekly_used = $row['sum_sess_time'];
124
	}
159
	}
125
	else
160
	else
126
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
161
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
127
	if ($monthly_limit != 'none' || $config[counter_monthly_calculate_usage] == 'true'){
162
	if ($monthly_limit != 'none' || (isset($config['counter_monthly_calculate_usage']) && $config['counter_monthly_calculate_usage'] == 'true')){
128
		$search = @da_sql_query($link,$config,
163
		$search = da_sql_query($link,$config,
129
		"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE username = '$login'
164
		"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE username = '$login'
130
		AND acctstarttime >= '$month_start' AND acctstarttime <= '$now_str';");
165
		AND acctstarttime >= '$month_start' AND acctstarttime <= '$now_str';");
131
		if ($search){
166
		if ($search){
132
			$row = @da_sql_fetch_array($search,$config);
167
			$row = da_sql_fetch_array($search,$config);
133
			$monthly_used = $row[sum_sess_time];
168
			$monthly_used = $row['sum_sess_time'];
134
		}
169
		}
135
		else
170
		else
136
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
171
			echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
137
	}
172
	}
138
	$search = @da_sql_query($link,$config,
173
	$search = da_sql_query($link,$config,
139
	"SELECT COUNT(*) AS counter FROM $config[sql_accounting_table] WHERE username = '$login'
174
	"SELECT COUNT(*) AS counter FROM $config[sql_accounting_table] WHERE username = '$login'
140
	AND acctstoptime >= '$week_str' AND acctstoptime <= '$now_str'
175
	AND acctstoptime >= '$week_str' AND acctstoptime <= '$now_str'
141
	AND (acctterminatecause LIKE 'Login-Incorrect%' OR
176
	AND (acctterminatecause LIKE 'Login-Incorrect%' OR
142
	acctterminatecause LIKE 'Invalid-User%' OR
177
	acctterminatecause LIKE 'Invalid-User%' OR
143
	acctterminatecause LIKE 'Multiple-Logins%');");
178
	acctterminatecause LIKE 'Multiple-Logins%');");
144
	if ($search){
179
	if ($search){
145
		$row = @da_sql_fetch_array($search,$config);
180
		$row = da_sql_fetch_array($search,$config);
146
		$tot_badlogins = $row[counter];
181
		$tot_badlogins = $row['counter'];
147
	}
182
	}
148
	else
183
	else
149
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
184
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
150
	for($i = 0; $i <=6; $i++){
185
	for($i = 0; $i <=6; $i++){
151
		if ($days[$i] == '')
186
		if ($days[$i] == '')
152
			continue;
187
			continue;
153
		$search = @da_sql_query($link,$config,
188
		$search = da_sql_query($link,$config,
154
		"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE
189
		"SELECT sum(acctsessiontime) AS sum_sess_time FROM $config[sql_accounting_table] WHERE
155
		username = '$login' AND acctstoptime >= '$days[$i] 00:00:00'
190
		username = '$login' AND acctstoptime >= '$days[$i] 00:00:00'
156
		AND acctstoptime <= '$days[$i] 23:59:59';");
191
		AND acctstoptime <= '$days[$i] 23:59:59';");
157
		if ($search){
192
		if ($search){
158
			$row = @da_sql_fetch_array($search,$config);
193
			$row = da_sql_fetch_array($search,$config);
159
			$used[$i] = $row[sum_sess_time];
194
			$used[$i] = $row['sum_sess_time'];
160
			if ($daily_limit != 'none' && $used[$i] > $daily_limit)
195
			if ($daily_limit != 'none' && $used[$i] > $daily_limit)
161
				$used[$i] = "<font color=red>" . time2str($used[$i]) . "</font>";
196
				$used[$i] = "<font color=red>" . time2str($used[$i]) . "</font>";
162
			else
197
			else
163
				$used[$i] = time2str($used[$i]);
198
				$used[$i] = time2str($used[$i]);
164
			if ($today == $i){
199
			if ($today == $i){
165
				$daily_used = $row[sum_sess_time];
200
				$daily_used = $row['sum_sess_time'];
166
				if ($daily_limit != 'none'){
201
				if ($daily_limit != 'none'){
167
					$remaining = $daily_limit - $daily_used;
202
					$remaining = $daily_limit - $daily_used;
168
					if ($remaining <=0)
203
					if ($remaining <=0)
169
						$remaining = 0;
204
						$remaining = 0;
170
					$log_color = ($remaining) ? 'green' : 'red';
205
					$log_color = ($remaining) ? 'green' : 'red';
Line 205... Line 240...
205
			$remaining = $tmp;
240
			$remaining = $tmp;
206
		if ($remaining > $tmp)
241
		if ($remaining > $tmp)
207
			$remaining = $tmp;
242
			$remaining = $tmp;
208
		$log_color = ($remaining) ? 'green' : 'red';
243
		$log_color = ($remaining) ? 'green' : 'red';
209
	}
244
	}
210
	if ($monthly_limit != 'none' || $config[counter_monthly_calculate_usage] == 'true'){
245
	if ($monthly_limit != 'none' || (isset($config['counter_monthly_calculate_usage']) && $config['counter_monthly_calculate_usage'] == 'true')){
211
		$monthly_used = time2str($monthly_used);
246
		$monthly_used = time2str($monthly_used);
212
		if ($monthly_limit != 'none' && !$tmp)
247
		if ($monthly_limit != 'none' && !$tmp)
213
			$monthly_used = "<font color=red>$monthly_used</font>";
248
			$monthly_used = "<font color=red>$monthly_used</font>";
214
	}
249
	}
215
	if ($session_limit != 'none'){
250
	if ($session_limit != 'none'){
Line 217... Line 252...
217
			$remaining = $session_limit;
252
			$remaining = $session_limit;
218
		if ($remaining > $session_limit)
253
		if ($remaining > $session_limit)
219
			$remaining = $session_limit;
254
			$remaining = $session_limit;
220
	}
255
	}
221
 
256
 
222
	$search = @da_sql_query($link,$config,
257
	$search = da_sql_query($link,$config,
223
	"SELECT " . da_sql_limit(1,0,$config) . " * FROM $config[sql_accounting_table]
258
	"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) . "
259
	WHERE username = '$login' AND acctstoptime IS NULL " . da_sql_limit(1,1,$config) . "
225
	 ORDER BY acctstarttime DESC " . da_sql_limit(1,2,$config). " ;");
260
	 ORDER BY acctstarttime DESC " . da_sql_limit(1,2,$config). " ;");
226
	if ($search){
261
	if ($search){
227
		if (@da_sql_num_rows($search,$config)){
262
		if (da_sql_num_rows($search,$config)){
228
			$logged_now = 1;
263
			$logged_now = 1;
229
			$row = @da_sql_fetch_array($search,$config);
264
			$row = da_sql_fetch_array($search,$config);
230
			$lastlog_time = $row['acctstarttime'];
265
			$lastlog_time = $row['acctstarttime'];
231
			$lastlog_server_ip = $row['nasipaddress'];
266
			$lastlog_server_ip = $row['nasipaddress'];
232
			$lastlog_server_port = $row['nasportid'];
267
			$lastlog_server_port = $row['nasportid'];
233
			$lastlog_session_time = date2timediv($lastlog_time,0);
268
			$lastlog_session_time = date2timediv($lastlog_time,0);
234
			if ($daily_limit != 'none'){
269
			if ($daily_limit != 'none'){
235
				$remaining = $remaining - $lastlog_session_time;
270
				$remaining = $remaining - $lastlog_session_time;
236
				if ($remaining < 0)
271
				if ($remaining < 0)
237
					$remaining = 0;
272
					$remaining = 0;
238
				$log_color = ($remaining) ? 'green' : 'red'; 
273
				$log_color = ($remaining) ? 'green' : 'red';
239
			}
274
			}
240
			$lastlog_session_time_jvs = 1000 * $lastlog_session_time;
275
			$lastlog_session_time_jvs = 1000 * $lastlog_session_time;
241
			$lastlog_session_time = time2strclock($lastlog_session_time);
276
			$lastlog_session_time = time2strclock($lastlog_session_time);
242
			$lastlog_client_ip = $row['framedipaddress'];	
277
			$lastlog_client_ip = $row['framedipaddress'];
243
			$lastlog_server_name = @gethostbyaddr($lastlog_server_ip);
278
			$lastlog_server_name = @gethostbyaddr($lastlog_server_ip);
244
			$lastlog_client_name = @gethostbyaddr($lastlog_client_ip);
279
			$lastlog_client_name = @gethostbyaddr($lastlog_client_ip);
245
			$lastlog_callerid = $row['callingstationid'];
280
			$lastlog_callerid = $row['callingstationid'];
246
			if ($lastlog_callerid == '')
281
			if ($lastlog_callerid == '')
247
				$lastlog_callerid = 'not available';
282
				$lastlog_callerid = 'not available';
Line 257... Line 292...
257
				$lastlog_output = 'not available';
292
				$lastlog_output = 'not available';
258
		}
293
		}
259
	}
294
	}
260
	else
295
	else
261
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
296
		echo "<b>Database query failed: " . da_sql_error($link,$config) . "</b><br>\n";
262
	if (! $logged_now){
297
	if (!isset($logged_now) || !$logged_now){
263
		$search = @da_sql_query($link,$config,
298
		$search = da_sql_query($link,$config,
264
		"SELECT " . da_sql_limit(1,0,$config) . " * FROM $config[sql_accounting_table]
299
		"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) . "
300
		WHERE username = '$login' AND acctsessiontime != '0' " . da_sql_limit(1,1,$config) . "
266
		 ORDER BY acctstoptime DESC " . da_sql_limit(1,2,$config). " ;");
301
		 ORDER BY acctstoptime DESC " . da_sql_limit(1,2,$config). " ;");
267
		if ($search){
302
		if ($search){
268
			if (@da_sql_num_rows($search,$config)){
303
			if (da_sql_num_rows($search,$config)){
269
				$row = @da_sql_fetch_array($search,$config);
304
				$row = da_sql_fetch_array($search,$config);
270
				$lastlog_time = $row['acctstarttime'];
305
				$lastlog_time = $row['acctstarttime'];
271
				$lastlog_server_ip = $row['nasipaddress'];
306
				$lastlog_server_ip = $row['nasipaddress'];
272
				$lastlog_server_port = $row['nasportid'];
307
				$lastlog_server_port = $row['nasportid'];
273
				$lastlog_session_time = time2str($row['acctsessiontime']);
308
				$lastlog_session_time = time2str($row['acctsessiontime']);
274
				$lastlog_client_ip = $row['framedipaddress'];	
309
				$lastlog_client_ip = $row['framedipaddress'];
275
		$lastlog_server_name = ($lastlog_server_ip != '') ? @gethostbyaddr($lastlog_server_ip) : '-';
310
		$lastlog_server_name = ($lastlog_server_ip != '') ? @gethostbyaddr($lastlog_server_ip) : '-';
276
		$lastlog_client_name = ($lastlog_client_ip != '') ? @gethostbyaddr($lastlog_client_ip) : '-';
311
		$lastlog_client_name = ($lastlog_client_ip != '') ? @gethostbyaddr($lastlog_client_ip) : '-';
277
				$lastlog_callerid = $row['callingstationid'];
312
				$lastlog_callerid = $row['callingstationid'];
278
				if ($lastlog_callerid == '')
313
				if ($lastlog_callerid == '')
279
					$lastlog_callerid = 'not available';
314
					$lastlog_callerid = 'not available';
Line 305... Line 340...
305
EON;
340
EON;
306
else
341
else
307
	$msg =<<<EON
342
	$msg =<<<EON
308
$l_user_remain_login<font color="$log_color"> <b>$remaining $extra_msg</b></font>
343
$l_user_remain_login<font color="$log_color"> <b>$remaining $extra_msg</b></font>
309
EON;
344
EON;
310
$lock_msg = $item_vals['Dialup-Lock-Msg'][0];
345
$lock_msg = (isset($item_vals['Dialup-Lock-Msg'][0])) ? $item_vals['Dialup-Lock-Msg'][0] : '';
311
if ($lock_msg != '')
346
if ($lock_msg != '')
312
	$descr =<<<EON
347
	$descr =<<<EON
313
<font color=red><b>$lock_msg </b</font>
348
<font color=red><b>$lock_msg </b</font>
314
EON;
349
EON;
315
else
350
else
316
	$descr = '-';
351
	$descr = '-';
317
 
352
 
318
$expiration = $default_vals['Expiration'][0];
353
$expiration = isset($default_vals['Expiration'][0]) ? $default_vals['Expiration'][0] : '';
319
if ($item_vals['Expiration'][0] != '')
354
if ($item_vals['Expiration'][0] != '')
320
	$expiration = $item_vals['Expiration'][0];
355
	$expiration = $item_vals['Expiration'][0];
321
if ($expiration != ''){
356
if ($expiration != ''){
322
	$expiration = strtotime($expiration);
357
	$expiration = strtotime($expiration);
323
	if ($expiration != -1 && $expiration < time())
358
	if ($expiration != -1 && $expiration < time())