Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* ====================================================================
3
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
4
 *	Copyright (c)  2005-2006 Bill Marquette <bill.marquette@gmail.com>
5
 *	Copyright (c)  2006 Paul Taylor <paultaylor@winn-dixie.com>.
6
 *	Copyright (c)  2003-2006 Manuel Kasper <mk@neon1.net>.
7
 *
8
 *	Redistribution and use in source and binary forms, with or without modification,
9
 *	are permitted provided that the following conditions are met:
10
 *
11
 *	1. Redistributions of source code must retain the above copyright notice,
12
 *		this list of conditions and the following disclaimer.
13
 *
14
 *	2. Redistributions in binary form must reproduce the above copyright
15
 *		notice, this list of conditions and the following disclaimer in
16
 *		the documentation and/or other materials provided with the
17
 *		distribution.
18
 *
19
 *	3. All advertising materials mentioning features or use of this software
20
 *		must display the following acknowledgment:
21
 *		"This product includes software developed by the pfSense Project
22
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
23
 *
24
 *	4. The names "pfSense" and "pfSense Project" must not be used to
25
 *		 endorse or promote products derived from this software without
26
 *		 prior written permission. For written permission, please contact
27
 *		 coreteam@pfsense.org.
28
 *
29
 *	5. Products derived from this software may not be called "pfSense"
30
 *		nor may "pfSense" appear in their names without prior written
31
 *		permission of the Electric Sheep Fencing, LLC.
32
 *
33
 *	6. Redistributions of any form whatsoever must retain the following
34
 *		acknowledgment:
35
 *
36
 *	"This product includes software developed by the pfSense Project
37
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
38
 *
39
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
40
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
43
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
51
 *
52
 *	====================================================================
53
 *
54
 */
55
include_once("auth.inc");
56
include_once("priv.inc");
57
if (!function_exists('platform_booting')) {
58
	require_once('globals.inc');
59
}
60

    
61
/* Authenticate user - exit if failed */
62
if (!session_auth()) {
63
	display_login_form();
64
	exit;
65
}
66

    
67
/*
68
 * Once here, the user has authenticated with the web server.
69
 * We give them access only to the appropriate pages based on
70
 * the user or group privileges.
71
 */
72
$allowedpages = getAllowedPages($_SESSION['Username'], $_SESSION['user_radius_attributes']);
73

    
74
/*
75
 * redirect to first allowed page if requesting a wrong url
76
 */
77

    
78
/* Fix this up otherwise the privilege check will fail. See Redmine #5909. */
79
if ($_SERVER['REQUEST_URI'] == "/") {
80
	$_SERVER['REQUEST_URI'] = "/index.php";
81
}
82

    
83
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
84
	if (count($allowedpages) > 0) {
85
		$page = str_replace('*', '', $allowedpages[0]);
86
		$_SESSION['Post_Login'] = true;
87
		require_once("functions.inc");
88
		pfSenseHeader("/{$page}");
89

    
90
		$username = empty($_SESSION["Username"]) ? "(system)" : $_SESSION['Username'];
91
		if (!empty($_SERVER['REMOTE_ADDR'])) {
92
			$username .= '@' . $_SERVER['REMOTE_ADDR'];
93
		}
94
		log_error("{$username} attempted to access {$_SERVER['SCRIPT_NAME']} but does not have access to that page. Redirecting to {$page}.");
95

    
96
		exit;
97
	} else {
98
		display_error_form("201", gettext("No page assigned to this user! Click here to logout."));
99
		exit;
100
	}
101
} else {
102
	$_SESSION['Post_Login'] = true;
103
}
104

    
105
/*
106
 * redirect browsers post-login to avoid pages
107
 * taking action in response to a POST request
108
 */
109
if (!$_SESSION['Post_Login']) {
110
	$_SESSION['Post_Login'] = true;
111
	require_once("functions.inc");
112
	pfSenseHeader($_SERVER['REQUEST_URI']);
113
	exit;
114
}
115

    
116
/*
117
 * Close session data to allow other scripts from same host to come in.
118
 * A session can be reactivated from calling session_start again
119
 */
120
session_commit();
121

    
122
/*
123
 * determine if the user is allowed access to the requested page
124
 */
125
function display_error_form($http_code, $desc) {
126
	global $config, $g;
127

    
128
	if (isAjax()) {
129
		printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
130
		return;
131
	}
132

    
133
	$cssfile = "/css/pfSense.css";
134

    
135
	if (isset($config['system']['webgui']['webguicss'])) {
136
	if (file_exists("/usr/local/www/css/" . $config['system']['webgui']['webguicss'])) {
137
		$cssfile = "/css/" . $config['system']['webgui']['webguicss'];
138
	}
139
}
140

    
141
?>
142
<!DOCTYPE html>
143
<html lang="en">
144
<head>
145
	<meta name="viewport" content="width=device-width, initial-scale=1">
146
	<link rel="stylesheet" href="<?=$cssfile?>" />
147
	<title><?=gettext("Error: not allowed"); ?></title>
148
</head>
149
<body id="error" class="no-menu">
150
	<div id="jumbotron">
151
		<div class="container">
152
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
153
				<!-- FIXME: We really need to POST the logout action -->
154
				<div class="alert alert-danger" role="alert"><a href="index.php?logout"><?=$desc;?></a></div>
155
			</div>
156
		</div>
157
	</div>
158
</body>
159
</html>
160
<?php
161

    
162
} // end function
163

    
164

    
165
function display_login_form() {
166
	require_once("globals.inc");
167
	global $config, $g;
168

    
169
	unset($input_errors);
170

    
171
	if (isAjax()) {
172
		if (isset($_POST['login'])) {
173
			if ($_SESSION['Logged_In'] <> "True") {
174
				isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = gettext("unknown reason");
175
				printf("showajaxmessage('" . gettext("Invalid login (%s).") . "')", $login_error);
176
			}
177
			if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
178
				// TODO: add the IP from the user who did lock the device
179
				$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
180
				printf("showajaxmessage('" . gettext("This device is currently being maintained by: %s.") . "');", $whom);
181
			}
182
		}
183
		exit;
184
	}
185

    
186
/* Check against locally configured IP addresses, which will catch when someone
187
   port forwards WebGUI access from WAN to an internal IP on the router. */
188
global $FilterIflist, $nifty_background;
189
$local_ip = false;
190
if (strpos($_SERVER['HTTP_HOST'], ":") === FALSE) {
191
	$http_host_port = explode(":", $_SERVER['HTTP_HOST']);
192
	$http_host = $http_host_port[0];
193
} else {
194
	$http_host = $_SERVER['HTTP_HOST'];
195
}
196
if (empty($FilterIflist)) {
197
	require_once('filter.inc');
198
	require_once('shaper.inc');
199
	filter_generate_optcfg_array();
200
}
201
foreach ($FilterIflist as $iflist) {
202
	if ($iflist['ip'] == $http_host) {
203
		$local_ip = true;
204
	} else if ($iflist['ipv6'] == $http_host) {
205
		$local_ip = true;
206
	} else if (is_array($iflist['vips'])) {
207
		foreach ($iflist['vips'] as $vip) {
208
			if ($vip['ip'] == $http_host) {
209
				$local_ip = true;
210
				break;
211
			}
212
		}
213
		unset($vip);
214
	}
215
	if ($local_ip == true) {
216
		break;
217
	}
218
}
219
unset($FilterIflist);
220
unset($iflist);
221

    
222
if ($local_ip == false) {
223
	if (is_array($config['openvpn']['openvpn-server'])) {
224
		foreach ($config['openvpn']['openvpn-server'] as $ovpns) {
225
			if (is_ipaddrv4($http_host) && !empty($ovpns['tunnel_network']) && ip_in_subnet($http_host, $ovpns['tunnel_network'])) {
226
				$local_ip = true;
227
			} else if (is_ipaddrv6($http_host) && !empty($ovpns['tunnel_networkv6']) && ip_in_subnet($http_host, $ovpns['tunnel_networkv6'])) {
228
				$local_ip = true;
229
			}
230
			if ($local_ip == true) {
231
				break;
232
			}
233
		}
234
	}
235
}
236

    
237
$cssfile = "/css/pfSense.css";
238

    
239
if (isset($config['system']['webgui']['webguicss'])) {
240
	if (file_exists("/usr/local/www/css/" . $config['system']['webgui']['webguicss'])) {
241
		$cssfile = "/css/" . $config['system']['webgui']['webguicss'];
242
	}
243
}
244

    
245
?>
246
<!DOCTYPE html>
247
<html lang="en">
248
<head>
249
	<meta name="viewport" content="width=device-width, initial-scale=1">
250
	<link rel="stylesheet" href="<?=$cssfile?>" />
251
	<title><?=gettext("Login"); ?></title>
252
	<script type="text/javascript">
253
	//<![CDATA{
254
	var events = events || [];
255
	//]]>
256
	</script>
257
</head>
258
<body id="login" class="no-menu">
259
	<div id="jumbotron">
260
		<div class="container">
261
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
262
<?php
263
	if (is_ipaddr($http_host) && !$local_ip && !isset($config['system']['webgui']['nohttpreferercheck'])) {
264
		$nifty_background = "#999";
265
		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."));
266
	}
267

    
268
	$loginautocomplete = isset($config['system']['webgui']['loginautocomplete']) ? '' : 'autocomplete="off"';
269
?>
270

    
271
				<div class="panel panel-default">
272
					<div class="panel-heading">
273
						<h2 class="panel-title"><?=sprintf(gettext("Login to %s"), $g['product_name'])?></h2>
274
					</div>
275

    
276
					<div class="panel-body">
277
<?php if (!empty($_SESSION['Login_Error'])): ?>
278
						<div class="alert alert-danger" role="alert"><?=$_SESSION['Login_Error'];?></div>
279
<?php endif ?>
280
						<div class="alert alert-warning hidden" id="no_cookies"><?= gettext("The browser must support cookies to login."); ?></div>
281

    
282
						<form method="post" <?= $loginautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>" class="form-horizontal">
283
							<div class="form-group">
284
								<label for="usernamefld" class="col-sm-3 control-label"><?=gettext("Username")?></label>
285
								<div class="col-sm-9 col-md-7">
286
									<input type="text" class="form-control" name="usernamefld" id="usernamefld" placeholder="<?=gettext("Enter your username")?>" autocorrect="off" autocapitalize="none" spellcheck="false">
287
								</div>
288
							</div>
289

    
290
							<div class="form-group">
291
								<label for="passwordfld" class="col-sm-3 control-label"><?=gettext("Password")?></label>
292
								<div class="col-sm-9 col-md-7">
293
									<input type="password" class="form-control" name="passwordfld" id="passwordfld" placeholder="<?=gettext("Enter your password")?>">
294
								</div>
295
							</div>
296

    
297
							<div class="form-group">
298
								<div class="col-sm-offset-3 col-sm-9 col-md-7">
299
									<button type="submit" class="btn btn-primary" name="login"><?=gettext("Login")?></button>
300
								</div>
301
							</div>
302
						</form>
303
					</div>
304
				</div>
305
			</div>
306
		</div>
307

    
308
		<script type="text/javascript">
309
		//!<[CDATA[
310
		events.push(function() {
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
			else
318
				document.getElementById("no_cookies").style.display="none";
319

    
320
			// Delete it
321
			document.cookie = "cookie_test=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
322
		});
323
		//]]>
324
		</script>
325
<?php
326
require('foot.inc');
327

    
328
} // end function
(5-5/65)