InfiniteWP Client - Version 1.2.15

Version Description

  • Improvement: Support for backup upload to SFTP repository
  • Fix: Bug fixes
Download this release

Release Info

Developer infinitewp
Plugin Icon 128x128 InfiniteWP Client
Version 1.2.15
Comparing to
See all releases

Code changes from version 1.3.0 to 1.2.15

Files changed (73) hide show
  1. addons/backup_repository/backup_repository.class.php +47 -5
  2. addons/brokenlinks/brokenlinks.class.php +7 -7
  3. addons/file_editor/file_editor.class.php +9 -9
  4. addons/google_webmasters/google_webmasters.class.php +0 -1
  5. addons/manage_users/user.class.php +12 -12
  6. addons/post_links/link.class.php +1 -1
  7. addons/post_links/post.class.php +8 -8
  8. addons/wordfence/wordfence.class.php +1 -1
  9. backup.class.multicall.php +0 -6067
  10. backup.class.singlecall.php → backup.class.php +919 -1060
  11. core.class.php +11 -64
  12. helper.class.php +21 -21
  13. init.php +67 -250
  14. installer.class.php +37 -37
  15. lib/Google/Auth/Abstract.php +41 -41
  16. lib/Google/Auth/AssertionCredentials.php +133 -133
  17. lib/Google/Auth/Exception.php +22 -22
  18. lib/Google/Auth/LoginTicket.php +69 -69
  19. lib/Google/Auth/OAuth2.php +587 -587
  20. lib/Google/Auth/Simple.php +92 -92
  21. lib/Google/Cache/Abstract.php +53 -53
  22. lib/Google/Cache/Apc.php +73 -73
  23. lib/Google/Cache/Exception.php +21 -21
  24. lib/Google/Cache/File.php +145 -145
  25. lib/Google/Cache/Memcache.php +137 -137
  26. lib/Google/Cache/Null.php +56 -56
  27. lib/Google/Client.php +608 -608
  28. lib/Google/Collection.php +94 -94
  29. lib/Google/Config.php +315 -315
  30. lib/Google/Exception.php +20 -20
  31. lib/Google/Http/Batch.php +143 -143
  32. lib/Google/Http/CacheParser.php +184 -184
  33. lib/Google/Http/MediaFileUpload.php +305 -304
  34. lib/Google/Http/REST.php +139 -139
  35. lib/Google/Http/Request.php +476 -476
  36. lib/Google/IO/Abstract.php +312 -312
  37. lib/Google/IO/Curl.php +135 -135
  38. lib/Google/IO/Exception.php +22 -22
  39. lib/Google/IO/Stream.php +182 -182
  40. lib/Google/IO/cacerts.pem +2183 -2183
  41. lib/Google/Model.php +250 -250
  42. lib/Google/Service.php +39 -39
  43. lib/Google/Service/Drive.php +5732 -5732
  44. lib/Google/Service/Exception.php +53 -53
  45. lib/Google/Service/Oauth2.php +412 -412
  46. lib/Google/Service/Resource.php +210 -210
  47. lib/Google/Signer/Abstract.php +29 -29
  48. lib/Google/Signer/P12.php +91 -91
  49. lib/Google/Utils.php +135 -135
  50. lib/Google/Utils/URITemplate.php +333 -333
  51. lib/Google/Verifier/Abstract.php +30 -30
  52. lib/Google/Verifier/Pem.php +74 -74
  53. lib/amazon_s3/extensions/dynamodbsessionhandler.class.php +513 -513
  54. lib/amazon_s3/extensions/s3browserupload.class.php +172 -172
  55. lib/amazon_s3/extensions/s3streamwrapper.class.php +606 -606
  56. lib/amazon_s3/lib/requestcore/LICENSE +25 -25
  57. lib/amazon_s3/lib/requestcore/README.md +15 -15
  58. lib/amazon_s3/lib/requestcore/cacert.pem +3390 -3390
  59. lib/amazon_s3/lib/requestcore/requestcore.class.php +1033 -1033
  60. lib/amazon_s3/services/s3.class.php +4307 -4307
  61. lib/amazon_s3/utilities/array.class.php +312 -312
  62. lib/amazon_s3/utilities/batchrequest.class.php +126 -126
  63. lib/amazon_s3/utilities/credential.class.php +157 -157
  64. lib/amazon_s3/utilities/credentials.class.php +134 -134
  65. lib/amazon_s3/utilities/mimetypes.class.php +223 -223
  66. lib/amazon_s3/utilities/request.class.php +70 -70
  67. lib/amazon_s3/utilities/response.class.php +30 -30
  68. lib/amazon_s3/utilities/simplexml.class.php +272 -272
  69. lib/amazon_s3/utilities/utilities.class.php +399 -399
  70. lib/dropbox.php +11 -22
  71. pclzip.class.php +203 -892
  72. readme.txt +2 -8
  73. stats.class.php +1 -1
addons/backup_repository/backup_repository.class.php CHANGED
@@ -1,5 +1,5 @@
1
<?php
2
- class IWP_MMB_Backup_Repository extends IWP_MMB_Backup_Singlecall
3
{
4
/*var $site_name;
5
var $statuses;
@@ -33,7 +33,7 @@ class IWP_MMB_Backup_Repository extends IWP_MMB_Backup_Singlecall
33
}*/
34
35
function backup_repository($args){
36
-
37
if (!empty($args))
38
extract($args);
39
@@ -53,7 +53,6 @@ class IWP_MMB_Backup_Repository extends IWP_MMB_Backup_Singlecall
53
$backup_file = $results[count($results) - 1]['server']['file_path'];
54
}
55
56
-
57
if ($backup_file && file_exists($backup_file)) {
58
//FTP, Amazon S3 or Dropbox
59
if (isset($account_info['iwp_ftp']) && !empty($account_info)) {
@@ -81,7 +80,50 @@ class IWP_MMB_Backup_Repository extends IWP_MMB_Backup_Singlecall
81
$return = $this->dropbox_backup($account_info['iwp_dropbox']);
82
$this->update_status($task_name, 'dropbox', true);
83
iwp_mmb_print_flush('Dropbox upload: End');
84
- }
85
86
if ($return == true && $del_host_file) {
87
@unlink($backup_file);
@@ -93,7 +135,7 @@ class IWP_MMB_Backup_Repository extends IWP_MMB_Backup_Singlecall
93
94
} else {
95
$return = array(
96
- 'error' => 'Backup file not found on your server. Please try again.', 'error_code' => 'backup_file_not_found_on_server'
97
);
98
}
99
1
<?php
2
+ class IWP_MMB_Backup_Repository extends IWP_MMB_Backup
3
{
4
/*var $site_name;
5
var $statuses;
33
}*/
34
35
function backup_repository($args){
36
+
37
if (!empty($args))
38
extract($args);
39
53
$backup_file = $results[count($results) - 1]['server']['file_path'];
54
}
55
56
if ($backup_file && file_exists($backup_file)) {
57
//FTP, Amazon S3 or Dropbox
58
if (isset($account_info['iwp_ftp']) && !empty($account_info)) {
80
$return = $this->dropbox_backup($account_info['iwp_dropbox']);
81
$this->update_status($task_name, 'dropbox', true);
82
iwp_mmb_print_flush('Dropbox upload: End');
83
+ }
84
+
85
+ if (isset($account_info['iwp_gdrive']) && !empty($account_info['iwp_gdrive'])) {
86
+
87
+ $this->update_status($task_name,'gDrive');
88
+ $account_info['iwp_gdrive']['backup_file'] = $backup_file;
89
+ iwp_mmb_print_flush('google Drive upload: Start');
90
+ $gdrive_result = $this->google_drive_backup($account_info['iwp_gdrive']);
91
+ $this->update_status($task_name, 'gDrive', true);
92
+ iwp_mmb_print_flush('google Drive upload: End');
93
+
94
+ if ($gdrive_result == false && $del_host_file) {
95
+ @unlink($backup_file);
96
+ $return = false;
97
+ }
98
+
99
+ if (is_array($gdrive_result) && isset($gdrive_result['error'])) {
100
+ return $gdrive_result;
101
+ }
102
+
103
+ //update the tasks different method for gDrive
104
+
105
+ if(!empty($gdrive_result))
106
+ {
107
+ $tasks = $this->tasks;
108
+ $task = $tasks['Backup Now'];
109
+ $results = $task['task_results'];
110
+ if (is_array($results) && count($results)) {
111
+ $results[count($results) - 1]['gDrive'] = $gdrive_result;
112
+ //$results[count($results) - 1]['gDriveOrgFileName'] = basename($backup_url); //not required
113
+ unset($results[count($results) - 1]['server']);
114
+ }
115
+
116
+ /* $paths['gDrive'] = $gdrive_result; //different from other upload ; storing the gDrive backupfile ID in the paths array for delete operation
117
+ $paths['gDriveOrgFileName'] = basename($backup_url); */
118
+
119
+ $tasks['Backup Now']['task_results'] = $results;
120
+ $this->tasks = $tasks;
121
+
122
+ $this->update_status($task_name,'gDrive', true);
123
+ unset($paths['server']);
124
+ $return = true;
125
+ }
126
+ }
127
128
if ($return == true && $del_host_file) {
129
@unlink($backup_file);
135
136
} else {
137
$return = array(
138
+ 'error' => 'Backup file not found on your server. Please try again.'
139
);
140
}
141
addons/brokenlinks/brokenlinks.class.php CHANGED
@@ -105,7 +105,7 @@ class IWP_MMB_BLC extends IWP_MMB_Core
105
}
106
return $success;
107
} else {
108
- return array('error'=>"Broken Link Checker plugin is not activated", 'error_code' => 'blc_plugin_not_activated_blc_get_all_links');
109
}
110
}
111
@@ -118,7 +118,7 @@ class IWP_MMB_BLC extends IWP_MMB_Core
118
$rez['linkType']=$params['linkType'];
119
return $rez;
120
} else {
121
- return array('error'=>"Broken Link Checker plugin is not activated", 'error_code' => 'blc_plugin_not_activated_blc_update_link');
122
}
123
}
124
@@ -133,7 +133,7 @@ class IWP_MMB_BLC extends IWP_MMB_Core
133
$rez['linkType']=$params['linkType'];
134
return $rez;
135
} else {
136
- return array('error'=>"Broken Link Checker plugin is not activated", 'error_code' => 'blc_plugin_not_activated_blc_unlink');
137
}
138
}
139
@@ -153,11 +153,11 @@ class IWP_MMB_BLC extends IWP_MMB_Core
153
if ( $link->save() ){
154
$rez = array('old_link_id'=>$params['linkID'],'linkType'=>$params['linkType'],'marked'=>1);
155
} else {
156
- $rez = array('error'=>'Action couldn\'t be completed', 'error_code' => 'blc_plugin_action_couldnt_completed_blc_mark_as_not_broken');
157
}
158
return $rez;
159
} else {
160
- return array('error'=>"Broken Link Checker plugin is not activated", 'error_code' => 'blc_plugin_not_activated_blc_mark_as_not_broken');
161
}
162
}
163
function blc_dismiss_link($params){
@@ -179,11 +179,11 @@ class IWP_MMB_BLC extends IWP_MMB_Core
179
if ( $link->save() ){
180
$rez = array('old_link_id'=>$params['linkID'],'linkType'=>$params['linkType'],'dismissvalue_set'=>1);
181
} else {
182
- $rez = array('error'=>'Action couldn\'t be completed', 'error_code' => 'blc_plugin_action_couldnt_completed_blc_set_dismiss_status');
183
}
184
return $rez;
185
} else {
186
- return array('error'=>"Broken Link Checker plugin is not activated", 'error_code' => 'blc_plugin_not_activated_blc_set_dismiss_status');
187
}
188
}
189
105
}
106
return $success;
107
} else {
108
+ return array('error'=>"Broken Link Checker plugin is not activated");
109
}
110
}
111
118
$rez['linkType']=$params['linkType'];
119
return $rez;
120
} else {
121
+ return array('error'=>"Broken Link Checker plugin is not activated");
122
}
123
}
124
133
$rez['linkType']=$params['linkType'];
134
return $rez;
135
} else {
136
+ return array('error'=>"Broken Link Checker plugin is not activated");
137
}
138
}
139
153
if ( $link->save() ){
154
$rez = array('old_link_id'=>$params['linkID'],'linkType'=>$params['linkType'],'marked'=>1);
155
} else {
156
+ $rez = array('error'=>'Action couldn\'t be completed');
157
}
158
return $rez;
159
} else {
160
+ return array('error'=>"Broken Link Checker plugin is not activated");
161
}
162
}
163
function blc_dismiss_link($params){
179
if ( $link->save() ){
180
$rez = array('old_link_id'=>$params['linkID'],'linkType'=>$params['linkType'],'dismissvalue_set'=>1);
181
} else {
182
+ $rez = array('error'=>'Action couldn\'t be completed');
183
}
184
return $rez;
185
} else {
186
+ return array('error'=>"Broken Link Checker plugin is not activated");
187
}
188
}
189
addons/file_editor/file_editor.class.php CHANGED
@@ -193,14 +193,14 @@ function iwp_mmb_direct_to_any_copy($source, $destination, $overwrite = false, $
193
extract($params);
194
if (!function_exists('gzinflate')) {
195
return array(
196
- 'error' => 'Gzip library functions are not available.', 'error_code' => 'gzip_library_functions_are_not_available'
197
);
198
}else{
199
$fileContent = gzinflate($fileContent);
200
}
201
if (!$this->is_server_writable()) {
202
return array(
203
- 'error' => 'Failed, please add FTP details', 'error_code' => 'failed_please_add_FTP_details_file_editor_upload'
204
);
205
}
206
@@ -208,14 +208,14 @@ function iwp_mmb_direct_to_any_copy($source, $destination, $overwrite = false, $
208
ob_start();
209
if (false === ($creds = request_filesystem_credentials($url, '', false, ABSPATH, null) ) ) {
210
return array(
211
- 'error' => 'Unable to get file system credentials', 'error_code' => 'unable_to_get_file_system_credentials_file_editor_upload'
212
); // stop processing here
213
}
214
ob_end_clean();
215
216
if ( ! WP_Filesystem($creds, ABSPATH) ) {
217
return array(
218
- 'error' => 'Unable to initiate file system. Please check you have entered valid FTP credentials.', 'error_code' => 'unable_to_initiate_file_system_check_ftp_credentials_file_editor_upload'
219
); // stop processing here
220
}
221
@@ -229,7 +229,7 @@ function iwp_mmb_direct_to_any_copy($source, $destination, $overwrite = false, $
229
$is_dir_created = mkdir($new_temp_folder);// new folder should be empty
230
if(!$is_dir_created){
231
return array(
232
- 'error' => 'Unable to create a temporary directory.', 'error_code' => 'unable_to_create_temporary_directory_file_editor_upload'
233
);
234
}
235
@@ -238,19 +238,19 @@ function iwp_mmb_direct_to_any_copy($source, $destination, $overwrite = false, $
238
$remote_abspath = trailingslashit($remote_abspath);
239
}else{
240
return array(
241
- 'error' => 'Unable to locate WP root directory using file system.', 'error_code' => 'unable_to_locate_root_directory_remote_abspath_file_editor_upload'
242
);
243
}
244
245
if($folderPath == 'root' && ($filePath == 'wp-config' || $filePath == 'wp-config.php' ) ){
246
return array(
247
- 'error' => 'wp-config file is not allowed.', 'error_code' => 'config_file_is_not_allowed_file_editor_upload'
248
);
249
}
250
251
$file = $this->get_file_editor_vars($remote_abspath,$folderPath,$filePath,$ext);
252
if($file === false){
253
- return array('error' => 'File path given is invalid.', 'error_code' => 'file_path_given_is_invalid_file_editor_upload');
254
}
255
256
$new_temp_subfolders = $new_temp_folder;
@@ -259,7 +259,7 @@ function iwp_mmb_direct_to_any_copy($source, $destination, $overwrite = false, $
259
$is_subdir_created = mkdir($new_temp_subfolders);// new folder should be empty
260
if(!$is_subdir_created){
261
return array(
262
- 'error' => 'Unable to create a temporary directory.', 'error_code' => 'unable_to_locate_wp_root_directory_using_file_system_file_editor_upload'
263
);
264
}
265
}
193
extract($params);
194
if (!function_exists('gzinflate')) {
195
return array(
196
+ 'error' => 'Gzip library functions are not available.'
197
);
198
}else{
199
$fileContent = gzinflate($fileContent);
200
}
201
if (!$this->is_server_writable()) {
202
return array(
203
+ 'error' => 'Failed, please add FTP details'
204
);
205
}
206
208
ob_start();
209
if (false === ($creds = request_filesystem_credentials($url, '', false, ABSPATH, null) ) ) {
210
return array(
211
+ 'error' => 'Unable to get file system credentials'
212
); // stop processing here
213
}
214
ob_end_clean();
215
216
if ( ! WP_Filesystem($creds, ABSPATH) ) {
217
return array(
218
+ 'error' => 'Unable to initiate file system. Please check you have entered valid FTP credentials.'
219
); // stop processing here
220
}
221
229
$is_dir_created = mkdir($new_temp_folder);// new folder should be empty
230
if(!$is_dir_created){
231
return array(
232
+ 'error' => 'Unable to create a temporary directory.'
233
);
234
}
235
238
$remote_abspath = trailingslashit($remote_abspath);
239
}else{
240
return array(
241
+ 'error' => 'Unable to locate WP root directory using file system.'
242
);
243
}
244
245
if($folderPath == 'root' && ($filePath == 'wp-config' || $filePath == 'wp-config.php' ) ){
246
return array(
247
+ 'error' => 'wp-config file is not allowed.'
248
);
249
}
250
251
$file = $this->get_file_editor_vars($remote_abspath,$folderPath,$filePath,$ext);
252
if($file === false){
253
+ return array('error' => 'File path given is invalid.');
254
}
255
256
$new_temp_subfolders = $new_temp_folder;
259
$is_subdir_created = mkdir($new_temp_subfolders);// new folder should be empty
260
if(!$is_subdir_created){
261
return array(
262
+ 'error' => 'Unable to create a temporary directory.'
263
);
264
}
265
}
addons/google_webmasters/google_webmasters.class.php CHANGED
@@ -9,7 +9,6 @@ if(!function_exists('iwp_mmb_create_webmasters_redirect_table')){
9
global $wpdb;
10
11
$IWP_MMB_WEBMASTERS_REDIRECT_TABLE_VERSION = get_site_option( 'iwp_webmasters_redirect_table_version' );
12
-
13
if(version_compare($IWP_MMB_WEBMASTERS_REDIRECT_TABLE_VERSION, '1.0') == -1){
14
15
$table_name = $wpdb->base_prefix . "iwp_redirects";
9
global $wpdb;
10
11
$IWP_MMB_WEBMASTERS_REDIRECT_TABLE_VERSION = get_site_option( 'iwp_webmasters_redirect_table_version' );
12
if(version_compare($IWP_MMB_WEBMASTERS_REDIRECT_TABLE_VERSION, '1.0') == -1){
13
14
$table_name = $wpdb->base_prefix . "iwp_redirects";
addons/manage_users/user.class.php CHANGED
@@ -81,10 +81,10 @@ class IWP_MMB_User extends IWP_MMB_Core
81
include_once(ABSPATH . WPINC . '/registration.php');
82
83
if(username_exists($args['user_login']))
84
- return array('error' => 'Username already exists', 'error_code' => 'username_already_exists');
85
86
if (email_exists($args['user_email']))
87
- return array('error' => 'Email already exists', 'error_code' => 'email_already_exists');
88
89
if(!function_exists('wp_insert_user'))
90
include_once (ABSPATH . 'wp-admin/includes/user.php');
@@ -99,7 +99,7 @@ class IWP_MMB_User extends IWP_MMB_Core
99
}
100
return $user_id;
101
}else{
102
- return array('error' => 'User not added. Please try again.', 'error_code' => 'user_not_added_please_try_again');
103
}
104
105
}
@@ -130,7 +130,7 @@ class IWP_MMB_User extends IWP_MMB_Core
130
$userdata['ID'] = $user_obj->ID;
131
$result = wp_update_user($userdata);
132
} else {
133
- $result = array('error' => 'No password provided.', 'error_code' => 'no_password_provided');
134
}
135
break;
136
case 'change-role':
@@ -142,13 +142,13 @@ class IWP_MMB_User extends IWP_MMB_Core
142
$userdata['role'] = strtolower($new_role);
143
$result = wp_update_user($userdata);
144
} else {
145
- $result = array('error' => 'Cannot change role to the only one left admin user.', 'error_code' => 'cannot_change_role_to_the_only_one_left_admin_user');
146
}
147
} else {
148
- $result = array('error' => 'Cannot change role to user assigned for InfiniteWP.', 'error_code' => 'cannot_change_role_to_user_assigned_to_InfiniteWP');
149
}
150
} else {
151
- $result = array('error' => 'No role provided.', 'error_code' => 'no_role_provided');
152
}
153
break;
154
case 'delete-user':
@@ -159,25 +159,25 @@ class IWP_MMB_User extends IWP_MMB_Core
159
if($to_user != false){
160
$result = wp_delete_user($user_obj->ID, $to_user->ID);
161
} else {
162
- $result = array('error' => 'User not deleted. User to reassign posts doesn\'t exist.', 'error_code' => 'user_not_deleted_user_to_reassign_posts_doesnt_exist');
163
}
164
} else {
165
$result = wp_delete_user($user_obj->ID);
166
}
167
} else {
168
- $result = array('error' => 'Cannot delete the only one left admin user.', 'error_code' => 'cannot_delete_the_only_one_left_admin_user');
169
}
170
} else {
171
- $result = array('error' => 'Cannot delete user assigned for InfiniteWP.', 'error_code' => 'cannot_delete_user_assigned_for_InfiniteWP');
172
}
173
174
break;
175
default:
176
- $result = array('error' => 'Wrong action provided. Please try again.', 'error_code' => 'wrong_action_provided_please_try_again');
177
break;
178
}
179
} else {
180
- $result = array('error' => 'User not found.', 'error_code' => 'user_not_found');
181
}
182
183
if(is_wp_error($result)){
81
include_once(ABSPATH . WPINC . '/registration.php');
82
83
if(username_exists($args['user_login']))
84
+ return array('error' => 'Username already exists');
85
86
if (email_exists($args['user_email']))
87
+ return array('error' => 'Email already exists');
88
89
if(!function_exists('wp_insert_user'))
90
include_once (ABSPATH . 'wp-admin/includes/user.php');
99
}
100
return $user_id;
101
}else{
102
+ return array('error' => 'User not added. Please try again.');
103
}
104
105
}
130
$userdata['ID'] = $user_obj->ID;
131
$result = wp_update_user($userdata);
132
} else {
133
+ $result = array('error' => 'No password provided.');
134
}
135
break;
136
case 'change-role':
142
$userdata['role'] = strtolower($new_role);
143
$result = wp_update_user($userdata);
144
} else {
145
+ $result = array('error' => 'Cannot change role to the only one left admin user.');
146
}
147
} else {
148
+ $result = array('error' => 'Cannot change role to user assigned for InfiniteWP.');
149
}
150
} else {
151
+ $result = array('error' => 'No role provided.');
152
}
153
break;
154
case 'delete-user':
159
if($to_user != false){
160
$result = wp_delete_user($user_obj->ID, $to_user->ID);
161
} else {
162
+ $result = array('error' => 'User not deleted. User to reassign posts doesn\'t exist.');
163
}
164
} else {
165
$result = wp_delete_user($user_obj->ID);
166
}
167
} else {
168
+ $result = array('error' => 'Cannot delete the only one left admin user.');
169
}
170
} else {
171
+ $result = array('error' => 'Cannot delete user assigned for InfiniteWP.');
172
}
173
174
break;
175
default:
176
+ $result = array('error' => 'Wrong action provided. Please try again.');
177
break;
178
}
179
} else {
180
+ $result = array('error' => 'User not found.');
181
}
182
183
if(is_wp_error($result)){
addons/post_links/link.class.php CHANGED
@@ -68,7 +68,7 @@ class IWP_MMB_Link extends IWP_MMB_Core
68
69
$is_success = wp_insert_link($params);
70
71
- return $is_success ? true : array('error' => 'Failed to add link.', 'error_code' => 'failed_to_add_link');
72
}
73
74
function remove_element($arr, $val){
68
69
$is_success = wp_insert_link($params);
70
71
+ return $is_success ? true : array('error' => 'Failed to add link.');
72
}
73
74
function remove_element($arr, $val){
addons/post_links/post.class.php CHANGED
@@ -152,13 +152,13 @@ class IWP_MMB_Post extends IWP_MMB_Core
152
}
153
154
if(isset($upload['error']) && !empty($upload['error'])){
155
- return array('error' => $upload['error'], 'error_code' => 'upload_error');
156
}
157
$file_name = basename($no_thumb);
158
$tmp_file = download_url($no_thumb);
159
160
if(is_wp_error($tmp_file)){
161
- return array('error' => $tmp_file->get_error_message(), 'error_code' => 'error_download_img_thumb_url');
162
}
163
164
$attach_upload['url'] = $upload['url'] . '/' . $file_name;
@@ -234,7 +234,7 @@ class IWP_MMB_Post extends IWP_MMB_Core
234
}
235
} else {
236
@unlink($tmp_file);
237
- return array('error' => "Cannot create attachment file in ".$attach_upload['path']." Please set correct permissions.", 'error_code' =>'cannot_create_attachment_file_set_correct_permissions' );
238
239
}
240
@unlink($tmp_file);
@@ -250,12 +250,12 @@ class IWP_MMB_Post extends IWP_MMB_Core
250
$file_name = basename($img['src']);
251
252
if(isset($upload['error']) && !empty($upload['error'])){
253
- return array('error' => $upload['error'], 'error_code' => 'upload_error_post_atta_img');
254
}
255
256
$tmp_file = download_url($img['src']);
257
if(is_wp_error($tmp_file)){
258
- return array('error' => $tmp_file->get_error_message(), 'error_code' => 'download_url_wp_error_post_atta_img');
259
}
260
261
$attach_upload['url'] = $upload['url'] . '/' . $file_name;
@@ -295,7 +295,7 @@ class IWP_MMB_Post extends IWP_MMB_Core
295
296
} else {
297
@unlink($tmp_file);
298
- return array('error' => "Cannot create attachment file in ".$attach_upload['path']." Please set correct permissions.", 'error_code' => 'cannot_create_attachment_post_featured_img');
299
}
300
@unlink($tmp_file);
301
}
@@ -344,7 +344,7 @@ class IWP_MMB_Post extends IWP_MMB_Core
344
if($post_data['iwp_post_edit'] && $post_data['iwp_force_publish']){
345
$post_id = wp_insert_post($post_data);
346
} elseif($post_data['iwp_post_edit'] && !$post_data['iwp_force_publish']) {
347
- return array('error' => "Post not found.", 'error_code' => 'post_not_found');
348
} else {
349
$post_id = wp_insert_post($post_data);
350
}
@@ -369,7 +369,7 @@ class IWP_MMB_Post extends IWP_MMB_Core
369
if ($post_featured_img != '') {
370
$file_name = basename($post_featured_img);
371
if(isset($upload['error']) && !empty($upload['error'])){
372
- return array('error' => $upload['error'], 'error_code' => 'error_post_featured_img');
373
}
374
$tmp_file = download_url($post_featured_img);
375
if(is_wp_error($tmp_file)){
152
}
153
154
if(isset($upload['error']) && !empty($upload['error'])){
155
+ return array('error' => $upload['error']);
156
}
157
$file_name = basename($no_thumb);
158
$tmp_file = download_url($no_thumb);
159
160
if(is_wp_error($tmp_file)){
161
+ return array('error' => $tmp_file->get_error_message());
162
}
163
164
$attach_upload['url'] = $upload['url'] . '/' . $file_name;
234
}
235
} else {
236
@unlink($tmp_file);
237
+ return array('error' => "Cannot create attachment file in ".$attach_upload['path']." Please set correct permissions.");
238
239
}
240
@unlink($tmp_file);
250
$file_name = basename($img['src']);
251
252
if(isset($upload['error']) && !empty($upload['error'])){
253
+ return array('error' => $upload['error']);
254
}
255
256
$tmp_file = download_url($img['src']);
257
if(is_wp_error($tmp_file)){
258
+ return array('error' => $tmp_file->get_error_message());
259
}
260
261
$attach_upload['url'] = $upload['url'] . '/' . $file_name;
295
296
} else {
297
@unlink($tmp_file);
298
+ return array('error' => "Cannot create attachment file in ".$attach_upload['path']." Please set correct permissions.");
299
}
300
@unlink($tmp_file);
301
}
344
if($post_data['iwp_post_edit'] && $post_data['iwp_force_publish']){
345
$post_id = wp_insert_post($post_data);
346
} elseif($post_data['iwp_post_edit'] && !$post_data['iwp_force_publish']) {
347
+ return array('error' => "Post not found.");
348
} else {
349
$post_id = wp_insert_post($post_data);
350
}
369
if ($post_featured_img != '') {
370
$file_name = basename($post_featured_img);
371
if(isset($upload['error']) && !empty($upload['error'])){
372
+ return array('error' => $upload['error']);
373
}
374
$tmp_file = download_url($post_featured_img);
375
if(is_wp_error($tmp_file)){
addons/wordfence/wordfence.class.php CHANGED
@@ -32,7 +32,7 @@ class IWP_WORDFENCE extends IWP_MMB_Core
32
if($this->_checkWordFence()) {
33
return wordfence::ajax_scan_callback();
34
} else {
35
- return array('error'=>"Word Fence plugin is not activated", 'error_code' => 'wordfence_plugin_is_not_activated');
36
}
37
}
38
32
if($this->_checkWordFence()) {
33
return wordfence::ajax_scan_callback();
34
} else {
35
+ return array('error'=>"Word Fence plugin is not activated");
36
}
37
}
38
backup.class.multicall.php DELETED
@@ -1,6067 +0,0 @@
1
- <?php
2
- /************************************************************
3
- * This plugin was modified by Revmakx *
4
- * Copyright (c) 2012 Revmakx *
5
- * www.revmakx.com *
6
- * *
7
- ************************************************************/
8
- /*************************************************************
9
- *
10
- * backup.class.php
11
- *
12
- * Manage Backups
13
- *
14
- *
15
- * Copyright (c) 2011 Prelovac Media
16
- * www.prelovac.com
17
- **************************************************************/
18
-
19
- if(!defined('IWP_BACKUP_DIR')){
20
- define('IWP_BACKUP_DIR', WP_CONTENT_DIR . '/infinitewp/backups');
21
- }
22
-
23
- if(!defined('IWP_DB_DIR')){
24
- define('IWP_DB_DIR', IWP_BACKUP_DIR . '/iwp_db');
25
- }
26
-
27
- if(!defined('PCLZIP_TEMPORARY_DIR')){
28
- define('PCLZIP_TEMPORARY_DIR', WP_CONTENT_DIR . '/infinitewp/temp/');
29
- }
30
-
31
- //require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.split.php';
32
- require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
33
-
34
-
35
-
36
- $zip_errors = array(
37
- 'No error',
38
- 'No error',
39
- 'Unexpected end of zip file',
40
- 'A generic error in the zipfile format was detected',
41
- 'zip was unable to allocate itself memory',
42
- 'A severe error in the zipfile format was detected',
43
- 'Entry too large to be split with zipsplit',
44
- 'Invalid comment format',
45
- 'zip -T failed or out of memory',
46
- 'The user aborted zip prematurely',
47
- 'zip encountered an error while using a temp file. Please check if this domain\'s account has enough disk space.',
48
- 'Read or seek error',
49
- 'zip has nothing to do',
50
- 'Missing or empty zip file',
51
- 'Error writing to a file. Please check if this domain\'s account has enough disk space.',
52
- 'zip was unable to create a file to write to',
53
- 'bad command line parameters',
54
- 'no error',
55
- 'zip could not open a specified file to read'
56
- );
57
- $unzip_errors = array(
58
- 'No error',
59
- 'One or more warning errors were encountered, but processing completed successfully anyway',
60
- 'A generic error in the zipfile format was detected',
61
- 'A severe error in the zipfile format was detected.',
62
- 'unzip was unable to allocate itself memory.',
63
- 'unzip was unable to allocate memory, or encountered an encryption error',
64
- 'unzip was unable to allocate memory during decompression to disk',
65
- 'unzip was unable allocate memory during in-memory decompression',
66
- 'unused',
67
- 'The specified zipfiles were not found',
68
- 'Bad command line parameters',
69
- 'No matching files were found',
70
- 50 => 'The disk is (or was) full during extraction',
71
- 51 => 'The end of the ZIP archive was encountered prematurely.',
72
- 80 => 'The user aborted unzip prematurely.',
73
- 81 => 'Testing or extraction of one or more files failed due to unsupported compression methods or unsupported decryption.',
74
- 82 => 'No files were found due to bad decryption password(s)'
75
- );
76
-
77
-
78
- class IWP_MMB_Backup_Multicall extends IWP_MMB_Core
79
- {
80
- var $site_name;
81
- var $statuses;
82
- var $tasks;
83
- var $s3;
84
- var $ftp;
85
- var $dropbox;
86
- var $statusLogVar;
87
- var $hisID;
88
- var $backup_url;
89
- var $backup_settings_vals = array();
90
- var $iwpScriptStartTime;
91
- function __construct()
92
- {
93
- parent::__construct();
94
- $this->site_name = str_replace(array(
95
- "_",
96
- "/",
97
- "~"
98
- ), array(
99
- "",
100
- "-",
101
- "-"
102
- ), rtrim($this->remove_http(get_bloginfo('url')), "/"));
103
- $this->statuses = array(
104
- 'db_dump' => 1,
105
- 'db_zip' => 2,
106
- 'files_zip' => 3,
107
- 'finished' => 100
108
- );
109
- $this->tasks = get_option('iwp_client_multi_backup_temp_values');
110
- $this->iwpScriptStartTime = $GLOBALS['IWP_MMB_PROFILING']['ACTION_START'];
111
- }
112
-
113
- function set_resource_limit()
114
- {
115
- $changed = array('execution_time' => 0, 'memory_limit' => 0, 'ini_memory_limit' => ini_get('memory_limit'), 'ini_execution_time' => ini_get('max_execution_time'));
116
- @ignore_user_abort(true);
117
-
118
-
119
- $mod_memory = (@ini_set('memory_limit', -1) == false) ? $changed['memory_limit'] = false : $changed['memory_limit'] = 1;
120
-
121
- @ini_set('memory_limit', '-1');
122
-
123
- if ( (int) @ini_get('max_execution_time') < 1200 ) {
124
- $mod_exec = @ini_set('max_execution_time', 1200) == false ? $changed['execution_time'] = false : $changed['execution_time'] = 1; //twenty minutes
125
- @set_time_limit(1200);
126
-
127
- }
128
-
129
- return $changed;
130
-
131
- }
132
-
133
-
134
- function trigger_check($datas)
135
- {
136
- if(!empty($datas))
137
- {
138
- $this->set_resource_limit();
139
- $responseParams = $this -> getRequiredData($datas['backupParentHID'],"responseParams");
140
- if(empty($responseParams))
141
- {
142
- return $this->statusLog($datas['backupParentHID'], array('stage' => 'trigger_check', 'status' => 'error', 'statusMsg' => 'Error while fetching table data', 'statusCode' => 'error_while_fetching_table_data'));
143
- }
144
- $action = $responseParams['nextFunc'];
145
- if(empty($action))
146
- {
147
- return $this->statusLog($datas['backupParentHID'], array('stage' => 'trigger_check', 'status' => 'error', 'statusMsg' => 'Calling Next Function failed - Error while fetching table data', 'statusCode' => 'calling_next_function_failed_error_while_fetching_table_data'));
148
- }
149
-
150
- unset($responseParams);
151
-
152
- if(method_exists('IWP_MMB_Backup_Multicall', $action)){
153
- $result = self::$action($datas['backupParentHID']);
154
- return $result;
155
- }
156
- }
157
- }
158
-
159
- function set_backup_task($params)
160
- {
161
- if(!empty($params))
162
- {
163
- //darkCode testing purpose static values
164
- if((empty($params['args']['file_block_size']))||($params['args']['file_block_size'] < 1))
165
- {
166
- $params['args']['file_block_size'] = 5; //MB
167
- }
168
- if($params['args']['disable_comp'] == '')
169
- {
170
- $params['args']['is_compressed'] = true;
171
- }
172
- else
173
- {
174
- $params['args']['is_compressed'] = false;
175
- }
176
- if((empty($params['args']['file_loop_break_time']))||($params['args']['file_loop_break_time'] < 6))
177
- {
178
- $params['args']['file_loop_break_time'] = 23;
179
- }
180
- if((empty($params['args']['db_loop_break_time']))||($params['args']['db_loop_break_time'] < 6))
181
- {
182
- $params['args']['db_loop_break_time'] = 23;
183
- }
184
- if($params['account_info'])
185
- {
186
- if((empty($params['account_info']['upload_loop_break_time']))||($params['account_info']['upload_loop_break_time'] < 6))
187
- {
188
- $params['account_info']['upload_loop_break_time'] = 23;
189
- }
190
- if((empty($params['account_info']['upload_file_block_size']))||($params['account_info']['upload_file_block_size'] < 1))
191
- {
192
- $params['account_info']['upload_file_block_size'] = (5*1024*1024)+1;
193
- }
194
- else
195
- {
196
- $params['account_info']['upload_file_block_size'] = ($params['account_info']['upload_file_block_size']*1024*1024)+1;
197
- }
198
- $params['account_info']['actual_file_size'] = 0;
199
-
200
- }
201
- $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'processing', 'statusMsg' => 'verificationInitiated'),$params);
202
-
203
- $historyID = $params['args']['parentHID'];
204
-
205
- $this->hisID = $historyID;
206
-
207
-
208
- $setMemory = $this->set_resource_limit();
209
-
210
- if(file_exists(IWP_BACKUP_DIR) && is_dir(IWP_BACKUP_DIR)){
211
- $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'processing', 'statusMsg' => 'Directory Writable'));
212
- }else{
213
- $mkdir = @mkdir(IWP_BACKUP_DIR, 0755, true);
214
- if(!$mkdir){
215
- return $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'error', 'statusMsg' => 'Permission denied; Make sure you have write permission for the wp-content folder.', 'statusCode' => 'permission_denied_make_sure_you_have_write_permission_for_the_wp_content_folder'));
216
- }
217
- }
218
- if(is_writable(IWP_BACKUP_DIR)){
219
- @file_put_contents(IWP_BACKUP_DIR . '/index.php', ''); //safe
220
-
221
- }else{
222
- $chmod = chmod(IWP_BACKUP_DIR, 777);
223
- if(!is_writable(IWP_BACKUP_DIR)){
224
- return $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'error', 'statusMsg' => IWP_BACKUP_DIR.' directory is not writable. Please set 755 or 777 file permission and try again.', 'statusCode' => 'backup_dir_is_not_writable'));
225
- }
226
- }
227
-
228
- //pclzip temp folder creation
229
-
230
- if(file_exists(PCLZIP_TEMPORARY_DIR) && is_dir(PCLZIP_TEMPORARY_DIR))
231
- {
232
- $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'processing', 'statusMsg' => 'Directorywritable'));
233
- }
234
- else
235
- {
236
- $mkdir = @mkdir(PCLZIP_TEMPORARY_DIR, 0755, true);
237
- if(!$mkdir){
238
- return $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'error', 'statusMsg' => 'Error creating database backup folder (' . PCLZIP_TEMPORARY_DIR . '). Make sure you have corrrect write permissions.', 'statusCode' => 'error_creating_database_backup_folder'));
239
- }
240
- }
241
- if(is_writable(PCLZIP_TEMPORARY_DIR))
242
- {
243
- @file_put_contents(PCLZIP_TEMPORARY_DIR . '/index.php', ''); //safe
244
- }
245
- else
246
- {
247
- $chmod = chmod(PCLZIP_TEMPORARY_DIR, 777);
248
- if(!is_writable(PCLZIP_TEMPORARY_DIR)){
249
- //$this->statusLog($historyID, "verification", false, "can't set 777");
250
- return $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'error', 'statusMsg' => PCLZIP_TEMPORARY_DIR.' directory is not writable. Please set 755 or 777 file permission and try again.', 'statusCode' => 'pclzip_dir_not_writable'));
251
- }
252
- }
253
-
254
- //if verification is ok then store the settings in the options table
255
- $backup_settings_values = array();
256
- $backup_settings_values['file_block_size'] = $params['args']['file_block_size'];
257
- $backup_settings_values['is_compressed'] = $params['args']['is_compressed'];
258
- $backup_settings_values['file_loop_break_time'] = $params['args']['file_loop_break_time'];
259
- $backup_settings_values['del_host_file'] = $params['args']['del_host_file'];
260
- $backup_settings_values['task_name'] = $params['args']['backup_name'];
261
- if($params['account_info'])
262
- {
263
- $backup_settings_values['upload_loop_break_time'] = $params['account_info']['upload_loop_break_time'];
264
- $backup_settings_values['upload_file_block_size'] = $params['account_info']['upload_file_block_size'];
265
- }
266
- if($params['args']['what'] != 'files')
267
- {
268
- $backup_settings_values['db_loop_break_time'] = $params['args']['db_loop_break_time'];
269
- }
270
-
271
- //Remove the old backups (limit)
272
- $removed = $this->remove_old_backups($params['task_name']);
273
- if (is_array($removed) && isset($removed['error']))
274
- {
275
- return $this->statusLog($this -> hisID, array('stage' => 'removingBackupFiles', 'status' => 'error', 'statusMsg' => 'Error while removing old backups. ('.$removed['error'].')', 'statusCode' => 'error_while_removing_old_backups', 'responseParams' => $result_arr));
276
- }
277
-
278
- update_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
279
- $responseParams = array();
280
- $responseParams['nextFunc'] = 'backup';
281
- $responseParams['mechanism'] = 'multiCall';
282
- return $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'completed', 'statusMsg' => 'verified', 'nextFunc' => 'backup', 'responseParams' => $responseParams));
283
- }
284
- }
285
-
286
- function backup($historyID)
287
- {
288
- $zipPartNotOver = true;
289
- $this -> hisID = $historyID;
290
- $args = $this->getRequiredData($historyID, "requestParams");
291
- //argsInsideBackup argsFormat
292
- extract($args['args']);
293
- extract($args);
294
- //$task_name = $args['task_name'];
295
- //Prepare .zip file name
296
- $hash = md5(time());
297
- $label = $type ? $type : 'manual';
298
- $backup_file_name = $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
299
- $backup_file = IWP_BACKUP_DIR . '/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
300
- $backup_url = content_url() . '/infinitewp/backups/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
301
- $this -> backup_url = $backup_url;
302
- //$backup_url = $backup_file;
303
-
304
- $backup_file_info = array();
305
- $backup_file_info['backup_file_name'] = $backup_file_name;
306
- $backup_file_info['backup_file'] = $backup_file;
307
- $backup_file_info['backup_url'] = $backup_url;
308
-
309
- if(!($account_info))
310
- {
311
- $account_info = array();
312
- }
313
-
314
- if($what == 'db')
315
- {
316
- //DB alone funcion
317
- $result = $this->backupDB($historyID,$backup_file,$account_info);
318
- return $result;
319
- }
320
- elseif($what == 'files')
321
- {
322
- //FIle alone
323
- $result = $this->backupFiles($historyID,$backup_file,$account_info);
324
- return $result;
325
- }
326
- elseif($what == 'full')
327
- {
328
- //both files and db.
329
-
330
- $result = $this->backupDB($historyID,$backup_file,$account_info);
331
- //$result = $this->backupFiles($historyID,$backup_file);
332
- return $result;
333
- }
334
-
335
-
336
- }
337
-
338
- function backup_uploads($historyID)
339
- {
340
-
341
- //after creating the backup file dont forget to include it in the account_info array
342
- $this -> hisID = $historyID;
343
- $files_to_zip = '';
344
- $responseParams = $this -> getRequiredData($historyID,"responseParams");
345
- $account_info = $responseParams['response_data']['account_info'];
346
- $backup_file = $responseParams['response_data']['backup_file'];
347
-
348
- //storing the filesize value into settings array - first get the values and then append the value of filesize to it
349
- $this -> backup_settings_vals = get_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
350
- $backup_settings_values = $this -> backup_settings_vals;
351
- $backup_settings_values['actual_file_size'] = iwp_mmb_get_file_size($backup_file);
352
- update_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
353
-
354
- if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
355
- $account_info['iwp_ftp']['backup_file'] = $backup_file;
356
- iwp_mmb_print_flush('FTP upload: Start');
357
- $ftp_result = $this->ftp_backup($historyID, $account_info['iwp_ftp']);
358
- if(!$ftp_result)
359
- {
360
- return array('error' => "Unexpected Error", 'error_code' => "unexpected_error");
361
- }
362
- else
363
- {
364
- return $ftp_result;
365
- }
366
- }
367
-
368
- if (isset($account_info['iwp_amazon_s3']) && !empty($account_info['iwp_amazon_s3'])) {
369
- $account_info['iwp_amazon_s3']['backup_file'] = $backup_file;
370
- iwp_mmb_print_flush('Amazon S3 upload: Start');
371
- $amazons3_result = $this->amazons3_backup($historyID,$account_info['iwp_amazon_s3']);
372
- iwp_mmb_print_flush('Amazon S3 upload: End');
373
- if($amazons3_result['status'] == 'partiallyCompleted') //darkCode true loop
374
- {
375
- return $amazons3_result;
376
- }
377
- if ($amazons3_result !== true && $del_host_file) {
378
- //@unlink($backup_file);
379
- }
380
- if (is_array($amazons3_result) && isset($amazons3_result['error'])) {
381
- return $amazons3_result;
382
- }
383
- return $amazons3_result;
384
-
385
- }
386
-
387
- if (isset($account_info['iwp_gdrive']) && !empty($account_info['iwp_gdrive'])) {
388
- $account_info['iwp_gdrive']['backup_file'] = $backup_file;
389
- iwp_mmb_print_flush('google Drive upload: Start');
390
- $gdrive_result = $this->google_drive_backup($historyID, $account_info['iwp_gdrive']);
391
- iwp_mmb_print_flush('google Drive upload: End');
392
-
393
- return $gdrive_result;
394
-
395
- }
396
-
397
- if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
398
- $this->statusLog($historyID, array('stage' => 'uploadDrobox', 'status' => 'processing', 'statusMsg' => 'tempDirectorywritable'));
399
-
400
- $account_info['iwp_dropbox']['backup_file'] = $backup_file;
401
- iwp_mmb_print_flush('Dropbox upload: Start');
402
- $dropbox_result = $this->dropbox_backup($historyID, $account_info['iwp_dropbox']);
403
- if($dropbox_result['status'] == 'partiallyCompleted')
404
- {
405
- return $dropbox_result;
406
- }
407
- iwp_mmb_print_flush('Dropbox upload: End');
408
- if ($dropbox_result !== true && $del_host_file) {
409
- //@unlink($backup_file);
410
- }
411
-
412
- if (is_array($dropbox_result) && isset($dropbox_result['error'])) {
413
- return $dropbox_result;
414
- }
415
-
416
-
417
-
418
- $this->wpdb_reconnect();
419
-
420
- return $dropbox_result;
421
- }
422
-
423
- if ($del_host_file) {
424
- //@unlink($backup_file); //darkCode testing purpose
425
- }
426
-
427
-
428
- }
429
-
430
- function backupDB($historyID,$backup_file,$account_info = array())
431
- {
432
- $this->statusLog($historyID, array('stage' => 'backupDB', 'status' => 'processing', 'statusMsg' => 'backupDBInitiated'));
433
-
434
- if(file_exists(IWP_DB_DIR) && is_dir(IWP_DB_DIR))
435
- {
436
- $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'processing', 'statusMsg' => 'Directorywritable'));
437
- }
438
- else
439
- {
440
- $mkdir = @mkdir(IWP_DB_DIR, 0755, true);
441
- if(!$mkdir){
442
- return $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'error', 'statusMsg' => 'Error creating database backup folder (' . IWP_DB_DIR . '). Make sure you have corrrect write permissions.', 'statusCode' => 'error_creating_database_backup_folder'));
443
- }
444
- }
445
- if(is_writable(IWP_DB_DIR))
446
- {
447
- @file_put_contents(IWP_DB_DIR . '/index.php', ''); //safe
448
- }
449
- else
450
- {
451
- $chmod = chmod(IWP_DB_DIR, 777);
452
- if(!is_writable(IWP_DB_DIR)){
453
- //$this->statusLog($historyID, "verification", false, "can't set 777");
454
- return $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'error', 'statusMsg' => IWP_DB_DIR.' directory is not writable. Please set 755 or 777 file permission and try again.', 'statusCode' => 'db_dir_not_writable'));
455
- }
456
- }
457
-
458
- if(true) // if the verification is true go for the DB process
459
- {
460
- $db_index_file = '<?php
461
- global $old_url, $old_file_path;
462
- $old_url = \''.get_option('siteurl').'\';
463
- $old_file_path = \''.ABSPATH.'\';
464
- ';
465
-
466
- @file_put_contents(IWP_DB_DIR . '/index.php', $db_index_file); //safe
467
-
468
- //$this->statusLog($historyID, "verification", true, "Backup DB directory Created and writable");
469
- $this->statusLog($historyID, array('stage' => 'verification', 'status' => 'processing', 'statusMsg' => 'BackupDBDirectoryCreatedAndWritable'));
470
- $res_arr = array();
471
- $res_arr['response_data'] = array();
472
- $res_arr['file_name'] = DB_NAME;
473
- $res_arr['response_data'] = array();
474
- $res_arr['backup_file'] = $backup_file;
475
- $res_arr['backup_url'] = $this -> backup_url;
476
- $res_arr['account_info'] = $account_info;
477
- $this->statusLog($historyID, array('stage' => 'backupDB', 'status' => 'initiating', 'statusMsg' => 'createdFileNameAndSent','responseParams' => $res_arr));
478
- $db_result = $this->backupDBPHP($historyID);
479
-
480
- //arguments format - dbresult_before_zip
481
- //$result = $this->backupDBZip($historyID,$db_result,$backup_url); //if DB is succsessful do the DB zip
482
-
483
-
484
- return $db_result;
485
- }
486
-
487
- }
488
-
489
- function backupDBZip($historyID)
490
- {
491
- // if the DB backup is successful do the zip operations
492
- $responseParams = $this -> getRequiredData($historyID,"responseParams");
493
- $responseParams['category'] = 'dbZip';
494
- $backup_file = $responseParams['backup_file'];
495
- $backup_url = $responseParams['backup_url'];
496
- $responseParams['response_data']['backup_file'] = $backup_file;
497
- $responseParams['response_data']['backup_url'] = $backup_url;
498
- $responseParams['response_data']['account_info'] = $responseParams['account_info'];
499
- $db_result = $responseParams['response_data'];
500
- $this->statusLog($historyID, array('stage' => 'backupDBZip', 'status' => 'processing', 'statusMsg' => 'backupZipInitiated','responseParams' => $responseParams));
501
- if ($db_result == false) {
502
- return array(
503
- 'error' => 'Failed to backup database.'
504
- );
505
- }
506
- else if (is_array($db_result) && isset($db_result['error'])) {
507
- return array(
508
- 'error' => $db_result['error']
509
- );
510
- }
511
- else
512
- {
513
- unset($responseParams);
514
- unset($db_result);
515
- //perform the zip operations here ..... for DB
516
- iwp_mmb_print_flush('DB ZIP PCL: Start');
517
- // fallback to pclzip
518
- //define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
519
- /* require_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
520
- $archive = new IWPPclZip($backup_file);
521
- $result = $archive->add(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR); */
522
- $result = $this -> backupFilesZIP($historyID);
523
- iwp_mmb_print_flush('DB ZIP PCL: End');
524
- /* @unlink($db_result);
525
- @unlink(IWP_BACKUP_DIR.'/iwp_db/index.php'); //dark comment
526
- @rmdir(IWP_DB_DIR); */
527
- if (!$result) {
528
- return $this->statusLog($historyID, array('stage' => 'backupDBZip', 'status' => 'error', 'statusMsg' => 'Database zip failed', 'statusCode' => 'database_zip_failed'));
529
- return array(
530
- 'error' => 'Failed to zip database (pclZip - ' . $archive->error_code . '): .' . $archive->error_string
531
- );
532
- }
533
-
534
- }
535
- //$this->statusLog($historyID, array('stage' => 'backupDBZip', 'status' => 'completed', 'statusMsg' => 'backupZipCompleted'));
536
-
537
- return $result;
538
- }
539
-
540
-
541
- function backupDBPHP($historyID) //file must be db name alone ; $response_array should be table_name and its fields and callCount
542
- {
543
- //getting the settings first
544
- $this -> backup_settings_vals = get_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
545
- $backup_settings_values = $this -> backup_settings_vals;
546
-
547
- //$file_block_size = $backup_settings_values['file_block_size'];
548
- //$is_compressed = $backup_settings_values['is_compressed'];
549
- //$file_loop_break_time = $backup_settings_values['file_loop_break_time'];
550
- //$db_loop_break_time = $backup_settings_values['db_loop_break_time'];
551
-
552
- //getting the settings by other method
553
- $requestParams = $this->getRequiredData($historyID, "requestParams");
554
- $file_block_size = $requestParams['args']['file_block_size']; //darkcode changed
555
- $is_compressed = $requestParams['args']['is_compressed'];
556
- $file_loop_break_time = $requestParams['args']['file_loop_break_time'];
557
- $db_loop_break_time = $requestParams['args']['db_loop_break_time'];
558
- $zip_split_size = $requestParams['args']['zip_split_size'];
559
- $responseParams = $this -> getRequiredData($historyID,"responseParams");
560
- $file = $responseParams['file_name'];
561
- $total_time_part = 0;
562
-
563
- if(!$file)
564
- {
565
- $file = '';
566
- }
567
- $backup_file = $responseParams['backup_file'];
568
- $backup_url = $responseParams['backup_url'];
569
- $response_array = $responseParams['response_data'];
570
- $account_info = $responseParams['account_info'];
571
- $backupStage = '';
572
- if(empty($response_array))
573
- {
574
- $backupStage = 'backupDB';
575
- $callCount = 0;
576
- }
577
- else
578
- {
579
- $callCount = $response_array['callCount'];
580
- $backupStage = 'backupDBMultiCall';
581
- }
582
- //$this->statusLog($historyID, "backupDB", true, "processing", $params, true);
583
- $this->statusLog($historyID, array('stage' => $backupStage, 'status' => 'processing', 'statusMsg' => 'backupDBInitiated', 'responseParams' => $responseParams));
584
- global $wpdb;
585
- $db_folder = IWP_DB_DIR . '/';
586
- $time = microtime(true);
587
- $start = $time;
588
- $break_flag = '';
589
- $is_continue = '';
590
- $break_flag_first_key = '';
591
- $temp_sql_file_name = '';
592
- iwp_mmb_print_flush('DB DUMP PHP Fail-safe: Start');
593
- $dump_data = '';
594
- //$response_array = array();
595
- //$response_array['db_response'] = array();
596
- //$response_array['status'] = '';
597
- //$response_array['callCount'] = 0;
598
- $left_out_array = array();
599
- $left_out_table = '';
600
- $left_out_count = '';
601
- $db_final_response = array();
602
- $db_final_response['success'] = array ();
603
- $db_final_response['success']['type'] = 'db';
604
- /* $response_array = array (
605
- 'callCount' => 5,
606
- 'wp_commentmeta' => 0,
607
- 'wp_comments' => 16,
608
- 'wp_links' => 92,
609
- 'wp_options' => 1149,
610
- 'wp_postmeta' => 109,
611
- 'wp_posts' => 116,
612
- 'wp_term_relationships' => 28,
613
- 'wp_term_taxonomy' => 79,
614
- 'wp_terms' => 22,
615
- );*/
616
-
617
- $left_out_array = array_slice($response_array,-1,1);
618
- array_pop($response_array);
619
- $response_array['callCount'] = $callCount;
620
- if($file == '')
621
- {
622
- $file = DB_NAME;
623
- }
624
- $db_final_response['success']['file_name'] = $file;
625
- //$temp_sql_file_name = $file."-".$callCount.".sql"; //old method
626
- $temp_sql_file_name = $file.".sql";
627
- $file = $db_folder . $temp_sql_file_name;
628
- //file_put_contents($file, '');//safe to reset any old data
629
- /* if($callCount == 0) //used in old method
630
- {
631
- $db_final_response['success']['file'] = $file;
632
- file_put_contents($file, '');//safe to reset any old data
633
- } */
634
- //$tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
635
- $tables = $wpdb->get_results('SHOW TABLES LIKE "'.$wpdb->base_prefix.'%"', ARRAY_N);
636
-
637
- foreach ($tables as $table) {
638
- $is_continue = '';
639
- foreach($response_array as $k => $v)
640
- {
641
- if($k == $table[0])
642
- {
643
- $is_continue = 'set';
644
- break;
645
- }
646
- else
647
- {
648
- $is_continue = '';
649
- }
650
- }
651
- if($is_continue == 'set')
652
- {
653
- continue;
654
- }
655
-
656
- foreach ($left_out_array as $key => $val)
657
- {
658
- $left_out_table = $key;
659
- $left_out_count = $val;
660
- }
661
- if($left_out_table != $table[0])
662
- {
663
- //drop existing table
664
- $dump_data = "DROP TABLE IF EXISTS $table[0];";
665
- file_put_contents($file, $dump_data, FILE_APPEND);
666
- //create table
667
- $create_table = $wpdb->get_row("SHOW CREATE TABLE $table[0]", ARRAY_N);
668
- $dump_data = "\n\n" . $create_table[1] . ";\n\n";
669
- $response_array[$table[0]] = 0;
670
- file_put_contents($file, $dump_data, FILE_APPEND);
671
- //$left_out_count = '';
672
- }
673
- $count = $wpdb->get_var("SELECT count(*) FROM $table[0]");
674
- $count_field = 1;
675
-
676
- $table_fields = $wpdb->get_results("SHOW COLUMNS FROM $table[0]", ARRAY_A);
677
- $no_of_cols = count($table_fields);
678
- $initialCount = 0;
679
- $done_count = 0;
680
- $breakingCount = $responseParams['breakingCount'];
681
- if(!$breakingCount)
682
- {
683
- $breakingCount = 0;
684
- }
685
- if ($count > 100)
686
- {
687
- $count = ceil($count / 100);
688
- if($left_out_count > 0)
689
- {
690
- $temp_left_count = $left_out_count;
691
- //$done_count = floor($temp_left_count / (100*$no_of_cols));
692
- $done_count = $breakingCount;
693
- }
694
- }
695
- else if ($count > 0)
696
- {
697
- $count = 1;
698
- }
699
-
700
- for($i = 0; $i < $count; $i++){
701
- if($done_count > 0)
702
- {
703
- if($done_count > ($i))
704
- {
705
- $count_field += 100 * $no_of_cols;
706
- continue;
707
- }
708
- }
709
-
710
- iwp_mmb_auto_print('backup_db_php_fail_safe');
711
- $low_limit = $i * 100;
712
- $qry = "SELECT * FROM $table[0] LIMIT $low_limit, 100";
713
- $rows = $wpdb->get_results($qry, ARRAY_A);
714
-
715
-
716
- if (is_array($rows)) {
717
- foreach ($rows as $row) {
718
- //insert single row
719
- if(($table[0] != $left_out_table))
720
- $dump_data = "INSERT INTO $table[0] VALUES(";
721
- if(($table[0] == $left_out_table)&&($left_out_count <= $count_field))
722
- $dump_data = "INSERT INTO $table[0] VALUES(";
723
- $num_values = count($row);
724
- $j = 1;
725
- foreach ($row as $key => $value) {
726
- $count_field++;
727
- $response_array[$table[0]] = $count_field;
728
- if(($left_out_table == $table[0])&&($count_field <= $left_out_count))
729
- {
730
- $j++;
731
- continue;
732
- }
733
- $time = microtime(true);
734
- $finish_part = $time;
735
- $total_time_part = $finish_part - $this->iwpScriptStartTime;
736
-
737
- //$dump_data .= $count_field;
738
-
739
- $value = addslashes($value);
740
- $value = preg_replace("/\n/Ui", "\\n", $value);
741
- $num_values == $j ? $dump_data .= "'" . $value . "'" : $dump_data .= "'" . $value . "', ";
742
-
743
- $j++;
744
- unset($value);
745
- if($total_time_part > $db_loop_break_time)
746
- {
747
- $break_flag = 'set';
748
- $break_flag_first_key = 'set';
749
- //$this -> sendNextCallFlag = '';
750
- break;
751
- }
752
- else
753
- {
754
- $break_flag == '';
755
- }
756
- }
757
- if(($left_out_table == $table[0])&&($count_field <= $left_out_count-1))
758
- {
759
- continue;
760
- }
761
- //if(($break_flag == '')&&($count_field > $left_out_count))
762
- if(($break_flag == ''))
763
- {
764
- $dump_data .= ");\n";
765
- }
766
- else
767
- {
768
- break;
769
- }
770
- /* if($count_field != $left_out_count)
771
- {
772
- } */
773
- file_put_contents($file, $dump_data, FILE_APPEND);
774
- }
775
- }
776
- if($break_flag == 'set')
777
- {
778
- break;
779
- }
780
- }
781
-
782
-
783
- if($break_flag == '')
784
- {
785
- $dump_data = "\n\n\n";
786
- file_put_contents($file, $dump_data, FILE_APPEND);
787
- }
788
- else
789
- {
790
- //$temp_sql_file_name = "DE_dbFailsafeCont"."-".$callCount.".sql";
791
- file_put_contents($file, $dump_data, FILE_APPEND);
792
- $callCount++;
793
- //$response_array['status'] = 'partiallyCompleted';
794
- $response_array['callCount'] = $callCount;
795
- $db_final_response['success']['response_data'] = $response_array;
796
- $db_final_response['success']['breakingCount'] = $i;
797
- $db_final_response['success']['status'] = 'partiallyCompleted';
798
- $db_final_response['success']['parentHID'] = $historyID;
799
- $db_final_response['success']['backupParentHID'] = $historyID;
800
- $db_final_response['success']['nextFunc'] = 'backupDBPHP';
801
- $db_final_response['success']['file'] = $file;
802
- $db_final_response['success']['backup_file'] = $backup_file;
803
- $db_final_response['success']['backup_url'] = $backup_url;
804
- $db_final_response['success']['account_info'] = $account_info;
805
-
806
- //$this->statusLog($historyID, array('stage' => $backupStage, 'status' => 'completed', 'statusMsg' => 'singleCallCompleted'));
807
- $this->statusLog($historyID, array('stage' => $backupStage, 'status' => 'completed', 'statusMsg' => 'singleDBCallPartiallyCompleted','nextFunc' => 'backupDBPHP', 'responseParams' => $db_final_response['success']));
808
- $db_res_array = array();
809
- $db_res_array['status'] = $db_final_response['success']['status'];
810
- $db_res_array['backupParentHID'] = $db_final_response['success']['backupParentHID'];
811
- $db_res_array['parentHID'] = $db_final_response['success']['parentHID'];
812
- return $db_res_array;
813
-
814
- break;
815
- }
816
-
817
- unset($rows);
818
- unset($dump_data);
819
- }
820
-
821
- unset($tables);
822
- iwp_mmb_print_flush('DB DUMP PHP Fail-safe: End');
823
-
824
-
825
- if (iwp_mmb_get_file_size($file) == 0 || !is_file($file))
826
- {
827
- //@unlink($file);
828
- $this->statusLog($historyID, array('stage' => $backupStage, 'status' => 'error', 'statusMsg' => 'DatabaseBackupFailed', 'statusCode' => 'database_backup_failed'));
829
- return array(
830
- 'error' => 'Database backup failed. Try to enable MySQL dump on your server.', 'error_code' => 'database_backup_failed_try_to_enable_mysql_dump_on_your_server' //returning here may not be necessary
831
- );
832
- }
833
- $db_final_response['success']['response_data'] = $response_array;
834
- $db_final_response['success']['backup_file'] = $backup_file;
835
- $db_final_response['success']['backup_url'] = $backup_url;
836
- $db_final_response['success']['parentHID'] = $historyID;
837
- $db_final_response['success']['backupParentHID'] = $historyID;
838
- $db_final_response['success']['nextFunc'] = 'backupDBZip';
839
- $db_final_response['success']['account_info'] = $account_info;
840
- //$this->statusLog($historyID, "backupDB", true, "completed", $params, true);
841
- //$this->statusLog($historyID, array('stage' => $backupStage, 'status' => 'completed', 'statusMsg' => 'backupDBCompleted'));
842
- $db_final_response['success']['status'] = 'partiallyCompleted';
843
- unset($response_array);
844
- $this->statusLog($historyID, array('stage' => $backupStage, 'status' => 'completed', 'statusMsg' => 'backupDBCompleted','nextFunc' => 'backupDBZip', 'responseParams' => $db_final_response['success']));
845
- unset($db_final_response['success']['response_data']);
846
- //to continue in the same call
847
- if(($db_loop_break_time - $total_time_part) > 5)
848
- {
849
- return $this->backupDBZip($historyID);
850
- }
851
- else
852
- {
853
- $db_res_array = array();
854
- $db_res_array['status'] = $db_final_response['success']['status'];
855
- $db_res_array['backupParentHID'] = $db_final_response['success']['backupParentHID'];
856
- $db_res_array['parentHID'] = $db_final_response['success']['parentHID'];
857
- return $db_res_array;
858
- }
859
-
860
- }
861
-
862
- function backupFiles($historyID, $backup_file='', $account_info = array(), $exclude = array(), $include = array())
863
- {
864
- $this -> hisID = $historyID;
865
-
866
- //for exclude and include
867
- $requestParams = $this->getRequiredData($historyID, "requestParams");
868
- $exclude = $requestParams['args']['exclude'];
869
- $include = $requestParams['args']['include'];
870
- $exclude_extensions = $requestParams['args']['exclude_extensions'];
871
- $exclude_file_size = $requestParams['args']['exclude_file_size'];
872
- if(empty($exclude_extensions))
873
- {
874
- $exclude_extensions = array();
875
- }
876
- else if($exclude_extensions == 'eg. .zip,.mp4')
877
- {
878
- $exclude_extensions = array();
879
- }
880
- else
881
- {
882
- $exclude_extensions_array = explode(",",$exclude_extensions);
883
- $exclude_extensions = array();
884
- $exclude_extensions = $exclude_extensions_array;
885
- }
886
- if($backup_file != '')
887
- {
888
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'processing', 'statusMsg' => 'backupFilesInitiated'));
889
- }
890
- $backup_url = $this -> backup_url;
891
- if($backup_file == '')
892
- {
893
- $responseParams = $this -> getRequiredData($this -> hisID, "responseParams");
894
- $backup_file = $responseParams['response_data']['backup_file'];
895
- $backup_url = $responseParams['response_data']['backup_url'];
896
- $category = $responseParams['category'];
897
- $account_info = $responseParams['response_data']['account_info'];
898
- $zip_split_part = $responseParams['response_data']['zip_split_part'];
899
- if(empty($zip_split_part))
900
- {
901
- $zip_split_part = 0;
902
- }
903
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'processing', 'statusMsg' => 'backupFilesInitiated','responseParams' => $responseParams));
904
- }
905
- /* if($category == "fileZipAfterDBZip")
906
- {
907
- $account_info = $responseParams['account_info'];
908
- } */
909
-
910
-
911
-
912
- //Always remove backup folders
913
- $remove = array(
914
- trim(basename(WP_CONTENT_DIR)) . "/infinitewp/backups",
915
- trim(basename(WP_CONTENT_DIR)) . "/" . md5('iwp_mmb-client') . "/iwp_backups",
916
- trim(basename(WP_CONTENT_DIR)) . "/cache",
917
- trim(basename(WP_CONTENT_DIR)) . "/w3tc"
918
- );
919
-
920
- if((!empty($exclude_file_size))||(!empty($exclude_extensions)))
921
- {
922
- //removing files which are larger than the specified size
923
- $total_files_array = get_all_files_from_dir(ABSPATH, $remove);
924
- $files_excluded_by_size = array();
925
- foreach($total_files_array as $key => $value)
926
- {
927
- $this_base_name = basename($value);
928
- $skip_after_ext = false;
929
- //file extension based exclude
930
- if(is_array($exclude_extensions) && (!empty($exclude_extensions)))
931
- {
932
- foreach($exclude_extensions as $ext)
933
- {
934
- $this_pos = strrpos($this_base_name, $ext);
935
- if($this_pos !== false)
936
- {
937
- if(substr($this_base_name, $this_pos) == $ext)
938
- {
939
- $files_excluded_by_size[] = substr($value, strlen(ABSPATH));
940
- $skip_after_ext = true; //to skip the file exclude by size
941
- break;
942
- }
943
- }
944
- }
945
- }
946
- if($skip_after_ext)
947
- {
948
- continue;
949
- }
950
- //file size based exclude
951
- if(!empty($exclude_file_size))
952
- {
953
- if(iwp_mmb_get_file_size($value) >= $exclude_file_size*1024*1024)
954
- {
955
- $files_excluded_by_size[] = substr($value, strlen(ABSPATH));
956
- }
957
- }
958
- }
959
- $remove = array_merge($remove, $files_excluded_by_size);
960
- }
961
- $exclude = array_merge($exclude, $remove);
962
-
963
- //Exclude paths
964
-
965
-
966
- //Include paths by default
967
- $add = array(
968
- trim(WPINC),
969
- trim(basename(WP_CONTENT_DIR)),
970
- "wp-admin"
971
- );
972
- chdir(ABSPATH);
973
- $include_data = array();
974
- if (!empty($include) && is_array($include)) {
975
- foreach ($include as $data) {
976
- if ($data && file_exists(ABSPATH . $data))
977
- $include_data[] = ABSPATH . $data . '/';
978
- }
979
- }
980
-
981
- foreach ($add as $data) {
982
- if (file_exists(ABSPATH . $data))
983
- $include_data[] = ABSPATH . $data . '/';
984
- }
985
-
986
- //Include root files
987
- if ($handle = opendir(ABSPATH)) {
988
- while (false !== ($file = readdir($handle))) {
989
- if ($file != "." && $file != ".." && !is_dir($file) && file_exists(ABSPATH . $file)) {
990
- $include_data[] = ABSPATH . $file;
991
- }
992
- }
993
- closedir($handle);
994
- }
995
-
996
- //exclude paths
997
- $exclude_data = array();
998
- if (!empty($exclude) && is_array($exclude)) {
999
- foreach ($exclude as $data) {
1000
- if (is_dir(ABSPATH . $data))
1001
- $exclude_data[] = $data . '/';
1002
- else
1003
- $exclude_data[] = $data;
1004
- }
1005
- }
1006
-
1007
- foreach ($remove as $rem) {
1008
- $exclude_data[] = $rem . '/';
1009
- }
1010
-
1011
- iwp_mmb_print_flush('Exclude Include Time Taken');
1012
-
1013
- $result_arr = array();
1014
- $result_arr['response_data']['nextCount'] = 0;
1015
- $result_arr['status'] = 'processing';
1016
- $result_arr['category'] = $category;
1017
- $result_arr['response_data']['include_data'] = $include_data;
1018
- $result_arr['response_data']['exclude_data'] = $exclude_data;
1019
- $result_arr['response_data']['backup_file'] = $backup_file;
1020
- $result_arr['response_data']['backup_url'] = $backup_url;
1021
- $result_arr['response_data']['account_info'] = $account_info;
1022
- $result_arr['response_data']['zip_split_part'] = $zip_split_part;
1023
- //$result_arr['response_data']['files_excluded_by_size'] = $files_excluded_by_size;
1024
-
1025
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'processing', 'statusMsg' => 'backupFileSingleCallStage1Complete','responseParams' => $result_arr));
1026
- unset($result_arr);
1027
- $result = $this->backupFilesZIP($this -> hisID);
1028
- return $result;
1029
- }
1030
-
1031
-
1032
- function backupFilesZIP($historyID)
1033
- {
1034
- $this -> hisID = $historyID;
1035
- $files_to_zip = '';
1036
- $files_with_error = array();
1037
- $files_excluded_by_size = array();
1038
- $start34 = microtime(true);
1039
- //get the backup settings values from options table
1040
- $this -> backup_settings_vals = get_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
1041
- $backup_settings_values = $this -> backup_settings_vals;
1042
- //$file_block_size = $backup_settings_values['file_block_size'];
1043
- //$is_compressed = $backup_settings_values['is_compressed'];
1044
- //$file_loop_break_time = $backup_settings_values['file_loop_break_time'];
1045
- //$task_name = $backup_settings_values['task_name'];
1046
-
1047
- //get the settings by other method
1048
- $requestParams = $this->getRequiredData($historyID, "requestParams");
1049
- $file_block_size = $requestParams['args']['file_block_size']; //darkcode changed
1050
- $is_compressed = $requestParams['args']['is_compressed'];
1051
- $file_loop_break_time = $requestParams['args']['file_loop_break_time'];
1052
- $task_name = $requestParams['args']['backup_name'];
1053
- $exclude_file_size = $requestParams['args']['exclude_file_size'];
1054
- $zip_split_size = $requestParams['args']['zip_split_size'];
1055
-
1056
- if($backup_settings_values['dbFileHashValue'][$historyID])
1057
- {
1058
- $dbFileHashValue = $backup_settings_values['dbFileHashValue'][$historyID];
1059
- }
1060
- else
1061
- {
1062
- $dbFileHashValue = array();
1063
- }
1064
- $responseParams = $this -> getRequiredData($historyID,"responseParams");
1065
- $category = $responseParams['category']; //Am getting the category to perform the dbZip actions
1066
-
1067
- if(!$responseParams)
1068
- {
1069
- return $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'error', 'statusMsg' => 'Backup of files failed - Error while fetching table data', 'statusCode' => 'backup_of_files_failed_error_while_fetching_table_data'));
1070
- }
1071
-
1072
- $include_data = $responseParams['response_data']['include_data'];
1073
- $exclude_data = $responseParams['response_data']['exclude_data'];
1074
- $backup_file = $responseParams['response_data']['backup_file'];
1075
- $backup_url = $responseParams['response_data']['backup_url'];
1076
- $nextCount = $responseParams['response_data']['nextCount'];
1077
- $account_info = $responseParams['response_data']['account_info'];
1078
- $files_with_error = $responseParams['response_data']['files_with_error'];
1079
- $files_excluded_by_size = $responseParams['response_data']['files_excluded_by_size'];
1080
- $p_filedescr_list = $responseParams['response_data']['p_filedescr_list'];
1081
- $zip_split_part = $responseParams['response_data']['zip_split_part'];
1082
- $is_new_zip = $responseParams['response_data']['is_new_zip'];
1083
- /* if(empty($zip_split_part))
1084
- {
1085
- $zip_split_part = 1;
1086
- } */
1087
- if((!empty($zip_split_part))&&(!empty($is_new_zip)))
1088
- {
1089
- if(strpos($backup_file, '_iwp_part_'))
1090
- {
1091
- $backup_file = substr($backup_file, 0, strpos($backup_file, '_iwp_part_')).'_iwp_part_'.$zip_split_part.'.zip';
1092
- $backup_url = substr($backup_url, 0, strpos($backup_url, '_iwp_part_')).'_iwp_part_'.$zip_split_part.'.zip';
1093
- }
1094
- else
1095
- {
1096
- $backup_file = substr($backup_file, 0, strpos($backup_file, '.zip')).'_iwp_part_'.$zip_split_part.'.zip';
1097
- $backup_url = substr($backup_url, 0, strpos($backup_url, '.zip')).'_iwp_part_'.$zip_split_part.'.zip';
1098
- }
1099
- }
1100
- else
1101
- {
1102
- $zip_split_part = 0;
1103
- }
1104
-
1105
- if(!$p_filedescr_list)
1106
- {
1107
- $p_filedescr_list = array();
1108
- }
1109
- if(!$files_with_error)
1110
- {
1111
- $files_with_error = array();
1112
- }
1113
- if(!$files_excluded_by_size)
1114
- {
1115
- $files_excluded_by_size = array();
1116
- }
1117
-
1118
- include_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.php';
1119
- //define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
1120
-
1121
- //include_once $GLOBALS['iwp_mmb_plugin_dir'].'/pclzip.class.split.php';
1122
- $returnArr = array();
1123
- if(!$nextCount)
1124
- {
1125
- $nextCount = 0;
1126
- }
1127
- if((($nextCount != 0)||($category == 'fileZipAfterDBZip'))&&(empty($is_new_zip)))
1128
- {
1129
- unset($responseParams);
1130
- $initialFileSize = iwp_mmb_get_file_size($backup_file)/1024/1024;
1131
- $returnArr = $this->backupFilesNext($include_data, $exclude_data, $backup_file, $backup_url, $nextCount, $p_filedescr_list, $account_info, $files_with_error, $files_excluded_by_size, $zip_split_part);
1132
- $fileNextTimeTaken = microtime(true) - $this->iwpScriptStartTime;
1133
- echo "<br>Total file size".(iwp_mmb_get_file_size($backup_file)/1024/1024);
1134
- $file_size_in_this_call = (iwp_mmb_get_file_size($backup_file)/1024/1024) - $initialFileSize;
1135
- echo "<br>file size in this call".$file_size_in_this_call;
1136
- echo "<br>Time taken in this call ".$fileNextTimeTaken."<br>";
1137
- if(($file_size_in_this_call == 0) && !(is_array($returnArr) && !empty($returnArr['error'])) && !(is_array($returnArr) && !empty($returnArr['isGetFileList'])))
1138
- {
1139
- return array( 'error' => 'Zip-error: Unable to zip', 'error_code' => 'zip_error_unable_to_zip');
1140
- }
1141
- return $returnArr;
1142
- }
1143
- else
1144
- {
1145
- //$nextCount = 0;
1146
- $this->statusLog($this->hisID, array('stage' => 'backupFiles', 'status' => 'processing', 'statusMsg' => 'backupSingleCallInitiated','responseParams' => $responseParams));
1147
-
1148
- $time = microtime(true);
1149
- $start = $time;
1150
- //$archive = new IWPPclZip('../archive.zip');
1151
- $archive = new IWPPclZip($backup_file);
1152
- if($category == 'dbZip')
1153
- {
1154
- if(empty($p_filedescr_list))
1155
- {
1156
- //define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
1157
- $p_filedescr_list_array = $archive->getFileList(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_CHUNK_BLOCK_SIZE, $file_block_size, PCLZIP_OPT_HISTORY_ID, $historyID); //darkCode set the file block size here .. static values
1158
- $p_filedescr_list = $p_filedescr_list_array['p_filedescr_list'];
1159
- unset($p_filedescr_list_array['p_filedescr_list']);
1160
-
1161
- if($p_filedescr_list_array['status'] == 'partiallyCompleted')
1162
- {
1163
- $result_arr = array();
1164
- $result_arr = $responseParams;
1165
- $result_arr['nextFunc'] = 'backupFilesZIP';
1166
- $result_arr['response_data']['p_filedescr_list'] = $p_filedescr_list;
1167
- unset($p_filedescr_list);
1168
- $result_arr['response_data']['complete_folder_list'] = $p_filedescr_list_array['complete_folder_list'];
1169
- unset($p_filedescr_list_array);
1170
- $this->statusLog($this -> hisID, array('stage' => 'gettingFileList', 'status' => 'processing', 'statusMsg' => 'gettingFileListInMultiCall','responseParams' => $result_arr));
1171
- $resArray = array();
1172
- $resArray['status'] = 'partiallyCompleted';
1173
- $resArray['backupParentHID'] = $historyID;
1174
- return $resArray;
1175
- }
1176
- elseif(($p_filedescr_list_array['status'] == 'error')||(!$p_filedescr_list_array))
1177
- {
1178
- return $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'error', 'statusMsg' => 'Backup of files failed - Error while preparing file list', 'statusCode' => 'dbZip_backup_of_files_failed_error_while_preparing_file_list'));
1179
- }
1180
- elseif($p_filedescr_list_array['status'] == 'completed')
1181
- {
1182
-
1183
- }
1184
- }
1185
- }
1186
- else
1187
- {
1188
- if(empty($p_filedescr_list))
1189
- {
1190
- $p_filedescr_list_array = $archive->getFileList($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data, PCLZIP_OPT_CHUNK_BLOCK_SIZE, $file_block_size, PCLZIP_OPT_HISTORY_ID, $historyID); //testing darkCode set the file block size here .. static values
1191
-
1192
- $p_filedescr_list = $p_filedescr_list_array['p_filedescr_list'];
1193
- unset($p_filedescr_list_array['p_filedescr_list']);
1194
- $next_file_index = $p_filedescr_list_array['next_file_index'];
1195
-
1196
- /* $resArray = array();
1197
- $resArray['status'] = 'completed';
1198
- //$resArray['backupParentHID'] = $historyID;
1199
- return $resArray;
1200
- exit; */
1201
-
1202
- if($p_filedescr_list_array['status'] == 'partiallyCompleted')
1203
- {
1204
- $result_arr = array();
1205
- $result_arr = $responseParams;
1206
- $result_arr['nextFunc'] = 'backupFilesZIP';
1207
- $result_arr['response_data']['p_filedescr_list'] = $p_filedescr_list;
1208
- unset($p_filedescr_list);
1209
- $result_arr['response_data']['next_file_index'] = $next_file_index;
1210
- $result_arr['response_data']['complete_folder_list'] = $p_filedescr_list_array['complete_folder_list'];
1211
- unset($p_filedescr_list_array);
1212
- $this->statusLog($this -> hisID, array('stage' => 'gettingFileList', 'status' => 'processing', 'statusMsg' => 'gettingFileListInMultiCall','responseParams' => $result_arr));
1213
-
1214
- $resArray = array();
1215
- $resArray['status'] = 'partiallyCompleted';
1216
- $resArray['backupParentHID'] = $historyID;
1217
- return $resArray;
1218
- }
1219
- elseif(($p_filedescr_list_array['status'] == 'error')||(!$p_filedescr_list_array))
1220
- {
1221
- return $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'error', 'statusMsg' => 'Backup of files failed - Error while preparing file list', 'statusCode' => 'backup_of_files_failed_error_while_preparing_file_list'));
1222
- }
1223
- elseif($p_filedescr_list_array['status'] == 'completed')
1224
- {
1225
-
1226
- }
1227
- }
1228
- }
1229
- //usort($p_filedescr_list, "cmp");
1230
- $p_options = array ( //darkCode static values
1231
- 77021 => true, //tempFile ON
1232
- 77007 => !($is_compressed), //if we dont need to compress .. set as true
1233
- 77020 => 63082332, //setting tempFIle threshold value here
1234
- 78999 => $file_block_size,
1235
- );
1236
- $v_result = 1;
1237
- $v_header = array();
1238
- $p_result_list = array();
1239
- $v_nb = sizeof($p_result_list);
1240
- $v_header_list = array();
1241
- $v_comment = '';
1242
- //$nextCount = 0;
1243
- $archive->privOpenFd('wb');
1244
- $p_filedescr_list_omitted = array();
1245
- $omitted_flag = '';
1246
- $p_filedescr_list_size = sizeof($p_filedescr_list);
1247
- echo "loopStarted";
1248
- for ($j=$nextCount; ($j<$p_filedescr_list_size) && ($v_result==1); $j++) {
1249
- // ----- Format the filename
1250
- $p_filedescr_list[$j]['filename'] = IWPPclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
1251
-
1252
- // ----- Skip empty file names
1253
-
1254
- // TBC : Can this be possible ? not checked in DescrParseAtt ?
1255
- if ($p_filedescr_list[$j]['filename'] == "") {
1256
- continue;
1257
- }
1258
-
1259
- // ----- Check the filename
1260
- if ( ($p_filedescr_list[$j]['type'] != 'virtual_file')
1261
- && (!file_exists($p_filedescr_list[$j]['filename']))) {
1262
- echo 'FILE DOESNT EXIST';
1263
- }
1264
-
1265
- // ----- Look if it is a file or a dir with no all path remove option
1266
- // or a dir with all its path removed
1267
- // if ( (is_file($p_filedescr_list[$j]['filename']))
1268
- // || ( is_dir($p_filedescr_list[$j]['filename'])
1269
- if ( ($p_filedescr_list[$j]['type'] == 'file')
1270
- || ($p_filedescr_list[$j]['type'] == 'virtual_file')
1271
- || ( ($p_filedescr_list[$j]['type'] == 'folder')
1272
- && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
1273
- || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
1274
- ) {
1275
-
1276
- $time = microtime(true);
1277
- $finish_part = $time;
1278
- $total_time_part = $finish_part - $start;
1279
- /* if(($total_time_part > 2)&&($p_filedescr_list[$j]['size'] > 5000000))
1280
- {
1281
- $p_filedescr_list_omitted[$j] = $p_filedescr_list[$j];
1282
- $v_nb++;
1283
- $nextCount = $v_nb;
1284
- $omitted_flag = 'set';
1285
- continue;
1286
-
1287
- }
1288
- */
1289
- // ----- Add the file
1290
- $v_result = $archive->privAddFile($p_filedescr_list[$j], $v_header, $p_options);
1291
-
1292
- // ----- Store the file infos
1293
- $p_result_list[$v_nb++] = $v_header;
1294
- $nextCount = $j+1;
1295
-
1296
- if ($v_result != 1) {
1297
- echo 'Error zipping this file'.$p_filedescr_list[$j]['filename'];
1298
- $files_with_error[] = $p_filedescr_list[$j]['filename'];
1299
- if($v_result == -10)
1300
- {
1301
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'Zip-error: Error compressing the file "'.$p_filedescr_list[$j]['filename'].'".Try excluding this file and try again.', 'statusCode' => 'zip_error_while_compressing_file'));
1302
- }
1303
- continue;
1304
- //return $v_result;
1305
- }
1306
- }
1307
-
1308
- $time = microtime(true);
1309
- $finish = $time;
1310
- $total_time = $finish - $this->iwpScriptStartTime;
1311
- //if(($total_time > $file_loop_break_time)||) //darkCode static Values
1312
- $buffer_size = $zip_split_size*1024*1024 - 3*1024*1024*$file_block_size;
1313
- $is_new_zip = false;
1314
- if(($total_time > $file_loop_break_time)||(iwp_mmb_get_file_size($backup_file) >= $buffer_size))
1315
- {
1316
- if(iwp_mmb_get_file_size($backup_file) >= $buffer_size)
1317
- {
1318
- $zip_split_part += 1;
1319
- $is_new_zip = true;
1320
- }
1321
- break;
1322
- }
1323
- //iwp_mmb_print_flush("|");
1324
- iwp_mmb_auto_print("multiCallZip");
1325
- echo("|");
1326
- }
1327
- echo "loopEnded";
1328
- $v_offset = @ftell($archive->zip_fd);
1329
- $v_header_list = $p_result_list;
1330
- //$nextCount = sizeof($p_result_list);
1331
- for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
1332
- {
1333
- // ----- Create the file header
1334
- if ($v_header_list[$i]['status'] == 'ok') {
1335
- if (($v_result = $archive->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
1336
- // ----- Return
1337
- echo 'error writing header';
1338
- //return $v_result;
1339
- }
1340
- $v_count++;
1341
- }
1342
-
1343
- // ----- Transform the header to a 'usable' info
1344
- $archive->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
1345
- }
1346
- $v_size = @ftell($archive->zip_fd)-$v_offset;
1347
- $archive->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment);
1348
- $archive->privCloseFd();
1349
- echo 'next Count -'.$nextCount;
1350
- if(($nextCount == sizeof($p_filedescr_list)+1)||($nextCount == sizeof($p_filedescr_list)))
1351
- {
1352
- $nextCount = "completed";
1353
- $status = "completed";
1354
- }
1355
- else
1356
- {
1357
- $status = "partiallyCompleted";
1358
- }
1359
- $result_arr = array();
1360
-
1361
- //return $p_result_list;
1362
- $result_arr['response_data']['nextCount'] = $nextCount;
1363
- $result_arr['status'] = $status;
1364
- $result_arr['category'] = $category;
1365
- $result_arr['nextFunc'] = 'backupFilesZIP';
1366
- $result_arr['response_data']['include_data'] = $include_data;
1367
- $result_arr['response_data']['exclude_data'] = $exclude_data;
1368
- $result_arr['response_data']['backup_file'] = $backup_file;
1369
- $result_arr['response_data']['backup_url'] = $backup_url;
1370
- $result_arr['response_data']['account_info'] = $account_info;
1371
- $result_arr['response_data']['files_with_error'] = $files_with_error;
1372
- $result_arr['response_data']['files_excluded_by_size'] = $files_excluded_by_size;
1373
- $result_arr['response_data']['is_new_zip'] = $is_new_zip;
1374
- //$result_arr['response_data']['p_filedescr_list'] = $p_filedescr_list;
1375
- $result_arr['response_data']['zip_split_part'] = $zip_split_part;
1376
- $resArray = array (
1377
- 'responseData' =>
1378
- array (
1379
- 'stage' => 'backupFiles',
1380
- 'status' => 'completed',
1381
-
1382
- ),
1383
- 'parentHID' => $this -> hisID,
1384
- 'nextFunc' => 'backupFilesZIP',
1385
- 'status' => $status,
1386
- 'backupParentHID' => $this -> hisID,
1387
- 'category' => $category,
1388
- );
1389
- if(($nextCount == 0)&&($nextCount != 'completed'))
1390
- {
1391
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'error', 'statusMsg' => 'backupFileSingleCall'.$status, 'statusCode' => 'backup_file_single_call_error', 'responseParams' => $result_arr));
1392
- $nextFunc = 'error';
1393
- $status = 'error';
1394
- return array('error' => 'Must be error');
1395
- }
1396
- if($status == 'partiallyCompleted')
1397
- {
1398
- echo 'filesNextCount: '.$nextCount;
1399
- echo 'totalFilesCount: '.count($p_filedescr_list);
1400
- $result_arr['response_data']['p_filedescr_list'] = $p_filedescr_list;
1401
- unset($p_filedescr_list);
1402
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'completed', 'statusMsg' => 'backupFileSingleCall'.$status,'nextFunc' => 'backupFilesZIP', 'responseParams' => $result_arr));
1403
- unset($result_arr);
1404
- }
1405
- else
1406
- {
1407
- $main_category = $this -> getRequiredData($historyID,"category");
1408
- if(($main_category == 'full')&&($category != 'fileZipAfterDBZip'))
1409
- {
1410
- //storing hash values of db-file if any
1411
- $backup_settings_values['dbFileHashValue'][$historyID] = $this -> getHashValuesArray($p_filedescr_list);
1412
- update_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
1413
-
1414
- $result_arr['category'] = 'fileZipAfterDBZip';
1415
- $result_arr['nextFunc'] = 'backupFiles';
1416
- $resArray['response_data']['backup_file'] = $backup_file;
1417
- $resArray['status'] = 'partiallyCompleted'; //Here am setting partiallyCompleted to continue the loop for the full(both db and files) method
1418
- $result_arr['status'] = 'partiallyCompleted';
1419
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'partiallyCompleted', 'statusMsg' => 'backupFileSingleCall'.$status,'nextFunc' => 'backupFiles', 'responseParams' => $result_arr));
1420
- }
1421
- else
1422
- {
1423
- $paths = array();
1424
- $tempPaths = array();
1425
-
1426
- $backup_files_array = $this->get_files_array_from_iwp_part($backup_file);
1427
- $backup_file = array();
1428
- $backup_file = $backup_files_array;
1429
-
1430
- $backup_url_array = $this->get_files_array_from_iwp_part($backup_url);
1431
- $backup_url = array();
1432
- $backup_url = $backup_url_array;
1433
-
1434
- $size = round($this->get_total_files_size($backup_file) / 1024, 2);
1435
- if ($size > 1000) {
1436
- $paths['size'] = round($size / 1024, 2) . " MB"; //Modified by IWP //Mb => MB
1437
- } else {
1438
- $paths['size'] = $size . 'KB'; //Modified by IWP //Kb => KB
1439
- }
1440
- $paths['backup_name'] = $task_name;
1441
- $paths['mechanism'] = 'multicall';
1442
- $paths['server'] = array(
1443
- 'file_path' => $backup_file,
1444
- 'file_url' => $backup_url);
1445
-
1446
- $paths['time'] = time();
1447
- $paths['adminHistoryID'] = $historyID;
1448
- $paths['files_with_error'] = $files_with_error;
1449
- $paths['files_excluded_by_size'] = $files_excluded_by_size;
1450
- //$paths['hashValues'] = $this -> getHashValuesArray($p_filedescr_list);
1451
- //$paths['hashValues'] = array_merge($dbFileHashValue, $paths['hashValues']);
1452
- unset($p_filedescr_list);
1453
- $tempPath = $paths;
1454
- $paths['task_results'][$historyID] = $tempPath;
1455
- if(empty($account_info))
1456
- {
1457
- $result_arr['nextFunc'] = 'backupFilesZIPOver';
1458
- }
1459
- else
1460
- {
1461
- $resArray['status'] = 'partiallyCompleted'; //continuing the flow to backup_uploads
1462
-
1463
- $result_arr['nextFunc'] = 'backup_uploads';
1464
- $result_arr['status'] = 'partiallyCompleted';
1465
- $result_arr['response_data']['backup_file'] = $backup_file;
1466
- }
1467
-
1468
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'completed', 'statusMsg' => 'backupFileSingleCall'.$status, 'responseParams' => $result_arr,'task_result' => $paths));
1469
-
1470
- if((($main_category != 'files')&&($category == 'dbZip')) || ($main_category == 'db'))
1471
- {
1472
- @unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
1473
- @unlink(DB_NAME);
1474
- @rmdir(IWP_DB_DIR);
1475
- }
1476
-
1477
- //verification
1478
- if(is_array($backup_file))
1479
- {
1480
- foreach($backup_file as $key => $single_backup_file)
1481
- {
1482
- $verification_result = $this -> postBackupVerification($archive, $single_backup_file);
1483
- if(!$verification_result)
1484
- {
1485
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'The zip file was corrupted while zipping', 'responseParams' => $result_arr));
1486
- }
1487
- }
1488
- }
1489
- //Remove the old backups (limit)
1490
- $removed = $this->remove_old_backups($requestParams['task_name']);
1491
- if (is_array($removed) && isset($removed['error'])) {
1492
- //$error_message = $removed['error'];
1493
- return $this->statusLog($this -> hisID, array('stage' => 'removingBackupFiles', 'status' => 'error', 'statusMsg' => 'Error while removing old backups. ('.$removed['error'].')', 'statusCode' => 'remove_old_backups_error_while_removing_old_backups', 'responseParams' => $result_arr));
1494
- }
1495
-
1496
- }
1497
-
1498
- }
1499
-
1500
- return $resArray;
1501
-
1502
- }
1503
- }
1504
-
1505
- function get_total_files_size($backup_files)
1506
- {
1507
- if(is_array($backup_files))
1508
- {
1509
- $total_size = 0;
1510
- foreach($backup_files as $key => $value)
1511
- {
1512
- $total_size += iwp_mmb_get_file_size($value);
1513
- }
1514
- return $total_size;
1515
- }
1516
- else
1517
- {
1518
- return iwp_mmb_get_file_size($backup_files);
1519
- }
1520
- }
1521
-
1522
- function backupFilesNext($include_data, $exclude_data, $backup_file, $backup_url, $nextCount, $p_filedescr_list = array(), $account_info = array(), $files_with_error = array(), $files_excluded_by_size = array(), $zip_split_part = 0)
1523
- {
1524
- $historyID = $this -> hisID;
1525
- $start34 = microtime(true);
1526
- $is_new_zip = false;
1527
- $backup_settings_values = $this -> backup_settings_vals;
1528
- //$file_block_size = $backup_settings_values['file_block_size'];
1529
- //$is_compressed = $backup_settings_values['is_compressed'];
1530
- //$file_loop_break_time = $backup_settings_values['file_loop_break_time'];
1531
- //$task_name = $backup_settings_values['task_name'];
1532
-
1533
- //get the settings by other method
1534
- $requestParams = $this->getRequiredData($historyID, "requestParams");
1535
- $file_block_size = $requestParams['args']['file_block_size']; //darkcode changed
1536
- $is_compressed = $requestParams['args']['is_compressed'];
1537
- $file_loop_break_time = $requestParams['args']['file_loop_break_time'];
1538
- $task_name = $requestParams['args']['backup_name'];
1539
- $exclude_file_size = $requestParams['args']['exclude_file_size'];
1540
- $zip_split_size = $requestParams['args']['zip_split_size'];
1541
-
1542
- if($backup_settings_values['dbFileHashValue'][$historyID])
1543
- $dbFileHashValue = $backup_settings_values['dbFileHashValue'][$historyID];
1544
- else
1545
- $dbFileHashValue = array();
1546
-
1547
- $responseParams = $this -> getRequiredData($historyID,"responseParams");
1548
- $category = $responseParams['category']; //Am getting the category to perform the dbZip actions
1549
-
1550
- $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'processing', 'statusMsg' => 'backupMultiCallInitiated', 'responseParams' => $responseParams));
1551
-
1552
- $time = microtime(true);
1553
- $start = $time;
1554
- //include_once 'pclzip.class.php';
1555
- //include_once 'pclzip.class.split.php';
1556
- $archive = new IWPPclZip($backup_file);
1557
- if($category == 'dbZip')
1558
- {
1559
- if(empty($p_filedescr_list)||($nextCount == 0))
1560
- {
1561
- $p_filedescr_list_array = $archive->getFileList(IWP_DB_DIR, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_CHUNK_BLOCK_SIZE, $file_block_size, PCLZIP_OPT_HISTORY_ID, $historyID);//darkCode set the file block size here .. static values
1562
- $p_filedescr_list = $p_filedescr_list_array['p_filedescr_list'];
1563
-
1564
- if($p_filedescr_list_array['status'] == 'partiallyCompleted')
1565
- {
1566
- $result_arr = array();
1567
- $result_arr = $responseParams;
1568
- $result_arr['nextFunc'] = 'backupFilesZIP';
1569
- $result_arr['response_data']['p_filedescr_list'] = $p_filedescr_list;
1570
- $result_arr['response_data']['next_file_index'] = $p_filedescr_list_array['next_file_index'];
1571
- $result_arr['response_data']['complete_folder_list'] = $p_filedescr_list_array['complete_folder_list'];
1572
- $this->statusLog($this -> hisID, array('stage' => 'gettingFileList', 'status' => 'processing', 'statusMsg' => 'gettingFileListInMultiCall','responseParams' => $result_arr));
1573
-
1574
- $resArray = array();
1575
- $resArray['status'] = 'partiallyCompleted';
1576
- $resArray['backupParentHID'] = $historyID;
1577
- return $resArray;
1578
- }
1579
- elseif(($p_filedescr_list_array['status'] == 'error')||(!$p_filedescr_list_array))
1580
- {
1581
- return $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'error', 'statusMsg' => 'Backup of files failed - Error while preparing file list', 'statusCode' => 'backup_files_next_dbZip_backup_of_files_failed_error_while_preparing_file_list'));
1582
- }
1583
- elseif($p_filedescr_list_array['status'] == 'completed')
1584
- {
1585
-
1586
- }
1587
- }
1588
- }
1589
- else
1590
- {
1591
- if(empty($p_filedescr_list)||($nextCount == 0))
1592
- {
1593
- $p_filedescr_list_array = $archive->getFileList($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_IWP_EXCLUDE, $exclude_data, PCLZIP_OPT_CHUNK_BLOCK_SIZE, $file_block_size, PCLZIP_OPT_HISTORY_ID, $historyID); //testing darkCode set the file block size here .. static values
1594
-
1595
- $p_filedescr_list = $p_filedescr_list_array['p_filedescr_list'];
1596
-
1597
- if($p_filedescr_list_array['status'] == 'partiallyCompleted')
1598
- {
1599
- $result_arr = array();
1600
- $result_arr = $responseParams;
1601
- $result_arr['nextFunc'] = 'backupFilesZIP';
1602
- $result_arr['response_data']['p_filedescr_list'] = $p_filedescr_list;
1603
- unset($p_filedescr_list);
1604
- unset($p_filedescr_list_array['p_filedescr_list']);
1605
- $result_arr['response_data']['next_file_index'] = $p_filedescr_list_array['next_file_index'];
1606
- $result_arr['response_data']['complete_folder_list'] = $p_filedescr_list_array['complete_folder_list'];
1607
-
1608
- $this->statusLog($this -> hisID, array('stage' => 'gettingFileList', 'status' => 'processing', 'statusMsg' => 'gettingFileListInMultiCall','responseParams' => $result_arr));
1609
- $timeTaken34 = microtime(true) - $start34;
1610
- unset($p_filedescr_list_array);
1611
- $resArray = array();
1612
- $resArray['status'] = 'partiallyCompleted';
1613
- $resArray['backupParentHID'] = $historyID;
1614
- $resArray['isGetFileList'] = true;
1615
- return $resArray;
1616
- }
1617
- elseif(($p_filedescr_list_array['status'] == 'error')||(!$p_filedescr_list_array))
1618
- {
1619
- return $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'error', 'statusMsg' => 'Backup of files failed - Error while preparing file list', 'statusCode' => 'backup_files_next_p_filedescr_list_array_dbZip_backup_of_files_failed_Error_while_preparing_file_list'));
1620
- }
1621
- elseif($p_filedescr_list_array['status'] == 'completed')
1622
- {
1623
-
1624
- }
1625
- }
1626
- }
1627
- $archive->privDisableMagicQuotes();
1628
- if (($v_result=$archive->privOpenFd('rb+')) != 1)
1629
- {
1630
- $archive->privSwapBackMagicQuotes();
1631
- $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'openingFileError', 'statusCode' => 'opening_file_error'));
1632
- return array( 'error' => 'Zip-error: Error opening file', 'error_code' => 'zip_error_opening_file');
1633
- //return $v_result;
1634
- }
1635
- clearstatcache();
1636
- // ----- Read the central directory informations
1637
- $v_central_dir = array();
1638
- if (($v_result = $archive->privReadEndCentralDir($v_central_dir)) != 1)
1639
- {
1640
- echo 'error2';
1641
- $archive->privCloseFd();
1642
- $archive->privSwapBackMagicQuotes();
1643
- if(is_array($v_result) && !empty($v_result['error']))
1644
- {
1645
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => $v_result['error'], 'statusCode' => 'priv_read_end_central_dir_error'));
1646
- }
1647
- else
1648
- {
1649
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'Zip-error: Error reading end directory', 'statusCode' => 'zip_error_error_reading_end_directory'));
1650
- }
1651
- }
1652
-
1653
- // ----- Go to beginning of File
1654
- @rewind($archive->zip_fd);
1655
-
1656
- // ----- Creates a temporay file
1657
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
1658
-
1659
- // ----- Open the temporary file in write mode
1660
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb+')) == 0)
1661
- {
1662
- $archive->privCloseFd();
1663
- $archive->privSwapBackMagicQuotes();
1664
- echo 'error3';
1665
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'Unable to open temporary file', 'statusCode' => 'unable_to_open_temporary_file')); // ----- Return
1666
-
1667
- }
1668
-
1669
- // ----- Copy the files from the archive to the temporary file
1670
- // TBC : Here I should better append the file and go back to erase the central dir
1671
- $v_size = $v_central_dir['offset'];
1672
-
1673
- fseek($archive->zip_fd, $v_size, SEEK_SET);
1674
- $actualFileSize = iwp_mmb_get_file_size($backup_file);
1675
-
1676
- while ($actualFileSize != 0)
1677
- {
1678
- $v_read_size = ($actualFileSize < PCLZIP_READ_BLOCK_SIZE ? $actualFileSize : PCLZIP_READ_BLOCK_SIZE);
1679
- $v_buffer = fread($archive->zip_fd, $v_read_size);
1680
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
1681
- $actualFileSize -= $v_read_size;
1682
- }
1683
-
1684
- // ----- Swap the file descriptor
1685
- // Here is a trick : I swap the temporary fd with the zip fd, in order to use
1686
- // the following methods on the temporary fil and not the real archive
1687
- /* $v_swap = $archive->zip_fd;
1688
- $archive->zip_fd = $v_zip_temp_fd;
1689
- $v_zip_temp_fd = $v_swap; */
1690
- //usort($p_filedescr_list, "cmp");
1691
-
1692
-
1693
- //truncate the file after just at the begining of central header
1694
- fseek($archive->zip_fd, $v_size, SEEK_SET);
1695
- $truncateResult = ftruncate($archive->zip_fd, $v_size);
1696
- clearstatcache();
1697
-
1698
-
1699
- $p_options = array ( //darkCode static values
1700
- 77021 => true, //using temp method
1701
- 77007 => !($is_compressed), //if no compression is needed set as true
1702
- 77020 => 63082332,
1703
- );
1704
- $v_result = 1;
1705
- $v_header = array();
1706
- $p_result_list = array();
1707
- $v_header_list = array();
1708
- $v_nb = sizeof($v_header_list);
1709
- $v_comment = '';
1710
- //$nextCount = $_REQUEST['nextCount'];
1711
- $omitted_flag = '';
1712
- $nextCountHere = 0;
1713
- $p_filedescr_list_size = sizeof($p_filedescr_list);
1714
- $timeBeforeAdd = microtime(true) - $start34;
1715
- iwp_mmb_print_flush("loopStarted");
1716
- for ($j=($nextCount); ($j<$p_filedescr_list_size) && ($v_result==1); $j++) {
1717
- // ----- Format the filename
1718
- $p_filedescr_list[$j]['filename']
1719
- = IWPPclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
1720
-
1721
-
1722
- // ----- Skip empty file names
1723
- // TBC : Can this be possible ? not checked in DescrParseAtt ?
1724
- if ($p_filedescr_list[$j]['filename'] == "") {
1725
- continue;
1726
- }
1727
-
1728
- // ----- Check the filename
1729
- if ( ($p_filedescr_list[$j]['type'] != 'virtual_file')
1730
- && (!file_exists($p_filedescr_list[$j]['filename']))) {
1731
- echo 'FILE DOESNT EXIST';
1732
- }
1733
-
1734
- // ----- Look if it is a file or a dir with no all path remove option
1735
- // or a dir with all its path removed
1736
- // if ( (is_file($p_filedescr_list[$j]['filename']))
1737
- // || ( is_dir($p_filedescr_list[$j]['filename'])
1738
- if ( ($p_filedescr_list[$j]['type'] == 'file')
1739
- || ($p_filedescr_list[$j]['type'] == 'virtual_file')
1740
- || ( ($p_filedescr_list[$j]['type'] == 'folder')
1741
- && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
1742
- || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
1743
- ) {
1744
- $time = microtime(true);
1745
- $finish_part = $time;
1746
- $total_time_part = $finish_part - $start;
1747
- $nextCountHere = $j+1;
1748
- /* if(($total_time_part > 2)&&($p_filedescr_list[$j]['size'] > 5000000))
1749
- {
1750
- $p_filedescr_list_omitted[$j] = $p_filedescr_list[$j];
1751
- $v_nb++;
1752
- $nextCount = $v_nb;
1753
- $omitted_flag = 'set';
1754
- continue;
1755
-
1756
- } */
1757
-
1758
- // ----- Add the file
1759
- $v_result = $archive->privAddFile($p_filedescr_list[$j], $v_header, $p_options);
1760
- // ----- Store the file infos
1761
- $v_header_list[$v_nb++] = $v_header;
1762
-
1763
- if ($v_result != 1) {
1764
- //$this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'SomeError1'));
1765
- echo "error zipping this file:".$p_filedescr_list[$j]['filename'];
1766
- echo 'errorCode - '.$v_result;
1767
- $files_with_error[] = $p_filedescr_list[$j]['filename'];
1768
- if($v_result == -10)
1769
- {
1770
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'Zip-error: Error compressing the file "'.$p_filedescr_list[$j]['filename'].'".Try excluding this file and try again.', 'statusCode' => 'zip_error_while_compressing_file'));
1771
- }
1772
- continue;
1773
- //return $v_result;
1774
- }
1775
- }
1776
-
1777
- $time = microtime(true);
1778
- $finish = $time;
1779
- $total_time = $finish - $this->iwpScriptStartTime;
1780
- $buffer_size = $zip_split_size*1024*1024 - 3*1024*1024*$file_block_size;
1781
- if(($total_time > $file_loop_break_time)||(iwp_mmb_get_file_size($backup_file) >= $buffer_size)) //darkCode static values
1782
- {
1783
- if(iwp_mmb_get_file_size($backup_file) >= $buffer_size)
1784
- {
1785
- $zip_split_part += 1;
1786
- $is_new_zip = true;
1787
- }
1788
- break;
1789
- }
1790
- //iwp_mmb_print_flush("|");
1791
- iwp_mmb_auto_print("multiCallZip");
1792
- //echo "|";
1793
- }
1794
- echo "loopEnded";
1795
- $v_offset = @ftell($archive->zip_fd);
1796
- $v_size = $v_central_dir['size'];
1797
- /* while ($v_size != 0)
1798
- {
1799
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
1800
- $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
1801
- @fwrite($archive->zip_fd, $v_buffer, $v_read_size);
1802
- $v_size -= $v_read_size;
1803
- }
1804
- */
1805
- clearstatcache();
1806
- $endOfFile = iwp_mmb_get_file_size($backup_file);
1807
-
1808
-
1809
-
1810
- //writing the header which is stored in temp file
1811
-
1812
- fseek($archive->zip_fd, $endOfFile, SEEK_SET);
1813
- fseek($v_zip_temp_fd, 0, SEEK_SET);
1814
-
1815
- $v_buffer = fread($v_zip_temp_fd, $v_central_dir['size']);
1816
- $writeResult = fwrite($archive->zip_fd, $v_buffer);
1817
-
1818
-
1819
-
1820
- //array_pop($v_header_list);
1821
- //$v_header_list = $p_result_list;
1822
- // ----- Create the Central Dir files header
1823
- for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
1824
- {
1825
- // ----- Create the file header
1826
- if ($v_header_list[$i]['status'] == 'ok') {
1827
- if (($v_result = $archive->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
1828
- echo 'error4';
1829
- fclose($v_zip_temp_fd);
1830
- $archive->privCloseFd();
1831
- @unlink($v_zip_temp_name);
1832
- $archive->privSwapBackMagicQuotes();// ----- Return
1833
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'Zip-error: Error while writing header', 'statusCode' => 'zip_error_while_writing_header'));
1834
- //return $v_result;
1835
- }
1836
- $v_count++;
1837
- }
1838
-
1839
- // ----- Transform the header to a 'usable' info
1840
- $archive->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
1841
- }
1842
- // ----- Calculate the size of the central header
1843
- $v_size = @ftell($archive->zip_fd)-$v_offset;
1844
-
1845
- // ----- Create the central dir footer
1846
- if (($v_result = $archive->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
1847
- {
1848
- // ----- Reset the file list
1849
- echo 'error5';
1850
- unset($v_header_list);
1851
- $archive->privSwapBackMagicQuotes();
1852
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'Zip-Error: Error while writing footer', 'statusCode' => 'zip_error_while_writing_footer'));
1853
- }
1854
-
1855
- // ----- Swap back the file descriptor
1856
- /* $v_swap = $archive->zip_fd;
1857
- $archive->zip_fd = $v_zip_temp_fd;
1858
- $v_zip_temp_fd = $v_swap; */
1859
-
1860
- // ----- Close
1861
- $archive->privCloseFd();
1862
-
1863
- // ----- Close the temporary file
1864
- @fclose($v_zip_temp_fd);
1865
-
1866
- // ----- Magic quotes trick
1867
- $archive->privSwapBackMagicQuotes();
1868
-
1869
- // ----- Delete the zip file
1870
- // TBC : I should test the result ...
1871
- //@unlink($archive->zipname);
1872
- @unlink($v_zip_temp_name);
1873
-
1874
- // ----- Rename the temporary file
1875
- // TBC : I should test the result ...
1876
- //@rename($v_zip_temp_name, $archive->zipname);
1877
- //IWPPclZipUtilRename($v_zip_temp_name, $archive->zipname);
1878
-
1879
- $nextCount = $nextCountHere;
1880
-
1881
- $size_file_des = sizeof($p_filedescr_list);
1882
- if($nextCount == $size_file_des)
1883
- //if(true)
1884
- {
1885
- $nextCount = "completed";
1886
- $status = "completed";
1887
-
1888
- }
1889
- else{
1890
- $status = "partiallyCompleted";
1891
- }
1892
-
1893
- $result_arr = array();
1894
- $result_arr['response_data']['nextCount'] = $nextCount;
1895
- $result_arr['status'] = $status;
1896
- $result_arr['category'] = $category;
1897
- $result_arr['nextFunc'] = 'backupFilesZIP';
1898
- $result_arr['response_data']['include_data'] = $include_data;
1899
- $result_arr['response_data']['exclude_data'] = $exclude_data;
1900
- $result_arr['response_data']['backup_file'] = $backup_file;
1901
- $result_arr['response_data']['backup_url'] = $backup_url;
1902
- $result_arr['response_data']['account_info'] = $account_info;
1903
- $result_arr['response_data']['zip_split_part'] = $zip_split_part;
1904
- $result_arr['response_data']['is_new_zip'] = $is_new_zip;
1905
- $result_arr['response_data']['files_with_error'] = $files_with_error;
1906
- $result_arr['response_data']['files_excluded_by_size'] = $files_excluded_by_size;
1907
-
1908
- //$result_arr['response_data']['p_filedescr_list'] = $p_filedescr_list;
1909
- $resArray = array (
1910
- 'responseData' =>
1911
- array (
1912
- 'stage' => 'backupFilesNext',
1913
- 'status' => 'completed',
1914
- ),
1915
- 'parentHID' => $this -> hisID,
1916
- 'nextFunc' => 'backupFilesZIP',
1917
- 'status' => $status,
1918
- 'backupParentHID' => $this -> hisID,
1919
- );
1920
- if(($nextCount == 0)&&($nextCount != 'completed'))
1921
- {
1922
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'error', 'statusMsg' => 'backupFileNextCallError'.$status, 'responseParams' => $result_arr, 'statusCode' => 'backup_file_next_call_error'));
1923
- $nextFunc = 'error';
1924
- $status = 'error';
1925
- return array('error' => 'Must be error', 'error_code' => 'backup_file_next_call_error');
1926
- }
1927
- if($status == "partiallyCompleted")
1928
- {
1929
- echo 'filesNextCount: '.$nextCount;
1930
- echo 'totalFilesCount: '.count($p_filedescr_list);
1931
- $result_arr['response_data']['p_filedescr_list'] = $p_filedescr_list;
1932
- unset($p_filedescr_list);
1933
- $this->statusLog($this -> hisID, array('stage' => 'backupFilesMultiCall', 'status' => 'completed', 'statusMsg' => 'nextCall'.$status,'nextFunc' => 'backupFilesZIP', 'responseParams' => $result_arr));
1934
- unset($result_arr);
1935
- }
1936
- else
1937
- {
1938
- $main_category = $this -> getRequiredData($historyID,"category");
1939
-
1940
- //this is where the call goes to backupFiles after DB complete
1941
- if(($main_category == 'full')&&($category != 'fileZipAfterDBZip'))
1942
- {
1943
- //storing hash values of db-file if any
1944
- $backup_settings_values['dbFileHashValue'][$historyID] = $this -> getHashValuesArray($p_filedescr_list);
1945
- update_option('iwp_client_multi_backup_temp_values', $backup_settings_values);
1946
-
1947
- $result_arr['category'] = 'fileZipAfterDBZip';
1948
- $resArray['status'] = 'partiallyCompleted';
1949
- $result_arr['nextFunc'] = 'backupFiles';
1950
- $result_arr['status'] = 'partiallyCompleted';
1951
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'completed', 'statusMsg' => 'nextCall'.$status,'nextFunc' => 'backupFiles', 'responseParams' => $result_arr));
1952
- }
1953
- else
1954
- {
1955
-
1956
- //$this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'completed', 'statusMsg' => 'nextCall'.$status, 'responseParams' => $result_arr));
1957
-
1958
- $paths = array();
1959
- $tempPaths = array();
1960
-
1961
- $backup_files_array = $this->get_files_array_from_iwp_part($backup_file);
1962
- $backup_file = array();
1963
- $backup_file = $backup_files_array;
1964
-
1965
- $backup_url_array = $this->get_files_array_from_iwp_part($backup_url);
1966
- $backup_url = array();
1967
- $backup_url = $backup_url_array;
1968
-
1969
- $size = round($this->get_total_files_size($backup_file) / 1024, 2);
1970
- if ($size > 1000) {
1971
- $paths['size'] = round($size / 1024, 2) . " MB"; //Modified by IWP //Mb => MB
1972
- } else {
1973
- $paths['size'] = $size . 'KB'; //Modified by IWP //Kb => KB
1974
- }
1975
- $paths['backup_name'] = $task_name;
1976
- $paths['mechanism'] = 'multicall';
1977
- $paths['server'] = array(
1978
- 'file_path' => $backup_file,
1979
- 'file_url' => $backup_url,
1980
- );
1981
-
1982
- $paths['time'] = time();
1983
- $paths['adminHistoryID'] = $historyID;
1984
- $paths['files_with_error'] = $files_with_error;
1985
- $paths['files_excluded_by_size'] = $files_excluded_by_size;
1986
- //$paths['hashValues'] = $this -> getHashValuesArray($p_filedescr_list);
1987
- //$paths['hashValues'] = array_merge($dbFileHashValue, $paths['hashValues']);
1988
- unset($p_filedescr_list);
1989
- $tempPath = $paths;
1990
- $paths['task_results'][$historyID] = $tempPath;
1991
-
1992
- if(empty($account_info))
1993
- {
1994
- //this is where the call goes to upload after backup zip completion ..
1995
- $resArray['status'] = 'completed';
1996
- $result_arr['nextFunc'] = 'backupFilesZIPOver';
1997
- $result_arr['status'] = 'completed';
1998
- }
1999
- else
2000
- {
2001
- $resArray['actual_file_size'] = $size; //necessary for dropbox function
2002
- $resArray['status'] = 'partiallyCompleted';
2003
- $result_arr['nextFunc'] = 'backup_uploads';
2004
- $result_arr['status'] = 'partiallyCompleted';
2005
- $result_arr['actual_file_size'] = $size;
2006
- $result_arr['backup_file'] = $backup_file;
2007
- }
2008
-
2009
- $this->statusLog($this -> hisID, array('stage' => 'backupFiles', 'status' => 'completed', 'statusMsg' => 'nextCall'.$status, 'responseParams' => $result_arr,'task_result' => $paths));
2010
-
2011
- if((($main_category != 'files')&&($category == 'dbZip')) || ($main_category == 'db'))
2012
- {
2013
- @unlink(IWP_BACKUP_DIR.'/iwp_db/index.php');
2014
- @unlink(DB_NAME);
2015
- @rmdir(IWP_DB_DIR);
2016
- }
2017
-
2018
- //checking zip corruption
2019
- if(is_array($backup_file))
2020
- {
2021
- foreach($backup_file as $key => $single_backup_file)
2022
- {
2023
- $verification_result = $this -> postBackupVerification($archive, $single_backup_file);
2024
- if(!$verification_result)
2025
- {
2026
- return $this->statusLog($historyID, array('stage' => 'backupFilesMultiCall', 'status' => 'error', 'statusMsg' => 'The zip file was corrupted while zipping', 'responseParams' => $result_arr));
2027
- }
2028
- }
2029
- }
2030
-
2031
- //Remove the old backups (limit)
2032
- $removed = $this->remove_old_backups($requestParams['task_name']);
2033
-
2034
- if (is_array($removed) && isset($removed['error'])) {
2035
- return $this->statusLog($this -> hisID, array('stage' => 'removingBackupFiles', 'status' => 'error', 'statusMsg' => 'Error while removing old backups. ('.$removed['error'].')', 'responseParams' => $result_arr, 'statusCode' => 'error_while_removing_old_backups'));
2036
- }
2037
-
2038
- }
2039
- }
2040
- $fileNextTimeTaken = microtime(true) - $start34;
2041
-
2042
- return $resArray;
2043
-
2044
- }
2045
-
2046
- function get_files_array_from_iwp_part($backup_file)
2047
- {
2048
- $backup_files_array = array();
2049
- if(strpos($backup_file, '_iwp_part') !== false)
2050
- {
2051
- $orgName = substr($backup_file, 0, strpos($backup_file, '_iwp_part_'));
2052
- $totalParts = substr($backup_file, strpos($backup_file, '_iwp_part_')+10);
2053
- $totalParts = substr($totalParts, 0, strlen($totalParts)-4);
2054
- for($i=0; $i<=$totalParts; $i++)
2055
- {
2056
- if($i == 0)
2057
- {
2058
- $backup_files_array[] = $orgName.'.zip';
2059
- }
2060
- else
2061
- {
2062
- $backup_files_array[] = $orgName.'_iwp_part_'.$i.'.zip';
2063
- }
2064
- }
2065
- return $backup_files_array;
2066
- }
2067
- else
2068
- {
2069
- $backup_files_array[] = $backup_file;
2070
- return $backup_file;
2071
- }
2072
- }
2073
-
2074
- function postBackupVerification(&$obj, $backup_file)
2075
- {
2076
- $file_size = iwp_mmb_get_file_size($backup_file);
2077
- if($file_size > 0)
2078
- {
2079
- $list = $obj->listContent();
2080
- if ($list == 0)
2081
- {
2082
- return false;
2083
- }
2084
- else
2085
- {
2086
- return true;
2087
- }
2088
- }
2089
- else
2090
- {
2091
- return false;
2092
- }
2093
- }
2094
-
2095
-
2096
-
2097
- function getHashValuesArray($p_filedescr_list)
2098
- {
2099
- $hashValues = array();
2100
- if(is_array($p_filedescr_list))
2101
- {
2102
- foreach($p_filedescr_list as $key => $value)
2103
- {
2104
- if($value['fileHash'])
2105
- {
2106
- if($value['fileHash'] !== '')
2107
- {
2108
- $hashValues[$value['stored_filename']] = $value['fileHash'];
2109
- }
2110
- }
2111
- }
2112
- }
2113
- return $hashValues;
2114
- }
2115
-
2116
- function maybe_serialize_compress($value){
2117
- $value = serialize($value);
2118
- if(!function_exists('gzdeflate') || !function_exists('gzinflate')){
2119
- return $value;
2120
- }
2121
- $value = gzdeflate($value);
2122
- $value = '**ZIP**'.base64_encode($value);
2123
- return $value;
2124
- }
2125
-
2126
- function maybe_unserialize_uncompress($value){
2127
- if(strpos($value, '**ZIP**') !== false){
2128
- $value = gzinflate (base64_decode(str_replace('**ZIP**', '', $value)));
2129
- }
2130
- return unserialize($value);
2131
- }
2132
-
2133
- function getRequiredData($historyID, $field){
2134
- global $wpdb;
2135
- $backupData = $wpdb->get_row("SELECT ".$field." FROM ".$wpdb->base_prefix."iwp_backup_status WHERE historyID = ".$historyID);
2136
- if(($field == 'responseParams')||($field == 'requestParams')||($field == 'taskResults')){
2137
-
2138
- $fieldParams = $this->maybe_unserialize_uncompress($backupData->$field);
2139
-
2140
- }
2141
- else
2142
- {
2143
- $fieldParams = $backupData->$field;
2144
- }
2145
- return $fieldParams;
2146
- }
2147
-
2148
- function get_all_tasks(){
2149
- /*global $wpdb;
2150
-
2151
- $stats = array();
2152
- $table_name = $wpdb->base_prefix . "iwp_backup_status";
2153
-
2154
- $rows = $wpdb->get_col("SELECT taskResults FROM ".$table_name);
2155
- $task_res = array();
2156
- foreach($rows as $key => $value){
2157
- $task_results = unserialize($value);
2158
- if(is_array($task_results['task_results'])){
2159
-
2160
- foreach($task_results['task_results'] as $key => $data){
2161
- $task_res['task_results'][$key] = $data;
2162
- }
2163
- }
2164
- }*/
2165
-
2166
- global $wpdb;
2167
-
2168
- $stats = array();
2169
- $table_name = $wpdb->base_prefix . "iwp_backup_status";
2170
-
2171
- $rows = $wpdb->get_results("SELECT taskName,taskResults FROM ".$table_name, ARRAY_A);
2172
-
2173
- $task_res = array();
2174
- foreach($rows as $key => $value){
2175
- $task_results = unserialize($value['taskResults']);
2176
-
2177
- if(!empty($task_results['task_results']))
2178
- foreach($task_results['task_results'] as $key => $data){
2179
-
2180
- $task_res[$value['taskName']]['task_results'][$key] = $data;
2181