PluginProbe
UpdraftPlus: WP Backup & Migration Plugin / 1.13.6
UpdraftPlus: WP Backup & Migration Plugin v1.13.6
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.13.6, at methods/cloudfiles.php

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