- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/update_class.php
- Класс: CUpdateSystem
- Вызов: CUpdateSystem::RegisterVersion
static function RegisterVersion(&$strError, $lang = false, $stableVersionsOnly = "Y")
{
$strError_tmp = "";
CUpdateSystem::AddMessage2Log("exec CUpdateSystem::RegisterVersion");
$stableVersionsOnly = (($stableVersionsOnly == "N") ? "N" : "Y");
if ($lang===false)
$lang = LANGUAGE_ID;
$GLOBALS["DB"]->GetVersion();
$strVars = "LICENSE_KEY=".urlencode(md5(CUpdateSystem::GetLicenseKey())).
"&CLIENT_SITE=".urlencode($_SERVER["SERVER_NAME"]).
"&CANGZIP=".urlencode((CUpdateSystem::IsGzipInstalled()) ? "Y" : "N").
"&UTYPES=".urlencode("R").
"&COUNT_ONLY=".urlencode("F").
"&VERSION=".urlencode(SM_VERSION).
"&SUPD_STS=".urlencode(CUpdateSystem::GetFooPath("GetList")).
"&SUPD_DBS=".urlencode($GLOBALS["DB"]->type).
"&XE=".urlencode((isset($GLOBALS["DB"]->XE) && $GLOBALS["DB"]->XE) ? "Y" : "N").
"&SUPD_VER=".urlencode(UPDATE_SYSTEM_VERSION).
"&CLIENT_PHPVER=".urlencode(phpversion()).
"&stable=".urlencode($stableVersionsOnly).
"&lang=".urlencode($lang);
CUpdateSystem::AddMessage2Log(preg_replace("/LICENSE_KEY=[^&]*/i", "LICENSE_KEY=X", $strVars));
$stime = CUpdateSystem::getmicrotime();
$fcontent = CUpdateSystem::getHTTPPage("bit_sysserver.php", $strVars, $strError_tmp);
CUpdateSystem::AddMessage2Log("TIME RegisterVersion.getHTTPPage ".Round(CUpdateSystem::getmicrotime()-$stime, 3)." sec");
if ($fcontent == '')
$strError_tmp .= "[URV01] ".GetMessage("SUPP_AS_EMPTY_RESP").".
";
if ($strError_tmp == '')
{
if (!($fp1 = fopen($_SERVER["DOCUMENT_ROOT"]."/bitrix/updates/update_archive.gz", "wb")))
$strError_tmp .= "[URV02] ".str_replace("#FILE#", $_SERVER["DOCUMENT_ROOT"]."/bitrix/updates", GetMessage("SUPP_RV_ER_TEMP_FILE")).".
";
}
if ($strError_tmp == '')
{
if (!fwrite($fp1, $fcontent))
$strError_tmp .= "[URV03] ".str_replace("#FILE#", $_SERVER["DOCUMENT_ROOT"]."/bitrix/updates/update_archive.gz", GetMessage("SUPP_RV_WRT_TEMP_FILE")).".
";
@fclose($fp1);
}
if ($strError_tmp == '')
{
$temporary_updates_dir = "";
if (!CUpdateSystem::UnGzipArchive($temporary_updates_dir, $strError_tmp, "Y"))
$strError_tmp .= "[URV04] ".GetMessage("SUPP_RV_BREAK").".
";
}
if ($strError_tmp == '')
{
$updates_dir_full = $_SERVER["DOCUMENT_ROOT"]."/bitrix/updates/".$temporary_updates_dir;
if (!file_exists($updates_dir_full."/update_info.xml") || !is_file($updates_dir_full."/update_info.xml"))
{
$strError_tmp .= "[URV05] ".str_replace("#FILE#", $updates_dir_full."/update_info.xml", GetMessage("SUPP_RV_ER_DESCR_FILE")).".
";
}
}
if ($strError_tmp == '')
{
if (!is_readable($updates_dir_full."/update_info.xml"))
$strError_tmp .= "[URV06] ".str_replace("#FILE#", $updates_dir_full."/update_info.xml", GetMessage("SUPP_RV_READ_DESCR_FILE")).".
";
}
if ($strError_tmp == '')
{
$content = file_get_contents($updates_dir_full."/update_info.xml");
}
if ($strError_tmp == '')
{
$arRes = Array();
CUpdateSystem::ParseServerData($content, $arRes, $strError_tmp);
}
if ($strError_tmp == '')
{
if (isset($arRes["DATA"]["#"]["ERROR"])
&& is_array($arRes["DATA"]["#"]["ERROR"])
&& !empty($arRes["DATA"]["#"]["ERROR"]))
{
for ($i = 0, $n = count($arRes["DATA"]["#"]["ERROR"]); $i < $n; $i++)
{
if ($arRes["DATA"]["#"]["ERROR"][$i]["@"]["TYPE"] <> '')
$strError_tmp .= "[".$arRes["DATA"]["#"]["ERROR"][$i]["@"]["TYPE"]."] ";
$strError_tmp .= $arRes["DATA"]["#"]["ERROR"][$i]["#"].".
";
}
}
}
if ($strError_tmp == '')
{
if (!file_exists($updates_dir_full."/include.php") || !is_file($updates_dir_full."/include.php"))
{
$strError_tmp .= "[URV07] ".GetMessage("SUPP_RV_NO_FILE").".
";
}
}
if ($strError_tmp == '')
{
$newfilesize = @filesize($updates_dir_full."/include.php");
if (intval($newfilesize)!=intval($arRes["DATA"]["#"]["FILE"][0]["@"]["SIZE"]))
{
$strError_tmp .= "[URV08] ".GetMessage("SUPP_RV_ER_SIZE").".
";
}
}
if ($strError_tmp == '')
{
if (!is_writeable($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include.php"))
{
$strError_tmp .= "[URV09] ".str_replace("#FILE#", $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include.php", GetMessage("SUPP_RV_NO_WRITE")).".
";
}
}
if ($strError_tmp == '')
{
if (!copy($updates_dir_full."/include.php", $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include.php"))
$strError_tmp .= "[URV10] ".GetMessage("SUPP_RV_ERR_COPY").".
";
@chmod($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include.php", BX_FILE_PERMISSIONS);
}
if ($strError_tmp == '')
{
$strongUpdateCheck = COption::GetOptionString("main", "strong_update_check", "Y");
if ($strongUpdateCheck == "Y")
{
$crc32_old = dechex(crc32(file_get_contents($updates_dir_full."/include.php")));
$crc32_new = dechex(crc32(file_get_contents($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include.php")));
if ($crc32_new != $crc32_old)
$strError_tmp .= "[URV1011] ".str_replace("#FILE#", $_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include.php", GetMessage("SUPP_UGA_FILE_CRUSH")).".
";
}
}
if ($strError_tmp == '')
{
CUpdateSystem::AddMessage2Log("Product registered successfully!", "CURV");
CUpdateSystem::DeleteDirFilesEx($updates_dir_full);
}
if ($strError_tmp <> '')
{
CUpdateSystem::AddMessage2Log($strError_tmp, "CURV");
$strError .= $strError_tmp;
return false;
}
else
return true;
}