ElixirVault/www/system-brs-core/config/init.php

116 lines
4.2 KiB
PHP

<?php
namespace BRSystems\Core\Config;
use BRSystems\Core\Library\cCoreSystem\cCoreSystem;
use BRSystems\Core\Library\cINI\cINI;
use BRSystems\Core\Library\cSysConsole\cSysConsole;
use BRSystems\Core\Library\cTimer\cTimer;
//-------------------------------------------------------------
// UPDATER REQUESTS
//-------------------------------------------------------------
if(substr($_SERVER['REQUEST_URI'], 0, 13) == '/proj-updater'){
require_once __MDIR__ . 'system-updater/index.php';
die();
}
//-------------------------------------------------------------
// Include functions
//-------------------------------------------------------------
require_once 'constants.php';
require_once __FUNCT__ . 'com.funct.php';
// Set handler functions
set_error_handler('errorHandler');
// Load site configuration file
$oCfg = new cINI(__CFG__ . 'init.cfg.ini');
$oCfg->loadSystemConstants();
//-------------------------------------------------------------
// Set developer configuration
//-------------------------------------------------------------
$debug_mode = false;
if($oCfg->getV('system', 'DEBUG_MODE')){
$excludeIps = $oCfg->getV('system_update', 'EXCLUDE_IP');
$debug_mode = (is_array($excludeIps) && in_array($_SERVER['REMOTE_ADDR'], $excludeIps) || $_SERVER['REMOTE_ADDR'] == $_SERVER['SERVER_ADDR']); // TODO BRS Aivars: Err: 2 Line: 24 Error: in_array() expects parameter 2 to be array, boolean given
}
if(!defined('DB_DEBUG')) define('DB_DEBUG', $debug_mode);
if(!defined('DEBUG_MODE')) define('DEBUG_MODE', $debug_mode);
if(!defined('DEBUG_QUERIES')) define('DEBUG_QUERIES', $debug_mode);
if(!defined('GET_REQ')) define('GET_REQ', $_SERVER['REQUEST_METHOD'] === 'GET');
if(!defined('POST_REQ')) define('POST_REQ', $_SERVER['REQUEST_METHOD'] === 'POST');
if(!defined('DISABLED_2FA')) define('DISABLED_2FA', ($oCfg->getV('system', 'DISABLE_2FA') && $debug_mode ? true : false));
if(!defined('ENABLE_RECAPTCHA_REG_FORM')) define('ENABLE_RECAPTCHA_REG_FORM', ($oCfg->getV('system', 'ENABLE_RECAPTCHA_REG_FORM') ? true : false));
//-------------------------------------------------------------
// Change php.ini configuration
//-------------------------------------------------------------
if(DEBUG_MODE){
ini_set('display_errors', 'On');
ini_set('error_reporting', E_ALL);
}else{
ini_set('display_errors','Off');
ini_set('error_reporting', !E_NOTICE & !E_WARNING);
}
// Set time zone
if($sZone = $oCfg->getV('system', 'DATE_TIMEZONE')){
ini_set('date.timezone', $sZone);
date_default_timezone_set($sZone);
}else{
// Set default
ini_set('date.timezone', 'Europe/Riga');
date_default_timezone_set('Europe/Riga');
}
// Set default host
if(empty($_SERVER['HTTP_HOST']) && $sDefaultHost = $oCfg->getV('system', 'DEFAULT_HOST'))
$_SERVER['HTTP_HOST'] = $sDefaultHost;
//-------------------------------------------------------------
// Redirect ajax / cron / updater
//-------------------------------------------------------------
if(@substr($_SERVER['REQUEST_URI'], 0,6) == '/ajax/'){
require_once 'ajax-c/ajax.php';
die();
}
if(@substr($_SERVER['REQUEST_URI'], 0,6) == '/cron/'){
require_once __MDIR__ . 'cron-c/cron.php';
die();
}
//-------------------------------------------------------------
// Start session
//-------------------------------------------------------------
startSessionSameSite(60*60*24);
if(isset($_SESSION['time']) && $_SESSION['time'] <= time())
startSessionSameSite( 60*60*24, true);
$_SESSION['time'] = time() + CUSTOM_SESSION_LIFE;
//-------------------------------------------------------------
// Page Load timer to script
//-------------------------------------------------------------
if(DEBUG_MODE){
cSysConsole::getInstance();
$cTimer = new cTimer('app_launch');
}
//-------------------------------------------------------------
// Load & Start app
//-------------------------------------------------------------
$app = new cCoreSystem();
$app->launch();