forked from phpMussel/phpMussel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.php
More file actions
182 lines (151 loc) · 5.97 KB
/
Copy pathloader.php
File metadata and controls
182 lines (151 loc) · 5.97 KB
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
<?php
/**
* This file is a part of the phpMussel package.
* Homepage: https://phpmussel.github.io/
*
* PHPMUSSEL COPYRIGHT 2013 AND BEYOND BY THE PHPMUSSEL TEAM.
*
* Authors:
* @see PEOPLE.md
*
* License: GNU/GPLv2
* @see LICENSE.txt
*
* This file: The loader (last modified: 2019.08.31).
*/
/**
* phpMussel should only be loaded once per PHP instance. To ensure this, we
* check for the existence of a "phpMussel" constant. If it doesn't exist, we
* define it and continue loading. If it already exists, we warn the client and
* kill the script.
*/
if (defined('phpMussel')) {
header('Content-Type: text/plain');
echo '[phpMussel] ' . (
isset($phpMussel['L10N']) ? $phpMussel['L10N']->getString('instance_already_active') : 'Instance already active! Please double-check your hooks.'
);
die;
}
define('phpMussel', true);
/** Autoloader for phpMussel classes. */
spl_autoload_register(function ($Class) {
$Vendor = (($Pos = strpos($Class, "\\", 1)) === false) ? '' : substr($Class, 0, $Pos);
$File = __DIR__ . '/vault/classes/' . ((!$Vendor || $Vendor === 'phpMussel') ? '' : $Vendor . '/') . (
(($Pos = strrpos($Class, "\\")) === false) ? $Class : substr($Class, $Pos + 1)
) . '.php';
if (is_readable($File)) {
require $File;
}
});
if (!version_compare(PHP_VERSION, '7.2.0', '>=')) {
header('Content-Type: text/plain');
die('[phpMussel] Not compatible with PHP versions below 7.2.0; Please update PHP in order to use phpMussel.');
}
/** Create an array for our working data. */
$phpMussel = [];
/** Determine the location of the "vault" directory. */
$phpMussel['Vault'] = __DIR__ . '/vault/';
/** Kill the script if we can't find the vault directory. */
if (!is_dir($phpMussel['Vault'])) {
header('Content-Type: text/plain');
die('[phpMussel] Vault directory not correctly set: Can\'t continue.');
}
/** Define the location of the "cache" directory. */
$phpMussel['cachePath'] = $phpMussel['Vault'] . 'cache/';
/** Define the location of the "lang" directory. */
$phpMussel['langPath'] = $phpMussel['Vault'] . 'lang/';
/** Define the location of the "plugins" directory. */
$phpMussel['pluginPath'] = $phpMussel['Vault'] . 'plugins/';
/** Define the location of the "quarantine" directory. */
$phpMussel['qfuPath'] = $phpMussel['Vault'] . 'quarantine/';
/** Define the location of the "signatures" directory. */
$phpMussel['sigPath'] = $phpMussel['Vault'] . 'signatures/';
/** Checks whether we're calling phpMussel directly or through a hook. */
$phpMussel['Direct'] = function () {
return (
!isset($_SERVER['SCRIPT_FILENAME']) ||
str_replace("\\", '/', strtolower(realpath($_SERVER['SCRIPT_FILENAME']))) === str_replace("\\", '/', strtolower(__FILE__))
);
};
/** Checks whether we're calling phpMussel through an alternative pathway (e.g., Cronable). */
$phpMussel['Alternate'] = (
class_exists('\Maikuolan\Cronable\Cronable')
);
/** Kill the script if the functions file doesn't exist. */
if (!file_exists($phpMussel['Vault'] . 'functions.php')) {
header('Content-Type: text/plain');
die('[phpMussel] Functions file missing! Please reinstall phpMussel.');
}
/** Load the functions file. */
require $phpMussel['Vault'] . 'functions.php';
/** Kill the script if the configuration handler doesn't exist. */
if (!file_exists($phpMussel['Vault'] . 'config.php')) {
header('Content-Type: text/plain');
die('[phpMussel] Configuration handler missing! Please reinstall phpMussel.');
}
/** Load the configuration handler. */
require $phpMussel['Vault'] . 'config.php';
/**
* Check whether the language handler exists; Kill the script if it
* doesn't.
*/
if (!file_exists($phpMussel['Vault'] . 'lang.php')) {
header('Content-Type: text/plain');
die('[phpMussel] Language handler missing! Please reinstall phpMussel.');
}
/** Load the language handler. */
require $phpMussel['Vault'] . 'lang.php';
/**
* Used to determine whether we've reached the end of this file without
* exiting cleanly (important for rendering scan results correctly).
*/
$phpMussel['EOF'] = false;
/** A safety feature for logging. */
$phpMussel['safety'] = "\x3c\x3fphp die; \x3f\x3e";
/** Plugins are detected and processed by phpMussel here. */
$phpMussel['MusselPlugins'] = ['hooks' => [], 'closures' => []];
if ($phpMussel['Config']['general']['enable_plugins']) {
foreach ($phpMussel['PluginIterator'](['ThisPlugin' => 'plugin.php']) as $phpMussel['ThisPlugin']) {
require_once $phpMussel['ThisPlugin']['ThisPlugin'];
}
unset($phpMussel['ThisPlugin']);
}
/* This code block only executed if we're NOT in CLI mode (or if we're running via Cronable). */
if (!$phpMussel['Mussel_sapi'] || $phpMussel['Alternate']) {
/**
* Check whether the upload handler exists and attempt to load it.
*/
if (file_exists($phpMussel['Vault'] . 'upload.php') && !$phpMussel['Alternate']) {
require $phpMussel['Vault'] . 'upload.php';
}
/**
* Check whether the front-end handler exists and attempt to load
* it. Skip this check if front-end access is disabled.
*/
if (
!$phpMussel['Config']['general']['disable_frontend'] &&
file_exists($phpMussel['Vault'] . 'frontend.php') &&
($phpMussel['Direct']() || $phpMussel['Alternate'])
) {
require $phpMussel['Vault'] . 'frontend.php';
}
}
/** This code block only executed if we're in CLI mode. */
elseif (file_exists($phpMussel['Vault'] . 'cli.php')) {
require $phpMussel['Vault'] . 'cli.php';
}
if ($phpMussel['Config']['general']['cleanup']) {
/** Destroy unrequired plugin closures. */
if (isset($phpMussel['MusselPlugins']['closures'])) {
foreach ($phpMussel['MusselPlugins']['closures'] as $x) {
if (isset($$x) && is_object($$x)) {
unset($$x);
}
}
}
/** Unset our working data so that we can exit cleanly. */
unset($x, $phpMussel);
} else {
/** Let the script know that we haven't exited cleanly. */
$phpMussel['EOF'] = true;
}