Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

    
150
} // end function
151

    
152

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

    
157
	unset($input_errors);
158

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

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

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

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

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

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

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

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

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

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

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

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

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

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