1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
storage_service_rackspace.php
См. документацию.
1<?php
3{
4 public function GetObject()
5 {
7 }
8
9 public function GetID()
10 {
11 return 'rackspace_storage';
12 }
13
14 public function GetName()
15 {
16 return 'Rackspace Cloud Files';
17 }
18
19 public function _GetToken($host, $user, $key)
20 {
21 global $APPLICATION;
22
23 $result = false;
24 $cache_id = 'v0|' . $host . '|' . $user . '|' . $key;
25 $obCache = new CPHPCache;
26
27 if ($obCache->InitCache(3600, $cache_id, '/'))
28 {
29 $result = $obCache->GetVars();
30 }
31 else
32 {
33 $this->status = 0;
34 $this->host = $host;
35 $this->verb = 'GET';
36 $this->url = 'http://' . $host . '/v1.0';
37 $this->headers = [];
38 $this->errno = 0;
39 $this->errstr = '';
40 $this->result = '';
41
43 'redirect' => false,
44 'streamTimeout' => $this->streamTimeout,
45 ]);
46 $request->setHeader('X-Auth-User', $user);
47 $request->setHeader('X-Auth-Key', $key);
48 $request->query($this->verb, $this->url);
49
50 $this->status = $request->getStatus();
51 foreach ($request->getHeaders() as $headerKey => $headerValue)
52 {
53 $this->headers[$headerKey] = is_array($headerValue) ? $headerValue[0] : $headerValue;
54 }
55 $this->errstr = implode("\n", $request->getError());
56 $this->errno = $this->errstr ? 255 : 0;
57 $this->result = $request->getResult();
58
59 if (
60 $this->status == 301
61 && $this->headers['Location'] <> ''
62 && preg_match('#^https://(.*?)(/.*)$#', $this->headers['Location'], $arNewLocation)
63 )
64 {
65 $APPLICATION->ResetException();
66
67 $this->status = 0;
68 $this->host = $arNewLocation[1];
69 $this->verb = 'GET';
70 $this->url = 'https://' . $arNewLocation[1] . '/v1.0';
71 $this->headers = [];
72 $this->errno = 0;
73 $this->errstr = '';
74 $this->result = '';
75
77 'redirect' => false,
78 'streamTimeout' => $this->streamTimeout,
79 ]);
80 $request->setHeader('X-Auth-User', $user);
81 $request->setHeader('X-Auth-Key', $key);
82 $request->query($this->verb, $this->url);
83
84 $this->status = $request->getStatus();
85 foreach ($request->getHeaders() as $headerKey => $headerValue)
86 {
87 $this->headers[$headerKey] = is_array($headerValue) ? $headerValue[0] : $headerValue;
88 }
89 $this->errstr = implode("\n", $request->getError());
90 $this->errno = $this->errstr ? 255 : 0;
91 $this->result = $request->getResult();
92
93 if ($this->status == 204)
94 {
95 if (preg_match('#^https://(.*?)(/.*)$#', $this->headers['X-Storage-Url'], $arStorage))
96 {
98 $result['X-Storage-Host'] = $arStorage[1];
99 $result['X-Storage-Port'] = 443;
100 $result['X-Storage-Urn'] = $arStorage[2];
101 $result['X-Storage-Proto'] = 'ssl://';
102 }
103 }
104 }
105 }
106
107 if (is_array($result))
108 {
109 if ($obCache->StartDataCache())
110 {
111 $obCache->EndDataCache($result);
112 }
113 }
114
115 return $result;
116 }
117
118 public function SendCDNRequest($settings, $verb, $bucket, $file_name='', $params='', $content=false, $additional_headers=[])
119 {
120 $arToken = $this->_GetToken($settings['HOST'], $settings['USER'], $settings['KEY']);
121 if (!$arToken)
122 {
123 return false;
124 }
125
126 if (isset($arToken['X-CDN-Management-Url']))
127 {
128 if (preg_match('#^http://(.*?)(|:\d+)(/.*)$#', $arToken['X-CDN-Management-Url'], $arCDN))
129 {
130 $Host = $arCDN[1];
131 $Port = $arCDN[2];
132 $Urn = $arCDN[3];
133 $Proto = 'http://';
134 }
135 elseif (preg_match('#^https://(.*?)(|:\d+)(/.*)$#', $arToken['X-CDN-Management-Url'], $arCDN))
136 {
137 $Host = $arCDN[1];
138 $Port = $arCDN[2];
139 $Urn = $arCDN[3];
140 $Proto = 'https://';
141 }
142 else
143 {
144 return false;
145 }
146 }
147 else
148 {
149 return false;
150 }
151
152 $this->status = 0;
153 $this->host = $Host;
154 $this->verb = $verb;
155 $this->url = $Proto . $Host . ($Port ?: '') . $Urn . CCloudUtil::URLEncode('/' . $bucket . $file_name . $params, 'UTF-8');
156 $this->headers = [];
157 $this->errno = 0;
158 $this->errstr = '';
159 $this->result = '';
160
161 $stime = 0;
162 $logRequest = false;
163 if (defined('BX_CLOUDS_TRACE') && $verb !== 'GET' && $verb !== 'HEAD')
164 {
165 $stime = microtime(1);
166 $logRequest = [
167 'request_id' => md5((string)mt_rand()),
168 'portal' => $_SERVER['HTTP_HOST'],
169 'verb' => $this->verb,
170 'url' => $this->url,
171 ];
172 AddMessage2Log(json_encode($logRequest), 'clouds', 20);
173 }
174
176 'redirect' => false,
177 'streamTimeout' => $this->streamTimeout,
178 ]);
179 $request->setHeader('X-Auth-Token', $arToken['X-Auth-Token']);
180 foreach ($additional_headers as $key => $value)
181 {
182 $request->setHeader($key, $value);
183 }
184 $request->query($this->verb, $this->url);
185
186 $this->status = $request->getStatus();
187 foreach ($request->getHeaders() as $key => $value)
188 {
189 $this->headers[$key] = is_array($value) ? $value[0] : $value;
190 }
191 $this->errstr = implode("\n", $request->getError());
192 $this->errno = $this->errstr ? 255 : 0;
193 $this->result = $request->getResult();
194
195 if ($logRequest)
196 {
197 $logRequest['status'] = $this->status;
198 $logRequest['time'] = round(microtime(true) - $stime, 6);
199 $logRequest['headers'] = $this->headers;
200 AddMessage2Log(json_encode($logRequest), 'clouds', 0);
201 }
202
203 return $request;
204 }
205
206 public function CreateBucket($arBucket)
207 {
208 $this->SendRequest(
209 $arBucket['SETTINGS'],
210 'PUT',
211 $arBucket['BUCKET']
212 );
213
214 //CDN Enable
215 if ($this->status == 201)
216 {
217 $this->SendCDNRequest(
218 $arBucket['SETTINGS'],
219 'PUT',
220 $arBucket['BUCKET'],
221 '', //filename
222 '', //params
223 false, //content
224 [
225 'X-CDN-Enabled' => 'True',
226 ]
227 );
228 }
229
230 return ($this->status == 201)/*Created*/ || ($this->status == 202) /*Accepted*/;
231 }
232
239 public function GetFileSRC($arBucket, $arFile, $encoded = true)
240 {
241 global $APPLICATION;
242
243 if ($arBucket['SETTINGS']['FORCE_HTTP'] === 'Y')
244 {
245 $proto = 'http';
246 }
247 else
248 {
249 $proto = ($APPLICATION->IsHTTPS() ? 'https' : 'http');
250 }
251
252 if ($arBucket['CNAME'])
253 {
254 $host = $proto . '://' . $arBucket['CNAME'];
255 }
256 else
257 {
258 $result = false;
259 $cache_id = md5(serialize($arBucket));
260 $obCache = new CPHPCache;
261 if ($obCache->InitCache(3600, $cache_id, '/'))
262 {
263 $result = $obCache->GetVars();
264 }
265 else
266 {
267 $this->SendCDNRequest(
268 $arBucket['SETTINGS'],
269 'HEAD',
270 $arBucket['BUCKET']
271 );
272 if ($this->status == 204)
273 {
274 $result = [];
275 foreach ($this->headers as $key => $value)
276 {
277 $result[mb_strtolower($key)] = $value;
278 }
279 }
280 }
281
282 if ($obCache->StartDataCache())
283 {
284 $obCache->EndDataCache($result);
285 }
286
287 if (is_array($result))
288 {
289 $host = $result['x-cdn-uri'];
290 }
291 else
292 {
293 return '/404.php';
294 }
295 }
296
297 if (is_array($arFile))
298 {
299 $URI = ltrim($arFile['SUBDIR'] . '/' . $arFile['FILE_NAME'], '/');
300 }
301 else
302 {
303 $URI = ltrim($arFile, '/');
304 }
305
306 if ($arBucket['PREFIX'])
307 {
308 if (mb_substr($URI, 0, mb_strlen($arBucket['PREFIX']) + 1) !== $arBucket['PREFIX'] . '/')
309 {
310 $URI = $arBucket['PREFIX'] . '/' . $URI;
311 }
312 }
313
314 if ($encoded)
315 {
316 return $host . '/' . CCloudUtil::URLEncode($URI, 'UTF-8', true);
317 }
318 else
319 {
320 return $host . '/' . $URI;
321 }
322 }
323}
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
SendRequest($settings, $verb, $bucket, $file_name='', $params='', $content=false, $additional_headers=[])
Определения storage_service_openstack.php:272
GetFileSRC($arBucket, $arFile, $encoded=true)
Определения storage_service_rackspace.php:239
SendCDNRequest($settings, $verb, $bucket, $file_name='', $params='', $content=false, $additional_headers=[])
Определения storage_service_rackspace.php:118
static URLEncode($str, $charset, $file_name=false)
Определения util.php:10
$content
Определения commerceml.php:144
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
AddMessage2Log($text, $module='', $traceDepth=6, $showArgs=false)
Определения tools.php:3941
$settings
Определения product_settings.php:43
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799