static function __GetHTTPPage($page, $strVars, &$strError)
{
global $SERVER_NAME, $DB;
CUpdateClientPartner::AddMessage2Log("exec CUpdateClientPartner::GetHTTPPage");
$ServerIP = COption::GetOptionString("main", "update_site", DEFAULT_UPDATE_SERVER);
// $ServerIP = 'www.1c-bitrix.ru';
$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 ($page == "LIST")
$page = "smp_updater_list.php";
elseif ($page == "STEPM")
$page = "smp_updater_modules.php";
elseif ($page == "SEARCH")
$page = "smp_updater_search.php";
elseif ($page == "MODULE")
$page = "smp_updater_actions.php";
elseif ($page == "REG")
$page = "smp_updater_register.php";
elseif ($page == "ACTIV")
$page = "us_updater_actions.php";
elseif ($page == "SEARCH_NEW")
$page = "smp_updater_search_new.php";
$strVars .= "&product=".(IsModuleInstalled("intranet") ? "CORPORTAL" : "BSM")."&verfix=2";
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";
$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: ".mb_strlen($strVars)."rnrn";
$strRequest .= "$strVars";
$strRequest .= "rn";
//CUpdateClientPartner::AddMessage2Log($strRequest, "!!!!!");
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;
}
}
$content = "";
if ($bChunked)
{
$maxReadSize = 4096;
$length = 0;
$line = FGets($FP, $maxReadSize);
$line = mb_strtolower($line);
$strChunkSize = "";
$i = 0;
while ($i < mb_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 += mb_strlen($line);
$newSize = $chunkSize - $processedSize;
$readSize = (($newSize > $maxReadSize) ? $maxReadSize : $newSize);
}
$length += $chunkSize;
$line = FGets($FP, $maxReadSize);
$line = FGets($FP, $maxReadSize);
$line = mb_strtolower($line);
$strChunkSize = "";
$i = 0;
while ($i < mb_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")." ";
CUpdateClientPartner::AddMessage2Log("Error connecting 2 ".$ServerIP.": [".$errno."] ".$errstr."", "ERRCONN");
}
//CUpdateClientPartner::AddMessage2Log($content, "!1!");
//echo "content:
".$content."
";
return $content;
}