-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathstartup.php
More file actions
287 lines (251 loc) · 9.88 KB
/
Copy pathstartup.php
File metadata and controls
287 lines (251 loc) · 9.88 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
/** @ignore */
if (!defined('IN_PHPBB') || !defined('IN_INSTALL'))
{
exit;
}
function phpbb_require_updated($path, $phpbb_root_path, $optional = false)
{
$new_path = $phpbb_root_path . 'install/update/new/' . $path;
$old_path = $phpbb_root_path . $path;
if (file_exists($new_path))
{
require($new_path);
}
else if (!$optional || file_exists($old_path))
{
require($old_path);
}
}
function phpbb_include_updated($path, $phpbb_root_path, $optional = false)
{
$new_path = $phpbb_root_path . 'install/update/new/' . $path;
$old_path = $phpbb_root_path . $path;
if (file_exists($new_path))
{
include($new_path);
}
else if (!$optional || file_exists($old_path))
{
include($old_path);
}
}
function installer_msg_handler($errno, $msg_text, $errfile, $errline): bool
{
global $phpbb_installer_container, $msg_long_text;
// Acording to https://www.php.net/manual/en/language.operators.errorcontrol.php
// error_reporting() return a different error code inside the error handler after php 8.0
$suppresed = E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
if (PHP_VERSION_ID < 80000)
{
$suppresed = 0;
}
if (error_reporting() == $suppresed)
{
return true;
}
// If the message handler is stripping text, fallback to the long version if available
if (!$msg_text && !empty($msg_long_text))
{
$msg_text = $msg_long_text;
}
switch ($errno)
{
case E_NOTICE:
case E_WARNING:
case E_USER_WARNING:
case E_USER_NOTICE:
$msg = '[phpBB Debug] "' . $msg_text . '" in file ' . $errfile . ' on line ' . $errline;
if (!empty($phpbb_installer_container))
{
try
{
/** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
$iohandler = $phpbb_installer_container->get('installer.helper.iohandler');
$iohandler->add_warning_message($msg);
}
catch (\phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception $e)
{
print($msg);
}
}
else
{
print($msg);
}
return false;
break;
case E_USER_ERROR:
$msg = '<b>General Error:</b><br>' . $msg_text . '<br> in file ' . $errfile . ' on line ' . $errline . '<br><br>';
if (!empty($phpbb_installer_container))
{
try
{
/** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
$iohandler = $phpbb_installer_container->get('installer.helper.iohandler');
$iohandler->add_error_message($msg, get_backtrace());
$iohandler->send_response(true);
exit();
}
catch (\phpbb\install\helper\iohandler\exception\iohandler_not_implemented_exception $e)
{
throw new \phpbb\exception\runtime_exception($msg);
}
}
throw new \phpbb\exception\runtime_exception($msg);
break;
case E_DEPRECATED:
return true;
break;
}
return false;
}
/**
* Register class loaders for installer
*
* @param string $phpbb_root_path phpBB root path
* @param string $phpEx PHP file extension
*/
function installer_class_loader($phpbb_root_path, $phpEx)
{
$phpbb_class_loader_new = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}install/update/new/phpbb/", $phpEx);
$phpbb_class_loader_new->register();
$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx);
$phpbb_class_loader->register();
$phpbb_class_loader = new \phpbb\class_loader('phpbb\\convert\\', "{$phpbb_root_path}install/convert/", $phpEx);
$phpbb_class_loader->register();
$phpbb_class_loader_ext = new \phpbb\class_loader('\\', "{$phpbb_root_path}ext/", $phpEx);
$phpbb_class_loader_ext->register();
}
/**
* Installer shutdown function. Tries to resolve errors that might have occured
* during execution of installer
*
* @param int $display_errors Original display errors value
*/
function installer_shutdown_function($display_errors)
{
$error = error_get_last();
if ($error)
{
// Restore original display errors value
@ini_set('display_errors', $display_errors);
// Manually define phpBB root path and phpEx. These will not be passed
// on from index.php
$phpbb_root_path = __DIR__ . '/../';
$phpEx = 'php';
installer_class_loader($phpbb_root_path, $phpEx);
$supported_error_levels = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED;
$cache = new \phpbb\cache\driver\file(__DIR__ . '/../cache/installer/');
$filesystem = new \phpbb\filesystem\filesystem();
if (strpos($error['file'], $filesystem->realpath($cache->cache_dir)) !== false && is_writable($cache->cache_dir))
{
$file_age = @filemtime($error['file']);
if ($file_age !== false && ($file_age + 60) < time())
{
$cache->purge();
$symfony_request = new \phpbb\symfony_request(new \phpbb\request\request(new \phpbb\request\type_cast_helper()));
header('Location: ' . $symfony_request->getRequestUri());
exit();
}
else
{
// Language system is not available
die('The installer has detected an issue with a cached file. Try reloading the page and/or manually clearing the cache to resolve the issue. If you require further assistance, please visit the <a href="https://www.phpbb.com/community/" target="_blank">phpBB support forums</a>.');
}
}
else if ($error['type'] & $supported_error_levels)
{
// Convert core errors to user warnings for trigger_error()
if ($error['type'] == E_CORE_ERROR || $error['type'] == E_COMPILE_ERROR)
{
$error['type'] = E_USER_ERROR;
}
else if ($error['type'] == E_CORE_WARNING)
{
$error['type'] = E_USER_WARNING;
}
try
{
installer_msg_handler($error['type'], $error['message'], $error['file'], $error['line']);
}
catch (\phpbb\exception\runtime_exception $exception)
{
echo '<!DOCTYPE html>';
echo '<html dir="ltr">';
echo '<head>';
echo '<meta charset="utf-8">';
echo '<meta http-equiv="X-UA-Compatible" content="IE=edge">';
echo '<title>General Error</title>';
echo '<style type="text/css">' . "\n" . '/* <![CDATA[ */' . "\n";
echo '* { margin: 0; padding: 0; } html { font-size: 100%; height: 100%; margin-bottom: 1px; background-color: #E4EDF0; } body { font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif; color: #536482; background: #E4EDF0; font-size: 62.5%; margin: 0; } ';
echo 'a:link, a:active, a:visited { color: #006699; text-decoration: none; } a:hover { color: #DD6900; text-decoration: underline; } ';
echo '#wrap { padding: 0 20px 15px 20px; min-width: 615px; } #page-header { text-align: right; height: 40px; } #page-footer { clear: both; font-size: 1em; text-align: center; } ';
echo '.panel { margin: 4px 0; background-color: #FFFFFF; border: solid 1px #A9B8C2; } ';
echo '#errorpage #page-header a { font-weight: bold; line-height: 6em; } #errorpage #content { padding: 10px; } #errorpage #content h1 { line-height: 1.2em; margin-bottom: 0; color: #DF075C; } ';
echo '#errorpage #content div { margin-top: 20px; margin-bottom: 5px; border-bottom: 1px solid #CCCCCC; padding-bottom: 5px; color: #333333; font: bold 1.2em "Lucida Grande", Arial, Helvetica, sans-serif; text-decoration: none; line-height: 120%; text-align: left; } ';
echo "\n" . '/* ]]> */' . "\n";
echo '</style>';
echo '</head>';
echo '<body id="errorpage">';
echo '<div id="wrap">';
echo ' <div id="acp">';
echo ' <div class="panel">';
echo ' <div id="content">';
echo ' <h1>General Error</h1>';
echo ' <div>' . $exception->getMessage() . '</div>';
echo ' </div>';
echo ' </div>';
echo ' </div>';
echo ' <div id="page-footer">';
echo ' Powered by <a href="https://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Limited';
echo ' </div>';
echo '</div>';
echo '</body>';
echo '</html>';
}
}
}
}
phpbb_require_updated('includes/startup.' . $phpEx, $phpbb_root_path);
phpbb_require_updated('phpbb/class_loader.' . $phpEx, $phpbb_root_path);
installer_class_loader($phpbb_root_path, $phpEx);
// In case $phpbb_adm_relative_path is not set (in case of an update), use the default.
$phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relative_path : 'adm/';
$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path;
// Include files
phpbb_require_updated('includes/compatibility_globals.' . $phpEx, $phpbb_root_path);
phpbb_require_updated('includes/functions.' . $phpEx, $phpbb_root_path);
phpbb_require_updated('includes/functions_content.' . $phpEx, $phpbb_root_path);
phpbb_include_updated('includes/functions_compatibility.' . $phpEx, $phpbb_root_path);
phpbb_require_updated('includes/functions_user.' . $phpEx, $phpbb_root_path);
phpbb_require_updated('includes/utf/utf_tools.' . $phpEx, $phpbb_root_path);
// Set PHP error handler to ours
set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'installer_msg_handler');
$php_ini = new \bantu\IniGetWrapper\IniGetWrapper();
$ini_display_errors = $php_ini->getNumeric('display_errors');
register_shutdown_function('installer_shutdown_function', $ini_display_errors);
// Suppress errors until we have created the containers
@ini_set('display_errors', 0);
$phpbb_installer_container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx);
$phpbb_installer_container_builder
->with_environment('installer')
->without_extensions();
$other_config_path = $phpbb_root_path . 'install/update/new/config';
$config_path = (file_exists($other_config_path . '/installer/config.yml')) ? $other_config_path : $phpbb_root_path . 'config';
$phpbb_installer_container = $phpbb_installer_container_builder
->with_config_path($config_path)
->with_custom_parameters(array('cache.driver.class' => 'phpbb\cache\driver\file'))
->get_container();
@ini_set('display_errors', $ini_display_errors);