PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 6.11
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v6.11
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / includes / admin / Destination / Backblaze / bb-form.php

bb-form.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 6.11, at includes/admin/Destination/Backblaze/bb-form.php

166 lines 8.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 $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( $_POST['wpdbbackup_update_bb_setting'] , 'wpdbbackup-update-bb-setting' ) ) {
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', wp_db_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', wp_db_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', wp_db_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', wp_db_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 // Put a "settings updated" message on the screen.
41 $update_msg = 'Your Blackblaze S3 setting has been saved.';
42 }
43 $wp_db_backup_destination_bb = get_option( 'wp_db_backup_destination_bb',0);
44 $wpdb_dest_bb_s3_bucket_host = get_option( 'wpdb_dest_bb_s3_bucket_host',null);
45 $wpdb_dest_bb_s3_bucket = get_option( 'wpdb_dest_bb_s3_bucket',null);
46 $wpdb_dest_bb_s3_bucket_key = get_option( 'wpdb_dest_bb_s3_bucket_key',null);
47 $wpdb_dest_bb_s3_bucket_secret = get_option( 'wpdb_dest_bb_s3_bucket_secret',null);
48
49 $wpdbbkp_bb_s3_status = '<label><b>Status</b>: Not Configured </label> ';
50
51 if($wp_db_backup_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))
52 {
53 $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> ';
54 }
55
56 ?>
57 <div class="panel panel-default">
58 <div class="panel-heading">
59 <h4 class="panel-title">
60 <a data-toggle="collapse" data-parent="#accordion" href="#collapsebb">
61 <h2><?php echo esc_html__('Blackblaze S3', 'wpdbbkp') ?> <?php echo $wpdbbkp_bb_s3_status;?> <span class="dashicons dashicons-admin-generic"></span></h2>
62
63 </a>
64 </h4>
65 </div>
66 <div id="collapsebb" class="panel-collapse collapse">
67 <div class="panel-body">
68 <?php
69 if($update_msg){
70 echo '<div class="updated"><p><strong>'.esc_html( $update_msg ).'</strong></p></div>';
71 }
72
73
74 if ( get_option( 'wpdb_dest_bb_s3_bucket_key' ) && get_option( 'wpdb_dest_bb_s3_bucket_secret' ) ) {
75
76 try {
77
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 esc_html__("ERROR: CURL extension not loaded\n\n", 'wpdbbkp');
83 }
84
85
86 $b2_authorize_url = "https://api.backblazeb2.com/b2api/v2/b2_authorize_account";
87 $credentials = base64_encode($wpdb_dest_bb_s3_bucket_key . ":" . $wpdb_dest_bb_s3_bucket_secret);
88
89 // Authorize account
90 $response = wp_remote_get($b2_authorize_url, array(
91 'headers' => array(
92 'Authorization' => 'Basic ' . $credentials
93 ),
94 'timeout' => 60 // Extend timeout
95 ));
96
97 if(!is_wp_error($response)){
98 $body = wp_remote_retrieve_body($response);
99 $data = json_decode($body);
100 }
101
102
103 if(is_wp_error($response) || empty($data->authorizationToken)){
104 echo '<span class="label label-warning">'.esc_html__( 'Invalid bucket name or Backblaze details' ,'wpdbbkp').'</span>';
105 }
106
107 } catch ( Exception $e ) {
108 echo '<span class="label label-warning">'.esc_html__( 'Invalid details' ,'wpdbbkp').'</span>';
109 }
110 }
111 ?>
112 <p> <?php echo esc_html__('Back up WordPress database to Blackblaze S3.', 'wpdbbkp') ?></p>
113 <p><?php echo esc_html__('Enter your Blackblaze S3 details for your offsite backup. Leave these blank for local backups OR Disable Blackblaze S3 Destination', 'wpdbbkp') ?></p>
114 <form class="form-group" name="Blackblazes3" method="post" action="">
115
116 <div class="row form-group">
117 <label class="col-sm-2" for="wp_db_backup_destination_bb"><?php echo esc_html__('Enable Blackblaze S3 Destination:', 'wpdbbkp') ?></label>
118 <div class="col-sm-6">
119 <input type="checkbox" id="wp_db_backup_destination_bb" <?php echo ( 1 == $wp_db_backup_destination_bb ) ? 'checked' : ''; ?> name="wp_db_backup_destination_bb">
120 </div>
121
122 </div>
123 <input type="hidden" name="wpdb_bb_s3" value="Y">
124 <input name="wpdbbackup_update_bb_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-bb-setting' ) ); ?>" />
125 <?php wp_nonce_field( 'wp-database-backup' ); ?>
126 <div class="row form-group">
127 <label class="col-sm-2" for="wpdb_dest_bb_s3_bucket"><?php echo esc_html__('Bucket Endpoint:', 'wpdbbkp') ?></label>
128 <div class="col-sm-6">
129
130 <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="Endpoint : https://s3.us-west-002.backblazeb2.com">
131 <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>
132 </div>
133 </div>
134 <div class="row form-group">
135 <label class="col-sm-2" for="wpdb_dest_bb_s3_bucket"><?php echo esc_html__('Bucket ID:', 'wpdbbkp') ?></label>
136 <div class="col-sm-6">
137
138 <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__('Bucket ID', 'wpdbbkp');?>">
139 <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>
140 </div>
141 </div>
142
143 <div class="row form-group">
144 <label class="col-sm-2" for="wpdb_dest_bb_s3_bucket_key"><?php echo esc_html__('Key:', 'wpdbbkp') ?></label>
145 <div class="col-sm-6">
146 <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__('your access key id', 'wpdbbkp');?>">
147 <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>
148 </div>
149 </div>
150
151 <div class="row form-group">
152 <label class="col-sm-2" for="wpdb_dest_bb_s3_bucket_secret"><?php echo esc_html__('Secret:', 'wpdbbkp') ?></label>
153 <div class="col-sm-6">
154 <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__('your secret access key', 'wpdbbkp');?>">
155 <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>
156 </div>
157 </div>
158
159 <p><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Save' , 'wpdbbkp' ); ?>" />&nbsp;
160 </p>
161 </form>
162
163 </div>
164 </div>
165 </div>
166