Project

General

Profile

Download (8.31 KB) Statistics
| Branch: | Tag: | Revision:
1 8c1ce6c7 Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 65fbb388 Scott Ullrich
    $Id$
4
    part of m0n0wall (http://m0n0.ch/wall)
5
6 9568c1a1 Ermal Lu?i
    Copyrigth (C) 2009	    Ermal Lu?i
7 65fbb388 Scott Ullrich
    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 5b237745 Scott Ullrich
*/
31 f5024891 Scott Ullrich
/*
32
	pfSense_MODULE:	captiveportal
33
*/
34 5b237745 Scott Ullrich
35 0092b3bd mgrooms
require_once("auth.inc");
36 65fbb388 Scott Ullrich
require_once("functions.inc");
37 483e6de8 Scott Ullrich
require_once("captiveportal.inc");
38 65fbb388 Scott Ullrich
39 eb15decb Ermal
$errormsg = "Invalid credentials specified.";
40
41 65fbb388 Scott Ullrich
header("Expires: 0");
42
header("Cache-Control: no-store, no-cache, must-revalidate");
43
header("Cache-Control: post-check=0, pre-check=0", false);
44
header("Pragma: no-cache");
45 232846a2 Ermal
header("Connection: close");
46 5b237745 Scott Ullrich
47
$orig_host = $_ENV['HTTP_HOST'];
48 fe383a26 Ermal
$orig_request = $_REQUEST['redirurl'];
49 6fa4bdc6 Scott Ullrich
$clientip = $_SERVER['REMOTE_ADDR'];
50 5b237745 Scott Ullrich
51
if (!$clientip) {
52 c9cb32c4 Ermal
	/* not good - bail out */
53
	log_error("Captive portal could not determine client's IP address.");
54
	$error_message = "An error occurred.  Please check the system logs for more information.";
55
	portal_reply_page($redirurl, "error", $errormsg);
56
	exit;
57 65fbb388 Scott Ullrich
}
58
59
if (isset($config['captiveportal']['httpslogin']))
60
    $ourhostname = $config['captiveportal']['httpsname'] . ":8001";
61 f8b11310 Ermal Lu?i
else {
62
    $ifip = portal_ip_from_client_ip($clientip);
63
    if (!$ifip)
64
    	$ourhostname = $config['system']['hostname'] . ":8000";
65
    else
66
    	$ourhostname = "{$ifip}:8000";
67
}
68 65fbb388 Scott Ullrich
69
if ($orig_host != $ourhostname) {
70
    /* the client thinks it's connected to the desired web server, but instead
71
       it's connected to us. Issue a redirect... */
72
73
    if (isset($config['captiveportal']['httpslogin']))
74
        header("Location: https://{$ourhostname}/index.php?redirurl=" . urlencode("http://{$orig_host}{$orig_request}"));
75
    else
76
        header("Location: http://{$ourhostname}/index.php?redirurl=" . urlencode("http://{$orig_host}{$orig_request}"));
77
78
    exit;
79 5b237745 Scott Ullrich
}
80 8ebbae22 Ermal
if (!empty($config['captiveportal']['redirurl']))
81
	$redirurl = $config['captiveportal']['redirurl'];
82 8380e833 Ermal
else if (preg_match("/redirurl=(.*)/", $orig_request, $matches))
83
	$redirurl = urldecode($matches[1]);
84
else if ($_REQUEST['redirurl'])
85
	$redirurl = $_REQUEST['redirurl'];
86 65fbb388 Scott Ullrich
87
$macfilter = !isset($config['captiveportal']['nomacfilter']);
88 0852838c Ermal
$passthrumac = isset($config['captiveportal']['passthrumacadd']);
89 65fbb388 Scott Ullrich
90 5b237745 Scott Ullrich
/* find MAC address for client */
91
$clientmac = arp_get_mac_by_ip($clientip);
92 0852838c Ermal
if (!$clientmac && ($macfilter || $passthrumac)) {
93 65fbb388 Scott Ullrich
    /* unable to find MAC address - shouldn't happen! - bail out */
94
    captiveportal_logportalauth("unauthenticated","noclientmac",$clientip,"ERROR");
95 18cbd65f Chris Buechler
    echo "An error occurred.  Please check the system logs for more information.";
96 d102e3ed Chris Buechler
    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.");
97 65fbb388 Scott Ullrich
    exit;
98 5b237745 Scott Ullrich
}
99
100 65fbb388 Scott Ullrich
/* find out if we need RADIUS + RADIUSMAC or not */
101
if (file_exists("{$g['vardb_path']}/captiveportal_radius.db")) {
102
    $radius_enable = TRUE;
103 f8b11310 Ermal Lu?i
    if (isset($config['captiveportal']['radmac_enable']))
104 65fbb388 Scott Ullrich
        $radmac_enable = TRUE;
105
}
106 6e865a74 Scott Ullrich
107 65fbb388 Scott Ullrich
if ($_POST['logout_id']) {
108 532cb894 Ermal
	echo <<<EOD
109 5b237745 Scott Ullrich
<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 b2ce71ff Scott Ullrich
<B>You have been disconnected.</B>
114 5b237745 Scott Ullrich
</SPAN>
115
<SCRIPT LANGUAGE="JavaScript">
116
<!--
117
setTimeout('window.close();',5000) ;
118
-->
119
</SCRIPT>
120
</BODY>
121
</HTML>
122
123
EOD;
124 006802ab Ermal
	captiveportal_disconnect_client($_POST['logout_id']);
125 532cb894 Ermal
	exit;
126 65fbb388 Scott Ullrich
} else if ($clientmac && $radmac_enable && portal_mac_radius($clientmac,$clientip)) {
127
    /* radius functions handle everything so we exit here since we're done */
128
    exit;
129
130 8015e67b Erik Fonnesbeck
} else if (portal_consume_passthrough_credit($clientmac)) {
131
    /* allow the client through if it had a pass-through credit for its MAC */
132
    captiveportal_logportalauth("unauthenticated",$clientmac,$clientip,"ACCEPT");
133
    portal_allow($clientip, $clientmac, "unauthenticated");
134
135 336e3c1c Charlie
} else if ($_POST['accept'] && $_POST['auth_voucher']) {
136
137
    $voucher = trim($_POST['auth_voucher']);
138
    $timecredit = voucher_auth($voucher);
139
    // $timecredit contains either a credit in minutes or an error message
140
    if ($timecredit > 0) {  // voucher is valid. Remaining minutes returned
141
        // if multiple vouchers given, use the first as username
142
        $a_vouchers = split("[\t\n\r ]+",$voucher);
143
        $voucher = $a_vouchers[0];
144
        $attr = array( 'voucher' => 1,
145
                'session_timeout' => $timecredit*60,
146
                'session_terminate_time' => 0);
147
        if (portal_allow($clientip, $clientmac,$voucher,null,$attr)) {
148
149
            // YES: user is good for $timecredit minutes.
150 d102e3ed Chris Buechler
            captiveportal_logportalauth($voucher,$clientmac,$clientip,"Voucher login good for $timecredit min.");
151 336e3c1c Charlie
        } else {
152 eb15decb Ermal
            portal_reply_page($redirurl, "error", $config['voucher']['msgexpired'] ? $config['voucher']['msgexpired']: $errormsg);
153 336e3c1c Charlie
        }
154
    } else if (-1 == $timecredit) {  // valid but expired
155
        captiveportal_logportalauth($voucher,$clientmac,$clientip,"FAILURE","voucher expired");
156 eb15decb Ermal
        portal_reply_page($redirurl, "error", $config['voucher']['msgexpired'] ? $config['voucher']['msgexpired']: $errormsg);
157 336e3c1c Charlie
    } else {
158
        captiveportal_logportalauth($voucher,$clientmac,$clientip,"FAILURE");
159 eb15decb Ermal
        portal_reply_page($redirurl, "error", $config['voucher']['msgnoaccess'] ? $config['voucher']['msgnoaccess'] : $errormsg);
160 336e3c1c Charlie
    }
161
162 65fbb388 Scott Ullrich
} else if ($_POST['accept'] && $radius_enable) {
163
164
    if ($_POST['auth_user'] && $_POST['auth_pass']) {
165
        $auth_list = radius($_POST['auth_user'],$_POST['auth_pass'],$clientip,$clientmac,"USER LOGIN");
166 814992f7 Ermal
	$type = "error";
167
	if (!empty($auth_list['url_redirection'])) {
168
		$redirurl = $auth_list['url_redirection'];
169
		$type = "redir";
170
	}
171 65fbb388 Scott Ullrich
172
        if ($auth_list['auth_val'] == 1) {
173
            captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"ERROR",$auth_list['error']);
174 eb15decb Ermal
 	    portal_reply_page($redirurl, $type, $auth_list['error'] ? $auth_list['error'] : $errormsg);
175 65fbb388 Scott Ullrich
        }
176
        else if ($auth_list['auth_val'] == 3) {
177
            captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"FAILURE",$auth_list['reply_message']);
178 eb15decb Ermal
            portal_reply_page($redirurl, $type, $auth_list['reply_message'] ? $auth_list['reply_message'] : $errormsg);
179 65fbb388 Scott Ullrich
        }
180
    } else {
181
        captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"ERROR");
182 eb15decb Ermal
        portal_reply_page($redirurl, "error", $errormsg);
183 65fbb388 Scott Ullrich
    }
184 8c1ce6c7 Scott Ullrich
185 65fbb388 Scott Ullrich
} else if ($_POST['accept'] && $config['captiveportal']['auth_method'] == "local") {
186 8c1ce6c7 Scott Ullrich
187 0092b3bd mgrooms
	//check against local user manager
188
	$loginok = local_backed($_POST['auth_user'], $_POST['auth_pass']);
189 65fbb388 Scott Ullrich
    if ($loginok){
190
        captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"LOGIN");
191
        portal_allow($clientip, $clientmac,$_POST['auth_user']);
192
    } else {
193
        captiveportal_logportalauth($_POST['auth_user'],$clientmac,$clientip,"FAILURE");
194 eb15decb Ermal
        portal_reply_page($redirurl, "error", $errormsg);
195 65fbb388 Scott Ullrich
    }
196 c7b5a8cf Ermal
} else if ($_POST['accept'] && $clientip && $config['captiveportal']['auth_method'] == "none") {
197 65fbb388 Scott Ullrich
    captiveportal_logportalauth("unauthenticated",$clientmac,$clientip,"ACCEPT");
198
    portal_allow($clientip, $clientmac, "unauthenticated");
199
} else {
200
    /* display captive portal page */
201 4993f81c Chris Buechler
    portal_reply_page($redirurl, "login",null,$clientmac,$clientip);
202 5b237745 Scott Ullrich
}
203
204
exit;
205
206 03552507 Erik Fonnesbeck
207 60b66b60 Ermal
?>