forked from NamelessMC/Nameless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
141 lines (111 loc) · 3.98 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
<?php
/*
* Made by Samerton
* https://github.com/NamelessMC/Nameless/
* NamelessMC version 2.0.0-pr13
*
* License: MIT
*
* Main index file
*/
// Uncomment to enable debugging
// define('DEBUGGING', 1);
header('X-Frame-Options: SAMEORIGIN');
if ((!defined('DEBUGGING') || !DEBUGGING) && (getenv('NAMELESS_DEBUGGING') || isset($_SERVER['NAMELESS_DEBUGGING']))) {
define('DEBUGGING', true);
}
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
define('PAGE_START_TIME', microtime(true));
if (!is_dir(__DIR__ . '/vendor') || !is_dir(__DIR__ . '/core/assets/vendor')) {
die(
"Your installation is missing the 'vendor' or 'core/assets/vendor' directory. These directories are included in
releases, but not in the git repository. For regular installations, please make sure to download a release from
the GitHub releases page, not from the button on the home page to download the latest source code. If you do
want to run the latest version from source control for development versions, please run 'composer install'
and 'yarnpkg'/'yarn install'."
);
}
const PATH = '/';
const ROOT_PATH = __DIR__;
require_once __DIR__ . '/vendor/autoload.php';
if (isset($_GET['route']) && $_GET['route'] == '/rewrite_test') {
require_once('rewrite_test.php');
die();
}
if (!Config::exists()) {
if (is_file(ROOT_PATH . '/install.php')) {
Redirect::to('install.php');
} else {
die('Config does not exist, but neither does the installer');
}
}
$page = 'Home';
if (!ini_get('upload_tmp_dir')) {
$tmp_dir = sys_get_temp_dir();
} else {
$tmp_dir = ini_get('upload_tmp_dir');
}
if (HttpUtils::getProtocol() === '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);
// Start initialising the page
require(ROOT_PATH . '/core/init.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');