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