-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_restore.php
More file actions
80 lines (73 loc) · 2.27 KB
/
Copy pathlaunch_restore.php
File metadata and controls
80 lines (73 loc) · 2.27 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
<?php
error_reporting(0);
function bm_get_wproot()
{
$base = dirname(__FILE__);
$path = false;
if(@file_exists(dirname(dirname($base))."/wp-load.php"))
$path = dirname(dirname($base));
else
if (@file_exists(dirname(dirname(dirname($base)))."/wp-load.php"))
$path = dirname(dirname(dirname($base)));
else
$path = false;
if ($path != false)
$path = str_replace("\\", "/", $path);
return $path;
}
require(bm_get_wproot() . '/wp-load.php');
define('ROOT_DIR',get_option('bm_path'));
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
function emptydir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != ".." && $object != 'backups' && $object != 'database') {
if (filetype($dir."/".$object) == "dir") emptydir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
@rmdir($dir);
}
}
if(file_exists(ROOT_DIR.'/backups/status.ini')) //Restore in progress, don't do anything or break everything
{
bm_mail_notif('Restore failed ! Error: alreadyrestore');
exit(json_encode(array('return'=>'alreadyrestore')));
}
if(isset($_GET['file']) && !empty($_GET['file'])) {
//only folder not affected, we will store progress in it
$f=fopen(ROOT_DIR.'/backups/status.ini','w+');
fwrite($f,0);
$path_zip=ROOT_DIR.'/backups/backup'.$_GET['file'].'.zip';
$zip=new ZipArchive;
$res=$zip->open($path_zip);
if($res) {
$handle = fopen(ROOT_DIR.'/backups/status.ini','w+');
fwrite($handle,10);
fclose($handle);
emptydir(ROOT_DIR);
$handle = fopen(ROOT_DIR.'/backups/status.ini','w+');
fwrite($handle,40);
fclose($handle);
$zip->extractTo(ROOT_DIR.'/');
$zip->close();
$handle = fopen(ROOT_DIR.'/backups/status.ini','w+');
fwrite($handle,100);
fclose($handle);
//unlink(ROOT_DIR.'/backups/status.ini');
bm_mail_notif('Restore terminated !');
echo json_encode(array('return'=>'ok'));
}
else
{
bm_mail_notif('Restore failed ! Error: nozip');
echo json_encode(array('return'=>'nozip'));
}
}
else
{
bm_mail_notif('Restore failed ! Error: nofile');
echo json_encode(array('return'=>'nofile'));
}