Projet

Général

Profil

Télécharger (10,4 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / inc / authgui.inc @ 340ce958

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($_SESSION['Username']);
55

    
56
/*
57
 * redirect to first allowed page if requesting a wrong url
58
 */
59
if (!isAllowedPage($_SERVER['REQUEST_URI'])) {
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
 * Close session data to allow other scripts from same host to come in.
92
 * A session can be reactivated from calling session_start again
93
 */
94
session_commit();
95

    
96
/*
97
 * determine if the user is allowed access to the requested page
98
 */
99
function display_error_form($http_code, $desc) {
100
	global $config, $g;
101
	$g['theme'] = get_current_theme();
102
	if(isAjax()) {
103
		printf(gettext('Error: %1$s Description: %2$s'), $http_code, $desc);
104
		return;
105
	}
106

    
107
?>
108

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

    
151
<?php
152

    
153
} // end function
154

    
155

    
156
function display_login_form() {
157
	require_once("globals.inc");
158
	global $config, $g;
159
	$g['theme'] = get_current_theme();
160

    
161
	unset($input_errors);
162

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

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

    
201
if($config['virtualip']) {
202
	if($config['virtualip']['vip']) {
203
		foreach($config['virtualip']['vip'] as $vip) {
204
			if($vip['subnet'] == $http_host)
205
				$local_ip = true;
206
		}
207
	}
208
}
209
if (is_array($config['openvpn']['openvpn-server'])) {
210
	foreach ($config['openvpn']['openvpn-server'] as $ovpns) {
211
		if (is_ipaddrv4($http_host) && !empty($ovpns['tunnel_network']) && ip_in_subnet($http_host, $ovpns['tunnel_network'])) {
212
			$local_ip = true;
213
			break;
214
		}
215

    
216
		if (is_ipaddrv6($http_host) && !empty($ovpns['tunnel_networkv6']) && ip_in_subnet($http_host, $ovpns['tunnel_networkv6'])) {
217
			$local_ip = true;
218
			break;
219
		}
220
	}
221
}
222
setcookie("cookie_test", time() + 3600);
223
$have_cookies = isset($_COOKIE["cookie_test"]);
224

    
225
?>
226

    
227
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
228
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
229
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
230
	<head>
231
		<script type="text/javascript" src="/javascript/jquery-1.11.1.min.js"></script>
232
		<script type="text/javascript" src="/javascript/jquery-migrate-1.2.1.min.js"></script>
233
		<script type="text/javascript">
234
		//<![CDATA[
235
		$(document).ready(function() { jQuery('#usernamefld').focus(); });
236
		//]]>
237
		</script>
238

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

    
293
					<?php if (!$have_cookies && isset($_POST['login'])): ?>
294
					<br /><br />
295
					<span style="text-align:center; font-weight: normal ; font-style: italic; color: #ff0000">
296
						<?= gettext("Your browser must support cookies to login."); ?>
297
					</span>
298
					<?php endif; ?>
299
				</p>        
300
				<p>
301
					<span style="text-align:center">
302
						<input type="submit" name="login" class="formbtn" value="<?=gettext("Login"); ?>" tabindex="3" />
303
					</span>
304
				</p>
305
			</form>
306
		</div>
307
	</body>
308
</html>
309
<?php
310
} // end function
311

    
312
?>
(6-6/68)