-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
357 lines (342 loc) · 11.6 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
include("phpscripts/fillin/scripts.php");
$conn = get_mysql_conn();
if(gettype($conn) !== "object" && file_exists("config.php")){
echo "<b><br>A MySQL connection error occured!<br><br>If you a guest of the server. Report the above error message to the server owner and wait for it to be fixed, there isn't much you can do.<br>If you are the server owner, clean any and all tables from your MySQL database, then delete the '/config.php' file in the main index folder of your server and refresh the page to able to setup the MySQL connection.</b>";
return;
}
//Main performance cause when loading pages is due to lots of user_has_permission functions. Adding onto the slower times is because user_has_permission checks if users are banned (which requires a MySQL query which takes EVEN longer).
//A solution must be found at once, but for now it is sort of tolerable. Just make sure ALL requests check if user has permission to do the requested action first.
// ### SECURITY COMES FIRST ###
$pageBase = 0;
$url = (parse_url($_SERVER['REQUEST_URI']));
$url['path'] = str_replace('.php', '', $url['path']);
$url['path'] = explode('/', $url['path']);
$url['path'][$pageBase] = strtolower($url['path'][$pageBase]);
if(count($url['path']) > $pageBase + 1 && $url['path'][$pageBase + 1] <> ''){
$url['path'][$pageBase + 1] = str_replace("%20", " ", $url['path'][$pageBase + 1]);
}
array_shift($url["path"]);
$url["path"] = array_map("strtolower", $url["path"]);
//Begin main page routing
$adminNavbar = false; //Never use this unless were serving the admin panel
$showNavbar = true;
$includeHead = true;
$informBans = true;
if(file_exists("config.php")){
$settings = include("config.php");
start_session();
$currUsertags = [];
if(accounts::is_logged_in()){
$currAccount = accounts::get_current_account();
if(!isset($_SESSION["usertags"])){
$_SESSION["usertags"] = [];
}
if(!isset($_SESSION["permissions"])){
$_SESSION["permissions"] = [];
}
if(isset($_SESSION["lastUsertagsUpdate"])){
if(time() - $_SESSION["lastUsertagsUpdate"] > $settings["updateUsertagsInterval"] || $_SESSION["usertags"] == []){ //update session usertags and permissions every xx seconds
$_SESSION["lastUsertagsUpdate"] = time();
$_SESSION["usertags"] = accounts::get_current_usertags();
$_SESSION["permissions"] = accounts::get_all_permissions();
//echo "updated usertags and permissions!";
}
}
$currUsertags = $_SESSION["usertags"];
}
$page = "/pages/errors/notfound.php"; //if we didn't assign a page dir by the end of the code, display 404
if($url["path"][0] == "" || $url["path"][0] == "index"){ //display main index page
//$page = "/pages/index.php";
$page = "/pages/forums/forums.php"; //really we should be sending user to index.php, but since were still starting, straight to forums!
}
if($url["path"][0] == "index"){ //display index page
$page = "/pages/index.php";
}
if($url["path"][0] == "forums"){ //display forums page
$page = "/pages/forums/forums.php";
}
if($url["path"][0] == "subforum"){ //display subforums page
if(isset($url["path"][1]) && $url["path"][1] != ""){
$subforum = forums::get_by_id($url["path"][1]);
if(usertags::can_tag_do($currUsertags, $subforum->canview) && $subforum->type == "subforum"){
$page = "/pages/forums/subforum.php";
if(isset($url["path"][2]) && $url["path"][2] == "postthread"){
$page = "/pages/forums/postthread.php";
}
}
}else{
header("Location:/");
}
}
if($url["path"][0] == "thread"){ //start thread section
if(isset($url["path"][1]) && $url["path"][1] != ""){ //main thread
$thread = forums::get_by_id($url["path"][1]);
$parent = forums::get_by_id($thread->parent);
if(isset($thread->id) && $thread->type == "thread" && usertags::can_tag_do($currUsertags, $parent->canview)){
$page = "/pages/forums/thread.php";
}
}else{
header("Location:/");
}
if(isset($url["path"][2]) && $url["path"][2] == "postreply"){ //post thread reply
if(isset($currAccount)){
$page = "/pages/forums/postreply.php";
}else{
$page = "/pages/errors/nopermission.php";
}
}
if(isset($url["path"][2]) && $url["path"][2] == "editthread"){ //edit thread
if(isset($currAccount)){
$thread = forums::get_by_id($url["path"][1]);
$page = "/pages/forums/editthread.php";
}else{
$page = "/pages/errors/nopermission.php";
}
}
if(isset($url["path"][2]) && $url["path"][2] == "editreply"){ //edit reply
if(isset($url["path"][3]) && $url["path"][3] != ""){
if(isset($currAccount)){
$replyID = $url["path"][3];
$page = "/pages/forums/editreply.php";
}else{
$page = "/pages/errors/nopermission.php";
}
}
}
}
if($url["path"][0] == "admin"){ //start admin panel
if(isset($currAccount) && accounts::is_staff($currAccount->id)){
$informBans = false;
$showNavbar = false;
$adminNavbar = true;
if($url["path"][1] == ""){ //dashboard
$page = "/admin/pages/dashboard.php";
}
if($url["path"][1] == "settings"){ //website settings
$page = "/admin/pages/settings.php";
}
if($url["path"][1] == "forums"){ //forums
$page = "/admin/pages/forums.php";
if(isset($url["path"][2]) && $url["path"][2] != ""){
$forum = forums::get_by_id($url["path"][2]);
if(isset($forum->id)){
if($forum->type == "subforum" || $forum->type == "forum"){
$page = "/admin/pages/updateforum.php";
}
}
if(usertags::user_has_permission($currUsertags, "createforums")){
if($url["path"][2] == "new"){
$page = "/admin/pages/createforum.php";
}
if(isset($url["path"][3]) && $url["path"][3] != "" && $forum->type == "forum"){
$page = "/admin/pages/createsubforum.php";
}
}else{
$page = "/pages/errors/nopermission.php";
}
}
}
if($url["path"][1] == "users"){ //users
$page = "/admin/pages/users.php";
}
if($url["path"][1] == "usertags"){ //usertags
$page = "/admin/pages/usertags.php";
if(isset($url["path"][2]) && $url["path"][2] != ""){
$usertag = usertags::get_by_id($url["path"][2]);
if(isset($usertag->id)){
if(usertags::user_has_permission($currUsertags, "updateusertag")){
$page = "/admin/pages/updateusertag.php";
}else{
$page = "/pages/errors/nopermission.php";
}
}
if($url["path"][2] == "new"){
if(usertags::user_has_permission($currUsertags, "addusertag")){
$page = "/admin/pages/createusertag.php";
}else{
$page = "/pages/errors/nopermission.php";
}
}
}
}
if($url["path"][1] == "permissions"){ //permissions
$page = "/admin/pages/permissions.php";
if(isset($url["path"][2]) && $url["path"][2] != ""){
$usertag = usertags::get_by_id($url["path"][2]);
if(isset($usertag->id)){
if(usertags::user_has_permission($currUsertags, "updatepermissions")){
$page = "/admin/pages/updatepermissions.php";
}else{
$page = "/pages/errors/nopermission.php";
}
}
}
}
if($url["path"][1] == "sessions"){ //sessions
$page = "/admin/pages/sessions.php";
}
if($url["path"][1] == "logs"){ //logs
$page = "/admin/pages/logs.php";
if(count($url["path"]) > 2){
$logDate = $url["path"][2]."/".$url["path"][3]."/".$url["path"][4];
$page = "/admin/pages/viewLog.php";
}
}
}else{
logs::add_log("admin access", "$1 tried to enter the admin panel, but he is not staff");
$page = "/pages/errors/nopermission.php";
}
}
if($url["path"][0] == "user"){
if(accounts::is_logged_in()){
if($url["path"][1] == "login"){
$page = "/pages/errors/nopermission.php";
}
if($url["path"][1] == "register"){
$page = "/pages/errors/nopermission.php";
}
}else{
if($url["path"][1] == "login"){
$page = "/pages/login.php";
}
if($url["path"][1] == "register"){
$page = "/pages/register.php";
}
}
if($url["path"][1] == "profile"){
if(isset($url["path"][2]) && $url["path"][2] != ""){
$profile = accounts::get_by_id($url["path"][2]);
$page = "/pages/profile.php";
}
}
if($url["path"][1] == "settings"){
if(isset($currAccount)){
$page = "/pages/settings.php";
}else{
$page = "/pages/errors/nopermission.php";
}
}
}
if($url["path"][0] == "about"){
$page = "/pages/about.php";
}
if($url["path"][0] == "403"){
$page = "/pages/errors/nopermission.php";
}
if($url["path"][0] == "404"){
$page = "/pages/errors/notfound.php";
}
}else{
$showNavbar = false;
$page = "/pages/firstTime.php";
}
?>
<?php if($includeHead){
include("phpscripts/fillin/head.php");
} ?>
<div id="body_div">
<?php
if($adminNavbar){
include("/admin/fillin/navbar.php");
}
if($showNavbar){
include("/phpscripts/fillin/navbar.php");
}
if(file_exists($_SERVER["DOCUMENT_ROOT"] . $page)){
include($page);
}else{
include("/pages/errors/fileerror.php");
}
?>
</div>
<?php
if(session_status() == 2 && isset($currAccount) && $informBans){
$warnings = accounts::get_warnings($currAccount->id);
$banned = accounts::confirm_ban($currAccount->id);
if(count($warnings) > 0 || $banned){
?>
<div class="modal fade" id="viewWarnings" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<?php
foreach($warnings as $key=>$value){
echo "
<div class='informWarningsDiv'>
Warning issued on ".timestamp_to_date($value->time, true)." by <b>".accounts::get_display_name($value->warnedby)."</b><br>
Reason: <i>$value->message</i>
</div>
";
if($key < count($warnings)-1){
echo "<br>";
}
}
if($banned){
echo "
<div class='informBansDiv'>
Banned by ".accounts::get_display_name($currAccount->bannedby)."<br>
Banned on the '".timestamp_to_date($currAccount->bannedtime, true)."' for '".$currAccount->bannedmsg."'<br>
Ban expires on the '".timestamp_to_date($currAccount->unbantime, true)."'
</div>
";
}
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" disabled id="viewWarningsAcceptBtn">Accept (4)</button>
</div>
</div>
</div>
</div>
<script>
$("#viewWarnings").modal("show")
setTimeout(function(){
$("#viewWarningsAcceptBtn").html("Accept (3)")
setTimeout(function(){
$("#viewWarningsAcceptBtn").html("Accept (2)")
setTimeout(function(){
$("#viewWarningsAcceptBtn").html("Accept (1)")
setTimeout(function(){
$("#viewWarningsAcceptBtn").html("Accept")
$("#viewWarningsAcceptBtn").removeAttr("disabled")
}, 1000)
}, 1000)
}, 1000)
}, 1000)
$("#viewWarningsAcceptBtn").click(function(){
$.post("phpscripts/requests/confirmwarnings.php", function(html){
console.log(html)
})
})
</script>
<?php
}
}
if(session_status() == 2 && isset($_SESSION["pageMessage"]) && $_SESSION["pageMessage"] !== ""){
$pageMessageType = "success";
if(isset($_SESSION["pageMessageType"])){
$pageMessageType = $_SESSION["pageMessageType"];
}
?>
<script>
$.notify({
message: "<?php echo $_SESSION["pageMessage"] ?>",
},{
type: "<?php echo $pageMessageType ?>",
z_index: 103001,
placement: {
from: "top",
align: "left"
},
})
</script>
<?php }
if(isset($_SESSION)){
unset($_SESSION["pageMessage"]);
unset($_SESSION["pageMessageType"]);
}
if(gettype($conn) == "object"){
mysqli_close($conn);
}
?>