15 |
15 |
* @lastmodified $Date$
|
16 |
16 |
*
|
17 |
17 |
*/
|
18 |
|
error_reporting( -1 );
|
19 |
|
$sStarttime = array_sum(explode(" ", microtime()));
|
20 |
|
$aPhpFunctions = get_defined_functions();
|
|
18 |
// $aPhpFunctions = get_defined_functions();
|
21 |
19 |
/**
|
22 |
20 |
* sanitize $_SERVER['HTTP_REFERER']
|
23 |
21 |
* @param string $sWbUrl qualified startup URL of current application
|
24 |
22 |
*/
|
25 |
|
function SanitizeHttpReferer($sWbUrl = WB_URL) {
|
|
23 |
function SanitizeHttpReferer($sWbUrl = WB_URL)
|
|
24 |
{
|
26 |
25 |
$sTmpReferer = '';
|
27 |
26 |
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
|
28 |
27 |
define('ORG_REFERER', ($_SERVER['HTTP_REFERER'] ?: ''));
|
... | ... | |
60 |
59 |
return preg_replace('/^(.*)$/', '[$1]', $aList);
|
61 |
60 |
}
|
62 |
61 |
|
63 |
|
/* ***************************************************************************************
|
64 |
|
* Start initialization *
|
65 |
|
****************************************************************************************/// aktivate exceptionhandler ---
|
66 |
|
// throw new Exception('PHP-'.PHP_VERSION.' found, but at last PHP-5.3.6 required !!');
|
67 |
|
// Stop execution if PHP version is too old
|
68 |
|
// PHP less then 5.6.0 is prohibited ---
|
69 |
|
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
|
70 |
|
$sMsg = '<p style="color: #ff0000;">WebsiteBaker is not able to run with PHP-Version less then 5.6.0!!<br />'
|
71 |
|
. 'Please change your PHP-Version to any kind from 5.6.0 and up!<br />'
|
72 |
|
. 'If you have problems to solve that, ask your hosting provider for it.<br />'
|
73 |
|
. 'The very best solution is the use of PHP-7.0 and up</p>';
|
74 |
|
die($sMsg);
|
75 |
|
}
|
76 |
|
|
77 |
|
/* -------------------------------------------------------- */
|
78 |
|
if ( !defined('WB_PATH')) { define('WB_PATH', dirname(__DIR__)); }
|
79 |
|
// *** initialize Exception handling
|
80 |
|
if(!function_exists('globalExceptionHandler')) {
|
81 |
|
include(__DIR__.'/globalExceptionHandler.php');
|
82 |
|
}
|
83 |
|
// *** initialize Error handling
|
84 |
|
$sErrorLogFile = dirname(__DIR__).'/var/logs/php_error.log.php';
|
85 |
|
$sErrorLogPath = dirname($sErrorLogFile);
|
86 |
|
|
87 |
|
if (!file_exists($sErrorLogFile)) {
|
88 |
|
$sTmp = '<?php die(\'illegal file access\'); ?>'
|
89 |
|
. 'created: ['.date('c').']'.PHP_EOL;
|
90 |
|
if (false === file_put_contents($sErrorLogFile, $sTmp, FILE_APPEND)) {
|
91 |
|
throw new Exception('unable to create logfile \'/var/logs/php_error.log.php\'');
|
92 |
|
}
|
93 |
|
}
|
94 |
|
if (!is_writeable($sErrorLogFile)) {
|
95 |
|
throw new Exception('not writeable logfile \'/var/logs/php_error.log.php\'');
|
96 |
|
}
|
97 |
|
ini_set('log_errors', 1);
|
98 |
|
ini_set ('error_log', $sErrorLogFile);
|
99 |
|
|
100 |
62 |
/**
|
101 |
63 |
* Read DB settings from configuration file
|
102 |
64 |
* @return array
|
... | ... | |
143 |
105 |
* Set constants for system/install values
|
144 |
106 |
* @throws RuntimeException
|
145 |
107 |
*/
|
146 |
|
function initSetInstallWbConstants($aCfg) {
|
|
108 |
function initSetInstallWbConstants($aCfg)
|
|
109 |
{
|
147 |
110 |
if (sizeof($aCfg)) {
|
148 |
111 |
foreach($aCfg['Constants'] as $key=>$value) {
|
149 |
112 |
switch($key):
|
... | ... | |
265 |
228 |
}
|
266 |
229 |
$aBt= debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
267 |
230 |
$x = sizeof($aBt) -1;
|
268 |
|
$x = $x < 0 ? 0 : ($x <= 2 ? $x : 2);
|
|
231 |
$iSize = $x < 0 ? 0 : ($x <= 2 ? $x : 2);
|
269 |
232 |
$sEntry = date('c').' '.'['.$sErrorType.'] '.str_replace(dirname(__DIR__), '', $sErrorFile).':['.$iErrorLine.'] '
|
270 |
|
. ' from '.str_replace(dirname(__DIR__), '', $aBt[$x]['file']).':['.$aBt[$x]['line'].'] '
|
271 |
|
. (@$aBt[$x]['class'] ? $aBt[$x]['class'].$aBt[$x]['type'] : '').$aBt[$x]['function'].' '
|
|
233 |
. ' from '.str_replace(dirname(__DIR__), '', $aBt[$iSize]['file']).':['.$aBt[$iSize]['line'].'] '
|
|
234 |
. (isset($aBt[$iSize]['class']) ? $aBt[$iSize]['class'].$aBt[$iSize]['type'] : '').$aBt[$iSize]['function'].' '
|
272 |
235 |
. '"'.$sErrorText.'"'.PHP_EOL;
|
273 |
236 |
file_put_contents($sErrorLogFile, $sEntry, FILE_APPEND);
|
274 |
237 |
return $bRetval;
|
275 |
238 |
}
|
|
239 |
/**
|
|
240 |
* create / recreate a admin object
|
|
241 |
* @param string $section_name (default: '##skip##')
|
|
242 |
* @param string $section_permission (default: 'start')
|
|
243 |
* @param bool $auto_header (default: true)
|
|
244 |
* @param bool $auto_auth (default: true)
|
|
245 |
* @return \admin
|
|
246 |
*/
|
|
247 |
function newAdmin($section_name= '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true)
|
|
248 |
{
|
|
249 |
if (isset($GLOBALS['admin']) && $GLOBALS['admin'] instanceof admin) {
|
|
250 |
unset($GLOBALS['admin']);
|
|
251 |
usleep(10000);
|
|
252 |
}
|
|
253 |
return new admin($section_name, $section_permission, $auto_header, $auto_auth);
|
|
254 |
}
|
|
255 |
|
276 |
256 |
/* ***************************************************************************************
|
277 |
257 |
* Start initialization *
|
278 |
258 |
****************************************************************************************/
|
279 |
|
// activate errorhandler
|
|
259 |
// Stop execution if PHP version is too old
|
|
260 |
// PHP less then 5.6.0 is prohibited ---
|
|
261 |
if (version_compare(PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION, '5.6.0', '<')) {
|
|
262 |
$sMsg = '<p style="color: #ff0000;">WebsiteBaker is not able to run with PHP-Version less then 5.6.0!!<br />'
|
|
263 |
. 'Please change your PHP-Version to any kind from 5.6.0 and up!<br />'
|
|
264 |
. 'If you have problems to solve that, ask your hosting provider for it.<br />'
|
|
265 |
. 'The very best solution is the use of PHP-7.0 and up</p>';
|
|
266 |
die($sMsg);
|
|
267 |
}
|
|
268 |
error_reporting(E_ALL);
|
|
269 |
$sStarttime = array_sum(explode(" ", microtime()));
|
|
270 |
/* -------------------------------------------------------- */
|
|
271 |
if ( !defined('WB_PATH')) { define('WB_PATH', dirname(__DIR__)); }
|
|
272 |
// *** initialize Exception handling
|
|
273 |
if(!function_exists('globalExceptionHandler')) {
|
|
274 |
include(__DIR__.'/globalExceptionHandler.php');
|
|
275 |
}
|
|
276 |
// *** initialize Error handling
|
|
277 |
$sErrorLogFile = dirname(__DIR__).'/var/logs/php_error.log.php';
|
|
278 |
$sErrorLogPath = dirname($sErrorLogFile);
|
|
279 |
|
|
280 |
if (!file_exists($sErrorLogFile)) {
|
|
281 |
$sTmp = '<?php die(\'illegal file access\'); ?>'
|
|
282 |
. 'created: ['.date('c').']'.PHP_EOL;
|
|
283 |
if (false === file_put_contents($sErrorLogFile, $sTmp, FILE_APPEND)) {
|
|
284 |
throw new Exception('unable to create logfile \'/var/logs/php_error.log.php\'');
|
|
285 |
}
|
|
286 |
}
|
|
287 |
if (!is_writeable($sErrorLogFile)) {
|
|
288 |
throw new Exception('not writeable logfile \'/var/logs/php_error.log.php\'');
|
|
289 |
}
|
|
290 |
ini_set('log_errors', 1);
|
|
291 |
ini_set ('error_log', $sErrorLogFile);
|
|
292 |
|
|
293 |
// activate errorhandler *****************************************************************
|
280 |
294 |
set_error_handler('WbErrorHandler', -1 );
|
281 |
|
if (! defined('SYSTEM_RUN')) { define('SYSTEM_RUN', true); }
|
|
295 |
defined('SYSTEM_RUN') ? '' : define('SYSTEM_RUN', true);
|
282 |
296 |
// load configuration ---
|
283 |
297 |
$aCfg = initReadSetupFile();
|
284 |
298 |
initSetInstallWbConstants($aCfg);
|
285 |
299 |
// ---------------------------
|
286 |
300 |
// get Database connection data from configuration
|
287 |
|
if (!defined('ADMIN_DIRECTORY')) { define('ADMIN_DIRECTORY', 'admin'); }
|
288 |
|
if (!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
|
289 |
|
throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
|
290 |
|
}
|
291 |
|
if ( !defined('ADMIN_URL')) { define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY); }
|
292 |
|
if ( !defined('ADMIN_PATH')) { define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY); }
|
293 |
|
if ( !defined('WB_REL')){
|
294 |
|
$x1 = parse_url(WB_URL);
|
295 |
|
define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
|
296 |
|
}
|
297 |
|
if ( !defined('DOCUMENT_ROOT')) {
|
298 |
|
define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(str_replace('\\', '/', WB_REL), '/').'$/', '', str_replace('\\', '/', WB_PATH)));
|
299 |
|
$_SERVER['DOCUMENT_ROOT'] = DOCUMENT_ROOT;
|
300 |
|
}
|
|
301 |
defined('ADMIN_DIRECTORY') ? '' : define('ADMIN_DIRECTORY', 'admin');
|
|
302 |
if (!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
|
|
303 |
throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
|
|
304 |
}
|
|
305 |
defined('ADMIN_URL') ? '' : define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY);
|
|
306 |
defined('ADMIN_PATH') ? '' : define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY);
|
|
307 |
if ( !defined('WB_REL')){
|
|
308 |
$x1 = parse_url(WB_URL);
|
|
309 |
define('WB_REL', (isset($x1['path']) ? $x1['path'] : ''));
|
|
310 |
}
|
|
311 |
if ( !defined('DOCUMENT_ROOT')) {
|
|
312 |
define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(str_replace('\\', '/', WB_REL), '/').'$/', '', str_replace('\\', '/', WB_PATH)));
|
|
313 |
$_SERVER['DOCUMENT_ROOT'] = DOCUMENT_ROOT;
|
|
314 |
}
|
|
315 |
// activate Autoloader
|
|
316 |
if (!class_exists('\bin\Autoloader')) {
|
|
317 |
include __DIR__.'/Autoloader.php';
|
|
318 |
}
|
|
319 |
\bin\Autoloader::doRegister();
|
|
320 |
|
301 |
321 |
if (file_exists(WB_PATH.'/framework/class.database.php')) {
|
302 |
322 |
// sanitize $_SERVER['HTTP_REFERER']
|
303 |
323 |
SanitizeHttpReferer(WB_URL);
|
... | ... | |
311 |
331 |
// register PHPMailer autoloader ---
|
312 |
332 |
$sTmp = dirname(dirname(__FILE__)).'/include/phpmailer/PHPMailerAutoload.php';
|
313 |
333 |
if (!function_exists('PHPMailerAutoload') && is_readable($sTmp)) {
|
314 |
|
require($sTmp);
|
|
334 |
include $sTmp;
|
315 |
335 |
}
|
316 |
336 |
|
317 |
|
if (!class_exists('database', false)){
|
318 |
|
// load database class
|
319 |
|
require(__DIR__.'/class.database.php');
|
|
337 |
// if (!class_exists('database', false)){
|
|
338 |
// // load database class
|
|
339 |
// require(__DIR__.'/class.database.php');
|
320 |
340 |
// Create database class
|
321 |
341 |
$database = new database();
|
322 |
|
$database->sTablePrefix = TABLE_PREFIX;
|
323 |
|
}
|
|
342 |
// }
|
324 |
343 |
|
325 |
344 |
// activate frontend OutputFilterApi (initialize.php)
|
326 |
345 |
if (is_readable(WB_PATH .'/modules/output_filter/OutputFilterApi.php')) {
|
... | ... | |
330 |
349 |
} else {
|
331 |
350 |
throw new RuntimeException('missing mandatory global OutputFilterApi!');
|
332 |
351 |
}
|
333 |
|
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
|
334 |
|
@ini_set("magic_quotes_runtime", 0); // Disable magic_quotes_runtime
|
335 |
|
@ini_set("magic_quotes_gpc", 0); // Disable magic_quotes_gpc
|
336 |
|
}
|
337 |
|
if (get_magic_quotes_gpc()) {
|
338 |
|
$unescape = function(&$value, $key) {
|
339 |
|
$value = stripslashes($value);
|
340 |
|
};
|
341 |
|
array_walk_recursive($_POST, $unescape);
|
342 |
|
array_walk_recursive($_GET, $unescape);
|
343 |
|
array_walk_recursive($_REQUEST, $unescape);
|
344 |
|
array_walk_recursive($_COOKIE, $unescape);
|
345 |
|
}
|
346 |
352 |
// Get website settings (title, keywords, description, header, and footer)
|
347 |
353 |
$sql = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'settings`';
|
348 |
354 |
if (($get_settings = $database->query($sql))) {
|
... | ... | |
356 |
362 |
if ($setting_value == 'true') {
|
357 |
363 |
$setting_value = true;
|
358 |
364 |
}
|
359 |
|
@define($setting_name, $setting_value);
|
|
365 |
defined($setting_name) ? '' : define($setting_name, $setting_value);
|
360 |
366 |
$x++;
|
361 |
367 |
}
|
362 |
368 |
} else {
|
... | ... | |
365 |
371 |
if (!$x) {
|
366 |
372 |
throw new RuntimeException('no settings found');
|
367 |
373 |
}
|
368 |
|
@define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
|
369 |
|
ini_set('display_errors', ((defined('DEBUG')&& (DEBUG==true)) ?'1':'0'));
|
|
374 |
defined('DO_NOT_TRACK') ? '' : define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT'])));
|
|
375 |
ini_set('display_errors', ((defined('DEBUG') && (DEBUG==true)) ?'1':'0'));
|
370 |
376 |
|
371 |
|
if (!defined('DEBUG')){ define('DEBUG', false); }
|
372 |
|
$string_file_mode = defined('STRING_FILE_MODE')?STRING_FILE_MODE:'0644';
|
373 |
|
@define('OCTAL_FILE_MODE',(int) octdec($string_file_mode));
|
374 |
|
$string_dir_mode = defined('STRING_DIR_MODE')?STRING_DIR_MODE:'0755';
|
375 |
|
@define('OCTAL_DIR_MODE',(int) octdec($string_dir_mode));
|
|
377 |
defined('DEBUG') ? '' : define('DEBUG', false);
|
|
378 |
$string_file_mode = defined('STRING_FILE_MODE') ? STRING_FILE_MODE : '0644';
|
|
379 |
defined('OCTAL_FILE_MODE') ? '' : define('OCTAL_FILE_MODE', (int) octdec($string_file_mode));
|
|
380 |
$string_dir_mode = defined('STRING_DIR_MODE') ? STRING_DIR_MODE : '0755';
|
|
381 |
defined('OCTAL_DIR_MODE') ? '' : define('OCTAL_DIR_MODE', (int) octdec($string_dir_mode));
|
376 |
382 |
// $sSecMod = (defined('SECURE_FORM_MODULE') && SECURE_FORM_MODULE != '') ? '.'.SECURE_FORM_MODULE : '';
|
377 |
383 |
// $sSecMod = WB_PATH.'/framework/SecureForm'.$sSecMod.'.php';
|
378 |
384 |
// require_once($sSecMod);
|
379 |
|
if (!defined("WB_INSTALL_PROCESS")) {
|
|
385 |
if (!defined('WB_INSTALL_PROCESS')) {
|
380 |
386 |
// get CAPTCHA and ASP settings
|
381 |
387 |
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_captcha_control`';
|
382 |
388 |
if (($get_settings = $database->query($sql)) &&
|
383 |
389 |
($setting = $get_settings->fetchRow(MYSQLI_ASSOC))
|
384 |
390 |
) {
|
385 |
|
@define('ENABLED_CAPTCHA', (($setting['enabled_captcha'] == '1') ? true : false));
|
386 |
|
@define('ENABLED_ASP', (($setting['enabled_asp'] == '1') ? true : false));
|
387 |
|
@define('CAPTCHA_TYPE', $setting['captcha_type']);
|
388 |
|
@define('ASP_SESSION_MIN_AGE', (int)$setting['asp_session_min_age']);
|
389 |
|
@define('ASP_VIEW_MIN_AGE', (int)$setting['asp_view_min_age']);
|
390 |
|
@define('ASP_INPUT_MIN_AGE', (int)$setting['asp_input_min_age']);
|
|
391 |
defined('ENABLED_CAPTCHA') ? '' : define('ENABLED_CAPTCHA', (bool) ($setting['enabled_captcha'] == '1'));
|
|
392 |
defined('ENABLED_ASP') ? '' : define('ENABLED_ASP', (bool) ($setting['enabled_asp'] == '1'));
|
|
393 |
defined('CAPTCHA_TYPE') ? '' : define('CAPTCHA_TYPE', $setting['captcha_type']);
|
|
394 |
defined('ASP_SESSION_MIN_AGE') ? '' : define('ASP_SESSION_MIN_AGE', (int) $setting['asp_session_min_age']);
|
|
395 |
defined('ASP_VIEW_MIN_AGE') ? '' : define('ASP_VIEW_MIN_AGE', (int) $setting['asp_view_min_age']);
|
|
396 |
defined('ASP_INPUT_MIN_AGE') ? '' : define('ASP_INPUT_MIN_AGE', (int) $setting['asp_input_min_age']);
|
391 |
397 |
} else {
|
392 |
398 |
throw new RuntimeException('CAPTCHA-Settings not found');
|
393 |
399 |
}
|
... | ... | |
442 |
448 |
require $slangFile;
|
443 |
449 |
}
|
444 |
450 |
}
|
445 |
|
if (!class_exists('Translate', false)) {
|
446 |
|
include __DIR__.'/Translate.php';
|
447 |
|
}
|
|
451 |
// if (!class_exists('Translate', false)) {
|
|
452 |
// include __DIR__.'/Translate.php';
|
|
453 |
// }
|
448 |
454 |
$oTrans = Translate::getInstance();
|
449 |
455 |
$oTrans->initialize(array('EN', DEFAULT_LANGUAGE, LANGUAGE), $sCachePath); // 'none'
|
450 |
456 |
// Get users timezone
|
... | ... | |
472 |
478 |
define('EDIT_ONE_SECTION', false);
|
473 |
479 |
define('EDITOR_WIDTH', 0);
|
474 |
480 |
}
|
475 |
|
|
476 |
|
function newAdmin($section_name= '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true)
|
477 |
|
{
|
478 |
|
if (isset($GLOBALS['admin']) && $GLOBALS['admin'] instanceof admin) {
|
479 |
|
unset($GLOBALS['admin']);
|
480 |
|
usleep(10000);
|
481 |
|
}
|
482 |
|
return new admin($section_name, $section_permission, $auto_header, $auto_auth);
|
483 |
|
}
|
modified class database to default charset utf8mb4
added property database->sTablePrefix