UpdraftPlus WordPress Backup Plugin - Version 1.0.11

Version Description

  • 12/22/2012 =
  • Fixed bug that set 1Tb (instead of 1Mb) chunk sizes for Google Drive uploads
  • Added link to some screenshots to help with Google Drive setup
  • Allowed use of existing Amazon S3 buckets with restrictive policies (previously, we tested for the bucket's existence by running a create operation on it, which may not be permitted)
  • Use WordPress's native HTTP functions for greater reliability when performing Google Drive authorisation
Download this release

Release Info

Developer DavidAnderson
Plugin Icon 128x128 UpdraftPlus WordPress Backup Plugin
Version 1.0.11
Comparing to
See all releases

Code changes from version 1.0.10 to 1.0.11

Files changed (2) hide show
  1. readme.txt +3 -3
  2. updraftplus.php +26 -69
readme.txt CHANGED
@@ -8,7 +8,7 @@ Donate link: http://david.dw-perspective.org.uk/donate
8
  License: GPLv3 or later
9
 
10
  == Upgrade Notice ==
11
- Allowed use of existing Amazon S3 buckets with more restrictive policies
12
 
13
  == Description ==
14
 
@@ -87,11 +87,11 @@ No, there's no warranty or guarantee, etc. It's completely up to you to verify t
87
 
88
  == Changelog ==
89
 
90
- = 1.0.10 - 12/22/2012 =
91
  * Fixed bug that set 1Tb (instead of 1Mb) chunk sizes for Google Drive uploads
92
  * Added link to some screenshots to help with Google Drive setup
93
  * Allowed use of existing Amazon S3 buckets with restrictive policies (previously, we tested for the bucket's existence by running a create operation on it, which may not be permitted)
94
- * Use CURL instead of native PHP for Google Drive HTTP interactions
95
 
96
  = 1.0.5 - 12/13/2012 =
97
  * Tweaked default Google Drive options
8
  License: GPLv3 or later
9
 
10
  == Upgrade Notice ==
11
+ Various bug + compatibility fixes for greater reliability
12
 
13
  == Description ==
14
 
87
 
88
  == Changelog ==
89
 
90
+ = 1.0.11 - 12/22/2012 =
91
  * Fixed bug that set 1Tb (instead of 1Mb) chunk sizes for Google Drive uploads
92
  * Added link to some screenshots to help with Google Drive setup
93
  * Allowed use of existing Amazon S3 buckets with restrictive policies (previously, we tested for the bucket's existence by running a create operation on it, which may not be permitted)
94
+ * Use WordPress's native HTTP functions for greater reliability when performing Google Drive authorisation
95
 
96
  = 1.0.5 - 12/13/2012 =
97
  * Tweaked default Google Drive options
updraftplus.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: UpdraftPlus - Backup/Restore
4
  Plugin URI: http://wordpress.org/extend/plugins/updraftplus
5
  Description: Uploads, themes, plugins, and your DB can be automatically backed up to Amazon S3, Google Drive, FTP, or emailed, on separate schedules.
6
  Author: David Anderson.
7
- Version: 1.0.10
8
  Donate link: http://david.dw-perspective.org.uk/donate
9
  License: GPLv3 or later
10
  Author URI: http://wordshell.net
@@ -60,7 +60,7 @@ define('UPDRAFT_DEFAULT_OTHERS_EXCLUDE','upgrade,cache,updraft,index.php');
60
 
61
  class UpdraftPlus {
62
 
63
- var $version = '1.0.10';
64
 
65
  var $dbhandle;
66
  var $errors = array();
@@ -123,32 +123,24 @@ class UpdraftPlus {
123
  * Get a Google account access token using the refresh token
124
  */
125
  function access_token( $token, $client_id, $client_secret ) {
126
- $context = array(
127
- 'http' => array(
128
- 'method' => 'POST',
129
- 'header' => 'Content-type: application/x-www-form-urlencoded',
130
- 'content' => http_build_query( array(
131
- 'refresh_token' => $token,
132
- 'client_id' => $client_id,
133
- 'client_secret' => $client_secret,
134
- 'grant_type' => 'refresh_token'
135
- ) )
136
- )
137
- );
138
  $this->log("Google Drive: requesting access token: client_id=$client_id");
139
- $result = $this->http_post('https://accounts.google.com/o/oauth2/token', $context);
140
- if($result) {
141
- $result = json_decode( $result, true );
142
- if ( isset( $result['access_token'] ) ) {
 
 
 
 
 
 
 
143
  $this->log("Google Drive: successfully obtained access token");
144
- return $result['access_token'];
145
  } else {
146
  $this->log("Google Drive error when requesting access token: response does not contain access_token");
147
  return false;
148
  }
149
- } else {
150
- $this->log("Google Drive error when requesting access token: no response");
151
- return false;
152
  }
153
  }
154
 
@@ -172,71 +164,36 @@ class UpdraftPlus {
172
  return;
173
  }
174
 
175
- function http_get($url) {
176
- if (function_exists('curl_init')) {
177
- $ch = curl_init();
178
- curl_setopt($ch, CURLOPT_URL, $url);
179
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
180
- $output = curl_exec($ch);
181
- curl_close($ch);
182
- return $output;
183
- } elseif (function_exists('http_get')) {
184
- return http_get($url);
185
- } else {
186
- return @file_get_contents($url);
187
- }
188
- }
189
-
190
- function http_post($url,$options) {
191
- if (function_exists('curl_init')) {
192
- $ch = curl_init();
193
- curl_setopt($ch, CURLOPT_URL, $url);
194
- curl_setopt($ch, CURLOPT_POST, 1);
195
- curl_setopt($ch, CURLOPT_POSTFIELDS, $options['http']['content']);
196
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
197
- $output = curl_exec($ch);
198
- curl_close($ch);
199
- return $output;
200
- } else {
201
- return @file_get_contents($url, false, stream_context_create($options));
202
- }
203
- }
204
-
205
  /**
206
  * Get a Google account refresh token using the code received from gdrive_auth_request
207
  */
208
  function gdrive_auth_token() {
209
  if( isset( $_GET['code'] ) ) {
210
- $context = array(
211
- 'http' => array(
212
- 'timeout' => 30,
213
- 'method' => 'POST',
214
- 'header' => 'Content-type: application/x-www-form-urlencoded',
215
- 'content' => http_build_query( array(
216
  'code' => $_GET['code'],
217
  'client_id' => get_option('updraft_googledrive_clientid'),
218
  'client_secret' => get_option('updraft_googledrive_secret'),
219
  'redirect_uri' => admin_url('options-general.php?page=updraftplus&action=auth'),
220
  'grant_type' => 'authorization_code'
221
- ) )
222
- )
223
  );
224
- $result = $this->http_post('https://accounts.google.com/o/oauth2/token', $context);
225
- if($result) {
226
- $result = json_decode( $result, true );
227
- if ( isset( $result['refresh_token'] ) ) {
228
- update_option('updraft_googledrive_token',$result['refresh_token']); // Save token
 
 
 
 
229
  header('Location: '.admin_url('options-general.php?page=updraftplus&message=' . __( 'Google Drive authorization was successful.', 'updraftplus' ) ) );
230
  }
231
  else {
232
  header('Location: '.admin_url('options-general.php?page=updraftplus&error=' . __( 'No refresh token was received!', 'updraftplus' ) ) );
233
  }
234
- } else {
235
- header('Location: '.admin_url('options-general.php?page=updraftplus&error=' . __( 'Bad response!', 'backup' ) ) );
236
  }
237
  }
238
  else {
239
- header('Location: '.admin_url('options-general.php?page=updraftplus&error=' . __( 'Authorisation failed!', 'backup' ) ) );
240
  }
241
  }
242
 
@@ -244,7 +201,7 @@ class UpdraftPlus {
244
  * Revoke a Google account refresh token
245
  */
246
  function gdrive_auth_revoke() {
247
- $ignore = $this->http_get('https://accounts.google.com/o/oauth2/revoke?token='.get_option('updraft_googledrive_token'));
248
  update_option('updraft_googledrive_token','');
249
  header('Location: '.admin_url( 'options-general.php?page=updraftplus&message=Authorisation revoked'));
250
  }
4
  Plugin URI: http://wordpress.org/extend/plugins/updraftplus
5
  Description: Uploads, themes, plugins, and your DB can be automatically backed up to Amazon S3, Google Drive, FTP, or emailed, on separate schedules.
6
  Author: David Anderson.
7
+ Version: 1.0.11
8
  Donate link: http://david.dw-perspective.org.uk/donate
9
  License: GPLv3 or later
10
  Author URI: http://wordshell.net
60
 
61
  class UpdraftPlus {
62
 
63
+ var $version = '1.0.11';
64
 
65
  var $dbhandle;
66
  var $errors = array();
123
  * Get a Google account access token using the refresh token
124
  */
125
  function access_token( $token, $client_id, $client_secret ) {
 
 
 
 
 
 
 
 
 
 
 
 
126
  $this->log("Google Drive: requesting access token: client_id=$client_id");
127
+
128
+ $query_body = array( 'refresh_token' => $token, 'client_id' => $client_id, 'client_secret' => $client_secret, 'grant_type' => 'refresh_token' );
129
+ $result = wp_remote_post('https://accounts.google.com/o/oauth2/token', array('timeout' => '15', 'method' => 'POST', 'body' => $query_body) );
130
+
131
+ if (is_wp_error($result)) {
132
+ $this->log("Google Drive error when requesting access token");
133
+ foreach ($result->get_error_messages() as $msg) { $this->log("Error message: $msg"); }
134
+ return false;
135
+ } else {
136
+ $json_values = json_decode( $result['body'], true );
137
+ if ( isset( $json_values['access_token'] ) ) {
138
  $this->log("Google Drive: successfully obtained access token");
139
+ return $json_values['access_token'];
140
  } else {
141
  $this->log("Google Drive error when requesting access token: response does not contain access_token");
142
  return false;
143
  }
 
 
 
144
  }
145
  }
146
 
164
  return;
165
  }
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  /**
168
  * Get a Google account refresh token using the code received from gdrive_auth_request
169
  */
170
  function gdrive_auth_token() {
171
  if( isset( $_GET['code'] ) ) {
172
+ $post_vars = array(
 
 
 
 
 
173
  'code' => $_GET['code'],
174
  'client_id' => get_option('updraft_googledrive_clientid'),
175
  'client_secret' => get_option('updraft_googledrive_secret'),
176
  'redirect_uri' => admin_url('options-general.php?page=updraftplus&action=auth'),
177
  'grant_type' => 'authorization_code'
 
 
178
  );
179
+
180
+ $result = wp_remote_post('https://accounts.google.com/o/oauth2/token', array('timeout' => 30, 'method' => 'POST', 'body' => $post_vars) );
181
+
182
+ if (is_wp_error($result)) {
183
+ header('Location: '.admin_url('options-general.php?page=updraftplus&error=' . __( 'Bad response!', 'backup' ) ) );
184
+ } else {
185
+ $json_values = json_decode( $result['body'], true );
186
+ if ( isset( $json_values['refresh_token'] ) ) {
187
+ update_option('updraft_googledrive_token',$json_values['refresh_token']); // Save token
188
  header('Location: '.admin_url('options-general.php?page=updraftplus&message=' . __( 'Google Drive authorization was successful.', 'updraftplus' ) ) );
189
  }
190
  else {
191
  header('Location: '.admin_url('options-general.php?page=updraftplus&error=' . __( 'No refresh token was received!', 'updraftplus' ) ) );
192
  }
 
 
193
  }
194
  }
195
  else {
196
+ header('Location: '.admin_url('options-general.php?page=updraftplus&error=' . __( 'Authorization failed!', 'updraftplus' ) ) );
197
  }
198
  }
199
 
201
  * Revoke a Google account refresh token
202
  */
203
  function gdrive_auth_revoke() {
204
+ $ignore = wp_remote_get('https://accounts.google.com/o/oauth2/revoke?token='.get_option('updraft_googledrive_token'));
205
  update_option('updraft_googledrive_token','');
206
  header('Location: '.admin_url( 'options-general.php?page=updraftplus&message=Authorisation revoked'));
207
  }