Project

General

Profile

Download (19.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
    $Id$
4
    part of m0n0wall (http://m0n0.ch/wall)
5

    
6
    Copyrigth (C) 2009	    Ermal Lu?i
7
    Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
8
    All rights reserved.
9

    
10
    Redistribution and use in source and binary forms, with or without
11
    modification, are permitted provided that the following conditions are met:
12

    
13
    1. Redistributions of source code must retain the above copyright notice,
14
       this list of conditions and the following disclaimer.
15

    
16
    2. Redistributions in binary form must reproduce the above copyright
17
       notice, this list of conditions and the following disclaimer in the
18
       documentation and/or other materials provided with the distribution.
19

    
20
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
    POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_BUILDER_BINARIES:	/sbin/ipfw	
33
	pfSense_MODULE:	captiveportal
34
*/
35

    
36
require_once("auth.inc");
37
require_once("functions.inc");
38
require_once("captiveportal.inc");
39

    
40
$errormsg = "Invalid credentials specified.";
41

    
42
header("Expires: 0");
43
header("Cache-Control: no-store, no-cache, must-revalidate");
44
header("Cache-Control: post-check=0, pre-check=0", false);
45
header("Pragma: no-cache");
46

    
47
$orig_host = $_ENV['HTTP_HOST'];
48
$orig_request = $_REQUEST['redirurl'];
49
$clientip = $_SERVER['REMOTE_ADDR'];
50

    
51
if (!$clientip) {
52
    /* not good - bail out */
53
    echo "An error occurred.  Please check the system logs for more information.";
54
    log_error("Captive portal could not determine client's IP address.");
55
    exit;
56
}
57

    
58
if (isset($config['captiveportal']['httpslogin']))
59
    $ourhostname = $config['captiveportal']['httpsname'] . ":8001";
60
else {
61
    $ifip = portal_ip_from_client_ip($clientip);
62
    if (!$ifip)
63
    	$ourhostname = $config['system']['hostname'] . ":8000";
64
    else
65
    	$ourhostname = "{$ifip}:8000";
66
}
67

    
68
if ($orig_host != $ourhostname) {
69
    /* the client thinks it's connected to the desired web server, but instead
70
       it's connected to us. Issue a redirect... */
71

    
72
    if (isset($config['captiveportal']['httpslogin']))
73
        header("Location: https://{$ourhostname}/index.php?redirurl=" . urlencode("http://{$orig_host}{$orig_request}"));
74
    else
75
        header("Location: http://{$ourhostname}/index.php?redirurl=" . urlencode("http://{$orig_host}{$orig_request}"));
76

    
77
    exit;
78
}
79
if (preg_match("/redirurl=(.*)/", $orig_request, $matches))
80
    $redirurl = urldecode($matches[1]);
81
if ($_POST['redirurl'])
82
    $redirurl = $_POST['redirurl'];
83
if (!empty($config['captiveportal']['redirurl']))
84
	$redirurl = $config['captiveportal']['redirurl'];
85

    
86
$macfilter = !isset($config['captiveportal']['nomacfilter']);
87
$passthrumac = isset($config['captiveportal']['passthrumacadd']);
88

    
89
/* find MAC address for client */
90
$clientmac = arp_get_mac_by_ip($clientip);
91
if (!$clientmac && ($macfilter || $passthrumac)) {
92
    /* unable to find MAC address - shouldn't happen! - bail out */
93
    captiveportal_logportalauth("unauthenticated","noclientmac",$clientip,"ERROR");
94
    echo "An error occurred.  Please check the system logs for more information.";
95
    log_error("Captive portal could not determine client's MAC address.  Disable MAC address filtering in captive portal if you do not need this functionality.");
96
    exit;
97
}
98

    
99
/* find out if we need RADIUS + RADIUSMAC or not */
100
if (file_exists("{$g['vardb_path']}/captiveportal_radius.db")) {
101
    $radius_enable = TRUE;
102
    if (isset($config['captiveportal']['radmac_enable']))
103
        $radmac_enable = TRUE;
104
}
105

    
106
if ($_POST['logout_id']) {
107
    disconnect_client($_POST['logout_id']);
108
    echo <<<EOD
109
<HTML>
110
<HEAD><TITLE>Disconnecting...</TITLE></HEAD>
111
<BODY BGCOLOR="#435370">
112
<SPAN STYLE="color: #ffffff; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 11px;">
113
<B>You have been disconnected.</B>
114
</SPAN>
115
<SCRIPT LANGUAGE="JavaScript">
116
<!--
117
setTimeout('window.close();',5000) ;
118
-->
119
</SCRIPT>
120
</BODY>
121
</HTML>
122

    
123
EOD;
124
exit;
125
} else if ($clientmac && $radmac_enable && portal_mac_radius($clientmac,$clientip)) {
126
    /* radius functions handle everything so we exit here since we're done */
127
    exit;
128

    
129
} else if ($_POST['accept'] && $_POST['auth_voucher']) {
130

    
131
    $voucher = trim($_POST['auth_voucher']);
132
    $timecredit = voucher_auth($voucher);
133
    // $timecredit contains either a credit in minutes or an error message
134
    if ($timecredit > 0) {  // voucher is valid. Remaining minutes returned
135
        // if multiple vouchers given, use the first as username
136
        $a_vouchers = split("[\t\n\r ]+",$voucher);
137
        $voucher = $a_vouchers[0];
138
        $attr = array( 'voucher' => 1,
139
                'session_timeout' => $timecredit*60,
140
                'session_terminate_time' => 0);
141
        if (portal_allow($clientip, $clientmac,$voucher,null,$attr)) {
142

    
143
            // YES: user is good for $timecredit minutes.
144
            captiveportal_logportalauth($voucher,$clientmac,$clientip,"Voucher login good for $timecredit min.");
145
        } else {
146
            portal_reply_page($redirurl, "error", $config['voucher']['msgexpired'] ? $config['voucher']['msgexpired']: $errormsg);
147
        }
148
    } else if (-1 == $timecredit) {  // valid but expired
149
        captiveportal_logportalauth($voucher,$clientmac,$clientip,"FAILURE","voucher expired");
150
        portal_reply_page($redirurl, "error", $config['voucher']['msgexpired'] ? $config['voucher']['msgexpired']: $errormsg);
151
    } else {
152
        captiveportal_logportalauth($voucher,$clientmac,$clientip,"FAILURE");
153
        portal_reply_page($redirurl, "error", $config['voucher']['msgnoaccess'] ? $config['voucher']['msgnoaccess'] : $errormsg);
154
    }
155

    
156
} else if ($_POST['accept'] && $radius_enable) {
157

    
158
    if ($_POST['auth_user'] && $_POST['auth_pass']) {
159
        $auth_list = radius($_POST['auth_user'],$_POST['auth_pass'],$clientip,$clientmac,"USER LOGIN");
160
	$type = "error";
161
	if (!empty($auth_list['url_redirection'])) {
162
		$redirurl = $auth_list['url_redirection'];
163
		$type = "redir";
164
	}
165

    
166
        if ($auth_list['auth_val'] == 1) {
167
            captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"ERROR",$auth_list['error']);
168
 	    portal_reply_page($redirurl, $type, $auth_list['error'] ? $auth_list['error'] : $errormsg);
169
        }
170
        else if ($auth_list['auth_val'] == 3) {
171
            captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"FAILURE",$auth_list['reply_message']);
172
            portal_reply_page($redirurl, $type, $auth_list['reply_message'] ? $auth_list['reply_message'] : $errormsg);
173
        }
174
    } else {
175
        captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"ERROR");
176
        portal_reply_page($redirurl, "error", $errormsg);
177
    }
178

    
179
} else if ($_POST['accept'] && $config['captiveportal']['auth_method'] == "local") {
180

    
181
	//check against local user manager
182
	$loginok = local_backed($_POST['auth_user'], $_POST['auth_pass']);
183
    if ($loginok){
184
        captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"LOGIN");
185
        portal_allow($clientip, $clientmac,$_POST['auth_user']);
186
    } else {
187
        captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"FAILURE");
188
        portal_reply_page($redirurl, "error", $errormsg);
189
    }
190
} else if ($_POST['accept'] && $clientip) {
191
    captiveportal_logportalauth("unauthenticated",$clientmac,$clientip,"ACCEPT");
192
    portal_allow($clientip, $clientmac, "unauthenticated");
193
} else {
194
    /* display captive portal page */
195
    portal_reply_page($redirurl, "login",null,$clientmac,$clientip);
196
}
197

    
198
exit;
199

    
200
function portal_reply_page($redirurl, $type = null, $message = null, $clientmac = null, $clientip = null, $username = null, $password = null) {
201
	global $g, $config;
202

    
203
	/* Get captive portal layout */
204
	if ($type == "redir") {
205
		header("Location: {$redirurl}");
206
		return;
207
	} else if ($type == "login")
208
		$htmltext = get_include_contents("{$g['varetc_path']}/captiveportal.html");
209
	else
210
		$htmltext = get_include_contents("{$g['varetc_path']}/captiveportal-error.html");
211

    
212
	/* substitute other variables */
213
	if (isset($config['captiveportal']['httpslogin'])) {
214
		$htmltext = str_replace("\$PORTAL_ACTION\$", "https://{$config['captiveportal']['httpsname']}:8001/", $htmltext);
215
		$htmltext = str_replace("#PORTAL_ACTION#", "https://{$config['captiveportal']['httpsname']}:8001/", $htmltext);
216
	} else {
217
		$ifip = portal_ip_from_client_ip($clientip);
218
		if (!$ifip)
219
			$ourhostname = $config['system']['hostname'] . ":8000";
220
		else
221
			$ourhostname = "{$ifip}:8000";
222
		$htmltext = str_replace("\$PORTAL_ACTION\$", "http://{$ourhostname}/", $htmltext);
223
		$htmltext = str_replace("#PORTAL_ACTION#", "http://{$ourhostname}/", $htmltext);
224
	}
225

    
226
	$htmltext = str_replace("\$PORTAL_REDIRURL\$", htmlspecialchars($redirurl), $htmltext);
227
	$htmltext = str_replace("\$PORTAL_MESSAGE\$", htmlspecialchars($message), $htmltext);
228
	$htmltext = str_replace("\$CLIENT_MAC\$", htmlspecialchars($clientmac), $htmltext);
229
	$htmltext = str_replace("\$CLIENT_IP\$", htmlspecialchars($clientip), $htmltext);
230

    
231
	// Special handling case for captive portal master page so that it can be ran 
232
	// through the PHP interpreter using the include method above.  We convert the
233
	// $VARIABLE$ case to #VARIABLE# in /etc/inc/captiveportal.inc before writing out.
234
	$htmltext = str_replace("#PORTAL_REDIRURL#", htmlspecialchars($redirurl), $htmltext);
235
	$htmltext = str_replace("#PORTAL_MESSAGE#", htmlspecialchars($message), $htmltext);
236
	$htmltext = str_replace("#CLIENT_MAC#", htmlspecialchars($clientmac), $htmltext);
237
	$htmltext = str_replace("#CLIENT_IP#", htmlspecialchars($clientip), $htmltext);
238
	$htmltext = str_replace("#USERNAME#", htmlspecialchars($username), $htmltext);
239
	$htmltext = str_replace("#PASSWORD#", htmlspecialchars($password), $htmltext);
240

    
241
    echo $htmltext;
242
}
243

    
244
function portal_mac_radius($clientmac,$clientip) {
245
    global $config ;
246

    
247
    $radmac_secret = $config['captiveportal']['radmac_secret'];
248

    
249
    /* authentication against the radius server */
250
    $username = mac_format($clientmac);
251
    $auth_list = radius($username,$radmac_secret,$clientip,$clientmac,"MACHINE LOGIN");
252
    if ($auth_list['auth_val'] == 2)
253
        return TRUE;
254
    if (!empty($auth_list['url_redirection']))
255
	portal_reply_page($auth_list['url_redirection'], "redir");
256

    
257
    return FALSE;
258
}
259

    
260
function portal_allow($clientip,$clientmac,$username,$password = null, $attributes = null, $ruleno = null)  {
261

    
262
	global $redirurl, $g, $config, $type, $passthrumac, $_POST;
263

    
264
	/* See if a ruleno is passed, if not start locking the sessions because this means there isn't one atm */
265
	$captiveshouldunlock = false;
266
	if ($ruleno == null) {
267
		$cplock = lock('captiveportal');
268
		$captiveshouldunlock = true;
269
		$ruleno = captiveportal_get_next_ipfw_ruleno();
270
	}
271

    
272
	/* if the pool is empty, return appropriate message and exit */
273
	if (is_null($ruleno)) {
274
		portal_reply_page($redirurl, "error", "System reached maximum login capacity");
275
		log_error("WARNING!  Captive portal has reached maximum login capacity");
276
		if ($captiveshouldunlock == true)
277
		unlock($cplock);
278
		exit;
279
	}
280

    
281
	// Ensure we create an array if we are missing attributes
282
	if (!is_array($attributes))
283
		$attributes = array();
284

    
285
	/* read in client database */
286
	$cpdb = captiveportal_read_db();
287

    
288
	$radiusservers = captiveportal_get_radius_servers();
289

    
290
	if ($attributes['voucher'])
291
		$remaining_time = $attributes['session_timeout'];
292

    
293
	$writecfg = false;
294
	/* Find an existing session */
295
	if ((isset($config['captiveportal']['noconcurrentlogins'])) && $passthrumac) {
296
		if (isset($config['captiveportal']['passthrumacadd'])) {
297
			$mac = captiveportal_passthrumac_findbyname($username);
298
			if (!empty($mac)) {
299
				if ($_POST['replacemacpassthru']) {
300
					foreach ($config['captiveportal']['passthrumac'] as $idx => $macent) {
301
						if ($macent['mac'] == $mac['mac']) {
302
							$macrules = "";
303
							$ruleno = captiveportal_get_ipfw_passthru_ruleno($mac['mac']);
304
                                			if ($ruleno) {
305
								captiveportal_free_ipfw_ruleno($ruleno, true);
306
                                        			$macrules .= "delete {$ruleno}\n";
307
								++$ruleno;
308
                                        			$macrules .= "delete {$ruleno}\n";
309
                                			}
310
							unset($config['captiveportal']['passthrumac'][$idx]);
311
							$mac['mac'] = $clientmac;
312
							$config['captiveportal']['passthrumac'][] = $mac;
313
							$macrules .= captiveportal_passthrumac_configure_entry($mac);
314
							file_put_contents("{$g['tmp_path']}/macentry.rules.tmp", $macrules);
315
							mwexec("/sbin/ipfw -q {$g['tmp_path']}/macentry.rules.tmp");
316
							$writecfg = true;
317
							$sessionid = true;
318
							break;
319
						}
320
					}
321
                                } else {
322
					portal_reply_page($redirurl, "error", "Username: {$username} is already authenticated using another MAC address.",
323
						$clientmac, $clientip, $username, $password);
324
					exit;
325
				}
326
			}
327
		}
328
	}
329

    
330
	$nousers = count($cpdb);
331
	for ($i = 0; $i < $nousers; $i++) {
332
		/* on the same ip */
333
		if($cpdb[$i][2] == $clientip) {
334
			captiveportal_logportalauth($cpdb[$i][4],$cpdb[$i][3],$cpdb[$i][2],"CONCURRENT LOGIN - REUSING OLD SESSION");
335
			$sessionid = $cpdb[$i][5];
336
			break;
337
		}
338
		elseif (($attributes['voucher']) && ($username != 'unauthenticated') && ($cpdb[$i][4] == $username)) {
339
			// user logged in with an active voucher. Check for how long and calculate 
340
			// how much time we can give him (voucher credit - used time)
341
			$remaining_time = $cpdb[$i][0] + $cpdb[$i][7] - time();
342
			if ($remaining_time < 0)    // just in case. 
343
				$remaining_time = 0;
344

    
345
			/* This user was already logged in so we disconnect the old one */
346
			captiveportal_disconnect($cpdb[$i],$radiusservers,13);
347
			captiveportal_logportalauth($cpdb[$i][4],$cpdb[$i][3],$cpdb[$i][2],"CONCURRENT LOGIN - TERMINATING OLD SESSION");
348
			unset($cpdb[$i]);
349
			break;
350
		}
351
		elseif ((isset($config['captiveportal']['noconcurrentlogins'])) && ($username != 'unauthenticated')) {
352
			/* on the same username */
353
			if (strcasecmp($cpdb[$i][4], $username) == 0) {
354
				/* This user was already logged in so we disconnect the old one */
355
				captiveportal_disconnect($cpdb[$i],$radiusservers,13);
356
				captiveportal_logportalauth($cpdb[$i][4],$cpdb[$i][3],$cpdb[$i][2],"CONCURRENT LOGIN - TERMINATING OLD SESSION");
357
				unset($cpdb[$i]);
358
				break;
359
			}
360
		}
361
	}
362

    
363
	if ($attributes['voucher'] && $remaining_time <= 0) {
364
		unlock($cplock);
365
		return 0;       // voucher already used and no time left
366
	}
367

    
368
	if (!isset($sessionid)) {
369

    
370
		/* generate unique session ID */
371
		$tod = gettimeofday();
372
		$sessionid = substr(md5(mt_rand() . $tod['sec'] . $tod['usec'] . $clientip . $clientmac), 0, 16);
373

    
374
		/* Add rules for traffic shaping
375
		 * We don't need to add extra rules since traffic will pass due to the following kernel option
376
		 * net.inet.ip.fw.one_pass: 1
377
		 */
378
		$peruserbw = isset($config['captiveportal']['peruserbw']);
379

    
380
		$bw_up = isset($attributes['bw_up']) ? trim($attributes['bw_up']) : $config['captiveportal']['bwdefaultup'];
381
		$bw_down = isset($attributes['bw_down']) ? trim($attributes['bw_down']) : $config['captiveportal']['bwdefaultdn'];
382

    
383
		if ($passthrumac) {
384
			$mac = array();
385
			$mac['mac'] = $clientmac;
386
			if (isset($config['captiveportal']['passthrumacaddusername']))
387
				$mac['username'] = $username;
388
			$mac['descr'] =  "Auto added pass-through MAC for user {$username}";
389
			if (!empty($bw_up))
390
				$mac['bw_up'] = $bw_up;
391
			if (!empty($bw_down))
392
				$mac['bw_down'] = $bw_down;
393
			if (!is_array($config['captiveportal']['passthrumac']))
394
				$config['captiveportal']['passthrumac'] = array();
395
			$config['captiveportal']['passthrumac'][] = $mac;
396
			$macrules = captiveportal_passthrumac_configure_entry($mac);
397
			file_put_contents("{$g['tmp_path']}/macentry.rules.tmp", $macrules);
398
			mwexec("/sbin/ipfw -q {$g['tmp_path']}/macentry.rules.tmp");
399
			$writecfg = true;
400
		} else {
401

    
402
			if ($peruserbw && !empty($bw_up) && is_numeric($bw_up)) {
403
				$bw_up_pipeno = $ruleno + 20000;
404
				//$bw_up /= 1000; // Scale to Kbit/s
405
				mwexec("/sbin/ipfw pipe {$bw_up_pipeno} config bw {$bw_up}Kbit/s queue 100");
406

    
407
				if (!isset($config['captiveportal']['nomacfilter']))
408
					mwexec("/sbin/ipfw table 1 add {$clientip} mac {$clientmac} {$bw_up_pipeno}");
409
				else
410
					mwexec("/sbin/ipfw table 1 add {$clientip} {$bw_up_pipeno}");
411
			} else {
412
				if (!isset($config['captiveportal']['nomacfilter']))
413
					mwexec("/sbin/ipfw table 1 add {$clientip} mac {$clientmac}");
414
				else
415
					mwexec("/sbin/ipfw table 1 add {$clientip}");
416
			}
417
			if ($peruserbw && !empty($bw_down) && is_numeric($bw_down)) {
418
				$bw_down_pipeno = $ruleno + 20001;
419
				//$bw_down /= 1000; // Scale to Kbit/s
420
				mwexec("/sbin/ipfw pipe {$bw_down_pipeno} config bw {$bw_down}Kbit/s queue 100");
421

    
422
				if (!isset($config['captiveportal']['nomacfilter']))
423
					mwexec("/sbin/ipfw table 2 add {$clientip} mac {$clientmac} {$bw_down_pipeno}");
424
				else
425
					mwexec("/sbin/ipfw table 2 add {$clientip} {$bw_down_pipeno}");
426
			} else {
427
				if (!isset($config['captiveportal']['nomacfilter']))
428
					mwexec("/sbin/ipfw table 2 add {$clientip} mac {$clientmac}");
429
				else
430
					mwexec("/sbin/ipfw table 2 add {$clientip}");
431
			}
432

    
433
			if ($attributes['voucher'])
434
				$attributes['session_timeout'] = $remaining_time;
435

    
436
			/* encode password in Base64 just in case it contains commas */
437
			$bpassword = base64_encode($password);
438
			$cpdb[] = array(time(), $ruleno, $clientip, $clientmac, $username, $sessionid, $bpassword,
439
				$attributes['session_timeout'], $attributes['idle_timeout'], $attributes['session_terminate_time']);
440

    
441
			if (isset($config['captiveportal']['radacct_enable']) && !empty($radiusservers)) {
442
				$acct_val = RADIUS_ACCOUNTING_START($ruleno,
443
                                		$username, $sessionid, $radiusservers, $clientip, $clientmac);
444

    
445
				if ($acct_val == 1)
446
					captiveportal_logportalauth($username,$clientmac,$clientip,$type,"RADIUS ACCOUNTING FAILED");
447
			}
448

    
449
			/* rewrite information to database */
450
			captiveportal_write_db($cpdb);
451
		}
452
	}
453

    
454
	if ($captiveshouldunlock == true)
455
		unlock($cplock);
456

    
457
	if ($writecfg == true)
458
		write_config();
459

    
460
	/* redirect user to desired destination */
461
	if (!empty($attributes['url_redirection']))
462
		$my_redirurl = $attributes['url_redirection'];
463
	else if ($config['captiveportal']['redirurl'])
464
		$my_redirurl = $config['captiveportal']['redirurl'];
465
	else
466
		$my_redirurl = $redirurl;
467

    
468
	if(isset($config['captiveportal']['logoutwin_enable']) && !$passthrumac) {
469

    
470
		if (isset($config['captiveportal']['httpslogin']))
471
			$logouturl = "https://{$config['captiveportal']['httpsname']}:8001/";
472
		else {
473
			$ifip = portal_ip_from_client_ip($clientip);
474
			if (!$ifip)
475
				$ourhostname = $config['system']['hostname'] . ":8000";
476
			else
477
				$ourhostname = "{$ifip}:8000";
478
			$logouturl = "http://{$ourhostname}/";
479
		}
480

    
481
		if (isset($attributes['reply_message']))
482
			$message = $attributes['reply_message'];
483
		else
484
			$message = 0;
485

    
486
		include("{$g['varetc_path']}/captiveportal-logout.html");
487

    
488
	} else {
489
		header("Location: " . $my_redirurl);
490
	}
491

    
492
	return $sessionid;
493
}
494

    
495

    
496

    
497
/* remove a single client by session ID
498
   by Dinesh Nair
499
 */
500
function disconnect_client($sessionid, $logoutReason = "LOGOUT", $term_cause = 1) {
501

    
502
    global $g, $config;
503

    
504
    $cplock = lock('captiveportal');
505
    /* read database */
506
    $cpdb = captiveportal_read_db();
507

    
508
    $radiusservers = captiveportal_get_radius_servers();
509

    
510
    /* find entry */
511
    $dbcount = count($cpdb);
512
    for ($i = 0; $i < $dbcount; $i++) {
513
        if ($cpdb[$i][5] == $sessionid) {
514
            captiveportal_disconnect($cpdb[$i],$radiusservers, $term_cause);
515
            captiveportal_logportalauth($cpdb[$i][4],$cpdb[$i][3],$cpdb[$i][2],$logoutReason);
516
            unset($cpdb[$i]);
517
            break;
518
        }
519
    }
520

    
521
    /* write database */
522
    captiveportal_write_db($cpdb);
523

    
524
    unlock($cplock);
525
}
526

    
527
?>
(1-1/3)