PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 2.0.3
JetBackup – Backup, Restore & Migrate v2.0.3
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / public / restore_wordpress.php
backup / public Last commit date
ajax 3 years ago config 3 years ago cron 3 years ago css 3 years ago fonts 3 years ago img 3 years ago include 3 years ago js 3 years ago templates 3 years ago backups.php 3 years ago boot.php 3 years ago cloud.php 3 years ago dashboardWidget.php 3 years ago pagesContent.php 3 years ago proFeatures.php 3 years ago restore_wordpress.php 3 years ago schedule.php 3 years ago settings.php 3 years ago support.php 3 years ago systemInfo.php 3 years ago videoTutorials.php 3 years ago
restore_wordpress.php
478 lines
1
2 <?php
3 #SG_DYNAMIC_DEFINES#
4
5 $action = isset($_REQUEST['action']) ? filter_var($_REQUEST['action'], FILTER_SANITIZE_STRING) : null;
6 $key = isset($_REQUEST['k']) ? filter_var($_REQUEST['k'], FILTER_SANITIZE_STRING) : null;
7 //validate key
8 if ($key != BG_RESTORE_KEY) die('Invalid key');
9
10 define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
11 define('SG_APP_ROOT_DIRECTORY', dirname(WP_CONTENT_DIR) . "/");
12 define('SG_ENV_WORDPRESS', 'Wordpress');
13 define('SG_ENV_ADAPTER', SG_ENV_WORDPRESS);
14 define('SG_DB_ADAPTER', SG_ENV_ADAPTER);
15 define('WP_DEBUG', false);
16 define('WP_DEBUG_DISPLAY', false);
17 define( 'WPINC', 'wp-includes' );
18
19 if (!defined('BG_EXTERNAL_RESTORE_RUNNING')) define('BG_EXTERNAL_RESTORE_RUNNING', true);
20
21 ini_set('display_errors', 0);
22 ini_set('display_startup_errors', 0);
23
24 //check if JetBackup plugin exists
25 $pluginPath = WP_PLUGIN_DIR . '/' . SG_PLUGIN_NAME . '/com/config/';
26 if (!file_exists($pluginPath . 'config.php')) die('Plugin not found');
27
28
29 function maintenanceMode($active = false) {
30
31 if ($active) {
32 file_put_contents(ABSPATH . '.maintenance', '<?php $upgrading = ' . time() . '; ?>');
33 } else {
34 unlink(ABSPATH . '.maintenance');
35 }
36
37 }
38
39
40 //require everything we need for only wpdb to run
41 include_once ABSPATH . 'wp-includes/version.php';
42 include_once ABSPATH . 'wp-includes/formatting.php';
43 include_once ABSPATH . 'wp-includes/plugin.php';
44 include_once ABSPATH . 'wp-includes/class-wp-error.php';
45 include_once ABSPATH . 'wp-includes/user.php';
46 include_once ABSPATH . 'wp-includes/class-wp-user.php';
47 include_once ABSPATH . 'wp-includes/link-template.php';
48 include_once ABSPATH . 'wp-includes/option.php';
49 include_once ABSPATH . 'wp-includes/load.php';
50 include_once ABSPATH . 'wp-includes/cache.php';
51 include_once ABSPATH . 'wp-includes/pluggable.php';
52 include_once ABSPATH . 'wp-includes/meta.php';
53 include_once ABSPATH . 'wp-includes/compat.php';
54
55
56 //starting from WordPress 4.7.1 is_wp_error() has been moved to another location
57 //wpdb needs it, so we create it here
58 if (!function_exists('is_wp_error')) {
59
60 function is_wp_error($thing) {
61 return ($thing instanceof WP_Error);
62 }
63
64 }
65
66 if (!function_exists('absint')) {
67 // Issue #39, in some environments this returns fatal error for some reason
68
69 function absint( $maybeint ) {
70 return abs( (int) $maybeint );
71 }
72
73 }
74
75 function readLines($fp, $num) {
76
77 $line_count = 0; $line = ''; $pos = -1; $lines = array(); $c = '';
78
79 while($line_count < $num) {
80 $line = $c . $line;
81 fseek($fp, $pos--, SEEK_END);
82 $c = fgetc($fp);
83 if($c == "\n") { $line_count++; $lines[] = $line; $line = ''; $c = ''; }
84 }
85 return $lines;
86 }
87
88 function array_in_string($str, array $arr) {
89 foreach($arr as $arr_value) { //start looping the array
90 if (stripos($str,$arr_value) !== false) return true; //if $arr_value is found in $str return true
91 }
92 return false; //else return false
93 }
94
95 include_once ABSPATH . 'wp-includes/wp-db.php';
96 global $wpdb;
97 $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
98 $wpdb->db_connect();
99
100 maintenanceMode(true);
101
102 //the mysql version is needed for the charset handler
103 if (!defined('SG_MYSQL_VERSION')) define('SG_MYSQL_VERSION', $wpdb->db_version());
104
105 $dbCharset = 'utf8';
106 if (@constant("DB_CHARSET")) $dbCharset = DB_CHARSET;
107 if (!defined('SG_DB_CHARSET')) define('SG_DB_CHARSET', $dbCharset);
108
109 //require JetBackup plugin
110 $sgPluginFile = '';
111 if (file_exists($pluginPath . 'config.wordpress.pro.php')) {
112 $sgPluginFile = 'backup-guard-pro';
113 include_once $pluginPath . 'config.wordpress.pro.php';
114 } else if (file_exists($pluginPath . 'config.wordpress.free.php')) {
115 $sgPluginFile = 'backup';
116 include_once $pluginPath . 'config.wordpress.free.php';
117 }
118 require_once $pluginPath . 'config.php';
119 require_once SG_CORE_PATH . 'SGBoot.php';
120 include_once SG_BACKUP_PATH . 'SGBackup.php';
121
122 switch ($action) {
123
124 case 'awake':
125
126 include_once SG_BACKUP_PATH . 'SGBackup.php';
127 $currentAction = SGBackup::getAction(SG_ACTION_ID);
128
129 $backup_dir = SG_BACKUP_DIRECTORY;
130 if (!is_dir($backup_dir)) $backup_dir = SG_BACKUP_OLD_DIRECTORY;
131
132 $restore_log = $backup_dir.$currentAction['name']."/".$currentAction['name']."_restore.log";
133
134 if (file_exists($restore_log)) {
135
136 $fp = @fopen($restore_log, "r");
137 $lines = readLines($fp, 2);
138 if ($lines) array_shift($lines);
139 $line = isset($lines[0]) ? $lines[0] : null;
140
141 if (strpos($line, '###_Extract_OffSet_###') === false) {
142 die('Busy');
143 }
144
145 fclose($fp);
146
147 }
148
149
150 $currentAction = SGBackup::getAction(SG_ACTION_ID);
151 if ($currentAction) {
152 $sgBackup = new SGBackup();
153 $sgBackup->restore($currentAction['name'], SG_ACTION_ID);
154 }
155
156 break;
157
158 case 'quit':
159
160 maintenanceMode(false);
161 // Todo - clear db & local state file
162
163 break;
164
165 case 'finalize':
166
167 maintenanceMode(false);
168
169 $row = $wpdb->get_row(
170 $wpdb->prepare('SELECT option_value FROM '.SG_ENV_DB_PREFIX.'options WHERE option_name = %s', 'active_plugins')
171 );
172
173 $activePLugins = unserialize($row->option_value);
174 $activePLugins[] = SG_PLUGIN_NAME . '/' . $sgPluginFile . '.php';
175 $activePLuginsRow = serialize($activePLugins);
176
177 $wpdb->query(
178 $wpdb->prepare(
179 "UPDATE `" . SG_ENV_DB_PREFIX . "options` SET option_value = %s WHERE option_name = %s",
180 $activePLuginsRow,
181 'active_plugins'
182 )
183 );
184
185 //include_once SG_BACKUP_PATH . 'SGBackup.php';
186 SGBackup::changeActionStatus(SG_ACTION_ID, SG_ACTION_STATUS_FINISHED);
187
188 $runningActions = SGBackup::getRunningActions();
189 if ($runningActions) SGBackup::cleanRunningActions($runningActions);
190
191 $currentUser = SGConfig::get('SG_CURRENT_USER');
192 $user = unserialize($currentUser);
193
194 $prefixFromBackup = SGConfig::get('SG_OLD_DB_PREFIX');
195
196
197 if ($prefixFromBackup != SG_ENV_DB_PREFIX) {
198
199 $WPconfig = ABSPATH.'wp-config.php';
200 $WPconfigBackup = ABSPATH.'.jetbackup_'.rand().'_wp-config.php';
201
202 if (file_exists($WPconfig)) {
203
204 @chmod($WPconfig, 0777);
205
206 $WPcontent=file_get_contents($WPconfig);
207 $split = explode (SG_ENV_DB_PREFIX, $WPcontent );
208 $NewWPcontent = implode( $prefixFromBackup, $split );
209 @copy($WPconfig, $WPconfigBackup);
210 @file_put_contents($WPconfig, $NewWPcontent);
211 @chmod($WPconfig, 0400);
212 @chmod($WPconfigBackup, 0400);
213
214 }
215
216 $dbuser = $wpdb->get_row($wpdb->prepare('SELECT * FROM '.$prefixFromBackup.'users WHERE `user_email` = %s', $user['email']));
217
218 // User from SG_CURRENT_USER is the same as user from DB
219 if (isset($dbuser->ID) && is_numeric($dbuser->ID)) die(1); // same user
220
221 // Not sure user, we need to inject current active admin so user can login after the switch
222 $name = $user['login'];
223 $email = $user['email'];
224 $pass = $user['pass'];
225 $now = date("Y-m-d H:i:s");
226
227 $sql = "INSERT INTO `" . $prefixFromBackup . "users`
228 (`user_login`,`user_pass`,`user_nicename`,`user_email`,`user_url`,`user_registered`,`user_activation_key`,`user_status`,`display_name`)
229 values ('".$name."', '".$pass."', '".$name."', '".$email."', 'url', '".$now."', 'key', 0, '".$name."')";
230
231 $res = $wpdb->query($sql);
232 $lastid = $wpdb->insert_id;
233
234 if ($lastid && is_numeric($lastid)) {
235
236 $user_id = $lastid;
237 $meta_key = $prefixFromBackup.'capabilities';
238 $meta_value = 'a:1:{s:13:"administrator";s:1:"1";}';
239
240 $sql = "INSERT INTO `" . $prefixFromBackup . "usermeta`
241 (`user_id`,`meta_key`,`meta_value`)
242 values ('".$user_id."', '".$meta_key."', '".$meta_value."')";
243 $res = $wpdb->query($sql);
244
245 }
246
247 die(1);
248
249 } // if ($prefixFromBackup != SG_ENV_DB_PREFIX)
250
251
252 die(1);
253
254 case 'getAction':
255
256 include_once SG_BACKUP_PATH . 'SGBackup.php';
257 $currentAction = SGBackup::getAction(SG_ACTION_ID);
258
259 $backup_dir = SG_BACKUP_DIRECTORY;
260 if (!is_dir($backup_dir)) $backup_dir = SG_BACKUP_OLD_DIRECTORY;
261
262 $restore_log = $backup_dir.$currentAction['name']."/".$currentAction['name']."_restore.log";
263
264 if (file_exists($restore_log)) {
265
266 $fp = @fopen($restore_log, "r");
267 $lines = readLines($fp, 2);
268 if ($lines) array_shift($lines);
269 $line = isset($lines[0]) ? $lines[0] : null;
270 $currentAction['lastAction'] = $line;
271 fclose($fp);
272
273 }
274
275
276 $status = isset($currentAction['status']) ? $currentAction['status'] : null;
277
278 switch ($status) {
279
280 case SG_ACTION_STATUS_CREATED:
281 case SG_ACTION_STATUS_IN_PROGRESS_FILES:
282 case SG_ACTION_STATUS_IN_PROGRESS_DB:
283
284 die (json_encode($currentAction));
285 break;
286
287 case SG_ACTION_STATUS_FINISHED:
288 case SG_ACTION_STATUS_FINISHED_WARNINGS:
289
290 die ('1');
291
292 default: die('0');
293
294 }
295
296 break;
297
298 default: break;
299
300
301 }
302
303 ?>
304 <!DOCTYPE html>
305 <html>
306 <head>
307 <link rel="stylesheet" type="text/css" href="<?php echo SG_PUBLIC_URL; ?>css/spinner.css">
308 <link rel="stylesheet" type="text/css" href="<?php echo SG_PUBLIC_URL; ?>css/bgstyle.less.css">
309 <link rel="stylesheet" type="text/css" href="<?php echo SG_PUBLIC_URL; ?>css/main.css">
310 <style>
311 body {
312 background-color: #fff;
313 padding: 0;
314 margin: 0;
315 }
316
317 .sg-box-center {
318 width: 400px;
319 position: absolute;
320 left: 50%;
321 margin-left: -200px;
322 margin-top: 100px;
323 border: 1px solid #5c5c5c;
324 }
325
326 .sg-logo {
327 text-align: center;
328 padding: 20px 0;
329 background-color: #0021C8;
330 }
331
332 .sg-wrapper-less .sg-progress {
333 height: 4px;
334 margin: 1px 0 0;
335 }
336
337 .sg-progress-box p {
338 margin-top: 10px;
339 text-align: center;
340 }
341
342 .restore-warning {
343 color: #C20000;
344 }
345
346 .restore-progress-p {
347 font-size: 21px;
348 font-weight: bold;
349 }
350 </style>
351 </head>
352 <body>
353 <div class="sg-wrapper-less">
354 <div class="sg-wrapper">
355 <div class="sg-box-center">
356 <div class="sg-logo">
357 <img width="172px" src="<?php echo SG_PUBLIC_URL; ?>img/jetbackup.svg">
358 </div>
359 <div class="sg-progress-box">
360 <p class="restore-progress-p">Restoring <span id="progressItem">files</span>: <span
361 id="progressTxt">0%</span></p>
362 <p class="restore-progress-file" style="font-style: italic; font-size: 12px;"><span id="progressFile">...</span></p>
363 <p class="restore-warning"><small>NOTE: Please don't close your browser until finished.</small></p>
364 <div class="sg-progress progress">
365 <div id="progressBar" class="progress-bar" style="width: 0%;"></div>
366 </div>
367 </div>
368 </div>
369 </div>
370 </div>
371 <script>
372
373
374 function bgRunAwake(url) {
375
376 var req;
377
378 if (window.XMLHttpRequest) {
379 req = new XMLHttpRequest();
380 } else if (window.ActiveXObject) {
381 req = new ActiveXObject("Microsoft.XMLHTTP");
382 }
383
384 req.open("GET", url, true);
385 req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
386 req.send();
387
388 }
389
390 function bgRunAjax(url, responseHandler, params) {
391 var req;
392 if (window.XMLHttpRequest) {
393 req = new XMLHttpRequest();
394 } else if (window.ActiveXObject) {
395 req = new ActiveXObject("Microsoft.XMLHTTP");
396 }
397 req.onreadystatechange = function () {
398 if (req.readyState == 4) {
399 if (req.status < 400) {
400 responseHandler(req, params);
401 }
402 }
403 };
404 req.open("POST", url, true);
405 req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
406 req.send(params);
407 }
408
409 function bgUpdateProgress(progress) {
410 var progressInPercents = progress + '%';
411 var progressBar = document.getElementById('progressBar');
412 progressBar.style.width = progressInPercents;
413 var progressTxt = document.getElementById('progressTxt');
414 progressTxt.innerHTML = progressInPercents;
415 }
416
417 var getActionRunning = false;
418
419 function getAction() {
420
421 if (getActionRunning) return;
422 getActionRunning = true;
423
424 bgRunAjax("<?php echo BG_RESTORE_URL; ?>&action=getAction", function (response) {
425 try {
426 var response = eval('(' + response.responseText + ')');
427
428 if (response === 1) {
429
430 clearInterval(getActionTimer);
431 clearInterval(getAwakeTimer);
432
433 bgRunAjax("<?php echo BG_RESTORE_URL; ?>&action=finalize", function (response) {
434
435 bgUpdateProgress(100);
436 location.href = '<?php echo BG_PLUGIN_URL; ?>';
437 }, "");
438
439 return;
440 } else if (response === 0) {
441 clearInterval(getActionTimer);
442 clearInterval(getAwakeTimer);
443
444 bgUpdateProgress(100);
445 location.href = '<?php echo BG_PLUGIN_URL; ?>';
446 return;
447 } else if (typeof response === 'object') {
448 bgUpdateProgress(response.progress);
449 if (response.status ==<?php echo SG_ACTION_STATUS_IN_PROGRESS_FILES; ?>) {
450 progressItem.innerHTML = 'files';
451 } else {
452 progressItem.innerHTML = 'database';
453 }
454 progressFile.innerHTML = response.lastAction;
455 }
456 } catch (e) {
457 }
458
459 getActionRunning = false;
460
461 }, "");
462 }
463
464 //get action (for progress)
465 var getActionTimer = setInterval(function () {
466 getAction();
467 }, 5000);
468
469 //get action (for progress)
470 var getAwakeTimer = setInterval(function () {
471 bgRunAwake("<?php echo BG_RESTORE_URL; ?>&action=awake");
472 }, 20000);
473
474 getAction();
475
476 </script>
477 </body>
478 </html>