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
|
|
46
|
/* Authenticate user - exit if failed */
|
47
|
if (!session_auth()) {
|
48
|
display_login_form();
|
49
|
exit;
|
50
|
}
|
51
|
|
52
|
/*
|
53
|
* Once here, the user has authenticated with the web server.
|
54
|
* We give them access only to the appropriate pages based on
|
55
|
* the user or group privileges.
|
56
|
*/
|
57
|
$allowedpages = getAllowedPages($_SESSION['Username'], $_SESSION['user_radius_attributes']);
|
58
|
|
59
|
/*
|
60
|
* redirect to first allowed page if requesting a wrong url
|
61
|
*/
|
62
|
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
|
63
|
if (count($allowedpages) > 0) {
|
64
|
$page = str_replace('*', '', $allowedpages[0]);
|
65
|
$_SESSION['Post_Login'] = true;
|
66
|
require_once("functions.inc");
|
67
|
pfSenseHeader("/{$page}");
|
68
|
|
69
|
$username = empty($_SESSION["Username"]) ? "(system)" : $_SESSION['Username'];
|
70
|
if (!empty($_SERVER['REMOTE_ADDR'])) {
|
71
|
$username .= '@' . $_SERVER['REMOTE_ADDR'];
|
72
|
}
|
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
|
display_error_form("201", gettext("No page assigned to this user! Click here to logout."));
|
78
|
exit;
|
79
|
}
|
80
|
} else {
|
81
|
$_SESSION['Post_Login'] = true;
|
82
|
}
|
83
|
|
84
|
/*
|
85
|
* redirect browsers post-login to avoid pages
|
86
|
* taking action in response to a POST request
|
87
|
*/
|
88
|
if (!$_SESSION['Post_Login']) {
|
89
|
$_SESSION['Post_Login'] = true;
|
90
|
require_once("functions.inc");
|
91
|
pfSenseHeader($_SERVER['REQUEST_URI']);
|
92
|
exit;
|
93
|
}
|
94
|
|
95
|
/*
|
96
|
* Close session data to allow other scripts from same host to come in.
|
97
|
* A session can be reactivated from calling session_start again
|
98
|
*/
|
99
|
session_commit();
|
100
|
|
101
|
/*
|
102
|
* determine if the user is allowed access to the requested page
|
103
|
*/
|
104
|
function display_error_form($http_code, $desc) {
|
105
|
global $config, $g;
|
106
|
$g['theme'] = get_current_theme();
|
107
|
if (isAjax()) {
|
108
|
printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
|
109
|
return;
|
110
|
}
|
111
|
|
112
|
?>
|
113
|
<<<<<<< HEAD
|
114
|
<!DOCTYPE html>
|
115
|
<html lang="en">
|
116
|
<head>
|
117
|
<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
|
118
|
<title><?=gettext("Error: not allowed"); ?></title>
|
119
|
</head>
|
120
|
<body id="error" class="no-menu">
|
121
|
<div id="jumbotron">
|
122
|
<div class="container">
|
123
|
<div class="col-sm-offset-3 col-sm-6 col-xs-12">
|
124
|
<!-- FIXME: We really need to POST the logout action -->
|
125
|
<div class="alert alert-danger" role="alert"><a href="index.php?logout"><?=$desc;?></a></div>
|
126
|
</div>
|
127
|
</div>
|
128
|
</div>
|
129
|
</body>
|
130
|
</html>
|
131
|
<?php
|
132
|
|
133
|
} // end function
|
134
|
|
135
|
|
136
|
function display_login_form() {
|
137
|
require_once("globals.inc");
|
138
|
global $config, $g;
|
139
|
$g['theme'] = get_current_theme();
|
140
|
|
141
|
unset($input_errors);
|
142
|
|
143
|
if (isAjax()) {
|
144
|
if (isset($_POST['login'])) {
|
145
|
if ($_SESSION['Logged_In'] <> "True") {
|
146
|
isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = gettext("unknown reason");
|
147
|
printf("showajaxmessage('" . gettext("Invalid login (%s).") . "')", $login_error);
|
148
|
}
|
149
|
if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
|
150
|
// TODO: add the IP from the user who did lock the device
|
151
|
$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
|
152
|
printf("showajaxmessage('" . gettext("This device is currently being maintained by: %s.") . "');", $whom);
|
153
|
}
|
154
|
}
|
155
|
exit;
|
156
|
}
|
157
|
|
158
|
/* Check against locally configured IP addresses, which will catch when someone
|
159
|
port forwards WebGUI access from WAN to an internal IP on the router. */
|
160
|
global $FilterIflist, $nifty_background;
|
161
|
$local_ip = false;
|
162
|
if (strpos($_SERVER['HTTP_HOST'], ":") === FALSE) {
|
163
|
$http_host_port = explode(":", $_SERVER['HTTP_HOST']);
|
164
|
$http_host = $http_host_port[0];
|
165
|
} else {
|
166
|
$http_host = $_SERVER['HTTP_HOST'];
|
167
|
}
|
168
|
if (empty($FilterIflist)) {
|
169
|
require_once('filter.inc');
|
170
|
require_once('shaper.inc');
|
171
|
filter_generate_optcfg_array();
|
172
|
}
|
173
|
foreach ($FilterIflist as $iflist) {
|
174
|
if ($iflist['ip'] == $http_host) {
|
175
|
$local_ip = true;
|
176
|
} else if ($iflist['ipv6'] == $http_host) {
|
177
|
$local_ip = true;
|
178
|
} else if (is_array($iflist['vips'])) {
|
179
|
foreach ($iflist['vips'] as $vip) {
|
180
|
if ($vip['ip'] == $http_host) {
|
181
|
$local_ip = true;
|
182
|
break;
|
183
|
}
|
184
|
}
|
185
|
unset($vip);
|
186
|
}
|
187
|
if ($local_ip == true) {
|
188
|
break;
|
189
|
}
|
190
|
}
|
191
|
unset($FilterIflist);
|
192
|
unset($iflist);
|
193
|
|
194
|
if ($local_ip == false) {
|
195
|
if (is_array($config['openvpn']['openvpn-server'])) {
|
196
|
foreach ($config['openvpn']['openvpn-server'] as $ovpns) {
|
197
|
if (is_ipaddrv4($http_host) && !empty($ovpns['tunnel_network']) && ip_in_subnet($http_host, $ovpns['tunnel_network'])) {
|
198
|
$local_ip = true;
|
199
|
} else if (is_ipaddrv6($http_host) && !empty($ovpns['tunnel_networkv6']) && ip_in_subnet($http_host, $ovpns['tunnel_networkv6'])) {
|
200
|
$local_ip = true;
|
201
|
}
|
202
|
if ($local_ip == true) {
|
203
|
break;
|
204
|
}
|
205
|
}
|
206
|
}
|
207
|
}
|
208
|
|
209
|
?>
|
210
|
<!DOCTYPE html>
|
211
|
<html lang="en">
|
212
|
<head>
|
213
|
<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
|
214
|
<title><?=gettext("Login"); ?></title>
|
215
|
<script>var events = events || [];</script>
|
216
|
</head>
|
217
|
<body id="login" class="no-menu">
|
218
|
<div id="jumbotron">
|
219
|
<div class="container">
|
220
|
<div class="col-sm-offset-3 col-sm-6 col-xs-12">
|
221
|
<?php
|
222
|
if (is_ipaddr($http_host) && !$local_ip && !isset($config['system']['webgui']['nohttpreferercheck'])) {
|
223
|
$nifty_background = "#999";
|
224
|
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."));
|
225
|
}
|
226
|
|
227
|
$loginautocomplete = isset($config['system']['webgui']['loginautocomplete']) ? '' : 'autocomplete="off"';
|
228
|
?>
|
229
|
|
230
|
<div class="panel panel-default">
|
231
|
<div class="panel-heading">
|
232
|
<h2 class="panel-title">Login to pfSense</h2>
|
233
|
</div>
|
234
|
|
235
|
<div class="panel-body">
|
236
|
<?php if (!empty($_SESSION['Login_Error'])): ?>
|
237
|
<div class="alert alert-danger" role="alert"><?=$_SESSION['Login_Error'];?></div>
|
238
|
<?php endif ?>
|
239
|
<div class="alert alert-warning" class="hidden" id="no_cookies"><?= gettext("Your browser must support cookies to login."); ?></div>
|
240
|
|
241
|
<form method="post" <?= $loginautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>" class="form-horizontal">
|
242
|
<div class="form-group">
|
243
|
<label for="usernamefld" class="col-sm-3 control-label">Username</label>
|
244
|
<div class="col-sm-9 col-md-7">
|
245
|
<input type="text" class="form-control" name="usernamefld" id="usernamefld" placeholder="Enter your username">
|
246
|
</div>
|
247
|
</div>
|
248
|
|
249
|
<div class="form-group">
|
250
|
<label for="passwordfld" class="col-sm-3 control-label">Password</label>
|
251
|
<div class="col-sm-9 col-md-7">
|
252
|
<input type="password" class="form-control" name="passwordfld" id="passwordfld" placeholder="Enter your password">
|
253
|
</div>
|
254
|
</div>
|
255
|
|
256
|
<div class="form-group">
|
257
|
<div class="col-sm-offset-3 col-sm-9 col-md-7">
|
258
|
<button type="submit" class="btn btn-primary" name="login">Login</button>
|
259
|
</div>
|
260
|
</div>
|
261
|
</form>
|
262
|
</div>
|
263
|
</div>
|
264
|
</div>
|
265
|
</div>
|
266
|
|
267
|
<script>
|
268
|
events.push(function() {
|
269
|
document.cookie=
|
270
|
"cookie_test=1" +
|
271
|
"<?php echo $config['system']['webgui']['protocol'] == 'https' ? '; secure' : '';?>";
|
272
|
|
273
|
if (document.cookie.indexOf("cookie_test") == -1)
|
274
|
document.getElementById("no_cookies").style.display="";
|
275
|
else
|
276
|
document.getElementById("no_cookies").style.display="none";
|
277
|
|
278
|
// Delete it
|
279
|
document.cookie = "cookie_test=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
280
|
});
|
281
|
</script>
|
282
|
<?php
|
283
|
require('foot.inc');
|
284
|
|
285
|
} // end function
|