Project

General

Profile

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

    
66
/* Authenticate user - exit if failed */
67
if (!session_auth()) {
68
	display_login_form();
69
	exit;
70
}
71

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

    
79
/*
80
 * redirect to first allowed page if requesting a wrong url
81
 */
82
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
83
	if (count($allowedpages) > 0) {
84
		$page = str_replace('*', '', $allowedpages[0]);
85
		$_SESSION['Post_Login'] = true;
86
		require_once("functions.inc");
87
		pfSenseHeader("/{$page}");
88

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

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

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

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

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

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

    
132
?>
133
<!DOCTYPE html>
134
<html lang="en">
135
<head>
136
	<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
137
	<title><?=gettext("Error: not allowed"); ?></title>
138
</head>
139
<body id="error" class="no-menu">
140
	<div id="jumbotron">
141
		<div class="container">
142
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
143
				<!-- FIXME: We really need to POST the logout action -->
144
				<div class="alert alert-danger" role="alert"><a href="index.php?logout"><?=$desc;?></a></div>
145
			</div>
146
		</div>
147
	</div>
148
</body>
149
</html>
150
<?php
151

    
152
} // end function
153

    
154

    
155
function display_login_form() {
156
	require_once("globals.inc");
157
	global $config, $g;
158

    
159
	unset($input_errors);
160

    
161
	if (isAjax()) {
162
		if (isset($_POST['login'])) {
163
			if ($_SESSION['Logged_In'] <> "True") {
164
				isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = gettext("unknown reason");
165
				printf("showajaxmessage('" . gettext("Invalid login (%s).") . "')", $login_error);
166
			}
167
			if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
168
				// TODO: add the IP from the user who did lock the device
169
				$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
170
				printf("showajaxmessage('" . gettext("This device is currently being maintained by: %s.") . "');", $whom);
171
			}
172
		}
173
		exit;
174
	}
175

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

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

    
227
?>
228
<!DOCTYPE html>
229
<html lang="en">
230
<head>
231
	<link rel="stylesheet" href="/bootstrap/css/pfSense.css" />
232
	<title><?=gettext("Login"); ?></title>
233
	<script>var events = events || [];</script>
234
</head>
235
<body id="login" class="no-menu">
236
	<div id="jumbotron">
237
		<div class="container">
238
			<div class="col-sm-offset-3 col-sm-6 col-xs-12">
239
<?php
240
	if (is_ipaddr($http_host) && !$local_ip && !isset($config['system']['webgui']['nohttpreferercheck'])) {
241
		$nifty_background = "#999";
242
		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."));
243
	}
244

    
245
	$loginautocomplete = isset($config['system']['webgui']['loginautocomplete']) ? '' : 'autocomplete="off"';
246
?>
247

    
248
				<div class="panel panel-default">
249
					<div class="panel-heading">
250
						<h2 class="panel-title">Login to pfSense</h2>
251
					</div>
252

    
253
					<div class="panel-body">
254
<?php if (!empty($_SESSION['Login_Error'])): ?>
255
						<div class="alert alert-danger" role="alert"><?=$_SESSION['Login_Error'];?></div>
256
<?php endif ?>
257
						<div class="alert alert-warning" class="hidden" id="no_cookies"><?= gettext("Your browser must support cookies to login."); ?></div>
258

    
259
						<form method="post" <?= $loginautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>" class="form-horizontal">
260
							<div class="form-group">
261
								<label for="usernamefld" class="col-sm-3 control-label">Username</label>
262
								<div class="col-sm-9 col-md-7">
263
									<input type="text" class="form-control" name="usernamefld" id="usernamefld" placeholder="Enter your username">
264
								</div>
265
							</div>
266

    
267
							<div class="form-group">
268
								<label for="passwordfld" class="col-sm-3 control-label">Password</label>
269
								<div class="col-sm-9 col-md-7">
270
									<input type="password" class="form-control" name="passwordfld" id="passwordfld" placeholder="Enter your password">
271
								</div>
272
							</div>
273

    
274
							<div class="form-group">
275
								<div class="col-sm-offset-3 col-sm-9 col-md-7">
276
									<button type="submit" class="btn btn-primary" name="login">Login</button>
277
								</div>
278
							</div>
279
						</form>
280
					</div>
281
				</div>
282
			</div>
283
		</div>
284

    
285
		<script>
286
		events.push(function() {
287
			document.cookie=
288
				"cookie_test=1" +
289
				"<?php echo $config['system']['webgui']['protocol'] == 'https' ? '; secure' : '';?>";
290

    
291
			if (document.cookie.indexOf("cookie_test") == -1)
292
				document.getElementById("no_cookies").style.display="";
293
			else
294
				document.getElementById("no_cookies").style.display="none";
295

    
296
			// Delete it
297
			document.cookie = "cookie_test=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
298
		});
299
		</script>
300
<?php
301
require('foot.inc');
302

    
303
} // end function
(5-5/67)