Project

General

Profile

Download (8.39 KB) Statistics
| Branch: | Tag: | Revision:
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("priv.inc");
39

    
40
/* We only support htpasswd backed HTTP Basic auth and session
41
 * based backing methods at the moment.
42
 * 		session_auth - this will use session based authentication and timeout
43
 * 		htpasswd_backed - this uses the "standard" .htpasswd file
44
 * 		passwd_backed - this will use the system passwd file in /etc
45
 * 		radius_backed - this will allow you to use a radius server
46
 *		pam_backed - this uses the system's PAM facility .htpasswd file
47
 */
48

    
49
//log_error("debug: FILE_NAME = {$_SERVER['REQUEST_URI']}");
50
//log_error("debug: FILE_NAME = {$_SERVER['SCRIPT_FILENAME']}");
51
//log_error("debug: SCRIPT_NAME = {$_SERVER['SCRIPT_NAME']}");
52

    
53
/* enable correct auth backend, default to htpasswd_backed */
54
$ldapcase = $config['system']['webgui']['backend'];
55
switch($ldapcase)
56
{
57
	case ldap:
58
		$backing_method="ldap_backed";
59
		break;
60
	case ldapother:
61
		$backing_method="ldap_backed";
62
		break;
63
	default:
64
		$backing_method="local_backed";
65
}
66

    
67
/* Authenticate user - exit if failed */
68
if (!session_auth($backing_method))
69
	exit;
70

    
71
/*
72
 * Once here, the user has authenticated with the web server.
73
 * We give them access only to the appropriate pages based on
74
 * the user or group privileges.
75
 */
76
$allowedpages = getAllowedPages($HTTP_SERVER_VARS['AUTH_USER']);
77

    
78
/*
79
 * redirect to first allowed page if requesting a wrong url
80
 */
81
if (!isAllowedPage($_SERVER['SCRIPT_NAME'])) {
82
	if (count($allowedpages) > 0) {
83
		$page = str_replace('*', '', $allowedpages[0]);
84
		$_SESSION['Post_Login'] = true;
85
		pfSenseHeader("/{$page}");
86
		exit;
87
	} else {
88
		display_error_form("201", "No page assigned to this user! Click here to logout.");
89
		exit;
90
	}
91
} else 
92
	$_SESSION['Post_Login'] = true;
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
function display_error_form($http_code, $desc) {
108
	global $config, $g;
109
	$g['theme'] = $config['theme'];
110
	if(isAjax()) {
111
		echo "Error: {$http_code} Description: {$desc}";
112
		return;
113
	}
114

    
115
?>
116

    
117
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
118
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
119
<html>
120
	<head>
121
		<script type="text/javascript" src="/javascript/scriptaculous/prototype.js"></script>
122
		<script type="text/javascript" src="/javascript/scriptaculous/scriptaculous.js"></script>
123
		<title><?=$http_code?></title>
124
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
125
		<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
126
		<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
127
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
128
		<?php else: ?>
129
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
130
		<?php endif; ?>
131
		<script type="text/javascript">
132
		<!--
133
			function page_load() {}
134
			function clearError() {
135
				if($('inputerrors'))
136
				$('inputerrors').innerHTML='';
137
			}
138
			<?php
139
				require("headjs.php");
140
				echo getHeadJS();
141
			?>
142
		//-->
143
		</script>
144
		<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
145
	</head>
146
	<body onload="page_load();">
147
		<div id="errordesc">
148
			<h1>&nbsp</h1>
149
			<a href="/index.php?logout">
150
			<p id="errortext" style="vertical-align: middle; text-align: center;">
151
				<span style="color: #000000; font-weight: bold;">
152
					<?=$desc;?>
153
				</span>
154
			</p>
155
		</div>
156
	</body>
157
</html>
158

    
159
<?php
160

    
161
} // end function
162

    
163

    
164
function display_login_form() {
165
	require_once("globals.inc");
166
	global $config, $g;
167
	$g['theme'] = $config['theme'];
168

    
169
	unset($input_errors);
170

    
171
	if(isAjax()) {
172
		if (isset($_POST['login'])) {
173
			if($_SESSION['Logged_In'] <> "True") {
174
				isset($_SESSION['Login_Error']) ? $login_error = $_SESSION['Login_Error'] : $login_error = "unknown reason";
175
				echo "showajaxmessage('Invalid login ({$login_error}).');";
176
			}
177
			if (file_exists("{$g['tmp_path']}/webconfigurator.lock")) {
178
				// TODO: add the IP from the user who did lock the device
179
				$whom = file_get_contents("{$g['tmp_path']}/webconfigurator.lock");
180
				echo "showajaxmessage('This device is currently beeing maintained by: {$whom}.');";
181
			}
182
		}
183
		exit;
184
	}
185

    
186
?>
187

    
188
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
189
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
190
<html>
191
	<head>
192
		<script type="text/javascript" src="/javascript/scriptaculous/prototype.js"></script>
193
		<script type="text/javascript" src="/javascript/scriptaculous/scriptaculous.js"></script>
194
		<script>document.observe('dom:loaded', function() { $('usernamefld').focus(); });</script>
195
		
196
		<title><?=gettext("Login"); ?></title>
197
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
198
		<link rel="shortcut icon" href="/themes/<?= $g['theme'] ?>/images/icons/favicon.ico" />
199
		<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/login.css")): ?>
200
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/login.css" media="all" />
201
		<?php else: ?>
202
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/all.css" media="all" />
203
		<?php endif; ?>
204
		<script type="text/javascript">
205
		<!--
206
			function page_load() {}
207
			function clearError() {
208
				if($('inputerrors'))
209
				$('inputerrors').innerHTML='';
210
			}
211
			<?php
212
				require("headjs.php");
213
				echo getHeadJS();
214
			?>
215
		//-->
216
		</script>
217
		<script type="text/javascript" src="/themes/<?= $g['theme'] ?>/javascript/niftyjsCode.js"></script>
218
	</head>
219
	<body onload="page_load()">
220
		<div id="login">
221
			<form id="iform" name="login_iform" method="post" autocomplete="off" action="<?=$_SERVER['SCRIPT_NAME'];?>">
222
				<h1></h1>
223
				<div id="inputerrors"><?=$_SESSION['Login_Error'];?></div>
224
				<p>
225
					<span style="text-align:left">
226
						<?=gettext("Username"); ?>:<br>
227
						<input onclick="clearError();" onchange="clearError();" id="usernamefld" type="text" name="usernamefld" class="formfld user" tabindex="1" />
228
					</span>
229
				</p>
230
				<br>
231
				<p>
232
					<span style="text-align:left">
233
						<?=gettext("Password"); ?>: <br>
234
						<input onclick="clearError();" onchange="clearError();" id="passwordfld" type="password" name="passwordfld" class="formfld pwd" tabindex="2" />
235
					</span>
236
				</p>
237
				<br>
238
				<p>
239
					<span style="text-align:center; font-weight: normal ; font-style: italic">
240
						<?=gettext("Enter username and password to login."); ?>
241
					</span>
242
				</p>        
243
				<p>
244
					<span style="text-align:center">
245
						<input type="submit" name="login" class="formbtn" value="<?=gettext("Login"); ?>" tabindex="3" />
246
					</span>
247
				</P>
248
			</form>
249
		</div>
250
	</body>
251
</html>
252
<?php
253
} // end function
254

    
255
?>
(5-5/43)