Project

General

Profile

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