/modules/main/include.php
https://gitlab.com/alexprowars/bitrix · PHP · 510 lines · 386 code · 79 blank · 45 comment · 134 complexity · 20071920d93f2923c82cb7d6ce0b7042 MD5 · raw file
- <?php
- /**
- * Bitrix Framework
- * @package bitrix
- * @subpackage main
- * @copyright 2001-2013 Bitrix
- */
- use Bitrix\Main\Session\Legacy\HealerEarlySessionStart;
- require_once(__DIR__."/bx_root.php");
- require_once(__DIR__."/start.php");
- $application = \Bitrix\Main\Application::getInstance();
- $application->initializeExtendedKernel(array(
- "get" => $_GET,
- "post" => $_POST,
- "files" => $_FILES,
- "cookie" => $_COOKIE,
- "server" => $_SERVER,
- "env" => $_ENV
- ));
- //define global application object
- $GLOBALS["APPLICATION"] = new CMain;
- if(defined("SITE_ID"))
- define("LANG", SITE_ID);
- if(defined("LANG"))
- {
- if(defined("ADMIN_SECTION") && ADMIN_SECTION===true)
- $db_lang = CLangAdmin::GetByID(LANG);
- else
- $db_lang = CLang::GetByID(LANG);
- $arLang = $db_lang->Fetch();
- if(!$arLang)
- {
- throw new \Bitrix\Main\SystemException("Incorrect site: ".LANG.".");
- }
- }
- else
- {
- $arLang = $GLOBALS["APPLICATION"]->GetLang();
- define("LANG", $arLang["LID"]);
- }
- if($arLang["CULTURE_ID"] == '')
- {
- throw new \Bitrix\Main\SystemException("Culture not found, or there are no active sites or languages.");
- }
- $lang = $arLang["LID"];
- if (!defined("SITE_ID"))
- define("SITE_ID", $arLang["LID"]);
- define("SITE_DIR", ($arLang["DIR"] ?? ''));
- define("SITE_SERVER_NAME", ($arLang["SERVER_NAME"] ?? ''));
- define("SITE_CHARSET", $arLang["CHARSET"]);
- define("FORMAT_DATE", $arLang["FORMAT_DATE"]);
- define("FORMAT_DATETIME", $arLang["FORMAT_DATETIME"]);
- define("LANG_DIR", ($arLang["DIR"] ?? ''));
- define("LANG_CHARSET", $arLang["CHARSET"]);
- define("LANG_ADMIN_LID", $arLang["LANGUAGE_ID"]);
- define("LANGUAGE_ID", $arLang["LANGUAGE_ID"]);
- $culture = \Bitrix\Main\Localization\CultureTable::getByPrimary($arLang["CULTURE_ID"], ["cache" => ["ttl" => CACHED_b_lang]])->fetchObject();
- $context = $application->getContext();
- $context->setLanguage(LANGUAGE_ID);
- $context->setCulture($culture);
- $request = $context->getRequest();
- if (!$request->isAdminSection())
- {
- $context->setSite(SITE_ID);
- }
- $application->start();
- $GLOBALS["APPLICATION"]->reinitPath();
- if (!defined("POST_FORM_ACTION_URI"))
- {
- define("POST_FORM_ACTION_URI", htmlspecialcharsbx(GetRequestUri()));
- }
- $GLOBALS["MESS"] = [];
- $GLOBALS["ALL_LANG_FILES"] = [];
- IncludeModuleLangFile(__DIR__."/tools.php");
- IncludeModuleLangFile(__FILE__);
- error_reporting(COption::GetOptionInt("main", "error_reporting", E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR|E_PARSE) & ~E_STRICT & ~E_DEPRECATED);
- if(!defined("BX_COMP_MANAGED_CACHE") && COption::GetOptionString("main", "component_managed_cache_on", "Y") <> "N")
- {
- define("BX_COMP_MANAGED_CACHE", true);
- }
- // global functions
- require_once(__DIR__."/filter_tools.php");
- define('BX_AJAX_PARAM_ID', 'bxajaxid');
- /*ZDUyZmZNjVhZThiNjNkOTZlZDE1OTE2YTM1NmVjZTNhODAwZTk=*/$GLOBALS['____2131814890']= array(base64_decode('ZGVmaW5l'));if(!function_exists(__NAMESPACE__.'\\___1614983869')){function ___1614983869($_321374208){static $_1997553827= false; if($_1997553827 == false) $_1997553827=array('RU5'.'DT0RF','WQ='.'=');return base64_decode($_1997553827[$_321374208]);}};class CBXFeatures{ public static function IsFeatureEnabled($_1585349041){ return true;} public static function IsFeatureEditable($_1585349041){ return true;} public static function SetFeatureEnabled($_1585349041, $_1373124910= true){} public static function SaveFeaturesSettings($_1252506144, $_63900902){} public static function GetFeaturesList(){ return array();} public static function InitiateEditionsSettings($_1317691075){} public static function ModifyFeaturesSettings($_1317691075, $_867319609){} public static function IsFeatureInstalled($_1585349041){ return true;}} $GLOBALS['____2131814890'][0](___1614983869(0), ___1614983869(1));/**/ //Do not remove this
- //component 2.0 template engines
- $GLOBALS["arCustomTemplateEngines"] = [];
- require_once(__DIR__."/autoload.php");
- require_once(__DIR__."/classes/general/menu.php");
- require_once(__DIR__."/classes/mysql/usertype.php");
- if(file_exists(($_fname = __DIR__."/classes/general/update_db_updater.php")))
- {
- $US_HOST_PROCESS_MAIN = False;
- include($_fname);
- }
- if(file_exists(($_fname = $_SERVER["DOCUMENT_ROOT"]."/bitrix/init.php")))
- include_once($_fname);
- if(($_fname = getLocalPath("php_interface/init.php", BX_PERSONAL_ROOT)) !== false)
- include_once($_SERVER["DOCUMENT_ROOT"].$_fname);
- if(($_fname = getLocalPath("php_interface/".SITE_ID."/init.php", BX_PERSONAL_ROOT)) !== false)
- include_once($_SERVER["DOCUMENT_ROOT"].$_fname);
- if(!defined("BX_FILE_PERMISSIONS"))
- define("BX_FILE_PERMISSIONS", 0644);
- if(!defined("BX_DIR_PERMISSIONS"))
- define("BX_DIR_PERMISSIONS", 0755);
- //global var, is used somewhere
- $GLOBALS["sDocPath"] = $GLOBALS["APPLICATION"]->GetCurPage();
- if((!(defined("STATISTIC_ONLY") && STATISTIC_ONLY && mb_substr($GLOBALS["APPLICATION"]->GetCurPage(), 0, mb_strlen(BX_ROOT."/admin/")) != BX_ROOT."/admin/")) && COption::GetOptionString("main", "include_charset", "Y")=="Y" && LANG_CHARSET <> '')
- header("Content-Type: text/html; charset=".LANG_CHARSET);
- if(COption::GetOptionString("main", "set_p3p_header", "Y")=="Y")
- header("P3P: policyref=\"/bitrix/p3p.xml\", CP=\"NON DSP COR CUR ADM DEV PSA PSD OUR UNR BUS UNI COM NAV INT DEM STA\"");
- header("X-Powered-CMS: Bitrix Site Manager (".(LICENSE_KEY == "DEMO"? "DEMO" : md5("BITRIX".LICENSE_KEY."LICENCE")).")");
- if (COption::GetOptionString("main", "update_devsrv", "") == "Y")
- header("X-DevSrv-CMS: Bitrix");
- if (!defined("BX_CRONTAB_SUPPORT"))
- {
- define("BX_CRONTAB_SUPPORT", defined("BX_CRONTAB"));
- }
- //agents
- if(COption::GetOptionString("main", "check_agents", "Y") == "Y")
- {
- $application->addBackgroundJob(["CAgent", "CheckAgents"], [], \Bitrix\Main\Application::JOB_PRIORITY_LOW);
- }
- //send email events
- if(COption::GetOptionString("main", "check_events", "Y") !== "N")
- {
- $application->addBackgroundJob(['\Bitrix\Main\Mail\EventManager', 'checkEvents'], [], \Bitrix\Main\Application::JOB_PRIORITY_LOW-1);
- }
- $healerOfEarlySessionStart = new HealerEarlySessionStart();
- $healerOfEarlySessionStart->process($application->getKernelSession());
- $kernelSession = $application->getKernelSession();
- $kernelSession->start();
- $application->getSessionLocalStorageManager()->setUniqueId($kernelSession->getId());
- foreach (GetModuleEvents("main", "OnPageStart", true) as $arEvent)
- ExecuteModuleEventEx($arEvent);
- //define global user object
- $GLOBALS["USER"] = new CUser;
- //session control from group policy
- $arPolicy = $GLOBALS["USER"]->GetSecurityPolicy();
- $currTime = time();
- if(
- (
- //IP address changed
- $kernelSession['SESS_IP']
- && $arPolicy["SESSION_IP_MASK"] <> ''
- && (
- (ip2long($arPolicy["SESSION_IP_MASK"]) & ip2long($kernelSession['SESS_IP']))
- !=
- (ip2long($arPolicy["SESSION_IP_MASK"]) & ip2long($_SERVER['REMOTE_ADDR']))
- )
- )
- ||
- (
- //session timeout
- $arPolicy["SESSION_TIMEOUT"]>0
- && $kernelSession['SESS_TIME']>0
- && $currTime-$arPolicy["SESSION_TIMEOUT"]*60 > $kernelSession['SESS_TIME']
- )
- ||
- (
- //signed session
- isset($kernelSession["BX_SESSION_SIGN"])
- && $kernelSession["BX_SESSION_SIGN"] <> bitrix_sess_sign()
- )
- ||
- (
- //session manually expired, e.g. in $User->LoginHitByHash
- isSessionExpired()
- )
- )
- {
- $compositeSessionManager = $application->getCompositeSessionManager();
- $compositeSessionManager->destroy();
- $application->getSession()->setId(md5(uniqid(rand(), true)));
- $compositeSessionManager->start();
- $GLOBALS["USER"] = new CUser;
- }
- $kernelSession['SESS_IP'] = $_SERVER['REMOTE_ADDR'];
- if (empty($kernelSession['SESS_TIME']))
- {
- $kernelSession['SESS_TIME'] = $currTime;
- }
- elseif (($currTime - $kernelSession['SESS_TIME']) > 60)
- {
- $kernelSession['SESS_TIME'] = $currTime;
- }
- if(!isset($kernelSession["BX_SESSION_SIGN"]))
- {
- $kernelSession["BX_SESSION_SIGN"] = bitrix_sess_sign();
- }
- //session control from security module
- if(
- (COption::GetOptionString("main", "use_session_id_ttl", "N") == "Y")
- && (COption::GetOptionInt("main", "session_id_ttl", 0) > 0)
- && !defined("BX_SESSION_ID_CHANGE")
- )
- {
- if(!isset($kernelSession['SESS_ID_TIME']))
- {
- $kernelSession['SESS_ID_TIME'] = $currTime;
- }
- elseif(($kernelSession['SESS_ID_TIME'] + COption::GetOptionInt("main", "session_id_ttl")) < $kernelSession['SESS_TIME'])
- {
- $compositeSessionManager = $application->getCompositeSessionManager();
- $compositeSessionManager->regenerateId();
- $kernelSession['SESS_ID_TIME'] = $currTime;
- }
- }
- define("BX_STARTED", true);
- if (isset($kernelSession['BX_ADMIN_LOAD_AUTH']))
- {
- define('ADMIN_SECTION_LOAD_AUTH', 1);
- unset($kernelSession['BX_ADMIN_LOAD_AUTH']);
- }
- if(!defined("NOT_CHECK_PERMISSIONS") || NOT_CHECK_PERMISSIONS!==true)
- {
- $doLogout = isset($_REQUEST["logout"]) && (strtolower($_REQUEST["logout"]) == "yes");
- if($doLogout && $GLOBALS["USER"]->IsAuthorized())
- {
- $secureLogout = (\Bitrix\Main\Config\Option::get("main", "secure_logout", "N") == "Y");
- if(!$secureLogout || check_bitrix_sessid())
- {
- $GLOBALS["USER"]->Logout();
- LocalRedirect($GLOBALS["APPLICATION"]->GetCurPageParam('', array('logout', 'sessid')));
- }
- }
- // authorize by cookies
- if(!$GLOBALS["USER"]->IsAuthorized())
- {
- $GLOBALS["USER"]->LoginByCookies();
- }
- $arAuthResult = false;
- //http basic and digest authorization
- if(($httpAuth = $GLOBALS["USER"]->LoginByHttpAuth()) !== null)
- {
- $arAuthResult = $httpAuth;
- $GLOBALS["APPLICATION"]->SetAuthResult($arAuthResult);
- }
- //Authorize user from authorization html form
- //Only POST is accepted
- if(isset($_POST["AUTH_FORM"]) && $_POST["AUTH_FORM"] <> '')
- {
- $bRsaError = false;
- if(COption::GetOptionString('main', 'use_encrypted_auth', 'N') == 'Y')
- {
- //possible encrypted user password
- $sec = new CRsaSecurity();
- if(($arKeys = $sec->LoadKeys()))
- {
- $sec->SetKeys($arKeys);
- $errno = $sec->AcceptFromForm(['USER_PASSWORD', 'USER_CONFIRM_PASSWORD', 'USER_CURRENT_PASSWORD']);
- if($errno == CRsaSecurity::ERROR_SESS_CHECK)
- $arAuthResult = array("MESSAGE"=>GetMessage("main_include_decode_pass_sess"), "TYPE"=>"ERROR");
- elseif($errno < 0)
- $arAuthResult = array("MESSAGE"=>GetMessage("main_include_decode_pass_err", array("#ERRCODE#"=>$errno)), "TYPE"=>"ERROR");
- if($errno < 0)
- $bRsaError = true;
- }
- }
- if($bRsaError == false)
- {
- if(!defined("ADMIN_SECTION") || ADMIN_SECTION !== true)
- $USER_LID = SITE_ID;
- else
- $USER_LID = false;
- if($_POST["TYPE"] == "AUTH")
- {
- $arAuthResult = $GLOBALS["USER"]->Login($_POST["USER_LOGIN"], $_POST["USER_PASSWORD"], $_POST["USER_REMEMBER"]);
- }
- elseif($_POST["TYPE"] == "OTP")
- {
- $arAuthResult = $GLOBALS["USER"]->LoginByOtp($_POST["USER_OTP"], $_POST["OTP_REMEMBER"], $_POST["captcha_word"], $_POST["captcha_sid"]);
- }
- elseif($_POST["TYPE"] == "SEND_PWD")
- {
- $arAuthResult = CUser::SendPassword($_POST["USER_LOGIN"], $_POST["USER_EMAIL"], $USER_LID, $_POST["captcha_word"], $_POST["captcha_sid"], $_POST["USER_PHONE_NUMBER"]);
- }
- elseif($_POST["TYPE"] == "CHANGE_PWD")
- {
- $arAuthResult = $GLOBALS["USER"]->ChangePassword($_POST["USER_LOGIN"], $_POST["USER_CHECKWORD"], $_POST["USER_PASSWORD"], $_POST["USER_CONFIRM_PASSWORD"], $USER_LID, $_POST["captcha_word"], $_POST["captcha_sid"], true, $_POST["USER_PHONE_NUMBER"], $_POST["USER_CURRENT_PASSWORD"]);
- }
- elseif(COption::GetOptionString("main", "new_user_registration", "N") == "Y" && $_POST["TYPE"] == "REGISTRATION" && (!defined("ADMIN_SECTION") || ADMIN_SECTION !== true))
- {
- $arAuthResult = $GLOBALS["USER"]->Register($_POST["USER_LOGIN"], $_POST["USER_NAME"], $_POST["USER_LAST_NAME"], $_POST["USER_PASSWORD"], $_POST["USER_CONFIRM_PASSWORD"], $_POST["USER_EMAIL"], $USER_LID, $_POST["captcha_word"], $_POST["captcha_sid"], false, $_POST["USER_PHONE_NUMBER"]);
- }
- if($_POST["TYPE"] == "AUTH" || $_POST["TYPE"] == "OTP")
- {
- //special login form in the control panel
- if($arAuthResult === true && defined('ADMIN_SECTION') && ADMIN_SECTION === true)
- {
- //store cookies for next hit (see CMain::GetSpreadCookieHTML())
- $GLOBALS["APPLICATION"]->StoreCookies();
- $kernelSession['BX_ADMIN_LOAD_AUTH'] = true;
- // die() follows
- CMain::FinalActions('<script type="text/javascript">window.onload=function(){(window.BX || window.parent.BX).AUTHAGENT.setAuthResult(false);};</script>');
- }
- }
- }
- $GLOBALS["APPLICATION"]->SetAuthResult($arAuthResult);
- }
- elseif(!$GLOBALS["USER"]->IsAuthorized() && isset($_REQUEST['bx_hit_hash']))
- {
- //Authorize by unique URL
- $GLOBALS["USER"]->LoginHitByHash($_REQUEST['bx_hit_hash']);
- }
- }
- //logout or re-authorize the user if something importand has changed
- $GLOBALS["USER"]->CheckAuthActions();
- //magic short URI
- if(defined("BX_CHECK_SHORT_URI") && BX_CHECK_SHORT_URI && CBXShortUri::CheckUri())
- {
- //local redirect inside
- die();
- }
- //application password scope control
- if(($applicationID = $GLOBALS["USER"]->GetParam("APPLICATION_ID")) !== null)
- {
- $appManager = \Bitrix\Main\Authentication\ApplicationManager::getInstance();
- if($appManager->checkScope($applicationID) !== true)
- {
- $event = new \Bitrix\Main\Event("main", "onApplicationScopeError", Array('APPLICATION_ID' => $applicationID));
- $event->send();
- CHTTP::SetStatus("403 Forbidden");
- die();
- }
- }
- //define the site template
- if(!defined("ADMIN_SECTION") || ADMIN_SECTION !== true)
- {
- $siteTemplate = "";
- if(isset($_REQUEST["bitrix_preview_site_template"]) && is_string($_REQUEST["bitrix_preview_site_template"]) && $_REQUEST["bitrix_preview_site_template"] <> "" && $GLOBALS["USER"]->CanDoOperation('view_other_settings'))
- {
- //preview of site template
- $signer = new Bitrix\Main\Security\Sign\Signer();
- try
- {
- //protected by a sign
- $requestTemplate = $signer->unsign($_REQUEST["bitrix_preview_site_template"], "template_preview".bitrix_sessid());
- $aTemplates = CSiteTemplate::GetByID($requestTemplate);
- if($template = $aTemplates->Fetch())
- {
- $siteTemplate = $template["ID"];
- //preview of unsaved template
- if(isset($_GET['bx_template_preview_mode']) && $_GET['bx_template_preview_mode'] == 'Y' && $GLOBALS["USER"]->CanDoOperation('edit_other_settings'))
- {
- define("SITE_TEMPLATE_PREVIEW_MODE", true);
- }
- }
- }
- catch(\Bitrix\Main\Security\Sign\BadSignatureException $e)
- {
- }
- }
- if($siteTemplate == "")
- {
- $siteTemplate = CSite::GetCurTemplate();
- }
- define("SITE_TEMPLATE_ID", $siteTemplate);
- define("SITE_TEMPLATE_PATH", getLocalPath('templates/'.SITE_TEMPLATE_ID, BX_PERSONAL_ROOT));
- }
- else
- {
- // prevents undefined constants
- define('SITE_TEMPLATE_ID', '.default');
- define('SITE_TEMPLATE_PATH', '/bitrix/templates/.default');
- }
- //magic parameters: show page creation time
- if(isset($_GET["show_page_exec_time"]))
- {
- if($_GET["show_page_exec_time"]=="Y" || $_GET["show_page_exec_time"]=="N")
- $kernelSession["SESS_SHOW_TIME_EXEC"] = $_GET["show_page_exec_time"];
- }
- //magic parameters: show included file processing time
- if(isset($_GET["show_include_exec_time"]))
- {
- if($_GET["show_include_exec_time"]=="Y" || $_GET["show_include_exec_time"]=="N")
- $kernelSession["SESS_SHOW_INCLUDE_TIME_EXEC"] = $_GET["show_include_exec_time"];
- }
- //magic parameters: show include areas
- if(isset($_GET["bitrix_include_areas"]) && $_GET["bitrix_include_areas"] <> "")
- $GLOBALS["APPLICATION"]->SetShowIncludeAreas($_GET["bitrix_include_areas"]=="Y");
- //magic sound
- if($GLOBALS["USER"]->IsAuthorized())
- {
- $cookie_prefix = COption::GetOptionString('main', 'cookie_name', 'BITRIX_SM');
- if(!isset($_COOKIE[$cookie_prefix.'_SOUND_LOGIN_PLAYED']))
- $GLOBALS["APPLICATION"]->set_cookie('SOUND_LOGIN_PLAYED', 'Y', 0);
- }
- //magic cache
- \Bitrix\Main\Composite\Engine::shouldBeEnabled();
- foreach(GetModuleEvents("main", "OnBeforeProlog", true) as $arEvent)
- ExecuteModuleEventEx($arEvent);
- if((!defined("NOT_CHECK_PERMISSIONS") || NOT_CHECK_PERMISSIONS!==true) && (!defined("NOT_CHECK_FILE_PERMISSIONS") || NOT_CHECK_FILE_PERMISSIONS!==true))
- {
- $real_path = $request->getScriptFile();
- if(!$GLOBALS["USER"]->CanDoFileOperation('fm_view_file', array(SITE_ID, $real_path)) || (defined("NEED_AUTH") && NEED_AUTH && !$GLOBALS["USER"]->IsAuthorized()))
- {
- /** @noinspection PhpUndefinedVariableInspection */
- if($GLOBALS["USER"]->IsAuthorized() && $arAuthResult["MESSAGE"] == '')
- {
- $arAuthResult = array("MESSAGE"=>GetMessage("ACCESS_DENIED").' '.GetMessage("ACCESS_DENIED_FILE", array("#FILE#"=>$real_path)), "TYPE"=>"ERROR");
- if(COption::GetOptionString("main", "event_log_permissions_fail", "N") === "Y")
- {
- CEventLog::Log("SECURITY", "USER_PERMISSIONS_FAIL", "main", $GLOBALS["USER"]->GetID(), $real_path);
- }
- }
- if(defined("ADMIN_SECTION") && ADMIN_SECTION==true)
- {
- if ($_REQUEST["mode"]=="list" || $_REQUEST["mode"]=="settings")
- {
- echo "<script>top.location='".$GLOBALS["APPLICATION"]->GetCurPage()."?".DeleteParam(array("mode"))."';</script>";
- die();
- }
- elseif ($_REQUEST["mode"]=="frame")
- {
- echo "<script type=\"text/javascript\">
- var w = (opener? opener.window:parent.window);
- w.location.href='".$GLOBALS["APPLICATION"]->GetCurPage()."?".DeleteParam(array("mode"))."';
- </script>";
- die();
- }
- elseif(defined("MOBILE_APP_ADMIN") && MOBILE_APP_ADMIN==true)
- {
- echo json_encode(Array("status"=>"failed"));
- die();
- }
- }
- /** @noinspection PhpUndefinedVariableInspection */
- $GLOBALS["APPLICATION"]->AuthForm($arAuthResult);
- }
- }
- //Do not remove this