PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.13
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.13
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 / GenericS3 / generics3-form.php

generics3-form.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 7.13, at includes/admin/Destination/GenericS3/generics3-form.php

208 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Destination Generic S3 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_generics3'] ) && 'Y' === $_POST['wpdb_generics3'] ) {
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_generics3_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_generics3_setting']) , 'wpdbbackup-update-generics3-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_generics3_endpoint'] ) ) {
24 update_option( 'wpdb_dest_generics3_endpoint', wpdbbkp_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_generics3_endpoint'] ) ) ), false );
25 }
26 if ( true === isset( $_POST['wpdb_dest_generics3_bucket'] ) ) {
27 update_option( 'wpdb_dest_generics3_bucket', wpdbbkp_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_generics3_bucket'] ) ) ), false );
28 }
29 if ( true === isset( $_POST['wpdb_dest_generics3_bucket_key'] ) ) {
30 update_option( 'wpdb_dest_generics3_bucket_key', wpdbbkp_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_generics3_bucket_key'] ) ) ) , false);
31 }
32 if ( true === isset( $_POST['wpdb_dest_generics3_bucket_secret'] ) ) {
33 update_option( 'wpdb_dest_generics3_bucket_secret', wpdbbkp_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_dest_generics3_bucket_secret'] ) ) ), false );
34 }
35 if ( isset( $_POST['wp_db_backup_destination_generics3'] ) ) {
36 update_option( 'wp_db_backup_destination_generics3', 1 , false);
37 } else {
38 update_option( 'wp_db_backup_destination_generics3', 0 , false);
39 }
40 // Put a "settings updated" message on the screen.
41 $wpdbbkp_update_msg = '<div class="updated"><p><strong>Your Generic S3 setting has been saved.</strong></p></div>';
42 }
43
44 $wpdbbkp_destination_generics3 = get_option( 'wp_db_backup_destination_generics3',0);
45 $wpdb_dest_generics3_endpoint = get_option( 'wpdb_dest_generics3_endpoint',null);
46 $wpdb_dest_generics3_bucket = get_option( 'wpdb_dest_generics3_bucket',null);
47 $wpdb_dest_generics3_bucket_key = get_option( 'wpdb_dest_generics3_bucket_key',null);
48 $wpdb_dest_generics3_bucket_secret = get_option( 'wpdb_dest_generics3_bucket_secret',null);
49
50 $wpdbbkp_generics3_status = '<label><b>'.esc_html__('Status','wpdbbkp').'</b>: '.esc_html__('Not Configured','wpdbbkp').' </label> ';
51 if($wpdbbkp_destination_generics3==1 && !empty($wpdb_dest_generics3_endpoint) && !empty($wpdb_dest_generics3_bucket) && !empty($wpdb_dest_generics3_bucket_key) && !empty($wpdb_dest_generics3_bucket_secret))
52 {
53 $wpdbbkp_generics3_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="#collapseGenericS3">
61 <h2><?php echo esc_html__('Generic S3 Compatible', 'wpdbbkp') ?> <?php echo wp_kses_post($wpdbbkp_generics3_status);?></h2>
62
63 </a>
64 </h4>
65 </div>
66 <div id="collapseGenericS3" class="panel-collapse collapse">
67 <div class="panel-body">
68 <?php
69 echo esc_html( $wpdbbkp_update_msg );
70
71 if ( get_option( 'wpdb_dest_generics3_bucket_key' ) && get_option( 'wpdb_dest_generics3_bucket_secret' ) && get_option( 'wpdb_dest_generics3_endpoint' ) ) {
72
73 try {
74 if ( ! class_exists( 'WPDatabaseBackupGenericS3Client' ) ) {
75 require_once plugin_dir_path( __FILE__ ) . 'class-wpdatabasebackupgenerics3.php';
76 }
77
78 // Generic S3 access info.
79 if ( ! defined( 'WPDBBKP_GENERICS3_ACCESS_KEY' ) ) {
80 define( 'WPDBBKP_GENERICS3_ACCESS_KEY', get_option( 'wpdb_dest_generics3_bucket_key' ) );
81 }
82 if ( ! defined( 'WPDBBKP_GENERICS3_SECRET_KEY' ) ) {
83 define( 'WPDBBKP_GENERICS3_SECRET_KEY', get_option( 'wpdb_dest_generics3_bucket_secret' ) );
84 }
85 if ( ! defined( 'WPDBBKP_GENERICS3_ENDPOINT' ) ) {
86 define( 'WPDBBKP_GENERICS3_ENDPOINT', get_option( 'wpdb_dest_generics3_endpoint' ) );
87 }
88
89 // Check for CURL.
90 if ( ! extension_loaded( 'curl' ) && ! @dl( 'so' === PHP_SHLIB_SUFFIX ? 'curl.so' : 'php_curl.dll' ) ) { // phpcs:ignore
91 echo "ERROR: CURL extension not loaded\n\n";
92 }
93
94 $wpdbbkp_s3 = new WPDatabaseBackupGenericS3Client( WPDBBKP_GENERICS3_ACCESS_KEY, WPDBBKP_GENERICS3_SECRET_KEY, WPDBBKP_GENERICS3_ENDPOINT );
95 $wpdbbkp_result = $wpdbbkp_s3->listBuckets();
96
97 if ( ! empty( $wpdbbkp_result ) && get_option( 'wpdb_dest_generics3_bucket' ) ) {
98 $wpdbbkp_bucket_found = false;
99 foreach ( $wpdbbkp_result as $wpdbbkp_bucket ) {
100 if ( $wpdbbkp_bucket['name'] === get_option( 'wpdb_dest_generics3_bucket' ) ) {
101 $wpdbbkp_bucket_found = true;
102 break;
103 }
104 }
105 if ( ! $wpdbbkp_bucket_found ) {
106 echo '<span class="label label-warning">'.esc_html__('Bucket not found or access denied','wpdbbkp').'</span>';
107 }
108 }
109 } catch ( Exception $e ) {
110 echo '<span class="label label-warning">'.esc_html__('Invalid Generic S3 details','wpdbbkp').'</span>';
111 }
112 }
113 ?>
114 <p> <?php echo esc_html__('Back up WordPress database to any S3-compatible storage provider.', 'wpdbbkp') ?></p>
115 <p><?php echo esc_html__('Enter your S3-compatible storage details for your offsite backup. This works with AWS S3, DigitalOcean Spaces, Linode Object Storage, Backblaze B2, MinIO, and other S3-compatible services. Leave these blank for local backups OR Disable Generic S3 Destination', 'wpdbbkp') ?></p>
116 <form class="form-group" name="generics3" method="post" action="">
117
118 <div class="row form-group">
119 <label class="col-sm-2" for="wp_db_backup_destination_generics3"><?php echo esc_html__('Enable Generic S3 Destination', 'wpdbbkp') ?></label>
120 <div class="col-sm-6">
121 <input type="checkbox" id="wp_db_backup_destination_generics3" <?php echo ( true == isset( $wpdbbkp_destination_generics3 ) && 1 == $wpdbbkp_destination_generics3 ) ? 'checked' : ''; ?> name="wp_db_backup_destination_generics3">
122 </div>
123
124 </div>
125 <input type="hidden" name="wpdb_generics3" value="Y">
126 <input name="wpdbbackup_update_generics3_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-generics3-setting' ) ); ?>" />
127 <?php wp_nonce_field( 'wp-database-backup' ); ?>
128
129 <div class="row form-group">
130 <label class="col-sm-2" for="wpdb_dest_generics3_endpoint"><?php echo esc_html__('Endpoint URL', 'wpdbbkp') ?></label>
131 <div class="col-sm-6">
132 <input type="text" id="wpdb_dest_generics3_endpoint" class="form-control" name="wpdb_dest_generics3_endpoint" value="<?php echo esc_html( get_option( 'wpdb_dest_generics3_endpoint' ) ); ?>" size="25" placeholder="<?php esc_attr_e('https://s3.region.amazonaws.com or https://region.digitaloceanspaces.com','wpdbbkp');?>">
133 <a href="https://docs.aws.amazon.com/general/latest/gr/s3.html" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
134 <p class="description"><?php echo esc_html__('Enter the endpoint URL for your S3-compatible storage. For AWS S3: https://s3.region.amazonaws.com', 'wpdbbkp') ?></p>
135 </div>
136 </div>
137
138 <div class="row form-group">
139 <label class="col-sm-2" for="wpdb_dest_generics3_bucket"><?php echo esc_html__('Bucket Name', 'wpdbbkp') ?></label>
140 <div class="col-sm-6">
141
142 <input type="text" id="wpdb_dest_generics3_bucket" class="form-control" name="wpdb_dest_generics3_bucket" value="<?php echo esc_html( get_option( 'wpdb_dest_generics3_bucket' ) ); ?>" size="25" placeholder="<?php esc_attr_e('your-bucket-name','wpdbbkp');?>">
143 <a href="https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
144 </div>
145 </div>
146
147 <div class="row form-group">
148 <label class="col-sm-2" for="wpdb_dest_generics3_bucket_key"><?php echo esc_html__('Access Key', 'wpdbbkp') ?></label>
149 <div class="col-sm-6">
150 <input type="text" id="wpdb_dest_generics3_bucket_key" class="form-control" name="wpdb_dest_generics3_bucket_key" value="<?php echo esc_html( get_option( 'wpdb_dest_generics3_bucket_key' ) ); ?>" size="25" placeholder="<?php esc_attr_e('your access key id','wpdbbkp');?>">
151 <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
152 </div>
153 </div>
154
155 <div class="row form-group">
156 <label class="col-sm-2" for="wpdb_dest_generics3_bucket_secret"><?php echo esc_html__('Secret Key', 'wpdbbkp') ?></label>
157 <div class="col-sm-6">
158 <input type="text" id="wpdb_dest_generics3_bucket_secret" class="form-control" name="wpdb_dest_generics3_bucket_secret" value="<?php echo esc_html( get_option( 'wpdb_dest_generics3_bucket_secret' ) ); ?>" size="25" placeholder="<?php esc_attr_e('your secret access key','wpdbbkp');?>">
159 <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
160 </div>
161 </div>
162
163 <p><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Save' , 'wpdbbkp' ); ?>" />&nbsp;
164 <input type="button" id="test-generics3-connection" class="btn btn-info" value="<?php esc_attr_e( 'Test Connection' , 'wpdbbkp' ); ?>" />
165 </p>
166 <div id="generics3-test-results" style="display: none; margin-top: 10px;"></div>
167 </form>
168
169 <script type="text/javascript">
170 jQuery(document).ready(function($) {
171 $('#test-generics3-connection').on('click', function() {
172 var $button = $(this);
173 var $results = $('#generics3-test-results');
174
175 $button.prop('disabled', true).val('Testing...');
176 $results.hide().html('<div class="alert alert-info">Testing connection...</div>').show();
177
178 $.ajax({
179 url: ajaxurl,
180 type: 'POST',
181 data: {
182 action: 'test_generics3_connection',
183 nonce: '<?php echo esc_js( wp_create_nonce( 'test_generics3_connection' ) ); ?>'
184 },
185 success: function(response) {
186 if (response.success) {
187 var messages = response.data.messages.join('<br>');
188 $results.html('<div class="alert alert-success"><strong>Connection Test Results:</strong><br>' + messages + '</div>');
189 } else {
190 var messages = response.data.messages ? response.data.messages.join('<br>') : 'Unknown error';
191 $results.html('<div class="alert alert-danger"><strong>Connection Test Failed:</strong><br>' + messages + '</div>');
192 }
193 },
194 error: function() {
195 $results.html('<div class="alert alert-danger">Failed to test connection. Please check your settings and try again.</div>');
196 },
197 complete: function() {
198 $button.prop('disabled', false).val('Test Connection');
199 }
200 });
201 });
202 });
203 </script>
204
205 </div>
206 </div>
207 </div>
208