-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathindex.php
More file actions
218 lines (185 loc) · 7.32 KB
/
index.php
File metadata and controls
218 lines (185 loc) · 7.32 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
if( version_compare( PHP_VERSION, '7.3.0', '<' ) ){
exit(
sprintf(
'FluxCP requires PHP 7.3.0 or higher. You are using PHP %s.',
PHP_VERSION
)
);
}
// Time started.
define('__START__', microtime(true));
define('FLUX_ROOT', str_replace('\\', '/', dirname(__FILE__)));
define('FLUX_DATA_DIR', 'data');
define('FLUX_CONFIG_DIR', 'config');
define('FLUX_LIB_DIR', 'lib');
define('FLUX_MODULE_DIR', 'modules');
define('FLUX_THEME_DIR', 'themes');
define('FLUX_ADDON_DIR', 'addons');
define('FLUX_LANG_DIR', 'lang');
// Clean GPC arrays in the event magic_quotes_gpc is enabled.
if (ini_get('magic_quotes_gpc')) {
$gpc = array(&$_GET, &$_POST, &$_REQUEST, &$_COOKIE);
foreach ($gpc as &$arr) {
foreach ($arr as $key => $value) {
if (is_string($value)) {
$arr[$key] = stripslashes($value);
}
}
}
}
set_include_path(FLUX_LIB_DIR.PATH_SEPARATOR.get_include_path());
// Default account group IDs.
require_once FLUX_CONFIG_DIR.'/groups.php';
// Some necessary Flux core libraries.
require_once 'Flux.php';
require_once 'Flux/Dispatcher.php';
require_once 'Flux/SessionData.php';
require_once 'Flux/DataObject.php';
require_once 'Flux/Authorization.php';
require_once 'Flux/Installer.php';
require_once 'Flux/PermissionError.php';
// Vendor libraries.
try {
// Initialize Flux.
Flux::initialize(array(
'appConfigFile' => FLUX_CONFIG_DIR.'/application.php',
'serversConfigFile' => FLUX_CONFIG_DIR.'/servers.php',
'appConfigFileImport' => FLUX_CONFIG_DIR.'/import/application.php',
'serversConfigFileImport' => FLUX_CONFIG_DIR.'/import/servers.php',
));
// Set time limit.
set_time_limit((int)Flux::config('ScriptTimeLimit'));
// Set default timezone for entire app.
$timezone = Flux::config('DateDefaultTimezone');
if ($timezone && !@date_default_timezone_set($timezone)) {
throw new Flux_Error("'$timezone' is not a valid timezone. Consult http://php.net/timezones for a list of valid timezones.");
}
// Create some basic directories.
$directories = array(
FLUX_DATA_DIR.'/logs/schemas',
FLUX_DATA_DIR.'/logs/schemas/logindb',
FLUX_DATA_DIR.'/logs/schemas/charmapdb',
FLUX_DATA_DIR.'/logs/transactions',
FLUX_DATA_DIR.'/logs/mail',
FLUX_DATA_DIR.'/logs/mysql',
FLUX_DATA_DIR.'/logs/mysql/errors',
FLUX_DATA_DIR.'/logs/errors',
FLUX_DATA_DIR.'/logs/errors/exceptions',
FLUX_DATA_DIR.'/logs/errors/mail',
);
// Schema log directories.
foreach (Flux::$loginAthenaGroupRegistry as $serverName => $loginAthenaGroup) {
$directories[] = FLUX_DATA_DIR."/logs/schemas/logindb/$serverName";
$directories[] = FLUX_DATA_DIR."/logs/schemas/charmapdb/$serverName";
foreach ($loginAthenaGroup->athenaServers as $athenaServer)
$directories[] = FLUX_DATA_DIR."/logs/schemas/charmapdb/$serverName/{$athenaServer->serverName}";
}
foreach ($directories as $directory) {
if (is_writable(dirname($directory)) && !is_dir($directory)) {
if (Flux::config('RequireOwnership'))
mkdir($directory, 0700);
else
mkdir($directory, 0777);
}
}
if (Flux::config('RequireOwnership') && function_exists('posix_getuid'))
$uid = posix_getuid();
$directories = array(
FLUX_DATA_DIR.'/logs' => 'log storage',
FLUX_DATA_DIR.'/itemshop' => 'item shop image',
FLUX_DATA_DIR.'/tmp' => 'temporary'
);
foreach ($directories as $directory => $directoryFunction) {
$directory = realpath($directory);
if (!is_dir($directory))
mkdir($directory, 0600);
if (!is_writable($directory) && is_dir($directory))
throw new Flux_PermissionError("The $directoryFunction directory '$directory' is not writable. Remedy with `chmod 0600 $directory`");
if (Flux::config('RequireOwnership') && function_exists('posix_getuid') && fileowner($directory) != $uid)
throw new Flux_PermissionError("The $directoryFunction directory '$directory' is not owned by the executing user. Remedy with `chown -R ".posix_geteuid().":".posix_geteuid()." $directory`");
}
if (ini_get('session.use_trans_sid'))
throw new Flux_Error("The 'session.use_trans_sid' php.ini configuration must be turned off for Flux to work.");
// Installer library.
$installer = Flux_Installer::getInstance();
if ($hasUpdates=$installer->updateNeeded())
Flux::config('ThemeName', array('installer'));
$sessionKey = Flux::config('SessionKey');
$sessionExpireDuration = Flux::config('SessionCookieExpire') * 60 * 60;
$cookie_options = array(
// Session timeout
'lifetime' => $sessionExpireDuration,
// Flux URL
'path' => Flux::config( 'BaseURI' ),
// Domain name for the cookie
'domain' => preg_replace( '/:\d+$/', '', Flux::config( 'ServerAddress' ) ), // Remove port number if present (e.g. "example.com:80")
// Only transfer the cookie via HTTPS
'secure' => Flux::config( 'ForceHTTPS' ),
// Only include the cookie in HTTP requests, making it inaccessible by Javascript
'httponly' => true,
// Only send the cookie to the domain+path defined above
'samesite' => 'Strict'
);
if( !session_set_cookie_params( $cookie_options ) ){
throw new Flux_Error( "Unable to configure the session cookie correctly" );
}
ini_set('session.gc_maxlifetime', $sessionExpireDuration);
ini_set('session.name', $sessionKey);
@session_start();
if (empty($_SESSION[$sessionKey]) || !is_array($_SESSION[$sessionKey])) {
$_SESSION[$sessionKey] = array();
}
// Initialize session data.
Flux::$sessionData = new Flux_SessionData($_SESSION[$sessionKey], $hasUpdates);
// Initialize authorization component.
$accessConfig = Flux::parseConfigFile(FLUX_CONFIG_DIR.'/access.php');
// Merge with add-on configs.
foreach (Flux::$addons as $addon) {
$accessConfig->merge($addon->accessConfig);
}
$accessConfig->set('unauthorized.index', AccountLevel::ANYONE);
$authComponent = Flux_Authorization::getInstance($accessConfig, Flux::$sessionData);
if (Flux::config('DebugMode')) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
}
// Dispatch requests->modules->actions->views.
$dispatcher = Flux_Dispatcher::getInstance();
$dispatcher->setDefaultModule(Flux::config('DefaultModule'));
$dispatcher->dispatch(array(
'basePath' => Flux::config('BaseURI'),
'useCleanUrls' => Flux::config('UseCleanUrls'),
'modulePath' => FLUX_MODULE_DIR,
'themePath' => FLUX_THEME_DIR,
'themeName' => Flux::$sessionData->theme,
'missingActionModuleAction' => Flux::config('DebugMode') ? array('errors', 'missing_action') : array('main', 'page_not_found'),
'missingViewModuleAction' => Flux::config('DebugMode') ? array('errors', 'missing_view') : array('main', 'page_not_found')
));
}
catch (Exception $e) {
$exceptionDir = FLUX_DATA_DIR.'/logs/errors/exceptions';
if (is_writable($exceptionDir)) {
require_once 'Flux/LogFile.php';
$today = date('Ymd');
$eLog = new Flux_LogFile("$exceptionDir/$today.log");
// Log exception.
$eLog->puts('(%s) Exception %s: %s', get_class($e), get_class($e), $e->getMessage());
foreach (explode("\n", $e->getTraceAsString()) as $traceLine) {
$eLog->puts('(%s) **TRACE** %s', get_class($e), $traceLine);
}
}
if(Flux::config('DiscordUseWebhook')) {
if(Flux::config('DiscordSendOnErrorException')) {
sendtodiscord(Flux::config('DiscordWebhookURL'), '```ansi
[2;31mERROR[0m
Error: '. get_class($e) .'
Exception: '. $e->getMessage() .'
File: '. $e->getFile() .':'. $e->getLine() .'```');
}
}
require_once FLUX_CONFIG_DIR.'/error.php';
define('__ERROR__', 1);
include $errorFile;
}
?>