-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
199 lines (167 loc) · 7.12 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
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
<?php
if (version_compare(PHP_VERSION, '5.2.1', '<')) {
echo '<h2>Erro</h2>';
echo '<p>A versão do PHP precisa ser 5.2.1 ou maior, pois é necessária para usar o Painel de Controle Flux.</p>';
echo '<p>Você está usando a versão '.PHP_VERSION.'</p>';
exit;
}
// Disable Zend Engine 1 compatibility mode.
// See: http://www.php.net/manual/en/ini.core.php#ini.zend.ze1-compatibility-mode
ini_set('zend.ze1_compatibility_mode', 0);
// Time started.
define('__START__', microtime(true));
error_reporting(E_ALL);
ini_set('display_errors', 1);
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/Security.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.
require_once 'markdown/markdown.php';
try {
if (!extension_loaded('pdo')) {
throw new Flux_Error('A extensão PDO é necessária para usar o Flux, tenha certeza que você tem instalado junto com o driver PDO_MYSQL.');
}
elseif (!extension_loaded('pdo_mysql')) {
throw new Flux_Error('O driver PDO_MYSQL para a extensão PDF deve ser instalada para se usar o Flux. Por favor, constule o manual PHP para instruções de instalação.');
}
// Initialize Flux.
Flux::initialize(array(
'appConfigFile' => FLUX_CONFIG_DIR.'/application.php',
'serversConfigFile' => FLUX_CONFIG_DIR.'/servers.php',
//'messagesConfigFile' => FLUX_CONFIG_DIR.'/messages.php' // No longer needed (Deprecated)
));
// 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' não é uma timezone válida. Consulte http://php.net/timezones para uma lista de timezones válidos.");
}
// 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_writable($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' no php.ini deve ser desligada para o Flux poder funcionar.");
// Installer library.
$installer = Flux_Installer::getInstance();
if ($hasUpdates=$installer->updateNeeded())
Flux::config('ThemeName', 'installer');
$sessionKey = Flux::config('SessionKey');
$sessionExpireDuration = Flux::config('SessionCookieExpire') * 60 * 60;
session_set_cookie_params($sessionExpireDuration, Flux::config('BaseURI'));
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);
Flux_Security::setSession($_SESSION[$sessionKey]);
// 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')) {
ini_set('display_errors', 0);
}
// 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.'/'.Flux::config('ThemeName'),
'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);
}
}
require_once FLUX_CONFIG_DIR.'/error.php';
define('__ERROR__', 1);
include $errorFile;
}
?>