فهرست منبع

#4745 S3 storage: option to force auth URLs

Alex Trofimov 2 سال پیش
والد
کامیت
51170b4a54

+ 12 - 0
inc/classes/BxDolStorage.php

@@ -1306,6 +1306,18 @@ abstract class BxDolStorage extends BxDolFactory implements iBxDolFactoryObject
         }
         return '';
     }
+
+    protected function isAuthUrl ($aFile)
+    {
+        $s = trim(getParam('sys_storage_s3_force_auth_urls'));
+        if ('*' == $s) 
+            return true;
+
+        if ($s && ($aStorages = explode(',', $s)))
+            return in_array($this->getObject(), $aStorages);
+
+        return $aFile['private'];
+    }
 }
 
 

+ 1 - 1
inc/classes/BxDolStorageS3.php

@@ -65,7 +65,7 @@ class BxDolStorageS3 extends BxDolStorage
         if (!$aFile)
             return false;
 
-        if ($aFile['private']) {
+        if ($this->isAuthUrl($aFile)) {
             $sFileLocation = $this->getObjectBaseDir($aFile['private']) . $aFile['path'];
 
             if ($this->_sDomain)

+ 3 - 3
inc/classes/BxDolStorageS3v4alt.php

@@ -64,11 +64,11 @@ class BxDolStorageS3v4alt extends BxDolStorageS3
         $aFile = $this->_oDb->getFileById($iFileId);
         if (!$aFile)
             return false;
-
-        if ($aFile['private']) {
+    
+        if ($this->isAuthUrl($aFile)) {
             $sFileLocation = $this->getObjectBaseDir($aFile['private']) . $aFile['path'];
             $sRet = $this->_s3->getAuthenticatedURL($this->_sBucket, $sFileLocation, $this->_aObject['token_life'], $this->_bSSL);
-        } 
+        }
         else {
             $sRet = $this->getObjectBaseUrl($aFile['private']) . $aFile['path'];
         }

+ 2 - 1
install/sql/system.sql

@@ -610,7 +610,8 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_storage_s3_sig_ver', '_adm_stg_cpt_option_sys_storage_s3_sig_ver', 'v2', 'select', 'v2,v4', '', '', 7),
 (@iCategoryId, 'sys_storage_s3_region', '_adm_stg_cpt_option_sys_storage_s3_region', '', 'digit', '', '', '', 8),
 (@iCategoryId, 'sys_storage_s3_amz_iam_role', '_adm_stg_cpt_option_sys_storage_s3_amz_iam_role', '', 'checkbox', '', '', '', 10),
-(@iCategoryId, 'sys_storage_s3_acl_enable', '_adm_stg_cpt_option_sys_storage_s3_acl_enable', 'on', 'checkbox', '', '', '', 12);
+(@iCategoryId, 'sys_storage_s3_acl_enable', '_adm_stg_cpt_option_sys_storage_s3_acl_enable', 'on', 'checkbox', '', '', '', 12),
+(@iCategoryId, 'sys_storage_s3_force_auth_urls', '_adm_stg_cpt_option_sys_storage_s3_force_auth_urls', '', 'digit', '', '', '', 14);
 --
 -- CATEGORY: Account
 --

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1692,6 +1692,7 @@
 	<string name="_adm_stg_cpt_option_sys_storage_s3_region"><![CDATA[Region (for signature v4 only)]]></string>
     <string name="_adm_stg_cpt_option_sys_storage_s3_amz_iam_role"><![CDATA[Authenticate using Amazon  IAM Role (S3v4alt storage only)]]></string>
     <string name="_adm_stg_cpt_option_sys_storage_s3_acl_enable"><![CDATA[Enable ACLs (S3v4alt storage only)]]></string>
+    <string name="_adm_stg_cpt_option_sys_storage_s3_force_auth_urls"><![CDATA[Force authenticated URLs for specific storages]]></string>
 
     <string name="_adm_stg_cpt_option_sys_template_cache_image_enable"><![CDATA[Enable cache for images]]></string>
     <string name="_adm_stg_cpt_option_sys_template_cache_image_max_size"><![CDATA[Cached image max size (in Kb)]]></string>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1667,6 +1667,7 @@
 	<string name="_adm_stg_cpt_option_sys_storage_s3_region"><![CDATA[Регион (только для подписи v4)]]></string>
     <string name="_adm_stg_cpt_option_sys_storage_s3_amz_iam_role"><![CDATA[Аутентификация с использованием Amazon IAM Role (только для S3v4alt)]]></string>
     <string name="_adm_stg_cpt_option_sys_storage_s3_acl_enable"><![CDATA[Включить ACLs (только для S3v4alt)]]></string>
+    <string name="_adm_stg_cpt_option_sys_storage_s3_force_auth_urls"><![CDATA[Применять аутентифицированные URL-адреса для определенных хранилищ]]></string>
 
     <string name="_adm_stg_cpt_option_sys_template_cache_image_enable"><![CDATA[Задействовать кэш для изображений]]></string>
     <string name="_adm_stg_cpt_option_sys_template_cache_image_max_size"><![CDATA[Максимальный размер кэшируемого изображения (в Кб)]]></string>