| 1 |
<?php |
| 2 |
|
| 3 |
# Migrate options to new-style storage - Jan 2014 |
| 4 |
if (!is_array(UpdraftPlus_Options::get_updraft_option('updraft_s3')) && '' != UpdraftPlus_Options::get_updraft_option('updraft_s3_login', '')) { |
| 5 |
$opts = array( |
| 6 |
'accesskey' => UpdraftPlus_Options::get_updraft_option('updraft_s3_login'), |
| 7 |
'secretkey' => UpdraftPlus_Options::get_updraft_option('updraft_s3_pass'), |
| 8 |
'path' => UpdraftPlus_Options::get_updraft_option('updraft_s3_remote_path') |
| 9 |
); |
| 10 |
UpdraftPlus_Options::update_updraft_option('updraft_s3', $opts); |
| 11 |
UpdraftPlus_Options::delete_updraft_option('updraft_s3_login'); |
| 12 |
UpdraftPlus_Options::delete_updraft_option('updraft_s3_pass'); |
| 13 |
UpdraftPlus_Options::delete_updraft_option('updraft_s3_remote_path'); |
| 14 |
} |
| 15 |
|
| 16 |
class UpdraftPlus_BackupModule_s3 { |
| 17 |
|
| 18 |
protected function get_config() { |
| 19 |
global $updraftplus; |
| 20 |
$opts = $updraftplus->get_job_option('updraft_s3'); |
| 21 |
if (!is_array($opts)) $opts = array('accesskey' => '', 'secretkey' => '', 'path' => ''); |
| 22 |
$opts['whoweare'] = 'S3'; |
| 23 |
$opts['whoweare_long'] = 'Amazon S3'; |
| 24 |
$opts['key'] = 's3'; |
| 25 |
return $opts; |
| 26 |
} |
| 27 |
|
| 28 |
public function get_credentials() { |
| 29 |
return array('updraft_s3'); |
| 30 |
} |
| 31 |
|
| 32 |
// Get an S3 object, after setting our options |
| 33 |
protected function getS3($key, $secret, $useservercerts, $disableverify, $nossl) { |
| 34 |
global $updraftplus; |
| 35 |
|
| 36 |
if (!class_exists('UpdraftPlus_S3')) require_once(UPDRAFTPLUS_DIR.'/includes/S3.php'); |
| 37 |
|
| 38 |
if (!class_exists('WP_HTTP_Proxy')) require_once(ABSPATH.'wp-includes/class-http.php'); |
| 39 |
$proxy = new WP_HTTP_Proxy(); |
| 40 |
$s3 = new UpdraftPlus_S3($key, $secret); |
| 41 |
|
| 42 |
if ( $proxy->is_enabled()) { |
| 43 |
# WP_HTTP_Proxy returns empty strings where we want nulls |
| 44 |
$user = $proxy->username(); |
| 45 |
if (empty($user)) { |
| 46 |
$user = null; |
| 47 |
$pass = null; |
| 48 |
} else { |
| 49 |
$pass = $proxy->password(); |
| 50 |
if (empty($pass)) $pass = null; |
| 51 |
} |
| 52 |
$port = (int)$proxy->port(); |
| 53 |
if (empty($port)) $port = 8080; |
| 54 |
$s3->setProxy($proxy->host(), $user, $pass, CURLPROXY_HTTP, $port); |
| 55 |
} |
| 56 |
|
| 57 |
if (!$nossl) { |
| 58 |
$curl_version = (function_exists('curl_version')) ? curl_version() : array('features' => null); |
| 59 |
$curl_ssl_supported= ($curl_version['features'] & CURL_VERSION_SSL); |
| 60 |
if ($curl_ssl_supported) { |
| 61 |
$s3->useSSL = true; |
| 62 |
if ($disableverify) { |
| 63 |
$s3->useSSLValidation = false; |
| 64 |
$updraftplus->log("S3: Disabling verification of SSL certificates"); |
| 65 |
} |
| 66 |
if ($useservercerts) { |
| 67 |
$updraftplus->log("S3: Using the server's SSL certificates"); |
| 68 |
} else { |
| 69 |
$s3->SSLCACert = UPDRAFTPLUS_DIR.'/includes/cacert.pem'; |
| 70 |
} |
| 71 |
} else { |
| 72 |
$updraftplus->log("S3: Curl/SSL is not available. Communications will not be encrypted."); |
| 73 |
} |
| 74 |
} else { |
| 75 |
$s3->useSSL = false; |
| 76 |
$updraftplus->log("SSL was disabled via the user's preference. Communications will not be encrypted."); |
| 77 |
} |
| 78 |
return $s3; |
| 79 |
} |
| 80 |
|
| 81 |
protected function set_endpoint($obj, $region) { |
| 82 |
switch ($region) { |
| 83 |
case 'EU': |
| 84 |
case 'eu-west-1': |
| 85 |
$endpoint = 's3-eu-west-1.amazonaws.com'; |
| 86 |
break; |
| 87 |
case 'us-west-1': |
| 88 |
case 'us-west-2': |
| 89 |
case 'ap-southeast-1': |
| 90 |
case 'ap-southeast-2': |
| 91 |
case 'ap-northeast-1': |
| 92 |
case 'sa-east-1': |
| 93 |
case 'us-gov-west-1': |
| 94 |
$endpoint = 's3-'.$region.'.amazonaws.com'; |
| 95 |
break; |
| 96 |
case 'cn-north-1': |
| 97 |
$endpoint = 's3.'.$region.'.amazonaws.com.cn'; |
| 98 |
break; |
| 99 |
default: |
| 100 |
break; |
| 101 |
} |
| 102 |
if (isset($endpoint)) { |
| 103 |
global $updraftplus; |
| 104 |
$updraftplus->log("Set endpoint: $endpoint"); |
| 105 |
$obj->setEndpoint($endpoint); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
public function backup($backup_array) { |
| 110 |
|
| 111 |
global $updraftplus, $updraftplus_backup; |
| 112 |
|
| 113 |
$config = $this->get_config(); |
| 114 |
$whoweare = $config['whoweare']; |
| 115 |
$whoweare_key = $config['key']; |
| 116 |
$whoweare_keys = substr($whoweare_key, 0, 3); |
| 117 |
|
| 118 |
$s3 = $this->getS3( |
| 119 |
$config['accesskey'], |
| 120 |
$config['secretkey'], |
| 121 |
UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'), UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'), |
| 122 |
UpdraftPlus_Options::get_updraft_option('updraft_ssl_nossl') |
| 123 |
); |
| 124 |
|
| 125 |
$bucket_name = untrailingslashit($config['path']); |
| 126 |
$bucket_path = ""; |
| 127 |
$orig_bucket_name = $bucket_name; |
| 128 |
|
| 129 |
if (preg_match("#^([^/]+)/(.*)$#",$bucket_name,$bmatches)) { |
| 130 |
$bucket_name = $bmatches[1]; |
| 131 |
$bucket_path = $bmatches[2]."/"; |
| 132 |
} |
| 133 |
|
| 134 |
// This needs to cope with both original S3 and others (where there is no getBucketLocation()) |
| 135 |
$region = ($config['key'] == 's3') ? @$s3->getBucketLocation($bucket_name) : 'n/a'; |
| 136 |
|
| 137 |
// See if we can detect the region (which implies the bucket exists and is ours), or if not create it |
| 138 |
if (!empty($region) || @$s3->putBucket($bucket_name, UpdraftPlus_S3::ACL_PRIVATE)) { |
| 139 |
|
| 140 |
if (empty($region) && $config['key'] == 's3') $region = $s3->getBucketLocation($bucket_name); |
| 141 |
$this->set_endpoint($s3, $region); |
| 142 |
|
| 143 |
$updraft_dir = trailingslashit($updraftplus->backups_dir_location()); |
| 144 |
|
| 145 |
foreach($backup_array as $key => $file) { |
| 146 |
|
| 147 |
// We upload in 5Mb chunks to allow more efficient resuming and hence uploading of larger files |
| 148 |
// N.B.: 5Mb is Amazon's minimum. So don't go lower or you'll break it. |
| 149 |
$fullpath = $updraft_dir.$file; |
| 150 |
$orig_file_size = filesize($fullpath); |
| 151 |
$chunks = floor($orig_file_size / 5242880); |
| 152 |
// There will be a remnant unless the file size was exactly on a 5Mb boundary |
| 153 |
if ($orig_file_size % 5242880 > 0) $chunks++; |
| 154 |
$hash = md5($file); |
| 155 |
|
| 156 |
$updraftplus->log("$whoweare upload ($region): $file (chunks: $chunks) -> s3://$bucket_name/$bucket_path$file"); |
| 157 |
|
| 158 |
$filepath = $bucket_path.$file; |
| 159 |
|
| 160 |
// This is extra code for the 1-chunk case, but less overhead (no bothering with job data) |
| 161 |
if ($chunks < 2) { |
| 162 |
$s3->setExceptions(true); |
| 163 |
try { |
| 164 |
if (!$s3->putObjectFile($fullpath, $bucket_name, $filepath, UpdraftPlus_S3::ACL_PRIVATE, array(), array(), apply_filters('updraft_'.$whoweare_key.'_storageclass', UpdraftPlus_S3::STORAGE_CLASS_STANDARD, $s3, $config))) { |
| 165 |
$updraftplus->log("$whoweare regular upload: failed ($fullpath)"); |
| 166 |
$updraftplus->log("$file: ".sprintf(__('%s Error: Failed to upload','updraftplus'),$whoweare), 'error'); |
| 167 |
} else { |
| 168 |
$updraftplus->log("$whoweare regular upload: success"); |
| 169 |
$updraftplus->uploaded_file($file); |
| 170 |
} |
| 171 |
} catch (Exception $e) { |
| 172 |
$updraftplus->log("$file: ".sprintf(__('%s Error: Failed to upload','updraftplus'),$whoweare).": ".$e->getMessage().' (line: '.$e->getLine().', file: '.$e->getFile()); |
| 173 |
$updraftplus->log("$file: ".sprintf(__('%s Error: Failed to upload','updraftplus'),$whoweare), 'error'); |
| 174 |
} |
| 175 |
$s3->setExceptions(false); |
| 176 |
} else { |
| 177 |
|
| 178 |
// Retrieve the upload ID |
| 179 |
$uploadId = $updraftplus->jobdata_get("upd_${whoweare_keys}_${hash}_uid"); |
| 180 |
if (empty($uploadId)) { |
| 181 |
$s3->setExceptions(true); |
| 182 |
try { |
| 183 |
$uploadId = $s3->initiateMultipartUpload($bucket_name, $filepath, UpdraftPlus_S3::ACL_PRIVATE, array(), array(), apply_filters('updraft_'.$whoweare_key.'_storageclass', UpdraftPlus_S3::STORAGE_CLASS_STANDARD, $s3, $config)); |
| 184 |
} catch (Exception $e) { |
| 185 |
$updraftplus->log("$whoweare error whilst trying initiateMultipartUpload: ".$e->getMessage().' (line: '.$e->getLine().', file: '.$e->getFile().')'); |
| 186 |
$uploadId = false; |
| 187 |
} |
| 188 |
$s3->setExceptions(false); |
| 189 |
|
| 190 |
if (empty($uploadId)) { |
| 191 |
$updraftplus->log("$whoweare upload: failed: could not get uploadId for multipart upload ($filepath)"); |
| 192 |
$updraftplus->log(sprintf(__("%s upload: getting uploadID for multipart upload failed - see log file for more details",'updraftplus'),$whoweare), 'error'); |
| 193 |
continue; |
| 194 |
} else { |
| 195 |
$updraftplus->log("$whoweare chunked upload: got multipart ID: $uploadId"); |
| 196 |
$updraftplus->jobdata_set("upd_${whoweare_keys}_${hash}_uid", $uploadId); |
| 197 |
} |
| 198 |
} else { |
| 199 |
$updraftplus->log("$whoweare chunked upload: retrieved previously obtained multipart ID: $uploadId"); |
| 200 |
} |
| 201 |
|
| 202 |
$successes = 0; |
| 203 |
$etags = array(); |
| 204 |
for ($i = 1 ; $i <= $chunks; $i++) { |
| 205 |
# Shorted to upd here to avoid hitting the 45-character limit |
| 206 |
$etag = $updraftplus->jobdata_get("ud_${whoweare_keys}_${hash}_e$i"); |
| 207 |
if (strlen($etag) > 0) { |
| 208 |
$updraftplus->log("$whoweare chunk $i: was already completed (etag: $etag)"); |
| 209 |
$successes++; |
| 210 |
array_push($etags, $etag); |
| 211 |
} else { |
| 212 |
// Sanity check: we've seen a case where an overlap was truncating the file from underneath us |
| 213 |
if (filesize($fullpath) < $orig_file_size) { |
| 214 |
$updraftplus->log("$whoweare error: $key: chunk $i: file was truncated underneath us (orig_size=$orig_file_size, now_size=".filesize($fullpath).")"); |
| 215 |
$updraftplus->log(sprintf(__('%s error: file %s was shortened unexpectedly', 'updraftplus'), $whoweare, $fullpath), 'error'); |
| 216 |
} |
| 217 |
$etag = $s3->uploadPart($bucket_name, $filepath, $uploadId, $fullpath, $i); |
| 218 |
if ($etag !== false && is_string($etag)) { |
| 219 |
$updraftplus->record_uploaded_chunk(round(100*$i/$chunks,1), "$i, $etag", $fullpath); |
| 220 |
array_push($etags, $etag); |
| 221 |
$updraftplus->jobdata_set("ud_${whoweare_keys}_${hash}_e$i", $etag); |
| 222 |
$successes++; |
| 223 |
} else { |
| 224 |
$updraftplus->log("$whoweare chunk $i: upload failed"); |
| 225 |
$updraftplus->log(sprintf(__("%s chunk %s: upload failed",'updraftplus'),$whoweare, $i), 'error'); |
| 226 |
} |
| 227 |
} |
| 228 |
} |
| 229 |
if ($successes >= $chunks) { |
| 230 |
$updraftplus->log("$whoweare upload: all chunks uploaded; will now instruct $whoweare to re-assemble"); |
| 231 |
|
| 232 |
$s3->setExceptions(true); |
| 233 |
try { |
| 234 |
if ($s3->completeMultipartUpload($bucket_name, $filepath, $uploadId, $etags)) { |
| 235 |
$updraftplus->log("$whoweare upload ($key): re-assembly succeeded"); |
| 236 |
$updraftplus->uploaded_file($file); |
| 237 |
} else { |
| 238 |
$updraftplus->log("$whoweare upload ($key): re-assembly failed ($file)"); |
| 239 |
$updraftplus->log(sprintf(__('%s upload (%s): re-assembly failed (see log for more details)','updraftplus'),$whoweare, $key), 'error'); |
| 240 |
} |
| 241 |
} catch (Exception $e) { |
| 242 |
$updraftplus->log("$whoweare re-assembly error ($key): ".$e->getMessage().' (line: '.$e->getLine().', file: '.$e->getFile().')'); |
| 243 |
$updraftplus->log($e->getMessage().": ".sprintf(__('%s re-assembly error (%s): (see log file for more)','updraftplus'),$whoweare, $e->getMessage()), 'error'); |
| 244 |
} |
| 245 |
// Remember to unset, as the deletion code later reuses the object |
| 246 |
$s3->setExceptions(false); |
| 247 |
} else { |
| 248 |
$updraftplus->log("$whoweare upload: upload was not completely successful on this run"); |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
return array('s3_object' => $s3, 's3_orig_bucket_name' => $orig_bucket_name); |
| 253 |
} else { |
| 254 |
$updraftplus->log("$whoweare Error: Failed to create bucket $bucket_name."); |
| 255 |
$updraftplus->log(sprintf(__('%s Error: Failed to create bucket %s. Check your permissions and credentials.','updraftplus'),$whoweare, $bucket_name), 'error'); |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
public function delete($files, $s3arr = false) { |
| 260 |
|
| 261 |
global $updraftplus; |
| 262 |
if (is_string($files)) $files=array($files); |
| 263 |
|
| 264 |
$config = $this->get_config(); |
| 265 |
$whoweare = $config['whoweare']; |
| 266 |
|
| 267 |
if ($s3arr) { |
| 268 |
$s3 = $s3arr['s3_object']; |
| 269 |
$orig_bucket_name = $s3arr['s3_orig_bucket_name']; |
| 270 |
} else { |
| 271 |
|
| 272 |
$s3 = $this->getS3( |
| 273 |
$config['accesskey'], |
| 274 |
$config['secretkey'], |
| 275 |
UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'), UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'), |
| 276 |
UpdraftPlus_Options::get_updraft_option('updraft_ssl_nossl') |
| 277 |
); |
| 278 |
$bucket_name = untrailingslashit($config['path']); |
| 279 |
$orig_bucket_name = $bucket_name; |
| 280 |
|
| 281 |
if (preg_match("#^([^/]+)/(.*)$#",$bucket_name,$bmatches)) { |
| 282 |
$bucket_name = $bmatches[1]; |
| 283 |
$bucket_path = $bmatches[2]."/"; |
| 284 |
} |
| 285 |
|
| 286 |
$region = ($config['key'] == 'dreamobjects' || $config['key'] == 's3generic') ? 'n/a' : @$s3->getBucketLocation($bucket_name); |
| 287 |
if (!empty($region)) { |
| 288 |
$this->set_endpoint($s3, $region); |
| 289 |
} else { |
| 290 |
$updraftplus->log("$whoweare Error: Failed to access bucket $bucket_name. Check your permissions and credentials."); |
| 291 |
$updraftplus->log(sprintf(__('%s Error: Failed to access bucket %s. Check your permissions and credentials.','updraftplus'),$whoweare, $bucket_name), 'error'); |
| 292 |
return false; |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
$ret = true; |
| 297 |
|
| 298 |
foreach ($files as $file) { |
| 299 |
|
| 300 |
if (preg_match("#^([^/]+)/(.*)$#", $orig_bucket_name, $bmatches)) { |
| 301 |
$s3_bucket=$bmatches[1]; |
| 302 |
$s3_uri = $bmatches[2]."/".$file; |
| 303 |
} else { |
| 304 |
$s3_bucket = $orig_bucket_name; |
| 305 |
$s3_uri = $file; |
| 306 |
} |
| 307 |
$updraftplus->log("$whoweare: Delete remote: bucket=$s3_bucket, URI=$s3_uri"); |
| 308 |
|
| 309 |
$s3->setExceptions(true); |
| 310 |
try { |
| 311 |
if (!$s3->deleteObject($s3_bucket, $s3_uri)) { |
| 312 |
$updraftplus->log("$whoweare: Delete failed"); |
| 313 |
} |
| 314 |
} catch (Exception $e) { |
| 315 |
$updraftplus->log("$whoweare delete failed: ".$e->getMessage().' (line: '.$e->getLine().', file: '.$e->getFile().')'); |
| 316 |
$s3->setExceptions(false); |
| 317 |
$ret = false; |
| 318 |
} |
| 319 |
$s3->setExceptions(false); |
| 320 |
|
| 321 |
} |
| 322 |
|
| 323 |
return $ret; |
| 324 |
|
| 325 |
} |
| 326 |
|
| 327 |
public function download($file) { |
| 328 |
|
| 329 |
global $updraftplus; |
| 330 |
|
| 331 |
$config = $this->get_config(); |
| 332 |
$whoweare = $config['whoweare']; |
| 333 |
|
| 334 |
$s3 = $this->getS3( |
| 335 |
$config['accesskey'], |
| 336 |
$config['secretkey'], |
| 337 |
UpdraftPlus_Options::get_updraft_option('updraft_ssl_useservercerts'), UpdraftPlus_Options::get_updraft_option('updraft_ssl_disableverify'), |
| 338 |
UpdraftPlus_Options::get_updraft_option('updraft_ssl_nossl') |
| 339 |
); |
| 340 |
|
| 341 |
$bucket_name = untrailingslashit($config['path']); |
| 342 |
$bucket_path = ""; |
| 343 |
|
| 344 |
if (preg_match("#^([^/]+)/(.*)$#", $bucket_name, $bmatches)) { |
| 345 |
$bucket_name = $bmatches[1]; |
| 346 |
$bucket_path = $bmatches[2]."/"; |
| 347 |
} |
| 348 |
|
| 349 |
$region = ($config['key'] == 'dreamobjects' || $config['key'] == 's3generic') ? 'n/a' : @$s3->getBucketLocation($bucket_name); |
| 350 |
if (!empty($region)) { |
| 351 |
$this->set_endpoint($s3, $region); |
| 352 |
$fullpath = $updraftplus->backups_dir_location().'/'.$file; |
| 353 |
if (!$s3->getObject($bucket_name, $bucket_path.$file, $fullpath, true)) { |
| 354 |
$updraftplus->log("$whoweare Error: Failed to download $file. Check your permissions and credentials."); |
| 355 |
$updraftplus->log(sprintf(__('%s Error: Failed to download %s. Check your permissions and credentials.','updraftplus'),$whoweare, $file), 'error'); |
| 356 |
return false; |
| 357 |
} |
| 358 |
} else { |
| 359 |
$updraftplus->log("$whoweare Error: Failed to access bucket $bucket_name. Check your permissions and credentials."); |
| 360 |
$updraftplus->log(sprintf(__('%s Error: Failed to access bucket %s. Check your permissions and credentials.','updraftplus'),$whoweare, $bucket_name), 'error'); |
| 361 |
return false; |
| 362 |
} |
| 363 |
return true; |
| 364 |
|
| 365 |
} |
| 366 |
|
| 367 |
public function config_print_javascript_onready() { |
| 368 |
$this->config_print_javascript_onready_engine('s3', 'S3'); |
| 369 |
} |
| 370 |
|
| 371 |
public function config_print_javascript_onready_engine($key, $whoweare) { |
| 372 |
?> |
| 373 |
jQuery('#updraft-<?php echo $key; ?>-test').click(function(){ |
| 374 |
jQuery('#updraft-<?php echo $key; ?>-test').html('<?php echo esc_js(sprintf(__('Testing %s Settings...', 'updraftplus'),$whoweare)); ?>'); |
| 375 |
var data = { |
| 376 |
action: 'updraft_ajax', |
| 377 |
subaction: 'credentials_test', |
| 378 |
method: '<?php echo $key; ?>', |
| 379 |
nonce: '<?php echo wp_create_nonce('updraftplus-credentialtest-nonce'); ?>', |
| 380 |
apikey: jQuery('#updraft_<?php echo $key; ?>_apikey').val(), |
| 381 |
apisecret: jQuery('#updraft_<?php echo $key; ?>_apisecret').val(), |
| 382 |
path: jQuery('#updraft_<?php echo $key; ?>_path').val(), |
| 383 |
endpoint: jQuery('#updraft_<?php echo $key; ?>_endpoint').val(), |
| 384 |
disableverify: (jQuery('#updraft_ssl_disableverify').is(':checked')) ? 1 : 0, |
| 385 |
useservercerts: (jQuery('#updraft_ssl_useservercerts').is(':checked')) ? 1 : 0, |
| 386 |
nossl: (jQuery('#updraft_ssl_nossl').is(':checked')) ? 1 : 0, |
| 387 |
}; |
| 388 |
jQuery.post(ajaxurl, data, function(response) { |
| 389 |
jQuery('#updraft-<?php echo $key; ?>-test').html('<?php echo esc_js(sprintf(__('Test %s Settings', 'updraftplus'),$whoweare)); ?>'); |
| 390 |
alert('<?php echo esc_js(sprintf(__('%s settings test result:', 'updraftplus'), $whoweare));?> ' + response); |
| 391 |
}); |
| 392 |
}); |
| 393 |
<?php |
| 394 |
} |
| 395 |
|
| 396 |
public function config_print() { |
| 397 |
|
| 398 |
# White: https://d36cz9buwru1tt.cloudfront.net/Powered-by-Amazon-Web-Services.jpg |
| 399 |
$this->config_print_engine('s3', 'S3', 'Amazon S3', 'AWS', 'http://aws.amazon.com/console/', '<img src="http://awsmedia.s3.amazonaws.com/AWS_logo_poweredby_black_127px.png" alt="Amazon Web Services">'); |
| 400 |
|
| 401 |
} |
| 402 |
|
| 403 |
public function config_print_engine($key, $whoweare_short, $whoweare_long, $console_descrip, $console_url, $img_html = '', $include_endpoint_chooser = false) { |
| 404 |
|
| 405 |
$opts = $this->get_config(); |
| 406 |
?> |
| 407 |
<tr class="updraftplusmethod <?php echo $key; ?>"> |
| 408 |
<td></td> |
| 409 |
<td><?php echo $img_html ?><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'),$whoweare_long);?></em></p> |
| 410 |
<?php |
| 411 |
if ('s3generic' == $key) { |
| 412 |
_e('Examples of S3-compatible storage providers:').' '; |
| 413 |
echo '<a href="http://www.cloudian.com/">Cloudian</a>, '; |
| 414 |
echo '<a href="http://cloud.google.com/storage">Google Cloud Storage</a>, '; |
| 415 |
echo '<a href="https://www.mh.connectria.com/rp/order/cloud_storage_index">Connectria</a>, '; |
| 416 |
echo '<a href="http://www.constant.com/cloud/storage/">Constant</a>, '; |
| 417 |
echo '<a href="http://www.eucalyptus.com/eucalyptus-cloud/iaas">Eucalyptus</a>, '; |
| 418 |
echo '<a href="http://cloud.nifty.com/storage/">Nifty</a>, '; |
| 419 |
echo '<a href="http://www.ntt.com/cloudn/data/storage.html">Cloudn</a>'; |
| 420 |
echo ''.__('... and many more!', 'updraftplus').'<br>'; |
| 421 |
} |
| 422 |
?> |
| 423 |
</td> |
| 424 |
</tr> |
| 425 |
<tr class="updraftplusmethod <?php echo $key; ?>"> |
| 426 |
<th></th> |
| 427 |
<td> |
| 428 |
<?php |
| 429 |
global $updraftplus_admin; |
| 430 |
if (!class_exists('SimpleXMLElement')) { |
| 431 |
$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'), 'SimpleXMLElement').' '.sprintf(__("UpdraftPlus's %s module <strong>requires</strong> %s. Please do not file any support requests; there is no alternative.",'updraftplus'),$whoweare_long, 'SimpleXMLElement'), $key); |
| 432 |
} |
| 433 |
$updraftplus_admin->curl_check($whoweare_long, true, $key); |
| 434 |
?> |
| 435 |
|
| 436 |
</td> |
| 437 |
</tr> |
| 438 |
<tr class="updraftplusmethod <?php echo $key; ?>"> |
| 439 |
<th></th> |
| 440 |
<td> |
| 441 |
<p><?php if ($console_url) echo sprintf(__('Get your access key and secret key <a href="%s">from your %s console</a>, then pick a (globally unique - all %s users) bucket name (letters and numbers) (and optionally a path) to use for storage. This bucket will be created for you if it does not already exist.','updraftplus'), $console_url, $console_descrip, $whoweare_long);?> <a href="http://updraftplus.com/faqs/i-get-ssl-certificate-errors-when-backing-up-andor-restoring/"><?php _e('If you see errors about SSL certificates, then please go here for help.','updraftplus');?></a> <a href="http://updraftplus.com/faq-category/amazon-s3/"><?php if ('s3' == $key) echo sprintf(__('Other %s FAQs.', 'updraftplus'), 'S3');?></a></p> |
| 442 |
</td></tr> |
| 443 |
<?php if ($include_endpoint_chooser) { ?> |
| 444 |
<tr class="updraftplusmethod <?php echo $key; ?>"> |
| 445 |
<th><?php echo sprintf(__('%s end-point','updraftplus'), $whoweare_short);?>:</th> |
| 446 |
<td><input type="text" style="width: 336px" id="updraft_<?php echo $key; ?>_endpoint" name="updraft_<?php echo $key; ?>[endpoint]" value="<?php echo htmlspecialchars($opts['endpoint']); ?>" /></td> |
| 447 |
</tr> |
| 448 |
<?php } else { ?> |
| 449 |
<input type="hidden" id="updraft_<?php echo $key; ?>_endpoint" name="updraft_<?php echo $key; ?>_endpoint" value=""> |
| 450 |
<?php } ?> |
| 451 |
<tr class="updraftplusmethod <?php echo $key; ?>"> |
| 452 |
<th><?php echo sprintf(__('%s access key','updraftplus'), $whoweare_short);?>:</th> |
| 453 |
<td><input type="text" autocomplete="off" style="width: 336px" id="updraft_<?php echo $key; ?>_apikey" name="updraft_<?php echo $key; ?>[accesskey]" value="<?php echo htmlspecialchars($opts['accesskey']); ?>" /></td> |
| 454 |
</tr> |
| 455 |
<tr class="updraftplusmethod <?php echo $key; ?>"> |
| 456 |
<th><?php echo sprintf(__('%s secret key','updraftplus'), $whoweare_short);?>:</th> |
| 457 |
<td><input type="<?php echo apply_filters('updraftplus_admin_secret_field_type', 'text'); ?>" autocomplete="off" style="width: 336px" id="updraft_<?php echo $key; ?>_apisecret" name="updraft_<?php echo $key; ?>[secretkey]" value="<?php echo htmlspecialchars($opts['secretkey']); ?>" /></td> |
| 458 |
</tr> |
| 459 |
<tr class="updraftplusmethod <?php echo $key; ?>"> |
| 460 |
<th><?php echo sprintf(__('%s location','updraftplus'), $whoweare_short);?>:</th> |
| 461 |
<td><?php echo $key; ?>://<input title="<?php echo htmlspecialchars(__('Enter only a bucket name or a bucket and path. Examples: mybucket, mybucket/mypath', 'updraftplus')); ?>" type="text" style="width: 336px" name="updraft_<?php echo $key; ?>[path]" id="updraft_<?php echo $key; ?>_path" value="<?php echo htmlspecialchars($opts['path']); ?>" /></td> |
| 462 |
</tr> |
| 463 |
<?php do_action('updraft_'.$key.'_extra_storage_options', $opts); ?> |
| 464 |
<tr class="updraftplusmethod <?php echo $key; ?>"> |
| 465 |
<th></th> |
| 466 |
<td><p><button id="updraft-<?php echo $key; ?>-test" type="button" class="button-primary" style="font-size:18px !important"><?php echo sprintf(__('Test %s Settings','updraftplus'),$whoweare_short);?></button></p></td> |
| 467 |
</tr> |
| 468 |
|
| 469 |
<?php |
| 470 |
} |
| 471 |
|
| 472 |
public function credentials_test() { |
| 473 |
$this->credentials_test_engine($this->get_config()); |
| 474 |
} |
| 475 |
|
| 476 |
public function credentials_test_engine($config) { |
| 477 |
|
| 478 |
if (empty($_POST['apikey'])) { |
| 479 |
printf(__("Failure: No %s was given.",'updraftplus'),__('API key','updraftplus')); |
| 480 |
return; |
| 481 |
} |
| 482 |
if (empty($_POST['apisecret'])) { |
| 483 |
printf(__("Failure: No %s was given.",'updraftplus'),__('API secret','updraftplus')); |
| 484 |
return; |
| 485 |
} |
| 486 |
|
| 487 |
$key = $_POST['apikey']; |
| 488 |
$secret = stripslashes($_POST['apisecret']); |
| 489 |
$path = $_POST['path']; |
| 490 |
$useservercerts = (isset($_POST['useservercerts'])) ? absint($_POST['useservercerts']) : 0; |
| 491 |
$disableverify = (isset($_POST['disableverify'])) ? absint($_POST['disableverify']) : 0; |
| 492 |
$nossl = (isset($_POST['nossl'])) ? absint($_POST['nossl']) : 0; |
| 493 |
$endpoint = (isset($_POST['endpoint'])) ? $_POST['endpoint'] : ''; |
| 494 |
|
| 495 |
if (preg_match("#^([^/]+)/(.*)$#", $path, $bmatches)) { |
| 496 |
$bucket = $bmatches[1]; |
| 497 |
$path = $bmatches[2]; |
| 498 |
} else { |
| 499 |
$bucket = $path; |
| 500 |
$path = ""; |
| 501 |
} |
| 502 |
|
| 503 |
if (empty($bucket)) { |
| 504 |
_e("Failure: No bucket details were given.",'updraftplus'); |
| 505 |
return; |
| 506 |
} |
| 507 |
$whoweare = $config['whoweare']; |
| 508 |
|
| 509 |
$s3 = $this->getS3($key, $secret, $useservercerts, $disableverify, $nossl); |
| 510 |
|
| 511 |
$location = ('s3' == $config['key']) ? @$s3->getBucketLocation($bucket) : 'n/a'; |
| 512 |
if ('s3' != $config['key']) $this->set_endpoint($s3, $endpoint); |
| 513 |
|
| 514 |
if ($location && 'n/a' != $location) { |
| 515 |
if ('s3' == $config['key']) { |
| 516 |
$bucket_exists = true; |
| 517 |
$bucket_verb = __('Region','updraftplus').": $location: "; |
| 518 |
} else { |
| 519 |
$bucket_verb = ''; |
| 520 |
} |
| 521 |
} |
| 522 |
if (!isset($bucket_exists)) { |
| 523 |
$s3->setExceptions(true); |
| 524 |
try { |
| 525 |
$try_to_create_bucket = @$s3->putBucket($bucket, UpdraftPlus_S3::ACL_PRIVATE); |
| 526 |
} catch (UpdraftPlus_S3Exception $e) { |
| 527 |
$try_to_create_bucket = false; |
| 528 |
$s3_error = $e->getMessage(); |
| 529 |
} |
| 530 |
$s3->setExceptions(false); |
| 531 |
if ($try_to_create_bucket) { |
| 532 |
$bucket_verb = ''; |
| 533 |
$bucket_exists = true; |
| 534 |
} else { |
| 535 |
echo sprintf(__("Failure: We could not successfully access or create such a bucket. Please check your access credentials, and if those are correct then try another bucket name (as another %s user may already have taken your name).",'updraftplus'),$whoweare); |
| 536 |
if (isset($s3_error)) echo "\n\n".sprintf(__('The error reported by %s was:','updraftplus'), $config['key']).' '.$s3_error; |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
if (isset($bucket_exists)) { |
| 541 |
$try_file = md5(rand()); |
| 542 |
if ($config['key'] != 'dreamobjects' && $config['key'] != 's3generic') $this->set_endpoint($s3, $location); |
| 543 |
$s3->setExceptions(true); |
| 544 |
try { |
| 545 |
if (!$s3->putObjectString($try_file, $bucket, $path.$try_file)) { |
| 546 |
echo __('Failure','updraftplus').": ${bucket_verb}".__('We successfully accessed the bucket, but the attempt to create a file in it failed.','updraftplus'); |
| 547 |
} else { |
| 548 |
echo __('Success','updraftplus').": ${bucket_verb}".__('We accessed the bucket, and were able to create files within it.','updraftplus').' '; |
| 549 |
$comm_with = ($config['key'] == 's3generic') ? $endpoint : $config['whoweare_long']; |
| 550 |
if ($s3->useSSL) { |
| 551 |
echo sprintf(__('The communication with %s was encrypted.', 'updraftplus'), $comm_with); |
| 552 |
} else { |
| 553 |
echo sprintf(__('The communication with %s was not encrypted.', 'updraftplus'), $comm_with); |
| 554 |
} |
| 555 |
@$s3->deleteObject($bucket, $path.$try_file); |
| 556 |
} |
| 557 |
} catch (Exception $e) { |
| 558 |
echo __('Failure','updraftplus').": ${bucket_verb}".__('We successfully accessed the bucket, but the attempt to create a file in it failed.','updraftplus').' '.__('Please check your access credentials.','updraftplus').' ('.$e->getMessage().')'; |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
} |
| 563 |
|
| 564 |
} |
| 565 |
?> |
| 566 |
|