Project

General

Profile

Download (8.78 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
		exit;
66
	} else {
67
		display_error_form("201", "No page assigned to this user! Click here to logout.");
68
		exit;
69
	}
70
} else 
71
	$_SESSION['Post_Login'] = true;
72

    
73
/*
74
 * redirect browsers post-login to avoid pages
75
 * taking action in reponse to a POST request
76
 */
77
if (!$_SESSION['Post_Login']) {
78
	$_SESSION['Post_Login'] = true;
79
	require_once("functions.inc");
80
	pfSenseHeader($_SERVER['REQUEST_URI']);
81
	exit;
82
}
83

    
84
/*
85
 * determine if the user is allowed access to the requested page
86
 */
87
function display_error_form($http_code, $desc) {
88
	global $config, $g;
89
	$g['theme'] = $config['theme'];
90
	if(isAjax()) {
91
		echo "Error: {$http_code} Description: {$desc}";
92
		return;
93
	}
94

    
95
?>
96

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

    
139
<?php
140

    
141
} // end function
142

    
143

    
144
function display_login_form() {
145
	require_once("globals.inc");
146
	global $config, $g;
147
	$g['theme'] = $config['theme'];
148

    
149
	unset($input_errors);
150

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

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

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

    
270
?>
(5-5/61)