-
-
Notifications
You must be signed in to change notification settings - Fork 352
/
Copy pathinit.php
111 lines (93 loc) · 2.79 KB
/
init.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
<?php
/*
|---------------------------------------------------------------
| DEFINE APPLICATION CONSTANTS
|---------------------------------------------------------------
|
| VERSION - The current ezXSS version
| DEBUG - Switch to display errors
|
*/
define('version', '3.6');
define('debug', false);
if (debug) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
}
/*
|---------------------------------------------------------------
| CHECK PHP VERSION
|---------------------------------------------------------------
|
| ezXSS needs PHP 7.1 or up to do its magic
|
*/
if (PHP_VERSION_ID < 70100) {
error('PHP 7.1 or up is required to use ezXSS');
}
/*
|---------------------------------------------------------------
| LOAD IN REQUIRED FILES AND CHECK CONFIG
|---------------------------------------------------------------
|
| This loads in the Autoload and config file, checks if
| the config file is valid and defines the config constant.
|
| CONFIG - Holds all the config values
|
*/
require_once __DIR__ . '/src/Autoload.php';
if(!file_exists('config.ini')) {
error('You did not setup your config file. Rename config.ini.example to config.ini.', true);
}
$config = parse_ini_file('config.ini');
if ($config === false) {
error('There is something wrong with your config file.', true);
}
define('config', $config);
/*
|---------------------------------------------------------------
| PRE-ROUTE
|---------------------------------------------------------------
|
| This checks the requested url and determines what kind of page
| needs to be served.
|
*/
$requestUrl = explode('?', $_SERVER['REQUEST_URI'])[0];
if (strpos($requestUrl, '/manage/') === 0 || strpos($requestUrl, '/manage') === 0) {
$path = str_replace('/manage/', '', explode('?', $_SERVER['REQUEST_URI'])[0]);
if (explode('/', $path)[0] === 'report') {
$path = explode('/', $path)[0];
}
if ($path === 'request') {
$request = new Request();
echo $request->json();
} else {
$route = new Route();
echo $route->template($path);
}
} else {
$route = new Route();
if ($requestUrl === '/callback') {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
echo $route->callback(file_get_contents('php://input'));
}
} else {
header('Content-Type: application/x-javascript');
echo $route->jsPayload();
}
}
/*
|---------------------------------------------------------------
| FATAL ERROR FUNCTION
|---------------------------------------------------------------
|
| This shows the error and closes the application
|
*/
function error($message, $wiki = false) {
$message .= ($wiki === true ? ' Visit the <a href="https://github.com/ssl/ezXSS">wiki</a> for more information.' : '');
echo "<h1>Error</h1><p>$message</p>";
exit();
}