-
-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathindex.php
97 lines (80 loc) · 2.22 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
<?php
/*
* Made by Samerton
* https://github.com/NamelessMC/Nameless/
* NamelessMC version 2.0.0-dev
*
* License: MIT
*
* Main index file
*/
// Ensure PHP version >= 5.4
if(version_compare(phpversion(), '5.4', '<')){
die('NamelessMC is not compatible with PHP versions older than 5.4');
}
// Start page load timer
$start = microtime(true);
// Definitions
define('PATH', '/');
define('ROOT_PATH', dirname(__FILE__));
$page = 'Home';
if(!ini_get('upload_tmp_dir')){
$tmp_dir = sys_get_temp_dir();
} else {
$tmp_dir = ini_get('upload_tmp_dir');
}
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);
// Installer?
if(is_file('install.php')){
if(isset($_GET['from']) && $_GET['from'] == 'install'){
if(is_writable('install.php')){
unlink('install.php');
} else {
die('Unable to automatically delete <strong>install.php</strong>, please do so manually.');
}
} else {
$page = 'install';
require('install.php');
die();
}
}
// Start initialising the page
require('core/init.php');
if(FRIENDLY_URLS == true){
// Load the main page content
// Check modules
$modules = $pages->returnPages();
// Custom rules
// Include the page
if(array_key_exists($directory, $modules)){
$path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'modules', $modules[$directory]['module'], $modules[$directory]['file']));
if(!file_exists($path)) require('404.php'); else require($path);
die();
} else {
// 404
require('404.php');
}
} else {
// Friendly URLs are disabled
if(!isset($_GET['route']) || $_GET['route'] == '/'){
// Homepage
require('modules/Core/pages/index.php');
} else {
if(!isset($route)) $route = rtrim($_GET['route'], '/');
// Check modules
$modules = $pages->returnPages();
// Include the page
if(array_key_exists($route, $modules)){
$path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'modules', $modules[$route]['module'], $modules[$route]['file']));
if(!file_exists($path)) require('404.php'); else require($path);
die();
} else {
// 404
require('404.php');
}
}
}