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
|
if (!function_exists('platform_booting'))
|
43
|
require_once('globals.inc');
|
44
|
|
45
|
/* Authenticate user - exit if failed */
|
46
|
if (!session_auth()) {
|
47
|
display_login_form();
|
48
|
exit;
|
49
|
}
|
50
|
|
51
|
/*
|
52
|
* Once here, the user has authenticated with the web server.
|
53
|
* We give them access only to the appropriate pages based on
|
54
|
* the user or group privileges.
|
55
|
*/
|
56
|
$allowedpages = getAllowedPages($_SESSION['Username'], $_SESSION['user_radius_attributes']);
|
57
|
|
58
|
/*
|
59
|
* redirect to first allowed page if requesting a wrong url
|
60
|
*/
|
61
|
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
|
62
|
if (count($allowedpages) > 0) {
|
63
|
$page = str_replace('*', '', $allowedpages[0]);
|
64
|
$_SESSION['Post_Login'] = true;
|
65
|
require_once("functions.inc");
|
66
|
pfSenseHeader("/{$page}");
|
67
|
|
68
|
$username = empty($_SESSION["Username"]) ? "(system)" : $_SESSION['Username'];
|
69
|
if (!empty($_SERVER['REMOTE_ADDR']))
|
70
|
$username .= '@' . $_SERVER['REMOTE_ADDR'];
|
71
|
log_error("{$username} attempted to access {$_SERVER['SCRIPT_NAME']} but does not have access to that page. Redirecting to {$page}.");
|
72
|
|
73
|
exit;
|
74
|
} else {
|
75
|
display_error_form("201", gettext("No page assigned to this user! Click here to logout."));
|
76
|
exit;
|
77
|
}
|
78
|
} else
|
79
|
$_SESSION['Post_Login'] = true;
|
80
|
|
81
|
/*
|
82
|
* redirect browsers post-login to avoid pages
|
83
|
* taking action in reponse to a POST request
|
84
|
*/
|
85
|
if (!$_SESSION['Post_Login']) {
|
86
|
$_SESSION['Post_Login'] = true;
|
87
|
require_once("functions.inc");
|
88
|
pfSenseHeader($_SERVER['REQUEST_URI']);
|
89
|
exit;
|
90
|
}
|
91
|
|
92
|
/*
|
93
|
* Close session data to allow other scripts from same host to come in.
|
94
|
* A session can be reactivated from calling session_start again
|
95
|
*/
|
96
|
session_commit();
|
97
|
|
98
|
/*
|
99
|
* determine if the user is allowed access to the requested page
|
100
|
*/
|
101
|
function display_error_form($http_code, $desc) {
|
102
|
global $config, $g;
|
103
|
$g['theme'] = get_current_theme();
|
104
|
if(isAjax()) {
|
105
|
printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
|
106
|
return;
|
107
|
}
|
108
|
|
109
|
?>
|
110
|
|
111
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
112
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
113
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
114
|
<head>
|
115
|
<script type="text/javascript" src="/javascript/jquery-1.11.1.min.js"></script>
|
116
|
<script type="text/javascript" src="/javascript/jquery-migrate-1.2.1.min.js"></script>
|
117
|
<title><?=$http_code?></title>
|
118
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
119
|
<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
|
120
|
<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
|
121
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
|
122
|
<?php else: ?>
|
123
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
|
124
|
<?php endif; ?>
|
125
|
<script type="text/javascript">
|
126
|
//<![CDATA[
|
127
|
function page_load() {}
|
128
|
function clearError() {
|
129
|
if($('#inputerrors'))
|
130
|
$('#inputerrors').html('');
|
131
|
}
|
132
|
<?php
|
133
|
require("headjs.php");
|
134
|
echo getHeadJS();
|
135
|
?>
|
136
|
//]]>
|
137
|
</script>
|
138
|
<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
|
139
|
</head>
|
140
|
<body onload="page_load();">
|
141
|
<div id="errordesc">
|
142
|
<h1> </h1>
|
143
|
<a href="/index.php?logout">
|
144
|
<p id="errortext" style="vertical-align: middle; text-align: center;">
|
145
|
<span style="color: #000000; font-weight: bold;">
|
146
|
<?=$desc;?>
|
147
|
</span>
|
148
|
</p>
|
149
|
</div>
|
150
|
</body>
|
151
|
</html>
|
152
|
|
153
|
<?php
|
154
|
|
155
|
} // end function
|
156
|
|
157
|
|
158
|
function display_login_form() {
|
159
|
require_once("globals.inc");
|
160
|
global $config, $g;
|
161
|
$g['theme'] = get_current_theme();
|
162
|
|
163
|
unset($input_errors);
|
164
|
|
165
|
if(isAjax()) {
|
166
|
if (isset($_POST['login'])) {
|
167
|
if($_SESSION['Logged_In'] <> "True") {
|
168
|
isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = gettext("unknown reason");
|
169
|
printf("showajaxmessage('" . gettext("Invalid login (%s).") . "')", $login_error);
|
170
|
}
|
171
|
if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
|
172
|
// TODO: add the IP from the user who did lock the device
|
173
|
$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
|
174
|
printf("showajaxmessage('" . gettext("This device is currently being maintained by: %s.") . "');", $whom);
|
175
|
}
|
176
|
}
|
177
|
exit;
|
178
|
}
|
179
|
|
180
|
/* Check against locally configured IP addresses, which will catch when someone
|
181
|
port forwards WebGUI access from WAN to an internal IP on the router. */
|
182
|
global $FilterIflist, $nifty_background;
|
183
|
$local_ip = false;
|
184
|
if (strpos($_SERVER['HTTP_HOST'], ":") === FALSE) {
|
185
|
$http_host_port = explode(":", $_SERVER['HTTP_HOST']);
|
186
|
$http_host = $http_host_port[0];
|
187
|
} else {
|
188
|
$http_host = $_SERVER['HTTP_HOST'];
|
189
|
}
|
190
|
if (empty($FilterIflist)) {
|
191
|
require_once('filter.inc');
|
192
|
require_once('shaper.inc');
|
193
|
filter_generate_optcfg_array();
|
194
|
}
|
195
|
foreach ($FilterIflist as $iflist) {
|
196
|
if ($iflist['ip'] == $http_host)
|
197
|
$local_ip = true;
|
198
|
else if ($iflist['ipv6'] == $http_host)
|
199
|
$local_ip = true;
|
200
|
else if (is_array($iflist['vips'])) {
|
201
|
foreach ($iflist['vips'] as $vip) {
|
202
|
if ($vip['ip'] == $http_host) {
|
203
|
$local_ip = true;
|
204
|
break;
|
205
|
}
|
206
|
}
|
207
|
unset($vip);
|
208
|
}
|
209
|
if ($local_ip == true)
|
210
|
break;
|
211
|
}
|
212
|
unset($FilterIflist);
|
213
|
unset($iflist);
|
214
|
|
215
|
if ($local_ip == false) {
|
216
|
if (is_array($config['openvpn']['openvpn-server'])) {
|
217
|
foreach ($config['openvpn']['openvpn-server'] as $ovpns) {
|
218
|
if (is_ipaddrv4($http_host) && !empty($ovpns['tunnel_network']) && ip_in_subnet($http_host, $ovpns['tunnel_network'])) {
|
219
|
$local_ip = true;
|
220
|
} else if (is_ipaddrv6($http_host) && !empty($ovpns['tunnel_networkv6']) && ip_in_subnet($http_host, $ovpns['tunnel_networkv6'])) {
|
221
|
$local_ip = true;
|
222
|
}
|
223
|
if ($local_ip == true)
|
224
|
break;
|
225
|
}
|
226
|
}
|
227
|
}
|
228
|
|
229
|
?>
|
230
|
|
231
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
232
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
233
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
234
|
<head>
|
235
|
<script type="text/javascript" src="/javascript/jquery-1.11.1.min.js"></script>
|
236
|
<script type="text/javascript" src="/javascript/jquery-migrate-1.2.1.min.js"></script>
|
237
|
<script type="text/javascript">
|
238
|
//<![CDATA[
|
239
|
$(document).ready(function() { jQuery('#usernamefld').focus(); });
|
240
|
//]]>
|
241
|
</script>
|
242
|
|
243
|
<title><?=gettext("Login"); ?></title>
|
244
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
245
|
<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
|
246
|
<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
|
247
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
|
248
|
<?php else: ?>
|
249
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
|
250
|
<?php endif; ?>
|
251
|
<script type="text/javascript">
|
252
|
//<![CDATA[
|
253
|
function page_load() {}
|
254
|
function clearError() {
|
255
|
if($('#inputerrors'))
|
256
|
$('#inputerrors').html('');
|
257
|
}
|
258
|
<?php
|
259
|
require("headjs.php");
|
260
|
echo getHeadJS();
|
261
|
?>
|
262
|
//]]>
|
263
|
</script>
|
264
|
<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
|
265
|
</head>
|
266
|
<body onload="page_load()">
|
267
|
<div id="login">
|
268
|
<?php
|
269
|
if(is_ipaddr($http_host) && !$local_ip && !isset($config['system']['webgui']['nohttpreferercheck'])) {
|
270
|
$nifty_background = "#999";
|
271
|
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."));
|
272
|
}
|
273
|
$loginautocomplete = isset($config['system']['webgui']['loginautocomplete']) ? '' : 'autocomplete="off"';
|
274
|
?>
|
275
|
<form id="iform" name="iform" method="post" <?= $loginautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>">
|
276
|
<h1> </h1>
|
277
|
<div id="inputerrors"><?=$_SESSION['Login_Error'];?></div>
|
278
|
<p>
|
279
|
<span style="text-align:left">
|
280
|
<?=gettext("Username:"); ?><br />
|
281
|
<input onclick="clearError();" onchange="clearError();" id="usernamefld" type="text" name="usernamefld" class="formfld user" tabindex="1" />
|
282
|
</span>
|
283
|
</p>
|
284
|
<p>
|
285
|
<br />
|
286
|
<span style="text-align:left">
|
287
|
<?=gettext("Password:"); ?> <br />
|
288
|
<input onclick="clearError();" onchange="clearError();" id="passwordfld" type="password" name="passwordfld" class="formfld pwd" tabindex="2" />
|
289
|
</span>
|
290
|
</p>
|
291
|
<p>
|
292
|
<br />
|
293
|
<span style="text-align:center; font-weight: normal ; font-style: italic">
|
294
|
<?=gettext("Enter username and password to login."); ?>
|
295
|
</span>
|
296
|
|
297
|
<span style="text-align:center; font-weight: normal ; font-style: italic; color: #ff0000; display:none" id="no_cookies">
|
298
|
<br /><br />
|
299
|
<?= gettext("Your browser must support cookies to login."); ?>
|
300
|
</span>
|
301
|
</p>
|
302
|
<p>
|
303
|
<span style="text-align:center">
|
304
|
<input type="submit" name="login" class="formbtn" value="<?=gettext("Login"); ?>" tabindex="3" />
|
305
|
</span>
|
306
|
</p>
|
307
|
</form>
|
308
|
</div>
|
309
|
<script type="text/javascript">
|
310
|
//<![CDATA[
|
311
|
document.cookie=
|
312
|
"cookie_test=1" +
|
313
|
"<?php echo $config['system']['webgui']['protocol'] == 'https' ? '; secure' : '';?>";
|
314
|
|
315
|
if (document.cookie.indexOf("cookie_test") == -1)
|
316
|
document.getElementById("no_cookies").style.display="";
|
317
|
|
318
|
// Delete it
|
319
|
document.cookie = "cookie_test=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
320
|
//]]>
|
321
|
</script>
|
322
|
</body>
|
323
|
</html>
|
324
|
<?php
|
325
|
} // end function
|
326
|
|
327
|
?>
|