Project

General

Profile

Download (9.39 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

    
43
/* Authenticate user - exit if failed */
44
if (!session_auth()) {
45
	display_login_form();
46
	exit;
47
}
48

    
49
/*
50
 * Once here, the user has authenticated with the web server.
51
 * We give them access only to the appropriate pages based on
52
 * the user or group privileges.
53
 */
54
$allowedpages = getAllowedPages($HTTP_SERVER_VARS['AUTH_USER']);
55

    
56
/*
57
 * redirect to first allowed page if requesting a wrong url
58
 */
59
if (!isAllowedPage($_SERVER['SCRIPT_NAME'])) {
60
	if (count($allowedpages) > 0) {
61
		$page = str_replace('*', '', $allowedpages[0]);
62
		$_SESSION['Post_Login'] = true;
63
		require_once("functions.inc");
64
		pfSenseHeader("/{$page}");
65

    
66
		$username = empty($_SESSION["Username"]) ? "(system)" : $_SESSION['Username'];
67
		if (!empty($_SERVER['REMOTE_ADDR']))
68
			$username .= '@' . $_SERVER['REMOTE_ADDR'];
69
		log_error("{$username} attempted to access {$_SERVER['SCRIPT_NAME']} but does not have access to that page. Redirecting to {$page}.");
70

    
71
		exit;
72
	} else {
73
		display_error_form("201", gettext("No page assigned to this user! Click here to logout."));
74
		exit;
75
	}
76
} else 
77
	$_SESSION['Post_Login'] = true;
78

    
79
/*
80
 * redirect browsers post-login to avoid pages
81
 * taking action in reponse to a POST request
82
 */
83
if (!$_SESSION['Post_Login']) {
84
	$_SESSION['Post_Login'] = true;
85
	require_once("functions.inc");
86
	pfSenseHeader($_SERVER['REQUEST_URI']);
87
	exit;
88
}
89

    
90
/*
91
 * determine if the user is allowed access to the requested page
92
 */
93
function display_error_form($http_code, $desc) {
94
	global $config, $g;
95
	$g['theme'] = $config['theme'];
96
	if(isAjax()) {
97
		printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
98
		return;
99
	}
100

    
101
?>
102

    
103
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
104
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
105
<html>
106
	<head>
107
		<script type="text/javascript" src="/javascript/jquery.js"></script>
108
		<title><?=$http_code?></title>
109
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
110
		<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
111
		<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
112
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
113
		<?php else: ?>
114
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
115
		<?php endif; ?>
116
		<script type="text/javascript">
117
		<!--
118
			function page_load() {}
119
			function clearError() {
120
				if($('#inputerrors'))
121
				$('#inputerrors').html('');
122
			}
123
			<?php
124
				require("headjs.php");
125
				echo getHeadJS();
126
			?>
127
		//-->
128
		</script>
129
		<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
130
	</head>
131
	<body onload="page_load();">
132
		<div id="errordesc">
133
			<h1>&nbsp</h1>
134
			<a href="/index.php?logout">
135
			<p id="errortext" style="vertical-align: middle; text-align: center;">
136
				<span style="color: #000000; font-weight: bold;">
137
					<?=$desc;?>
138
				</span>
139
			</p>
140
		</div>
141
	</body>
142
</html>
143

    
144
<?php
145

    
146
} // end function
147

    
148

    
149
function display_login_form() {
150
	require_once("globals.inc");
151
	global $config, $g;
152
	$g['theme'] = $config['theme'];
153

    
154
	unset($input_errors);
155

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

    
171
/* Check against locally configured IP addresses, which will catch when someone 
172
   port forwards WebGUI access from WAN to an internal IP on the router. */
173
global $FilterIflist, $nifty_background;
174
$local_ip = false;
175
if(strstr($_SERVER['HTTP_HOST'], ":")) {
176
	$http_host_port = explode(":", $_SERVER['HTTP_HOST']);
177
	$http_host = $http_host_port[0];
178
} else {
179
	$http_host = $_SERVER['HTTP_HOST'];
180
}
181
if (empty($FilterIflist)) {
182
	require_once('filter.inc');
183
	require_once('shaper.inc');
184
	filter_generate_optcfg_array();
185
}
186
foreach ($FilterIflist as $iflist) {
187
	if($iflist['ip'] == $http_host)
188
		$local_ip = true;
189
	if($iflist['ipv6'] == $http_host)
190
		$local_ip = true;
191
}
192
if($config['virtualip']) {
193
	if($config['virtualip']['vip']) {
194
		foreach($config['virtualip']['vip'] as $vip) {
195
			if($vip['subnet'] == $http_host)
196
				$local_ip = true;
197
		}
198
	}
199
}
200
setcookie("cookie_test", time() + 3600);
201
$have_cookies = isset($_COOKIE["cookie_test"]);
202

    
203
?>
204

    
205
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
206
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
207
<html>
208
	<head>
209
		<script type="text/javascript" src="/javascript/jquery.js"></script>
210
		<script>$(document).ready(function() { jQuery('#usernamefld').focus(); });</script>
211
		
212
		<title><?=gettext("Login"); ?></title>
213
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
214
		<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
215
		<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
216
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
217
		<?php else: ?>
218
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
219
		<?php endif; ?>
220
		<script type="text/javascript">
221
		<!--
222
			function page_load() {}
223
			function clearError() {
224
				if($('#inputerrors'))
225
				$('#inputerrors').html('');
226
			}
227
			<?php
228
				require("headjs.php");
229
				echo getHeadJS();
230
			?>
231
		//-->
232
		</script>
233
		<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
234
	</head>
235
	<body onload="page_load()">
236
		<div id="login">
237
			<?php 
238
				if(is_ipaddr($http_host) && !$local_ip) {
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
				$noautocomplete = isset($config['system']['webgui']['noautocomplete']) ? 'autocomplete="off"' : '';
243
			?>
244
			<form id="iform" name="login_iform" method="post" <?= $noautocomplete ?> action="<?=$_SERVER['SCRIPT_NAME'];?>">
245
				<h1></h1>
246
				<div id="inputerrors"><?=$_SESSION['Login_Error'];?></div>
247
				<p>
248
					<span style="text-align:left">
249
						<?=gettext("Username:"); ?><br>
250
						<input onclick="clearError();" onchange="clearError();" id="usernamefld" type="text" name="usernamefld" class="formfld user" tabindex="1" />
251
					</span>
252
				</p>
253
				<br>
254
				<p>
255
					<span style="text-align:left">
256
						<?=gettext("Password:"); ?> <br>
257
						<input onclick="clearError();" onchange="clearError();" id="passwordfld" type="password" name="passwordfld" class="formfld pwd" tabindex="2" />
258
					</span>
259
				</p>
260
				<br>
261
				<p>
262
					<span style="text-align:center; font-weight: normal ; font-style: italic">
263
						<?=gettext("Enter username and password to login."); ?>
264
					</span>
265

    
266
					<? if (!$have_cookies && isset($_POST['login'])): ?>
267
					<br/><br/>
268
					<span style="text-align:center; font-weight: normal ; font-style: italic; color: #ff0000">
269
						<?= gettext("Your browser must support cookies to login."); ?>
270
					</span>
271
					<? endif; ?>
272
				</p>        
273
				<p>
274
					<span style="text-align:center">
275
						<input type="submit" name="login" class="formbtn" value="<?=gettext("Login"); ?>" tabindex="3" />
276
					</span>
277
				</P>
278
			</form>
279
		</div>
280
	</body>
281
</html>
282
<?php
283
} // end function
284

    
285
?>
(6-6/65)