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-2013 BSD Perimeter
|
10
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
11
|
* Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
|
12
|
* All rights reserved.
|
13
|
*
|
14
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
15
|
* you may not use this file except in compliance with the License.
|
16
|
* You may obtain a copy of the License at
|
17
|
*
|
18
|
* http://www.apache.org/licenses/LICENSE-2.0
|
19
|
*
|
20
|
* Unless required by applicable law or agreed to in writing, software
|
21
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
22
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
23
|
* See the License for the specific language governing permissions and
|
24
|
* limitations under the License.
|
25
|
*/
|
26
|
|
27
|
include_once("auth.inc");
|
28
|
include_once("config.inc");
|
29
|
include_once("config.lib.inc");
|
30
|
include_once("priv.inc");
|
31
|
if (!function_exists('platform_booting')) {
|
32
|
require_once('globals.inc');
|
33
|
}
|
34
|
require_once('pfsense-utils.inc');
|
35
|
|
36
|
/* Authenticate user - exit if failed */
|
37
|
if (!session_auth()) {
|
38
|
display_login_form();
|
39
|
exit;
|
40
|
}
|
41
|
|
42
|
phpsession_begin();
|
43
|
|
44
|
/*
|
45
|
* Once here, the user has authenticated with the web server.
|
46
|
* We give them access only to the appropriate pages based on
|
47
|
* the user or group privileges.
|
48
|
*/
|
49
|
$allowedpages = getAllowedPages($_SESSION['Username'], $_SESSION['user_radius_attributes']);
|
50
|
|
51
|
/*
|
52
|
* Get user-based preference settings so they can be easily referenced.
|
53
|
*/
|
54
|
$user_settings = get_user_settings($_SESSION['Username']);
|
55
|
|
56
|
/*
|
57
|
* redirect to first allowed page if requesting a wrong url
|
58
|
*/
|
59
|
|
60
|
/* Fix this up otherwise the privilege check will fail. See Redmine #5909. */
|
61
|
if ($_SERVER['REQUEST_URI'] == "/") {
|
62
|
$_SERVER['REQUEST_URI'] = "/index.php";
|
63
|
}
|
64
|
|
65
|
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
|
66
|
if (count($allowedpages) > 0) {
|
67
|
$page = str_replace('*', '', $allowedpages[0]);
|
68
|
$_SESSION['Post_Login'] = true;
|
69
|
require_once("functions.inc");
|
70
|
pfSenseHeader("/{$page}");
|
71
|
|
72
|
$username = get_config_user();
|
73
|
log_error("{$username} attempted to access {$_SERVER['SCRIPT_NAME']} but does not have access to that page. Redirecting to {$page}.");
|
74
|
|
75
|
exit;
|
76
|
} else {
|
77
|
// add this so they don't get stuck on the logout page when they have no permissions.
|
78
|
$_SESSION["Logged_In"] = false;
|
79
|
display_error_form("201", gettext("No page assigned to this user! Click here to logout."));
|
80
|
|
81
|
exit;
|
82
|
}
|
83
|
} else {
|
84
|
$_SESSION['Post_Login'] = true;
|
85
|
}
|
86
|
|
87
|
/*
|
88
|
* redirect browsers post-login to avoid pages
|
89
|
* taking action in response to a POST request
|
90
|
*/
|
91
|
if (!$_SESSION['Post_Login']) {
|
92
|
$_SESSION['Post_Login'] = true;
|
93
|
require_once("functions.inc");
|
94
|
pfSenseHeader($_SERVER['REQUEST_URI']);
|
95
|
exit;
|
96
|
}
|
97
|
|
98
|
/*
|
99
|
* Close session data to allow other scripts from same host to come in.
|
100
|
* A session can be reactivated from calling phpsession_begin again
|
101
|
*/
|
102
|
phpsession_end(true);
|
103
|
|
104
|
/*
|
105
|
* determine if the user is allowed access to the requested page
|
106
|
*/
|
107
|
function display_error_form($http_code, $desc) {
|
108
|
if (isAjax()) {
|
109
|
printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
|
110
|
return;
|
111
|
}
|
112
|
|
113
|
$logincssfile = "#770101";
|
114
|
?>
|
115
|
|
116
|
<!DOCTYPE html>
|
117
|
<html lang="en">
|
118
|
<head>
|
119
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
120
|
<link rel="stylesheet" href="/vendor/bootstrap/css/bootstrap.min.css" type="text/css">
|
121
|
<link rel="stylesheet" href="/css/login.css?v=<?=filemtime('/usr/local/www/css/login.css')?>" type="text/css">
|
122
|
<title><?=gettext("Error"); ?></title>
|
123
|
</head>
|
124
|
|
125
|
<body id="error" >
|
126
|
<div id="total">
|
127
|
<header>
|
128
|
<div id="headerrow">
|
129
|
<div class="row">
|
130
|
<div class="col-sm-4">
|
131
|
<div id="logodiv" style="text-align:center" class="nowarning">
|
132
|
<?php include("/usr/local/www/logo.svg"); ?>
|
133
|
</div>
|
134
|
</div>
|
135
|
<div class="col-sm-8 nowarning msgbox text-center">
|
136
|
<span id="hostspan">
|
137
|
</span>
|
138
|
</div>
|
139
|
</div>
|
140
|
</div>
|
141
|
</header>
|
142
|
|
143
|
<div style="background: <?=$logincssfile?>;" class="pagebody">
|
144
|
<div class="col-sm-2"></div>
|
145
|
|
146
|
<div class="col-sm-8 offset-md-4 logoCol">
|
147
|
<div class="loginCont center-block error-panel">
|
148
|
<a href="index.php?logout"><?=$desc;?></a>
|
149
|
</div>
|
150
|
</div>
|
151
|
|
152
|
<div class="col-sm-2"></div>
|
153
|
</div>
|
154
|
|
155
|
<footer id="3">
|
156
|
<div id="footertext">
|
157
|
<p class="text-muted">
|
158
|
<?=print_credit()?>
|
159
|
</p>
|
160
|
</div>
|
161
|
</footer>
|
162
|
</div>
|
163
|
</body>
|
164
|
</html>
|
165
|
|
166
|
<?php
|
167
|
|
168
|
} // end function
|
169
|
|
170
|
|
171
|
function display_login_form() {
|
172
|
require_once("globals.inc");
|
173
|
global $g;
|
174
|
|
175
|
unset($input_errors);
|
176
|
|
177
|
if (isAjax()) {
|
178
|
if (isset($_POST['login'])) {
|
179
|
if ($_SESSION['Logged_In'] <> "True") {
|
180
|
isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = gettext("unknown reason");
|
181
|
printf("showajaxmessage('" . gettext("Invalid login (%s).") . "')", $login_error);
|
182
|
}
|
183
|
if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
|
184
|
// TODO: add the IP from the user who did lock the device
|
185
|
$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
|
186
|
printf("showajaxmessage('" . gettext("This device is currently being maintained by: %s.") . "');", $whom);
|
187
|
}
|
188
|
}
|
189
|
//If session ended
|
190
|
echo "SESSION_TIMEOUT";
|
191
|
exit;
|
192
|
}
|
193
|
|
194
|
/* Check against locally configured IP addresses, which will catch when someone
|
195
|
port forwards WebGUI access from WAN to an internal IP on the router. */
|
196
|
global $FilterIflist;
|
197
|
|
198
|
$local_ip = false;
|
199
|
|
200
|
if (strpos($_SERVER['HTTP_HOST'], ":") === FALSE) {
|
201
|
$http_host_port = explode(":", $_SERVER['HTTP_HOST']);
|
202
|
$http_host = $http_host_port[0];
|
203
|
} else {
|
204
|
$http_host = $_SERVER['HTTP_HOST'];
|
205
|
}
|
206
|
|
207
|
if (empty($FilterIflist)) {
|
208
|
require_once('filter.inc');
|
209
|
require_once('shaper.inc');
|
210
|
filter_generate_optcfg_array();
|
211
|
}
|
212
|
|
213
|
foreach ($FilterIflist as $iflist) {
|
214
|
if ($iflist['ip'] == $http_host) {
|
215
|
$local_ip = true;
|
216
|
} else if ($iflist['ipv6'] == $http_host) {
|
217
|
$local_ip = true;
|
218
|
} else if (is_array($iflist['vips'])) {
|
219
|
foreach ($iflist['vips'] as $vip) {
|
220
|
if ($vip['ip'] == $http_host) {
|
221
|
$local_ip = true;
|
222
|
break;
|
223
|
}
|
224
|
}
|
225
|
|
226
|
unset($vip);
|
227
|
}
|
228
|
|
229
|
if ($local_ip == true) {
|
230
|
break;
|
231
|
}
|
232
|
}
|
233
|
|
234
|
unset($FilterIflist);
|
235
|
unset($iflist);
|
236
|
|
237
|
if ($local_ip == false) {
|
238
|
foreach (config_get_path('openvpn/openvpn-server', []) as $ovpns) {
|
239
|
if (is_ipaddrv4($http_host) && !empty($ovpns['tunnel_network']) && ip_in_subnet($http_host, $ovpns['tunnel_network'])) {
|
240
|
$local_ip = true;
|
241
|
} else if (is_ipaddrv6($http_host) && !empty($ovpns['tunnel_networkv6']) && ip_in_subnet($http_host, $ovpns['tunnel_networkv6'])) {
|
242
|
$local_ip = true;
|
243
|
}
|
244
|
|
245
|
if ($local_ip == true) {
|
246
|
break;
|
247
|
}
|
248
|
}
|
249
|
}
|
250
|
|
251
|
// For the login form, get the settings of no particular user.
|
252
|
// That ensures we will use the system default theme for the login form.
|
253
|
$user_settings = get_user_settings("");
|
254
|
$logincssfile = "#1e3f75";
|
255
|
|
256
|
if (isset($user_settings['webgui']['logincss']) && strlen($user_settings['webgui']['logincss']) == 6) {
|
257
|
$logincssfile = "#" . $user_settings['webgui']['logincss'];
|
258
|
}
|
259
|
|
260
|
if (config_path_enabled('system/webgui','loginshowhost')) {
|
261
|
$loginbannerstr = sprintf(gettext('%1$s.%2$s'),
|
262
|
htmlspecialchars(config_get_path('system/hostname', "")),
|
263
|
htmlspecialchars(config_get_path('system/domain', "")));
|
264
|
$login_title = gettext(htmlspecialchars(config_get_path('system/hostname', "") . " - Login"));
|
265
|
} Else {
|
266
|
$loginbannerstr = sprintf(gettext('Login to %1$s'), $g['product_label']);
|
267
|
$login_title = sprintf(gettext("%s - Login"), $g['product_label']);
|
268
|
}
|
269
|
|
270
|
$loginautocomplete = config_path_enabled('system/webgui','loginautocomplete') ? '' : 'autocomplete="off"';
|
271
|
|
272
|
if (is_ipaddr($http_host) && !$local_ip &&
|
273
|
!config_path_enabled('system/webgui','nohttpreferercheck')) {
|
274
|
$warnclass = "pagebodywarn"; // Make room for a warning display row
|
275
|
} else {
|
276
|
$warnclass = "pagebody";
|
277
|
}
|
278
|
?>
|
279
|
<!DOCTYPE html>
|
280
|
<html lang="en">
|
281
|
<head>
|
282
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
283
|
<link rel="stylesheet" href="/vendor/bootstrap/css/bootstrap.min.css" type="text/css">
|
284
|
<link rel="stylesheet" href="/css/login.css?v=<?=filemtime('/usr/local/www/css/login.css')?>" type="text/css">
|
285
|
<title><?=$login_title; ?></title>
|
286
|
<script type="text/javascript">
|
287
|
//<![CDATA{
|
288
|
var events = events || [];
|
289
|
//]]>
|
290
|
</script>
|
291
|
</head>
|
292
|
|
293
|
<body id="login" >
|
294
|
<div id="total">
|
295
|
<header>
|
296
|
<div id="headerrow">
|
297
|
<div class="row">
|
298
|
<!-- Header left logo box -->
|
299
|
<div class="col-sm-4">
|
300
|
<div id="logodiv" style="text-align:center" class="nowarning">
|
301
|
<?php include("/usr/local/www/logo.svg"); ?>
|
302
|
</div>
|
303
|
</div>
|
304
|
|
305
|
<!-- Header center message box -->
|
306
|
<div class="col-sm-4 nowarning msgbox text-center text-danger">
|
307
|
<?php
|
308
|
if (!empty($_POST['usernamefld'])) {
|
309
|
print("<h4>" . $_SESSION['Login_Error'] . "</h4>");
|
310
|
}
|
311
|
?>
|
312
|
</div>
|
313
|
|
314
|
<!-- Header right message box (hostname or msg)-->
|
315
|
<div class="col-sm-4 nowarning msgbox text-center">
|
316
|
<span id="hostspan">
|
317
|
<h4><?=$loginbannerstr?></h4>
|
318
|
</span>
|
319
|
</div>
|
320
|
</div>
|
321
|
<?php
|
322
|
if ($warnclass == "pagebodywarn") {
|
323
|
?>
|
324
|
<div class="row">
|
325
|
<div class="col-sm-12">
|
326
|
<div class="alert alert-warning <?=$warnclass?>">
|
327
|
<?=gettext("The IP address being used to access this router is not configured locally, which may be forwarded by NAT or other means.
|
328
|
If this forwarding is unexpected, it should be verified that a man-in-the-middle attack is not taking place.")?>
|
329
|
</div>
|
330
|
</div>
|
331
|
</div>
|
332
|
<?php
|
333
|
}
|
334
|
?>
|
335
|
</div>
|
336
|
</header>
|
337
|
|
338
|
<div style="background: <?=$logincssfile?>;" class="<?=$warnclass?>">
|
339
|
<div class="col-sm-4"></div>
|
340
|
|
341
|
<div class="col-sm-4 offset-md-4 logoCol">
|
342
|
<div class="loginCont center-block">
|
343
|
<form method="post" <?=$loginautocomplete?> class="login">
|
344
|
<p class="form-title">Sign In</p>
|
345
|
<input name="usernamefld" id="usernamefld" type="text" placeholder="Username" autocorrect="off" autocapitalize="none"/>
|
346
|
<input name="passwordfld" id="passwordfld" type="password" placeholder="Password" />
|
347
|
<input type="submit" name="login" value="Sign In" class="btn btn-success btn-sm" />
|
348
|
</form>
|
349
|
</div>
|
350
|
</div>
|
351
|
|
352
|
<div class="col-sm-4"></div>
|
353
|
</div>
|
354
|
|
355
|
<footer id="3">
|
356
|
<div id="footertext">
|
357
|
<p class="text-muted">
|
358
|
<?=print_credit()?>
|
359
|
</p>
|
360
|
</div>
|
361
|
</footer>
|
362
|
</div>
|
363
|
|
364
|
<script type="text/javascript">
|
365
|
//<![CDATA[
|
366
|
/* Prevent duplicate submission */
|
367
|
events.push(function() {
|
368
|
var submitted = false;
|
369
|
|
370
|
$(form).submit(function(e){
|
371
|
if (submitted) {
|
372
|
e.preventDefault();
|
373
|
} else {
|
374
|
submitted = true;
|
375
|
// Form is submitted because default action is not prevented
|
376
|
}
|
377
|
});
|
378
|
});
|
379
|
//]]>
|
380
|
</script>
|
381
|
|
382
|
<script src="/vendor/jquery/jquery-3.5.1.min.js?v=<?=filemtime('/usr/local/www/vendor/jquery/jquery-3.5.1.min.js')?>"></script>
|
383
|
<script src="/vendor/bootstrap/js/bootstrap.min.js?v=<?=filemtime('/usr/local/www/vendor/bootstrap/js/bootstrap.min.js')?>"></script>
|
384
|
<script src="/js/pfSense.js?v=<?=filemtime('/usr/local/www/js/pfSense.js')?>"></script>
|
385
|
|
386
|
<script type="text/javascript">
|
387
|
//!<[CDATA[
|
388
|
events.push(function() {
|
389
|
document.cookie=
|
390
|
"cookie_test=1" +
|
391
|
"<?php echo config_get_path('system/webgui/protocol') == 'https' ? '; secure' : '';?>";
|
392
|
|
393
|
if (document.cookie.indexOf("cookie_test") == -1) {
|
394
|
alert("<?=gettext('The browser must support cookies to login.')?>");
|
395
|
}
|
396
|
|
397
|
// Delete it
|
398
|
document.cookie = "cookie_test=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
399
|
});
|
400
|
//]]>
|
401
|
</script>
|
402
|
|
403
|
</body>
|
404
|
</html>
|
405
|
|
406
|
<?php
|
407
|
} // end function
|