1
|
<?php
|
2
|
/*
|
3
|
* authgui.inc
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2003-2006 Manuel Kasper <mk@neon1.net>
|
7
|
* Copyright (c) 2005-2006 Bill Marquette <bill.marquette@gmail.com>
|
8
|
* Copyright (c) 2006 Paul Taylor <paultaylor@winn-dixie.com>
|
9
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
10
|
* All rights reserved.
|
11
|
*
|
12
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
13
|
* you may not use this file except in compliance with the License.
|
14
|
* You may obtain a copy of the License at
|
15
|
*
|
16
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17
|
*
|
18
|
* Unless required by applicable law or agreed to in writing, software
|
19
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
20
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
21
|
* See the License for the specific language governing permissions and
|
22
|
* limitations under the License.
|
23
|
*/
|
24
|
|
25
|
include_once("auth.inc");
|
26
|
include_once("priv.inc");
|
27
|
if (!function_exists('platform_booting')) {
|
28
|
require_once('globals.inc');
|
29
|
}
|
30
|
|
31
|
/* Authenticate user - exit if failed */
|
32
|
if (!session_auth()) {
|
33
|
display_login_form();
|
34
|
exit;
|
35
|
}
|
36
|
|
37
|
/*
|
38
|
* Once here, the user has authenticated with the web server.
|
39
|
* We give them access only to the appropriate pages based on
|
40
|
* the user or group privileges.
|
41
|
*/
|
42
|
$allowedpages = getAllowedPages($_SESSION['Username'], $_SESSION['user_radius_attributes']);
|
43
|
|
44
|
/*
|
45
|
* Get user-based preference settings so they can be easily referenced.
|
46
|
*/
|
47
|
$user_settings = get_user_settings($_SESSION['Username']);
|
48
|
|
49
|
/*
|
50
|
* redirect to first allowed page if requesting a wrong url
|
51
|
*/
|
52
|
|
53
|
/* Fix this up otherwise the privilege check will fail. See Redmine #5909. */
|
54
|
if ($_SERVER['REQUEST_URI'] == "/") {
|
55
|
$_SERVER['REQUEST_URI'] = "/index.php";
|
56
|
}
|
57
|
|
58
|
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
|
59
|
if (count($allowedpages) > 0) {
|
60
|
$page = str_replace('*', '', $allowedpages[0]);
|
61
|
$_SESSION['Post_Login'] = true;
|
62
|
require_once("functions.inc");
|
63
|
pfSenseHeader("/{$page}");
|
64
|
|
65
|
$username = empty($_SESSION["Username"]) ? "(system)" : $_SESSION['Username'];
|
66
|
if (!empty($_SERVER['REMOTE_ADDR'])) {
|
67
|
$username .= '@' . $_SERVER['REMOTE_ADDR'];
|
68
|
}
|
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
|
/*
|
81
|
* redirect browsers post-login to avoid pages
|
82
|
* taking action in response to a POST request
|
83
|
*/
|
84
|
if (!$_SESSION['Post_Login']) {
|
85
|
$_SESSION['Post_Login'] = true;
|
86
|
require_once("functions.inc");
|
87
|
pfSenseHeader($_SERVER['REQUEST_URI']);
|
88
|
exit;
|
89
|
}
|
90
|
|
91
|
/*
|
92
|
* Close session data to allow other scripts from same host to come in.
|
93
|
* A session can be reactivated from calling session_start again
|
94
|
*/
|
95
|
session_commit();
|
96
|
|
97
|
/*
|
98
|
* determine if the user is allowed access to the requested page
|
99
|
*/
|
100
|
function display_error_form($http_code, $desc) {
|
101
|
global $config, $user_settings, $g;
|
102
|
|
103
|
if (isAjax()) {
|
104
|
printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
|
105
|
return;
|
106
|
}
|
107
|
|
108
|
$cssfile = "/css/pfSense.css";
|
109
|
|
110
|
if (isset($user_settings['webgui']['webguicss'])) {
|
111
|
if (file_exists("/usr/local/www/css/" . $user_settings['webgui']['webguicss'])) {
|
112
|
$cssfile = "/css/" . $user_settings['webgui']['webguicss'];
|
113
|
}
|
114
|
}
|
115
|
|
116
|
?>
|
117
|
<!DOCTYPE html>
|
118
|
<html lang="en">
|
119
|
<head>
|
120
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
121
|
<link rel="stylesheet" href="<?=$cssfile?>" />
|
122
|
<title><?=gettext("Error: not allowed"); ?></title>
|
123
|
</head>
|
124
|
<body id="error" class="no-menu">
|
125
|
<div id="jumbotron">
|
126
|
<div class="container">
|
127
|
<div class="col-sm-offset-3 col-sm-6 col-xs-12">
|
128
|
<!-- FIXME: We really need to POST the logout action -->
|
129
|
<div class="alert alert-danger" role="alert"><a href="index.php?logout"><?=$desc;?></a></div>
|
130
|
</div>
|
131
|
</div>
|
132
|
</div>
|
133
|
</body>
|
134
|
</html>
|
135
|
<?php
|
136
|
|
137
|
} // end function
|
138
|
|
139
|
|
140
|
function display_login_form() {
|
141
|
require_once("globals.inc");
|
142
|
global $config, $g;
|
143
|
|
144
|
unset($input_errors);
|
145
|
|
146
|
if (isAjax()) {
|
147
|
if (isset($_POST['login'])) {
|
148
|
if ($_SESSION['Logged_In'] <> "True") {
|
149
|
isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = gettext("unknown reason");
|
150
|
printf("showajaxmessage('" . gettext("Invalid login (%s).") . "')", $login_error);
|
151
|
}
|
152
|
if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
|
153
|
// TODO: add the IP from the user who did lock the device
|
154
|
$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
|
155
|
printf("showajaxmessage('" . gettext("This device is currently being maintained by: %s.") . "');", $whom);
|
156
|
}
|
157
|
}
|
158
|
exit;
|
159
|
}
|
160
|
|
161
|
/* Check against locally configured IP addresses, which will catch when someone
|
162
|
port forwards WebGUI access from WAN to an internal IP on the router. */
|
163
|
global $FilterIflist, $nifty_background;
|
164
|
$local_ip = false;
|
165
|
if (strpos($_SERVER['HTTP_HOST'], ":") === FALSE) {
|
166
|
$http_host_port = explode(":", $_SERVER['HTTP_HOST']);
|
167
|
$http_host = $http_host_port[0];
|
168
|
} else {
|
169
|
$http_host = $_SERVER['HTTP_HOST'];
|
170
|
}
|
171
|
if (empty($FilterIflist)) {
|
172
|
require_once('filter.inc');
|
173
|
require_once('shaper.inc');
|
174
|
filter_generate_optcfg_array();
|
175
|
}
|
176
|
foreach ($FilterIflist as $iflist) {
|
177
|
if ($iflist['ip'] == $http_host) {
|
178
|
$local_ip = true;
|
179
|
} else if ($iflist['ipv6'] == $http_host) {
|
180
|
$local_ip = true;
|
181
|
} else if (is_array($iflist['vips'])) {
|
182
|
foreach ($iflist['vips'] as $vip) {
|
183
|
if ($vip['ip'] == $http_host) {
|
184
|
$local_ip = true;
|
185
|
break;
|
186
|
}
|
187
|
}
|
188
|
unset($vip);
|
189
|
}
|
190
|
if ($local_ip == true) {
|
191
|
break;
|
192
|
}
|
193
|
}
|
194
|
unset($FilterIflist);
|
195
|
unset($iflist);
|
196
|
|
197
|
if ($local_ip == false) {
|
198
|
if (is_array($config['openvpn']['openvpn-server'])) {
|
199
|
foreach ($config['openvpn']['openvpn-server'] as $ovpns) {
|
200
|
if (is_ipaddrv4($http_host) && !empty($ovpns['tunnel_network']) && ip_in_subnet($http_host, $ovpns['tunnel_network'])) {
|
201
|
$local_ip = true;
|
202
|
} else if (is_ipaddrv6($http_host) && !empty($ovpns['tunnel_networkv6']) && ip_in_subnet($http_host, $ovpns['tunnel_networkv6'])) {
|
203
|
$local_ip = true;
|
204
|
}
|
205
|
if ($local_ip == true) {
|
206
|
break;
|
207
|
}
|
208
|
}
|
209
|
}
|
210
|
}
|
211
|
|
212
|
// For the login form, get the settings of no particular user.
|
213
|
// That ensures we will use the system default theme for the login form.
|
214
|
$user_settings = get_user_settings("");
|
215
|
$cssfile = "/css/pfSense.css";
|
216
|
|
217
|
if (isset($user_settings['webgui']['webguicss'])) {
|
218
|
if (file_exists("/usr/local/www/css/" . $user_settings['webgui']['webguicss'])) {
|
219
|
$cssfile = "/css/" . $user_settings['webgui']['webguicss'];
|
220
|
}
|
221
|
}
|
222
|
|
223
|
if (isset($config['system']['webgui']['loginshowhost'])) {
|
224
|
$hoststr = sprintf(gettext(" on %s.%s"), htmlspecialchars($config['system']['hostname']), htmlspecialchars($config['system']['domain']));
|
225
|
} else {
|
226
|
$hoststr = "";
|
227
|
}
|
228
|
|
229
|
?>
|
230
|
<!DOCTYPE html>
|
231
|
<html lang="en">
|
232
|
<head>
|
233
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
234
|
<link rel="stylesheet" href="<?=$cssfile?>" />
|
235
|
<title><?=gettext("Login"); ?></title>
|
236
|
<script type="text/javascript">
|
237
|
//<![CDATA{
|
238
|
var events = events || [];
|
239
|
//]]>
|
240
|
</script>
|
241
|
</head>
|
242
|
<body id="login" class="no-menu">
|
243
|
<div id="jumbotron">
|
244
|
<div class="container">
|
245
|
<div class="col-sm-offset-3 col-sm-6 col-xs-12">
|
246
|
<?php
|
247
|
if (is_ipaddr($http_host) && !$local_ip && !isset($config['system']['webgui']['nohttpreferercheck'])) {
|
248
|
$nifty_background = "#999";
|
249
|
print_info_box(gettext("The IP address being used to access this router is not configured locally, which may be forwarded by NAT or other means. <br /><br />If this forwarding is unexpected, it should be verified that a man-in-the-middle attack is not taking place."));
|
250
|
}
|
251
|
|
252
|
$loginautocomplete = isset($config['system']['webgui']['loginautocomplete']) ? '' : 'autocomplete="off"';
|
253
|
?>
|
254
|
|
255
|
<div class="panel panel-default">
|
256
|
<div class="panel-heading">
|
257
|
<h2 class="panel-title"><?=sprintf(gettext("Login to %s %s"), $g['product_name'], $hoststr)?></h2>
|
258
|
</div>
|
259
|
|
260
|
<div class="panel-body">
|
261
|
<?php if (!empty($_SESSION['Login_Error'])): ?>
|
262
|
<div class="alert alert-danger" role="alert"><?=$_SESSION['Login_Error'];?></div>
|
263
|
<?php endif ?>
|
264
|
<div class="alert alert-warning hidden" id="no_cookies"><?= gettext("The browser must support cookies to login."); ?></div>
|
265
|
|
266
|
<form method="post" <?= $loginautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>" class="form-horizontal">
|
267
|
<div class="form-group">
|
268
|
<label for="usernamefld" class="col-sm-3 control-label"><?=gettext("Username")?></label>
|
269
|
<div class="col-sm-9 col-md-7">
|
270
|
<input type="text" class="form-control" name="usernamefld" id="usernamefld" placeholder="<?=gettext("Enter your username")?>" autocorrect="off" autocapitalize="none" spellcheck="false">
|
271
|
</div>
|
272
|
</div>
|
273
|
|
274
|
<div class="form-group">
|
275
|
<label for="passwordfld" class="col-sm-3 control-label"><?=gettext("Password")?></label>
|
276
|
<div class="col-sm-9 col-md-7">
|
277
|
<input type="password" class="form-control" name="passwordfld" id="passwordfld" placeholder="<?=gettext("Enter your password")?>">
|
278
|
</div>
|
279
|
</div>
|
280
|
|
281
|
<div class="form-group">
|
282
|
<div class="col-sm-offset-3 col-sm-9 col-md-7">
|
283
|
<button type="submit" class="btn btn-primary" name="login"><?=gettext("Login")?></button>
|
284
|
</div>
|
285
|
</div>
|
286
|
</form>
|
287
|
</div>
|
288
|
</div>
|
289
|
</div>
|
290
|
</div>
|
291
|
|
292
|
<script type="text/javascript">
|
293
|
//!<[CDATA[
|
294
|
events.push(function() {
|
295
|
document.cookie=
|
296
|
"cookie_test=1" +
|
297
|
"<?php echo $config['system']['webgui']['protocol'] == 'https' ? '; secure' : '';?>";
|
298
|
|
299
|
if (document.cookie.indexOf("cookie_test") == -1)
|
300
|
document.getElementById("no_cookies").style.display="";
|
301
|
else
|
302
|
document.getElementById("no_cookies").style.display="none";
|
303
|
|
304
|
// Delete it
|
305
|
document.cookie = "cookie_test=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
306
|
});
|
307
|
//]]>
|
308
|
</script>
|
309
|
<?php
|
310
|
require_once('foot.inc');
|
311
|
|
312
|
} // end function
|