-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
164 lines (159 loc) · 4.44 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
<?php
session_start();
require('php-bin/db.inc.php');
require('php-bin/global.php');
$logged_in = isset( $_SESSION['User'] );
function load_user_data( $type ){
$conn = new mysqli( DB_HOST, DB_USER, DB_PASS, 'users' );
$user = $conn -> real_escape_string( $_SESSION['User'] );
$query = "SELECT * FROM `users` WHERE name='$user'";
$res = $conn -> query($query);
if( !$res ){
return '';
}
$data = $res -> fetch_assoc();
if( !$data ){
return '';
}
if( isset( $data[$type] ) ){
return $data[$type];
}
return '';
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo htmlentities(CTF_NAME); ?></title>
<link href="http://fonts.googleapis.com/css?family=Lato&subset=latin,latin-ext" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="style.css" />
<script src="home.js"></script>
<script src="dates.js"></script>
</head>
<body>
<div id="head">
<span class="title">
<?php echo htmlentities(CTF_NAME); ?>
</span>
<ul id="nav">
<?php
if( !$logged_in ){
?>
<li onclick="Data.ShowDialog('Register')"><span class="text">Register</span></li>
<li onclick="Data.ShowDialog('Login')"><span class="text">Log In</span></li>
<?php
}else{
?>
<?php
if( load_user_data('role') === "admin" ){
?>
<li onclick="location.assign('dashboard.php')"><span class="text">Dashboard</span></li>
<?php
}
?>
<li onclick="location.assign('account.php')"><span class="text">Account</span></li>
<li onclick="location.assign('challenges.php')"><span class="text">Challenges</span></li>
<li onclick="location.assign('scoreboard.php')"><span class="text">Scoreboard</span></li>
<li onclick="Data.SignOut()"><span class="text">Log Out</span></li>
<?php
}
?>
</ul>
</div>
<div id="main">
<div id="countdown">
<span id="days"></span> DAYS,
<span id="hours"></span> HOURS,
<span id="minutes"></span> MINUTES,
<span id="seconds"></span> SECONDS
</div>
<hr />
<div id="user">
<?php
if( $logged_in ){
echo 'Welcome, ' . htmlentities($_SESSION['User']) . '.';
}else{
echo 'Please sign in to participate in ' . htmlentities(CTF_NAME) . '.';
}
?>
</div>
<div id="disp-msg"></div>
</div>
<footer>
<?php echo FOOTER; ?>
</footer>
<div id="dialogs" class="modal">
<div class="popup" data-dlg="Login">
<div class="title">
Log In
<img src="x.png" onclick="Data.HideDialog('Login')" alt="" class="closer" />
</div>
<form onsubmit="Data.SignIn(event)" id="login-form">
<table>
<tbody>
<tr>
<td>Username:</td>
<td><input type="text" name="user" placeholder="Username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" placeholder="Password123" /></td>
</tr>
</tbody>
</table>
<button type="submit" class="submit">Log In</button>
</form>
</div>
<div class="popup" data-dlg="Register">
<div class="title">
Register
<img src="x.png" onclick="Data.HideDialog('Register')" alt="" class="closer" />
</div>
<form onsubmit="Data.SignUp(event)" id="signup-form">
<table>
<tbody>
<tr>
<td>Username:</td>
<td><input type="text" name="user" placeholder="Username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="pwd" placeholder="Password123" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="email" name="email" placeholder="[email protected]" /></td>
</tr>
<tr>
<td>
Why are you signing up?
</td>
<td>
<select name="role">
<option value="competitor" selected>To compete as a Student</option>
<option value="spectator">To spectate</option>
</select>
</td>
</tr>
</tbody>
</table>
<button type="submit" class="submit">Register</button>
</form>
</div>
<div class="popup" data-dlg="Success">
<div class="title">
Success
</div>
<span id="success-msg">Operation succeeded.</span>
<button onclick="location.reload()" class="submit">OK</button>
</div>
<div class="popup" data-dlg="Failure">
<div class="title">
Failure
</div>
<span id="failure-msg">Operation failed.</span>
<button onclick="location.reload()" class="submit">OK</button>
</div>
</div>
</body>
</html>