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
|
|
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
|
* 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
|
*/
|
49
|
|
50
|
//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
|
/* enable correct auth backend, default to htpasswd_backed */
|
55
|
$ldapcase = $config['system']['webgui']['backend'];
|
56
|
switch($ldapcase)
|
57
|
{
|
58
|
case ldap:
|
59
|
$backing_method="ldap_backed";
|
60
|
break;
|
61
|
case ldapother:
|
62
|
$backing_method="ldap_backed";
|
63
|
break;
|
64
|
default:
|
65
|
$backing_method="local_backed";
|
66
|
}
|
67
|
|
68
|
/* Authenticate user - exit if failed */
|
69
|
if (!session_auth($backing_method))
|
70
|
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
|
getAllowedPages($HTTP_SERVER_VARS['AUTH_USER']);
|
78
|
|
79
|
/*
|
80
|
* get the user homepage
|
81
|
*/
|
82
|
$home = $config['system']['user'][$userindex[$HTTP_SERVER_VARS['AUTH_USER']]]['home'];
|
83
|
if (!$home)
|
84
|
$home = "/index.php";
|
85
|
|
86
|
/*
|
87
|
* redirect to homepage if no url is specified
|
88
|
*/
|
89
|
if ($_SERVER['REQUEST_URI'] == "/") {
|
90
|
pfSenseHeader($home);
|
91
|
exit;
|
92
|
}
|
93
|
|
94
|
/*
|
95
|
* redirect browsers post-login to avoid pages
|
96
|
* taking action in reponse to a POST request
|
97
|
*/
|
98
|
if (!$_SESSION['Post_Login']) {
|
99
|
$_SESSION['Post_Login'] = true;
|
100
|
pfSenseHeader($_SERVER['REQUEST_URI']);
|
101
|
exit;
|
102
|
}
|
103
|
|
104
|
/*
|
105
|
* determine if the user is allowed access to the requested page
|
106
|
*/
|
107
|
if (!isAllowedPage($pagereq)) {
|
108
|
|
109
|
/*
|
110
|
* The currently logged in user is not allowed to access the page
|
111
|
* they are attempting to view. Redirect them to an allowed page.
|
112
|
*/
|
113
|
if(stristr($_SERVER['SCRIPT_NAME'],"sajax")) {
|
114
|
echo "||Access to AJAX has been disallowed for this user.";
|
115
|
exit;
|
116
|
}
|
117
|
|
118
|
header("HTTP/1.0 401 Unauthorized");
|
119
|
header("Status: 401 Unauthorized");
|
120
|
display_error_form("401", "Unauthorized. You do not have access to the page {$pagereq}");
|
121
|
exit;
|
122
|
}
|
123
|
|
124
|
function display_error_form($http_code, $desc) {
|
125
|
global $config, $g;
|
126
|
$g['theme'] = $config['theme'];
|
127
|
if(isAjax()) {
|
128
|
echo "Error: {$http_code} Description: {$desc}";
|
129
|
return;
|
130
|
}
|
131
|
|
132
|
?>
|
133
|
|
134
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
135
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
136
|
<html>
|
137
|
<head>
|
138
|
<script type="text/javascript" src="/javascript/scriptaculous/prototype.js"></script>
|
139
|
<script type="text/javascript" src="/javascript/scriptaculous/scriptaculous.js"></script>
|
140
|
<title><?=$http_code?></title>
|
141
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
142
|
<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
|
143
|
<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
|
144
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
|
145
|
<?php else: ?>
|
146
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
|
147
|
<?php endif; ?>
|
148
|
<script type="text/javascript">
|
149
|
<!--
|
150
|
function page_load() {}
|
151
|
function clearError() {
|
152
|
if($('inputerrors'))
|
153
|
$('inputerrors').innerHTML='';
|
154
|
}
|
155
|
<?php
|
156
|
require("headjs.php");
|
157
|
echo getHeadJS();
|
158
|
?>
|
159
|
//-->
|
160
|
</script>
|
161
|
<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
|
162
|
</head>
|
163
|
<body onload="page_load();">
|
164
|
<div id="errordesc">
|
165
|
<h1> </h1>
|
166
|
<a href="/">
|
167
|
<p id="errortext" style="vertical-align: middle; text-align: center;">
|
168
|
<span style="color: #000000; font-weight: bold;">
|
169
|
<?=$desc;?>
|
170
|
</span>
|
171
|
</p>
|
172
|
</div>
|
173
|
</body>
|
174
|
</html>
|
175
|
|
176
|
<?php
|
177
|
|
178
|
} // end function
|
179
|
|
180
|
|
181
|
function display_login_form() {
|
182
|
require_once("globals.inc");
|
183
|
global $config, $g;
|
184
|
$g['theme'] = $config['theme'];
|
185
|
|
186
|
unset($input_errors);
|
187
|
|
188
|
if(isAjax()) {
|
189
|
if (isset($_POST['login'])) {
|
190
|
if($_SESSION['Logged_In'] <> "True") {
|
191
|
isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = "unknown reason";
|
192
|
echo "showajaxmessage('Invalid login ({$login_error}).');";
|
193
|
}
|
194
|
if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
|
195
|
// TODO: add the IP from the user who did lock the device
|
196
|
$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
|
197
|
echo "showajaxmessage('This device is currently beeing maintained by: {$whom}.');";
|
198
|
}
|
199
|
}
|
200
|
exit;
|
201
|
}
|
202
|
|
203
|
?>
|
204
|
|
205
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
206
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
207
|
<html>
|
208
|
<head>
|
209
|
<script type="text/javascript" src="/javascript/scriptaculous/prototype.js"></script>
|
210
|
<script type="text/javascript" src="/javascript/scriptaculous/scriptaculous.js"></script>
|
211
|
<title><?=gettext("Login"); ?></title>
|
212
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
213
|
<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
|
214
|
<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
|
215
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
|
216
|
<?php else: ?>
|
217
|
<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
|
218
|
<?php endif; ?>
|
219
|
<script type="text/javascript">
|
220
|
<!--
|
221
|
function page_load() {}
|
222
|
function clearError() {
|
223
|
if($('inputerrors'))
|
224
|
$('inputerrors').innerHTML='';
|
225
|
}
|
226
|
<?php
|
227
|
require("headjs.php");
|
228
|
echo getHeadJS();
|
229
|
?>
|
230
|
//-->
|
231
|
</script>
|
232
|
<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
|
233
|
</head>
|
234
|
<body onload="page_load()">
|
235
|
<div id="login">
|
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
|
?>
|