PluginProbe
UpdraftPlus: WP Backup & Migration Plugin / 1.16.5
UpdraftPlus: WP Backup & Migration Plugin v1.16.5
1.26.7 1.26.6 1.26.5 1.26.4 1.26.3 1.9.19 1.9.25 1.9.26 1.9.30 1.9.31 1.9.32 1.9.4 1.9.40 1.9.41 1.9.42 1.9.43 1.9.44 1.9.45 1.9.46 1.9.5 1.9.50 1.9.51 1.9.60 1.9.62 1.9.63 All 371 releases
updraftplus / methods / cloudfiles.php

cloudfiles.php in UpdraftPlus: WP Backup & Migration Plugin 1.16.5, at methods/cloudfiles.php

590 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('UPDRAFTPLUS_DIR')) die('No direct access.');
4
5 /**
6 * Converted to job_options: yes
7 * Converted to array options: yes
8 * Migration code for "new"-style options removed: Feb 2017 (created: Dec 2013)
9 */
10
11 if (!class_exists('UpdraftPlus_BackupModule')) require_once(UPDRAFTPLUS_DIR.'/methods/backup-module.php');
12
13 /**
14 * Old SDK
15 */
16 class UpdraftPlus_BackupModule_cloudfiles_oldsdk extends UpdraftPlus_BackupModule {
17
18 /**
19 * This function does not catch any exceptions - that should be done by the caller
20 *
21 * @param string $user
22 * @param string $apikey
23 * @param string $authurl
24 * @param boolean $useservercerts
25 * @return array
26 */
27 private function getCF($user, $apikey, $authurl, $useservercerts = false) {
28
29 $storage = $this->get_storage();
30 if (!empty($storage)) return $storage;
31
32 global $updraftplus;
33
34 if (!class_exists('UpdraftPlus_CF_Authentication')) include_once(UPDRAFTPLUS_DIR.'/includes/cloudfiles/cloudfiles.php');
35
36 if (!defined('UPDRAFTPLUS_SSL_DISABLEVERIFY')) define('UPDRAFTPLUS_SSL_DISABLEVERIFY', UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'));
37
38 $auth = new UpdraftPlus_CF_Authentication($user, trim($apikey), null, $authurl);
39
40 $updraftplus->log("Cloud Files authentication URL: $authurl");
41
42 $auth->authenticate();
43
44 $storage = new UpdraftPlus_CF_Connection($auth);
45
46 if (!$useservercerts) $storage->ssl_use_cabundle(UPDRAFTPLUS_DIR.'/includes/cacert.pem');
47
48 $this->set_storage($storage);
49
50 return $storage;
51
52 }
53
54 /**
55 * This method overrides the parent method and lists the supported features of this remote storage option.
56 *
57 * @return Array - an array of supported features (any features not
58 * mentioned are assumed to not be supported)
59 */
60 public function get_supported_features() {
61 // This options format is handled via only accessing options via $this->get_options()
62 return array('multi_options', 'config_templates', 'multi_storage');
63 }
64
65 /**
66 * Retrieve default options for this remote storage module.
67 *
68 * @return Array - an array of options
69 */
70 public function get_default_options() {
71 return array(
72 'user' => '',
73 'authurl' => 'https://auth.api.rackspacecloud.com',
74 'apikey' => '',
75 'path' => '',
76 'region' => null
77 );
78 }
79
80 public function backup($backup_array) {
81
82 global $updraftplus, $updraftplus_backup;
83
84 $opts = $this->get_options();
85
86 $updraft_dir = $updraftplus->backups_dir_location().'/';
87
88 $container = $opts['path'];
89
90 try {
91 $storage = $this->getCF($opts['user'], $opts['apikey'], $opts['authurl'], UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'));
92 $container_object = $storage->create_container($container);
93 } catch (AuthenticationException $e) {
94 $updraftplus->log('Cloud Files authentication failed ('.$e->getMessage().')');
95 $updraftplus->log(sprintf(__('%s authentication failed', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
96 return false;
97 } catch (NoSuchAccountException $s) {
98 $updraftplus->log('Cloud Files authentication failed ('.$e->getMessage().')');
99 $updraftplus->log(sprintf(__('%s authentication failed', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
100 return false;
101 } catch (Exception $e) {
102 $updraftplus->log('Cloud Files error - failed to create and access the container ('.$e->getMessage().')');
103 $updraftplus->log(__('Cloud Files error - failed to create and access the container', 'updraftplus').' ('.$e->getMessage().')', 'error');
104 return false;
105 }
106
107 $chunk_size = 5*1024*1024;
108
109 foreach ($backup_array as $key => $file) {
110
111 $fullpath = $updraft_dir.$file;
112 $orig_file_size = filesize($fullpath);
113
114 // $cfpath = ($path == '') ? $file : "$path/$file";
115 // $chunk_path = ($path == '') ? "chunk-do-not-delete-$file" : "$path/chunk-do-not-delete-$file";
116 $cfpath = $file;
117 $chunk_path = "chunk-do-not-delete-$file";
118
119 try {
120 $object = new UpdraftPlus_CF_Object($container_object, $cfpath);
121 $object->content_type = "application/zip";
122
123 $uploaded_size = (isset($object->content_length)) ? $object->content_length : 0;
124
125 if ($uploaded_size <= $orig_file_size) {
126
127 $fp = @fopen($fullpath, "rb");
128 if (!$fp) {
129 $updraftplus->log("Cloud Files: failed to open file: $fullpath");
130 $updraftplus->log("$file: ".sprintf(__('%s Error: Failed to open local file', 'updraftplus'), 'Cloud Files'), 'error');
131 return false;
132 }
133
134 $chunks = floor($orig_file_size / $chunk_size);
135 // There will be a remnant unless the file size was exactly on a 5MB boundary
136 if ($orig_file_size % $chunk_size > 0) $chunks++;
137
138 $updraftplus->log("Cloud Files upload: $file (chunks: $chunks) -> cloudfiles://$container/$cfpath ($uploaded_size)");
139
140 if ($chunks < 2) {
141 try {
142 $object->load_from_filename($fullpath);
143 $updraftplus->log("Cloud Files regular upload: success");
144 $updraftplus->uploaded_file($file);
145 } catch (Exception $e) {
146 $updraftplus->log("Cloud Files regular upload: failed ($file) (".$e->getMessage().")");
147 $updraftplus->log("$file: ".sprintf(__('%s Error: Failed to upload', 'updraftplus'), 'Cloud Files'), 'error');
148 }
149 } else {
150 $errors_so_far = 0;
151 for ($i = 1; $i <= $chunks; $i++) {
152 $upload_start = ($i-1)*$chunk_size;
153 // The file size -1 equals the byte offset of the final byte
154 $upload_end = min($i*$chunk_size-1, $orig_file_size-1);
155 $upload_remotepath = $chunk_path."_$i";
156 // Don't forget the +1; otherwise the last byte is omitted
157 $upload_size = $upload_end - $upload_start + 1;
158 $chunk_object = new UpdraftPlus_CF_Object($container_object, $upload_remotepath);
159 $chunk_object->content_type = "application/zip";
160 // Without this, some versions of Curl add Expect: 100-continue, which results in Curl then giving this back: curl error: 55) select/poll returned error
161 // Didn't make the difference - instead we just check below for actual success even when Curl reports an error
162 // $chunk_object->headers = array('Expect' => '');
163
164 $remote_size = (isset($chunk_object->content_length)) ? $chunk_object->content_length : 0;
165
166 if ($remote_size >= $upload_size) {
167 $updraftplus->log("Cloud Files: Chunk $i ($upload_start - $upload_end): already uploaded");
168 } else {
169 $updraftplus->log("Cloud Files: Chunk $i ($upload_start - $upload_end): begin upload");
170 // Upload the chunk
171 fseek($fp, $upload_start);
172 try {
173 $chunk_object->write($fp, $upload_size, false);
174 $updraftplus->record_uploaded_chunk(round(100*$i/$chunks, 1), $i, $fullpath);
175 } catch (Exception $e) {
176 $updraftplus->log("Cloud Files chunk upload: error: ($file / $i) (".$e->getMessage().")");
177 // Experience shows that Curl sometimes returns a select/poll error (curl error 55) even when everything succeeded. Google seems to indicate that this is a known bug.
178
179 $chunk_object = new UpdraftPlus_CF_Object($container_object, $upload_remotepath);
180 $chunk_object->content_type = "application/zip";
181 $remote_size = (isset($chunk_object->content_length)) ? $chunk_object->content_length : 0;
182
183 if ($remote_size >= $upload_size) {
184
185 $updraftplus->log("$file: Chunk now exists; ignoring error (presuming it was an apparently known curl bug)");
186
187 } else {
188
189 $updraftplus->log("$file: ".sprintf(__('%s Error: Failed to upload', 'updraftplus'), 'Cloud Files'), 'error');
190 $errors_so_far++;
191 if ($errors_so_far >=3) return false;
192
193 }
194
195 }
196 }
197 }
198 if ($errors_so_far) return false;
199 // All chunks are uploaded - now upload the manifest
200
201 try {
202 $object->manifest = $container."/".$chunk_path."_";
203 // Put a zero-length file
204 $object->write("", 0, false);
205 $object->sync_manifest();
206 $updraftplus->log("Cloud Files upload: success");
207 $updraftplus->uploaded_file($file);
208 // } catch (InvalidResponseException $e) {
209 } catch (Exception $e) {
210 $updraftplus->log('Cloud Files error - failed to re-assemble chunks ('.$e->getMessage().')');
211 $updraftplus->log(sprintf(__('%s error - failed to re-assemble chunks', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
212 return false;
213 }
214 }
215 }
216
217 } catch (Exception $e) {
218 $updraftplus->log(__('Cloud Files error - failed to upload file', 'updraftplus').' ('.$e->getMessage().')');
219 $updraftplus->log(sprintf(__('%s error - failed to upload file', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
220 return false;
221 }
222
223 }
224
225 return array('cloudfiles_object' => $container_object, 'cloudfiles_orig_path' => $opts['path'], 'cloudfiles_container' => $container);
226
227 }
228
229 public function listfiles($match = 'backup_') {
230
231 $opts = $this->get_options();
232 $container = $opts['path'];
233
234 if (empty($opts['user']) || empty($opts['apikey'])) new WP_Error('no_settings', __('No settings were found', 'updraftplus'));
235
236 try {
237 $storage = $this->getCF($opts['user'], $opts['apikey'], $opts['authurl'], UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'));
238 $container_object = $storage->create_container($container);
239 } catch (Exception $e) {
240 return new WP_Error('no_access', sprintf(__('%s authentication failed', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')');
241 }
242
243 $results = array();
244
245 try {
246 $objects = $container_object->list_objects(0, null, $match);
247 foreach ($objects as $name) {
248 $result = array('name' => $name);
249 try {
250 $object = new UpdraftPlus_CF_Object($container_object, $name, true);
251 if (0 == $object->content_length) {
252 $result = false;
253 } else {
254 $result['size'] = $object->content_length;
255 }
256 } catch (Exception $e) {
257 // Catch
258 }
259 if (is_array($result)) $results[] = $result;
260 }
261 } catch (Exception $e) {
262 return new WP_Error('cf_error', 'Cloud Files error ('.$e->getMessage().')');
263 }
264
265 return $results;
266
267 }
268
269 public function delete($files, $cloudfilesarr = false, $sizeinfo = array()) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
270
271 global $updraftplus;
272 if (is_string($files)) $files =array($files);
273
274 if ($cloudfilesarr) {
275 $container_object = $cloudfilesarr['cloudfiles_object'];
276 $container = $cloudfilesarr['cloudfiles_container'];
277 $path = $cloudfilesarr['cloudfiles_orig_path'];
278 } else {
279 try {
280 $opts = $this->get_options();
281 $container = $opts['path'];
282 $storage = $this->getCF($opts['user'], $opts['apikey'], $opts['authurl'], UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'));
283 $container_object = $storage->create_container($container);
284 } catch (Exception $e) {
285 $updraftplus->log('Cloud Files authentication failed ('.$e->getMessage().')');
286 $updraftplus->log(sprintf(__('%s authentication failed', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
287 return false;
288 }
289 }
290
291 $ret = true;
292 foreach ($files as $file) {
293
294 $fpath = $file;
295
296 $updraftplus->log("Cloud Files: Delete remote: container=$container, path=$fpath");
297
298 // We need to search for chunks
299 // $chunk_path = ($path == '') ? "chunk-do-not-delete-$file_" : "$path/chunk-do-not-delete-$file_";
300 $chunk_path = "chunk-do-not-delete-$file";
301
302 try {
303 $objects = $container_object->list_objects(0, null, $chunk_path.'_');
304 foreach ($objects as $chunk) {
305 $updraftplus->log('Cloud Files: Chunk to delete: '.$chunk);
306 $container_object->delete_object($chunk);
307 $updraftplus->log('Cloud Files: Chunk deleted: '.$chunk);
308 }
309 } catch (Exception $e) {
310 $updraftplus->log('Cloud Files chunk delete failed: '.$e->getMessage());
311 }
312
313 try {
314 $container_object->delete_object($fpath);
315 $updraftplus->log('Cloud Files: Deleted: '.$fpath);
316 } catch (Exception $e) {
317 $updraftplus->log('Cloud Files delete failed: '.$e->getMessage());
318 $ret = false;
319 }
320 }
321 return $ret;
322 }
323
324 public function download($file) {
325
326 global $updraftplus;
327 $updraft_dir = $updraftplus->backups_dir_location();
328
329 $opts = $this->get_options();
330
331 try {
332 $storage = $this->getCF($opts['user'], $opts['apikey'], $opts['authurl'], UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'));
333 } catch (AuthenticationException $e) {
334 $updraftplus->log('Cloud Files authentication failed ('.$e->getMessage().')');
335 $updraftplus->log(sprintf(__('%s authentication failed', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
336 return false;
337 } catch (NoSuchAccountException $s) {
338 $updraftplus->log('Cloud Files authentication failed ('.$e->getMessage().')');
339 $updraftplus->log(sprintf(__('%s authentication failed', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
340 return false;
341 } catch (Exception $e) {
342 $updraftplus->log('Cloud Files error - failed to create and access the container ('.$e->getMessage().')');
343 $updraftplus->log(__('Cloud Files error - failed to create and access the container', 'updraftplus').' ('.$e->getMessage().')', 'error');
344 return false;
345 }
346
347 $path = untrailingslashit($opts['path']);
348
349 $container = $path;
350
351 try {
352 $container_object = $storage->create_container($container);
353 } catch (Exception $e) {
354 $updraftplus->log('Cloud Files error - failed to create and access the container ('.$e->getMessage().')');
355 $updraftplus->log(__('Cloud Files error - failed to create and access the container', 'updraftplus').' ('.$e->getMessage().')', 'error');
356 return false;
357 }
358
359 $path = $file;
360
361 $updraftplus->log("Cloud Files download: cloudfiles://$container/$path");
362
363 try {
364 // The third parameter causes an exception to be thrown if the object does not exist remotely
365 $object = new UpdraftPlus_CF_Object($container_object, $path, true);
366
367 $fullpath = $updraft_dir.'/'.$file;
368
369 $start_offset = (file_exists($fullpath)) ? filesize($fullpath) : 0;
370
371 // Get file size from remote - see if we've already finished
372
373 $remote_size = $object->content_length;
374
375 if ($start_offset >= $remote_size) {
376 $updraftplus->log("Cloud Files: file is already completely downloaded ($start_offset/$remote_size)");
377 return true;
378 }
379
380 // Some more remains to download - so let's do it
381 if (!$fh = fopen($fullpath, 'a')) {
382 $updraftplus->log("Cloud Files: Error opening local file: $fullpath");
383 $updraftplus->log(sprintf("$file: ".__("%s Error", 'updraftplus'), 'Cloud Files').": ".__('Error opening local file: Failed to download', 'updraftplus'), 'error');
384 return false;
385 }
386
387 $headers = array();
388 // If resuming, then move to the end of the file
389 if ($start_offset) {
390 $updraftplus->log("Cloud Files: local file is already partially downloaded ($start_offset/$remote_size)");
391 fseek($fh, $start_offset);
392 $headers['Range'] = "bytes=$start_offset-";
393 }
394
395 // Now send the request itself
396 try {
397 $object->stream($fh, $headers);
398 } catch (Exception $e) {
399 $updraftplus->log("Cloud Files: Failed to download: $file (".$e->getMessage().")");
400 $updraftplus->log("$file: ".sprintf(__("%s Error", 'updraftplus'), 'Cloud Files').": ".__('Error downloading remote file: Failed to download', 'updraftplus').' ('.$e->getMessage().")", 'error');
401 return false;
402 }
403
404 // All-in-one-go method:
405 // $object->save_to_filename($fullpath);
406
407 } catch (NoSuchObjectException $e) {
408 $updraftplus->log('Cloud Files error - no such file exists at Cloud Files ('.$e->getMessage().')');
409 $updraftplus->log(sprintf(__('Error - no such file exists at %s', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
410 return false;
411 } catch (Exception $e) {
412 $updraftplus->log('Cloud Files error - failed to download the file ('.$e->getMessage().')');
413 $updraftplus->log(sprintf(__('Error - failed to download the file from %s', 'updraftplus'), 'Cloud Files').' ('.$e->getMessage().')', 'error');
414 return false;
415 }
416
417 return true;
418
419 }
420
421 /**
422 * Get the pre configuration template
423 *
424 * @return String - the template
425 */
426 public function get_pre_configuration_template() {
427
428 global $updraftplus_admin;
429
430 $classes = $this->get_css_classes(false);
431
432 ?>
433 <tr class="<?php echo $classes . ' ' . 'cloudfiles_pre_config_container';?>">
434 <td colspan="2">
435 <img alt="Rackspace Cloud Files" src="<?php echo UPDRAFTPLUS_URL;?>/images/rackspacecloud-logo.png"><br>
436 <?php
437 // Check requirements.
438 global $updraftplus_admin;
439 if (!function_exists('mb_substr')) {
440 $updraftplus_admin->show_double_warning('<strong>'.__('Warning', 'updraftplus').':</strong> '.sprintf(__('Your web server\'s PHP installation does not included a required module (%s). Please contact your web hosting provider\'s support.', 'updraftplus'), 'mbstring').' '.sprintf(__("UpdraftPlus's %s module <strong>requires</strong> %s. Please do not file any support requests; there is no alternative.", 'updraftplus'), 'Cloud Files', 'mbstring'), 'cloudfiles', false);
441 }
442 $updraftplus_admin->curl_check('Rackspace Cloud Files', false, 'cloudfiles', false);
443 ?>
444
445 <?php
446 echo '<p>' . __('Get your API key <a href="https://mycloud.rackspace.com/" target="_blank">from your Rackspace Cloud console</a> (read instructions <a href="http://www.rackspace.com/knowledge_center/article/rackspace-cloud-essentials-1-generating-your-api-key" target="_blank">here</a>), then pick a container name to use for storage. This container will be created for you if it does not already exist.', 'updraftplus').' <a href="https://updraftplus.com/faqs/there-appear-to-be-lots-of-extra-files-in-my-rackspace-cloud-files-container/" target="_blank">'.__('Also, you should read this important FAQ.', 'updraftplus').'</a></p>';
447 ?>
448 </td>
449 </tr>
450
451 <?php
452 }
453
454 /**
455 * Get the configuration template
456 *
457 * @return String - the template, ready for substitutions to be carried out
458 */
459 public function get_configuration_template() {
460 $classes = $this->get_css_classes();
461 $template_str = '
462 <tr class="'.$classes.'">
463 <th>'.__('US or UK Cloud', 'updraftplus').':</th>
464 <td>
465 <select data-updraft_settings_test="authurl" '.$this->output_settings_field_name_and_id('authurl', true).'>
466 <option {{#ifeq "https://auth.api.rackspacecloud.com" authurl}}selected="selected"{{/ifeq}} value="https://auth.api.rackspacecloud.com">'.__('US (default)', 'updraftplus').'</option>
467 <option {{#ifeq "https://lon.auth.api.rackspacecloud.com" authurl}}selected="selected"{{/ifeq}} value="https://lon.auth.api.rackspacecloud.com">'.__('UK', 'updraftplus').'</option>
468 </select>
469 </td>
470 </tr>
471 <input type="hidden" data-updraft_settings_test="region" '.$this->output_settings_field_name_and_id('region', true).' value="">';
472
473 /*
474 // Can put a message here if someone asks why region storage is not available (only available on new SDK)
475 <tr class="updraftplusmethod cloudfiles">
476 <th><?php _e('Rackspace Storage Region','updraftplus');?>:</th>
477 <td>
478 </td>
479 </tr>
480 */
481 $template_str .= '
482 <tr class="'.$classes.'">
483 <th>'.__('Cloud Files username', 'updraftplus').':</th>
484 <td><input data-updraft_settings_test="user" type="text" autocomplete="off" class="updraft_input--wide" '.$this->output_settings_field_name_and_id('user', true).' value="{{user}}" /></td>
485 </tr>
486 <tr class="'.$classes.'">
487 <th>'.__('Cloud Files API Key', 'updraftplus').':</th>
488 <td><input data-updraft_settings_test="apikey" type="'.apply_filters('updraftplus_admin_secret_field_type', 'password').'" autocomplete="off" class="updraft_input--wide" '.$this->output_settings_field_name_and_id('apikey', true).' value="{{apikey}}" />
489 </td>
490 </tr>
491 <tr class="'.$classes.'">
492 <th>'.apply_filters('updraftplus_cloudfiles_location_description', __('Cloud Files Container', 'updraftplus')).':</th>
493 <td><input data-updraft_settings_test="path" type="text" class="updraft_input--wide" '.$this->output_settings_field_name_and_id('path', true).' value="{{path}}" /></td>
494 </tr>';
495 $template_str .= $this->get_test_button_html(__('Cloud Files', 'updraftplus'));
496 return $template_str;
497 }
498
499 /**
500 * Modifies handerbar template options
501 *
502 * @param array $opts handerbar template options
503 * @return array - Modified handerbar template options
504 */
505 public function transform_options_for_template($opts) {
506 $opts['apikey'] = trim($opts['apikey']);
507 $opts['authurl'] = isset($opts['authurl']) ? $opts['authurl'] : '';
508 return $opts;
509 }
510
511 /**
512 * Perform a test of user-supplied credentials, and echo the result
513 *
514 * @param Array $posted_settings - settings to test
515 */
516 public function credentials_test($posted_settings) {
517
518 if (empty($posted_settings['apikey'])) {
519 printf(__("Failure: No %s was given.", 'updraftplus'), __('API key', 'updraftplus'));
520 return;
521 }
522
523 if (empty($posted_settings['user'])) {
524 printf(__("Failure: No %s was given.", 'updraftplus'), __('Username', 'updraftplus'));
525 return;
526 }
527
528 $key = $posted_settings['apikey'];
529 $user = $posted_settings['user'];
530 $path = $posted_settings['path'];
531 $authurl = $posted_settings['authurl'];
532 $useservercerts = $posted_settings['useservercerts'];
533 $disableverify = $posted_settings['disableverify'];
534
535 if (preg_match("#^([^/]+)/(.*)$#", $path, $bmatches)) {
536 $container = $bmatches[1];
537 $path = $bmatches[2];
538 } else {
539 $container = $path;
540 $path = "";
541 }
542
543 if (empty($container)) {
544 _e("Failure: No container details were given.", 'updraftplus');
545 return;
546 }
547
548 define('UPDRAFTPLUS_SSL_DISABLEVERIFY', $disableverify);
549
550 try {
551 $storage = $this->getCF($user, $key, $authurl, $useservercerts);
552 $container_object = $storage->create_container($container);
553 } catch (AuthenticationException $e) {
554 echo __('Cloud Files authentication failed', 'updraftplus').' ('.$e->getMessage().')';
555 return;
556 } catch (NoSuchAccountException $s) {
557 echo __('Cloud Files authentication failed', 'updraftplus').' ('.$e->getMessage().')';
558 return;
559 } catch (Exception $e) {
560 echo __('Cloud Files authentication failed', 'updraftplus').' ('.$e->getMessage().')';
561 return;
562 }
563
564 $try_file = md5(rand()).'.txt';
565
566 try {
567 $object = $container_object->create_object($try_file);
568 $object->content_type = "text/plain";
569 $object->write('UpdraftPlus test file');
570 } catch (Exception $e) {
571 echo __('Cloud Files error - we accessed the container, but failed to create a file within it', 'updraftplus').' ('.$e->getMessage().')';
572 return;
573 }
574
575 echo __('Success', 'updraftplus').": ".__('We accessed the container, and were able to create files within it.', 'updraftplus');
576
577 @$container_object->delete_object($try_file);
578 }
579 }
580
581 // Moved to the bottom to fix a bug in some version or install of PHP which required UpdraftPlus_BackupModule_cloudfiles_oldsdk to be defined earlier in the file (despite the conditionality) - see HS#19911
582 if (version_compare(PHP_VERSION, '5.3.3', '>=') && (!defined('UPDRAFTPLUS_CLOUDFILES_USEOLDSDK') || UPDRAFTPLUS_CLOUDFILES_USEOLDSDK != true)) {
583 include_once(UPDRAFTPLUS_DIR.'/methods/cloudfiles-new.php');
584 class UpdraftPlus_BackupModule_cloudfiles extends UpdraftPlus_BackupModule_cloudfiles_opencloudsdk {
585 }
586 } else {
587 class UpdraftPlus_BackupModule_cloudfiles extends UpdraftPlus_BackupModule_cloudfiles_oldsdk {
588 }
589 }
590