1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
storage_service_hotbox.php
См. документацию.
1<?php
3
5{
6 protected $set_headers = /*.(array[string]string).*/[];
7 protected $new_end_point = '';
8 protected $_public = true;
9 protected $location = '';
10
14 public function GetObject()
15 {
16 return new CCloudStorageService_HotBox();
17 }
18
22 public function GetID()
23 {
24 return 'hot_box';
25 }
26
30 public function GetName()
31 {
32 return 'HotBox';
33 }
34
38 public function GetLocationList()
39 {
40 return [
41 'ru-msk' => 'ru',
42 'kz-ast' => 'kz',
43 ];
44 }
45
53 public function GetSettingsHTML($arBucket, $bServiceSet, $cur_SERVICE_ID, $bVarsFromForm)
54 {
56 {
57 $arSettings = $_POST['SETTINGS'][$this->GetID()];
58 }
59 else
60 {
61 $arSettings = unserialize($arBucket['SETTINGS'], ['allowed_classes' => false]);
62 }
63
64 if (!is_array($arSettings))
65 {
66 $arSettings = ['ACCESS_KEY' => '', 'SECRET_KEY' => ''];
67 }
68
69 $htmlID = htmlspecialcharsbx($this->GetID());
70
71 $result = '
72 <tr id="SETTINGS_0_' . $htmlID . '" style="display:' . ($cur_SERVICE_ID === $this->GetID() || !$bServiceSet ? '' : 'none') . '" class="settings-tr adm-detail-required-field">
73 <td>' . GetMessage('CLO_STORAGE_HOTBOX_EDIT_ACCESS_KEY') . ':</td>
74 <td><input type="hidden" name="SETTINGS[' . $htmlID . '][ACCESS_KEY]" id="' . $htmlID . 'ACCESS_KEY" value="' . htmlspecialcharsbx($arSettings['ACCESS_KEY']) . '"><input type="text" size="55" name="' . $htmlID . 'INP_ACCESS_KEY" id="' . $htmlID . 'INP_ACCESS_KEY" value="' . htmlspecialcharsbx($arSettings['ACCESS_KEY']) . '" ' . ($arBucket['READ_ONLY'] === 'Y' ? '"disabled"' : '') . ' onchange="BX(\'' . $htmlID . 'ACCESS_KEY\').value = this.value"></td>
75 </tr>
76 <tr id="SETTINGS_1_' . $htmlID . '" style="display:' . ($cur_SERVICE_ID === $this->GetID() || !$bServiceSet ? '' : 'none') . '" class="settings-tr adm-detail-required-field">
77 <td>' . GetMessage('CLO_STORAGE_HOTBOX_EDIT_SECRET_KEY') . ':</td>
78 <td><input type="hidden" name="SETTINGS[' . $htmlID . '][SECRET_KEY]" id="' . $htmlID . 'SECRET_KEY" value="' . htmlspecialcharsbx($arSettings['SECRET_KEY']) . '"><input type="text" size="55" name="' . $htmlID . 'INP_SECRET_KEY" id="' . $htmlID . 'INP_SECRET_KEY" value="' . htmlspecialcharsbx($arSettings['SECRET_KEY']) . '" autocomplete="off" ' . ($arBucket['READ_ONLY'] === 'Y' ? '"disabled"' : '') . ' onchange="BX(\'' . $htmlID . 'SECRET_KEY\').value = this.value"></td>
79 </tr>
80 ';
81 return $result;
82 }
83
89 public function CheckSettings($arBucket, &$arSettings)
90 {
91 global $APPLICATION;
92 $aMsg = /*.(array[int][string]string).*/[];
93
94 $result = [
95 'ACCESS_KEY' => is_array($arSettings) ? trim($arSettings['ACCESS_KEY']) : '',
96 'SECRET_KEY' => is_array($arSettings) ? trim($arSettings['SECRET_KEY']) : '',
97 ];
98 if (is_array($arSettings) && array_key_exists('SESSION_TOKEN', $arSettings))
99 {
100 $result['SESSION_TOKEN'] = trim($arSettings['SESSION_TOKEN']);
101 }
102
103 if ($arBucket['READ_ONLY'] !== 'Y' && $result['ACCESS_KEY'] === '')
104 {
105 $aMsg[] = [
106 'id' => $this->GetID() . 'INP_ACCESS_KEY',
107 'text' => GetMessage('CLO_STORAGE_HOTBOX_EMPTY_ACCESS_KEY'),
108 ];
109 }
110
111 if ($arBucket['READ_ONLY'] !== 'Y' && $result['SECRET_KEY'] === '')
112 {
113 $aMsg[] = [
114 'id' => $this->GetID() . 'INP_SECRET_KEY',
115 'text' => GetMessage('CLO_STORAGE_HOTBOX_EMPTY_SECRET_KEY'),
116 ];
117 }
118
119 if (!empty($aMsg))
120 {
121 $e = new CAdminException($aMsg);
122 $APPLICATION->ThrowException($e);
123 return false;
124 }
125 else
126 {
127 $arSettings = $result;
128 }
129
130 return true;
131 }
132
137 protected function GetRequestHost($bucket, $arSettings)
138 {
139 if (
140 $this->new_end_point !== ''
141 && preg_match('#^(http|https)://' . preg_quote($bucket, '#') . '(.+?)/#', $this->new_end_point, $match) > 0
142 )
143 {
144 return $bucket . $match[2];
145 }
146 elseif ($this->location && $this->location !== 'ru-msk')
147 {
148 if ($bucket !== '')
149 {
150 return $bucket . '.hb.' . $this->location . '.bizmrg.com';
151 }
152 else
153 {
154 return 'hb.' . $this->location . '.bizmrg.com';
155 }
156 }
157 else
158 {
159 if ($bucket !== '')
160 {
161 return $bucket . '.hb.bizmrg.com';
162 }
163 else
164 {
165 return 'hb.bizmrg.com';
166 }
167 }
168 }
169
176 public function GetFileSRC($arBucket, $arFile, $encoded = true)
177 {
178 /* @var \Bitrix\Main\HttpRequest $request */
179 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
180 $proto = $request->isHttps() ? 'https' : 'http';
181
182 if ($arBucket['CNAME'] != '')
183 {
184 $host = $arBucket['CNAME'];
185 $pref = '';
186 }
187 elseif ($proto === 'https' && mb_strpos($arBucket['BUCKET'], '.') !== false)
188 {
189 $host = 'hb.bizmrg.com';
190 $pref = $arBucket['BUCKET'];
191 }
192 else
193 {
194 $host = $arBucket['BUCKET'] . '.hb.bizmrg.com';
195 $pref = '';
196 }
197
198 if (is_array($arFile))
199 {
200 $URI = ltrim($arFile['SUBDIR'] . '/' . $arFile['FILE_NAME'], '/');
201 }
202 else
203 {
204 $URI = ltrim($arFile, '/');
205 }
206
207 if ($arBucket['PREFIX'] != '')
208 {
209 if (mb_substr($URI, 0, mb_strlen($arBucket['PREFIX']) + 1) !== $arBucket['PREFIX'] . '/')
210 {
211 $URI = $arBucket['PREFIX'] . '/' . $URI;
212 }
213 }
214
215 if ($pref !== '')
216 {
217 $URI = $pref . '/' . $URI;
218 }
219
220 if ($encoded)
221 {
222 return $proto . '://' . $host . '/' . CCloudUtil::URLEncode($URI, 'UTF-8', true);
223 }
224 else
225 {
226 return $proto . '://' . $host . '/' . $URI;
227 }
228 }
229
234 public function DeleteBucket($arBucket)
235 {
236 //Do not delete bucket if there is some files left
237 if (!$this->IsEmptyBucket($arBucket))
238 {
239 return false;
240 }
241
242 return parent::DeleteBucket($arBucket);
243 }
244
251 {
252 if ($status == 400 && mb_strpos($result, 'ExpiredToken') !== false)
253 {
254 return true;
255 }
256 if ($status == 400 && mb_strpos($result, 'token is malformed') !== false)
257 {
258 return true;
259 }
260 if ($status == 403 && mb_strpos($result, 'The AWS Access Key Id you provided does not exist in our records.') !== false)
261 {
262 return true;
263 }
264 return false;
265 }
266}
global $APPLICATION
Определения include.php:80
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
GetRequestHost($bucket, $arSettings)
Определения storage_service_hotbox.php:137
checkForTokenExpiration($status, $result)
Определения storage_service_hotbox.php:250
GetFileSRC($arBucket, $arFile, $encoded=true)
Определения storage_service_hotbox.php:176
CheckSettings($arBucket, &$arSettings)
Определения storage_service_hotbox.php:89
GetSettingsHTML($arBucket, $bServiceSet, $cur_SERVICE_ID, $bVarsFromForm)
Определения storage_service_hotbox.php:53
IsEmptyBucket($arBucket)
Определения storage_service_s3.php:641
static URLEncode($str, $charset, $file_name=false)
Определения util.php:10
$bVarsFromForm
Определения file_edit.php:44
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393