Project

General

Profile

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

    
145
<?php
146

    
147
} // end function
148

    
149

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

    
155
	unset($input_errors);
156

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

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

    
204
?>
205

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

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

    
287
?>
(5-5/62)