-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.php
294 lines (221 loc) · 9.77 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
/*
**************************************************************************************************************************
** CORAL Authentication Module v. 1.0
**
** Copyright (c) 2011 University of Notre Dame
**
** This file is part of CORAL.
**
** CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
**
** CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along with CORAL. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************************************************************
*/
session_start();
include_once 'directory.php';
$util = new Utility();
if (isset($_GET['service'])){
$service = $_GET['service'];
}else{
$service = $util->getCORALURL();
}
$errorMessage = '';
$message=' ';
$inputLoginID='';
$rememberChecked='';
if(isset($_SESSION['loginID'])){
$loginID=$_SESSION['loginID'];
$user = new User(new NamedArguments(array('primaryKey' => $loginID)));
}
//user is trying to log out
if(array_key_exists('logout', $_GET)){
$user->processLogout();
$message = _('You are successfully logged out of the system.');
$user = new User();
//get login, if set
$inputLoginID = $user->getRememberLogin();
if ($inputLoginID){
$rememberChecked = 'checked';
}
//the user is trying to log in
}else if (isset($_POST['loginID']) && isset($_POST['password'])){
$loginID = $_POST['loginID'];
$password = $_POST['password'];
$user = new User(new NamedArguments(array('primaryKey' => $loginID)));
//set login remember cookie if it was checked
if (isset($_POST['remember'])){
$user->setRememberLogin();
$rememberChecked = 'checked';
}else{
$user->unsetRememberLogin();
}
//perform login checks
if ($user->loginID == ''){
$errorMessage = _("Invalid login ID. Please try again.");
//perform login, if failed issue message
}else{
if(!$user->processLogin($password)){
$errorMessage = _("Invalid password. Please try again.");
$inputLoginID = $loginID;
}else{
//login succeeded, perform redirect
header('Location: ' . $service) ;
}
}
//user is already logged in
}else if(isset($_SESSION['loginID'])){
if ($user->getOpenSession()){
$message = _("You are already logged in as ") . $loginID . ".<br />" . _("You may log in as another user below,")." <a href='" . $service . "'>"._("return")."</a> "._("or")." <a href='?logout'>". _("logout")."</a>.";
}
$inputLoginID = $user->getRememberLogin();
if ($inputLoginID){
$rememberChecked = 'checked';
}
//user comes in new
}else{
$user = new User();
//get login, if set
$inputLoginID = $user->getRememberLogin();
if ($inputLoginID){
$rememberChecked = 'checked';
}
$message = _("Please enter login credentials to sign in.");
}
//user was just timed out
if(array_key_exists('timeout', $_GET)){
$errorMessage = _("Your session has timed out.");
$message = "";
}
//user does not have permissions to enter the module
if(array_key_exists('invalid', $_GET)){
$errorMessage = _("You do not have permission to enter.")."<br />"._("Please contact an administrator.");
$message = "";
}
//user needs to access admin page
if(array_key_exists('admin', $_GET)){
$errorMessage = _("You must log in before accessing the admin page.");
$message = "";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CORAL Authentication</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/thickbox.css" type="text/css" media="screen" />
<link rel="SHORTCUT ICON" href="images/clownfishfavicon.ico" />
<script type="text/javascript" src="js/plugins/jquery.js"></script>
<script type="text/javascript" src="js/plugins/thickbox.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/plugins/Gettext.js"></script>
<?php
// Add translation for the JavaScript files
global $http_lang;
$str = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
$default_l = $lang_name->getLanguage($str);
if($default_l==null || empty($default_l)){$default_l=$str;}
if(isset($_COOKIE["lang"])){
if($_COOKIE["lang"]==$http_lang && $_COOKIE["lang"] != "en_US"){
echo "<link rel='gettext' type='application/x-po' href='./locale/".$http_lang."/LC_MESSAGES/messages.po' />";
}
}else if($default_l==$http_lang && $default_l != "en_US"){
echo "<link rel='gettext' type='application/x-po' href='./locale/".$http_lang."/LC_MESSAGES/messages.po' />";
}
?>
</head>
<body>
<noscript><font face="arial"><?= _("JavaScript must be enabled in order for you to use CORAL. However, it seems JavaScript is either disabled or not supported by your browser. To use CORAL, enable JavaScript by changing your browser options, then")." <a href=''>"._("try again")."</a>."?></font></noscript>
<center>
<form name="loginForm" method="post" action="index.php?service=<?php echo htmlentities($service); ?>">
<br />
<div style="width:451px; height:307px;background-image:url('images/authpage.gif');background-repeat:no-repeat;text-align:right;">
<label style='text-align:left;width:100%;margin-top:100px;font-weight:normal;'><span class='smallerText'><?php echo $message; ?></span><span class='smallDarkRedText'><?php echo $errorMessage; ?></span></label><br />
<label for='loginID' style='margin-top:10px;'><?= _("Login ID:")?> </label>
<input type='text' id='loginID' name='loginID' value="<?php echo $inputLoginID; ?>" style='margin-top:10px;width:170px;' />
<br />
<label for='password' style='margin-bottom:15px;'><?= _("Password:")?> </label>
<input type='password' id='password' name='password' value='' style='width:170px;margin-bottom:15px;' />
<br />
<label for='remember'> </label>
<input type='checkbox' id='remember' name='remember' value='Y' style='margin:1px 0px 0px 0px; padding:0px; height:0.8em;' <?php echo $rememberChecked; ?> /><span style='float:left;' class='smallText'> <?= _("Remember my login ID")?></span>
<br />
<label for='loginbutton' style='margin-top:17px;'> </label>
<input type="submit" value="<?= _('Login')?>" id="loginbutton" class="loginButton" style='margin-top:17px;' />
</div>
<div class='boxRight'>
<p class="fontText"><?= _("Change language:");?></p>
<select name="lang" id="lang" class="dropDownLang">
<?php
// Get all translations on the 'locale' folder
$route='locale';
$lang[]="en_US"; // add default language
if (is_dir($route)) {
if ($dh = opendir($route)) {
while (($file = readdir($dh)) !== false) {
if (is_dir("$route/$file") && $file!="." && $file!=".."){
$lang[]=$file;
}
}
closedir($dh);
}
}else {
echo "<br>"._("Invalid translation route!");
}
// Get language of navigator
$defLang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
// Show an ordered list
sort($lang);
for($i=0; $i<count($lang); $i++){
if(isset($_COOKIE["lang"])){
if($_COOKIE["lang"]==$lang[$i]){
echo "<option value='".$lang[$i]."' selected='selected'>".$lang_name->getNameLang(substr($lang[$i],0,2))."</option>";
}else{
echo "<option value='".$lang[$i]."'>".$lang_name->getNameLang(substr($lang[$i],0,2))."</option>";
}
}else{
if($defLang==substr($lang[$i],0,2)){
echo "<option value='".$lang[$i]."' selected='selected'>".$lang_name->getNameLang(substr($lang[$i],0,2))."</option>";
}else{
echo "<option value='".$lang[$i]."'>".$lang_name->getNameLang(substr($lang[$i],0,2))."</option>";
}
}
}
?>
</select>
</div>
<div class='smallerText' style='text-align:center; margin-top:13px;'><a href='admin.php'><?= _("Admin page")?></a></div>
</form>
<br />
<br />
</center>
<br />
<br />
<script>
/*
* Functions to change the language with the dropdown
*/
$("#lang").change(function() {
setLanguage($("#lang").val());
location.reload();
});
// Create a cookie with the code of language
function setLanguage(lang) {
var wl = window.location, now = new Date(), time = now.getTime();
var cookievalid=2592000000; // 30 days (1000*60*60*24*30)
time += cookievalid;
now.setTime(time);
document.cookie ='lang='+lang+';path=/'+';domain='+wl.host+';expires='+now;
}
</script>
<script type="text/javascript">
//give focus to login form
document.getElementById('loginID').focus();
</script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>