forked from NamelessMC/Nameless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
124 lines (98 loc) · 3.32 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
<?php
/*
* Made by Samerton
* https://github.com/NamelessMC/Nameless/
* NamelessMC version 2.0.0-pr9
*
* License: MIT
*
* Main index file
*/
// Uncomment to enable debugging
// define('DEBUGGING', 1);
header('X-Frame-Options: SAMEORIGIN');
if ((!defined('DEBUGGING') || !DEBUGGING) && getenv('NAMELESS_DEBUGGING')) {
define('DEBUGGING', 1);
}
if (defined('DEBUGGING') && DEBUGGING) {
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
}
// Ensure PHP version >= 7.4
if (PHP_VERSION_ID < 70400) {
die('NamelessMC is not compatible with PHP versions older than 7.4');
}
// Start page load timer
$start = microtime(true);
// Definitions
const PATH = '/';
const ROOT_PATH = __DIR__;
$page = 'Home';
if (!ini_get('upload_tmp_dir')) {
$tmp_dir = sys_get_temp_dir();
} else {
$tmp_dir = ini_get('upload_tmp_dir');
}
if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) {
ini_set('session.cookie_secure', 'On');
}
ini_set('session.cookie_httponly', 1);
ini_set('open_basedir', ROOT_PATH . PATH_SEPARATOR . $tmp_dir . PATH_SEPARATOR . '/proc/stat');
// Get the directory the user is trying to access
$directory = $_SERVER['REQUEST_URI'];
$directories = explode('/', $directory);
$lim = count($directories);
if (isset($_GET['route']) && $_GET['route'] == '/rewrite_test') {
require_once('rewrite_test.php');
die();
}
// Start initialising the page
require(ROOT_PATH . '/core/init.php');
if (!isset($GLOBALS['config']['core']) && is_file(ROOT_PATH . '/install.php')) {
Redirect::to('install.php');
}
// Get page to load from URL
if (!isset($_GET['route']) || $_GET['route'] == '/') {
if (((!isset($_GET['route']) || ($_GET['route'] != '/')) && count($directories) > 1)) {
require(ROOT_PATH . '/404.php');
} else {
// Homepage
$pages->setActivePage($pages->getPageByURL('/'));
require(ROOT_PATH . '/modules/Core/pages/index.php');
}
die();
}
$route = rtrim(strtok($_GET['route'], '?'), '/');
$all_pages = $pages->returnPages();
if (array_key_exists($route, $all_pages)) {
$pages->setActivePage($all_pages[$route]);
if (isset($all_pages[$route]['custom'])) {
require(implode(DIRECTORY_SEPARATOR, [ROOT_PATH, 'modules', 'Core', 'pages', 'custom.php']));
die();
}
$path = implode(DIRECTORY_SEPARATOR, [ROOT_PATH, 'modules', $all_pages[$route]['module'], $all_pages[$route]['file']]);
if (file_exists($path)) {
require($path);
die();
}
} else {
// Use recursion to check - might have URL parameters in path
$path_array = explode('/', $route);
for ($i = count($path_array) - 2; $i > 0; $i--) {
$new_path = '/';
for ($n = 1; $n <= $i; $n++) {
$new_path .= $path_array[$n] . '/';
}
$new_path = rtrim($new_path, '/');
if (array_key_exists($new_path, $all_pages)) {
$path = implode(DIRECTORY_SEPARATOR, [ROOT_PATH, 'modules', $all_pages[$new_path]['module'], $all_pages[$new_path]['file']]);
if (file_exists($path)) {
$pages->setActivePage($all_pages[$new_path]);
require($path);
die();
}
}
}
}
require(ROOT_PATH . '/404.php');