Пример #1
0
 function CheckKernel($arParams)
 {
     $time_start = time();
     global $DB;
     $arCompare = array("install/components/bitrix/" => "/bitrix/components/bitrix/", "install/js/" => "/bitrix/js/", "install/activities/" => "/bitrix/activities/", "install/admin/" => "/bitrix/admin/", "install/wizards/" => "/bitrix/wizards/");
     if (!$_SESSION["BX_CHECKLIST"][$arParams["TEST_ID"]]) {
         $_SESSION["BX_CHECKLIST"][$arParams["TEST_ID"]] = array();
     }
     $NS =& $_SESSION["BX_CHECKLIST"][$arParams["TEST_ID"]];
     if ($arParams["STEP"] == false) {
         $NS = array();
         $rsInstalledModules = CModule::GetList();
         while ($ar = $rsInstalledModules->Fetch()) {
             if (!strpos($ar["ID"], ".")) {
                 $NS["MLIST"][] = $ar["ID"];
             }
         }
         $NS["MNUM"] = 0;
         $NS["FILE_LIST"] = array();
         $NS["FILES_COUNT"] = 0;
         $NS["MODFILES_COUNT"] = 0;
     }
     $arError = false;
     $module_id = $NS["MLIST"][$NS["MNUM"]];
     $module_folder = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/" . $module_id . "/";
     $dbtype = strtolower($DB->type);
     if ($module_id == "main") {
         $ver = SM_VERSION;
     } else {
         $arModuleVersion = array();
         @(include $module_folder . "install/version.php");
         $ver = $arModuleVersion["VERSION"];
     }
     $arFilesCount = 0;
     $arModifiedFilesCount = 0;
     $state = array();
     $Skip = false;
     if (!$ver) {
         $state = array("STATUS" => false, "MESSAGE" => GetMessage("CL_MODULE_VERSION_ERROR", array("#module_id#" => $module_id)) . "\n");
         $arError = true;
     } else {
         if (count($NS["FILE_LIST"]) == 0) {
             $sHost = COption::GetOptionString("main", "update_site", "www.bitrixsoft.com");
             $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", "");
             $http = new \Bitrix\Main\Web\HttpClient();
             $http->setProxy($proxyAddr, $proxyPort, $proxyUserName, $proxyPassword);
             $data = $http->get("http://" . $sHost . "/bitrix/updates/checksum.php?check_sum=Y&module_id=" . $module_id . "&ver=" . $ver . "&dbtype=" . $dbtype . "&mode=2");
             $NS["FILE_LIST"] = $result = unserialize(gzinflate($data));
             $NS["MODULE_FILES_COUNT"] = count($NS["FILE_LIST"]);
         } else {
             $result = $NS["FILE_LIST"];
         }
         $arMessage = "";
         $timeout = COption::GetOptionString("main", "update_load_timeout", "30");
         if (is_array($result) && !$result["error"]) {
             foreach ($result as $file => $checksum) {
                 $arFile = $module_folder . $file;
                 unset($NS["FILE_LIST"][$file]);
                 if (!file_exists($arFile)) {
                     continue;
                 }
                 $arFilesCount++;
                 if (md5_file($arFile) != $checksum) {
                     $arMessage .= str_replace(array("//", "\\\\"), array("/", "\\"), $arFile) . "\n";
                     $arModifiedFilesCount++;
                 }
                 $arTmpCompare = $arCompare;
                 foreach ($arTmpCompare as $key => $value) {
                     if (strpos($file, $key) === 0) {
                         $arFile = str_replace($key, $_SERVER["DOCUMENT_ROOT"] . $value, $file);
                         if (!file_exists($arFile) || md5_file($arFile) != $checksum) {
                             $arModifiedFilesCount++;
                             $arMessage .= str_replace(array("//", "\\\\"), array("/", "\\"), $arFile) . "\n";
                         }
                         $arFilesCount++;
                     }
                 }
                 if (time() - $time_start >= $timeout) {
                     break;
                 }
             }
             if (strlen($arMessage) > 0) {
                 $state = array("MESSAGE" => $arMessage, "STATUS" => false);
             }
         } else {
             if ($result["error"] != "unknow module id") {
                 $state["MESSAGE"] = GetMessage("CL_CANT_CHECK", array("#module_id#" => $module_id)) . "\n";
                 $arError = true;
             } else {
                 $Skip = true;
             }
         }
     }
     if ($state["MESSAGE"]) {
         $NS["MESSAGE"][$module_id] .= $state["MESSAGE"];
     }
     if (!$arError && !$Skip) {
         if (count($NS["FILE_LIST"]) == 0) {
             if (strlen($NS["MESSAGE"][$module_id]) == 0) {
                 $NS["MESSAGE"][$module_id] = GetMessage("CL_NOT_MODIFIED", array("#module_id#" => $module_id)) . "\n";
             } else {
                 $NS["MESSAGE"][$module_id] = GetMessage("CL_MODIFIED_FILES", array("#module_id#" => $module_id)) . "\n" . $NS["MESSAGE"][$module_id];
             }
         }
         $NS["FILES_COUNT"] += $arFilesCount;
         $NS["MODFILES_COUNT"] += $arModifiedFilesCount;
     }
     if ($state["STATUS"] === false || $arError == true || $Skip) {
         if ($state["STATUS"] === false || $arError == true) {
             $NS["STATUS"] = false;
         }
         $NS["FILE_LIST"] = array();
         $NS["MODULE_FILES_COUNT"] = 0;
     }
     if ($NS["MNUM"] + 1 >= count($NS["MLIST"]) && !$NS["LAST_FILE"]) {
         $arDetailReport = "";
         foreach ($NS["MESSAGE"] as $module_message) {
             $arDetailReport .= "<div class=\"checklist-dot-line\"></div>" . $module_message;
         }
         $arResult = array("MESSAGE" => array("PREVIEW" => GetMessage("CL_KERNEL_CHECK_FILES") . $NS["FILES_COUNT"] . "\n" . GetMessage("CL_KERNEL_CHECK_MODULE") . count($NS["MLIST"]) . "\n" . GetMessage("CL_KERNEL_CHECK_MODIFIED") . $NS["MODFILES_COUNT"], "DETAIL" => $arDetailReport), "STATUS" => $NS["STATUS"] === false ? false : true);
     } else {
         $percent = round($NS["MNUM"] / (count($NS["MLIST"]) * 0.01), 0);
         $module_percent = 0;
         if ($NS["MODULE_FILES_COUNT"] > 0) {
             $module_percent = 1 / (count($NS["MLIST"]) * 0.01) * (($NS["MODULE_FILES_COUNT"] - count($NS["FILE_LIST"])) / ($NS["MODULE_FILES_COUNT"] * 0.01) * 0.01);
         }
         $percent += $module_percent;
         $arResult = array("IN_PROGRESS" => "Y", "PERCENT" => number_format($percent, 2));
         if (count($NS["FILE_LIST"]) == 0) {
             $NS["MNUM"]++;
             $NS["MODULE_FILES_COUNT"] = 0;
         }
     }
     return $arResult;
 }