/
login.php
269 lines (239 loc) · 13.8 KB
/
login.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
<?php
// vim: tabstop=2:softtabstop=2
if(!isset($_SERVER['HTTPS'])) { //Force use of SSL
header("location: https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
}
require_once "config.php";
require_once "functions.php";
// I18N support information here
if (empty($locale))
$language = 'en_GB.utf8';
if (isset($_GET['locale']) && !empty($_GET['locale']))
$language = $_GET['locale'];
putenv("LANG=$language");
setlocale(LC_ALL, $language);
// Set the text domain as 'login'
$domain = 'login';
bindtextdomain($domain, "locale");
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
session_start();
$successpage = "index.php";
if(!empty($_SESSION["userid"])) {
header("Location: $successpage");
} elseif ($_SERVER['REQUEST_METHOD'] == "POST") {
if (!empty($_POST["username"]) && !empty($_POST["password"])) {
$dbh = db_connect();
$sql = "SELECT id, \"user\", hash, salt, name, admin FROM users WHERE \"user\" = :username";
$sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute(array(":username" => $_POST["username"]));
$data = $sth->fetch(PDO::FETCH_ASSOC);
if ($data && hash("sha256", $_POST["password"] . $data["salt"]) == $data["hash"]) {
$_SESSION["userid"] = $data["id"];
$_SESSION["username"] = $data["user"];
$_SESSION["usernick"] = $data[$data["name"] ? "name" : "user"];
$_SESSION["useradmin"] = $data["admin"];
$_SESSION["salt"] = hash("sha256", $_SERVER["REQUEST_TIME"]);
$_SESSION["fingerprint"] = session_create_fingerprint();
if (array_key_exists("redirectto",$_GET)) {
header("Location: " . rawurldecode($_GET["redirectto"]));
} elseif (array_key_exists("backto",$_SESSION)) {
header("Location: " . $_SESSION["backto"]);
} elseif (array_key_exists("HTTP_REFERER",$_SERVER)) {
header("Location: " . rawurldecode($_SERVER["HTTP_REFERER"]));
} else {
header("Location: $successpage");
}
} else {
$error = _("Incorrect username or password");
error_log("[" . date('d/M/Y:H:i:s O') .
"] authentication failure: [client: " .
$_SERVER['REMOTE_ADDR'] .
"] [user: " . $_POST['username'] . "]\n",
3, "/var/log/taxidi.log");
}
} else {
$error = _("Form not completed");
}
}
?>
<!DOCTYPE html>
<html lang="<?php echo $language ?>">
<head>
<script src="bootstrap/js/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title><?php echo _('Login'); ?> · Taxídí</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Web interface for Taxidi check-in system">
<meta name="author" content="">
<!-- Le styles -->
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="resources/img/favicon.ico" />
<!--<link rel="apple-touch-icon-precomposed" sizes="144x144" href="bootstrap/ico/apple-touch-icon-144-precomposed.png"> -->
<!--<link rel="apple-touch-icon-precomposed" sizes="114x114" href="bootstrap/ico/apple-touch-icon-114-precomposed.png"> -->
<!--<link rel="apple-touch-icon-precomposed" sizes="72x72" href="bootstrap/ico/apple-touch-icon-72-precomposed.png"> -->
<!-- <link rel="apple-touch-icon-precomposed" href="resources/img/apple-touch-icon-57-optimized.png"> -->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.php">Taxídí</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="login.php"><?php echo _('Login') ?></a></li>
</ul>
<ul class="nav pull-right">
<li id="fat-menu" class="dropdown">
<a href="#" id="drop3" role="button" class="dropdown-toggle" data-toggle="dropdown">
<?php echo _('Language') ?>: <strong>
<?php $lang = substr($language, 0, 2);
if ($lang=="en") echo "English (UK)";
if ($language=="de_DE") echo "Deutsch";
if ($language=="fr_FR.utf8") echo "français";
?>
</strong><b class="caret"></b></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="drop3">
<li><a tabindex="-1" href="login.php?locale=en">English</a></li>
<li><a tabindex="-1" href="login.php?locale=de_DE">Deutsch</a></li>
<li><a tabindex="-1" href="login.php?locale=fr_FR.utf8">françias</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#"><?php echo _('Translate this application') ?></a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- TODO: Store banner in config so it's not duplicated twice here -->
<div class="visible-desktop" id="modal_banner"></div>
<div class="row-fluid" id="noscript_banner">
<div class="span4"></div>
<div class="span5" style="margin-left: auto; margin-right:auto">
<div class="alert alert-error">
<h2 style="text-align: center"><i class="icon-lock" style="margin-top: 10px;"></i>
<?php echo _('Private Computer System') ?>
<i class="icon-lock" style="margin-top: 10px;"></i></h2><br>
<p style="text-align: justify">
This computer system including all related equipment, network devices
(specifically including Internet access), are provided only for authorized use.
All computer systems may be monitored for all lawful purposes, including to
ensure that their use is authorized, for management of the system, to
facilitate protection against unauthorized access, and to verify security
procedures, survivability and operational security. Monitoring includes active
attacks by authorized personnel and their entities to test or verify the
security of the system. During monitoring, information may be examined,
recorded, copied and used for authorized purposes. All information including
personal information, placed on or sent over this system may be monitored. Uses
of this system, authorized or unauthorized, constitutes consent to monitoring
of this system. Unauthorized use may subject you to criminal prosecution.
Evidence of any such unauthorized use collected during monitoring may be used
for administrative, criminal or other adverse action.</p>
<p><b>
<?php echo _('Login Agreement'); /* Use of this system constitutes consent to monitoring for these purposes. */ ?>
<br></b></p>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span4"></div>
<div class="span4">
<?php echo $error ? "<div class=\"alert alert-error\">$error</div>": ""; ?>
<form class="form-horizontal" method="POST">
<legend><strong><?php echo _('Login') ?></strong></legend>
<div class="control-group">
<label class="control-label" for="username"><?php echo _('Username') ?></label>
<div class="controls">
<input type="text" id="username" name="username"
autocapitalize="off"
placeholder="<?php echo _('Username') ?>" autofocus>
</div>
</div>
<div class="control-group">
<label class="control-label" for="password"><?php echo _('Password') ?></label>
<div class="controls">
<input type="password" id="password" name="password"
placeholder="<?php echo _('Password') ?>">
</div>
</div>
<div class="control-group">
<div class="controls form-inline">
<button type="submit" class="btn btn-primary"><?php echo _('Sign in') ?></button>
<!--<label class="checkbox pull-right">
<input type="checkbox"> Remember me
</label>-->
</div>
</div>
</form>
<noscript>
<div style="text-align: center">
<a href="login.php?locale=en">English</a> ·
<a href="login.php?locale=de_DE">Deutsch</a> ·
<a href="login.php?locale=fr_FR.utf8">françias</a> ·
<a href="#"><?php echo _('Translate this application') ?></a>
</div>
</noscript>
<script>
// add modal banner:
var width = $(window).width();
$(document).ready(function() {
if (width > 979) {
console.log("Desktop view");
document.getElementById('noscript_banner').innerHTML = "";
document.getElementById('modal_banner').innerHTML =
'<div class="modal hide fade" id="banner" tabindex="-1" role="dialog" aria-labelledby="bannerLabel" aria-hidden="true" style="margin-top: -270px;">' +
'<div class="modal-header" style="background-color: #850505; border-bottom-color: #600000; color: white;">' +
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
'<h3 id="bannerLabel" style="margin: 0;">' +
'<i class="icon-warning-sign icon-white" style="margin-top: 7px;">' +
'</i> <?php echo _('Warning'); ?> </h3></div>' +
'<div class="modal-body" style="background-color: #800000; color: white;">' +
'<h2 style="text-align: center"><i class="icon-lock icon-white" style="margin-top: 10px;"></i> '+
'<?php echo _('Private Computer System') ?> '+
'<i class="icon-lock icon-white" style="margin-top: 10px;"></i></h2><br>'+
'<p style="text-align: justify">'+
'This computer system including all related equipment, network devices'+
'(specifically including Internet access), are provided only for authorized use.'+
'All computer systems may be monitored for all lawful purposes, including to'+
'ensure that their use is authorized, for management of the system, to'+
'facilitate protection against unauthorized access, and to verify security'+
'procedures, survivability and operational security. Monitoring includes active'+
'attacks by authorized personnel and their entities to test or verify the'+
'security of the system. During monitoring, information may be examined,'+
'recorded, copied and used for authorized purposes. All information including '+
'personal information, placed on or sent over this system may be monitored. Uses'+
'of this system, authorized or unauthorized, constitutes consent to monitoring'+
'of this system. Unauthorized use may subject you to criminal prosecution.'+
'Evidence of any such unauthorized use collected during monitoring may be used'+
'for administrative, criminal or other adverse action.</p>'+
'<p><b>'+
'<?php echo _('Login Agreement'); /* Use of this system constitutes consent to monitoring for these purposes. */ ?>'+
'<br></b></p></div>'+
'<div class="modal-footer" style="background-color: #850505; color: white; border-top-color: #600000; box-shadow: 0 1px 0 #700000 inset;">'+
'<button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo _('Continue'); ?> <i class="icon-arrow-right"></i>'+
'</button></div></div>';
}
});
$(function(){
<? echo $_SERVER['REQUEST_METHOD'] != "POST" ? "$('#banner').modal('show');" : ""; ?>
$("#banner").on("hide", function() {$("#username").focus();});
});
</script>
<?php require_once "template/footer.php" ; ?>