Ejemplo n.º 1
0
	/**
	 * Update disk quota and cache statistic
	 * @param float $bytes positive or negative value
	 */
	public static function updateQuota($bytes)
	{
		if ($bytes == 0.0)
		{
			return;
		}

		if (class_exists("cdiskquota"))
		{
			CDiskQuota::updateDiskQuota("file", abs($bytes), $bytes > 0.0 ? "copy" : "delete");
		}

		CHTMLPagesCache::writeStatistic(0, 0, 0, 0, $bytes);
	}
Ejemplo n.º 2
0
 function writeFile($file_name, $content)
 {
     global $USER;
     if (is_object($USER) && $USER->IsAuthorized()) {
         return;
     }
     $content_len = function_exists('mb_strlen') ? mb_strlen($content, 'latin1') : strlen($content);
     if ($content_len <= 0) {
         return;
     }
     $arHTMLPagesOptions = CHTMLPagesCache::GetOptions(true);
     if (!is_array($arHTMLPagesOptions)) {
         return;
     }
     //Let's be pessimists
     $bQuota = false;
     if (class_exists("cdiskquota")) {
         $quota = new CDiskQuota();
         if ($quota->checkDiskQuota(array("FILE_SIZE" => $content_len))) {
             $bQuota = true;
         }
     } else {
         $bQuota = true;
     }
     $arStat = CHTMLPagesCache::readStatistic();
     if ($arStat) {
         $cached_size = $arStat["FILE_SIZE"];
     } else {
         $cached_size = 0.0;
     }
     $cache_quota = doubleval($arHTMLPagesOptions["~FILE_QUOTA"]);
     if ($bQuota && $cache_quota > 0.0) {
         if ($cache_quota < $cached_size + $content_len) {
             $bQuota = false;
         }
     }
     if ($bQuota) {
         CheckDirPath($file_name);
         $written = 0;
         $tmp_filename = $file_name . md5(mt_rand()) . ".tmp";
         $file = fopen($tmp_filename, "wb");
         if ($file !== false) {
             $written = fwrite($file, $content);
             if ($written == $content_len) {
                 fclose($file);
                 if (file_exists($file_name)) {
                     unlink($file_name);
                 }
                 rename($tmp_filename, $file_name);
                 @chmod($file_name, defined("BX_FILE_PERMISSIONS") ? BX_FILE_PERMISSIONS : 0664);
                 if (class_exists("cdiskquota")) {
                     CDiskQuota::updateDiskQuota("file", $content_len, "copy");
                 }
             } else {
                 $written = 0;
                 fclose($file);
                 if (file_exists($file_name)) {
                     unlink($file_name);
                 }
                 if (file_exists($tmp_filename)) {
                     unlink($tmp_filename);
                 }
             }
         }
         $arStat = CHTMLPagesCache::writeStatistic(0, 1, 0, 0, $written);
     } else {
         //Fire cleanup
         CHTMLPagesCache::CleanAll();
         CHTMLPagesCache::writeStatistic(0, 0, 1, 0, false);
     }
 }
Ejemplo n.º 3
0
             $_SESSION["CACHE_STAT"]["space_total"] += $file_size;
             if (@unlink($file)) {
                 $_SESSION["CACHE_STAT"]["deleted"]++;
                 $_SESSION["CACHE_STAT"]["space_freed"] += $file_size;
                 $space_freed += $file_size;
             } else {
                 $_SESSION["CACHE_STAT"]["errors"]++;
             }
             if (time() >= $endTime) {
                 break;
             }
         }
         //no more than 200 files per second
         usleep(5000);
     }
     CHTMLPagesCache::writeStatistic(0, 0, 0, 0, -$space_freed);
 } elseif (\Bitrix\Main\Data\Cache::getCacheEngineType() == "cacheenginefiles") {
     $obCacheCleaner->Start();
     while ($file = $obCacheCleaner->GetNextFile()) {
         if (is_string($file)) {
             $date_expire = $obCacheCleaner->GetFileExpiration($file);
             if ($date_expire) {
                 $file_size = filesize($file);
                 $_SESSION["CACHE_STAT"]["scanned"]++;
                 $_SESSION["CACHE_STAT"]["space_total"] += $file_size;
                 if ($bDoNotCheckExpiredDate || $date_expire < $curentTime) {
                     if (@unlink($file)) {
                         $_SESSION["CACHE_STAT"]["deleted"]++;
                         $_SESSION["CACHE_STAT"]["space_freed"] += $file_size;
                     } else {
                         $_SESSION["CACHE_STAT"]["errors"]++;
Ejemplo n.º 4
0
 /**
  * Writes a debug information in a log file
  */
 private function writeDebug()
 {
     if (!$this->debugEnabled || !defined("BX_COMPOSITE_DEBUG") || BX_COMPOSITE_DEBUG !== true || !$this->storage->exists()) {
         return;
     }
     if (!$this->storage->shouldCountQuota() || \CHTMLPagesCache::checkQuota()) {
         //temporary check
         if ($this->storage instanceof StaticHtmlFileStorage) {
             $cacheFile = $this->storage->getCacheFile();
             $backupName = $cacheFile->getPath() . ".delete." . microtime(true);
             AddMessage2Log($backupName, "composite");
             $backupFile = new Main\IO\File($backupName);
             $backupFile->putContents($cacheFile->getContents());
             \CHTMLPagesCache::writeStatistic(0, 0, 0, 0, $cacheFile->getSize());
         } else {
             AddMessage2Log($this->cacheKey . " was deleted", "composite");
         }
     } else {
         AddMessage2Log($this->cacheKey . "(quota exceeded)", "composite");
     }
 }
Ejemplo n.º 5
0
$APPLICATION->SetAdditionalCSS("/bitrix/panel/main/composite.css");
$APPLICATION->AddHeadString("<style type=\"text/css\">" . \Bitrix\Main\Page\Frame::getInjectedCSS() . "</style>");
$aTabs = array(array("DIV" => "edit1", "TAB" => GetMessage("MAIN_COMPOSITE_TAB"), "ICON" => "main_settings", "TITLE" => GetMessage("MAIN_COMPOSITE_TAB_TITLE")), array("DIV" => "edit2", "TAB" => GetMessage("MAIN_COMPOSITE_TAB_GROUPS"), "ICON" => "main_settings", "TITLE" => GetMessage("MAIN_COMPOSITE_TAB_GROUPS_TITLE")), array("DIV" => "edit3", "TAB" => GetMessage("MAIN_COMPOSITE_BANNER_SEP"), "ICON" => "main_banner", "TITLE" => GetMessage("MAIN_COMPOSITE_BANNER_SEP") . " &quot;" . GetMessage("COMPOSITE_BANNER_TEXT") . "&quot;"));
$tabControl = new CAdminTabControl("tabControl", $aTabs, true, true);
if ($_SERVER["REQUEST_METHOD"] == "POST" && check_bitrix_sessid() && $isAdmin && (isset($_REQUEST["composite_save_opt"]) && strlen($_REQUEST["composite_save_opt"]) > 0 || isset($_REQUEST["composite_siteb"]) && strlen($_REQUEST["composite_siteb"]) > 0)) {
    $arHTMLCacheOptions = CHTMLPagesCache::getOptions();
    $arHTMLCacheOptions["INCLUDE_MASK"] = $_REQUEST["composite_include_mask"];
    $arHTMLCacheOptions["EXCLUDE_MASK"] = $_REQUEST["composite_exclude_mask"];
    $arHTMLCacheOptions["NO_PARAMETERS"] = $_REQUEST["composite_no_parameters"];
    $arHTMLCacheOptions["ONLY_PARAMETERS"] = $_REQUEST["composite_only_parameters"];
    $arHTMLCacheOptions["FILE_QUOTA"] = $_REQUEST["composite_quota"];
    $arHTMLCacheOptions["BANNER_BGCOLOR"] = $_REQUEST["composite_banner_bgcolor"];
    $arHTMLCacheOptions["BANNER_STYLE"] = $_REQUEST["composite_banner_style"];
    $arHTMLCacheOptions["ALLOW_HTTPS"] = $_REQUEST["composite_allow_https"];
    if (isset($arHTMLCacheOptions["STORAGE"]) && isset($_REQUEST["composite_storage"]) && $arHTMLCacheOptions["STORAGE"] !== $_REQUEST["composite_storage"]) {
        CHTMLPagesCache::writeStatistic(false, false, false, false, false);
    }
    $storage = $_REQUEST["composite_storage"];
    if (($storage === "memcached" || $storage === "memcached_cluster") && extension_loaded("memcache")) {
        $arHTMLCacheOptions["MEMCACHED_HOST"] = $_REQUEST["composite_memcached_host"];
        $arHTMLCacheOptions["MEMCACHED_PORT"] = $_REQUEST["composite_memcached_port"];
        if (defined("BX_CLUSTER_GROUP")) {
            $arHTMLCacheOptions["MEMCACHED_CLUSTER_GROUP"] = BX_CLUSTER_GROUP;
        }
    } else {
        $storage = "files";
    }
    $arHTMLCacheOptions["STORAGE"] = $storage;
    if (isset($_REQUEST["group"]) && is_array($_REQUEST["group"])) {
        $arHTMLCacheOptions["GROUPS"] = array();
        $b = "";