forked from alex-phillips/TwoFactorAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
86 lines (76 loc) · 3.27 KB
/
index.php
File metadata and controls
86 lines (76 loc) · 3.27 KB
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
<?php
/**
* TwoFactorAuth index page
*
* @author Arno0x0x - https://twitter.com/Arno0x0x
* @license GPLv3 - licence available here: http://www.gnu.org/copyleft/gpl.html
* @link https://github.com/Arno0x/
*/
//------------------------------------------------------
// Include config file
require_once("config.php");
//------------------------------------------------------
// Application base url
$baseUrl = rtrim(dirname($_SERVER["SCRIPT_NAME"]), '/');
//------------------------------------------------------
// If this page is being called for the first time since the package has been
// deployed on a server and the installation hasn't been performed yet, then redirect
// to the insstallation page
if (!file_exists(USER_SQL_DATABASE_FILE)) {
$redirectTo = ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === "on")? "https://" : "http://").$_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$baseUrl."/install/install.php";
header("Location: /install/install.php",true,302);
}
else {
//------------------------------------------------------
// Restore session
session_name(SESSION_NAME);
session_start();
// Check the whether we have a currently logged in user
if (isset($_SESSION["authenticated"]) && $_SESSION["authenticated"] === true) {
//------------------------------------------------------
// Retrieve the currently logged user from the session
$username = $_SESSION["username"];
echo <<<EOT
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TwoFactorAuth</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container" style="margin-top: 10px">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<div class="panel panel-default">
<div class="panel-heading" style="text-align: center">
<span class="fa fa-user" aria-hidden="true"></span>
<span class="panel-title"><strong>Logged as {$username}</strong></span>
<a href="user/logout.php"><span style="font-size: 1.5em" class="fa fa-power-off pull-right"></span></a>
</div> <!-- End of panel heading -->
<ul class="list-group">
EOT;
echo "<li class=\"list-group-item\"><a href=\"user/user.php\">User management</a> <span class=\"fa fa-user pull-right\" aria-hidden=\"true\"></span></li>";
if (isset($_SESSION["isAdmin"]) && $_SESSION["isAdmin"] === true) {
echo "<li class=\"list-group-item\"><a href=\"admin/admin.php\">Administration</a> <span class=\"fa fa-wrench pull-right\" aria-hidden=\"true\"></span></li>";
}
echo <<<EOT
</ul>
</div>
</div> <!-- End of column classes -->
</div> <!-- End of row -->
</div> <!-- End of container -->
</body>
</html>
EOT;
}
else {
$redirectTo = ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === "on")? "https://" : "http://").$_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$baseUrl."/login/login.php";
header("Location: /login/login.php",true,302);
}
}
?>