Project

General

Profile

Download (7.63 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
		pfSense_MODULE: authgui
38
*/
39

    
40
include_once("auth.inc");
41
include_once("priv.inc");
42

    
43
/* Authenticate user - exit if failed */
44
if (!session_auth()) {
45
	display_login_form();
46
	exit;
47
}
48

    
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
$allowedpages = getAllowedPages($HTTP_SERVER_VARS['AUTH_USER']);
55

    
56
/*
57
 * redirect to first allowed page if requesting a wrong url
58
 */
59
if (!isAllowedPage($_SERVER['SCRIPT_NAME'], $_SESSION['Username'])) {
60
	if (count($allowedpages) > 0) {
61
		$page = str_replace('*', '', $allowedpages[0]);
62
		$_SESSION['Post_Login'] = true;
63
		require_once("functions.inc");
64
		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

    
73
/*
74
 * redirect browsers post-login to avoid pages
75
 * taking action in reponse to a POST request
76
 */
77
if (!$_SESSION['Post_Login']) {
78
	$_SESSION['Post_Login'] = true;
79
	require_once("functions.inc");
80
	pfSenseHeader($_SERVER['REQUEST_URI']);
81
	exit;
82
}
83

    
84
/*
85
 * determine if the user is allowed access to the requested page
86
 */
87
function display_error_form($http_code, $desc) {
88
	global $config, $g;
89
	$g['theme'] = $config['theme'];
90
	if(isAjax()) {
91
		echo "Error: {$http_code} Description: {$desc}";
92
		return;
93
	}
94

    
95
?>
96

    
97
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
98
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
99
<html>
100
	<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
			<a href="/index.php?logout">
130
			<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
</html>
138

    
139
<?php
140

    
141
} // end function
142

    
143

    
144
function display_login_form() {
145
	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

    
166
?>
167

    
168
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
169
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
170
<html>
171
	<head>
172
		<script type="text/javascript" src="/javascript/scriptaculous/prototype.js"></script>
173
		<script type="text/javascript" src="/javascript/scriptaculous/scriptaculous.js"></script>
174
		<script>document.observe('dom:loaded', function() { $('usernamefld').focus(); });</script>
175
		
176
		<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
			<form id="iform" name="login_iform" method="post" autocomplete="off" action="<?=$_SERVER['SCRIPT_NAME'];?>">
202
				<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
</html>
232
<?php
233
} // end function
234

    
235
?>
(5-5/50)