Esempio n. 1
0
 /**
  *
  * @param string &$content
  * @return void
  *
  */
 public function OnEndBufferContent(&$content)
 {
     if (isset($_GET["nocdn"])) {
         return;
     }
     self::$proto = CMain::IsHTTPS() ? "https" : "http";
     self::$config = CBitrixCloudCDNConfig::getInstance()->loadFromOptions();
     if (self::$config->isExpired()) {
         if (self::$config->lock()) {
             try {
                 try {
                     $delayExpiration = true;
                     self::$config = CBitrixCloudCDNConfig::getInstance()->loadRemoteXML();
                     self::$config->saveToOptions();
                     self::$config->unlock();
                 } catch (CBitrixCloudException $e) {
                     //In case of documented XML error we'll disable CDN
                     if ($e->getErrorCode() !== "") {
                         self::SetActive(false);
                         $delayExpiration = false;
                     }
                     throw $e;
                 }
             } catch (exception $e) {
                 if ($delayExpiration) {
                     self::$config->setExpired(time() + 1800);
                 }
                 CAdminNotify::Add(array("MESSAGE" => GetMessage("BCL_CDN_NOTIFY", array("#HREF#" => "/bitrix/admin/bitrixcloud_cdn.php?lang=" . LANGUAGE_ID)), "TAG" => "bitrixcloud_off", "MODULE_ID" => "bitrixcloud", "ENABLE_CLOSE" => "Y"));
                 self::$config->unlock();
                 return;
             }
         }
     }
     if (!self::$config->isActive()) {
         return false;
     }
     $sites = self::$config->getSites();
     if (defined("ADMIN_SECTION")) {
         if (!isset($sites["admin"])) {
             return;
         }
     } elseif (defined("SITE_ID")) {
         if (!isset($sites[SITE_ID])) {
             return;
         }
     } else {
         return;
     }
     self::$ajax = preg_match("/<head>/i", substr($content, 0, 512)) === 0;
     $arPrefixes = array_map(array("CBitrixCloudCDN", "_preg_quote"), self::$config->getLocationsPrefixes());
     $arExtensions = array_map(array("CBitrixCloudCDN", "_preg_quote"), self::$config->getLocationsExtensions());
     if (!empty($arPrefixes) && !empty($arExtensions)) {
         $prefix_regex = "(?:" . implode("|", $arPrefixes) . ")";
         $extension_regex = "(?:" . implode("|", $arExtensions) . ")";
         $regex = "/\n\t\t\t\t((?i:\n\t\t\t\t\thref=\n\t\t\t\t\t|src=\n\t\t\t\t\t|BX\\.loadCSS\\(\n\t\t\t\t\t|BX\\.loadScript\\(\n\t\t\t\t\t|jsUtils\\.loadJSFile\\(\n\t\t\t\t\t|background\\s*:\\s*url\\(\n\t\t\t\t))                                                   #attribute\n\t\t\t\t(\"|')                                               #open_quote\n\t\t\t\t(" . $prefix_regex . ")                                  #prefix\n\t\t\t\t([^?'\"]+\\.)                                        #href body\n\t\t\t\t(" . $extension_regex . ")                               #extension\n\t\t\t\t(|\\?\\d+|\\?v=\\d+)                                 #params\n\t\t\t\t(\\2)                                                #close_quote\n\t\t\t/x";
         $content = preg_replace_callback($regex, array("CBitrixCloudCDN", "_filter"), $content);
     }
 }
Esempio n. 2
0
 /**
  *
  * @return bool
  *
  */
 private static function updateConfig()
 {
     if (!self::$config->lock()) {
         return true;
     }
     $delayExpiration = true;
     try {
         try {
             self::$config = CBitrixCloudCDNConfig::getInstance()->loadRemoteXML();
             self::$config->saveToOptions();
             self::$config->unlock();
         } catch (CBitrixCloudException $e) {
             //In case of documented XML error we'll disable CDN
             if ($e->getErrorCode() !== "") {
                 self::SetActive(false);
                 $delayExpiration = false;
             }
             throw $e;
         }
     } catch (exception $e) {
         if ($delayExpiration) {
             self::$config->setExpired(time() + 1800);
         }
         CAdminNotify::Add(array("MESSAGE" => GetMessage("BCL_CDN_NOTIFY", array("#HREF#" => "/bitrix/admin/bitrixcloud_cdn.php?lang=" . LANGUAGE_ID)), "TAG" => "bitrixcloud_off", "MODULE_ID" => "bitrixcloud", "ENABLE_CLOSE" => "Y"));
         self::$config->unlock();
         return false;
     }
     self::$config->unlock();
     //Web service were disabled
     if (!self::$config->isActive()) {
         //By traffic quota
         if (self::$config->getQuota()->getTrafficSize() > self::$config->getQuota()->getAllowedSize()) {
             self::$config->setExpired(time() + 1800);
             CAdminNotify::Add(array("MESSAGE" => GetMessage("BCL_CDN_NOTIFY_QUOTA_LIMIT"), "TAG" => "bitrixcloud_off", "MODULE_ID" => "bitrixcloud", "ENABLE_CLOSE" => "N"));
             self::$config->unlock();
             return false;
         } elseif (self::$config->getQuota()->isExpired()) {
             self::$config->setExpired(time() + 1800);
             CAdminNotify::Add(array("MESSAGE" => GetMessage("BCL_CDN_NOTIFY_QUOTA_EXPIRED"), "TAG" => "bitrixcloud_off", "MODULE_ID" => "bitrixcloud", "ENABLE_CLOSE" => "N"));
             self::$config->unlock();
             return false;
         }
     }
     CAdminNotify::DeleteByTag("bitrixcloud_off");
     return true;
 }