13 return 'openstack_storage';
18 return 'OpenStack Object Storage';
32 $arSettings = $_POST[
'SETTINGS'][$this->
GetID()];
36 $arSettings = unserialize($arBucket[
'SETTINGS'], [
'allowed_classes' =>
false]);
39 if (!is_array($arSettings))
50 $show = (($cur_SERVICE_ID == $this->
GetID()) || !$bServiceSet) ?
'' :
'none';
53 <tr id="SETTINGS_2_' . $htmlID .
'" style="display:' . $show .
'" class="settings-tr adm-detail-required-field">
54 <td>' .
GetMessage(
'CLO_STORAGE_OPENSTACK_EDIT_HOST') .
':</td>
55 <td><input type="hidden" name="SETTINGS[' . $htmlID .
'][HOST]" id="' . $htmlID .
'HOST" value="' .
htmlspecialcharsbx($arSettings[
'HOST']) .
'"><input type="text" size="55" name="' . $htmlID .
'INP_HOST" id="' . $htmlID .
'INP_HOST" value="' .
htmlspecialcharsbx($arSettings[
'HOST']) .
'" ' . ($arBucket[
'READ_ONLY'] ==
'Y' ?
'"disabled"' :
'') .
' onchange="BX(\'' . $htmlID .
'HOST\').value = this.value"></td>
57 <tr id="SETTINGS_0_' . $htmlID .
'" style="display:' . $show .
'" class="settings-tr adm-detail-required-field">
58 <td>' .
GetMessage(
'CLO_STORAGE_OPENSTACK_EDIT_USER') .
':</td>
59 <td><input type="hidden" name="SETTINGS[' . $htmlID .
'][USER]" id="' . $htmlID .
'USER" value="' .
htmlspecialcharsbx($arSettings[
'USER']) .
'"><input type="text" size="55" name="' . $htmlID .
'INP_" id="' . $htmlID .
'INP_USER" value="' .
htmlspecialcharsbx($arSettings[
'USER']) .
'" ' . ($arBucket[
'READ_ONLY'] ==
'Y' ?
'"disabled"' :
'') .
' onchange="BX(\'' . $htmlID .
'USER\').value = this.value"></td>
61 <tr id="SETTINGS_1_' . $htmlID .
'" style="display:' . $show .
'" class="settings-tr adm-detail-required-field">
62 <td>' .
GetMessage(
'CLO_STORAGE_OPENSTACK_EDIT_KEY') .
':</td>
63 <td><input type="hidden" name="SETTINGS[' . $htmlID .
'][KEY]" id="' . $htmlID .
'KEY" value="' .
htmlspecialcharsbx($arSettings[
'KEY']) .
'"><input type="text" size="55" name="' . $htmlID .
'INP_KEY" id="' . $htmlID .
'INP_KEY" value="' .
htmlspecialcharsbx($arSettings[
'KEY']) .
'" autocomplete="off" ' . ($arBucket[
'READ_ONLY'] ==
'Y' ?
'"disabled"' :
'') .
' onchange="BX(\'' . $htmlID .
'KEY\').value = this.value"></td>
65 <tr id="SETTINGS_3_' . $htmlID .
'" style="display:' . $show .
'" class="settings-tr">
66 <td>' .
GetMessage(
'CLO_STORAGE_OPENSTACK_FORCE_HTTP') .
':</td>
67 <td><input type="hidden" name="SETTINGS[' . $htmlID .
'][FORCE_HTTP]" id="' . $htmlID .
'KEY" value="N"><input type="checkbox" name="SETTINGS[' . $htmlID .
'][FORCE_HTTP]" id="' . $htmlID .
'FORCE_HTTP" value="Y" ' . ($arSettings[
'FORCE_HTTP'] ==
'Y' ?
'checked="checked"' :
'') .
'></td>
79 'HOST' => is_array($arSettings) ? trim($arSettings[
'HOST']) :
'',
80 'USER' => is_array($arSettings) ? trim($arSettings[
'USER']) :
'',
81 'KEY' => is_array($arSettings) ? trim($arSettings[
'KEY']) :
'',
82 'FORCE_HTTP' => is_array($arSettings) && $arSettings[
'FORCE_HTTP'] ==
'Y' ?
'Y' :
'N',
85 if ($arBucket[
'READ_ONLY'] !==
'Y' && !mb_strlen(
$result[
'HOST']))
87 $aMsg[] = [
'id' => $this->
GetID() .
'INP_HOST',
'text' =>
GetMessage(
'CLO_STORAGE_OPENSTACK_EMPTY_HOST')];
90 if ($arBucket[
'READ_ONLY'] !==
'Y' && !mb_strlen(
$result[
'USER']))
92 $aMsg[] = [
'id' => $this->
GetID() .
'INP_USER',
'text' =>
GetMessage(
'CLO_STORAGE_OPENSTACK_EMPTY_USER')];
95 if ($arBucket[
'READ_ONLY'] !==
'Y' && !mb_strlen(
$result[
'KEY']))
97 $aMsg[] = [
'id' => $this->
GetID() .
'INP_KEY',
'text' =>
GetMessage(
'CLO_STORAGE_OPENSTACK_EMPTY_KEY')];
104 $aMsg[] = [
'text' =>
GetMessage(
'CLO_STORAGE_OPENSTACK_ERROR_GET_TOKEN')];
125 static $results = [];
126 $cache_id =
'v0|' .
$host .
'|' . $user .
'|' .
$key;
128 if (array_key_exists($cache_id, $results))
135 $obCache =
new CPHPCache;
137 if ($obCache->InitCache(600, $cache_id,
'/'))
146 $this->url =
'http://' .
$host .
'/v1.0';
154 if (defined(
'BX_CLOUDS_TRACE') && $this->verb !==
'GET' && $this->verb !==
'HEAD')
156 $stime = microtime(1);
158 'request_id' => md5((
string)mt_rand()),
168 'streamTimeout' => $this->streamTimeout,
170 $request->setHeader(
'X-Auth-User', $user);
172 $request->query($this->verb, $this->url);
174 $this->status =
$request->getStatus();
175 foreach (
$request->getHeaders() as $headerKey => $headerValue)
177 $this->headers[$headerKey] = is_array($headerValue) ? $headerValue[0] : $headerValue;
179 $this->errstr = implode(
"\n",
$request->getError());
180 $this->errno = $this->errstr ? 255 : 0;
181 $this->result =
$request->getResult();
186 $logRequest[
'time'] = round(microtime(
true) - $stime, 6);
191 if ($this->status == 412)
198 $this->url =
'http://' .
$host .
'/auth/v1.0';
205 if (defined(
'BX_CLOUDS_TRACE') && $this->verb !==
'GET' && $this->verb !==
'HEAD')
207 $stime = microtime(1);
209 'request_id' => md5((
string)mt_rand()),
219 'streamTimeout' => $this->streamTimeout,
221 $request->setHeader(
'X-Auth-User', $user);
223 $request->query($this->verb, $this->url);
225 $this->status =
$request->getStatus();
226 foreach (
$request->getHeaders() as $headerKey => $headerValue)
228 $this->headers[$headerKey] = is_array($headerValue) ? $headerValue[0] : $headerValue;
230 $this->errstr = implode(
"\n",
$request->getError());
231 $this->errno = $this->errstr ? 255 : 0;
232 $this->result =
$request->getResult();
237 $logRequest[
'time'] = round(microtime(
true) - $stime, 6);
243 if ($this->status == 204 || $this->status == 200)
246 if (preg_match(
'#^http://(.*?)(|:\d+)(/.*)$#', $this->headers[
'X-Storage-Url'], $arStorage))
249 $result[
'X-Storage-NoProtoUrl'] = $arStorage[1] . ($arStorage[2] ===
':80' ?
'' : $arStorage[2]) . $arStorage[3];
250 $result[
'X-Storage-Host'] = $arStorage[1];
251 $result[
'X-Storage-Port'] = $arStorage[2] ? mb_substr($arStorage[2], 1) : 80;
252 $result[
'X-Storage-Urn'] = $arStorage[3];
253 $result[
'X-Storage-Proto'] =
'';
260 if ($obCache->StartDataCache())
262 $obCache->EndDataCache(
$result);
282 'streamTimeout' => $this->streamTimeout,
284 if (isset($additional_headers[
'option-file-result']))
286 $request->setOutputStream($additional_headers[
'option-file-result']);
289 $RequestURI = $file_name;
292 $request->setHeader(
'X-Auth-Token', $arToken[
'X-Auth-Token']);
293 foreach ($additional_headers as
$key => $value)
295 if (
$key ==
'Content-Type')
297 $ContentType = $value;
306 $this->host = $arToken[
'X-Storage-Host'];
307 $this->port = $arToken[
'X-Storage-Port'];
309 $this->url = rtrim($arToken[
'X-Storage-Url'],
'/') .
'/' . $bucket . $RequestURI .
$params;
317 if (defined(
'BX_CLOUDS_TRACE') && $this->verb !==
'GET' && $this->verb !==
'HEAD')
319 $stime = microtime(1);
321 'request_id' => md5((
string)mt_rand()),
329 $request->setHeader(
'Content-type', $ContentType);
332 $this->status =
$request->getStatus();
335 $this->headers[
$key] = is_array($value) ? $value[0] : $value;
337 $this->errstr = implode(
"\n",
$request->getError());
338 $this->errno = $this->errstr ? 255 : 0;
339 $this->result =
$request->getResult();
344 $logRequest[
'time'] = round(microtime(
true) - $stime, 6);
355 $arBucket[
'SETTINGS'],
362 'X-Container-Read' =>
'.r:*',
363 'X-Container-Meta-Web-Listings' =>
'false',
364 'X-Container-Meta-Type' =>
'public',
368 return ($this->status == 201) || ($this->status == 202) ;
373 if ($arBucket[
'PREFIX'])
382 $arAllBucket = $arBucket;
383 $arBucket[
'PREFIX'] =
'';
391 $arBucket[
'SETTINGS'],
398 || $this->status == 404
412 $arBucket[
'SETTINGS'],
416 '?limit=1&format=xml' . ($arBucket[
'PREFIX'] ?
'&prefix=' . $arBucket[
'PREFIX'] :
'')
420 if ($this->status && $this->result)
423 $text = preg_replace(
'/<' .
'\\?XML.*?\\?' .
'>/i',
'', $this->result);
424 if ($obXML->LoadString(
$text))
426 $arXML = $obXML->GetArray();
430 if ($this->status == 404)
437 !isset($arXML[
'container'])
438 || !is_array($arXML[
'container'])
439 || !isset($arXML[
'container'][
'#'])
440 || !is_array($arXML[
'container'][
'#'])
441 || !isset($arXML[
'container'][
'#'][
'object'])
442 || !is_array($arXML[
'container'][
'#'][
'object']);
456 public function GetFileSRC($arBucket, $arFile, $encoded =
true)
458 $forceHttp = $arBucket[
'SETTINGS'][
'FORCE_HTTP'] ??
'N';
459 if ($forceHttp ===
'Y')
466 $request = \Bitrix\Main\Context::getCurrent()->getRequest();
467 $proto =
$request->isHttps() ?
'https' :
'http';
470 if ($arBucket[
'CNAME'])
472 $host = $proto .
'://' . $arBucket[
'CNAME'];
477 $arBucket[
'SETTINGS'][
'HOST'],
478 $arBucket[
'SETTINGS'][
'USER'],
479 $arBucket[
'SETTINGS'][
'KEY']
482 if (is_array($arToken))
484 if ($arToken[
'X-Storage-NoProtoUrl'])
486 $host = $proto .
'://' . $arToken[
'X-Storage-NoProtoUrl'] .
'/' . $arBucket[
'BUCKET'];
490 $host = $arToken[
'X-Storage-Url'] .
'/' . $arBucket[
'BUCKET'];
499 if (is_array($arFile))
501 $URI = ltrim($arFile[
'SUBDIR'] .
'/' . $arFile[
'FILE_NAME'],
'/');
505 $URI = ltrim($arFile,
'/');
508 if ($arBucket[
'PREFIX'])
510 if (mb_substr($URI, 0, mb_strlen($arBucket[
'PREFIX']) + 1) !== $arBucket[
'PREFIX'] .
'/')
512 $URI = $arBucket[
'PREFIX'] .
'/' . $URI;
522 return $host .
'/' . $URI;
530 if ($arBucket[
'PREFIX'])
532 if (mb_substr($filePath, 0, mb_strlen($arBucket[
'PREFIX']) + 2) !==
'/' . $arBucket[
'PREFIX'] .
'/')
534 $filePath =
'/' . $arBucket[
'PREFIX'] .
'/' . ltrim($filePath,
'/');
540 $arBucket[
'SETTINGS'],
546 if ($this->status == 200)
548 if (isset($this->headers[
'Content-Length']) && $this->headers[
'Content-Length'] > 0)
550 return $this->headers[
'Content-Length'];
557 elseif ($this->status == 206)
569 public function FileCopy($arBucket, $arFile, $filePath)
571 if ($arBucket[
'PREFIX'])
573 if (mb_substr($filePath, 0, mb_strlen($arBucket[
'PREFIX']) + 2) !==
'/' . $arBucket[
'PREFIX'] .
'/')
575 $filePath =
'/' . $arBucket[
'PREFIX'] .
'/' . ltrim($filePath,
'/');
578 $fileSource =
CCloudUtil::URLEncode(
'/' . $arBucket[
'BUCKET'] .
'/' . ($arBucket[
'PREFIX'] ? $arBucket[
'PREFIX'] .
'/' :
'') . ($arFile[
'SUBDIR'] ? $arFile[
'SUBDIR'] .
'/' :
'') . $arFile[
'FILE_NAME'],
'UTF-8',
true);
581 $arBucket[
'SETTINGS'],
588 'X-Copy-From' => $fileSource,
589 'Content-Type' => $arFile[
'CONTENT_TYPE'],
593 if ($this->status == 200 || $this->status == 201)
595 return $this->
GetFileSRC($arBucket, $filePath);
607 if ($arBucket[
'PREFIX'])
609 if (mb_substr($filePath, 0, mb_strlen($arBucket[
'PREFIX']) + 2) !==
'/' . $arBucket[
'PREFIX'] .
'/')
611 $filePath =
'/' . $arBucket[
'PREFIX'] .
'/' . ltrim($filePath,
'/');
617 $arBucket[
'SETTINGS'],
624 if ($this->status == 404 && mb_strpos($filePath,
'+') !==
false)
626 $filePath = str_replace(
'+',
'%20', $filePath);
628 $arBucket[
'SETTINGS'],
635 if ($this->status == 204 || $this->status == 404)
647 public function SaveFile($arBucket, $filePath, $arFile)
649 if ($arBucket[
'PREFIX'])
651 if (mb_substr($filePath, 0, mb_strlen($arBucket[
'PREFIX']) + 2) !==
'/' . $arBucket[
'PREFIX'] .
'/')
653 $filePath =
'/' . $arBucket[
'PREFIX'] .
'/' . ltrim($filePath,
'/');
658 if (array_key_exists(
'content', $arFile))
661 $arBucket[
'SETTINGS'],
668 'Content-Type' => $arFile[
'type'],
669 'Content-Length' => strlen($arFile[
'content']),
676 $arBucket[
'SETTINGS'],
681 fopen($arFile[
'tmp_name'],
'rb'),
683 'Content-Type' => $arFile[
'type'],
684 'Content-Length' => filesize($arFile[
'tmp_name']),
689 if ($this->status == 201)
699 public function ListFiles($arBucket, $filePath, $bRecursive =
false)
710 $filePath = trim($filePath,
'/');
711 if ($filePath !==
'')
716 if ($arBucket[
'PREFIX'])
718 if (mb_substr($filePath, 0, mb_strlen($arBucket[
'PREFIX']) + 2) !==
'/' . $arBucket[
'PREFIX'] .
'/')
720 $filePath = $arBucket[
'PREFIX'] .
'/' . ltrim($filePath,
'/');
723 $filePath = str_replace(
' ',
'+', $filePath);
730 $arBucket[
'SETTINGS'],
734 $s =
'?format=xml&' . ($bRecursive ?
'' :
'&delimiter=/') .
'&prefix=' . urlencode($filePath) .
'&marker=' . urlencode($marker)
737 if ($this->result && $this->status == 200)
740 $text = preg_replace(
'/<' .
'\\?XML.*?\\?' .
'>/i',
'', $this->result);
741 if ($obXML->LoadString(
$text))
743 $arXML = $obXML->GetArray();
745 isset($arXML[
'container'])
746 && is_array($arXML[
'container'])
747 && isset($arXML[
'container'][
'#'])
748 && is_array($arXML[
'container'][
'#'])
749 && !empty($arXML[
'container'][
'#'])
753 isset($arXML[
'container'][
'#'][
'object'])
754 && is_array($arXML[
'container'][
'#'][
'object'])
755 && !empty($arXML[
'container'][
'#'][
'object'])
759 foreach ($arXML[
'container'][
'#'][
'object'] as
$a)
761 $new_marker =
$a[
'#'][
'name'][0][
'#'];
762 if (
$a[
'#'][
'content_type'][0][
'#'] ===
'application/directory')
764 $dir_name = trim(mb_substr(
$a[
'#'][
'name'][0][
'#'], mb_strlen($filePath)),
'/');
765 $result[
'dir'][$dir_name] =
true;
769 $file_name = mb_substr(
$a[
'#'][
'name'][0][
'#'], mb_strlen($filePath));
770 if (!in_array($file_name,
$result[
'file'],
true))
772 $result[
'file'][] = $file_name;
773 $result[
'file_size'][] =
$a[
'#'][
'bytes'][0][
'#'];
774 $result[
'file_mtime'][] = mb_substr(
$a[
'#'][
'last_modified'][0][
'#'], 0, 19);
775 $result[
'file_hash'][] =
$a[
'#'][
'hash'][0][
'#'];
776 $result[
'last_key'] = $file_name;
783 isset($arXML[
'container'][
'#'][
'subdir'])
784 && is_array($arXML[
'container'][
'#'][
'subdir'])
785 && !empty($arXML[
'container'][
'#'][
'subdir'])
789 foreach ($arXML[
'container'][
'#'][
'subdir'] as
$a)
791 $new_marker =
$a[
'@'][
'name'];
792 $dir_name = trim(mb_substr(
$a[
'@'][
'name'], mb_strlen($filePath)),
'/');
793 $result[
'dir'][rawurldecode($dir_name)] =
true;
804 if ($new_marker === $marker)
814 $marker = $new_marker;
824 $filePath =
'/' . trim($filePath,
'/');
825 if ($arBucket[
'PREFIX'])
827 if (mb_substr($filePath, 0, mb_strlen($arBucket[
'PREFIX']) + 2) !==
'/' . $arBucket[
'PREFIX'] .
'/')
829 $filePath =
'/' . $arBucket[
'PREFIX'] . $filePath;
834 'filePath' => $filePath,
838 'Content-Type' => $ContentType,
846 return 5 * 1024 * 1024;
851 $filePath =
$NS[
'fileTemp'] .
'/' . sprintf(
'%06d', $part_no + 1);
855 $arBucket[
'SETTINGS'],
863 if ($this->status == 201)
866 $NS[
'Parts'][$part_no] = $filePath;
885 $arBucket[
'SETTINGS'],
892 'Content-Length' => 0,
893 'Content-Type' =>
$NS[
'Content-Type'],
894 'X-Object-Manifest' => $arBucket[
'BUCKET'] . $filePath .
'/',
898 if ($this->status == 201)
903 $arBucket[
'SETTINGS'],
910 'Content-Type' =>
$NS[
'Content-Type'],
911 'X-Copy-From' => $fileSource,
917 || $this->status == 200
929 foreach (
$NS[
'Parts'] as $tmpPath)
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
static translit($file_name, $safe_chars='')
DeleteFile($arBucket, $filePath)
InitiateMultipartUpload($arBucket, &$NS, $filePath, $fileSize, $ContentType)
FileExists($arBucket, $filePath)
UploadPart($arBucket, &$NS, $data)
GetFileSRC($arBucket, $arFile, $encoded=true)
FileCopy($arBucket, $arFile, $filePath)
UploadPartNo($arBucket, &$NS, $data, $part_no)
CompleteMultipartUpload($arBucket, &$NS)
_GetToken($host, $user, $key)
SaveFile($arBucket, $filePath, $arFile)
SendRequest($settings, $verb, $bucket, $file_name='', $params='', $content=false, $additional_headers=[])
ListFiles($arBucket, $filePath, $bRecursive=false)
CheckSettings($arBucket, &$arSettings)
GetSettingsHTML($arBucket, $bServiceSet, $cur_SERVICE_ID, $bVarsFromForm)
static URLEncode($str, $charset, $file_name=false)
$_SERVER["DOCUMENT_ROOT"]
if(!defined('NOT_CHECK_PERMISSIONS')) $NS
AddMessage2Log($text, $module='', $traceDepth=6, $showArgs=false)
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']