1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
storage_service_yandex.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_Yandex();
17 }
18
22 public function GetID()
23 {
24 return 'yandex';
25 }
26
30 public function GetName()
31 {
32 return 'Yandex Object Storage';
33 }
34
38 public function GetLocationList()
39 {
40 return [
41 '' => 'storage.yandexcloud.net',
42 ];
43 }
44
52 public function GetSettingsHTML($arBucket, $bServiceSet, $cur_SERVICE_ID, $bVarsFromForm)
53 {
55 {
56 $arSettings = $_POST['SETTINGS'][$this->GetID()];
57 }
58 else
59 {
60 $arSettings = unserialize($arBucket['SETTINGS'], ['allowed_classes' => false]);
61 }
62
63 if (!is_array($arSettings))
64 {
65 $arSettings = ['ACCESS_KEY' => '', 'SECRET_KEY' => ''];
66 }
67
68 $htmlID = htmlspecialcharsbx($this->GetID());
69 $show = (($cur_SERVICE_ID === $this->GetID()) || !$bServiceSet) ? '' : 'none';
70 $useHttps = $arSettings['USE_HTTPS'] ?? 'N';
71
72 $result = '
73 <tr id="SETTINGS_0_' . $htmlID . '" style="display:' . $show . '" class="settings-tr adm-detail-required-field">
74 <td>' . GetMessage('CLO_STORAGE_YANDEX_EDIT_ACCESS_KEY') . ':</td>
75 <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>
76 </tr>
77 <tr id="SETTINGS_1_' . $htmlID . '" style="display:' . $show . '" class="settings-tr adm-detail-required-field">
78 <td>' . GetMessage('CLO_STORAGE_YANDEX_EDIT_SECRET_KEY') . ':</td>
79 <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">' . (
80 array_key_exists('SESSION_TOKEN', $arSettings) ?
81 '<input type="hidden" name="SETTINGS[' . $htmlID . '][SESSION_TOKEN]" id="' . $htmlID . 'SESSION_TOKEN" value="' . htmlspecialcharsbx($arSettings['SESSION_TOKEN']) . '">' :
82 ''
83 ) . '</td>
84 </tr>
85 <tr id="SETTINGS_3_' . $htmlID . '" style="display:' . $show . '" class="settings-tr">
86 <td nowrap>' . GetMessage('CLO_STORAGE_YANDEX_EDIT_USE_HTTPS') . ':</td>
87 <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>
88 </tr>
89 ';
90
91 return $result;
92 }
93
99 public function CheckSettings($arBucket, &$arSettings)
100 {
101 global $APPLICATION;
102 $aMsg = /*.(array[int][string]string).*/[];
103
104 $result = [
105 'ACCESS_KEY' => is_array($arSettings) ? trim($arSettings['ACCESS_KEY']) : '',
106 'SECRET_KEY' => is_array($arSettings) ? trim($arSettings['SECRET_KEY']) : '',
107 'USE_HTTPS' => is_array($arSettings) && $arSettings['USE_HTTPS'] == 'Y' ? 'Y' : 'N',
108 ];
109 if (is_array($arSettings) && array_key_exists('SESSION_TOKEN', $arSettings))
110 {
111 $result['SESSION_TOKEN'] = trim($arSettings['SESSION_TOKEN']);
112 }
113
114 if ($arBucket['READ_ONLY'] !== 'Y' && $result['ACCESS_KEY'] === '')
115 {
116 $aMsg[] = [
117 'id' => $this->GetID() . 'INP_ACCESS_KEY',
118 'text' => GetMessage('CLO_STORAGE_YANDEX_EMPTY_ACCESS_KEY'),
119 ];
120 }
121
122 if ($arBucket['READ_ONLY'] !== 'Y' && $result['SECRET_KEY'] === '')
123 {
124 $aMsg[] = [
125 'id' => $this->GetID() . 'INP_SECRET_KEY',
126 'text' => GetMessage('CLO_STORAGE_YANDEX_EMPTY_SECRET_KEY'),
127 ];
128 }
129
130 if (!empty($aMsg))
131 {
132 $e = new CAdminException($aMsg);
133 $APPLICATION->ThrowException($e);
134 return false;
135 }
136 else
137 {
138 $arSettings = $result;
139 }
140
141 return true;
142 }
143
148 protected function GetRequestHost($bucket, $arSettings)
149 {
150 if (
151 $this->new_end_point !== ''
152 && preg_match('#^(http|https)://' . preg_quote($bucket, '#') . '(.+?)/#', $this->new_end_point, $match) > 0
153 )
154 {
155 return $bucket . $match[2];
156 }
157 else
158 {
159 if ($bucket !== '')
160 {
161 return $bucket . '.storage.yandexcloud.net';
162 }
163 else
164 {
165 return 'storage.yandexcloud.net';
166 }
167 }
168 }
169
180 public function SendRequest($arSettings, $verb, $bucket, $file_name='/', $params='', $content='', $additional_headers=/*.(array[string]string).*/[])
181 {
182 $file_name = str_replace('+', '%20', $file_name);
183 if (isset($additional_headers['x-amz-copy-source']))
184 {
185 $additional_headers['x-amz-copy-source'] = str_replace('+', '%20', $additional_headers['x-amz-copy-source']);
186 }
187 return parent::SendRequest($arSettings, $verb, $bucket, $file_name, $params, $content, $additional_headers);
188 }
189
196 public function GetFileSRC($arBucket, $arFile, $encoded = true)
197 {
198 /* @var \Bitrix\Main\HttpRequest $request */
199 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
200 $proto = $request->isHttps() ? 'https' : 'http';
201
202 if ($arBucket['CNAME'] != '')
203 {
204 $host = $arBucket['CNAME'];
205 $pref = '';
206 }
207 elseif ($proto === 'https' && mb_strpos($arBucket['BUCKET'], '.') !== false)
208 {
209 $host = 'storage.yandexcloud.net';
210 $pref = $arBucket['BUCKET'];
211 }
212 else
213 {
214 $host = $arBucket['BUCKET'] . '.storage.yandexcloud.net';
215 $pref = '';
216 }
217
218 if (is_array($arFile))
219 {
220 $URI = ltrim($arFile['SUBDIR'] . '/' . $arFile['FILE_NAME'], '/');
221 }
222 else
223 {
224 $URI = ltrim($arFile, '/');
225 }
226
227 if ($arBucket['PREFIX'] != '')
228 {
229 if (mb_substr($URI, 0, mb_strlen($arBucket['PREFIX']) + 1) !== $arBucket['PREFIX'] . '/')
230 {
231 $URI = $arBucket['PREFIX'] . '/' . $URI;
232 }
233 }
234
235 if ($pref !== '')
236 {
237 $URI = $pref . '/' . $URI;
238 }
239
240 if ($encoded)
241 {
242 return $proto . '://' . $host . '/' . str_replace('+', '%20', CCloudUtil::URLEncode($URI, 'UTF-8'));
243 }
244 else
245 {
246 return $proto . '://' . $host . '/' . $URI;
247 }
248 }
249
254 public function DeleteBucket($arBucket)
255 {
256 //Do not delete bucket if there is some files left
257 if (!$this->IsEmptyBucket($arBucket))
258 {
259 return false;
260 }
261
262 return parent::DeleteBucket($arBucket);
263 }
264
265 public function FileCopy($arBucket, $arFile, $filePath)
266 {
267 $this->streamTimeout = 3600;
268 return parent::FileCopy($arBucket, $arFile, $filePath);
269 }
270
276 public function CompleteMultipartUpload($arBucket, &$NS)
277 {
278 $this->streamTimeout = 3600;
279 return parent::CompleteMultipartUpload($arBucket, $NS);
280 }
281
288 {
289 if ($status == 400 && mb_strpos($result, 'ExpiredToken') !== false)
290 {
291 return true;
292 }
293 if ($status == 403 && mb_strpos($result, 'The request signature we calculated does not match the signature you provided.') !== false)
294 {
295 return true;
296 }
297 return false;
298 }}
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
IsEmptyBucket($arBucket)
Определения storage_service_s3.php:641
GetRequestHost($bucket, $arSettings)
Определения storage_service_yandex.php:148
checkForTokenExpiration($status, $result)
Определения storage_service_yandex.php:287
GetFileSRC($arBucket, $arFile, $encoded=true)
Определения storage_service_yandex.php:196
FileCopy($arBucket, $arFile, $filePath)
Определения storage_service_yandex.php:265
CompleteMultipartUpload($arBucket, &$NS)
Определения storage_service_yandex.php:276
SendRequest($arSettings, $verb, $bucket, $file_name='/', $params='', $content='', $additional_headers=[])
Определения storage_service_yandex.php:180
CheckSettings($arBucket, &$arSettings)
Определения storage_service_yandex.php:99
GetSettingsHTML($arBucket, $bServiceSet, $cur_SERVICE_ID, $bVarsFromForm)
Определения storage_service_yandex.php:52
static URLEncode($str, $charset, $file_name=false)
Определения util.php:10
$content
Определения commerceml.php:144
$bVarsFromForm
Определения file_edit.php:44
if(!defined('NOT_CHECK_PERMISSIONS')) $NS
Определения backup.php:24
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
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799