1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
storage_service_amazon.php
См. документацию.
1<?php
3
5{
9 public function GetObject()
10 {
12 }
13
17 public function GetID()
18 {
19 return 'amazon_s3';
20 }
21
25 public function GetName()
26 {
27 return 'Amazon Simple Storage Service';
28 }
29
33 public function GetLocationList()
34 {
35 // http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
36 return [
37 '' => 'US Standard',
38 'us-east-2' => 'US East (Ohio)',
39 'us-east-1' => 'US East (N. Virginia)',
40 'us-west-1' => 'US West (N. California)',
41 'us-west-2' => 'US West (Oregon)',
42 'af-south-1' => 'Africa (Cape Town)',
43 'ap-east-1' => 'Asia Pacific (Hong Kong)',
44 'ap-south-2' => 'Asia Pacific (Hyderabad)',
45 'ap-southeast-3' => 'Asia Pacific (Jakarta)',
46 'ap-southeast-4' => 'Asia Pacific (Melbourne)',
47 'ap-south-1' => 'Asia Pacific (Mumbai)',
48 'ap-northeast-3' => 'Asia Pacific (Osaka-Local)',
49 'ap-northeast-2' => 'Asia Pacific (Seoul)',
50 'ap-southeast-1' => 'Asia Pacific (Singapore)',
51 'ap-southeast-2' => 'Asia Pacific (Sydney)',
52 'ap-northeast-1' => 'Asia Pacific (Tokyo)',
53 'ca-central-1' => 'Canada (Central)',
54 'ca-west-1' => 'Canada West (Calgary)',
55 'eu-central-1' => 'Europe (Frankfurt)',
56 'eu-west-1' => 'Europe (Ireland)',
57 'eu-west-2' => 'Europe (London)',
58 'eu-south-1' => 'Europe (Milan)',
59 'eu-west-3' => 'Europe (Paris)',
60 'eu-south-2' => 'Europe (Spain)',
61 'eu-north-1' => 'Europe (Stockholm)',
62 'eu-central-2' => 'Europe (Zurich)',
63 'il-central-1' => 'Israel (Tel Aviv)',
64 'me-south-1' => 'Middle East (Bahrain)',
65 'me-central-1' => 'Middle East (UAE)',
66 'sa-east-1' => 'South America (Sao Paulo)',
67 'us-gov-east-1' => 'AWS GovCloud (US-East)',
68 'us-gov-west-1' => 'AWS GovCloud (US-West)',
69 ];
70 }
71
75 public function GetAPList()
76 {
77 // https://docs.aws.amazon.com/general/latest/gr/s3.html
78 return [
79 '' => 's3.amazonaws.com',
80 'us-east-2' => 's3.us-east-2.amazonaws.com',
81 'us-east-1' => 's3.us-east-1.amazonaws.com',
82 'us-west-1' => 's3.us-west-1.amazonaws.com',
83 'us-west-2' => 's3.us-west-2.amazonaws.com',
84 'af-south-1' => 's3.af-south-1.amazonaws.com',
85 'ap-east-1' => 's3.ap-east-1.amazonaws.com',
86 'ap-south-2' => 's3.ap-south-2.amazonaws.com',
87 'ap-southeast-3' => 's3.ap-southeast-3.amazonaws.com',
88 'ap-southeast-4' => 's3.ap-southeast-4.amazonaws.com',
89 'ap-south-1' => 's3.ap-south-1.amazonaws.com',
90 'ap-northeast-3' => 's3.ap-northeast-3.amazonaws.com',
91 'ap-northeast-2' => 's3.ap-northeast-2.amazonaws.com',
92 'ap-southeast-1' => 's3.ap-southeast-1.amazonaws.com',
93 'ap-southeast-2' => 's3.ap-southeast-2.amazonaws.com',
94 'ap-northeast-1' => 's3.ap-northeast-1.amazonaws.com',
95 'ca-central-1' => 's3.ca-central-1.amazonaws.com',
96 'ca-west-1' => 's3.ca-west-1.amazonaws.com',
97 'eu-central-1' => 's3.eu-central-1.amazonaws.com',
98 'eu-west-1' => 's3.eu-west-1.amazonaws.com',
99 'eu-west-2' => 's3.eu-west-2.amazonaws.com',
100 'eu-south-1' => 's3.eu-south-1.amazonaws.com',
101 'eu-west-3' => 's3.eu-west-3.amazonaws.com',
102 'eu-south-2' => 's3.eu-south-2.amazonaws.com',
103 'eu-north-1' => 's3.eu-north-1.amazonaws.com',
104 'eu-central-2' => 's3.eu-central-2.amazonaws.com',
105 'il-central-1' => 's3.il-central-1.amazonaws.com',
106 'me-south-1' => 's3.me-south-1.amazonaws.com',
107 'me-central-1' => 's3.me-central-1.amazonaws.com',
108 'sa-east-1' => 's3.sa-east-1.amazonaws.com',
109 'us-gov-east-1' => 's3.us-gov-east-1.amazonaws.com',
110 'us-gov-west-1' => 's3.us-gov-west-1.amazonaws.com',
111 ];
112 }
113
121 public function GetSettingsHTML($arBucket, $bServiceSet, $cur_SERVICE_ID, $bVarsFromForm)
122 {
123 if ($bVarsFromForm)
124 {
125 $arSettings = $_POST['SETTINGS'][$this->GetID()];
126 }
127 else
128 {
129 $arSettings = unserialize($arBucket['SETTINGS'], ['allowed_classes' => false]);
130 }
131
132 if (!is_array($arSettings))
133 {
134 $arSettings = ['ACCESS_KEY' => '', 'SECRET_KEY' => ''];
135 }
136
137 $htmlID = htmlspecialcharsbx($this->GetID());
138 $show = (($cur_SERVICE_ID === $this->GetID()) || !$bServiceSet) ? '' : 'none';
139 $useHttps = $arSettings['USE_HTTPS'] ?? 'N';
140
141 $result = '
142 <tr id="SETTINGS_0_' . $htmlID . '" style="display:' . $show . '" class="settings-tr adm-detail-required-field">
143 <td>' . GetMessage('CLO_STORAGE_AMAZON_EDIT_ACCESS_KEY') . ':</td>
144 <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>
145 </tr>
146 <tr id="SETTINGS_1_' . $htmlID . '" style="display:' . $show . '" class="settings-tr adm-detail-required-field">
147 <td>' . GetMessage('CLO_STORAGE_AMAZON_EDIT_SECRET_KEY') . ':</td>
148 <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">' . (
149 array_key_exists('SESSION_TOKEN', $arSettings) ?
150 '<input type="hidden" name="SETTINGS[' . $htmlID . '][SESSION_TOKEN]" id="' . $htmlID . 'SESSION_TOKEN" value="' . htmlspecialcharsbx($arSettings['SESSION_TOKEN']) . '">' :
151 ''
152 ) . '</td>
153 </tr>
154 <tr id="SETTINGS_3_' . $htmlID . '" style="display:' . $show . '" class="settings-tr">
155 <td nowrap>' . GetMessage('CLO_STORAGE_AMAZON_EDIT_USE_HTTPS') . ':</td>
156 <td><input type="hidden" name="SETTINGS[' . $htmlID . '][USE_HTTPS]" id="' . $htmlID . 'KEY" value="N"><input type="checkbox" name="SETTINGS[' . $htmlID . '][USE_HTTPS]" id="' . $htmlID . 'USE_HTTPS" value="Y" ' . ($useHttps == 'Y' ? 'checked="checked"' : '') . '></td>
157 </tr><tr id="SETTINGS_2_' . $htmlID . '" style="display:' . $show . '" class="settings-tr">
158 <td>&nbsp;</td>
159 <td>' . BeginNote() . GetMessage('CLO_STORAGE_AMAZON_EDIT_HELP') . EndNote() . '</td>
160 </tr>
161 ';
162
163 return $result;
164 }
165
171 public function CheckSettings($arBucket, &$arSettings)
172 {
173 global $APPLICATION;
174 $aMsg = /*.(array[int][string]string).*/[];
175
176 $result = [
177 'ACCESS_KEY' => is_array($arSettings) ? trim($arSettings['ACCESS_KEY']) : '',
178 'SECRET_KEY' => is_array($arSettings) ? trim($arSettings['SECRET_KEY']) : '',
179 ];
180 if (is_array($arSettings) && array_key_exists('SESSION_TOKEN', $arSettings))
181 {
182 $result['SESSION_TOKEN'] = trim($arSettings['SESSION_TOKEN']);
183 }
184
185 if ($arBucket['READ_ONLY'] !== 'Y' && $result['ACCESS_KEY'] === '')
186 {
187 $aMsg[] = [
188 'id' => $this->GetID() . 'INP_ACCESS_KEY',
189 'text' => GetMessage('CLO_STORAGE_AMAZON_EMPTY_ACCESS_KEY'),
190 ];
191 }
192
193 if ($arBucket['READ_ONLY'] !== 'Y' && $result['SECRET_KEY'] === '')
194 {
195 $aMsg[] = [
196 'id' => $this->GetID() . 'INP_SECRET_KEY',
197 'text' => GetMessage('CLO_STORAGE_AMAZON_EMPTY_SECRET_KEY'),
198 ];
199 }
200
201 if (!empty($aMsg))
202 {
203 $e = new CAdminException($aMsg);
204 $APPLICATION->ThrowException($e);
205 return false;
206 }
207 else
208 {
209 $arSettings = $result;
210 }
211
212 return true;
213 }
214
219 protected function GetRequestHost($bucket, $arSettings)
220 {
221 if (
222 $this->new_end_point != ''
223 && preg_match('#^(http|https)://' . preg_quote($bucket, '#') . '(.+?)/#', $this->new_end_point, $match) > 0
224 )
225 {
226 return $bucket . $match[2];
227 }
228 elseif ($this->location)
229 {
230 if ($bucket !== '')
231 {
232 return $bucket . '.s3.' . $this->location . '.amazonaws.com';
233 }
234 else
235 {
236 return 's3.' . $this->location . '.amazonaws.com';
237 }
238 }
239 else
240 {
241 if ($bucket !== '')
242 {
243 return $bucket . '.s3.amazonaws.com';
244 }
245 else
246 {
247 return 's3.amazonaws.com';
248 }
249 }
250 }
251
258 public function GetFileSRC($arBucket, $arFile, $encoded = true)
259 {
260 /* @var \Bitrix\Main\HttpRequest $request */
261 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
262 $proto = $request->isHttps() ? 'https' : 'http';
263
264 static $aps = null;
265 if (!$aps)
266 {
267 $aps = $this->GetAPList();
268 }
269
270 if ($arBucket['CNAME'] != '')
271 {
272 $host = $arBucket['CNAME'];
273 $pref = '';
274 }
275 elseif ($proto === 'https' && strpos($arBucket['BUCKET'], '.') !== false)
276 {
277 if (isset($aps[$arBucket['LOCATION']]))
278 {
279 $host = $aps[$arBucket['LOCATION']];
280 }
281 else
282 {
283 $host = $aps[''];
284 }
285
286 $pref = $arBucket['BUCKET'];
287 }
288 else
289 {
290 if (isset($aps[$arBucket['LOCATION']]))
291 {
292 $host = $arBucket['BUCKET'] . '.' . $aps[$arBucket['LOCATION']];
293 }
294 else
295 {
296 $host = $aps[''];
297 }
298
299 $pref = '';
300 }
301
302 if (is_array($arFile))
303 {
304 $URI = ltrim($arFile['SUBDIR'] . '/' . $arFile['FILE_NAME'], '/');
305 }
306 else
307 {
308 $URI = ltrim($arFile, '/');
309 }
310
311 if ($arBucket['PREFIX'] != '')
312 {
313 if (substr($URI, 0, strlen($arBucket['PREFIX']) + 1) !== $arBucket['PREFIX'] . '/')
314 {
315 $URI = $arBucket['PREFIX'] . '/' . $URI;
316 }
317 }
318
319 if ($pref !== '')
320 {
321 $URI = $pref . '/' . $URI;
322 }
323
324 if ($encoded)
325 {
326 return $proto . '://' . $host . '/' . CCloudUtil::URLEncode($URI, 'UTF-8', true);
327 }
328 else
329 {
330 return $proto . '://' . $host . '/' . $URI;
331 }
332 }
333
338 public function CreateBucket($arBucket)
339 {
340 global $APPLICATION;
341
342 $arFiles = $this->ListFiles($arBucket, '/', false, 1);
343 if (is_array($arFiles))
344 {
345 return true;
346 }
347
348 // The bucket already exists and user has specified wrong location
349 if (
350 $this->status == 301
351 && $arBucket['LOCATION'] != ''
352 && $this->GetLastRequestHeader('x-amz-bucket-region') !== ''
353 && $this->GetLastRequestHeader('x-amz-bucket-region') !== $arBucket['LOCATION']
354 )
355 {
356 return false;
357 }
358
359 if ($arBucket['LOCATION'] != '' && $arBucket['LOCATION'] !== 'us-east-1')
360 {
361 $content =
362 '<CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">'
363 . '<LocationConstraint>' . $arBucket['LOCATION'] . '</LocationConstraint>'
364 . '</CreateBucketConfiguration>';
365 }
366 else
367 {
368 $content = '';
369 }
370
371 $this->SetLocation($arBucket['LOCATION']);
372 $response = $this->SendRequest(
373 $arBucket['SETTINGS'],
374 'PUT',
375 $arBucket['BUCKET'],
376 '/',
377 '',
378 $content,
379 ['x-amz-object-ownership' => 'ObjectWriter']
380 );
381
382 if ($this->status == 409/*Already exists*/)
383 {
384 $APPLICATION->ResetException();
385 return true;
386 }
387 elseif ($this->status == 200)
388 {
389 $response = $this->SendRequest(
390 $arBucket['SETTINGS'],
391 'DELETE',
392 $arBucket['BUCKET'],
393 '/',
394 '?publicAccessBlock='
395 );
396 if ($this->status == 204)
397 {
398 return true;
399 }
400
401 if (defined('BX_CLOUDS_ERROR_DEBUG'))
402 {
403 AddMessage2Log($this);
404 }
405 return false;
406 }
407 elseif (is_array($response))
408 {
409 return true;
410 }
411 else
412 {
413 if (defined('BX_CLOUDS_ERROR_DEBUG'))
414 {
415 AddMessage2Log($this);
416 }
417 return false;
418 }
419 }
420}
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_amazon.php:219
GetFileSRC($arBucket, $arFile, $encoded=true)
Определения storage_service_amazon.php:258
CheckSettings($arBucket, &$arSettings)
Определения storage_service_amazon.php:171
GetSettingsHTML($arBucket, $bServiceSet, $cur_SERVICE_ID, $bVarsFromForm)
Определения storage_service_amazon.php:121
SetLocation($location)
Определения storage_service_s3.php:268
ListFiles($arBucket, $filePath, $bRecursive=false, $pageSize=0, $pageMarker='')
Определения storage_service_s3.php:1219
SendRequest($arSettings, $verb, $bucket, $file_name='/', $params='', $content='', $additional_headers=[])
Определения storage_service_s3.php:316
GetLastRequestHeader($headerName)
Определения storage_service.php:300
static URLEncode($str, $charset, $file_name=false)
Определения util.php:10
$content
Определения commerceml.php:144
$bVarsFromForm
Определения file_edit.php:44
EndNote()
Определения filter_tools.php:601
BeginNote($sParams='', $sMessParams='')
Определения filter_tools.php:589
AddMessage2Log($text, $module='', $traceDepth=6, $showArgs=false)
Определения tools.php:3941
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
$arFiles
Определения options.php:60
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$response
Определения result.php:21