1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
Copyright (C) 2007, 2008 Scott Ullrich <sullrich@gmail.com>
|
5
|
All rights reserved.
|
6
|
|
7
|
Copyright (C) 2005-2006 Bill Marquette <bill.marquette@gmail.com>
|
8
|
All rights reserved.
|
9
|
|
10
|
Copyright (C) 2006 Paul Taylor <paultaylor@winn-dixie.com>.
|
11
|
All rights reserved.
|
12
|
|
13
|
Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
|
14
|
All rights reserved.
|
15
|
|
16
|
Redistribution and use in source and binary forms, with or without
|
17
|
modification, are permitted provided that the following conditions are met:
|
18
|
|
19
|
1. Redistributions of source code must retain the above copyright notice,
|
20
|
this list of conditions and the following disclaimer.
|
21
|
|
22
|
2. Redistributions in binary form must reproduce the above copyright
|
23
|
notice, this list of conditions and the following disclaimer in the
|
24
|
documentation and/or other materials provided with the distribution.
|
25
|
|
26
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
27
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
28
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
29
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
30
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
31
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
32
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
33
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
34
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35
|
POSSIBILITY OF SUCH DAMAGE.
|
36
|
|
37
|
pfSense_MODULE: authgui
|
38
|
*/
|
39
|
|
40
|
include_once("auth.inc");
|
41
|
include_once("priv.inc");
|
42
|
|
43
|
/* Authenticate user - exit if failed */
|
44
|
if (!session_auth()) {
|
45
|
display_login_form();
|
46
|
exit;
|
47
|
}
|
48
|
|
49
|
/*
|
50
|
* Once here, the user has authenticated with the web server.
|
51
|
* We give them access only to the appropriate pages based on
|
52
|
* the user or group privileges.
|
53
|
*/
|
54
|
$allowedpages = getAllowedPages($_SESSION['Username']);
|
55
|
|
56
|
/*
|
57
|
* redirect to first allowed page if requesting a wrong url
|
58
|
*/
|
59
|
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
|
60
|
if (count($allowedpages) > 0) {
|
61
|
$page = str_replace('*', '', $allowedpages[0]);
|
62
|
$_SESSION['Post_Login'] = true;
|
63
|
require_once("functions.inc");
|
64
|
pfSenseHeader("/{$page}");
|
65
|
|
66
|
$username = empty($_SESSION["Username"]) ? "(system)" : $_SESSION['Username'];
|
67
|
if (!empty($_SERVER['REMOTE_ADDR']))
|
68
|
$username .= '@' . $_SERVER['REMOTE_ADDR'];
|
69
|
log_error("{$username} attempted to access {$_SERVER['SCRIPT_NAME']} but does not have access to that page. Redirecting to {$page}.");
|
70
|
|
71
|
exit;
|
72
|
} else {
|
73
|
display_error_form("201", gettext("No page assigned to this user! Click here to logout."));
|
74
|
exit;
|
75
|
}
|
76
|
} else
|
77
|
$_SESSION['Post_Login'] = true;
|
78
|
|
79
|
/*
|
80
|
* redirect browsers post-login to avoid pages
|
81
|
* taking action in reponse to a POST request
|
82
|
*/
|
83
|
if (!$_SESSION['Post_Login']) {
|
84
|
$_SESSION['Post_Login'] = true;
|
85
|
require_once("functions.inc");
|
86
|
pfSenseHeader($_SERVER['REQUEST_URI']);
|
87
|
exit;
|
88
|
}
|
89
|
|
90
|
/*
|
91
|
* Close session data to allow other scripts from same host to come in.
|
92
|
* A session can be reactivated from calling session_start again
|
93
|
*/
|
94
|
session_commit();
|
95
|
|
96
|
/*
|
97
|
* determine if the user is allowed access to the requested page
|
98
|
*/
|
99
|
function display_error_form($http_code, $desc) {
|
100
|
global $config, $g;
|
101
|
$g['theme'] = get_current_theme();
|
102
|
if(isAjax()) {
|
103
|
printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
|
104
|
return;
|
105
|
}
|
106
|
|
107
|
?>
|
108
|
|
109
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
110
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
111
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
112
|
<head>
|
113
|
<script type="text/javascript" src="/javascript/jquery.js"></script>
|
114
|
<title><?=$http_code?></title>
|
115
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
116
|
<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
|
117
|
<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
|
118
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
|
119
|
<?php else: ?>
|
120
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
|
121
|
<?php endif; ?>
|
122
|
<script type="text/javascript">
|
123
|
//<![CDATA[
|
124
|
function page_load() {}
|
125
|
function clearError() {
|
126
|
if($('#inputerrors'))
|
127
|
$('#inputerrors').html('');
|
128
|
}
|
129
|
<?php
|
130
|
require("headjs.php");
|
131
|
echo getHeadJS();
|
132
|
?>
|
133
|
//]]>
|
134
|
</script>
|
135
|
<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
|
136
|
</head>
|
137
|
<body onload="page_load();">
|
138
|
<div id="errordesc">
|
139
|
<h1> </h1>
|
140
|
<a href="/index.php?logout">
|
141
|
<p id="errortext" style="vertical-align: middle; text-align: center;">
|
142
|
<span style="color: #000000; font-weight: bold;">
|
143
|
<?=$desc;?>
|
144
|
</span>
|
145
|
</p>
|
146
|
</div>
|
147
|
</body>
|
148
|
</html>
|
149
|
|
150
|
<?php
|
151
|
|
152
|
} // end function
|
153
|
|
154
|
|
155
|
function display_login_form() {
|
156
|
require_once("globals.inc");
|
157
|
global $config, $g;
|
158
|
$g['theme'] = get_current_theme();
|
159
|
|
160
|
unset($input_errors);
|
161
|
|
162
|
if(isAjax()) {
|
163
|
if (isset($_POST['login'])) {
|
164
|
if($_SESSION['Logged_In'] <> "True") {
|
165
|
isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = gettext("unknown reason");
|
166
|
printf("showajaxmessage('" . gettext("Invalid login (%s).") . "')", $login_error);
|
167
|
}
|
168
|
if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
|
169
|
// TODO: add the IP from the user who did lock the device
|
170
|
$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
|
171
|
printf("showajaxmessage('" . gettext("This device is currently being maintained by: %s.") . "');", $whom);
|
172
|
}
|
173
|
}
|
174
|
exit;
|
175
|
}
|
176
|
|
177
|
/* Check against locally configured IP addresses, which will catch when someone
|
178
|
port forwards WebGUI access from WAN to an internal IP on the router. */
|
179
|
global $FilterIflist, $nifty_background;
|
180
|
$local_ip = false;
|
181
|
if(strstr($_SERVER['HTTP_HOST'], ":")) {
|
182
|
$http_host_port = explode(":", $_SERVER['HTTP_HOST']);
|
183
|
$http_host = $http_host_port[0];
|
184
|
} else {
|
185
|
$http_host = $_SERVER['HTTP_HOST'];
|
186
|
}
|
187
|
if (empty($FilterIflist)) {
|
188
|
require_once('filter.inc');
|
189
|
require_once('shaper.inc');
|
190
|
filter_generate_optcfg_array();
|
191
|
}
|
192
|
foreach ($FilterIflist as $iflist) {
|
193
|
if($iflist['ip'] == $http_host)
|
194
|
$local_ip = true;
|
195
|
if($iflist['ipv6'] == $http_host)
|
196
|
$local_ip = true;
|
197
|
}
|
198
|
unset($FilterIflist);
|
199
|
|
200
|
if($config['virtualip']) {
|
201
|
if($config['virtualip']['vip']) {
|
202
|
foreach($config['virtualip']['vip'] as $vip) {
|
203
|
if($vip['subnet'] == $http_host)
|
204
|
$local_ip = true;
|
205
|
}
|
206
|
}
|
207
|
}
|
208
|
if (is_array($config['openvpn']['openvpn-server'])) {
|
209
|
foreach ($config['openvpn']['openvpn-server'] as $ovpns) {
|
210
|
if (is_ipaddrv4($http_host) && !empty($ovpns['tunnel_network']) && ip_in_subnet($http_host, $ovpns['tunnel_network'])) {
|
211
|
$local_ip = true;
|
212
|
break;
|
213
|
}
|
214
|
|
215
|
if (is_ipaddrv6($http_host) && !empty($ovpns['tunnel_networkv6']) && ip_in_subnet($http_host, $ovpns['tunnel_networkv6'])) {
|
216
|
$local_ip = true;
|
217
|
break;
|
218
|
}
|
219
|
}
|
220
|
}
|
221
|
setcookie("cookie_test", time() + 3600);
|
222
|
$have_cookies = isset($_COOKIE["cookie_test"]);
|
223
|
|
224
|
?>
|
225
|
|
226
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
227
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
228
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
229
|
<head>
|
230
|
<script type="text/javascript" src="/javascript/jquery.js"></script>
|
231
|
<script type="text/javascript">
|
232
|
//<![CDATA[
|
233
|
$(document).ready(function() { jQuery('#usernamefld').focus(); });
|
234
|
//]]>
|
235
|
</script>
|
236
|
|
237
|
<title><?=gettext("Login"); ?></title>
|
238
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
239
|
<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
|
240
|
<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
|
241
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
|
242
|
<?php else: ?>
|
243
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
|
244
|
<?php endif; ?>
|
245
|
<script type="text/javascript">
|
246
|
//<![CDATA[
|
247
|
function page_load() {}
|
248
|
function clearError() {
|
249
|
if($('#inputerrors'))
|
250
|
$('#inputerrors').html('');
|
251
|
}
|
252
|
<?php
|
253
|
require("headjs.php");
|
254
|
echo getHeadJS();
|
255
|
?>
|
256
|
//]]>
|
257
|
</script>
|
258
|
<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
|
259
|
</head>
|
260
|
<body onload="page_load()">
|
261
|
<div id="login">
|
262
|
<?php
|
263
|
if(is_ipaddr($http_host) && !$local_ip && !isset($config['system']['webgui']['nohttpreferercheck'])) {
|
264
|
$nifty_background = "#999";
|
265
|
print_info_box(gettext("You are accessing this router by an IP address not configured locally, which may be forwarded by NAT or other means. <br /><br />If you did not setup this forwarding, you may be the target of a man-in-the-middle attack."));
|
266
|
}
|
267
|
$noautocomplete = isset($config['system']['webgui']['noautocomplete']) ? 'autocomplete="off"' : '';
|
268
|
?>
|
269
|
<form id="iform" name="iform" method="post" <?= $noautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>">
|
270
|
<h1> </h1>
|
271
|
<div id="inputerrors"><?=$_SESSION['Login_Error'];?></div>
|
272
|
<p>
|
273
|
<span style="text-align:left">
|
274
|
<?=gettext("Username:"); ?><br />
|
275
|
<input onclick="clearError();" onchange="clearError();" id="usernamefld" type="text" name="usernamefld" class="formfld user" tabindex="1" />
|
276
|
</span>
|
277
|
</p>
|
278
|
<p>
|
279
|
<br />
|
280
|
<span style="text-align:left">
|
281
|
<?=gettext("Password:"); ?> <br />
|
282
|
<input onclick="clearError();" onchange="clearError();" id="passwordfld" type="password" name="passwordfld" class="formfld pwd" tabindex="2" />
|
283
|
</span>
|
284
|
</p>
|
285
|
<p>
|
286
|
<br />
|
287
|
<span style="text-align:center; font-weight: normal ; font-style: italic">
|
288
|
<?=gettext("Enter username and password to login."); ?>
|
289
|
</span>
|
290
|
|
291
|
<?php if (!$have_cookies && isset($_POST['login'])): ?>
|
292
|
<br /><br />
|
293
|
<span style="text-align:center; font-weight: normal ; font-style: italic; color: #ff0000">
|
294
|
<?= gettext("Your browser must support cookies to login."); ?>
|
295
|
</span>
|
296
|
<?php endif; ?>
|
297
|
</p>
|
298
|
<p>
|
299
|
<span style="text-align:center">
|
300
|
<input type="submit" name="login" class="formbtn" value="<?=gettext("Login"); ?>" tabindex="3" />
|
301
|
</span>
|
302
|
</p>
|
303
|
</form>
|
304
|
</div>
|
305
|
</body>
|
306
|
</html>
|
307
|
<?php
|
308
|
} // end function
|
309
|
|
310
|
?>
|