• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/update_class.php
  • Класс: CUpdateSystem
  • Вызов: CUpdateSystem::getHTTPPage
static function getHTTPPage($page, $strVars, &$strError)
{
	global $SERVER_NAME, $DB;

	CUpdateSystem::AddMessage2Log("exec CUpdateSystem::getHTTPPage");

	$ServerIP = COption::GetOptionString("main", "update_site", "www.bitrixsoft.com");
	$ServerPort = 80;

	$proxyAddr = COption::GetOptionString("main", "update_site_proxy_addr", "");
	$proxyPort = COption::GetOptionString("main", "update_site_proxy_port", "");
	$proxyUserName = COption::GetOptionString("main", "update_site_proxy_user", "");
	$proxyPassword = COption::GetOptionString("main", "update_site_proxy_pass", "");

	$bUseProxy = ($proxyAddr <> '' && $proxyPort <> '');

	if ($bUseProxy)
	{
		$proxyPort = intval($proxyPort);
		if ($proxyPort <= 0)
			$proxyPort = 80;

		$requestIP = $proxyAddr;
		$requestPort = $proxyPort;
	}
	else
	{
		$requestIP = $ServerIP;
		$requestPort = $ServerPort;
	}

	$FP = fsockopen($requestIP, $requestPort, $errno, $errstr, 120);

	if ($FP)
	{
		$strRequest = "";

		if ($bUseProxy)
		{
			$strRequest .= "POST http://".$ServerIP."/bitrix/updates/".$page." HTTP/1.0rn";
			if ($proxyUserName <> '')
				$strRequest .= "Proxy-Authorization: Basic ".base64_encode($proxyUserName.":".$proxyPassword)."rn";
		}
		else
			$strRequest .= "POST /bitrix/updates/".$page." HTTP/1.0rn";

		$CRCCode = COption::GetOptionString("main", "crc_code", "");
		$strVars .= "&spd=".urlencode($CRCCode);
		if (defined('BX_UTF'))
			$strVars .= "&utf=".urlencode("Y");
		else
			$strVars .= "&utf=".urlencode("N");
		$dbv = $DB->GetVersion();
		$strVars .= "&dbv=".urlencode($dbv != false ? $dbv : "");

		$strRequest .= "User-Agent: BitrixSMUpdaterrn";
		$strRequest .= "Accept: */*rn";
		$strRequest .= "Host: ".$ServerIP."rn";
		$strRequest .= "Accept-Language: enrn";
		$strRequest .= "Content-type: application/x-www-form-urlencodedrn";
		$strRequest .= "Content-length: ".strlen($strVars)."rnrn";
		$strRequest .= "$strVars";
		$strRequest .= "rn";

		fputs($FP, $strRequest);

		$bChunked = false;
		while (!feof($FP))
		{
			$line = fgets($FP, 4096);
			if ($line != "rn")
			{
				if (preg_match("/Transfer-Encoding: +chunked/i", $line))
					$bChunked = true;
			}
			else
			{
				break;
			}
		}

		/*
		while (($line = fgets($FP, 4096)) && $line != "rn")
		{
			if (preg_match("/Transfer-Encoding: +chunked/i", $line))
				$bChunked = True;
		}
		*/

		$content = "";
		if ($bChunked)
		{
			$maxReadSize = 4096;

			$length = 0;
			$line = FGets($FP, $maxReadSize);
			$line = StrToLower($line);

			$strChunkSize = "";
			$i = 0;
			while ($i < StrLen($line) && in_array($line[$i], array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f")))
			{
				$strChunkSize .= $line[$i];
				$i++;
			}

			$chunkSize = hexdec($strChunkSize);

			while ($chunkSize > 0)
			{
				$processedSize = 0;
				$readSize = (($chunkSize > $maxReadSize) ? $maxReadSize : $chunkSize);

				while ($readSize > 0 && $line = fread($FP, $readSize))
				{
					$content .= $line;
					$processedSize += StrLen($line);
					$newSize = $chunkSize - $processedSize;
					$readSize = (($newSize > $maxReadSize) ? $maxReadSize : $newSize);
				}
				$length += $chunkSize;

				$line = FGets($FP, $maxReadSize);

				$line = FGets($FP, $maxReadSize);
				$line = StrToLower($line);

				$strChunkSize = "";
				$i = 0;
				while ($i < StrLen($line) && in_array($line[$i], array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f")))
				{
					$strChunkSize .= $line[$i];
					$i++;
				}

				$chunkSize = hexdec($strChunkSize);
			}
		}
		else
		{
			while ($line = fread($FP, 4096))
				$content .= $line;
		}

		fclose($FP);
	}
	else
	{
		$content = "";
		$strError .= GetMessage("SUPP_GHTTP_ER").": [".$errno."] ".$errstr.". ";
		if (intval($errno)<=0) $strError .= GetMessage("SUPP_GHTTP_ER_DEF")." ";

		CUpdateSystem::AddMessage2Log("Error connecting 2 ".$ServerIP.": [".$errno."] ".$errstr."", "ERRCONN");
	}
	return $content;
}