Project

General

Profile

Download (10.6 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
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
78
	if (count($allowedpages) > 0) {
79
		$page = str_replace('*', '', $allowedpages[0]);
80
		$_SESSION['Post_Login'] = true;
81
		require_once("functions.inc");
82
		pfSenseHeader("/{$page}");
83

    
84
		$username = empty($_SESSION["Username"]) ? "(system)" : $_SESSION['Username'];
85
		if (!empty($_SERVER['REMOTE_ADDR'])) {
86
			$username .= '@' . $_SERVER['REMOTE_ADDR'];
87
		}
88
		log_error("{$username} attempted to access {$_SERVER['SCRIPT_NAME']} but does not have access to that page. Redirecting to {$page}.");
89

    
90
		exit;
91
	} else {
92
		display_error_form("201", gettext("No page assigned to this user! Click here to logout."));
93
		exit;
94
	}
95
} else {
96
	$_SESSION['Post_Login'] = true;
97
}
98

    
99
/*
100
 * redirect browsers post-login to avoid pages
101
 * taking action in response to a POST request
102
 */
103
if (!$_SESSION['Post_Login']) {
104
	$_SESSION['Post_Login'] = true;
105
	require_once("functions.inc");
106
	pfSenseHeader($_SERVER['REQUEST_URI']);
107
	exit;
108
}
109

    
110
/*
111
 * Close session data to allow other scripts from same host to come in.
112
 * A session can be reactivated from calling session_start again
113
 */
114
session_commit();
115

    
116
/*
117
 * determine if the user is allowed access to the requested page
118
 */
119
function display_error_form($http_code, $desc) {
120
	global $config, $g;
121

    
122
	if (isAjax()) {
123
		printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
124
		return;
125
	}
126

    
127
	$cssfile = "/bootstrap/css/pfSense.css";
128

    
129
	if (isset($config['system']['webgui']['webguicss'])) {
130
	if (file_exists("bootstrap/css/" . $config['system']['webgui']['webguicss'])) {
131
		$cssfile = "/bootstrap/css/" . $config['system']['webgui']['webguicss'];
132
	}
133
}
134

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

    
156
} // end function
157

    
158

    
159
function display_login_form() {
160
	require_once("globals.inc");
161
	global $config, $g;
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
}
213
unset($FilterIflist);
214
unset($iflist);
215

    
216
if ($local_ip == false) {
217
	if (is_array($config['openvpn']['openvpn-server'])) {
218
		foreach ($config['openvpn']['openvpn-server'] as $ovpns) {
219
			if (is_ipaddrv4($http_host) && !empty($ovpns['tunnel_network']) && ip_in_subnet($http_host, $ovpns['tunnel_network'])) {
220
				$local_ip = true;
221
			} else if (is_ipaddrv6($http_host) && !empty($ovpns['tunnel_networkv6']) && ip_in_subnet($http_host, $ovpns['tunnel_networkv6'])) {
222
				$local_ip = true;
223
			}
224
			if ($local_ip == true) {
225
				break;
226
			}
227
		}
228
	}
229
}
230

    
231
$cssfile = "/bootstrap/css/pfSense.css";
232

    
233
if (isset($config['system']['webgui']['webguicss'])) {
234
	if (file_exists("bootstrap/css/" . $config['system']['webgui']['webguicss'])) {
235
		$cssfile = "/bootstrap/css/" . $config['system']['webgui']['webguicss'];
236
	}
237
}
238

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

    
262
	$loginautocomplete = isset($config['system']['webgui']['loginautocomplete']) ? '' : 'autocomplete="off"';
263
?>
264

    
265
				<div class="panel panel-default">
266
					<div class="panel-heading">
267
						<h2 class="panel-title">Login to pfSense</h2>
268
					</div>
269

    
270
					<div class="panel-body">
271
<?php if (!empty($_SESSION['Login_Error'])): ?>
272
						<div class="alert alert-danger" role="alert"><?=$_SESSION['Login_Error'];?></div>
273
<?php endif ?>
274
						<div class="alert alert-warning" class="hidden" id="no_cookies"><?= gettext("Your browser must support cookies to login."); ?></div>
275

    
276
						<form method="post" <?= $loginautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>" class="form-horizontal">
277
							<div class="form-group">
278
								<label for="usernamefld" class="col-sm-3 control-label">Username</label>
279
								<div class="col-sm-9 col-md-7">
280
									<input type="text" class="form-control" name="usernamefld" id="usernamefld" placeholder="Enter your username">
281
								</div>
282
							</div>
283

    
284
							<div class="form-group">
285
								<label for="passwordfld" class="col-sm-3 control-label">Password</label>
286
								<div class="col-sm-9 col-md-7">
287
									<input type="password" class="form-control" name="passwordfld" id="passwordfld" placeholder="Enter your password">
288
								</div>
289
							</div>
290

    
291
							<div class="form-group">
292
								<div class="col-sm-offset-3 col-sm-9 col-md-7">
293
									<button type="submit" class="btn btn-primary" name="login">Login</button>
294
								</div>
295
							</div>
296
						</form>
297
					</div>
298
				</div>
299
			</div>
300
		</div>
301

    
302
		<script type="text/javascript">
303
		//!<[CDATA[
304
		events.push(function() {
305
			document.cookie=
306
				"cookie_test=1" +
307
				"<?php echo $config['system']['webgui']['protocol'] == 'https' ? '; secure' : '';?>";
308

    
309
			if (document.cookie.indexOf("cookie_test") == -1)
310
				document.getElementById("no_cookies").style.display="";
311
			else
312
				document.getElementById("no_cookies").style.display="none";
313

    
314
			// Delete it
315
			document.cookie = "cookie_test=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
316
		});
317
		//]]>
318
		</script>
319
<?php
320
require('foot.inc');
321

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