Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/main/lib/engine/response/ |
Upload File : |
<?php namespace Bitrix\Main\Engine\Response; use Bitrix\Main; use Bitrix\Main\Context; use Bitrix\Main\Web\Uri; class Redirect extends Main\HttpResponse { /** @var string */ private $url; /** @var bool */ private $skipSecurity; public function __construct($url, bool $skipSecurity = false) { parent::__construct(); $this ->setStatus('302 Found') ->setSkipSecurity($skipSecurity) ->setUrl($url) ; } /** * @return string */ public function getUrl() { return $this->url; } /** * @param string $url * @return $this */ public function setUrl($url) { $this->url = (string)$url; return $this; } /** * @return bool */ public function isSkippedSecurity(): bool { return $this->skipSecurity; } /** * @param bool $skipSecurity * @return $this */ public function setSkipSecurity(bool $skipSecurity) { $this->skipSecurity = $skipSecurity; return $this; } private function checkTrial(): bool { $isTrial = defined("DEMO") && DEMO === "Y" && ( !defined("SITEEXPIREDATE") || !defined("OLDSITEEXPIREDATE") || SITEEXPIREDATE == '' || SITEEXPIREDATE != OLDSITEEXPIREDATE ) ; return $isTrial; } private function isExternalUrl($url): bool { return preg_match("'^(http://|https://|ftp://)'i", $url); } private function modifyBySecurity($url) { /** @global \CMain $APPLICATION */ global $APPLICATION; $isExternal = $this->isExternalUrl($url); if (!$isExternal && !str_starts_with($url, "/")) { $url = $APPLICATION->GetCurDir() . $url; } if ($isExternal) { // normalizes user info part of the url $url = (string)(new Uri($this->url)); } //doubtful about & and http response splitting defence $url = str_replace(["&", "\r", "\n"], ["&", "", ""], $url); return $url; } private function processInternalUrl($url) { /** @global \CMain $APPLICATION */ global $APPLICATION; //store cookies for next hit (see CMain::GetSpreadCookieHTML()) $APPLICATION->StoreCookies(); $server = Context::getCurrent()->getServer(); $protocol = Context::getCurrent()->getRequest()->isHttps() ? "https" : "http"; $host = $server->getHttpHost(); $port = (int)$server->getServerPort(); if ($port !== 80 && $port !== 443 && $port > 0 && !str_contains($host, ":")) { $host .= ":" . $port; } return "{$protocol}://{$host}{$url}"; } public function send() { if ($this->checkTrial()) { die(Main\Localization\Loc::getMessage('MAIN_ENGINE_REDIRECT_TRIAL_EXPIRED')); } $url = $this->getUrl(); $isExternal = $this->isExternalUrl($url); $url = $this->modifyBySecurity($url); foreach (GetModuleEvents("main", "OnBeforeLocalRedirect", true) as $event) { ExecuteModuleEventEx($event, [&$url, $this->isSkippedSecurity(), &$isExternal, $this]); } if (!$isExternal) { $url = $this->processInternalUrl($url); } $this->addHeader('Location', $url); foreach (GetModuleEvents("main", "OnLocalRedirect", true) as $event) { ExecuteModuleEventEx($event); } Main\Application::getInstance()->getKernelSession()["BX_REDIRECT_TIME"] = time(); parent::send(); } }