Backup & Restore Dropbox - Version 1.4.6

Version Description

Please, keep your Dropbox Backup and Restore plugin up-to-date.

Download this release

Release Info

Developer backup-dropbox
Plugin Icon 128x128 Backup & Restore Dropbox
Version 1.4.6
Comparing to
See all releases

Code changes from version 1.4.5 to 1.4.6

dropbox-backup.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Dropbox Backup & Restore
4
  Description: Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + Database) of your Web Page
5
- Version: 1.4.5
6
  Text Domain: dropbox-backup
7
  Domain Path: /languages/
8
  */
2
  /*
3
  Plugin Name: Dropbox Backup & Restore
4
  Description: Dropbox Backup & Restore Plugin to create Dropbox Full Backup (Files + Database) of your Web Page
5
+ Version: 1.4.4
6
  Text Domain: dropbox-backup
7
  Domain Path: /languages/
8
  */
libs/wpadm.server.main.class.php CHANGED
@@ -589,7 +589,7 @@
589
  $count_zip = 0;
590
  $backups[$i]['files'] = "[";
591
  while($d_b = readdir($dir_b)) {
592
- if ($d_b != '.' && $d_b != '..' && file_exists($dir_backup . "/$d/$d_b") && substr($d_b, -3) != "php") {
593
  $backups[$i]['files'] .= "$d_b,";
594
  $size += filesize($dir_backup . "/$d/$d_b");
595
  $count_zip = $count_zip + 1;
@@ -800,7 +800,7 @@
800
  <?php $ex = $c['ex']; ?>
801
  <td><?php echo ( $ex ) === false ? 'All present' : '<span style="color:#ffba00;font-weight:bold;">' . implode(", ", $ex) . '</span>'; ?></td>
802
  <td><?php echo ( $ex ) === false ? 'Found' : '<span style="color:#ffba00;font-weight:bold;">Not Found</span>'; ?></td>
803
- <td><?php echo ( $ex ) === false ? '<span style="color:green;font-weight:bold;">Ok</span>' : '<span style="color:#fb8004;font-weight:bold;">Functionality is not guaranteed.</span>'; ?></td>
804
  </tr>
805
  <tr>
806
  <th scope="row">Disabled Functions</th>
589
  $count_zip = 0;
590
  $backups[$i]['files'] = "[";
591
  while($d_b = readdir($dir_b)) {
592
+ if ($d_b != '.' && $d_b != '..' && file_exists($dir_backup . "/$d/$d_b") && ( substr($d_b, -3) == "zip" || substr($d_b, -3) == 'md5' ) ) {
593
  $backups[$i]['files'] .= "$d_b,";
594
  $size += filesize($dir_backup . "/$d/$d_b");
595
  $count_zip = $count_zip + 1;
800
  <?php $ex = $c['ex']; ?>
801
  <td><?php echo ( $ex ) === false ? 'All present' : '<span style="color:#ffba00;font-weight:bold;">' . implode(", ", $ex) . '</span>'; ?></td>
802
  <td><?php echo ( $ex ) === false ? 'Found' : '<span style="color:#ffba00;font-weight:bold;">Not Found</span>'; ?></td>
803
+ <td><?php echo ( $ex ) === false ? '<span style="color:green;font-weight:bold;">Ok</span>' : '<span style="color:#fb8004;font-weight:bold;">Functionality are not guaranteed.</span>'; ?></td>
804
  </tr>
805
  <tr>
806
  <th scope="row">Disabled Functions</th>
main/wpadm-class-wp.php CHANGED
@@ -610,10 +610,12 @@
610
  $k = $data['data'][$i]['count'];
611
  $data['data'][$i]['files'] = '[';
612
  for($j = 0; $j < $k; $j++) {
613
- if (strpos($backup['items'][$j]['name'] , '.md5') !== false ) {
614
- $not_all_upload = true;
 
 
 
615
  }
616
- $data['data'][$i]['files'] .= $backup['items'][$j]['name'] . ',';
617
  }
618
  $data['data'][$i]['not_all_upload'] = $not_all_upload;
619
  }
@@ -672,7 +674,20 @@
672
  $name_running_backup = str_replace("https://", '', $name_running_backup);
673
  $name_running_backup = preg_replace("|\W|", "_", $name_running_backup);
674
  $name_running_backup .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $running_backup['params']['time']);
675
-
 
 
 
 
 
 
 
 
 
 
 
 
 
676
  }
677
 
678
  $show = !get_option('wpadm_pub_key') && is_super_admin();
610
  $k = $data['data'][$i]['count'];
611
  $data['data'][$i]['files'] = '[';
612
  for($j = 0; $j < $k; $j++) {
613
+ if ( strpos($backup['items'][$j]['name'] , '.md5') !== false || strpos($backup['items'][$j]['name'] , '.zip') !== true ) {
614
+ if ( strpos($backup['items'][$j]['name'] , '.md5') !== false ) {
615
+ $not_all_upload = true;
616
+ }
617
+ $data['data'][$i]['files'] .= $backup['items'][$j]['name'] . ',';
618
  }
 
619
  }
620
  $data['data'][$i]['not_all_upload'] = $not_all_upload;
621
  }
674
  $name_running_backup = str_replace("https://", '', $name_running_backup);
675
  $name_running_backup = preg_replace("|\W|", "_", $name_running_backup);
676
  $name_running_backup .= '-' . wpadm_class::$type . '-' . date("Y_m_d_H_i", $running_backup['params']['time']);
677
+ }
678
+
679
+ if ( !file_exists( DROPBOX_BACKUP_DIR_BACKUP . '/local-key') ) {
680
+ WPAdm_Core::mkdir(DROPBOX_BACKUP_DIR_BACKUP);
681
+ $key = md5(time() . 'wpadm-key');
682
+ file_put_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key', wpadm_pack(array('key' => $key, 'time-update' => time() + 3600) ));
683
+ } else {
684
+ $key_values = wpadm_unpack( file_get_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key') );
685
+ if (isset($key_values['time-update']) && $key_values['time-update'] <= time()) {
686
+ $key = md5(time() . 'wpadm-key');
687
+ file_put_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key', wpadm_pack(array('key' => $key, 'time-update' => time() + 3600) ));
688
+ } else {
689
+ $key = $key_values['key'];
690
+ }
691
  }
692
 
693
  $show = !get_option('wpadm_pub_key') && is_super_admin();
modules/class-wpadm-core.php CHANGED
@@ -229,6 +229,9 @@ if (!class_exists('WPAdm_Core')) {
229
  }
230
  }
231
  }
 
 
 
232
  return self::$error;
233
  }
234
 
@@ -279,16 +282,16 @@ if (!class_exists('WPAdm_Core')) {
279
  */
280
  static function rmdir($dir) {
281
  if (is_dir($dir)) {
282
- $files = glob($dir. '/*');
283
- foreach($files as $f) {
284
  if ($f == '..' or $f == '.') {
285
  continue;
286
  }
287
- if (is_dir($f)) {
288
- self::rmdir($f);
289
  }
290
- if (file_exists($f)) {
291
- @unlink($f);
292
  }
293
  }
294
  @rmdir($dir);
229
  }
230
  }
231
  }
232
+ if (!file_exists($dir . '/.htaccess')) {
233
+ @file_put_contents($dir . '/.htaccess', 'DENY FROM ALL');
234
+ }
235
  return self::$error;
236
  }
237
 
282
  */
283
  static function rmdir($dir) {
284
  if (is_dir($dir)) {
285
+ $dir_open = opendir($dir);
286
+ while($f = readdir($dir_open)) {
287
  if ($f == '..' or $f == '.') {
288
  continue;
289
  }
290
+ if (is_dir($dir . '/' . $f)) {
291
+ self::rmdir($dir . '/' . $f);
292
  }
293
+ if (file_exists($dir . '/' . $f)) {
294
+ @unlink($dir . '/' . $f);
295
  }
296
  }
297
  @rmdir($dir);
modules/class-wpadm-running.php CHANGED
@@ -34,6 +34,15 @@ if (!class_exists('WPAdm_Running')) {
34
  WPAdm_Core::rmdir($path . "/command_dropbox");
35
  WPAdm_Core::rmdir($path . "/errors_sending");
36
  WPAdm_Core::rmdir($path . "/tabledb");
 
 
 
 
 
 
 
 
 
37
  if ($method) {
38
  $files = glob($path ."/wpadm_method*.queue");
39
  if (!empty($files)) {
34
  WPAdm_Core::rmdir($path . "/command_dropbox");
35
  WPAdm_Core::rmdir($path . "/errors_sending");
36
  WPAdm_Core::rmdir($path . "/tabledb");
37
+ WPAdm_Core::rmdir($path . "/restore-backup");
38
+ WPAdm_Core::rmdir($path . "/log-restore.log");
39
+ WPAdm_Core::rmdir($path . "/log-restore2");
40
+ WPAdm_Core::rmdir($path . "/md5_info-restore");
41
+ WPAdm_Core::rmdir($path . "/restore-backup");
42
+ WPAdm_Core::rmdir($path . "/files-list-retore");
43
+ WPAdm_Core::rmdir($path . "/extract-files-restore");
44
+ WPAdm_Core::rmdir($path . "/cron-restore.data");
45
+
46
  if ($method) {
47
  $files = glob($path ."/wpadm_method*.queue");
48
  if (!empty($files)) {
modules/index.html ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head lang="en">
4
+ <meta charset="UTF-8">
5
+ <title></title>
6
+ </head>
7
+ <body>
8
+
9
+ </body>
10
+ </html>
modules/restore-class.php ADDED
@@ -0,0 +1,909 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+
5
+ if (!class_exists('dbr_gui')) {
6
+ class dbr_gui {
7
+
8
+ }
9
+ }
10
+
11
+ if (!class_exists('dbr_database')) {
12
+ class dbr_database {
13
+ private static $connect = null;
14
+ private static $db = null;
15
+ private static $db_prefix = '';
16
+ public static $error = '';
17
+
18
+ public static function inc_wp_config()
19
+ {
20
+ if (!defined('DB_NAME') && !defined('DB_USER') && !defined('DB_PASSWORD') && !defined('DB_HOST') && is_null(self::$connect) ) {
21
+
22
+ include ABSPATH . 'wp-config.php';
23
+ if ( !defined('WP_CONTENT_DIR') )
24
+ define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
25
+ self::$connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD) or die(mysqli_error());
26
+ mysqli_set_charset(self::$connect, DB_CHARSET) or die(mysql_error());
27
+ mysqli_select_db(self::$connect, DB_NAME) or die(mysql_error());
28
+ self::$db_prefix = $table_prefix;
29
+ }
30
+ }
31
+ public static function db_insert($table, $vars = array())
32
+ {
33
+ if (count($vars) > 0) {
34
+ $stmt = "";
35
+ foreach ($vars as $col_name => $value) {
36
+ $stmt .= "`$col_name`='" . ($value) . "',";
37
+ }
38
+ if ($stmt != "") $stmt = substr($stmt, 0, -1);
39
+ $table = self::$db_prefix . $table;
40
+ $stmt = "INSERT `" . $table . "` SET " . $stmt . " ";
41
+ return self::query($stmt);
42
+ } else {
43
+ return false;
44
+ }
45
+ }
46
+
47
+ public static function db_delete ($table, $values = array() )
48
+ {
49
+ $res = false;
50
+ if (!empty($values)) {
51
+ $table = self::$db_prefix . $table;
52
+ $str = array();
53
+ foreach ($values as $k => $v) {
54
+ $str[] = "`$k`='" . ($v) . "'";
55
+ }
56
+ if (count($str) == 0) return false;
57
+ $stmt =
58
+ "DELETE FROM `" . $table . "` "
59
+ . "WHERE " . implode(" AND ", $str) ;
60
+ $res = self::query($stmt);
61
+ }
62
+ return $res;
63
+ }
64
+ public static function db_update($table, $updateValues = null, $whereValues = null)
65
+ {
66
+ if ($updateValues !== null) {
67
+ $table = self::$db_prefix . $table;
68
+ $q = "UPDATE `$table` SET ";
69
+ foreach($updateValues as $v=>$k){
70
+ $q .= "`$v`='$k',";
71
+ }
72
+ $q = substr($q, 0, -1);
73
+ $q .= " WHERE 1";
74
+ if ($whereValues !== null) {
75
+ foreach($whereValues as $v => $k){
76
+ $q .= " AND `$v` = '$k'";
77
+ }
78
+ }
79
+ return self::query($q);
80
+ }
81
+ return false;
82
+ }
83
+ public static function db_get($table, $var_key = null, $var_search = null, $limit = -1, $res_type = MYSQL_BOTH, $keys_array = "", $value_array = "" )
84
+ {
85
+ if (!isset($var_key)) $d = "*";
86
+ else {
87
+ $d = "`" . implode("`, `", $var_key) . "`";
88
+ }
89
+ $str = array();
90
+ if (count($var_search))
91
+ foreach ($var_search as $k => $v) {
92
+ if (!is_array($v)) {
93
+ $str[] = "`$k`='" . $v . "'";
94
+ } elseif(isset($v['mark'])) {
95
+ $str[] = "`$k` " . $v['mark'] . $v['data'] . "";
96
+ } elseif(isset($v['in']) && is_array($v['in'])) {
97
+ $str[] = "`$k` IN ('" . implode('\' , \'', $v['in']) . "')";
98
+ }
99
+ }
100
+ $lim = '';
101
+ if (is_array($limit)) {
102
+ $lim = ' LIMIT ' . $limit[0] . ', ' . $limit[1];
103
+ $limit = -1;
104
+ }
105
+ $table = self::$db_prefix . $table;
106
+ $whr = count($str) > 0 ? " WHERE " . implode(" AND ", $str) : '';
107
+ $sql = "SELECT $d FROM `$table` ".$whr . $lim;
108
+ $query = self::query($sql);
109
+ return self::returnArray($query, $limit, $res_type, $keys_array, $value_array);
110
+ }
111
+ public static function query($stmt)
112
+ {
113
+ $res = mysqli_query(self::$connect, $stmt);
114
+ if ( $res === false ) {
115
+ self::$error = mysqli_error(self::$connect);
116
+ }
117
+ if ($res !== false and preg_match("/^INSERT/i", ltrim($stmt))) {
118
+ return self::lastID(self::$connect);
119
+ }
120
+ return $res;
121
+ }
122
+ /**
123
+ * get insert last id
124
+ *
125
+ */
126
+ public static function lastID($lastlink)
127
+ {
128
+ return mysqli_insert_id($lastlink);
129
+ }
130
+ public static function num($res)
131
+ {
132
+ return mysqli_num_rows($res);
133
+
134
+ }
135
+ private static function returnArray($query, $limit = 1, $res_type = MYSQL_BOTH, $key = "", $value = "")
136
+ {
137
+ if ($query && self::num($query) > 0) {
138
+ $res = false;
139
+ if ($limit == 1) {
140
+ $rec = self::fetch($query, $res_type);
141
+ $res = self::value_keys($rec, $key, $value);
142
+ } else {
143
+ if (!empty($key) && !empty($value)) {
144
+ while ($rec = self::fetch($query, $res_type)) {
145
+ $res[$rec[$key]] = $rec[$value];
146
+ }
147
+ } elseif (empty($key) && !empty($value)) {
148
+ while ($rec = self::fetch($query, $res_type)) {
149
+ $res[] = $rec[$value];
150
+ }
151
+ } elseif (empty($value) && !empty($key)) {
152
+ while ($rec = self::fetch($query, $res_type)) {
153
+ $res[$rec[$key]] = $rec;
154
+ }
155
+ } elseif ($limit != -1) {
156
+ $i = 1;
157
+ while ($rec = self::fetch($query, $res_type)) {
158
+ if ($i >= $limit) {
159
+ break;
160
+ }
161
+ $res[] = $rec;
162
+ $i++;
163
+ }
164
+ } else {
165
+ while ($rec = self::fetch($query, $res_type)) {
166
+ $res[] = $rec;
167
+ }
168
+ }
169
+ }
170
+ return $res;
171
+ }
172
+ return false;
173
+ }
174
+ private static function fetch ($res, $res_type = MYSQL_BOTH)
175
+ {
176
+ return mysqli_fetch_array($res, $res_type);
177
+ }
178
+
179
+ public static function value_keys($array_from, $key = "", $value = "")
180
+ {
181
+
182
+ $returned = array();
183
+ if (!empty($key) && !empty($value)) {
184
+ if (isset($array_from[$key]) && isset($array_from[$value])) {
185
+ $returned[$array_from[$key]] = $array_from[$value];
186
+ }
187
+ } elseif(empty($key) && !empty($value)) {
188
+ if (isset($array_from[$value])) {
189
+ $returned = $array_from[$value];
190
+ }
191
+ } elseif(empty($value) && !empty($key)) {
192
+ if (isset($array_from[$key])) {
193
+ $returned[$array_from[$key]] = $array_from;
194
+ }
195
+ } else {
196
+ $returned = $array_from;
197
+ }
198
+
199
+ return $returned;
200
+ }
201
+ }
202
+ }
203
+
204
+ if ( !class_exists('dbr_api') ) {
205
+ class dbr_api {
206
+ public static function post($url, $post, $options = array() )
207
+ {
208
+ $info = array();
209
+ $result = '';
210
+ if (function_exists("curl_init") && function_exists("curl_setopt") && function_exists("curl_exec") && function_exists("curl_close")) {
211
+ $curl = curl_init($url);
212
+ $post = http_build_query($post, '', '&');
213
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
214
+ curl_setopt($curl, CURLOPT_POST, true);
215
+ if (!empty($options)) {
216
+ if(isset($options['timelimit'])) {
217
+ curl_setopt($curl, CURLOPT_TIMEOUT, $options['timelimit']);
218
+ }
219
+ }
220
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
221
+ $result = curl_exec($curl);
222
+ $info = curl_getinfo($curl);
223
+ curl_close($curl);
224
+ } elseif (function_exists("fsockopen")) {
225
+ $postdata = http_build_query($post, '', '&');
226
+ $length = strlen($postdata);
227
+ $url = trim( substr(WPADM_URL_BASE, 7), '/' );
228
+ $req = '/api/';
229
+ $out = "POST " . $req . " HTTP/1.1\r\n";
230
+ $out.= "HOST: " . $url . "\r\n";
231
+ $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
232
+ $out.= "Content-Length: ".$length."\r\n";
233
+ $out.= "Connection:Close\r\n\r\n";
234
+ $out.= $postdata."\r\n\r\n";
235
+ try {
236
+ $errno='';
237
+ $errstr = '';
238
+ $socket = @fsockopen($url, 80, $errno, $errstr, 30);
239
+ if($socket) {
240
+ if(!fwrite($socket, $out)) {
241
+ throw new Exception("unable to write fsockopen");
242
+ } else {
243
+ while ($in = @fgets ($socket, 1024)) {
244
+ $result .= $in;
245
+ }
246
+ }
247
+ $result = explode("\r\n\r\n", $result);
248
+ $result = $result[1];
249
+
250
+ }
251
+ } catch(exception $e) {
252
+ array('res' => $result, 'info' => $info );
253
+ }
254
+ }
255
+ return array('res' => $result, 'info' => $info );
256
+ }
257
+
258
+ }
259
+ }
260
+
261
+ if ( !class_exists('dbr_helper') ) {
262
+ class dbr_helper {
263
+
264
+ private static $cron_is_work = 60;
265
+
266
+ public static function setError($txt)
267
+ {
268
+ throw new Exception($txt);
269
+ }
270
+
271
+ public static function is_work($time = '', $type = '')
272
+ {
273
+ $res = true;
274
+ $file = DBP_PATH_TMP . '/cron-restore.data';
275
+ if (file_exists($file)) {
276
+ $cron = dbr_helper::unpack( file_get_contents($file) );
277
+ if (empty($time)) {
278
+ if (isset($cron['finish'])) {
279
+ $res = true;
280
+ } else {
281
+ if (isset($cron['start']) && ( $cron['start'] + self::$cron_is_work ) < time() ) {
282
+ $res = false;
283
+ }
284
+ }
285
+ } else {
286
+ $cron[$type] = $time;
287
+ file_put_contents($file, dbr_helper::pack($cron) );
288
+ }
289
+ } else {
290
+ if (!empty($time)) {
291
+ $cron[$type] = $time;
292
+ file_put_contents($file, dbr_helper::pack($cron) );
293
+ }
294
+ $res = false;
295
+ }
296
+ return $res;
297
+ }
298
+
299
+
300
+ public static function getProjectName()
301
+ {
302
+ $name_running_backup = '';
303
+ $site_url = dbr_database::db_get('options', array('option_value'), array('option_name' => 'siteurl'), 1);
304
+ if (isset($site_url['option_value'])) {
305
+ $name_running_backup = str_replace("http://", '', $site_url['option_value']);
306
+ $name_running_backup = str_replace("https://", '', $name_running_backup);
307
+ $name_running_backup = preg_replace("|\W|", "_", $name_running_backup);
308
+ }
309
+ return $name_running_backup;
310
+ }
311
+ public static function clearTMP()
312
+ {
313
+ if (is_dir(DBP_PATH_TMP)) {
314
+ $files = opendir(DBP_PATH_TMP);
315
+ while($file = readdir($files)) {
316
+ if (file_exists(DBP_PATH_TMP . '/' . $file)) {
317
+ @unlink(DBP_PATH_TMP . '/' . $file);
318
+ }
319
+ }
320
+ // @rmdir(DBP_PATH_TMP);
321
+ }
322
+ }
323
+
324
+ public static function pack($data)
325
+ {
326
+ return base64_encode( serialize( $data ) );
327
+ }
328
+
329
+ public static function unpack($data)
330
+ {
331
+ return unserialize( base64_decode( $data ) );
332
+ }
333
+
334
+ public static function mkdir($path)
335
+ {
336
+ $error = '';
337
+ if (!is_dir($path)) {
338
+ @mkdir($path, 0755);
339
+
340
+ if (!is_dir($path)) {
341
+ $error = str_replace("%s", $dir, 'Failed to create a file, please check the permissions on the folders "%s".' );
342
+ }
343
+ @file_put_contents($path . '/index.php', '<?php // create automatically' );
344
+ if ( !is_writable($path . '/index.php') ) {
345
+ $error = str_replace("%s", $dir, 'Failed to create a file, please check the permissions on the folders "%s".');
346
+ }
347
+ }
348
+ return $error;
349
+ }
350
+
351
+ public static function setCommand($command, $value, $key = '' )
352
+ {
353
+ if (!is_dir(DBP_PATH_TMP)) {
354
+ self::mkdir(DBP_PATH_TMP);
355
+ }
356
+ $data = array();
357
+ if (file_exists(DBP_PATH_TMP . '/' . $command )) {
358
+ $data = self::unpack(file_get_contents( DBP_PATH_TMP . '/' . $command ) );
359
+ }
360
+ if (!empty($key)) {
361
+ $data[$key] = $value;
362
+ } else {
363
+ $data = $value;
364
+ }
365
+ file_put_contents(DBP_PATH_TMP . '/' . $command, self::pack($data) );
366
+ }
367
+
368
+ public static function getCommand($command, $key = '')
369
+ {
370
+ if (file_exists(DBP_PATH_TMP . '/' . $command)) {
371
+ $tmp = dbr_helper::unpack( file_get_contents(DBP_PATH_TMP . '/' . $command) );
372
+ if (!empty($key) && isset($tmp[$key])) {
373
+ return $tmp[$key];
374
+ } else {
375
+ return $tmp;
376
+ }
377
+ }
378
+ return false;
379
+ }
380
+
381
+ static function rmdir($dir)
382
+ {
383
+ if (is_dir($dir)) {
384
+ $dir_open = opendir($dir);
385
+ while($f = readdir($dir_open)) {
386
+ if ($f == '..' or $f == '.') {
387
+ continue;
388
+ }
389
+ if (is_dir($dir . '/' . $f)) {
390
+ self::rmdir($dir . '/' . $f);
391
+ }
392
+ if (file_exists($dir . '/' . $f)) {
393
+ @unlink($dir . '/' . $f);
394
+ }
395
+ }
396
+ @rmdir($dir);
397
+ } elseif (is_file($dir)) {
398
+ @unlink($dir);
399
+ }
400
+ }
401
+
402
+ }
403
+ }
404
+
405
+ if ( !class_exists('dbr_log') ) {
406
+ class dbr_log {
407
+
408
+ public static function log($txt = '')
409
+ {
410
+ if (!empty($txt)) {
411
+ dbr_helper::mkdir(DBP_PATH_TMP);
412
+ $log_file = DBP_PATH_TMP . '/log-restore.log';
413
+ file_put_contents($log_file, date("Y-m-d H:i:s") ."\t{$class}\t{$txt}\n", FILE_APPEND);
414
+ }
415
+ }
416
+
417
+ public static function getLog()
418
+ {
419
+ $log_file = DBP_PATH_TMP . '/log-restore.log';
420
+ if (file_exists($log_file)) {
421
+ $log2 = DBP_PATH_TMP. "/log-restore2";
422
+ $log = @file_get_contents($log_file);
423
+ if (file_exists($log2)) {
424
+ $text = @file_get_contents($log2);
425
+ file_put_contents($log2, $log);
426
+ $log = str_replace($text, "", $log);
427
+ } else {
428
+ file_put_contents($log2, $log);
429
+ }
430
+ $log = explode("\n", $log);
431
+ krsort($log);
432
+ $log_array = $log;
433
+ return $log_array;
434
+ }
435
+ return array();
436
+ }
437
+ }
438
+ }
439
+
440
+ if ( !class_exists('dbr_core') ) {
441
+ class dbr_core {
442
+
443
+ }
444
+ }
445
+
446
+ if ( !class_exists('dbr_methods') ) {
447
+ class dbr_methods{
448
+
449
+ private $setting_restore = array();
450
+ private $main = array();
451
+ private $md5_info = array();
452
+ private $dir_backup = '';
453
+ private $files_resotre = array();
454
+ /**
455
+ * MAIN METHOD
456
+ *
457
+ */
458
+ public function wpadm_logs_method()
459
+ {
460
+ $json = array();
461
+ $json['log'] = dbr_log::getlog();
462
+ if ( isset($_POST['type-backup']) && $_POST['type-backup'] == 'restore' ) {
463
+ if (file_exists(DBP_PATH_TMP . '/result-restore')) {
464
+ $json['data'] = dbr_helper::getCommand('result-restore');
465
+ }
466
+ }
467
+ echo json_encode ( $json );
468
+ exit;
469
+ }
470
+
471
+ /**
472
+ * MAIN METHOD
473
+ *
474
+ */
475
+ public function restore_method()
476
+ {
477
+ $this->setting_restore = dbr_helper::getCommand('restore-backup');
478
+ if (isset($this->setting_restore['action'])) {
479
+ dbr_log::log('Start restoring of backup "' . $this->setting_restore['name'] . '"');
480
+ $this->dir_backup = DROPBOX_BACKUP_DIR_BACKUP . "/{$this->setting_restore['name']}";
481
+ switch($this->setting_restore['action']) {
482
+ case 'wpadm_restore_dropbox':
483
+ if ( $this->dowloadDropbox() ) {
484
+ $this->parseFilesToRestore();
485
+ $this->restoreFiles();
486
+ $this->restoreDataBase();
487
+ dbr_helper::rmdir($this->dir_backup);
488
+ }
489
+ break;
490
+ case 'wpadm_local_restore':
491
+ $this->parseFilesToRestore();
492
+ $this->restoreFiles();
493
+ $this->restoreDataBase();
494
+ break;
495
+ }
496
+ } else {
497
+ dbr_helper::setError('Unknown action of backup method to start restoring.');
498
+ }
499
+ }
500
+ private function restoreDataBase()
501
+ {
502
+ dbr_log::log('Database restoring was started');
503
+ $file = DROPBOX_BACKUP_DIR_BACKUP . '/mysqldump.sql';
504
+ if (!file_exists($file)) {
505
+ dbr_helper::setError( 'Error: dump/database file wasn\'t found' );
506
+ }
507
+ $fo = fopen($file, "r");
508
+ if (!$fo) {
509
+ dbr_helper::setError( 'Error of opening dump/database file' );
510
+ }
511
+ dbr_helper::is_work(time(), 'start');
512
+ $sql = "";
513
+ while(false !== ($char = fgetc($fo))) {
514
+ $sql .= $char;
515
+ if ($char == ";") {
516
+ $char_new = fgetc($fo);
517
+ if ($char_new !== false && $char_new != "\n") {
518
+ $sql .= $char_new;
519
+ } else {
520
+ $is_sql = true;
521
+ if ( strpos($sql, '_transient_timeout_drb_running') === false ) {
522
+ $is_sql = false;
523
+ }
524
+ if ( strpos($sql, '_transient_drb_running') === false ) {
525
+ $is_sql = false;
526
+ }
527
+ if ( strpos($sql, PREFIX_BACKUP_ . "_commands") === false ) {
528
+ $is_sql = false;
529
+ }
530
+ if ( strpos($sql, PREFIX_BACKUP_ . "proccess-command") === false ) {
531
+ $is_sql = false;
532
+ }
533
+ if ($is_sql) {
534
+ $ress = dbr_database::query( $sql );
535
+ }
536
+ if ( $ress === false || !empty( dbr_database::$error )) {
537
+ dbr_helper::setError('MySQL Error: ' . dbr_database::$error );
538
+ break;
539
+ };
540
+ $sql = "";
541
+ }
542
+ }
543
+ }
544
+
545
+ // ----------------- set command for create backup to null
546
+ dbr_database::db_update('options', array('option_value' => serialize( array() ) ), array('option_name' => PREFIX_BACKUP_ . "_commands") );
547
+ dbr_database::db_update('options', array('option_value' => serialize( array() ) ), array('option_name' => PREFIX_BACKUP_ . "proccess-command") );
548
+ // -----------------
549
+ dbr_helper::setCommand('result-restore', array('name' => $this->setting_restore['name'], 'result' => 'success'));
550
+ dbr_log::log( 'Database restoring was finished successfully' );
551
+ }
552
+ private function parseFilesToRestore()
553
+ {
554
+ $md5_info = dbr_helper::getCommand('md5_info-restore');
555
+ $file_list = dbr_helper::getCommand('files-list-retore');
556
+ if (!$md5_info || !$file_list) {
557
+ dbr_log::log('Reading backup files and creating of file list for restoring process');
558
+ dbr_helper::is_work(time(), 'start');
559
+ $dir_open = opendir($this->dir_backup);
560
+ $file_md5 = '';
561
+ while($d = readdir($dir_open)) {
562
+ if ($d != "." && $d != '..') {
563
+ if(strpos($d, ".zip") !== false) {
564
+ $this->files_resotre[$d] = $this->dir_backup . "/$d";
565
+ }
566
+ if(strpos($d, ".md5") !== false) {
567
+ $file_md5 = $this->dir_backup . "/$d";
568
+ }
569
+ }
570
+ }
571
+ dbr_helper::setCommand('files-list-retore', $this->files_resotre);
572
+ dbr_helper::is_work(time(), 'start');
573
+
574
+ if (!empty($file_md5)) {
575
+
576
+ if (file_exists($file_md5)) {
577
+ $this->md5_info = explode ("\n", file_get_contents( $file_md5 ) ); // delemiter \t (1 - file name, 2 - md5_file, 3 - zip file)
578
+ dbr_helper::setCommand('md5_info-restore', $this->md5_info);
579
+ dbr_helper::is_work(time(), 'start');
580
+ } else {
581
+ dbr_helper::setError('Error of MD5 file parsing during restoring of backup');
582
+ }
583
+ } else {
584
+ dbr_helper::setError('Error during creating of MD5 file list for restoring process. Backup files wasn\'t found');
585
+ }
586
+ } else {
587
+ $this->md5_info = $md5_info;
588
+ $this->files_resotre = $file_list;
589
+ }
590
+
591
+ }
592
+
593
+ private function restoreFiles()
594
+ {
595
+ include 'pclzip.lib.php';
596
+ $files = dbr_helper::getCommand('files-list-retore');
597
+ if ($files) {
598
+ dbr_helper::is_work(time(), 'start');
599
+ if ( empty( $this->md5_info ) ) {
600
+ $this->md5_info = dbr_helper::getCommand('md5_info-restore');
601
+ }
602
+ $zip_database = dbr_helper::getCommand('zip-database');
603
+ if ($zip_database) {
604
+ $while = true;
605
+ while($while) {
606
+ $file_info = array_pop($this->md5_info);
607
+ if (strpos($file_info, 'mysqldump.sql') !== false && strpos($file_info, DROPBOX_BACKUP_DIR_NAME) !== false) {
608
+ $info = explode("\t", $file_info);
609
+ if (isset($info[2])) {
610
+ $zip_database = $info;
611
+ dbr_helper::setCommand('zip-database-restore', $zip_database);
612
+ $while = false;
613
+ }
614
+ }
615
+ }
616
+ }
617
+ foreach($files as $f => $file) {
618
+ $extract_files = dbr_helper::getCommand('extract-files-restore');
619
+ if (!isset($extract_files[$f])) {
620
+ dbr_log::log('Data will be decompressed of ' . basename($file));
621
+ if (strpos($f, '.zip')) {
622
+ if (file_exists($file) && filesize($file) > 0) {
623
+ $archive = new PclZip($file);
624
+ $unzip = $archive->extract(
625
+ PCLZIP_OPT_PATH, ABSPATH,
626
+ PCLZIP_OPT_REPLACE_NEWER /// extracted all files & databasedump
627
+ );
628
+ if ($unzip== 0) {
629
+ dbr_helper::setError("Error during extracting of archive: " . $archive->errorInfo(true) );
630
+ }
631
+ if (strpos($file, $zip_database[2]) !== false) {
632
+ $archive = new PclZip($file);
633
+ $base_path = dbr_helper::getBasePath($zip_database[1]); // dump in directory website archive
634
+ $unzip = $archive->extract(PCLZIP_OPT_PATH, ABSPATH,
635
+ PCLZIP_OPT_REPLACE_NEWER,
636
+ PCLZIP_OPT_BY_EREG, "mysqldump.sql$"
637
+ );
638
+ if ($unzip== 0) {
639
+ dbr_helper::setError("Error during extracting of dump/database from archive: " . $archive->errorInfo(true) );
640
+ }
641
+ }
642
+ $extract_files[$f] = true;
643
+ dbr_helper::setCommand('extract-files-restore', $extract_files);
644
+ dbr_helper::is_work(time(), 'start');
645
+ } else {
646
+ dbr_helper::setError('File (' . $file . ') for restoring wasn\'t found or file size is 0 byte');
647
+ }
648
+ }
649
+ }
650
+ }
651
+ } else {
652
+ dbr_helper::setError('Restoration file list wasn\'t created or is empty. Please, check if folder exists and elso check folder rights. Folder path: ' . $this->dir_backup);
653
+ }
654
+ }
655
+
656
+
657
+ private function dowloadDropbox()
658
+ {
659
+ $success = dbr_helper::getCommand('download-with-dropbox-restore', 'success');
660
+ if ($success) {
661
+ return true;
662
+ }
663
+ include "dropbox.class.php";
664
+ $setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
665
+ if (isset($setting['option_value'] )) {
666
+ $this->main = dbr_helper::unpack( $setting['option_value'] );
667
+ }
668
+ if (!empty($this->main)) {
669
+ if (isset($this->main['app_key']) && isset($this->main['app_secret']) && isset($this->main['auth_token_secret'])) {
670
+ $dropbox = new dropbox($this->main['app_key'], $this->main['app_secret'], $this->main['auth_token_secret']);
671
+ if ($dropbox->isAuth()) {
672
+ dbr_helper::is_work(time(), 'start');
673
+ dbr_log::log('Connect to dropbox was successful');
674
+ dbr_helper::mkdir($this->dir_backup);
675
+ $folder_project = dbr_helper::getProjectName();
676
+ $name_backup = $this->setting_restore['name'];
677
+ $file_list = dbr_helper::getCommand('download-with-dropbox-restore', 'file-list');
678
+ if ($file_list === false) {
679
+ dbr_log::log('Getting list of files from Dropbox');
680
+ $files = $dropbox->listing("$folder_project/$name_backup");
681
+ dbr_helper::setCommand('download-with-dropbox-restore', $files, 'file-list');
682
+ dbr_helper::is_work(time(), 'start');
683
+ } else {
684
+ $files = $file_list;
685
+ }
686
+
687
+ if (isset($files['items'])) {
688
+ dbr_log::log('File list was created successful');
689
+ $n = count($files['items']);
690
+ dbr_log::log('Starting of files download from Dropbox');
691
+ for($i = 0; $i < $n; $i++) {
692
+ $files_download = dbr_helper::getCommand('download-with-dropbox-restore', 'download');
693
+ if (!isset($files_download[$files['items'][$i]['name']])) {
694
+ $res = $dropbox->downloadFile("$folder_project/$name_backup/{$files['items'][$i]['name']}", "{$this->dir_backup}/{$files['items'][$i]['name']}");
695
+ if ($res != "{$this->dir_backup}/{$files['items'][$i]['name']}" && isset($res['text'])) {
696
+ dbr_helper::setError( 'During download of file "' . $files['items'][$i]['name'] . '" an error occurred: ' . $res['text'] );
697
+ } else {
698
+ $log = str_replace('%s', $files['items'][$i]['name'], 'File (%s) was successfully downloaded from Dropbox' );
699
+ dbr_log::log($log);
700
+ if (file_exists("{$this->dir_backup}/{$files['items'][$i]['name']}") && filesize("{$this->dir_backup}/{$files['items'][$i]['name']}") > 0) {
701
+ $files_download[$files['items'][$i]['name']] = true;
702
+ dbr_helper::setCommand('download-with-dropbox-restore', $files_download, 'download' );
703
+ dbr_helper::is_work(time(), 'start');
704
+ }
705
+ }
706
+ }
707
+ }
708
+ $md5 = glob($this->dir_backup . '/*.md5');
709
+ if (count( $md5 ) == 0) {
710
+ dbr_helper::setError( "File list from MD5 file wasn\'t loaded. Please, check folder and folder rights " . $this->dir_backup . " and MD5 file in this folder with file rights");
711
+ }
712
+ dbr_helper::setCommand('download-with-dropbox-restore', true, 'success');
713
+ return true;
714
+ }
715
+ } else {
716
+ dbr_helper::setError('Authentication error during connect to Dropbox. Please, try again later');
717
+ }
718
+ } else {
719
+ dbr_helper::setError('Dropbox connection settings wasn\'t found or wrong. Please, check Dropbox connections settings');
720
+ }
721
+ } else {
722
+ dbr_helper::setError('Dropbox connection settings wasn\'t found or wrong. Please, check Dropbox connections settings');
723
+ }
724
+ }
725
+ }
726
+ }
727
+
728
+ if (!class_exists('dbr_route')) {
729
+
730
+ if (!defined('ABSPATH')) {
731
+ define('ABSPATH', dirname(__FILE__) . '/../../../../');
732
+ }
733
+ if (!defined('DBP_PATH')) {
734
+ define('DBP_PATH', dirname(__FILE__) . '/../');
735
+ }
736
+ if (!defined('DBP_PATH_TMP')) {
737
+ define('DBP_PATH_TMP', DBP_PATH . 'tmp');
738
+ }
739
+
740
+
741
+ class dbr_route {
742
+
743
+ private $cron_is_work = 60;
744
+
745
+ private $plugins = array();
746
+
747
+ private $setting = array();
748
+
749
+ private $method_access = array('wpadm_logs');
750
+
751
+ function __construct()
752
+ {
753
+ if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
754
+ if ( isset($_POST['key']) ) {
755
+ $this->parsMethod();
756
+ } elseif( !isset($_POST['key']) && isset($_POST['name']) ) {
757
+ dbr_helper::clearTMP();
758
+ dbr_database::inc_wp_config();
759
+ $setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
760
+ if (isset($setting['option_value'] )) {
761
+ $this->setting = dbr_helper::unpack( $setting['option_value'] );
762
+ }
763
+ $this->setting['restore-key'] = md5( time() . microtime() . __FILE__);
764
+ include 'constant.php';
765
+ $plugin = $this->parsePlugin('/dropbox-backup');
766
+ $plugin_name = 'dropbox-backup';
767
+ $version = '1.0';
768
+ if (isset($plugin['/dropbox-backup']['Version'])) {
769
+ $version = $plugin['/dropbox-backup']['Version'];
770
+ } else{
771
+ $plugin = $this->parsePlugin('/dropbox-backup-pro');
772
+ if (isset($plugin['/dropbox-backup-pro']['Version'])) {
773
+ $version = $plugin['/dropbox-backup-pro']['Version'];
774
+ $plugin_name = 'dropbox-backup-pro';
775
+ }
776
+ }
777
+ $data = array('actApi' => 'setPluginCode', $plugin_name . '_request' => array('action' => 'restore', 'site' => home_url(), 'pl' => $plugin_name, 'key' => $this->setting['restore-key'], 'pl_v' => $version, ) );
778
+ $res = dbr_api::post(WPADM_URL_BASE . 'api/', $data);
779
+ if ( !empty( $res['res'] ) ) {
780
+ $result = json_decode($res['res'], true);
781
+ if (isset($result['code'])) {
782
+ switch($result['code']) {
783
+ case 101 :
784
+ dbr_helper::setError('The restoring method has an error');
785
+ break;
786
+ case 108 :
787
+ dbr_helper::setError('Error of the post/request data');
788
+ break;
789
+ case 109 :
790
+ dbr_helper::setError('Error of the params data');
791
+ break;
792
+ case 110 :
793
+ dbr_helper::setError('Unknown error');
794
+ break;
795
+ }
796
+ dbr_database::db_update('options', array('option_value' => dbr_helper::pack( $this->setting ) ), array('option_name' => 'wpadm_backup_dropbox-setting') ) ;
797
+ dbr_helper::setCommand('restore-backup', $_POST);
798
+ echo json_encode(array('result' => 'work'));
799
+ }
800
+ }
801
+ }
802
+ }
803
+ }
804
+
805
+
806
+ private function parsMethod()
807
+ {
808
+ if ( isset($_POST['method']) ) {
809
+ try {
810
+ dbr_helper::mkdir(DBP_PATH_TMP);
811
+ if (!dbr_helper::is_work() || in_array($_POST['method'], $this->method_access ) ) {
812
+ if (isset($_POST['key'])) {
813
+ dbr_database::inc_wp_config();
814
+ $setting = dbr_database::db_get('options', array('option_value'), array('option_name' => 'wpadm_backup_dropbox-setting'), 1);
815
+ $this->setting = dbr_helper::unpack( $setting['option_value'] );
816
+ if (file_exists(DROPBOX_BACKUP_DIR_BACKUP . '/local-key')) {
817
+ $key_values = dbr_helper::unpack( file_get_contents(DROPBOX_BACKUP_DIR_BACKUP . '/local-key') );
818
+ }
819
+ if ($_POST['key'] == $this->setting['restore-key'] || ( isset($key_values['key']) && $_POST['key'] == $key_values['key'] ) ) {
820
+ $methods = new dbr_methods();
821
+ $method = $_POST['method']. '_method';
822
+ if (method_exists($methods, $method)) {
823
+ if ($_POST['method'] != 'wpadm_logs') {
824
+ if (file_exists(DBP_PATH_TMP . '/result-restore')) {
825
+ dbr_helper::is_work(time(), 'finish');
826
+ $result = dbr_helper::getCommand('result-restore');
827
+ if (isset($result['result']) && $result['result'] == 'success') {
828
+ $this->getResult(200);
829
+ } elseif (isset($result['result']) && isset($result['message']) && $result['result'] == 'error') {
830
+ $this->getResult(402, $result['message']);
831
+ }
832
+ }
833
+ }
834
+
835
+ if (isset($_POST['type-backup']) && $_POST['type-backup'] == 'restore') {
836
+ if ( !dbr_helper::is_work() && dbr_helper::getCommand('restore-backup') ) {
837
+ dbr_api::post('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], array('key' => $this->setting['restore-key'], 'method' => 'restore'), array('timelimit' => 5) );
838
+ }
839
+ } else {
840
+ dbr_helper::is_work(time(), 'start');
841
+ }
842
+ $methods->$method();
843
+ if (!isset($_POST['type-backup'])) {
844
+ dbr_helper::is_work(time(), 'finish');
845
+ }
846
+ } else {
847
+ $this->getResult(401);
848
+ }
849
+ } else {
850
+ $this->getResult(400);
851
+ }
852
+ } else {
853
+ $this->getResult(400);
854
+ }
855
+ }
856
+ } catch(Exception $e) {
857
+ dbr_log::log($e->getMessage());
858
+ dbr_helper::setCommand('result-restore', array('name' => $this->setting_restore['name'], 'result' => 'error', 'message' => $e->getMessage() ) );
859
+ }
860
+ }
861
+ }
862
+
863
+
864
+
865
+
866
+ /**
867
+ * json encode
868
+ *
869
+ * @param integer $code
870
+ * @param mixed $data
871
+ *
872
+ * 200 - success
873
+ * 400 - error in key
874
+ * 401 - method not exists
875
+ * 402 - error in work
876
+ */
877
+ private function getResult($code, $data = '')
878
+ {
879
+ $encode = array('code' => $code);
880
+ if (!empty($data)) {
881
+ $encode['data'] = $data;
882
+ }
883
+ echo json_encode($encode);
884
+ exit;
885
+ }
886
+
887
+ private function parsePlugin($folder)
888
+ {
889
+ $plugin_dir = ABSPATH . 'wp-content/plugins' . $folder ;
890
+ if (is_dir($plugin_dir) ) {
891
+ $files = glob($plugin_dir . '/*.php');
892
+ $n = count($files);
893
+ for($i = 0; $i < $n; $i++) {
894
+ $plugin = file_get_contents($files[$i]);
895
+ if (preg_match("/version: ([0-9\.]+)/i", $plugin, $data)) {
896
+ if (isset($data[1]) && !empty($data[1])) {
897
+ $this->plugins[$folder]['Version'] = $data[1];
898
+ break;
899
+ }
900
+ }
901
+
902
+ }
903
+ }
904
+ return $this->plugins;
905
+ }
906
+ }
907
+
908
+ new dbr_route();
909
+ }
readme.txt CHANGED
@@ -1,6 +1,6 @@
1
  === Dropbox Backup & Restore ===
2
  Plugin Name: Dropbox Backup & Restore
3
- Version: 1.4.5
4
  Donate link: http://www.wpadm.com/donate
5
  URI: http://www.wpadm.com/dropbox-backup
6
  Tags: dropbox, backup, dropbox backup, database, file, full backup, manage, sicherung, database backup, file backup, page backup, page, web, web backup, web page, synchronize, clone, duplicate, move, web page backup, site, site backup, back up, cloud, Cloud Files, cloud backup, db backup, dump, german, migrate, multisite, German, schedule, storage, time, upload, data bank, zip, archive, backups, restore, db, recover, recovery, restoration, wp backup, wordpress backup, wordpress backup to dropbox, plugin wordpress backup, wpadm, wpadm.com, website, website backup, website back up, wp backup, wordpress backup, scheduled backup, backup scheduler, tool, backup tool
@@ -180,11 +180,6 @@ Before you try to make a backup of your website to dropbox, please make sure, th
180
  To do this, please, open the "Settings" block in your "Dropbox backup and restore" plugin. There you must see your Dropbox UID (User ID on Dropbox). If you didn't see your Dropbox connection App UID - your Dropbox plugin is NOT CONNECTED to your Dropbox and you can't do the backup of your website.<br />
181
  So please, at first connect yourself to Dropbox and then, try to make your backup to dropbox.
182
 
183
- = Should I have an account of Dropbox to make a back up of my website there? =
184
-
185
- You should have not only an account on Dropbox. The installed Dropbox backup and restore plugin must be also connected to your Dropbox account to perform a backup.
186
-
187
-
188
  = How to restore my site from dropbox backup? =
189
 
190
  - First of all, install the Dropbox backup & restore plugin;<br />
@@ -396,8 +391,6 @@ Please, keep your Dropbox Backup and Restore plugin up-to-date.
396
 
397
  **Rev.**&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;**Description** <br />
398
 
399
- &nbsp;&nbsp;&nbsp;&nbsp;Working process of backup was corrected. Bug fixes. New look of backup process was integrated.<br />
400
- &nbsp;&nbsp;&nbsp;&nbsp;Dropbox Backup and Restore plugin new version 1.4.4 for WordPress. Fixed methods and commands process.<br />
401
  &nbsp;&nbsp;&nbsp;&nbsp;Tested up to WordPress version 4.4.2<br />
402
  &nbsp;&nbsp;&nbsp;&nbsp;Answers for questions about dropbox back up and restore plugin window.<br />
403
  &nbsp;&nbsp;&nbsp;&nbsp;Changes of features list for dropbox back up and restore plugin.<br />
1
  === Dropbox Backup & Restore ===
2
  Plugin Name: Dropbox Backup & Restore
3
+ Version: 1.4.4
4
  Donate link: http://www.wpadm.com/donate
5
  URI: http://www.wpadm.com/dropbox-backup
6
  Tags: dropbox, backup, dropbox backup, database, file, full backup, manage, sicherung, database backup, file backup, page backup, page, web, web backup, web page, synchronize, clone, duplicate, move, web page backup, site, site backup, back up, cloud, Cloud Files, cloud backup, db backup, dump, german, migrate, multisite, German, schedule, storage, time, upload, data bank, zip, archive, backups, restore, db, recover, recovery, restoration, wp backup, wordpress backup, wordpress backup to dropbox, plugin wordpress backup, wpadm, wpadm.com, website, website backup, website back up, wp backup, wordpress backup, scheduled backup, backup scheduler, tool, backup tool
180
  To do this, please, open the "Settings" block in your "Dropbox backup and restore" plugin. There you must see your Dropbox UID (User ID on Dropbox). If you didn't see your Dropbox connection App UID - your Dropbox plugin is NOT CONNECTED to your Dropbox and you can't do the backup of your website.<br />
181
  So please, at first connect yourself to Dropbox and then, try to make your backup to dropbox.
182
 
 
 
 
 
 
183
  = How to restore my site from dropbox backup? =
184
 
185
  - First of all, install the Dropbox backup & restore plugin;<br />
391
 
392
  **Rev.**&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;**Description** <br />
393
 
 
 
394
  &nbsp;&nbsp;&nbsp;&nbsp;Tested up to WordPress version 4.4.2<br />
395
  &nbsp;&nbsp;&nbsp;&nbsp;Answers for questions about dropbox back up and restore plugin window.<br />
396
  &nbsp;&nbsp;&nbsp;&nbsp;Changes of features list for dropbox back up and restore plugin.<br />
template/expsys.php CHANGED
@@ -13,13 +13,27 @@
13
  jQuery('.body-functions-view').hide('slow');
14
  }
15
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  </script>
17
  <div class="functions-view">
18
  <div class="title-functions-view" onclick="showView();">
19
  <?php echo $str; ?>
20
  </div>
21
  <div class="body-functions-view">
22
- <?php echo isset($functions_need) ? $functions_need : ''; ?>
23
  </div>
24
  </div>
25
  <?php
13
  jQuery('.body-functions-view').hide('slow');
14
  }
15
  }
16
+ function getView(id, form_id)
17
+ {
18
+ data = {'action' : 'getForm', 'form_id' : id};
19
+ jQuery.ajax({
20
+ url: ajaxurl,
21
+ type: 'post',
22
+ data: data,
23
+ success: function(data) {
24
+ if(data){
25
+ jQuery(form_id).html(data);
26
+ }
27
+ }
28
+ });
29
+ }
30
  </script>
31
  <div class="functions-view">
32
  <div class="title-functions-view" onclick="showView();">
33
  <?php echo $str; ?>
34
  </div>
35
  <div class="body-functions-view">
36
+ <?php echo $functions_need; ?>
37
  </div>
38
  </div>
39
  <?php
template/index.html ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head lang="en">
4
+ <meta charset="UTF-8">
5
+ <title></title>
6
+ </head>
7
+ <body>
8
+
9
+ </body>
10
+ </html>
template/wpadm_show_backup.php CHANGED
@@ -349,26 +349,45 @@
349
  'action': 'wpadm_logs',
350
  'type-backup' : method,
351
  };
 
 
 
 
 
 
 
352
  jQuery.ajax({
353
  type: "POST",
354
- url: ajaxurl,
355
  data: data_log,
356
  success: function(response){
357
- eval("var data=" + response);
358
- for(s in data.log) {
359
- if (jQuery.inArray(s , logs) == -1) {
360
- l = jQuery("#log-backup").html();
361
- l = "<div>" + data.log[s] + "</div>" + l;
362
- jQuery("#log-backup").html(l);
 
 
363
  }
364
- }
365
- if (process_flag == 1) {
366
- if (data.data) {
367
- showData(data.data);
368
- processStop();
369
- } else {
370
- setTimeout('processBar("' + method + '")', 5000);
 
 
 
 
 
 
 
 
371
  }
 
 
372
  }
373
  },
374
  error: function(jqXHR, textStatus, errorThrown){
@@ -407,14 +426,47 @@
407
  document.form_auth_backup_create.submit();
408
  }
409
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
  function show_recovery_form(type, name)
411
  {
412
  var act = '';
413
  if (confirm("<?php _e('Are you sure you want to start the recovery process?','dropbox-backup')?>")) {
414
  if (type == 'local') {
415
  act = 'wpadm_local_restore';
 
416
  } else {
417
  act = 'wpadm_restore_dropbox';
 
418
  }
419
  var data_backup = {
420
  'action': act,
@@ -433,17 +485,18 @@
433
  jQuery("#action-buttons").css('margin-top', '8px');
434
  jQuery.ajax({
435
  type: "POST",
436
- url: ajaxurl,
 
437
  data: data_backup,
438
  beforeSend: function(){
439
  process_flag = 1
440
- processBar();
441
  showTime();
442
 
443
  },
444
  success: function(data){
445
- process_flag = 0;
446
  if (data.result == 'success') {
 
447
  jQuery('.title-logs').css('display', 'none');
448
  jQuery('.title-status').css({'display':'block', 'color':'green'});
449
  if (type == 'local') {
@@ -458,6 +511,7 @@
458
  } else if (data.result == 'work'){
459
 
460
  } else {
 
461
  jQuery('.title-logs').css('display', 'none');
462
  jQuery('.title-status').css({'display':'block', 'color':'red'});
463
  if (type == 'local') {
@@ -823,7 +877,9 @@
823
  }?>
824
  <div id="is-dropbox-auth" style="display: none; width: 380px; text-align: center; background: #fff; border: 2px solid #dde4ff; border-radius: 5px;">
825
  <div class="title-description" style="font-size: 20px; text-align: center;padding-top:45px; line-height: 30px;">
826
- <?php _e('Please, add your Dropbox credentials:','dropbox-backup'); ?><br />
 
 
827
  <strong><?php _e('"App key"','dropbox-backup'); ?></strong> & <strong><?php _e('"App secret"','dropbox-backup'); ?></strong> <br />
828
  <?php _e('in the Setting Form','dropbox-backup'); ?>
829
  </div>
349
  'action': 'wpadm_logs',
350
  'type-backup' : method,
351
  };
352
+
353
+ var url_ajax = ajaxurl;
354
+ if (method == 'restore') {
355
+ url_ajax = '<?php echo plugins_url('/modules/restore-class.php', dirname(__FILE__) ); ?>';
356
+ data_log['key'] = '<?php echo $key; ?>';
357
+ data_log['method'] = 'wpadm_logs';
358
+ }
359
  jQuery.ajax({
360
  type: "POST",
361
+ url: url_ajax,
362
  data: data_log,
363
  success: function(response){
364
+ if (response != '') {
365
+ eval("var data=" + response);
366
+ for(s in data.log) {
367
+ if (jQuery.inArray(s , logs) == -1) {
368
+ l = jQuery("#log-backup").html();
369
+ l = "<div>" + data.log[s] + "</div>" + l;
370
+ jQuery("#log-backup").html(l);
371
+ }
372
  }
373
+ if (process_flag == 1) {
374
+ if (data.data) {
375
+ if (method == 'restore') {
376
+ if (type_restore == 'local') {
377
+ showRestoreInfo(data.data.result, 'local', data.data.name)
378
+ } else if (type_restore == 'dropbox') {
379
+ showRestoreInfo(data.data.result, 'dropbox', data.data.name)
380
+ }
381
+ } else {
382
+ showData(data.data);
383
+ }
384
+ processStop();
385
+ } else {
386
+ setTimeout('processBar("' + method + '")', 5000);
387
+ }
388
  }
389
+ } else {
390
+ setTimeout('processBar("' + method + '")', 5000);
391
  }
392
  },
393
  error: function(jqXHR, textStatus, errorThrown){
426
  document.form_auth_backup_create.submit();
427
  }
428
  }
429
+
430
+ function showRestoreInfo(result, type, name)
431
+ {
432
+ if (result == 'success') {
433
+ jQuery('.title-logs').css('display', 'none');
434
+ jQuery('.title-status').css({'display':'block', 'color':'green'});
435
+ if (type == 'local') {
436
+ str = '<?php _e('Local Backup (%s) was restored successfully','dropbox-backup'); ?>';
437
+ str = str.replace('%s', name);
438
+ jQuery('.title-status').html(str);
439
+ } else {
440
+ str = '<?php _e('Dropbox Backup (%s) was restored successfully','dropbox-backup'); ?>';
441
+ str = str.replace('%s', name);
442
+ jQuery('.title-status').html(str);
443
+ }
444
+ } else {
445
+ jQuery('.title-logs').css('display', 'none');
446
+ jQuery('.title-status').css({'display':'block', 'color':'red'});
447
+ if (type == 'local') {
448
+ str = "<?php _e('Local Backup (%s) wasn\'t restored','dropbox-backup'); ?>";
449
+ str = str.replace("%s", name) ;
450
+ jQuery('.title-status').html(str);
451
+ } else {
452
+ str = "<?php _e('Dropbox Backup (%s) wasn\'t restored','dropbox-backup'); ?>";
453
+ str = str.replace('%s', name);
454
+ jQuery('.title-status').html(str);
455
+ }
456
+ }
457
+ }
458
+
459
+ var type_restore = '';
460
  function show_recovery_form(type, name)
461
  {
462
  var act = '';
463
  if (confirm("<?php _e('Are you sure you want to start the recovery process?','dropbox-backup')?>")) {
464
  if (type == 'local') {
465
  act = 'wpadm_local_restore';
466
+ type_restore = 'local';
467
  } else {
468
  act = 'wpadm_restore_dropbox';
469
+ type_restore = 'dropbox';
470
  }
471
  var data_backup = {
472
  'action': act,
485
  jQuery("#action-buttons").css('margin-top', '8px');
486
  jQuery.ajax({
487
  type: "POST",
488
+ // url: ajaxurl,
489
+ url: '<?php echo plugins_url('/modules/restore-class.php', dirname(__FILE__) ); ?>',
490
  data: data_backup,
491
  beforeSend: function(){
492
  process_flag = 1
493
+ processBar('restore');
494
  showTime();
495
 
496
  },
497
  success: function(data){
 
498
  if (data.result == 'success') {
499
+ process_flag = 0;
500
  jQuery('.title-logs').css('display', 'none');
501
  jQuery('.title-status').css({'display':'block', 'color':'green'});
502
  if (type == 'local') {
511
  } else if (data.result == 'work'){
512
 
513
  } else {
514
+ process_flag = 0;
515
  jQuery('.title-logs').css('display', 'none');
516
  jQuery('.title-status').css({'display':'block', 'color':'red'});
517
  if (type == 'local') {
877
  }?>
878
  <div id="is-dropbox-auth" style="display: none; width: 380px; text-align: center; background: #fff; border: 2px solid #dde4ff; border-radius: 5px;">
879
  <div class="title-description" style="font-size: 20px; text-align: center;padding-top:45px; line-height: 30px;">
880
+ <?php _e('Your Dropbox account must be connected before backup to Dropbox.', 'dropbox-backup'); ?> <br />
881
+ <?php _e('To do this, please, click the button "Connect to Dropbox" in the settings', 'dropbox-backup'); ?> <br />
882
+ <?php _e('or add your own Dropbox credentials:', 'dropbox-backup'); ?> <br />
883
  <strong><?php _e('"App key"','dropbox-backup'); ?></strong> & <strong><?php _e('"App secret"','dropbox-backup'); ?></strong> <br />
884
  <?php _e('in the Setting Form','dropbox-backup'); ?>
885
  </div>