Project

General

Profile

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