| 1 |
<?php |
| 2 |
/** |
| 3 |
* Destination form. |
| 4 |
* |
| 5 |
* @package wpdbbkp |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
$wpdbbkp_update_msg = ''; |
| 13 |
if ( true === isset( $_POST['wpdb_bb_s3'] ) && 'Y' === $_POST['wpdb_bb_s3'] ) { |
| 14 |
// Validate that the contents of the form request came from the current site and not somewhere else added 21-08-15 V.3.4. |
| 15 |
if ( ! isset( $_POST['wpdbbackup_update_bb_setting'] ) ) { |
| 16 |
wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') ); |
| 17 |
} |
| 18 |
if ( ! wp_verify_nonce( wp_unslash( $_POST['wpdbbackup_update_bb_setting'] ) , 'wpdbbackup-update-bb-setting' ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- using as nonce |
| 19 |
wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') ); |
| 20 |
} |
| 21 |
|
| 22 |
// Save the posted value in the database. |
| 23 |
if ( true === isset( $_POST['wpdb_dest_bb_s3_bucket_host'] ) ) { |
| 24 |
update_option( 'wpdb_dest_bb_s3_bucket_host', wpdbbkp_filter_data( sanitize_url( wp_unslash( $_POST['wpdb_dest_bb_s3_bucket_host'] ) ) ), false ); |
| 25 |
} |
| 26 |
if ( true === isset( $_POST['wpdb_dest_bb_s3_bucket'] ) ) { |
| 27 |
update_option( 'wpdb_dest_bb_s3_bucket', wpdbbkp_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_bb_s3_bucket'] ) ) ), false ); |
| 28 |
} |
| 29 |
if ( true === isset( $_POST['wpdb_dest_bb_s3_bucket_key'] ) ) { |
| 30 |
update_option( 'wpdb_dest_bb_s3_bucket_key', wpdbbkp_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_bb_s3_bucket_key'] ) ) ) , false); |
| 31 |
} |
| 32 |
if ( true === isset( $_POST['wpdb_dest_bb_s3_bucket_secret'] ) ) { |
| 33 |
update_option( 'wpdb_dest_bb_s3_bucket_secret', wpdbbkp_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_bb_s3_bucket_secret'] ) ) ), false ); |
| 34 |
} |
| 35 |
if ( isset( $_POST['wp_db_backup_destination_bb'] ) ) { |
| 36 |
update_option( 'wp_db_backup_destination_bb', 1 , false); |
| 37 |
} else { |
| 38 |
update_option( 'wp_db_backup_destination_bb', 0 , false); |
| 39 |
} |
| 40 |
|
| 41 |
if ( isset( $_POST['wp_db_incremental_backup'] ) ) { |
| 42 |
update_option( 'wp_db_incremental_backup', 1 , false); |
| 43 |
} else { |
| 44 |
update_option( 'wp_db_incremental_backup', 0 , false); |
| 45 |
} |
| 46 |
// Put a "settings updated" message on the screen. |
| 47 |
$wpdbbkp_update_msg = esc_html__('Your Blackblaze S3 setting has been saved.' , 'wpdbbkp'); |
| 48 |
} |
| 49 |
$wpdbbkp_destination_bb = get_option( 'wp_db_backup_destination_bb',0); |
| 50 |
$wpdb_dest_bb_s3_bucket_host = get_option( 'wpdb_dest_bb_s3_bucket_host',null); |
| 51 |
$wpdb_dest_bb_s3_bucket = get_option( 'wpdb_dest_bb_s3_bucket',null); |
| 52 |
$wpdb_dest_bb_s3_bucket_key = get_option( 'wpdb_dest_bb_s3_bucket_key',null); |
| 53 |
$wpdb_dest_bb_s3_bucket_secret = get_option( 'wpdb_dest_bb_s3_bucket_secret',null); |
| 54 |
$wpdbbkp_incremental_backup = get_option( 'wp_db_incremental_backup', 0 ); |
| 55 |
if ( 1 === (int) get_option( 'wp_db_incremental_backup', 0 ) ) { |
| 56 |
$wpdbbkp_incremental_backup = 'checked'; |
| 57 |
} else { |
| 58 |
$wpdbbkp_incremental_backup = ''; |
| 59 |
} |
| 60 |
|
| 61 |
$wpdbbkp_bb_s3_status = '<label><b>'.esc_html__('Status', 'wpdbbkp').'</b>: '.esc_html__('Not Configured', 'wpdbbkp').' </label> '; |
| 62 |
|
| 63 |
if($wpdbbkp_destination_bb == 1 && !empty($wpdb_dest_bb_s3_bucket) && !empty($wpdb_dest_bb_s3_bucket_key) && !empty($wpdb_dest_bb_s3_bucket_secret) && !empty($wpdb_dest_bb_s3_bucket_host)) |
| 64 |
{ |
| 65 |
$wpdbbkp_bb_s3_status ='<label><b>'.esc_html__('Status', 'wpdbbkp').'</b>: <span class="dashicons dashicons-yes-alt" style="color:green;font-size:16px" title="'.esc_attr__('Destination enabled', 'wpdbbkp').'"></span><span class="configured">'.esc_html__('Configured', 'wpdbbkp').' </span> </label> '; |
| 66 |
} |
| 67 |
|
| 68 |
?> |
| 69 |
<div class="panel panel-default"> |
| 70 |
<div class="panel-heading"> |
| 71 |
<h4 class="panel-title"> |
| 72 |
<a data-toggle="collapse" data-parent="#accordion" href="#collapsebb"> |
| 73 |
<h2><?php echo esc_html__('Blackblaze', 'wpdbbkp') ?> <?php echo wp_kses_post($wpdbbkp_bb_s3_status);?> <span class="dashicons dashicons-admin-generic"></span></h2> |
| 74 |
|
| 75 |
</a> |
| 76 |
</h4> |
| 77 |
</div> |
| 78 |
<div id="collapsebb" class="panel-collapse collapse"> |
| 79 |
<div class="panel-body"> |
| 80 |
<?php |
| 81 |
if($wpdbbkp_update_msg){ |
| 82 |
echo '<div class="updated"><p><strong>'.esc_html( $wpdbbkp_update_msg ).'</strong></p></div>'; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
if ( get_option( 'wpdb_dest_bb_s3_bucket_key' ) && get_option( 'wpdb_dest_bb_s3_bucket_secret' ) ) { |
| 87 |
|
| 88 |
try { |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
// Check for CURL. |
| 93 |
if ( ! extension_loaded( 'curl' ) && ! @dl( 'so' === PHP_SHLIB_SUFFIX ? 'curl.so' : 'php_curl.dll' ) ) { // phpcs:ignore |
| 94 |
echo esc_html__("ERROR: CURL extension not loaded\n\n", 'wpdbbkp'); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
$wpdbbkp_b2_authorize_url = 'https://api.backblazeb2.com/b2api/v2/b2_authorize_account'; |
| 99 |
$wpdbbkp_credentials = base64_encode( $wpdb_dest_bb_s3_bucket_key . ':' . $wpdb_dest_bb_s3_bucket_secret ); |
| 100 |
|
| 101 |
// Authorize account |
| 102 |
$wpdbbkp_response = wp_remote_get( |
| 103 |
$wpdbbkp_b2_authorize_url, |
| 104 |
array( |
| 105 |
'headers' => array( |
| 106 |
'Authorization' => 'Basic ' . $wpdbbkp_credentials, |
| 107 |
), |
| 108 |
'timeout' => 60, // Extend timeout |
| 109 |
) |
| 110 |
); |
| 111 |
|
| 112 |
if ( ! is_wp_error( $wpdbbkp_response ) ) { |
| 113 |
$wpdbbkp_body = wp_remote_retrieve_body( $wpdbbkp_response ); |
| 114 |
$wpdbbkp_data = json_decode( $wpdbbkp_body ); |
| 115 |
} |
| 116 |
|
| 117 |
if ( is_wp_error( $wpdbbkp_response ) || empty( $wpdbbkp_data->authorizationToken ) ) { |
| 118 |
echo '<span class="label label-warning">'.esc_html__( 'Invalid bucket name or Backblaze details' ,'wpdbbkp').'</span>'; |
| 119 |
} |
| 120 |
|
| 121 |
} catch ( Exception $e ) { |
| 122 |
echo '<span class="label label-warning">'.esc_html__( 'Invalid details' ,'wpdbbkp').'</span>'; |
| 123 |
} |
| 124 |
} |
| 125 |
?> |
| 126 |
<p> <?php echo esc_html__('Back up WordPress to Blackblaze.', 'wpdbbkp') ?></p> |
| 127 |
<p><?php echo esc_html__('Enter your Blackblaze details for your offsite backup. Leave these blank for local backups OR Disable Blackblaze Destination', 'wpdbbkp') ?></p> |
| 128 |
<form class="form-group" name="Blackblazes3" method="post" action=""> |
| 129 |
|
| 130 |
<div class="row form-group"> |
| 131 |
<label class="col-sm-2" for="wp_db_backup_destination_bb"><?php echo esc_html__('Enable Blackblaze Destination', 'wpdbbkp') ?></label> |
| 132 |
<div class="col-sm-6"> |
| 133 |
<input type="checkbox" id="wp_db_backup_destination_bb" <?php echo ( 1 == $wpdbbkp_destination_bb ) ? 'checked' : ''; ?> name="wp_db_backup_destination_bb"> |
| 134 |
</div> |
| 135 |
|
| 136 |
</div> |
| 137 |
<input type="hidden" name="wpdb_bb_s3" value="Y"> |
| 138 |
<input name="wpdbbackup_update_bb_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-bb-setting' ) ); ?>" /> |
| 139 |
<?php wp_nonce_field( 'wp-database-backup' ); ?> |
| 140 |
<div class="row form-group conditional_fields"> |
| 141 |
<label class="col-sm-2" for="wpdb_dest_bb_s3_bucket"><?php echo esc_html__('Bucket Endpoint', 'wpdbbkp') ?></label> |
| 142 |
<div class="col-sm-6"> |
| 143 |
|
| 144 |
<input type="text" id="wpdb_dest_bb_s3_bucket_host" class="form-control" name="wpdb_dest_bb_s3_bucket_host" value="<?php echo esc_html( get_option( 'wpdb_dest_bb_s3_bucket_host' ) ); ?>" size="25" placeholder="<?php esc_attr_e('Endpoint : https://s3.us-west-002.backblazeb2.com','wpdbbkp');?>"> |
| 145 |
<a href="https://www.backblaze.com/apidocs/introduction-to-the-s3-compatible-api" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a> |
| 146 |
</div> |
| 147 |
</div> |
| 148 |
<div class="row form-group conditional_fields"> |
| 149 |
<label class="col-sm-2" for="wpdb_dest_bb_s3_bucket"><?php echo esc_html__('Bucket ID', 'wpdbbkp') ?></label> |
| 150 |
<div class="col-sm-6"> |
| 151 |
|
| 152 |
<input type="text" id="wpdb_dest_bb_s3_bucket" class="form-control" name="wpdb_dest_bb_s3_bucket" value="<?php echo esc_html( get_option( 'wpdb_dest_bb_s3_bucket' ) ); ?>" size="25" placeholder="<?php esc_attr_e('Bucket ID', 'wpdbbkp');?>"> |
| 153 |
<a href="https://www.backblaze.com/apidocs/introduction-to-the-s3-compatible-api" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a> |
| 154 |
</div> |
| 155 |
</div> |
| 156 |
|
| 157 |
<div class="row form-group conditional_fields"> |
| 158 |
<label class="col-sm-2" for="wpdb_dest_bb_s3_bucket_key"><?php echo esc_html__('Key', 'wpdbbkp') ?></label> |
| 159 |
<div class="col-sm-6"> |
| 160 |
<input type="text" id="wpdb_dest_bb_s3_bucket_key" class="form-control" name="wpdb_dest_bb_s3_bucket_key" value="<?php echo esc_html( get_option( 'wpdb_dest_bb_s3_bucket_key' ) ); ?>" size="25" placeholder="<?php esc_attr_e('your access key id', 'wpdbbkp');?>"> |
| 161 |
<a href="https://www.backblaze.com/apidocs/introduction-to-the-s3-compatible-api" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
|
| 165 |
<div class="row form-group conditional_fields"> |
| 166 |
<label class="col-sm-2" for="wpdb_dest_bb_s3_bucket_secret"><?php echo esc_html__('Secret', 'wpdbbkp') ?></label> |
| 167 |
<div class="col-sm-6"> |
| 168 |
<input type="text" id="wpdb_dest_bb_s3_bucket_secret" class="form-control" name="wpdb_dest_bb_s3_bucket_secret" value="<?php echo esc_html( get_option( 'wpdb_dest_bb_s3_bucket_secret' ) ); ?>" size="25" placeholder="<?php esc_attr_e('your secret access key', 'wpdbbkp');?>"> |
| 169 |
<a href="https://www.backblaze.com/apidocs/introduction-to-the-s3-compatible-api" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a> |
| 170 |
</div> |
| 171 |
</div> |
| 172 |
|
| 173 |
<div class="row form-group conditional_fields"> |
| 174 |
<label class="col-sm-2" for="wpdb_dest_bb_s3_bucket"><?php echo esc_html__('Enable Incremental backup', 'wpdbbkp') ?></label> |
| 175 |
<div class="col-sm-10"> |
| 176 |
|
| 177 |
<input type="checkbox" <?php echo esc_attr( $wpdbbkp_incremental_backup ); ?> name="wp_db_incremental_backup"><br><?php echo esc_html__('Only updated files will be backedup after first backup is complete. This feature is currently available for Blackblaze backup method', 'wpdbbkp') ?> |
| 178 |
</div> |
| 179 |
|
| 180 |
</div> |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
<p><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Save' , 'wpdbbkp' ); ?>" /> |
| 185 |
</p> |
| 186 |
</form> |
| 187 |
<script> |
| 188 |
jQuery(document).ready(function(){ |
| 189 |
if(jQuery('#wp_db_backup_destination_bb').is(':checked')){ |
| 190 |
jQuery('.conditional_fields').show(); |
| 191 |
}else{ |
| 192 |
jQuery('.conditional_fields').hide(); |
| 193 |
} |
| 194 |
jQuery('#wp_db_backup_destination_bb').change(function(){ |
| 195 |
if(jQuery(this).is(':checked')){ |
| 196 |
jQuery('.conditional_fields').show(); |
| 197 |
}else{ |
| 198 |
jQuery('.conditional_fields').hide(); |
| 199 |
} |
| 200 |
}); |
| 201 |
}); |
| 202 |
</script> |
| 203 |
|
| 204 |
</div> |
| 205 |
</div> |
| 206 |
</div> |
| 207 |
|