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