Project

General

Profile

Download (8.42 KB) Statistics
| Branch: | Tag: | Revision:
1 16513324 Holger Bauer
<?php
2
/* $Id$ */
3
/*
4 403a270e Ermal Luçi
	Copyright (C) 2007, 2008 Scott Ullrich <sullrich@gmail.com>
5
	All rights reserved.
6 16513324 Holger Bauer
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 523855b0 Scott Ullrich
37
		pfSense_MODULE: authgui
38 16513324 Holger Bauer
*/
39
40 6dc88d53 Ermal Luci
include_once("priv.inc");
41 16513324 Holger Bauer
42
/* We only support htpasswd backed HTTP Basic auth and session
43
 * based backing methods at the moment.
44
 * 		session_auth - this will use session based authentication and timeout
45 45ee90ed Matthew Grooms
 * 		htpasswd_backed - this uses the "standard" .htpasswd file
46
 * 		passwd_backed - this will use the system passwd file in /etc
47
 * 		radius_backed - this will allow you to use a radius server
48
 *		pam_backed - this uses the system's PAM facility .htpasswd file
49 16513324 Holger Bauer
 */
50
51 d97ab688 Matthew Grooms
//log_error("debug: FILE_NAME = {$_SERVER['REQUEST_URI']}");
52
//log_error("debug: FILE_NAME = {$_SERVER['SCRIPT_FILENAME']}");
53
//log_error("debug: SCRIPT_NAME = {$_SERVER['SCRIPT_NAME']}");
54
55 16513324 Holger Bauer
/* enable correct auth backend, default to htpasswd_backed */
56
$ldapcase = $config['system']['webgui']['backend'];
57
switch($ldapcase)
58
{
59 45ee90ed Matthew Grooms
	case ldap:
60
		$backing_method="ldap_backed";
61
		break;
62
	case ldapother:
63
		$backing_method="ldap_backed";
64
		break;
65
	default:
66 659fa7f2 Matthew Grooms
		$backing_method="local_backed";
67 16513324 Holger Bauer
}
68
69
/* Authenticate user - exit if failed */
70 659fa7f2 Matthew Grooms
if (!session_auth($backing_method))
71 45ee90ed Matthew Grooms
	exit;
72
73
/*
74
 * Once here, the user has authenticated with the web server.
75
 * We give them access only to the appropriate pages based on
76
 * the user or group privileges.
77
 */
78 403a270e Ermal Luçi
$allowedpages = getAllowedPages($HTTP_SERVER_VARS['AUTH_USER']);
79 16513324 Holger Bauer
80 45ee90ed Matthew Grooms
/*
81 403a270e Ermal Luçi
 * redirect to first allowed page if requesting a wrong url
82 45ee90ed Matthew Grooms
 */
83 403a270e Ermal Luçi
if (!isAllowedPage($_SERVER['SCRIPT_NAME'])) {
84
	if (count($allowedpages) > 0) {
85
		$page = str_replace('*', '', $allowedpages[0]);
86
		$_SESSION['Post_Login'] = true;
87
		pfSenseHeader("/{$page}");
88
		exit;
89
	} else {
90
		display_error_form("201", "No page assigned to this user! Click here to logout.");
91
		exit;
92
	}
93
} else 
94
	$_SESSION['Post_Login'] = true;
95 16513324 Holger Bauer
96 45ee90ed Matthew Grooms
/*
97 d97ab688 Matthew Grooms
 * redirect browsers post-login to avoid pages
98
 * taking action in reponse to a POST request
99 45ee90ed Matthew Grooms
 */
100 d97ab688 Matthew Grooms
if (!$_SESSION['Post_Login']) {
101
	$_SESSION['Post_Login'] = true;
102
	pfSenseHeader($_SERVER['REQUEST_URI']);
103
	exit;
104
}
105 16513324 Holger Bauer
106 45ee90ed Matthew Grooms
/*
107
 * determine if the user is allowed access to the requested page
108
 */
109 16513324 Holger Bauer
function display_error_form($http_code, $desc) {
110 45ee90ed Matthew Grooms
	global $config, $g;
111
	$g['theme'] = $config['theme'];
112 16513324 Holger Bauer
	if(isAjax()) {
113
		echo "Error: {$http_code} Description: {$desc}";
114
		return;
115
	}
116
117
?>
118 45ee90ed Matthew Grooms
119 16513324 Holger Bauer
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
120
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
121
<html>
122 45ee90ed Matthew Grooms
	<head>
123
		<script type="text/javascript" src="/javascript/scriptaculous/prototype.js"></script>
124
		<script type="text/javascript" src="/javascript/scriptaculous/scriptaculous.js"></script>
125
		<title><?=$http_code?></title>
126
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
127
		<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
128
		<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
129
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
130
		<?php else: ?>
131
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
132
		<?php endif; ?>
133
		<script type="text/javascript">
134
		<!--
135
			function page_load() {}
136
			function clearError() {
137
				if($('inputerrors'))
138
				$('inputerrors').innerHTML='';
139
			}
140
			<?php
141
				require("headjs.php");
142
				echo getHeadJS();
143
			?>
144
		//-->
145
		</script>
146
		<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
147
	</head>
148
	<body onload="page_load();">
149
		<div id="errordesc">
150
			<h1>&nbsp</h1>
151 403a270e Ermal Luçi
			<a href="/index.php?logout">
152 45ee90ed Matthew Grooms
			<p id="errortext" style="vertical-align: middle; text-align: center;">
153
				<span style="color: #000000; font-weight: bold;">
154
					<?=$desc;?>
155
				</span>
156
			</p>
157
		</div>
158
	</body>
159 16513324 Holger Bauer
</html>
160 45ee90ed Matthew Grooms
161 16513324 Holger Bauer
<?php
162
163 45ee90ed Matthew Grooms
} // end function
164 16513324 Holger Bauer
165
166
function display_login_form() {
167 45ee90ed Matthew Grooms
	require_once("globals.inc");
168
	global $config, $g;
169
	$g['theme'] = $config['theme'];
170
171
	unset($input_errors);
172
173
	if(isAjax()) {
174
		if (isset($_POST['login'])) {
175
			if($_SESSION['Logged_In'] <> "True") {
176
				isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = "unknown reason";
177
				echo "showajaxmessage('Invalid login ({$login_error}).');";
178
			}
179
			if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
180
				// TODO: add the IP from the user who did lock the device
181
				$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
182
				echo "showajaxmessage('This device is currently beeing maintained by: {$whom}.');";
183
			}
184
		}
185
		exit;
186
	}
187 16513324 Holger Bauer
188
?>
189 45ee90ed Matthew Grooms
190 16513324 Holger Bauer
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
191
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
192
<html>
193 45ee90ed Matthew Grooms
	<head>
194
		<script type="text/javascript" src="/javascript/scriptaculous/prototype.js"></script>
195
		<script type="text/javascript" src="/javascript/scriptaculous/scriptaculous.js"></script>
196 e7d9eea6 Bill Marquette
		<script>document.observe('dom:loaded', function() { $('usernamefld').focus(); });</script>
197
		
198 45ee90ed Matthew Grooms
		<title><?=gettext("Login"); ?></title>
199
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
200
		<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
201
		<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
202
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
203
		<?php else: ?>
204
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
205
		<?php endif; ?>
206
		<script type="text/javascript">
207
		<!--
208
			function page_load() {}
209
			function clearError() {
210
				if($('inputerrors'))
211
				$('inputerrors').innerHTML='';
212
			}
213
			<?php
214
				require("headjs.php");
215
				echo getHeadJS();
216
			?>
217
		//-->
218
		</script>
219
		<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
220
	</head>
221
	<body onload="page_load()">
222
		<div id="login">
223 d97ab688 Matthew Grooms
			<form id="iform" name="login_iform" method="post" autocomplete="off" action="<?=$_SERVER['SCRIPT_NAME'];?>">
224 45ee90ed Matthew Grooms
				<h1></h1>
225
				<div id="inputerrors"><?=$_SESSION['Login_Error'];?></div>
226
				<p>
227
					<span style="text-align:left">
228
						<?=gettext("Username"); ?>:<br>
229
						<input onclick="clearError();" onchange="clearError();" id="usernamefld" type="text" name="usernamefld" class="formfld user" tabindex="1" />
230
					</span>
231
				</p>
232
				<br>
233
				<p>
234
					<span style="text-align:left">
235
						<?=gettext("Password"); ?>: <br>
236
						<input onclick="clearError();" onchange="clearError();" id="passwordfld" type="password" name="passwordfld" class="formfld pwd" tabindex="2" />
237
					</span>
238
				</p>
239
				<br>
240
				<p>
241
					<span style="text-align:center; font-weight: normal ; font-style: italic">
242
						<?=gettext("Enter username and password to login."); ?>
243
					</span>
244
				</p>        
245
				<p>
246
					<span style="text-align:center">
247
						<input type="submit" name="login" class="formbtn" value="<?=gettext("Login"); ?>" tabindex="3" />
248
					</span>
249
				</P>
250
			</form>
251
		</div>
252
	</body>
253 16513324 Holger Bauer
</html>
254
<?php
255
} // end function
256
257 45ee90ed Matthew Grooms
?>