| 1 |
<?php |
| 2 |
/** |
| 3 |
* Destination form. |
| 4 |
* |
| 5 |
* @package wpdbbkp |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
$update_msg = ''; |
| 12 |
if ( true === isset( $_POST['wpdb_amazon_s3'] ) && 'Y' === $_POST['wpdb_amazon_s3'] ) { |
| 13 |
// Validate that the contents of the form request came from the current site and not somewhere else added 21-08-15 V.3.4. |
| 14 |
if ( ! isset( $_POST['wpdbbackup_update_amazon_setting'] ) ) { |
| 15 |
wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') ); |
| 16 |
} |
| 17 |
if ( ! wp_verify_nonce( $_POST['wpdbbackup_update_amazon_setting'] , 'wpdbbackup-update-amazon-setting' ) ) { |
| 18 |
wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') ); |
| 19 |
} |
| 20 |
|
| 21 |
// Save the posted value in the database. |
| 22 |
if ( true === isset( $_POST['wpdb_dest_amazon_s3_bucket'] ) ) { |
| 23 |
update_option( 'wpdb_dest_amazon_s3_bucket', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_amazon_s3_bucket'] ) ) ), false ); |
| 24 |
} |
| 25 |
if ( true === isset( $_POST['wpdb_dest_amazon_s3_bucket_key'] ) ) { |
| 26 |
update_option( 'wpdb_dest_amazon_s3_bucket_key', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_amazon_s3_bucket_key'] ) ) ) , false); |
| 27 |
} |
| 28 |
if ( true === isset( $_POST['wpdb_dest_amazon_s3_bucket_secret'] ) ) { |
| 29 |
update_option( 'wpdb_dest_amazon_s3_bucket_secret', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_amazon_s3_bucket_secret'] ) ) ), false ); |
| 30 |
} |
| 31 |
if ( isset( $_POST['wp_db_backup_destination_s3'] ) ) { |
| 32 |
update_option( 'wp_db_backup_destination_s3', 1 , false); |
| 33 |
} else { |
| 34 |
update_option( 'wp_db_backup_destination_s3', 0 , false); |
| 35 |
} |
| 36 |
// Put a "settings updated" message on the screen. |
| 37 |
$update_msg = '<div class="updated"><p><strong>Your amazon s3 setting has been saved.</strong></p></div>'; |
| 38 |
} |
| 39 |
$wp_db_backup_destination_s3 = get_option( 'wp_db_backup_destination_s3',0); |
| 40 |
$wpdb_dest_amazon_s3_bucket = get_option( 'wpdb_dest_amazon_s3_bucket',null); |
| 41 |
$wpdb_dest_amazon_s3_bucket_key = get_option( 'wpdb_dest_amazon_s3_bucket_key',null); |
| 42 |
$wpdb_dest_amazon_s3_bucket_secret = get_option( 'wpdb_dest_amazon_s3_bucket_secret',null); |
| 43 |
|
| 44 |
$wpdbbkp_amazon_s3_status = '<label><b>Status</b>: Not Configured </label> '; |
| 45 |
if($wp_db_backup_destination_s3==1 && !empty($wpdb_dest_amazon_s3_bucket) && !empty($wpdb_dest_amazon_s3_bucket_key) && !empty($wpdb_dest_amazon_s3_bucket_secret)) |
| 46 |
{ |
| 47 |
$wpdbbkp_amazon_s3_status='<label><b>Status</b>: <span class="dashicons dashicons-yes-alt" style="color:green;font-size:16px" title="Destination enabled"></span><span class="configured">Configured </span> </label> '; |
| 48 |
} |
| 49 |
|
| 50 |
?> |
| 51 |
<div class="panel panel-default"> |
| 52 |
<div class="panel-heading"> |
| 53 |
<h4 class="panel-title"> |
| 54 |
<a data-toggle="collapse" data-parent="#accordion" href="#collapseAmazon"> |
| 55 |
<h2><?php echo esc_html__('Amazon S3', 'wpdbbkp') ?> <?php echo $wpdbbkp_amazon_s3_status;?> <span class="dashicons dashicons-admin-generic"></span></h2> |
| 56 |
|
| 57 |
</a> |
| 58 |
</h4> |
| 59 |
</div> |
| 60 |
<div id="collapseAmazon" class="panel-collapse collapse"> |
| 61 |
<div class="panel-body"> |
| 62 |
<?php |
| 63 |
echo esc_html( $update_msg ); |
| 64 |
|
| 65 |
if ( get_option( 'wpdb_dest_amazon_s3_bucket_key' ) && get_option( 'wpdb_dest_amazon_s3_bucket_secret' ) ) { |
| 66 |
|
| 67 |
try { |
| 68 |
if ( ! class_exists( 'S3' ) ) { |
| 69 |
require_once 'S3.php'; |
| 70 |
} |
| 71 |
|
| 72 |
// AWS access info. |
| 73 |
if ( ! defined( 'AWSACCESSKEY' ) ) { |
| 74 |
define( 'AWSACCESSKEY', get_option( 'wpdb_dest_amazon_s3_bucket_key' ) ); |
| 75 |
} |
| 76 |
if ( ! defined( 'AWSSECRETKEY' ) ) { |
| 77 |
define( 'AWSSECRETKEY', get_option( 'wpdb_dest_amazon_s3_bucket_secret' ) ); |
| 78 |
} |
| 79 |
|
| 80 |
// Check for CURL. |
| 81 |
if ( ! extension_loaded( 'curl' ) && ! @dl( 'so' === PHP_SHLIB_SUFFIX ? 'curl.so' : 'php_curl.dll' ) ) { // phpcs:ignore |
| 82 |
echo "ERROR: CURL extension not loaded\n\n"; |
| 83 |
} |
| 84 |
|
| 85 |
$s3 = new S3( AWSACCESSKEY, AWSSECRETKEY ); |
| 86 |
$result = $s3->listBuckets(); |
| 87 |
if ( get_option( 'wpdb_dest_amazon_s3_bucket' ) ) { |
| 88 |
if (!empty($result) && false === in_array( get_option( 'wpdb_dest_amazon_s3_bucket' ), $result, true ) ) { |
| 89 |
echo '<span class="label label-warning">Invalid bucket name or AWS details</span>'; |
| 90 |
} |
| 91 |
} |
| 92 |
} catch ( Exception $e ) { |
| 93 |
echo '<span class="label label-warning">Invalid AWS details</span>'; |
| 94 |
} |
| 95 |
} |
| 96 |
?> |
| 97 |
<p> <?php echo esc_html__('Back up WordPress database to Amazon S3.', 'wpdbbkp') ?></p> |
| 98 |
<p><?php echo esc_html__('Enter your Amazon S3 details for your offsite backup. Leave these blank for local backups OR Disable Amazon S3 Destination', 'wpdbbkp') ?></p> |
| 99 |
<form class="form-group" name="amazons3" method="post" action=""> |
| 100 |
|
| 101 |
<div class="row form-group"> |
| 102 |
<label class="col-sm-2" for="wp_db_backup_destination_s3"><?php echo esc_html__('Enable Amazon S3 Destination:', 'wpdbbkp') ?></label> |
| 103 |
<div class="col-sm-6"> |
| 104 |
<input type="checkbox" id="wp_db_backup_destination_s3" <?php echo ( true === isset( $wp_db_backup_destination_s3 ) && 1 === $wp_db_backup_destination_s3 ) ? 'checked' : ''; ?> name="wp_db_backup_destination_s3"> |
| 105 |
</div> |
| 106 |
|
| 107 |
</div> |
| 108 |
<input type="hidden" name="wpdb_amazon_s3" value="Y"> |
| 109 |
<input name="wpdbbackup_update_amazon_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-amazon-setting' ) ); ?>" /> |
| 110 |
<?php wp_nonce_field( 'wp-database-backup' ); ?> |
| 111 |
<div class="row form-group"> |
| 112 |
<label class="col-sm-2" for="wpdb_dest_amazon_s3_bucket"><?php echo esc_html__('Bucket Name:', 'wpdbbkp') ?></label> |
| 113 |
<div class="col-sm-6"> |
| 114 |
|
| 115 |
<input type="text" id="wpdb_dest_amazon_s3_bucket" class="form-control" name="wpdb_dest_amazon_s3_bucket" value="<?php echo esc_html( get_option( 'wpdb_dest_amazon_s3_bucket' ) ); ?>" size="25" placeholder="Buket name"> |
| 116 |
<a href="http://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a> |
| 117 |
</div> |
| 118 |
</div> |
| 119 |
|
| 120 |
<div class="row form-group"> |
| 121 |
<label class="col-sm-2" for="wpdb_dest_amazon_s3_bucket_key"><?php echo esc_html__('Key:', 'wpdbbkp') ?></label> |
| 122 |
<div class="col-sm-6"> |
| 123 |
<input type="text" id="wpdb_dest_amazon_s3_bucket_key" class="form-control" name="wpdb_dest_amazon_s3_bucket_key" value="<?php echo esc_html( get_option( 'wpdb_dest_amazon_s3_bucket_key' ) ); ?>" size="25" placeholder="your access key id"> |
| 124 |
<a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a> |
| 125 |
</div> |
| 126 |
</div> |
| 127 |
|
| 128 |
<div class="row form-group"> |
| 129 |
<label class="col-sm-2" for="wpdb_dest_amazon_s3_bucket_secret"><?php echo esc_html__('Secret:', 'wpdbbkp') ?></label> |
| 130 |
<div class="col-sm-6"> |
| 131 |
<input type="text" id="wpdb_dest_amazon_s3_bucket_secret" class="form-control" name="wpdb_dest_amazon_s3_bucket_secret" value="<?php echo esc_html( get_option( 'wpdb_dest_amazon_s3_bucket_secret' ) ); ?>" size="25" placeholder="your secret access key"> |
| 132 |
<a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a> |
| 133 |
</div> |
| 134 |
</div> |
| 135 |
|
| 136 |
<p><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Save' , 'wpdbbkp' ); ?>" /> |
| 137 |
</p> |
| 138 |
</form> |
| 139 |
|
| 140 |
</div> |
| 141 |
</div> |
| 142 |
</div> |
| 143 |
|