Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
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']);
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

    
114
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
115
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
116
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
117
	<head>
118
		<script type="text/javascript" src="/javascript/jquery-1.11.1.min.js"></script>
119
		<script type="text/javascript" src="/javascript/jquery-migrate-1.2.1.min.js"></script>
120
		<title><?=$http_code?></title>
121
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
122
		<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
123
		<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
124
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
125
		<?php else: ?>
126
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
127
		<?php endif; ?>
128
		<script type="text/javascript">
129
		//<![CDATA[
130
			function page_load() {}
131
			function clearError() {
132
				if ($('#inputerrors')) {
133
					$('#inputerrors').html('');
134
				}
135
			}
136
			<?php
137
				require("headjs.php");
138
				echo getHeadJS();
139
			?>
140
		//]]>
141
		</script>
142
		<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
143
	</head>
144
	<body onload="page_load();">
145
		<div id="errordesc">
146
			<h1>&nbsp</h1>
147
			<a href="/index.php?logout">
148
			<p id="errortext" style="vertical-align: middle; text-align: center;">
149
				<span style="color: #000000; font-weight: bold;">
150
					<?=$desc;?>
151
				</span>
152
			</p>
153
		</div>
154
	</body>
155
</html>
156

    
157
<?php
158

    
159
} // end function
160

    
161

    
162
function display_login_form() {
163
	require_once("globals.inc");
164
	global $config, $g;
165
	$g['theme'] = get_current_theme();
166

    
167
	unset($input_errors);
168

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

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

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

    
235
?>
236

    
237
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
238
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
239
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
240
	<head>
241
		<script type="text/javascript" src="/javascript/jquery-1.11.1.min.js"></script>
242
		<script type="text/javascript" src="/javascript/jquery-migrate-1.2.1.min.js"></script>
243
		<script type="text/javascript">
244
		//<![CDATA[
245
		$(document).ready(function() { jQuery('#usernamefld').focus(); });
246
		//]]>
247
		</script>
248

    
249
		<title><?=gettext("Login"); ?></title>
250
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
251
		<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
252
		<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
253
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
254
		<?php else: ?>
255
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
256
		<?php endif; ?>
257
		<script type="text/javascript">
258
		//<![CDATA[
259
			function page_load() {}
260
			function clearError() {
261
				if ($('#inputerrors')) {
262
					$('#inputerrors').html('');
263
				}
264
			}
265
			<?php
266
				require("headjs.php");
267
				echo getHeadJS();
268
			?>
269
		//]]>
270
		</script>
271
		<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
272
	</head>
273
	<body onload="page_load()">
274
		<div id="login">
275
			<?php
276
				if (is_ipaddr($http_host) && !$local_ip && !isset($config['system']['webgui']['nohttpreferercheck'])) {
277
					$nifty_background = "#999";
278
					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."));
279
				}
280
				$loginautocomplete = isset($config['system']['webgui']['loginautocomplete']) ? '' : 'autocomplete="off"';
281
			?>
282
			<form id="iform" name="iform" method="post" <?= $loginautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>">
283
				<h1>&nbsp;</h1>
284
				<div id="inputerrors"><?=$_SESSION['Login_Error'];?></div>
285
				<p>
286
					<span style="text-align:left">
287
						<?=gettext("Username:"); ?><br />
288
						<input onclick="clearError();" onchange="clearError();" id="usernamefld" type="text" name="usernamefld" class="formfld user" tabindex="1" />
289
					</span>
290
				</p>
291
				<p>
292
					<br />
293
					<span style="text-align:left">
294
						<?=gettext("Password:"); ?> <br />
295
						<input onclick="clearError();" onchange="clearError();" id="passwordfld" type="password" name="passwordfld" class="formfld pwd" tabindex="2" />
296
					</span>
297
				</p>
298
				<p>
299
					<br />
300
					<span style="text-align:center; font-weight: normal ; font-style: italic">
301
						<?=gettext("Enter username and password to login."); ?>
302
					</span>
303

    
304
					<span style="text-align:center; font-weight: normal ; font-style: italic; color: #ff0000; display:none" id="no_cookies">
305
						<br /><br />
306
						<?= gettext("Your browser must support cookies to login."); ?>
307
					</span>
308
				</p>
309
				<p>
310
					<span style="text-align:center">
311
						<input type="submit" name="login" class="formbtn" value="<?=gettext("Login"); ?>" tabindex="3" />
312
					</span>
313
				</p>
314
			</form>
315
		</div>
316
		<script type="text/javascript">
317
		//<![CDATA[
318
		document.cookie=
319
			"cookie_test=1" +
320
			"<?php echo $config['system']['webgui']['protocol'] == 'https' ? '; secure' : '';?>";
321

    
322
		if (document.cookie.indexOf("cookie_test") == -1)
323
			document.getElementById("no_cookies").style.display="";
324

    
325
		// Delete it
326
		document.cookie = "cookie_test=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
327
		//]]>
328
		</script>
329
	</body>
330
</html>
331
<?php
332
} // end function
333

    
334
?>
(5-5/67)