-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpvivid-backuprestore.php
More file actions
351 lines (327 loc) · 13.5 KB
/
Copy pathwpvivid-backuprestore.php
File metadata and controls
351 lines (327 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?php
/**
* @link https://wpvivid.com
* @since 0.9.1
* @package wpvivid
*
* @wordpress-plugin
* Plugin Name: WPvivid Backup Plugin
* Description: Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one.
* Version: 0.9.124
* Author: WPvivid Backup & Migration
* Author URI: https://wpvivid.com
* License: GPL-3.0+
* License URI: http://www.gnu.org/copyleft/gpl.html
* Text Domain: wpvivid-backuprestore
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
define( 'WPVIVID_PLUGIN_VERSION', '0.9.124' );
//
define('WPVIVID_RESTORE_INIT','init');
define('WPVIVID_RESTORE_READY','ready');
define('WPVIVID_RESTORE_COMPLETED','completed');
define('WPVIVID_RESTORE_RUNNING','running');
define('WPVIVID_RESTORE_ERROR','error');
define('WPVIVID_RESTORE_WAIT','wait');
define('WPVIVID_RESTORE_TIMEOUT',180);
define('WPVIVID_PLUGIN_SLUG','WPvivid');
define('WPVIVID_PLUGIN_NAME',plugin_basename(__FILE__));
define('WPVIVID_PLUGIN_URL',plugins_url('',__FILE__));
define('WPVIVID_PLUGIN_DIR',dirname(__FILE__));
define('WPVIVID_PLUGIN_DIR_URL',plugin_dir_url(__FILE__).'admin/');
define('WPVIVID_PLUGIN_IMAGES_URL',WPVIVID_PLUGIN_URL.'/admin/partials/images/');
//We set a long enough default execution time (10 min) to ensure that the backup process can be completed.
define('WPVIVID_MAX_EXECUTION_TIME',300);
define('WPVIVID_RESTORE_MAX_EXECUTION_TIME', 300);
define('WPVIVID_MEMORY_LIMIT','512M');
define('WPVIVID_RESTORE_MEMORY_LIMIT','512M');
define('WPVIVID_MIGRATE_SIZE', '2048');
//If the server uses fastcgi then default execution time should be set to 2 min for more efficient.
define('WPVIVID_MAX_EXECUTION_TIME_FCGI',180);
//Default number of reserved backups
define('WPVIVID_MAX_BACKUP_COUNT',7);
define('WPVIVID_DEFAULT_BACKUP_COUNT',3);
define('WPVIVID_DEFAULT_COMPRESS_TYPE','zip');
//Max zip file size.
define('WPVIVID_DEFAULT_MAX_FILE_SIZE',200);
//Instruct PclZip to use all the time temporary files to create the zip archive or not.The default value is 1.
define('WPVIVID_DEFAULT_USE_TEMP',1);
//Instruct PclZip to use temporary files for files with size greater than.The default value is 16M.
define('WPVIVID_DEFAULT_USE_TEMP_SIZE',16);
//Exclude the files which is larger than.The default value is 0 means unlimited.
define('WPVIVID_DEFAULT_EXCLUDE_FILE_SIZE',0);
//Add a file in an archive without compressing the file.The default value is 200.
define('WPVIVID_DEFAULT_NO_COMPRESS',true);
//Backup save folder under WP_CONTENT_DIR
define('WPVIVID_DEFAULT_BACKUP_DIR','wpvividbackups');
//Log save folder under WP_CONTENT_DIR
define('WPVIVID_DEFAULT_LOG_DIR','wpvividbackups'.DIRECTORY_SEPARATOR.'wpvivid_log');
//Old files folder under WPVIVID_DEFAULT_BACKUP_DIR
define('WPVIVID_DEFAULT_ROLLBACK_DIR','wpvivid-old-files');
//
define('WPVIVID_DEFAULT_ADMIN_BAR', true);
define('WPVIVID_DEFAULT_TAB_MENU', true);
define('WPVIVID_DEFAULT_DOMAIN_INCLUDE', true);
//
define('WPVIVID_DEFAULT_ESTIMATE_BACKUP', true);
//Specify the folder and database to be backed up
define('WPVIVID_DEFAULT_SUBPACKAGE_PLUGIN_UPLOAD', false);
//define schedule hooks
define('WPVIVID_MAIN_SCHEDULE_EVENT','wpvivid_main_schedule_event');
define('WPVIVID_RESUME_SCHEDULE_EVENT','wpvivid_resume_schedule_event');
define('WPVIVID_CLEAN_BACKING_UP_DATA_EVENT','wpvivid_clean_backing_up_data_event');
define('WPVIVID_TASK_MONITOR_EVENT','wpvivid_task_monitor_event');
define('WPVIVID_CLEAN_BACKUP_RECORD_EVENT','wpvivid_clean_backup_record_event');
//backup resume retry times
define('WPVIVID_RESUME_RETRY_TIMES',6);
define('WPVIVID_RESUME_INTERVAL',60);
define('WPVIVID_REMOTE_CONNECT_RETRY_TIMES','3');
define('WPVIVID_REMOTE_CONNECT_RETRY_INTERVAL','3');
define('WPVIVID_PACK_SIZE',1 << 20);
define('WPVIVID_SUCCESS','success');
define('WPVIVID_FAILED','failed');
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
//when active plugin redirect plugin page.
function wpvivid_plugin_activate()
{
$dir=get_option('wpvivid_local_setting');
if(!isset($dir['path']))
{
$backup_dir=WPVIVID_DEFAULT_BACKUP_DIR;
$backup_log_dir=WPVIVID_DEFAULT_LOG_DIR;
}
else
{
$backup_dir=$dir['path'];
$backup_log_dir=$dir['path'].DIRECTORY_SEPARATOR.'wpvivid_log';
}
if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir))
{
@mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir,0777,true);
@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir.DIRECTORY_SEPARATOR.'index.html', 'x');
$tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir.DIRECTORY_SEPARATOR.'.htaccess', 'x');
if($tempfile)
{
$text="<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\nRewriteRule .* - [F,L]\r\n</IfModule>";
fwrite($tempfile,$text );
fclose($tempfile);
}
}
if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir))
{
@mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir,0777,true);
@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'index.html', 'x');
$tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'.htaccess', 'x');
if($tempfile)
{
$text="<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\nRewriteRule .* - [F,L]\r\n</IfModule>";
fwrite($tempfile,$text );
fclose($tempfile);
}
}
if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'error'))
{
@mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'error',0777,true);
@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.'index.html', 'x');
$tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_log_dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.'.htaccess', 'x');
if($tempfile)
{
$text="<IfModule mod_rewrite.c>\r\nRewriteEngine On\r\nRewriteRule .* - [F,L]\r\n</IfModule>";
fwrite($tempfile,$text );
fclose($tempfile);
}
}
//A flag to determine whether plugin had been initialized
$init=get_option('wpvivid_init', 'not init');
if($init=='not init')
{
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-setting.php';
//Initialization settings
WPvivid_Setting::init_option();
update_option('wpvivid_init','init','no');
}
$wpvivid_remote_init=get_option('wpvivid_remote_init', 'not init');
if($wpvivid_remote_init=='not init')
{
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-setting.php';
wpvivid_init_remote_option();
update_option('wpvivid_remote_init','init','no');
}
add_option('wpvivid_do_activation_redirect', true);
}
function wpvivid_init_plugin_redirect()
{
if (get_option('wpvivid_do_activation_redirect', false))
{
delete_option('wpvivid_do_activation_redirect');
$active_plugins = get_option('active_plugins');
if(!function_exists('get_plugins'))
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
$plugins=get_plugins();
$pro_wpvivid_slug='wpvivid-backup-pro/wpvivid-backup-pro.php';
$b_redirect_pro=false;
if(!empty($plugins))
{
if(isset($plugins[$pro_wpvivid_slug]))
{
if(in_array($pro_wpvivid_slug, $active_plugins))
{
$b_redirect_pro=true;
}
}
}
if($b_redirect_pro)
{
$url=apply_filters('wpvivid_backup_activate_redirect_url','admin.php?page=wpvivid-dashboard');
if (is_multisite())
{
wp_redirect(network_admin_url().$url);
}
else
{
wp_redirect(admin_url().$url);
}
}
else
{
$url=apply_filters('wpvivid_backup_activate_redirect_url','admin.php?page=WPvivid');
if (is_multisite())
{
wp_redirect(network_admin_url().$url);
}
else
{
wp_redirect(admin_url().$url);
}
}
}
}
function wpvivid_init_remote_option()
{
$remoteslist=WPvivid_Setting::get_all_remote_options();
foreach ($remoteslist as $key=>$value)
{
if(!array_key_exists('options',$value))
{
continue;
}
$remote = array();
if($value['type'] === 'ftp')
{
$remote['host']=$value['options']['host'];
$remote['username']=$value['options']['username'];
$remote['password']=$value['options']['password'];
$remote['path']=$value['options']['path'];
$remote['name']=$value['options']['name'];
$remote['passive']=$value['options']['passive'];
$value['type'] = strtolower($value['type']);
$remote['type']=$value['type'];
$remoteslist[$key]=$remote;
}
elseif ($value['type'] === 'sftp')
{
$remote['host']=$value['options']['host'];
$remote['username']=$value['options']['username'];
$remote['password']=$value['options']['password'];
$remote['path']=$value['options']['path'];
$remote['name']=$value['options']['name'];
$remote['port']=$value['options']['port'];
$value['type'] = strtolower($value['type']);
$remote['type']=$value['type'];
$remoteslist[$key]=$remote;
}
elseif ($value['type'] === 'amazonS3')
{
$remote['classMode']='0';
$remote['sse']='0';
$remote['name']=$value['options']['name'];
$remote['access']=$value['options']['access'];
$remote['secret']=$value['options']['secret'];
$remote['s3Path']=$value['options']['s3Path'];
$value['type'] = strtolower($value['type']);
$remote['type']=$value['type'];
$remoteslist[$key]=$remote;
}
}
WPvivid_Setting::update_option('wpvivid_upload_setting',$remoteslist);
include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-backuplist.php';
$backuplist=WPvivid_Backuplist::get_backuplist();
foreach ($backuplist as $key=>$value)
{
if(is_array($value['remote']))
{
foreach ($value['remote'] as $remote_key=>$storage_type)
{
if(!array_key_exists('options',$storage_type))
{
continue;
}
$remote = array();
if($storage_type['type'] === 'ftp')
{
$remote['host']=$storage_type['options']['host'];
$remote['username']=$storage_type['options']['username'];
$remote['password']=$storage_type['options']['password'];
$remote['path']=$storage_type['options']['path'];
$remote['name']=$storage_type['options']['name'];
$remote['passive']=$storage_type['options']['passive'];
$storage_type['type'] = strtolower($storage_type['type']);
$remote['type']=$storage_type['type'];
}
elseif ($storage_type['type'] === 'sftp')
{
$remote['host']=$storage_type['options']['host'];
$remote['username']=$storage_type['options']['username'];
$remote['password']=$storage_type['options']['password'];
$remote['path']=$storage_type['options']['path'];
$remote['name']=$storage_type['options']['name'];
$remote['port']=$storage_type['options']['port'];
$storage_type['type'] = strtolower($storage_type['type']);
$remote['type']=$storage_type['type'];
}
elseif ($storage_type['type'] === 'amazonS3')
{
$remote['classMode']='0';
$remote['sse']='0';
$remote['name']=$storage_type['options']['name'];
$remote['access']=$storage_type['options']['access'];
$remote['secret']=$storage_type['options']['secret'];
$remote['s3Path']=$storage_type['options']['s3Path'];
$storage_type['type'] = strtolower($storage_type['type']);
$remote['type']=$storage_type['type'];
}
$backuplist[$key]['remote'][$remote_key]=$remote;
}
}
}
WPvivid_Setting::update_option('wpvivid_backup_list',$backuplist);
}
register_activation_hook(__FILE__, 'wpvivid_plugin_activate');
add_action('admin_init', 'wpvivid_init_plugin_redirect');
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 0.9.1
*/
if(isset($wpvivid_plugin)&&is_a($wpvivid_plugin,'WPvivid'))
{
return ;
}
require plugin_dir_path( __FILE__ ) . 'includes/class-wpvivid.php';
function run_wpvivid()
{
$wpvivid_plugin = new WPvivid();
$GLOBALS['wpvivid_plugin'] = $wpvivid_plugin;
}
run_wpvivid();