Project

General

Profile

Download (20 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

    
80
if (preg_match("/redirurl=(.*)/", $orig_request, $matches))
81
    $redirurl = urldecode($matches[1]);
82
if ($_POST['redirurl'])
83
    $redirurl = $_POST['redirurl'];
84

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

    
88
/* find MAC address for client */
89
$clientmac = arp_get_mac_by_ip($clientip);
90
if (!$clientmac && ($macfilter || $passthrumac)) {
91
    /* unable to find MAC address - shouldn't happen! - bail out */
92
    captiveportal_logportalauth("unauthenticated","noclientmac",$clientip,"ERROR");
93
    echo "An error occurred.  Please check the system logs for more information.";
94
    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.");
95
    exit;
96
}
97

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

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

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

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

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

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

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

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

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

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

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

    
197
exit;
198

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

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

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

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

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

    
240
    echo $htmltext;
241
}
242

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

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

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

    
256
    return FALSE;
257
}
258

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

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

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

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

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

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

    
287
	$radiusservers = captiveportal_get_radius_servers();
288

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
482
	} else {
483
		if($_POST['ORIGINAL_PORTAL_IP'] && $_SERVER['SERVER_NAME'] != $_POST['ORIGINAL_PORTAL_IP']) {
484
 			header ('HTTP/1.1 301 Moved Permanently');
485
			header("Location: " . $_POST['ORIGINAL_PORTAL_IP']);
486
		} else {
487
			header("Location: " . $my_redirurl);
488
		}
489
	}
490

    
491
	return $sessionid;
492
}
493

    
494

    
495

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

    
501
    global $g, $config;
502

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

    
507
    $radiusservers = captiveportal_get_radius_servers();
508

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

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

    
523
    unlock($cplock);
524
}
525

    
526
?>
(1-1/3)