@@ -65,13 +65,8 @@ |
||
65 | 65 | |
66 | 66 | use League\Flysystem\Config; |
67 | 67 | use League\Flysystem\Filesystem; |
68 | -use League\Flysystem\Util; |
|
69 | 68 | use League\Flysystem\Adapter\Local; |
70 | - |
|
71 | 69 | use splitbrain\PHPArchive\Tar; |
72 | -use splitbrain\PHPArchive\Archive; |
|
73 | -use splitbrain\PHPArchive\FileInfo; |
|
74 | - |
|
75 | 70 | use Monolog\Logger; |
76 | 71 | use Monolog\Handler\StreamHandler; |
77 | 72 |
@@ -45,8 +45,7 @@ discard block |
||
45 | 45 | { |
46 | 46 | |
47 | 47 | require_once($file); |
48 | -} |
|
49 | -elseif (file_exists("vendor.phar") and extension_loaded('phar')) |
|
48 | +} elseif (file_exists("vendor.phar") and extension_loaded('phar')) |
|
50 | 49 | { |
51 | 50 | require_once(__DIR__.DS."vendor.phar"); |
52 | 51 | } else { |
@@ -87,7 +86,7 @@ discard block |
||
87 | 86 | try { |
88 | 87 | $return = $xcloner_restore->init(); |
89 | 88 | $xcloner_restore->send_response(200, $return); |
90 | -}catch (Exception $e) { |
|
89 | +} catch (Exception $e) { |
|
91 | 90 | $xcloner_restore->send_response(417, $e->getMessage()); |
92 | 91 | } |
93 | 92 | |
@@ -228,13 +227,15 @@ discard block |
||
228 | 227 | { |
229 | 228 | $target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
230 | 229 | |
231 | - if (!$_POST['start']) |
|
232 | - $fp = fopen($target_file, "wb+"); |
|
233 | - else |
|
234 | - $fp = fopen($target_file, "ab+"); |
|
230 | + if (!$_POST['start']) { |
|
231 | + $fp = fopen($target_file, "wb+"); |
|
232 | + } else { |
|
233 | + $fp = fopen($target_file, "ab+"); |
|
234 | + } |
|
235 | 235 | |
236 | - if (!$fp) |
|
237 | - throw new Exception("Unable to open $target_file file for writing"); |
|
236 | + if (!$fp) { |
|
237 | + throw new Exception("Unable to open $target_file file for writing"); |
|
238 | + } |
|
238 | 239 | |
239 | 240 | fseek($fp, $_POST['start']); |
240 | 241 | |
@@ -244,22 +245,24 @@ discard block |
||
244 | 245 | |
245 | 246 | $blob = file_get_contents($_FILES['blob']['tmp_name']); |
246 | 247 | |
247 | - if (!$bytes_written = fwrite($fp, $blob)) |
|
248 | - throw new Exception("Unable to write data to file $target_file"); |
|
248 | + if (!$bytes_written = fwrite($fp, $blob)) { |
|
249 | + throw new Exception("Unable to write data to file $target_file"); |
|
250 | + } |
|
249 | 251 | |
250 | 252 | try { |
251 | 253 | unlink($_FILES['blob']['tmp_name']); |
252 | - }catch (Exception $e) { |
|
254 | + } catch (Exception $e) { |
|
253 | 255 | |
254 | 256 | } |
255 | 257 | |
256 | - }elseif (isset($_POST['blob'])) { |
|
258 | + } elseif (isset($_POST['blob'])) { |
|
257 | 259 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
258 | 260 | |
259 | 261 | $blob = $_POST['blob']; |
260 | 262 | |
261 | - if (!$bytes_written = fwrite($fp, $blob)) |
|
262 | - throw new Exception("Unable to write data to file $target_file"); |
|
263 | + if (!$bytes_written = fwrite($fp, $blob)) { |
|
264 | + throw new Exception("Unable to write data to file $target_file"); |
|
265 | + } |
|
263 | 266 | } else { |
264 | 267 | throw new Exception("Upload failed, did not receive any binary data"); |
265 | 268 | } |
@@ -294,10 +297,11 @@ discard block |
||
294 | 297 | |
295 | 298 | $mysqli->query("SET sql_mode='';"); |
296 | 299 | $mysqli->query("SET foreign_key_checks = 0;"); |
297 | - if (isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) |
|
298 | - $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
299 | - else |
|
300 | - $mysqli->query("SET NAMES utf8;"); |
|
300 | + if (isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) { |
|
301 | + $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
302 | + } else { |
|
303 | + $mysqli->query("SET NAMES utf8;"); |
|
304 | + } |
|
301 | 305 | |
302 | 306 | return $mysqli; |
303 | 307 | } |
@@ -327,8 +331,9 @@ discard block |
||
327 | 331 | |
328 | 332 | $mysql_backup_file = $remote_path.DS.$mysqldump_file; |
329 | 333 | |
330 | - if (!file_exists($mysql_backup_file)) |
|
331 | - throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file)); |
|
334 | + if (!file_exists($mysql_backup_file)) { |
|
335 | + throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file)); |
|
336 | + } |
|
332 | 337 | |
333 | 338 | |
334 | 339 | /*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
@@ -360,16 +365,18 @@ discard block |
||
360 | 365 | // process the line read. |
361 | 366 | |
362 | 367 | //check if line is comment |
363 | - if (substr($line, 0, 1) == "#") |
|
364 | - continue; |
|
368 | + if (substr($line, 0, 1) == "#") { |
|
369 | + continue; |
|
370 | + } |
|
365 | 371 | |
366 | 372 | //check if line is empty |
367 | - if ($line == "\n" or trim($line) == "") |
|
368 | - continue; |
|
373 | + if ($line == "\n" or trim($line) == "") { |
|
374 | + continue; |
|
375 | + } |
|
369 | 376 | |
370 | - if (substr($line, strlen($line) - 2, strlen($line)) == ";\n") |
|
371 | - $query .= $line; |
|
372 | - else { |
|
377 | + if (substr($line, strlen($line) - 2, strlen($line)) == ";\n") { |
|
378 | + $query .= $line; |
|
379 | + } else { |
|
373 | 380 | $query .= $line; |
374 | 381 | continue; |
375 | 382 | } |
@@ -493,7 +500,7 @@ discard block |
||
493 | 500 | $tar->open($this->backup_storage_dir.DS.$backup_file, $start); |
494 | 501 | |
495 | 502 | $data = $tar->contents($this->process_files_limit_list); |
496 | - }catch (Exception $e) |
|
503 | + } catch (Exception $e) |
|
497 | 504 | { |
498 | 505 | $return['error'] = true; |
499 | 506 | $return['message'] = $e->getMessage(); |
@@ -528,8 +535,9 @@ discard block |
||
528 | 535 | |
529 | 536 | ++$return['part']; |
530 | 537 | |
531 | - if ($return['part'] < sizeof($backup_parts)) |
|
532 | - $return['finished'] = 0; |
|
538 | + if ($return['part'] < sizeof($backup_parts)) { |
|
539 | + $return['finished'] = 0; |
|
540 | + } |
|
533 | 541 | |
534 | 542 | } |
535 | 543 | } |
@@ -670,19 +678,22 @@ discard block |
||
670 | 678 | { |
671 | 679 | $config = file_get_contents($wp_config); |
672 | 680 | preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches); |
673 | - if (isset($matches[1])) |
|
674 | - $table_prefix = $matches[1]; |
|
675 | - else |
|
676 | - throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
681 | + if (isset($matches[1])) { |
|
682 | + $table_prefix = $matches[1]; |
|
683 | + } else { |
|
684 | + throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
685 | + } |
|
686 | + } else { |
|
687 | + throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
677 | 688 | } |
678 | - else |
|
679 | - throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
680 | 689 | |
681 | - if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
682 | - throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
690 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) { |
|
691 | + throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
692 | + } |
|
683 | 693 | |
684 | - if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
685 | - throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
694 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) { |
|
695 | + throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
696 | + } |
|
686 | 697 | |
687 | 698 | return true; |
688 | 699 | } |
@@ -720,8 +731,9 @@ discard block |
||
720 | 731 | |
721 | 732 | $this->logger->info(sprintf('Updating wp-config.php file with the new mysql details')); |
722 | 733 | |
723 | - if (!file_put_contents($wp_config, $content)) |
|
724 | - throw new Exception("Could not write updated config data to ".$wp_config); |
|
734 | + if (!file_put_contents($wp_config, $content)) { |
|
735 | + throw new Exception("Could not write updated config data to ".$wp_config); |
|
736 | + } |
|
725 | 737 | |
726 | 738 | chmod($wp_config, $file_perms); |
727 | 739 | |
@@ -766,10 +778,11 @@ discard block |
||
766 | 778 | $mysqldump_list[$file['path']]['size'] = $file['size']; |
767 | 779 | $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i", $file['timestamp']); |
768 | 780 | |
769 | - if ($hash and $hash == $matches[1]) |
|
770 | - $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
771 | - else |
|
772 | - $mysqldump_list[$file['path']]['selected'] = ""; |
|
781 | + if ($hash and $hash == $matches[1]) { |
|
782 | + $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
783 | + } else { |
|
784 | + $mysqldump_list[$file['path']]['selected'] = ""; |
|
785 | + } |
|
773 | 786 | } |
774 | 787 | } |
775 | 788 | } |
@@ -790,13 +803,15 @@ discard block |
||
790 | 803 | */ |
791 | 804 | private function get_hash_from_backup($backup_file) |
792 | 805 | { |
793 | - if (!$backup_file) |
|
794 | - return false; |
|
806 | + if (!$backup_file) { |
|
807 | + return false; |
|
808 | + } |
|
795 | 809 | |
796 | 810 | $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file) - 10, strlen($backup_file)), $matches); |
797 | 811 | |
798 | - if ($result and isset($matches[1])) |
|
799 | - return ($matches[1]); |
|
812 | + if ($result and isset($matches[1])) { |
|
813 | + return ($matches[1]); |
|
814 | + } |
|
800 | 815 | |
801 | 816 | return false; |
802 | 817 | } |
@@ -821,10 +836,11 @@ discard block |
||
821 | 836 | if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
822 | 837 | { |
823 | 838 | $lines = explode(PHP_EOL, $this->filesystem->read($file_info['path'])); |
824 | - foreach ($lines as $line) |
|
825 | - if ($line) |
|
839 | + foreach ($lines as $line) { |
|
840 | + if ($line) |
|
826 | 841 | { |
827 | 842 | $data = str_getcsv($line); |
843 | + } |
|
828 | 844 | if (is_array($data)) { |
829 | 845 | $parents[$data[0]] = $file_info['path']; |
830 | 846 | $file_info['childs'][] = $data; |
@@ -834,20 +850,22 @@ discard block |
||
834 | 850 | |
835 | 851 | } |
836 | 852 | |
837 | - if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
838 | - $backup_files[$file_info['path']] = $file_info; |
|
853 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
854 | + $backup_files[$file_info['path']] = $file_info; |
|
855 | + } |
|
839 | 856 | } |
840 | 857 | |
841 | 858 | $new_list = array(); |
842 | 859 | |
843 | 860 | foreach ($backup_files as $key=>$file_info) |
844 | 861 | { |
845 | - if (isset($parents[$file_info['path']])) |
|
846 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
847 | - else { |
|
862 | + if (isset($parents[$file_info['path']])) { |
|
863 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
864 | + } else { |
|
848 | 865 | |
849 | - if ($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
850 | - $file_info['selected'] = 'selected'; |
|
866 | + if ($local_backup_file and ($file_info['basename'] == $local_backup_file)) { |
|
867 | + $file_info['selected'] = 'selected'; |
|
868 | + } |
|
851 | 869 | |
852 | 870 | $this->logger->info(sprintf('Found %s backup file', $file_info['path'])); |
853 | 871 | |
@@ -894,8 +912,9 @@ discard block |
||
894 | 912 | $backup_archive = new Tar(); |
895 | 913 | if ($this->is_multipart($backup_file)) |
896 | 914 | { |
897 | - if (!$return['part']) |
|
898 | - $return['processed'] += $this->filesystem->getSize($backup_file); |
|
915 | + if (!$return['part']) { |
|
916 | + $return['processed'] += $this->filesystem->getSize($backup_file); |
|
917 | + } |
|
899 | 918 | |
900 | 919 | $backup_parts = $this->get_multipart_files($backup_file); |
901 | 920 | $backup_file = $backup_parts[$return['part']]; |
@@ -915,10 +934,11 @@ discard block |
||
915 | 934 | } |
916 | 935 | } |
917 | 936 | |
918 | - if (isset($data['start'])) |
|
919 | - //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
937 | + if (isset($data['start'])) { |
|
938 | + //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
920 | 939 | { |
921 | 940 | $return['finished'] = 0; |
941 | + } |
|
922 | 942 | $return['start'] = $data['start']; |
923 | 943 | } else { |
924 | 944 | |
@@ -930,14 +950,16 @@ discard block |
||
930 | 950 | |
931 | 951 | ++$return['part']; |
932 | 952 | |
933 | - if ($return['part'] < sizeof($backup_parts)) |
|
934 | - $return['finished'] = 0; |
|
953 | + if ($return['part'] < sizeof($backup_parts)) { |
|
954 | + $return['finished'] = 0; |
|
955 | + } |
|
935 | 956 | |
936 | 957 | } |
937 | 958 | } |
938 | 959 | |
939 | - if ($return['finished']) |
|
940 | - $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
960 | + if ($return['finished']) { |
|
961 | + $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
962 | + } |
|
941 | 963 | |
942 | 964 | $return['backup_file'] = $backup_file; |
943 | 965 | |
@@ -969,8 +991,7 @@ discard block |
||
969 | 991 | $return['remote_mysql_user'] = $wpdb->dbuser; |
970 | 992 | $return['remote_mysql_pass'] = $wpdb->dbpassword; |
971 | 993 | $return['remote_mysql_db'] = $wpdb->dbname; |
972 | - } |
|
973 | - else { |
|
994 | + } else { |
|
974 | 995 | $return['dir'] = ($pathinfo['dirname']).DS.$suffix; |
975 | 996 | $return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix; |
976 | 997 | } |
@@ -989,11 +1010,13 @@ discard block |
||
989 | 1010 | { |
990 | 1011 | //check if i can write |
991 | 1012 | $tmp_file = md5(time()); |
992 | - if (!file_put_contents($tmp_file, "++")) |
|
993 | - throw new Exception("Could not write to new host"); |
|
1013 | + if (!file_put_contents($tmp_file, "++")) { |
|
1014 | + throw new Exception("Could not write to new host"); |
|
1015 | + } |
|
994 | 1016 | |
995 | - if (!unlink($tmp_file)) |
|
996 | - throw new Exception("Could not delete temporary file from new host"); |
|
1017 | + if (!unlink($tmp_file)) { |
|
1018 | + throw new Exception("Could not delete temporary file from new host"); |
|
1019 | + } |
|
997 | 1020 | |
998 | 1021 | $max_upload = $this->return_bytes((ini_get('upload_max_filesize'))); |
999 | 1022 | $max_post = $this->return_bytes((ini_get('post_max_size'))); |
@@ -1037,8 +1060,9 @@ discard block |
||
1037 | 1060 | */ |
1038 | 1061 | public function is_multipart($backup_name) |
1039 | 1062 | { |
1040 | - if (stristr($backup_name, "-multipart")) |
|
1041 | - return true; |
|
1063 | + if (stristr($backup_name, "-multipart")) { |
|
1064 | + return true; |
|
1065 | + } |
|
1042 | 1066 | |
1043 | 1067 | return false; |
1044 | 1068 | } |
@@ -1056,8 +1080,9 @@ discard block |
||
1056 | 1080 | if ($this->is_multipart($backup_name)) |
1057 | 1081 | { |
1058 | 1082 | $backup_parts = $this->get_multipart_files($backup_name); |
1059 | - foreach ($backup_parts as $part_file) |
|
1060 | - $backup_size += $this->filesystem->getSize($part_file); |
|
1083 | + foreach ($backup_parts as $part_file) { |
|
1084 | + $backup_size += $this->filesystem->getSize($part_file); |
|
1085 | + } |
|
1061 | 1086 | } |
1062 | 1087 | |
1063 | 1088 | return $backup_size; |
@@ -1119,15 +1144,13 @@ discard block |
||
1119 | 1144 | if ($direction == 'desc') { |
1120 | 1145 | if ($a > $b) { |
1121 | 1146 | return -1; |
1122 | - } |
|
1123 | - else { |
|
1147 | + } else { |
|
1124 | 1148 | return 1; |
1125 | 1149 | } |
1126 | 1150 | } else { |
1127 | 1151 | if ($a < $b) { |
1128 | 1152 | return -1; |
1129 | - } |
|
1130 | - else { |
|
1153 | + } else { |
|
1131 | 1154 | return 1; |
1132 | 1155 | } |
1133 | 1156 | } |
@@ -1157,7 +1180,7 @@ discard block |
||
1157 | 1180 | { |
1158 | 1181 | $return['statusText'] = $response['message']; |
1159 | 1182 | $return['error'] = true; |
1160 | - }elseif ($status != 200 and $status != 418) |
|
1183 | + } elseif ($status != 200 and $status != 418) |
|
1161 | 1184 | { |
1162 | 1185 | $return['error'] = true; |
1163 | 1186 | $return['message'] = $response; |
@@ -1181,8 +1204,9 @@ discard block |
||
1181 | 1204 | return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function($m) { |
1182 | 1205 | $data = ""; |
1183 | 1206 | |
1184 | - if (!isset($m[3])) |
|
1185 | - $m[3] = ""; |
|
1207 | + if (!isset($m[3])) { |
|
1208 | + $m[3] = ""; |
|
1209 | + } |
|
1186 | 1210 | |
1187 | 1211 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
1188 | 1212 | //return $this->unescape_quotes($data); |
@@ -28,13 +28,8 @@ |
||
28 | 28 | |
29 | 29 | use League\Flysystem\Config; |
30 | 30 | use League\Flysystem\Filesystem; |
31 | -use League\Flysystem\Util; |
|
32 | 31 | use League\Flysystem\Adapter\Local; |
33 | - |
|
34 | 32 | use splitbrain\PHPArchive\Tar; |
35 | -use splitbrain\PHPArchive\Zip; |
|
36 | -use splitbrain\PHPArchive\Archive; |
|
37 | -use splitbrain\PHPArchive\FileInfo; |
|
38 | 33 | |
39 | 34 | |
40 | 35 | /** |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->xcloner_remote_storage = $xcloner_container->get_xcloner_remote_storage(); |
90 | 90 | |
91 | 91 | if (isset($_POST['API_ID'])) { |
92 | - $this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), |
|
92 | + $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), |
|
93 | 93 | 0, 15)); |
94 | 94 | } |
95 | 95 | |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | |
132 | 132 | |
133 | 133 | $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
134 | - $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database"; |
|
135 | - $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql"; |
|
134 | + $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
135 | + $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
136 | 136 | |
137 | 137 | try { |
138 | 138 | $this->xcloner_database->init($data); |
139 | 139 | |
140 | - } catch (Exception $e) { |
|
140 | + }catch (Exception $e) { |
|
141 | 141 | |
142 | 142 | $this->send_response($e->getMessage()); |
143 | 143 | $this->logger->error($e->getMessage()); |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | } else { |
224 | 224 | |
225 | 225 | $schedule['status'] = 1; |
226 | - $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
|
227 | - " " . $this->form_params['backup_params']['schedule_start_time']); |
|
226 | + $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date']. |
|
227 | + " ".$this->form_params['backup_params']['schedule_start_time']); |
|
228 | 228 | |
229 | 229 | if ($schedule['start_at'] <= time()) { |
230 | 230 | $schedule['start_at'] = ""; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | if (!isset($_POST['id'])) { |
251 | 251 | $wpdb->insert( |
252 | - $wpdb->prefix . 'xcloner_scheduler', |
|
252 | + $wpdb->prefix.'xcloner_scheduler', |
|
253 | 253 | $schedule, |
254 | 254 | array( |
255 | 255 | '%s', |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | ); |
259 | 259 | } else { |
260 | 260 | $wpdb->update( |
261 | - $wpdb->prefix . 'xcloner_scheduler', |
|
261 | + $wpdb->prefix.'xcloner_scheduler', |
|
262 | 262 | $schedule, |
263 | 263 | array('id' => $_POST['id']), |
264 | 264 | array( |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | try { |
310 | 310 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], |
311 | 311 | $this->form_params['extra'], $init); |
312 | - } catch (Exception $e) { |
|
312 | + }catch (Exception $e) { |
|
313 | 313 | $return = array(); |
314 | 314 | $return['error'] = true; |
315 | 315 | $return['status'] = 500; |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $additional['lines_total'] = $return['extra']['lines_total']; |
337 | 337 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], |
338 | 338 | $this->form_params, "", $additional); |
339 | - } catch (Exception $e) { |
|
339 | + }catch (Exception $e) { |
|
340 | 340 | $this->logger->error($e->getMessage()); |
341 | 341 | } |
342 | 342 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | if (isset($params->backup_params)) { |
431 | 431 | foreach ($params->backup_params as $param) { |
432 | 432 | $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value); |
433 | - $this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array( |
|
433 | + $this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array( |
|
434 | 434 | 'POST', |
435 | 435 | 'fields filter' |
436 | 436 | )); |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | if (isset($params->table_params)) { |
443 | 443 | foreach ($params->table_params as $param) { |
444 | 444 | $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id); |
445 | - $this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array( |
|
445 | + $this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array( |
|
446 | 446 | 'POST', |
447 | 447 | 'database filter' |
448 | 448 | )); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | if (!in_array($param->parent, $this->form_params['excluded_files'])) { |
462 | 462 | //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
463 | 463 | $unique_exclude_files[] = $param->id; |
464 | - $this->logger->debug("Adding file filter " . $param->id . "\n", array( |
|
464 | + $this->logger->debug("Adding file filter ".$param->id."\n", array( |
|
465 | 465 | 'POST', |
466 | 466 | 'exclude files filter' |
467 | 467 | )); |
@@ -509,13 +509,13 @@ discard block |
||
509 | 509 | 'text' => $this->xcloner_settings->get_xcloner_start_path(), |
510 | 510 | //'children' => true, |
511 | 511 | 'state' => array('selected' => false, 'opened' => true), |
512 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png" |
|
512 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-root.png" |
|
513 | 513 | ); |
514 | 514 | } |
515 | 515 | |
516 | 516 | try { |
517 | 517 | $files = $this->xcloner_file_system->list_directory($folder); |
518 | - } catch (Exception $e) { |
|
518 | + }catch (Exception $e) { |
|
519 | 519 | |
520 | 520 | print $e->getMessage(); |
521 | 521 | $this->logger->error($e->getMessage()); |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | if ($file['type'] == "dir") { |
537 | 537 | $children = true; |
538 | 538 | } else { |
539 | - $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")"; |
|
539 | + $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")"; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | if ($this->xcloner_file_system->is_excluded($file)) { |
@@ -552,8 +552,8 @@ discard block |
||
552 | 552 | //'title' => "test", |
553 | 553 | 'children' => $children, |
554 | 554 | 'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected), |
555 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'], |
|
556 | - 0, 1)) . ".png" |
|
555 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-".strtolower(substr($file['type'], |
|
556 | + 0, 1)).".png" |
|
557 | 557 | ); |
558 | 558 | } |
559 | 559 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | if ($database == "#") { |
580 | 580 | try { |
581 | 581 | $return = $this->xcloner_database->get_all_databases(); |
582 | - } catch (Exception $e) { |
|
582 | + }catch (Exception $e) { |
|
583 | 583 | $this->logger->error($e->getMessage()); |
584 | 584 | } |
585 | 585 | |
@@ -600,10 +600,10 @@ discard block |
||
600 | 600 | $data[] = array( |
601 | 601 | 'id' => $database['name'], |
602 | 602 | 'parent' => '#', |
603 | - 'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")", |
|
603 | + 'text' => $database['name']." (".(int)$database['num_tables'].")", |
|
604 | 604 | 'children' => true, |
605 | 605 | 'state' => $state, |
606 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png" |
|
606 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/database-icon.png" |
|
607 | 607 | ); |
608 | 608 | } |
609 | 609 | |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | |
612 | 612 | try { |
613 | 613 | $return = $this->xcloner_database->list_tables($database, "", 1); |
614 | - } catch (Exception $e) { |
|
614 | + }catch (Exception $e) { |
|
615 | 615 | $this->logger->error($e->getMessage()); |
616 | 616 | } |
617 | 617 | |
@@ -628,12 +628,12 @@ discard block |
||
628 | 628 | } |
629 | 629 | |
630 | 630 | $data[] = array( |
631 | - 'id' => $database . "." . $table['name'], |
|
631 | + 'id' => $database.".".$table['name'], |
|
632 | 632 | 'parent' => $database, |
633 | - 'text' => $table['name'] . " (" . (int)$table['records'] . ")", |
|
633 | + 'text' => $table['name']." (".(int)$table['records'].")", |
|
634 | 634 | 'children' => false, |
635 | 635 | 'state' => $state, |
636 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png" |
|
636 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/table-icon.png" |
|
637 | 637 | ); |
638 | 638 | } |
639 | 639 | } |
@@ -677,17 +677,17 @@ discard block |
||
677 | 677 | $return['data'] = array(); |
678 | 678 | |
679 | 679 | foreach ($data as $res) { |
680 | - $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
|
681 | - <a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
|
680 | + $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
|
681 | + <a href=\"#" . $res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
|
682 | 682 | if ($res->status) { |
683 | 683 | $status = '<i class="material-icons active status">timer</i>'; |
684 | 684 | } else { |
685 | 685 | $status = '<i class="material-icons status inactive">timer_off</i>'; |
686 | 686 | } |
687 | 687 | |
688 | - $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id)); |
|
688 | + $next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)); |
|
689 | 689 | |
690 | - $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time); |
|
690 | + $next_run = date(get_option('date_format')." ".get_option('time_format'), $next_run_time); |
|
691 | 691 | |
692 | 692 | $remote_storage = $res->remote_storage; |
693 | 693 | |
@@ -696,16 +696,16 @@ discard block |
||
696 | 696 | } |
697 | 697 | |
698 | 698 | if (trim($next_run)) { |
699 | - $date_text = date(get_option('date_format') . " " . get_option('time_format'), |
|
699 | + $date_text = date(get_option('date_format')." ".get_option('time_format'), |
|
700 | 700 | $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
701 | 701 | |
702 | 702 | if ($next_run_time >= time()) { |
703 | - $next_run = "in " . human_time_diff($next_run_time, time()); |
|
703 | + $next_run = "in ".human_time_diff($next_run_time, time()); |
|
704 | 704 | } else { |
705 | 705 | $next_run = __("executed", 'xcloner-backup-and-restore'); |
706 | 706 | } |
707 | 707 | |
708 | - $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>"; |
|
708 | + $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>"; |
|
709 | 709 | //$next_run .=" ($date_text)"; |
710 | 710 | } |
711 | 711 | |
@@ -717,11 +717,11 @@ discard block |
||
717 | 717 | if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) { |
718 | 718 | $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup); |
719 | 719 | $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup)); |
720 | - $backup_time = date(get_option('date_format') . " " . get_option('time_format'), |
|
720 | + $backup_time = date(get_option('date_format')." ".get_option('time_format'), |
|
721 | 721 | $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
722 | 722 | } |
723 | 723 | |
724 | - $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>"; |
|
724 | + $backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>"; |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | $schedules = wp_get_schedules(); |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | $return['data'][] = array( |
734 | 734 | $res->id, |
735 | 735 | $res->name, |
736 | - $res->recurrence,/*$res->start_at,*/ |
|
736 | + $res->recurrence, /*$res->start_at,*/ |
|
737 | 737 | $next_run, |
738 | 738 | $remote_storage, |
739 | 739 | $backup_text, |
@@ -795,25 +795,25 @@ discard block |
||
795 | 795 | $this->process_params($params); |
796 | 796 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($this->form_params['extra']['backup_parent']); |
797 | 797 | |
798 | - if(isset($this->form_params['extra']['start'])) { |
|
798 | + if (isset($this->form_params['extra']['start'])) { |
|
799 | 799 | $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']); |
800 | - }else{ |
|
800 | + } else { |
|
801 | 801 | $start = 0; |
802 | 802 | } |
803 | 803 | |
804 | - if(isset($this->form_params['extra']['iv'])) { |
|
804 | + if (isset($this->form_params['extra']['iv'])) { |
|
805 | 805 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']); |
806 | - }else{ |
|
806 | + } else { |
|
807 | 807 | $iv = ""; |
808 | 808 | } |
809 | 809 | |
810 | - if(isset($this->form_params['extra']['part'])) { |
|
810 | + if (isset($this->form_params['extra']['part'])) { |
|
811 | 811 | $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']); |
812 | - }else{ |
|
812 | + } else { |
|
813 | 813 | $return['part'] = 0; |
814 | 814 | } |
815 | 815 | |
816 | - }else{ |
|
816 | + } else { |
|
817 | 817 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
818 | 818 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
819 | 819 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
@@ -828,14 +828,14 @@ discard block |
||
828 | 828 | } |
829 | 829 | |
830 | 830 | $return['processing_file'] = $backup_file; |
831 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
831 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
832 | 832 | |
833 | 833 | try { |
834 | 834 | $this->logger->info(json_encode($_POST)); |
835 | 835 | $this->logger->info($iv); |
836 | 836 | $return = array_merge($return, |
837 | 837 | $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv))); |
838 | - }catch(\Exception $e){ |
|
838 | + }catch (\Exception $e) { |
|
839 | 839 | $return['error'] = true; |
840 | 840 | $return['message'] = $e->getMessage(); |
841 | 841 | $return['error_message'] = $e->getMessage(); |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | |
844 | 844 | //echo strlen($return['iv']);exit; |
845 | 845 | |
846 | - if($return['finished']) { |
|
846 | + if ($return['finished']) { |
|
847 | 847 | if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
848 | 848 | $return['start'] = 0; |
849 | 849 | |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | } |
858 | 858 | |
859 | 859 | if (isset($_POST['data'])) { |
860 | - $return['extra'] = array_merge($this->form_params['extra'], $return); |
|
860 | + $return['extra'] = array_merge($this->form_params['extra'], $return); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | $this->send_response($return, 0); |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
877 | 877 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
878 | 878 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
879 | - $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']);; |
|
879 | + $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']); ; |
|
880 | 880 | $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
881 | 881 | |
882 | 882 | $backup_file = $source_backup_file; |
@@ -887,17 +887,17 @@ discard block |
||
887 | 887 | } |
888 | 888 | |
889 | 889 | $return['processing_file'] = $backup_file; |
890 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
890 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
891 | 891 | |
892 | 892 | try { |
893 | 893 | $return = array_merge($return, |
894 | 894 | $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv))); |
895 | - }catch(\Exception $e){ |
|
895 | + }catch (\Exception $e) { |
|
896 | 896 | $return['error'] = true; |
897 | 897 | $return['message'] = $e->getMessage(); |
898 | 898 | } |
899 | 899 | |
900 | - if($return['finished']) { |
|
900 | + if ($return['finished']) { |
|
901 | 901 | if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
902 | 902 | $return['start'] = 0; |
903 | 903 | |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | foreach ($backup_list as $file_info):?> |
930 | 930 | <?php |
931 | 931 | if ($storage_selection == "gdrive") { |
932 | - $file_info['path'] = $file_info['filename'] . "." . $file_info['extension']; |
|
932 | + $file_info['path'] = $file_info['filename'].".".$file_info['extension']; |
|
933 | 933 | } |
934 | 934 | $file_exists_on_local_storage = true; |
935 | 935 | |
@@ -1050,10 +1050,10 @@ discard block |
||
1050 | 1050 | <?php endif ?> |
1051 | 1051 | <?php |
1052 | 1052 | $basename = $file_info['basename']; |
1053 | - if(isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1053 | + if (isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1054 | 1054 | $basename = $file_info['childs'][0][0]; |
1055 | 1055 | ?> |
1056 | - <?php if($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
|
1056 | + <?php if ($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
|
1057 | 1057 | <a href="#<?php echo $file_info['basename'] ?>" class="backup-decryption" |
1058 | 1058 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
1059 | 1059 | <i class="material-icons">enhanced_encryption</i> |
@@ -1110,7 +1110,7 @@ discard block |
||
1110 | 1110 | $backup_file = $backup_parts[$return['part']]; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - if($this->xcloner_encryption->is_encrypted_file($backup_file)) { |
|
1113 | + if ($this->xcloner_encryption->is_encrypted_file($backup_file)) { |
|
1114 | 1114 | $return['error'] = true; |
1115 | 1115 | $return['message'] = __("Backup archive is encrypted, please decrypt it first before you can list it's content.", "xcloner-backup-and-restore"); |
1116 | 1116 | $this->send_response($return, 0); |
@@ -1118,10 +1118,10 @@ discard block |
||
1118 | 1118 | |
1119 | 1119 | try { |
1120 | 1120 | $tar = new Tar(); |
1121 | - $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start); |
|
1121 | + $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
|
1122 | 1122 | |
1123 | 1123 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
1124 | - } catch (Exception $e) { |
|
1124 | + }catch (Exception $e) { |
|
1125 | 1125 | $return['error'] = true; |
1126 | 1126 | $return['message'] = $e->getMessage(); |
1127 | 1127 | $this->send_response($return, 0); |
@@ -1129,14 +1129,14 @@ discard block |
||
1129 | 1129 | |
1130 | 1130 | $return['files'] = array(); |
1131 | 1131 | $return['finished'] = 1; |
1132 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
1132 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
1133 | 1133 | $i = 0; |
1134 | 1134 | |
1135 | 1135 | if (isset($data['extracted_files']) and is_array($data['extracted_files'])) { |
1136 | 1136 | foreach ($data['extracted_files'] as $file) { |
1137 | 1137 | $return['files'][$i]['path'] = $file->getPath(); |
1138 | 1138 | $return['files'][$i]['size'] = $file->getSize(); |
1139 | - $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'), |
|
1139 | + $return['files'][$i]['mtime'] = date(get_option('date_format')." ".get_option('time_format'), |
|
1140 | 1140 | $file->getMtime()); |
1141 | 1141 | |
1142 | 1142 | $i++; |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | "copy_backup_remote_to_local" |
1185 | 1185 | ), array($backup_file, $storage_type)); |
1186 | 1186 | } |
1187 | - } catch (Exception $e) { |
|
1187 | + }catch (Exception $e) { |
|
1188 | 1188 | |
1189 | 1189 | $return['error'] = 1; |
1190 | 1190 | $return['message'] = $e->getMessage(); |
@@ -1223,7 +1223,7 @@ discard block |
||
1223 | 1223 | "upload_backup_to_storage" |
1224 | 1224 | ), array($backup_file, $storage_type)); |
1225 | 1225 | } |
1226 | - } catch (Exception $e) { |
|
1226 | + }catch (Exception $e) { |
|
1227 | 1227 | |
1228 | 1228 | $return['error'] = 1; |
1229 | 1229 | $return['message'] = $e->getMessage(); |
@@ -1283,21 +1283,21 @@ discard block |
||
1283 | 1283 | $phar2->setStub($phar2->createDefaultStub('vendor/autoload.php', 'vendor/autoload.php')); |
1284 | 1284 | * */ |
1285 | 1285 | |
1286 | - $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz"; |
|
1286 | + $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path().DS."xcloner-restore.tgz"; |
|
1287 | 1287 | |
1288 | 1288 | $tar = new Tar(); |
1289 | 1289 | $tar->create($tmp_file); |
1290 | 1290 | |
1291 | - $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar"); |
|
1291 | + $tar->addFile(dirname(__DIR__)."/restore/vendor.build.txt", "vendor.phar"); |
|
1292 | 1292 | //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz"); |
1293 | 1293 | |
1294 | 1294 | $files = $xcloner_plugin_filesystem->listContents("vendor/", true); |
1295 | 1295 | foreach ($files as $file) { |
1296 | - $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']); |
|
1296 | + $tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | - $content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php"); |
|
1300 | - $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content); |
|
1299 | + $content = file_get_contents(dirname(__DIR__)."/restore/xcloner_restore.php"); |
|
1300 | + $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '".md5(AUTH_KEY)."');", $content); |
|
1301 | 1301 | |
1302 | 1302 | $tar->addData("xcloner_restore.php", $content); |
1303 | 1303 | |
@@ -1306,11 +1306,11 @@ discard block |
||
1306 | 1306 | if (file_exists($tmp_file)) { |
1307 | 1307 | header('Content-Description: File Transfer'); |
1308 | 1308 | header('Content-Type: application/octet-stream'); |
1309 | - header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"'); |
|
1309 | + header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"'); |
|
1310 | 1310 | header('Expires: 0'); |
1311 | 1311 | header('Cache-Control: must-revalidate'); |
1312 | 1312 | header('Pragma: public'); |
1313 | - header('Content-Length: ' . filesize($tmp_file)); |
|
1313 | + header('Content-Length: '.filesize($tmp_file)); |
|
1314 | 1314 | readfile($tmp_file); |
1315 | 1315 | |
1316 | 1316 | } |
@@ -1342,9 +1342,9 @@ discard block |
||
1342 | 1342 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
1343 | 1343 | header('Cache-Control: private', false); |
1344 | 1344 | header('Content-Transfer-Encoding: binary'); |
1345 | - header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";'); |
|
1345 | + header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
|
1346 | 1346 | header('Content-Type: application/octet-stream'); |
1347 | - header('Content-Length: ' . $metadata['size']); |
|
1347 | + header('Content-Length: '.$metadata['size']); |
|
1348 | 1348 | |
1349 | 1349 | @ob_end_clean(); |
1350 | 1350 | |
@@ -1404,12 +1404,12 @@ discard block |
||
1404 | 1404 | $xcloner_file_transfer->set_target($target_url); |
1405 | 1405 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
1406 | 1406 | |
1407 | - } catch (Exception $e) { |
|
1407 | + }catch (Exception $e) { |
|
1408 | 1408 | |
1409 | 1409 | $return = array(); |
1410 | 1410 | $return['error'] = true; |
1411 | 1411 | $return['status'] = 500; |
1412 | - $return['message'] = "CURL communication error with the restore host. " . $e->getMessage(); |
|
1412 | + $return['message'] = "CURL communication error with the restore host. ".$e->getMessage(); |
|
1413 | 1413 | $this->send_response($return, 0); |
1414 | 1414 | |
1415 | 1415 | } |
@@ -1433,7 +1433,7 @@ discard block |
||
1433 | 1433 | $this->check_access(); |
1434 | 1434 | |
1435 | 1435 | define("XCLONER_PLUGIN_ACCESS", 1); |
1436 | - include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php"); |
|
1436 | + include_once(dirname(__DIR__).DS."restore".DS."xcloner_restore.php"); |
|
1437 | 1437 | |
1438 | 1438 | return; |
1439 | 1439 | } |
@@ -797,23 +797,23 @@ discard block |
||
797 | 797 | |
798 | 798 | if(isset($this->form_params['extra']['start'])) { |
799 | 799 | $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']); |
800 | - }else{ |
|
800 | + } else{ |
|
801 | 801 | $start = 0; |
802 | 802 | } |
803 | 803 | |
804 | 804 | if(isset($this->form_params['extra']['iv'])) { |
805 | 805 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']); |
806 | - }else{ |
|
806 | + } else{ |
|
807 | 807 | $iv = ""; |
808 | 808 | } |
809 | 809 | |
810 | 810 | if(isset($this->form_params['extra']['part'])) { |
811 | 811 | $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']); |
812 | - }else{ |
|
812 | + } else{ |
|
813 | 813 | $return['part'] = 0; |
814 | 814 | } |
815 | 815 | |
816 | - }else{ |
|
816 | + } else{ |
|
817 | 817 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
818 | 818 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
819 | 819 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | $this->logger->info($iv); |
836 | 836 | $return = array_merge($return, |
837 | 837 | $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv))); |
838 | - }catch(\Exception $e){ |
|
838 | + } catch(\Exception $e){ |
|
839 | 839 | $return['error'] = true; |
840 | 840 | $return['message'] = $e->getMessage(); |
841 | 841 | $return['error_message'] = $e->getMessage(); |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | try { |
893 | 893 | $return = array_merge($return, |
894 | 894 | $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv))); |
895 | - }catch(\Exception $e){ |
|
895 | + } catch(\Exception $e){ |
|
896 | 896 | $return['error'] = true; |
897 | 897 | $return['message'] = $e->getMessage(); |
898 | 898 | } |
@@ -994,7 +994,8 @@ discard block |
||
994 | 994 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
995 | 995 | <i class="material-icons">enhanced_encryption</i> |
996 | 996 | </a> |
997 | - <?php else: ?> |
|
997 | + <?php else { |
|
998 | + : ?> |
|
998 | 999 | <a href="#<?php echo $child[0] ?>" class="list-backup-content" |
999 | 1000 | title="<?php echo __('List Backup Content', |
1000 | 1001 | 'xcloner-backup-and-restore') ?>"><i |
@@ -1013,7 +1014,9 @@ discard block |
||
1013 | 1014 | class="material-icons">file_upload</i></a> |
1014 | 1015 | <?php endif ?> |
1015 | 1016 | </li> |
1016 | - <?php endforeach; ?> |
|
1017 | + <?php endforeach; |
|
1018 | +} |
|
1019 | +?> |
|
1017 | 1020 | </ul> |
1018 | 1021 | <?php endif; ?> |
1019 | 1022 | <?php |
@@ -1021,11 +1024,12 @@ discard block |
||
1021 | 1024 | ob_end_clean(); |
1022 | 1025 | ?> |
1023 | 1026 | <?php ob_start(); ?> |
1024 | - <?php if (isset($file_info['timestamp'])) |
|
1027 | + <?php if (isset($file_info['timestamp'])) { |
|
1025 | 1028 | echo date("Y-m-d H:i", $file_info['timestamp']) |
1026 | 1029 | ?> |
1027 | 1030 | <?php |
1028 | 1031 | $return['data'][$i][] = ob_get_contents(); |
1032 | +} |
|
1029 | 1033 | ob_end_clean(); |
1030 | 1034 | ?> |
1031 | 1035 | |
@@ -1050,15 +1054,17 @@ discard block |
||
1050 | 1054 | <?php endif ?> |
1051 | 1055 | <?php |
1052 | 1056 | $basename = $file_info['basename']; |
1053 | - if(isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1054 | - $basename = $file_info['childs'][0][0]; |
|
1057 | + if(isset($file_info['childs']) and sizeof($file_info['childs'])) { |
|
1058 | + $basename = $file_info['childs'][0][0]; |
|
1059 | + } |
|
1055 | 1060 | ?> |
1056 | 1061 | <?php if($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
1057 | 1062 | <a href="#<?php echo $file_info['basename'] ?>" class="backup-decryption" |
1058 | 1063 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
1059 | 1064 | <i class="material-icons">enhanced_encryption</i> |
1060 | 1065 | </a> |
1061 | - <?php else: ?> |
|
1066 | + <?php else { |
|
1067 | + : ?> |
|
1062 | 1068 | <a href="#<?php echo $file_info['basename'] ?>" class="list-backup-content" |
1063 | 1069 | title="<?php echo __('List Backup Content', 'xcloner-backup-and-restore') ?>"><i |
1064 | 1070 | class="material-icons">folder_open</i></a> |
@@ -1068,7 +1074,9 @@ discard block |
||
1068 | 1074 | <i class="material-icons">no_encryption</i> |
1069 | 1075 | </a> |
1070 | 1076 | <?php endif?> |
1071 | - <?php endif; ?> |
|
1077 | + <?php endif; |
|
1078 | +} |
|
1079 | +?> |
|
1072 | 1080 | |
1073 | 1081 | <a href="#<?php echo $file_info['basename'] ?>" class="delete" |
1074 | 1082 | title="<?php echo __('Delete Backup', 'xcloner-backup-and-restore') ?>"> |
@@ -28,7 +28,6 @@ |
||
28 | 28 | |
29 | 29 | use League\Flysystem\Config; |
30 | 30 | use League\Flysystem\Filesystem; |
31 | -use League\Flysystem\Util; |
|
32 | 31 | use League\Flysystem\Adapter\Local; |
33 | 32 | |
34 | 33 | /** |
@@ -37,857 +37,857 @@ discard block |
||
37 | 37 | class Xcloner_File_System |
38 | 38 | { |
39 | 39 | |
40 | - private $excluded_files = ""; |
|
41 | - private $additional_regex_patterns = array(); |
|
42 | - private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
43 | - private $included_files_handler = "backup_files.csv"; |
|
44 | - private $temp_dir_handler = ".dir"; |
|
45 | - public $filesystem; |
|
46 | - public $tmp_filesystem; |
|
47 | - public $storage_filesystem; |
|
48 | - private $xcloner_container; |
|
49 | - private $diff_timestamp_start = ""; |
|
50 | - |
|
51 | - private $logger; |
|
52 | - private $start_adapter; |
|
53 | - private $tmp_adapter; |
|
54 | - private $storage_adapter; |
|
55 | - private $xcloner_settings; |
|
56 | - private $start_filesystem; |
|
57 | - private $tmp_filesystem_append; |
|
58 | - private $storage_filesystem_append; |
|
59 | - |
|
60 | - private $files_counter; |
|
61 | - private $files_size; |
|
62 | - private $last_logged_file; |
|
63 | - private $folders_to_process_per_session = 25; |
|
64 | - private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted"); |
|
65 | - private $backup_name_tags = array('[time]', '[hostname]', '[domain]'); |
|
66 | - |
|
67 | - /** |
|
68 | - * Xcloner_File_System constructor. |
|
69 | - * @param Xcloner $xcloner_container |
|
70 | - * @param string $hash |
|
71 | - */ |
|
72 | - public function __construct(Xcloner $xcloner_container, $hash = "") |
|
73 | - { |
|
74 | - $this->xcloner_container = $xcloner_container; |
|
75 | - |
|
76 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system"); |
|
77 | - $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
78 | - |
|
79 | - try { |
|
80 | - |
|
81 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
82 | - $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
|
83 | - 'disable_asserts' => true, |
|
84 | - ])); |
|
85 | - |
|
86 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
87 | - $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
|
88 | - 'disable_asserts' => true, |
|
89 | - ])); |
|
90 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
91 | - $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
|
92 | - 'disable_asserts' => true, |
|
93 | - ])); |
|
94 | - |
|
95 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
96 | - $this->storage_filesystem = new Filesystem($adapter, new Config([ |
|
97 | - 'disable_asserts' => true, |
|
98 | - ])); |
|
99 | - |
|
100 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, |
|
101 | - 'SKIP_LINKS'); |
|
102 | - $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
|
103 | - 'disable_asserts' => true, |
|
104 | - ])); |
|
105 | - }catch (Exception $e) { |
|
106 | - $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - if ($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
111 | - $this->folders_to_process_per_session = $value; |
|
112 | - } |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Set differential timestamp date |
|
118 | - * @param string $timestamp |
|
119 | - */ |
|
120 | - public function set_diff_timestamp_start($timestamp = "") |
|
121 | - { |
|
122 | - if ($timestamp) { |
|
123 | - $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array( |
|
124 | - "FILESYSTEM", |
|
125 | - "DIFF" |
|
126 | - )); |
|
127 | - $this->diff_timestamp_start = $timestamp; |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Gets the differential timestamp date |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function get_diff_timestamp_start() |
|
136 | - { |
|
137 | - return $this->diff_timestamp_start; |
|
138 | - } |
|
139 | - |
|
140 | - private function get_xcloner_container() |
|
141 | - { |
|
142 | - return $this->xcloner_container; |
|
143 | - } |
|
144 | - |
|
145 | - public function set_hash($hash) |
|
146 | - { |
|
147 | - $this->xcloner_settings->set_hash($hash); |
|
148 | - } |
|
149 | - |
|
150 | - public function get_hash($hash) |
|
151 | - { |
|
152 | - $this->xcloner_settings->get_hash(); |
|
153 | - } |
|
154 | - |
|
155 | - public function get_tmp_filesystem() |
|
156 | - { |
|
157 | - return $this->tmp_filesystem; |
|
158 | - } |
|
159 | - |
|
160 | - public function get_storage_filesystem($remote_storage_selection = "") |
|
161 | - { |
|
162 | - if ($remote_storage_selection != "") { |
|
163 | - $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
164 | - $method = "get_".$remote_storage_selection."_filesystem"; |
|
165 | - |
|
166 | - if (!method_exists($remote_storage, $method)) { |
|
167 | - return false; |
|
168 | - } |
|
169 | - |
|
170 | - list($adapter, $filesystem) = $remote_storage->$method(); |
|
171 | - |
|
172 | - return $filesystem; |
|
173 | - } |
|
174 | - |
|
175 | - return $this->storage_filesystem; |
|
176 | - } |
|
177 | - |
|
178 | - public function get_tmp_filesystem_adapter() |
|
179 | - { |
|
180 | - return $this->tmp_adapter; |
|
181 | - } |
|
182 | - |
|
183 | - public function get_tmp_filesystem_append() |
|
184 | - { |
|
185 | - return $this->tmp_filesystem_append; |
|
186 | - } |
|
187 | - |
|
188 | - public function get_start_adapter() |
|
189 | - { |
|
190 | - return $this->start_adapter; |
|
191 | - } |
|
192 | - |
|
193 | - public function get_start_filesystem() |
|
194 | - { |
|
195 | - return $this->start_filesystem; |
|
196 | - } |
|
197 | - |
|
198 | - public function get_logger() |
|
199 | - { |
|
200 | - return $this->logger; |
|
201 | - } |
|
202 | - |
|
203 | - public function get_start_path_file_info($file) |
|
204 | - { |
|
205 | - $info = $this->getMetadataFull('start_adapter', $file); |
|
206 | - |
|
207 | - return $this->start_filesystem->normalizeFileInfo($info); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $file |
|
212 | - */ |
|
213 | - public function get_storage_path_file_info($file) |
|
214 | - { |
|
215 | - return $this->getMetadataFull('storage_adapter', $file); |
|
216 | - } |
|
217 | - |
|
218 | - public function get_included_files_handler($metadata = 0) |
|
219 | - { |
|
220 | - $path = $this->included_files_handler; |
|
221 | - if (!$metadata) { |
|
222 | - return $path; |
|
223 | - } |
|
224 | - |
|
225 | - $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
|
226 | - |
|
227 | - return $spl_info; |
|
228 | - |
|
229 | - } |
|
230 | - |
|
231 | - public function get_temp_dir_handler() |
|
232 | - { |
|
233 | - return $this->temp_dir_handler; |
|
234 | - } |
|
235 | - |
|
236 | - public function get_latest_backup() |
|
237 | - { |
|
238 | - $files = $this->get_backup_archives_list(); |
|
239 | - |
|
240 | - if (is_array($files)) { |
|
241 | - $this->sort_by($files, "timestamp", "desc"); |
|
242 | - } |
|
243 | - |
|
244 | - $new_list = array(); |
|
245 | - |
|
246 | - foreach ($files as $key => $file) { |
|
247 | - if (!isset($file['parent'])) { |
|
248 | - $new_list[] = ($files[$key]); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - if (isset($new_list[0])) { |
|
253 | - return $new_list[0]; |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - public function get_latest_backups() |
|
258 | - { |
|
259 | - $files = $this->get_backup_archives_list(); |
|
260 | - |
|
261 | - if (is_array($files)) { |
|
262 | - $this->sort_by($files, "timestamp", "desc"); |
|
263 | - } |
|
264 | - |
|
265 | - $new_list = array(); |
|
266 | - |
|
267 | - foreach ($files as $key => $file) { |
|
268 | - if (!isset($file['parent'])) { |
|
269 | - $new_list[] = ($files[$key]); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - return $new_list; |
|
274 | - } |
|
275 | - |
|
276 | - public function get_storage_usage() |
|
277 | - { |
|
278 | - $files = $this->get_backup_archives_list(); |
|
279 | - $total = 0; |
|
280 | - |
|
281 | - if (is_array($files)) { |
|
282 | - foreach ($files as $file) { |
|
283 | - $total += $file['size']; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - return $total; |
|
288 | - } |
|
289 | - |
|
290 | - public function is_part($backup_name) |
|
291 | - { |
|
292 | - if (stristr($backup_name, "-part")) { |
|
293 | - return true; |
|
294 | - } |
|
295 | - |
|
296 | - return false; |
|
297 | - } |
|
298 | - |
|
299 | - public function is_multipart($backup_name) |
|
300 | - { |
|
301 | - if (stristr($backup_name, "-multipart")) { |
|
302 | - return true; |
|
303 | - } |
|
304 | - |
|
305 | - return false; |
|
306 | - } |
|
307 | - |
|
308 | - public function get_backup_size($backup_name) |
|
309 | - { |
|
310 | - $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
|
311 | - if ($this->is_multipart($backup_name)) { |
|
312 | - $backup_parts = $this->get_multipart_files($backup_name); |
|
313 | - foreach ($backup_parts as $part_file) { |
|
314 | - $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
315 | - } |
|
316 | - } |
|
317 | - |
|
318 | - return $backup_size; |
|
319 | - } |
|
320 | - |
|
321 | - public function get_multipart_files($backup_name, $storage_selection = "") |
|
322 | - { |
|
323 | - $files = array(); |
|
324 | - |
|
325 | - if ($this->is_multipart($backup_name)) { |
|
326 | - $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
|
327 | - foreach ($lines as $line) { |
|
328 | - if ($line) { |
|
329 | - $data = str_getcsv($line); |
|
330 | - $files[] = $data[0]; |
|
331 | - } |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - return $files; |
|
336 | - } |
|
337 | - |
|
338 | - public function delete_backup_by_name($backup_name, $storage_selection = "") |
|
339 | - { |
|
340 | - if ($this->is_multipart($backup_name)) { |
|
341 | - $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
|
342 | - foreach ($lines as $line) { |
|
343 | - if ($line) { |
|
344 | - $data = str_getcsv($line); |
|
345 | - $this->get_storage_filesystem($storage_selection)->delete($data[0]); |
|
346 | - } |
|
347 | - } |
|
348 | - } |
|
349 | - |
|
350 | - if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) { |
|
351 | - $return = true; |
|
352 | - } else { |
|
353 | - $return = false; |
|
354 | - } |
|
355 | - |
|
356 | - return $return; |
|
357 | - } |
|
358 | - |
|
359 | - public function getMetadataFull($adapter = "storage_adapter", $path) |
|
360 | - { |
|
361 | - $location = $this->$adapter->applyPathPrefix($path); |
|
362 | - $spl_info = new SplFileInfo($location); |
|
363 | - |
|
364 | - return ($spl_info); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - public function get_backup_archives_list($storage_selection = "") |
|
369 | - { |
|
370 | - $list = array(); |
|
371 | - |
|
372 | - |
|
373 | - if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) { |
|
374 | - $list = $this->get_storage_filesystem($storage_selection)->listContents(); |
|
375 | - } |
|
376 | - |
|
377 | - $backup_files = array(); |
|
378 | - $parents = array(); |
|
379 | - |
|
380 | - foreach ($list as $file_info) { |
|
381 | - if (isset($file_info['extension']) and $file_info['extension'] == "csv") { |
|
382 | - $data = array(); |
|
383 | - |
|
384 | - $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path'])); |
|
385 | - foreach ($lines as $line) { |
|
386 | - if ($line) { |
|
387 | - $data = str_getcsv($line); |
|
388 | - if (is_array($data)) { |
|
389 | - $parents[$data[0]] = $file_info['basename']; |
|
390 | - $file_info['childs'][] = $data; |
|
391 | - $file_info['size'] += $data[2]; |
|
392 | - } |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - } |
|
397 | - |
|
398 | - if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], |
|
399 | - $this->backup_archive_extensions)) { |
|
400 | - $backup_files[$file_info['path']] = $file_info; |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - foreach ($backup_files as $key => $file_info) { |
|
405 | - if (!isset($backup_files[$key]['timestamp'])) { |
|
406 | - //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']); |
|
407 | - } |
|
408 | - |
|
409 | - if (isset($parents[$file_info['basename']])) { |
|
410 | - $backup_files[$key]['parent'] = $parents[$file_info['basename']]; |
|
411 | - } |
|
412 | - } |
|
413 | - |
|
414 | - return $backup_files; |
|
415 | - } |
|
416 | - |
|
417 | - public function start_file_recursion($init = 0) |
|
418 | - { |
|
419 | - if ($init) { |
|
420 | - $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), |
|
421 | - $this->xcloner_settings->get_xcloner_start_path())); |
|
422 | - $this->do_system_init(); |
|
423 | - } |
|
424 | - |
|
425 | - if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
426 | - //.dir exists, we presume we have files to iterate |
|
427 | - $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
|
428 | - $files = array_filter(explode("\n", $content)); |
|
429 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
430 | - |
|
431 | - $counter = 0; |
|
432 | - foreach ($files as $file) { |
|
433 | - if ($counter < $this->folders_to_process_per_session) { |
|
434 | - $this->build_files_list($file); |
|
435 | - $counter++; |
|
436 | - } else { |
|
437 | - $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
|
438 | - } |
|
439 | - } |
|
440 | - } else { |
|
441 | - $this->build_files_list(); |
|
442 | - } |
|
443 | - |
|
444 | - if ($this->scan_finished()) { |
|
445 | - $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
|
446 | - $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
447 | - $this->files_counter++; |
|
448 | - |
|
449 | - //adding included dump file to the included files list |
|
450 | - if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) { |
|
451 | - $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
|
452 | - $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
453 | - $this->files_counter++; |
|
454 | - } |
|
455 | - |
|
456 | - //adding a default index.html to the temp xcloner folder |
|
457 | - if (!$this->get_tmp_filesystem()->has("index.html")) { |
|
458 | - $this->get_tmp_filesystem()->write("index.html", ""); |
|
459 | - } |
|
460 | - |
|
461 | - //adding the default log file |
|
462 | - if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) { |
|
463 | - $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
|
464 | - $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
465 | - $this->files_counter++; |
|
466 | - } |
|
467 | - |
|
468 | - return false; |
|
469 | - } |
|
470 | - |
|
471 | - return true; |
|
472 | - } |
|
473 | - |
|
474 | - public function get_backup_attachments() |
|
475 | - { |
|
476 | - $return = array(); |
|
477 | - |
|
478 | - $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
|
479 | - if (file_exists($files_list_file)) { |
|
480 | - $return[] = $files_list_file; |
|
481 | - } |
|
482 | - |
|
483 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
484 | - $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
485 | - if (!file_exists($log_file)) { |
|
486 | - $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename(); |
|
487 | - } |
|
488 | - |
|
489 | - if (file_exists($log_file)) { |
|
490 | - $return[] = $log_file; |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - return $return; |
|
495 | - } |
|
496 | - |
|
497 | - public function remove_tmp_filesystem() |
|
498 | - { |
|
499 | - //delete the temporary folder |
|
500 | - $this->logger->debug(sprintf("Deleting the temporary storage folder %s", |
|
501 | - $this->xcloner_settings->get_xcloner_tmp_path())); |
|
502 | - |
|
503 | - $contents = $this->get_tmp_filesystem()->listContents(); |
|
504 | - |
|
505 | - if (is_array($contents)) { |
|
506 | - foreach ($contents as $file_info) { |
|
507 | - $this->get_tmp_filesystem()->delete($file_info['path']); |
|
508 | - } |
|
509 | - } |
|
510 | - |
|
511 | - @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
|
512 | - |
|
513 | - return; |
|
514 | - } |
|
515 | - |
|
516 | - public function cleanup_tmp_directories() |
|
517 | - { |
|
518 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
519 | - $tmp_filesystem = new Filesystem($adapter, new Config([ |
|
520 | - 'disable_asserts' => true, |
|
521 | - ])); |
|
522 | - |
|
523 | - $contents = $tmp_filesystem->listContents(); |
|
524 | - |
|
525 | - foreach ($contents as $file) { |
|
526 | - |
|
527 | - if (preg_match("/.xcloner-(.*)/", $file['path'])) { |
|
528 | - if ($file['timestamp'] < strtotime("-1days")) { |
|
529 | - $tmp_filesystem->deleteDir($file['path']); |
|
530 | - $this->logger->debug(sprintf("Delete temporary directory %s", $file['path'])); |
|
531 | - } |
|
532 | - } |
|
533 | - } |
|
534 | - |
|
535 | - return true; |
|
536 | - } |
|
537 | - |
|
538 | - private function do_system_init() |
|
539 | - { |
|
540 | - $this->files_counter = 0; |
|
541 | - |
|
542 | - if (!$this->storage_filesystem->has("index.html")) { |
|
543 | - $this->storage_filesystem->write("index.html", ""); |
|
544 | - } |
|
545 | - |
|
546 | - if (!$this->tmp_filesystem->has("index.html")) { |
|
547 | - $this->tmp_filesystem->write("index.html", ""); |
|
548 | - } |
|
549 | - |
|
550 | - if ($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
551 | - $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
552 | - } |
|
553 | - |
|
554 | - if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
555 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
556 | - } |
|
557 | - } |
|
558 | - |
|
559 | - public function get_scanned_files_num() |
|
560 | - { |
|
561 | - return $this->files_counter; |
|
562 | - } |
|
563 | - |
|
564 | - public function get_scanned_files_total_size() |
|
565 | - { |
|
566 | - return $this->files_size; |
|
567 | - } |
|
568 | - |
|
569 | - public function last_logged_file() |
|
570 | - { |
|
571 | - return $this->last_logged_file; |
|
572 | - } |
|
573 | - |
|
574 | - public static function is_regex($regex) |
|
575 | - { |
|
576 | - return preg_match("/^\^(.*)\$$/i", $regex); |
|
577 | - } |
|
40 | + private $excluded_files = ""; |
|
41 | + private $additional_regex_patterns = array(); |
|
42 | + private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
43 | + private $included_files_handler = "backup_files.csv"; |
|
44 | + private $temp_dir_handler = ".dir"; |
|
45 | + public $filesystem; |
|
46 | + public $tmp_filesystem; |
|
47 | + public $storage_filesystem; |
|
48 | + private $xcloner_container; |
|
49 | + private $diff_timestamp_start = ""; |
|
50 | + |
|
51 | + private $logger; |
|
52 | + private $start_adapter; |
|
53 | + private $tmp_adapter; |
|
54 | + private $storage_adapter; |
|
55 | + private $xcloner_settings; |
|
56 | + private $start_filesystem; |
|
57 | + private $tmp_filesystem_append; |
|
58 | + private $storage_filesystem_append; |
|
59 | + |
|
60 | + private $files_counter; |
|
61 | + private $files_size; |
|
62 | + private $last_logged_file; |
|
63 | + private $folders_to_process_per_session = 25; |
|
64 | + private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted"); |
|
65 | + private $backup_name_tags = array('[time]', '[hostname]', '[domain]'); |
|
66 | + |
|
67 | + /** |
|
68 | + * Xcloner_File_System constructor. |
|
69 | + * @param Xcloner $xcloner_container |
|
70 | + * @param string $hash |
|
71 | + */ |
|
72 | + public function __construct(Xcloner $xcloner_container, $hash = "") |
|
73 | + { |
|
74 | + $this->xcloner_container = $xcloner_container; |
|
75 | + |
|
76 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system"); |
|
77 | + $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
78 | + |
|
79 | + try { |
|
80 | + |
|
81 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
82 | + $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
|
83 | + 'disable_asserts' => true, |
|
84 | + ])); |
|
85 | + |
|
86 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
87 | + $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
|
88 | + 'disable_asserts' => true, |
|
89 | + ])); |
|
90 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
91 | + $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
|
92 | + 'disable_asserts' => true, |
|
93 | + ])); |
|
94 | + |
|
95 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
96 | + $this->storage_filesystem = new Filesystem($adapter, new Config([ |
|
97 | + 'disable_asserts' => true, |
|
98 | + ])); |
|
99 | + |
|
100 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, |
|
101 | + 'SKIP_LINKS'); |
|
102 | + $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
|
103 | + 'disable_asserts' => true, |
|
104 | + ])); |
|
105 | + }catch (Exception $e) { |
|
106 | + $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + if ($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
111 | + $this->folders_to_process_per_session = $value; |
|
112 | + } |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Set differential timestamp date |
|
118 | + * @param string $timestamp |
|
119 | + */ |
|
120 | + public function set_diff_timestamp_start($timestamp = "") |
|
121 | + { |
|
122 | + if ($timestamp) { |
|
123 | + $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array( |
|
124 | + "FILESYSTEM", |
|
125 | + "DIFF" |
|
126 | + )); |
|
127 | + $this->diff_timestamp_start = $timestamp; |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Gets the differential timestamp date |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function get_diff_timestamp_start() |
|
136 | + { |
|
137 | + return $this->diff_timestamp_start; |
|
138 | + } |
|
139 | + |
|
140 | + private function get_xcloner_container() |
|
141 | + { |
|
142 | + return $this->xcloner_container; |
|
143 | + } |
|
144 | + |
|
145 | + public function set_hash($hash) |
|
146 | + { |
|
147 | + $this->xcloner_settings->set_hash($hash); |
|
148 | + } |
|
149 | + |
|
150 | + public function get_hash($hash) |
|
151 | + { |
|
152 | + $this->xcloner_settings->get_hash(); |
|
153 | + } |
|
154 | + |
|
155 | + public function get_tmp_filesystem() |
|
156 | + { |
|
157 | + return $this->tmp_filesystem; |
|
158 | + } |
|
159 | + |
|
160 | + public function get_storage_filesystem($remote_storage_selection = "") |
|
161 | + { |
|
162 | + if ($remote_storage_selection != "") { |
|
163 | + $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
164 | + $method = "get_".$remote_storage_selection."_filesystem"; |
|
165 | + |
|
166 | + if (!method_exists($remote_storage, $method)) { |
|
167 | + return false; |
|
168 | + } |
|
169 | + |
|
170 | + list($adapter, $filesystem) = $remote_storage->$method(); |
|
171 | + |
|
172 | + return $filesystem; |
|
173 | + } |
|
174 | + |
|
175 | + return $this->storage_filesystem; |
|
176 | + } |
|
177 | + |
|
178 | + public function get_tmp_filesystem_adapter() |
|
179 | + { |
|
180 | + return $this->tmp_adapter; |
|
181 | + } |
|
182 | + |
|
183 | + public function get_tmp_filesystem_append() |
|
184 | + { |
|
185 | + return $this->tmp_filesystem_append; |
|
186 | + } |
|
187 | + |
|
188 | + public function get_start_adapter() |
|
189 | + { |
|
190 | + return $this->start_adapter; |
|
191 | + } |
|
192 | + |
|
193 | + public function get_start_filesystem() |
|
194 | + { |
|
195 | + return $this->start_filesystem; |
|
196 | + } |
|
197 | + |
|
198 | + public function get_logger() |
|
199 | + { |
|
200 | + return $this->logger; |
|
201 | + } |
|
202 | + |
|
203 | + public function get_start_path_file_info($file) |
|
204 | + { |
|
205 | + $info = $this->getMetadataFull('start_adapter', $file); |
|
206 | + |
|
207 | + return $this->start_filesystem->normalizeFileInfo($info); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $file |
|
212 | + */ |
|
213 | + public function get_storage_path_file_info($file) |
|
214 | + { |
|
215 | + return $this->getMetadataFull('storage_adapter', $file); |
|
216 | + } |
|
217 | + |
|
218 | + public function get_included_files_handler($metadata = 0) |
|
219 | + { |
|
220 | + $path = $this->included_files_handler; |
|
221 | + if (!$metadata) { |
|
222 | + return $path; |
|
223 | + } |
|
224 | + |
|
225 | + $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
|
226 | + |
|
227 | + return $spl_info; |
|
228 | + |
|
229 | + } |
|
230 | + |
|
231 | + public function get_temp_dir_handler() |
|
232 | + { |
|
233 | + return $this->temp_dir_handler; |
|
234 | + } |
|
235 | + |
|
236 | + public function get_latest_backup() |
|
237 | + { |
|
238 | + $files = $this->get_backup_archives_list(); |
|
239 | + |
|
240 | + if (is_array($files)) { |
|
241 | + $this->sort_by($files, "timestamp", "desc"); |
|
242 | + } |
|
243 | + |
|
244 | + $new_list = array(); |
|
245 | + |
|
246 | + foreach ($files as $key => $file) { |
|
247 | + if (!isset($file['parent'])) { |
|
248 | + $new_list[] = ($files[$key]); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + if (isset($new_list[0])) { |
|
253 | + return $new_list[0]; |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + public function get_latest_backups() |
|
258 | + { |
|
259 | + $files = $this->get_backup_archives_list(); |
|
260 | + |
|
261 | + if (is_array($files)) { |
|
262 | + $this->sort_by($files, "timestamp", "desc"); |
|
263 | + } |
|
264 | + |
|
265 | + $new_list = array(); |
|
266 | + |
|
267 | + foreach ($files as $key => $file) { |
|
268 | + if (!isset($file['parent'])) { |
|
269 | + $new_list[] = ($files[$key]); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + return $new_list; |
|
274 | + } |
|
275 | + |
|
276 | + public function get_storage_usage() |
|
277 | + { |
|
278 | + $files = $this->get_backup_archives_list(); |
|
279 | + $total = 0; |
|
280 | + |
|
281 | + if (is_array($files)) { |
|
282 | + foreach ($files as $file) { |
|
283 | + $total += $file['size']; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + return $total; |
|
288 | + } |
|
289 | + |
|
290 | + public function is_part($backup_name) |
|
291 | + { |
|
292 | + if (stristr($backup_name, "-part")) { |
|
293 | + return true; |
|
294 | + } |
|
295 | + |
|
296 | + return false; |
|
297 | + } |
|
298 | + |
|
299 | + public function is_multipart($backup_name) |
|
300 | + { |
|
301 | + if (stristr($backup_name, "-multipart")) { |
|
302 | + return true; |
|
303 | + } |
|
304 | + |
|
305 | + return false; |
|
306 | + } |
|
307 | + |
|
308 | + public function get_backup_size($backup_name) |
|
309 | + { |
|
310 | + $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
|
311 | + if ($this->is_multipart($backup_name)) { |
|
312 | + $backup_parts = $this->get_multipart_files($backup_name); |
|
313 | + foreach ($backup_parts as $part_file) { |
|
314 | + $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
315 | + } |
|
316 | + } |
|
317 | + |
|
318 | + return $backup_size; |
|
319 | + } |
|
320 | + |
|
321 | + public function get_multipart_files($backup_name, $storage_selection = "") |
|
322 | + { |
|
323 | + $files = array(); |
|
324 | + |
|
325 | + if ($this->is_multipart($backup_name)) { |
|
326 | + $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
|
327 | + foreach ($lines as $line) { |
|
328 | + if ($line) { |
|
329 | + $data = str_getcsv($line); |
|
330 | + $files[] = $data[0]; |
|
331 | + } |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + return $files; |
|
336 | + } |
|
337 | + |
|
338 | + public function delete_backup_by_name($backup_name, $storage_selection = "") |
|
339 | + { |
|
340 | + if ($this->is_multipart($backup_name)) { |
|
341 | + $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
|
342 | + foreach ($lines as $line) { |
|
343 | + if ($line) { |
|
344 | + $data = str_getcsv($line); |
|
345 | + $this->get_storage_filesystem($storage_selection)->delete($data[0]); |
|
346 | + } |
|
347 | + } |
|
348 | + } |
|
349 | + |
|
350 | + if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) { |
|
351 | + $return = true; |
|
352 | + } else { |
|
353 | + $return = false; |
|
354 | + } |
|
355 | + |
|
356 | + return $return; |
|
357 | + } |
|
358 | + |
|
359 | + public function getMetadataFull($adapter = "storage_adapter", $path) |
|
360 | + { |
|
361 | + $location = $this->$adapter->applyPathPrefix($path); |
|
362 | + $spl_info = new SplFileInfo($location); |
|
363 | + |
|
364 | + return ($spl_info); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + public function get_backup_archives_list($storage_selection = "") |
|
369 | + { |
|
370 | + $list = array(); |
|
371 | + |
|
372 | + |
|
373 | + if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) { |
|
374 | + $list = $this->get_storage_filesystem($storage_selection)->listContents(); |
|
375 | + } |
|
376 | + |
|
377 | + $backup_files = array(); |
|
378 | + $parents = array(); |
|
379 | + |
|
380 | + foreach ($list as $file_info) { |
|
381 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") { |
|
382 | + $data = array(); |
|
383 | + |
|
384 | + $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path'])); |
|
385 | + foreach ($lines as $line) { |
|
386 | + if ($line) { |
|
387 | + $data = str_getcsv($line); |
|
388 | + if (is_array($data)) { |
|
389 | + $parents[$data[0]] = $file_info['basename']; |
|
390 | + $file_info['childs'][] = $data; |
|
391 | + $file_info['size'] += $data[2]; |
|
392 | + } |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + } |
|
397 | + |
|
398 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], |
|
399 | + $this->backup_archive_extensions)) { |
|
400 | + $backup_files[$file_info['path']] = $file_info; |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + foreach ($backup_files as $key => $file_info) { |
|
405 | + if (!isset($backup_files[$key]['timestamp'])) { |
|
406 | + //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']); |
|
407 | + } |
|
408 | + |
|
409 | + if (isset($parents[$file_info['basename']])) { |
|
410 | + $backup_files[$key]['parent'] = $parents[$file_info['basename']]; |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + return $backup_files; |
|
415 | + } |
|
416 | + |
|
417 | + public function start_file_recursion($init = 0) |
|
418 | + { |
|
419 | + if ($init) { |
|
420 | + $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), |
|
421 | + $this->xcloner_settings->get_xcloner_start_path())); |
|
422 | + $this->do_system_init(); |
|
423 | + } |
|
424 | + |
|
425 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
426 | + //.dir exists, we presume we have files to iterate |
|
427 | + $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
|
428 | + $files = array_filter(explode("\n", $content)); |
|
429 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
430 | + |
|
431 | + $counter = 0; |
|
432 | + foreach ($files as $file) { |
|
433 | + if ($counter < $this->folders_to_process_per_session) { |
|
434 | + $this->build_files_list($file); |
|
435 | + $counter++; |
|
436 | + } else { |
|
437 | + $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
|
438 | + } |
|
439 | + } |
|
440 | + } else { |
|
441 | + $this->build_files_list(); |
|
442 | + } |
|
443 | + |
|
444 | + if ($this->scan_finished()) { |
|
445 | + $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
|
446 | + $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
447 | + $this->files_counter++; |
|
448 | + |
|
449 | + //adding included dump file to the included files list |
|
450 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) { |
|
451 | + $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
|
452 | + $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
453 | + $this->files_counter++; |
|
454 | + } |
|
455 | + |
|
456 | + //adding a default index.html to the temp xcloner folder |
|
457 | + if (!$this->get_tmp_filesystem()->has("index.html")) { |
|
458 | + $this->get_tmp_filesystem()->write("index.html", ""); |
|
459 | + } |
|
460 | + |
|
461 | + //adding the default log file |
|
462 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) { |
|
463 | + $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
|
464 | + $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
465 | + $this->files_counter++; |
|
466 | + } |
|
467 | + |
|
468 | + return false; |
|
469 | + } |
|
470 | + |
|
471 | + return true; |
|
472 | + } |
|
473 | + |
|
474 | + public function get_backup_attachments() |
|
475 | + { |
|
476 | + $return = array(); |
|
477 | + |
|
478 | + $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
|
479 | + if (file_exists($files_list_file)) { |
|
480 | + $return[] = $files_list_file; |
|
481 | + } |
|
482 | + |
|
483 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
484 | + $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
485 | + if (!file_exists($log_file)) { |
|
486 | + $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename(); |
|
487 | + } |
|
488 | + |
|
489 | + if (file_exists($log_file)) { |
|
490 | + $return[] = $log_file; |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + return $return; |
|
495 | + } |
|
496 | + |
|
497 | + public function remove_tmp_filesystem() |
|
498 | + { |
|
499 | + //delete the temporary folder |
|
500 | + $this->logger->debug(sprintf("Deleting the temporary storage folder %s", |
|
501 | + $this->xcloner_settings->get_xcloner_tmp_path())); |
|
502 | + |
|
503 | + $contents = $this->get_tmp_filesystem()->listContents(); |
|
504 | + |
|
505 | + if (is_array($contents)) { |
|
506 | + foreach ($contents as $file_info) { |
|
507 | + $this->get_tmp_filesystem()->delete($file_info['path']); |
|
508 | + } |
|
509 | + } |
|
510 | + |
|
511 | + @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
|
512 | + |
|
513 | + return; |
|
514 | + } |
|
515 | + |
|
516 | + public function cleanup_tmp_directories() |
|
517 | + { |
|
518 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
519 | + $tmp_filesystem = new Filesystem($adapter, new Config([ |
|
520 | + 'disable_asserts' => true, |
|
521 | + ])); |
|
522 | + |
|
523 | + $contents = $tmp_filesystem->listContents(); |
|
524 | + |
|
525 | + foreach ($contents as $file) { |
|
526 | + |
|
527 | + if (preg_match("/.xcloner-(.*)/", $file['path'])) { |
|
528 | + if ($file['timestamp'] < strtotime("-1days")) { |
|
529 | + $tmp_filesystem->deleteDir($file['path']); |
|
530 | + $this->logger->debug(sprintf("Delete temporary directory %s", $file['path'])); |
|
531 | + } |
|
532 | + } |
|
533 | + } |
|
534 | + |
|
535 | + return true; |
|
536 | + } |
|
537 | + |
|
538 | + private function do_system_init() |
|
539 | + { |
|
540 | + $this->files_counter = 0; |
|
541 | + |
|
542 | + if (!$this->storage_filesystem->has("index.html")) { |
|
543 | + $this->storage_filesystem->write("index.html", ""); |
|
544 | + } |
|
545 | + |
|
546 | + if (!$this->tmp_filesystem->has("index.html")) { |
|
547 | + $this->tmp_filesystem->write("index.html", ""); |
|
548 | + } |
|
549 | + |
|
550 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
551 | + $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
552 | + } |
|
553 | + |
|
554 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
555 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
556 | + } |
|
557 | + } |
|
558 | + |
|
559 | + public function get_scanned_files_num() |
|
560 | + { |
|
561 | + return $this->files_counter; |
|
562 | + } |
|
563 | + |
|
564 | + public function get_scanned_files_total_size() |
|
565 | + { |
|
566 | + return $this->files_size; |
|
567 | + } |
|
568 | + |
|
569 | + public function last_logged_file() |
|
570 | + { |
|
571 | + return $this->last_logged_file; |
|
572 | + } |
|
573 | + |
|
574 | + public static function is_regex($regex) |
|
575 | + { |
|
576 | + return preg_match("/^\^(.*)\$$/i", $regex); |
|
577 | + } |
|
578 | 578 | |
579 | - public function set_excluded_files($excluded_files = array()) |
|
580 | - { |
|
581 | - if (!is_array($excluded_files)) { |
|
582 | - $excluded_files = array(); |
|
583 | - } |
|
579 | + public function set_excluded_files($excluded_files = array()) |
|
580 | + { |
|
581 | + if (!is_array($excluded_files)) { |
|
582 | + $excluded_files = array(); |
|
583 | + } |
|
584 | 584 | |
585 | - foreach ($excluded_files as $excl) { |
|
585 | + foreach ($excluded_files as $excl) { |
|
586 | 586 | |
587 | - if ($this->is_regex($excl)) { |
|
588 | - $this->additional_regex_patterns[] = $excl; |
|
589 | - } |
|
590 | - } |
|
587 | + if ($this->is_regex($excl)) { |
|
588 | + $this->additional_regex_patterns[] = $excl; |
|
589 | + } |
|
590 | + } |
|
591 | 591 | |
592 | - $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
|
592 | + $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
|
593 | 593 | |
594 | - return $this->excluded_files; |
|
595 | - } |
|
594 | + return $this->excluded_files; |
|
595 | + } |
|
596 | 596 | |
597 | - public function get_excluded_files() |
|
598 | - { |
|
599 | - return $this->excluded_files_by_default; |
|
600 | - } |
|
597 | + public function get_excluded_files() |
|
598 | + { |
|
599 | + return $this->excluded_files_by_default; |
|
600 | + } |
|
601 | 601 | |
602 | - public function list_directory($path) |
|
603 | - { |
|
604 | - return $this->start_filesystem->listContents($path); |
|
605 | - } |
|
602 | + public function list_directory($path) |
|
603 | + { |
|
604 | + return $this->start_filesystem->listContents($path); |
|
605 | + } |
|
606 | 606 | |
607 | - public function build_files_list($folder = "") |
|
608 | - { |
|
609 | - $this->logger->debug(sprintf(("Building the files system list"))); |
|
607 | + public function build_files_list($folder = "") |
|
608 | + { |
|
609 | + $this->logger->debug(sprintf(("Building the files system list"))); |
|
610 | 610 | |
611 | - //if we start with the root folder(empty value), we initializa the file system |
|
612 | - if (!$folder) { |
|
611 | + //if we start with the root folder(empty value), we initializa the file system |
|
612 | + if (!$folder) { |
|
613 | 613 | |
614 | - } |
|
614 | + } |
|
615 | 615 | |
616 | - try { |
|
616 | + try { |
|
617 | 617 | |
618 | - $files = $this->start_filesystem->listContents($folder); |
|
619 | - foreach ($files as $file) { |
|
620 | - if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) { |
|
621 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), |
|
622 | - $file['path']), array( |
|
623 | - "FILESYSTEM SCAN", |
|
624 | - "NOT READABLE" |
|
625 | - )); |
|
626 | - } elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
627 | - $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array( |
|
628 | - "FILESYSTEM SCAN", |
|
629 | - "INCLUDE" |
|
630 | - )); |
|
631 | - $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
|
632 | - if ($this->store_file($file)) { |
|
633 | - $this->files_counter++; |
|
634 | - } |
|
635 | - if (isset($file['size'])) { |
|
636 | - $this->files_size += $file['size']; |
|
637 | - } |
|
638 | - |
|
639 | - } else { |
|
640 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), |
|
641 | - $file['path'], $matching_pattern), array( |
|
642 | - "FILESYSTEM SCAN", |
|
643 | - "EXCLUDE" |
|
644 | - )); |
|
645 | - } |
|
646 | - } |
|
618 | + $files = $this->start_filesystem->listContents($folder); |
|
619 | + foreach ($files as $file) { |
|
620 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) { |
|
621 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), |
|
622 | + $file['path']), array( |
|
623 | + "FILESYSTEM SCAN", |
|
624 | + "NOT READABLE" |
|
625 | + )); |
|
626 | + } elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
627 | + $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array( |
|
628 | + "FILESYSTEM SCAN", |
|
629 | + "INCLUDE" |
|
630 | + )); |
|
631 | + $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
|
632 | + if ($this->store_file($file)) { |
|
633 | + $this->files_counter++; |
|
634 | + } |
|
635 | + if (isset($file['size'])) { |
|
636 | + $this->files_size += $file['size']; |
|
637 | + } |
|
638 | + |
|
639 | + } else { |
|
640 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), |
|
641 | + $file['path'], $matching_pattern), array( |
|
642 | + "FILESYSTEM SCAN", |
|
643 | + "EXCLUDE" |
|
644 | + )); |
|
645 | + } |
|
646 | + } |
|
647 | 647 | |
648 | - }catch (Exception $e) { |
|
648 | + }catch (Exception $e) { |
|
649 | 649 | |
650 | - $this->logger->error($e->getMessage()); |
|
651 | - |
|
652 | - } |
|
650 | + $this->logger->error($e->getMessage()); |
|
651 | + |
|
652 | + } |
|
653 | 653 | |
654 | - } |
|
654 | + } |
|
655 | 655 | |
656 | - public function estimate_read_write_time() |
|
657 | - { |
|
658 | - $tmp_file = ".xcloner".substr(md5(time()), 0, 5); |
|
656 | + public function estimate_read_write_time() |
|
657 | + { |
|
658 | + $tmp_file = ".xcloner".substr(md5(time()), 0, 5); |
|
659 | 659 | |
660 | - $start_time = microtime(true); |
|
660 | + $start_time = microtime(true); |
|
661 | 661 | |
662 | - $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
662 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
663 | 663 | |
664 | - try { |
|
665 | - $this->tmp_filesystem->write($tmp_file, $data); |
|
664 | + try { |
|
665 | + $this->tmp_filesystem->write($tmp_file, $data); |
|
666 | 666 | |
667 | - $end_time = microtime(true) - $start_time; |
|
667 | + $end_time = microtime(true) - $start_time; |
|
668 | 668 | |
669 | - $return['writing_time'] = $end_time; |
|
669 | + $return['writing_time'] = $end_time; |
|
670 | 670 | |
671 | - $return['reading_time'] = $this->estimate_reading_time($tmp_file); |
|
671 | + $return['reading_time'] = $this->estimate_reading_time($tmp_file); |
|
672 | 672 | |
673 | - $this->tmp_filesystem->delete($tmp_file); |
|
673 | + $this->tmp_filesystem->delete($tmp_file); |
|
674 | 674 | |
675 | - }catch (Exception $e) { |
|
675 | + }catch (Exception $e) { |
|
676 | 676 | |
677 | - $this->logger->error($e->getMessage()); |
|
677 | + $this->logger->error($e->getMessage()); |
|
678 | 678 | |
679 | - } |
|
679 | + } |
|
680 | 680 | |
681 | - return $return; |
|
682 | - } |
|
681 | + return $return; |
|
682 | + } |
|
683 | 683 | |
684 | - public function backup_storage_cleanup() |
|
685 | - { |
|
686 | - $this->logger->info(sprintf(("Cleaning the backup storage on matching rules"))); |
|
684 | + public function backup_storage_cleanup() |
|
685 | + { |
|
686 | + $this->logger->info(sprintf(("Cleaning the backup storage on matching rules"))); |
|
687 | 687 | |
688 | - $_storage_size = 0; |
|
689 | - $_backup_files_list = array(); |
|
688 | + $_storage_size = 0; |
|
689 | + $_backup_files_list = array(); |
|
690 | 690 | |
691 | - //rule date limit |
|
692 | - $current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days"); |
|
693 | - |
|
694 | - $files = $this->storage_filesystem->listContents(); |
|
695 | - |
|
696 | - if (is_array($files)) { |
|
697 | - foreach ($files as $file) { |
|
698 | - if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) { |
|
699 | - $_storage_size += $file['size']; //bytes |
|
700 | - $_backup_files_list[] = $file; |
|
701 | - } |
|
702 | - } |
|
703 | - } |
|
691 | + //rule date limit |
|
692 | + $current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days"); |
|
693 | + |
|
694 | + $files = $this->storage_filesystem->listContents(); |
|
695 | + |
|
696 | + if (is_array($files)) { |
|
697 | + foreach ($files as $file) { |
|
698 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) { |
|
699 | + $_storage_size += $file['size']; //bytes |
|
700 | + $_backup_files_list[] = $file; |
|
701 | + } |
|
702 | + } |
|
703 | + } |
|
704 | 704 | |
705 | 705 | |
706 | - $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
707 | - |
|
708 | - $_backups_counter = sizeof($_backup_files_list); |
|
709 | - |
|
710 | - foreach ($_backup_files_list as $file) { |
|
711 | - //processing rule folder capacity |
|
712 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
713 | - $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
714 | - { |
|
715 | - $this->storage_filesystem->delete($file['path']); |
|
716 | - $_storage_size -= $file['size']; |
|
717 | - $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
718 | - "STORAGE SIZE LIMIT", |
|
719 | - $_storage_size." >= ".$set_storage_limit |
|
720 | - )); |
|
721 | - } |
|
722 | - |
|
723 | - //processing rule days limit |
|
724 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) { |
|
725 | - $this->storage_filesystem->delete($file['path']); |
|
726 | - $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
727 | - "RETENTION LIMIT TIMESTAMP", |
|
728 | - $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') |
|
729 | - )); |
|
730 | - } |
|
731 | - |
|
732 | - //processing backup countert limit |
|
733 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) { |
|
734 | - $this->storage_filesystem->delete($file['path']); |
|
735 | - $_backups_counter--; |
|
736 | - $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
737 | - "BACKUP QUANTITY LIMIT", |
|
738 | - $_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') |
|
739 | - )); |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - } |
|
706 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
707 | + |
|
708 | + $_backups_counter = sizeof($_backup_files_list); |
|
709 | + |
|
710 | + foreach ($_backup_files_list as $file) { |
|
711 | + //processing rule folder capacity |
|
712 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
713 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
714 | + { |
|
715 | + $this->storage_filesystem->delete($file['path']); |
|
716 | + $_storage_size -= $file['size']; |
|
717 | + $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
718 | + "STORAGE SIZE LIMIT", |
|
719 | + $_storage_size." >= ".$set_storage_limit |
|
720 | + )); |
|
721 | + } |
|
722 | + |
|
723 | + //processing rule days limit |
|
724 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) { |
|
725 | + $this->storage_filesystem->delete($file['path']); |
|
726 | + $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
727 | + "RETENTION LIMIT TIMESTAMP", |
|
728 | + $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') |
|
729 | + )); |
|
730 | + } |
|
731 | + |
|
732 | + //processing backup countert limit |
|
733 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) { |
|
734 | + $this->storage_filesystem->delete($file['path']); |
|
735 | + $_backups_counter--; |
|
736 | + $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
737 | + "BACKUP QUANTITY LIMIT", |
|
738 | + $_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') |
|
739 | + )); |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + } |
|
744 | 744 | |
745 | - } |
|
745 | + } |
|
746 | 746 | |
747 | - /** |
|
748 | - * @param string $tmp_file |
|
749 | - */ |
|
750 | - public function estimate_reading_time($tmp_file) |
|
751 | - { |
|
752 | - $this->logger->debug(sprintf(("Estimating file system reading time"))); |
|
753 | - |
|
754 | - $start_time = microtime(true); |
|
755 | - |
|
756 | - if ($this->tmp_filesystem->has($tmp_file)) { |
|
757 | - $this->tmp_filesystem->read($tmp_file); |
|
758 | - } |
|
759 | - |
|
760 | - $end_time = microtime(true) - $start_time; |
|
761 | - |
|
762 | - return $end_time; |
|
763 | - |
|
764 | - } |
|
765 | - |
|
766 | - public function process_backup_name($name = "", $max_length = 100) |
|
767 | - { |
|
768 | - if (!$name) { |
|
769 | - $name = $this->xcloner_settings->get_default_backup_name(); |
|
770 | - } |
|
771 | - |
|
772 | - foreach ($this->backup_name_tags as $tag) { |
|
773 | - if ($tag == '[time]') { |
|
774 | - $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
775 | - } elseif ($tag == '[hostname]') { |
|
776 | - $name = str_replace($tag, gethostname(), $name); |
|
777 | - } elseif ($tag == '[domain]') { |
|
778 | - $domain = parse_url(admin_url(), PHP_URL_HOST); |
|
779 | - $name = str_replace($tag, $domain, $name); |
|
780 | - } |
|
781 | - } |
|
782 | - |
|
783 | - if ($max_length) { |
|
784 | - $name = substr($name, 0, $max_length); |
|
785 | - } |
|
786 | - |
|
787 | - return $name; |
|
788 | - } |
|
789 | - |
|
790 | - /** |
|
791 | - * @param string $field |
|
792 | - */ |
|
793 | - public function sort_by(&$array, $field, $direction = 'asc') |
|
794 | - { |
|
795 | - if (strtolower($direction) == "desc" || $direction == SORT_DESC) { |
|
796 | - $direction = SORT_DESC; |
|
797 | - } else { |
|
798 | - $direction = SORT_ASC; |
|
799 | - } |
|
800 | - |
|
801 | - $array = $this->array_orderby($array, $field, $direction); |
|
802 | - |
|
803 | - return true; |
|
804 | - } |
|
805 | - |
|
806 | - private function array_orderby() |
|
807 | - { |
|
808 | - $args = func_get_args(); |
|
809 | - $data = array_shift($args); |
|
810 | - |
|
811 | - foreach ($args as $n => $field) { |
|
812 | - if (is_string($field)) { |
|
813 | - $tmp = array(); |
|
814 | - foreach ($data as $key => $row) { |
|
815 | - if (is_array($row)) { |
|
816 | - $tmp[$key] = $row[$field]; |
|
817 | - } else { |
|
818 | - $tmp[$key] = $row->$field; |
|
819 | - } |
|
820 | - } |
|
821 | - $args[$n] = $tmp; |
|
822 | - } |
|
823 | - } |
|
824 | - $args[] = &$data; |
|
825 | - |
|
826 | - call_user_func_array('array_multisort', $args); |
|
827 | - |
|
828 | - return array_pop($args); |
|
829 | - } |
|
830 | - |
|
831 | - private function check_file_diff_time($file) |
|
832 | - { |
|
833 | - if ($this->get_diff_timestamp_start() != "") { |
|
834 | - $fileMeta = $this->getMetadataFull("start_adapter", $file['path']); |
|
835 | - $timestamp = $fileMeta->getMTime(); |
|
836 | - if ($timestamp < $fileMeta->getCTime()) { |
|
837 | - $timestamp = $fileMeta->getCTime(); |
|
838 | - } |
|
839 | - |
|
840 | - if ($timestamp <= $this->get_diff_timestamp_start()) { |
|
841 | - return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start; |
|
842 | - } |
|
843 | - } |
|
844 | - |
|
845 | - return false; |
|
846 | - } |
|
847 | - |
|
848 | - public function is_excluded($file) |
|
849 | - { |
|
850 | - $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
|
851 | - |
|
852 | - if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) { |
|
853 | - if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
854 | - return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
855 | - } |
|
856 | - } |
|
857 | - |
|
858 | - if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) { |
|
859 | - $this->set_excluded_files(); |
|
860 | - } |
|
861 | - |
|
862 | - if (is_array($this->excluded_files)) { |
|
863 | - foreach ($this->excluded_files as $excluded_file_pattern) { |
|
864 | - if ($excluded_file_pattern == "/") { |
|
865 | - $needle = "$"; |
|
866 | - } else { |
|
867 | - $needle = "$".$excluded_file_pattern; |
|
868 | - } |
|
869 | - |
|
870 | - if (strstr("$".$file['path'], $needle)) { |
|
871 | - return $excluded_file_pattern; |
|
872 | - } |
|
873 | - } |
|
874 | - } |
|
875 | - |
|
876 | - if ($regex = $this->is_excluded_regex($file)) { |
|
877 | - return $regex; |
|
878 | - } |
|
879 | - |
|
880 | - if ($file['type'] == "file") { |
|
881 | - $check_file_diff_timestamp = $this->check_file_diff_time($file); |
|
882 | - if ($check_file_diff_timestamp) { |
|
883 | - return $check_file_diff_timestamp; |
|
884 | - } |
|
885 | - } |
|
886 | - |
|
887 | - return false; |
|
888 | - } |
|
889 | - |
|
890 | - /*REGEX examples |
|
747 | + /** |
|
748 | + * @param string $tmp_file |
|
749 | + */ |
|
750 | + public function estimate_reading_time($tmp_file) |
|
751 | + { |
|
752 | + $this->logger->debug(sprintf(("Estimating file system reading time"))); |
|
753 | + |
|
754 | + $start_time = microtime(true); |
|
755 | + |
|
756 | + if ($this->tmp_filesystem->has($tmp_file)) { |
|
757 | + $this->tmp_filesystem->read($tmp_file); |
|
758 | + } |
|
759 | + |
|
760 | + $end_time = microtime(true) - $start_time; |
|
761 | + |
|
762 | + return $end_time; |
|
763 | + |
|
764 | + } |
|
765 | + |
|
766 | + public function process_backup_name($name = "", $max_length = 100) |
|
767 | + { |
|
768 | + if (!$name) { |
|
769 | + $name = $this->xcloner_settings->get_default_backup_name(); |
|
770 | + } |
|
771 | + |
|
772 | + foreach ($this->backup_name_tags as $tag) { |
|
773 | + if ($tag == '[time]') { |
|
774 | + $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
775 | + } elseif ($tag == '[hostname]') { |
|
776 | + $name = str_replace($tag, gethostname(), $name); |
|
777 | + } elseif ($tag == '[domain]') { |
|
778 | + $domain = parse_url(admin_url(), PHP_URL_HOST); |
|
779 | + $name = str_replace($tag, $domain, $name); |
|
780 | + } |
|
781 | + } |
|
782 | + |
|
783 | + if ($max_length) { |
|
784 | + $name = substr($name, 0, $max_length); |
|
785 | + } |
|
786 | + |
|
787 | + return $name; |
|
788 | + } |
|
789 | + |
|
790 | + /** |
|
791 | + * @param string $field |
|
792 | + */ |
|
793 | + public function sort_by(&$array, $field, $direction = 'asc') |
|
794 | + { |
|
795 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) { |
|
796 | + $direction = SORT_DESC; |
|
797 | + } else { |
|
798 | + $direction = SORT_ASC; |
|
799 | + } |
|
800 | + |
|
801 | + $array = $this->array_orderby($array, $field, $direction); |
|
802 | + |
|
803 | + return true; |
|
804 | + } |
|
805 | + |
|
806 | + private function array_orderby() |
|
807 | + { |
|
808 | + $args = func_get_args(); |
|
809 | + $data = array_shift($args); |
|
810 | + |
|
811 | + foreach ($args as $n => $field) { |
|
812 | + if (is_string($field)) { |
|
813 | + $tmp = array(); |
|
814 | + foreach ($data as $key => $row) { |
|
815 | + if (is_array($row)) { |
|
816 | + $tmp[$key] = $row[$field]; |
|
817 | + } else { |
|
818 | + $tmp[$key] = $row->$field; |
|
819 | + } |
|
820 | + } |
|
821 | + $args[$n] = $tmp; |
|
822 | + } |
|
823 | + } |
|
824 | + $args[] = &$data; |
|
825 | + |
|
826 | + call_user_func_array('array_multisort', $args); |
|
827 | + |
|
828 | + return array_pop($args); |
|
829 | + } |
|
830 | + |
|
831 | + private function check_file_diff_time($file) |
|
832 | + { |
|
833 | + if ($this->get_diff_timestamp_start() != "") { |
|
834 | + $fileMeta = $this->getMetadataFull("start_adapter", $file['path']); |
|
835 | + $timestamp = $fileMeta->getMTime(); |
|
836 | + if ($timestamp < $fileMeta->getCTime()) { |
|
837 | + $timestamp = $fileMeta->getCTime(); |
|
838 | + } |
|
839 | + |
|
840 | + if ($timestamp <= $this->get_diff_timestamp_start()) { |
|
841 | + return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start; |
|
842 | + } |
|
843 | + } |
|
844 | + |
|
845 | + return false; |
|
846 | + } |
|
847 | + |
|
848 | + public function is_excluded($file) |
|
849 | + { |
|
850 | + $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
|
851 | + |
|
852 | + if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) { |
|
853 | + if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
854 | + return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
855 | + } |
|
856 | + } |
|
857 | + |
|
858 | + if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) { |
|
859 | + $this->set_excluded_files(); |
|
860 | + } |
|
861 | + |
|
862 | + if (is_array($this->excluded_files)) { |
|
863 | + foreach ($this->excluded_files as $excluded_file_pattern) { |
|
864 | + if ($excluded_file_pattern == "/") { |
|
865 | + $needle = "$"; |
|
866 | + } else { |
|
867 | + $needle = "$".$excluded_file_pattern; |
|
868 | + } |
|
869 | + |
|
870 | + if (strstr("$".$file['path'], $needle)) { |
|
871 | + return $excluded_file_pattern; |
|
872 | + } |
|
873 | + } |
|
874 | + } |
|
875 | + |
|
876 | + if ($regex = $this->is_excluded_regex($file)) { |
|
877 | + return $regex; |
|
878 | + } |
|
879 | + |
|
880 | + if ($file['type'] == "file") { |
|
881 | + $check_file_diff_timestamp = $this->check_file_diff_time($file); |
|
882 | + if ($check_file_diff_timestamp) { |
|
883 | + return $check_file_diff_timestamp; |
|
884 | + } |
|
885 | + } |
|
886 | + |
|
887 | + return false; |
|
888 | + } |
|
889 | + |
|
890 | + /*REGEX examples |
|
891 | 891 | * |
892 | 892 | * exclude all except .php file |
893 | 893 | * PATTERN: ^(.*)\.(.+)$(?<!(php)) |
@@ -919,163 +919,163 @@ discard block |
||
919 | 919 | * exclude the backup folders |
920 | 920 | * PATTERN: (^|^\/)(wp-content\/backups|administrator\/backups)(.*)$"; |
921 | 921 | */ |
922 | - private function is_excluded_regex($file) |
|
923 | - { |
|
924 | - //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
|
925 | - |
|
926 | - $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude')); |
|
927 | - |
|
928 | - if (is_array($this->additional_regex_patterns)) { |
|
929 | - $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns); |
|
930 | - } |
|
931 | - |
|
932 | - //print_r($regex_patterns);exit; |
|
933 | - |
|
934 | - if (is_array($regex_patterns)) { |
|
935 | - //$this->excluded_files = array(); |
|
936 | - //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
|
937 | - //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
|
938 | - |
|
939 | - foreach ($regex_patterns as $excluded_file_pattern) { |
|
940 | - |
|
941 | - if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, |
|
942 | - strlen($excluded_file_pattern)) == "\r") { |
|
943 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
944 | - } |
|
945 | - |
|
946 | - if ($file['path'] == "/") { |
|
947 | - $needle = "/"; |
|
948 | - } else { |
|
949 | - $needle = "/".$file['path']; |
|
950 | - } |
|
951 | - //echo $needle."---".$excluded_file_pattern."---\n"; |
|
952 | - |
|
953 | - if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
954 | - return $excluded_file_pattern; |
|
955 | - } |
|
956 | - } |
|
957 | - } |
|
958 | - |
|
959 | - return false; |
|
960 | - } |
|
961 | - |
|
962 | - public function store_file($file, $storage = 'start_filesystem') |
|
963 | - { |
|
964 | - $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
|
965 | - |
|
966 | - if (!isset($file['size'])) { |
|
967 | - $file['size'] = 0; |
|
968 | - } |
|
969 | - if (!isset($file['visibility'])) { |
|
970 | - $file['visibility'] = "private"; |
|
971 | - } |
|
972 | - |
|
973 | - $csv_filename = str_replace('"', '""', $file['path']); |
|
974 | - |
|
975 | - $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
|
976 | - |
|
977 | - $this->last_logged_file = $file['path']; |
|
978 | - |
|
979 | - if ($file['type'] == "dir") { |
|
980 | - try { |
|
981 | - $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
|
982 | - }catch (Exception $e) { |
|
983 | - $this->logger->error($e->getMessage()); |
|
984 | - } |
|
985 | - } |
|
986 | - |
|
987 | - if ($this->get_diff_timestamp_start()) { |
|
988 | - if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) { |
|
989 | - $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], |
|
990 | - $response), array( |
|
991 | - "FILESYSTEM SCAN", |
|
992 | - "DIR DIFF" |
|
993 | - )); |
|
994 | - |
|
995 | - return false; |
|
996 | - } |
|
997 | - } |
|
998 | - |
|
999 | - try { |
|
1000 | - if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) { |
|
1001 | - //adding fix for UTF-8 CSV preview |
|
1002 | - $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL; |
|
1003 | - $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line); |
|
1004 | - } |
|
1005 | - |
|
1006 | - $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
|
1007 | - |
|
1008 | - }catch (Exception $e) { |
|
1009 | - |
|
1010 | - $this->logger->error($e->getMessage()); |
|
1011 | - } |
|
1012 | - |
|
1013 | - return true; |
|
1014 | - } |
|
1015 | - |
|
1016 | - public function get_fileystem_handler() |
|
1017 | - { |
|
1018 | - return $this; |
|
1019 | - } |
|
1020 | - |
|
1021 | - public function get_filesystem($system = "") |
|
1022 | - { |
|
1023 | - if ($system == "storage_filesystem_append") { |
|
1024 | - return $this->storage_filesystem_append; |
|
1025 | - } elseif ($system == "tmp_filesystem_append") { |
|
1026 | - return $this->tmp_filesystem_append; |
|
1027 | - } elseif ($system == "tmp_filesystem") { |
|
1028 | - return $this->tmp_filesystem; |
|
1029 | - } elseif ($system == "storage_filesystem") { |
|
1030 | - return $this->storage_filesystem; |
|
1031 | - } else { |
|
1032 | - return $this->start_filesystem; |
|
1033 | - } |
|
1034 | - } |
|
1035 | - |
|
1036 | - public function get_adapter($system) |
|
1037 | - { |
|
1038 | - if ($system == "tmp_filesystem") { |
|
1039 | - return $this->tmp_adapter; |
|
1040 | - } elseif ($system == "storage_filesystem") { |
|
1041 | - return $this->storage_adapter; |
|
1042 | - } else { |
|
1043 | - return $this->start_adapter; |
|
1044 | - } |
|
1045 | - } |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * File scan finished |
|
1049 | - * Method called when file scan is finished |
|
1050 | - * |
|
1051 | - * @return bool |
|
1052 | - */ |
|
1053 | - private function scan_finished() |
|
1054 | - { |
|
1055 | - if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && |
|
1056 | - $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
1057 | - return false; |
|
1058 | - } |
|
1059 | - |
|
1060 | - if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
1061 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
1062 | - } |
|
1063 | - |
|
1064 | - $this->logger->debug(sprintf(("File scan finished"))); |
|
1065 | - |
|
1066 | - return true; |
|
1067 | - } |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * Calculate bytes from MB value |
|
1071 | - * |
|
1072 | - * @param int $mb_size |
|
1073 | - * |
|
1074 | - * @return float|int |
|
1075 | - */ |
|
1076 | - private function calc_to_bytes($mb_size) |
|
1077 | - { |
|
1078 | - return $mb_size * (1024 * 1024); |
|
1079 | - } |
|
922 | + private function is_excluded_regex($file) |
|
923 | + { |
|
924 | + //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
|
925 | + |
|
926 | + $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude')); |
|
927 | + |
|
928 | + if (is_array($this->additional_regex_patterns)) { |
|
929 | + $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns); |
|
930 | + } |
|
931 | + |
|
932 | + //print_r($regex_patterns);exit; |
|
933 | + |
|
934 | + if (is_array($regex_patterns)) { |
|
935 | + //$this->excluded_files = array(); |
|
936 | + //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
|
937 | + //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
|
938 | + |
|
939 | + foreach ($regex_patterns as $excluded_file_pattern) { |
|
940 | + |
|
941 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, |
|
942 | + strlen($excluded_file_pattern)) == "\r") { |
|
943 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
944 | + } |
|
945 | + |
|
946 | + if ($file['path'] == "/") { |
|
947 | + $needle = "/"; |
|
948 | + } else { |
|
949 | + $needle = "/".$file['path']; |
|
950 | + } |
|
951 | + //echo $needle."---".$excluded_file_pattern."---\n"; |
|
952 | + |
|
953 | + if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
954 | + return $excluded_file_pattern; |
|
955 | + } |
|
956 | + } |
|
957 | + } |
|
958 | + |
|
959 | + return false; |
|
960 | + } |
|
961 | + |
|
962 | + public function store_file($file, $storage = 'start_filesystem') |
|
963 | + { |
|
964 | + $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
|
965 | + |
|
966 | + if (!isset($file['size'])) { |
|
967 | + $file['size'] = 0; |
|
968 | + } |
|
969 | + if (!isset($file['visibility'])) { |
|
970 | + $file['visibility'] = "private"; |
|
971 | + } |
|
972 | + |
|
973 | + $csv_filename = str_replace('"', '""', $file['path']); |
|
974 | + |
|
975 | + $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
|
976 | + |
|
977 | + $this->last_logged_file = $file['path']; |
|
978 | + |
|
979 | + if ($file['type'] == "dir") { |
|
980 | + try { |
|
981 | + $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
|
982 | + }catch (Exception $e) { |
|
983 | + $this->logger->error($e->getMessage()); |
|
984 | + } |
|
985 | + } |
|
986 | + |
|
987 | + if ($this->get_diff_timestamp_start()) { |
|
988 | + if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) { |
|
989 | + $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], |
|
990 | + $response), array( |
|
991 | + "FILESYSTEM SCAN", |
|
992 | + "DIR DIFF" |
|
993 | + )); |
|
994 | + |
|
995 | + return false; |
|
996 | + } |
|
997 | + } |
|
998 | + |
|
999 | + try { |
|
1000 | + if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) { |
|
1001 | + //adding fix for UTF-8 CSV preview |
|
1002 | + $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL; |
|
1003 | + $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line); |
|
1004 | + } |
|
1005 | + |
|
1006 | + $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
|
1007 | + |
|
1008 | + }catch (Exception $e) { |
|
1009 | + |
|
1010 | + $this->logger->error($e->getMessage()); |
|
1011 | + } |
|
1012 | + |
|
1013 | + return true; |
|
1014 | + } |
|
1015 | + |
|
1016 | + public function get_fileystem_handler() |
|
1017 | + { |
|
1018 | + return $this; |
|
1019 | + } |
|
1020 | + |
|
1021 | + public function get_filesystem($system = "") |
|
1022 | + { |
|
1023 | + if ($system == "storage_filesystem_append") { |
|
1024 | + return $this->storage_filesystem_append; |
|
1025 | + } elseif ($system == "tmp_filesystem_append") { |
|
1026 | + return $this->tmp_filesystem_append; |
|
1027 | + } elseif ($system == "tmp_filesystem") { |
|
1028 | + return $this->tmp_filesystem; |
|
1029 | + } elseif ($system == "storage_filesystem") { |
|
1030 | + return $this->storage_filesystem; |
|
1031 | + } else { |
|
1032 | + return $this->start_filesystem; |
|
1033 | + } |
|
1034 | + } |
|
1035 | + |
|
1036 | + public function get_adapter($system) |
|
1037 | + { |
|
1038 | + if ($system == "tmp_filesystem") { |
|
1039 | + return $this->tmp_adapter; |
|
1040 | + } elseif ($system == "storage_filesystem") { |
|
1041 | + return $this->storage_adapter; |
|
1042 | + } else { |
|
1043 | + return $this->start_adapter; |
|
1044 | + } |
|
1045 | + } |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * File scan finished |
|
1049 | + * Method called when file scan is finished |
|
1050 | + * |
|
1051 | + * @return bool |
|
1052 | + */ |
|
1053 | + private function scan_finished() |
|
1054 | + { |
|
1055 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && |
|
1056 | + $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
1057 | + return false; |
|
1058 | + } |
|
1059 | + |
|
1060 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
1061 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
1062 | + } |
|
1063 | + |
|
1064 | + $this->logger->debug(sprintf(("File scan finished"))); |
|
1065 | + |
|
1066 | + return true; |
|
1067 | + } |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * Calculate bytes from MB value |
|
1071 | + * |
|
1072 | + * @param int $mb_size |
|
1073 | + * |
|
1074 | + * @return float|int |
|
1075 | + */ |
|
1076 | + private function calc_to_bytes($mb_size) |
|
1077 | + { |
|
1078 | + return $mb_size * (1024 * 1024); |
|
1079 | + } |
|
1080 | 1080 | |
1081 | 1081 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
103 | 103 | 'disable_asserts' => true, |
104 | 104 | ])); |
105 | - }catch (Exception $e) { |
|
105 | + } catch (Exception $e) { |
|
106 | 106 | $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
107 | 107 | } |
108 | 108 | |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | } |
646 | 646 | } |
647 | 647 | |
648 | - }catch (Exception $e) { |
|
648 | + } catch (Exception $e) { |
|
649 | 649 | |
650 | 650 | $this->logger->error($e->getMessage()); |
651 | 651 | |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | |
673 | 673 | $this->tmp_filesystem->delete($tmp_file); |
674 | 674 | |
675 | - }catch (Exception $e) { |
|
675 | + } catch (Exception $e) { |
|
676 | 676 | |
677 | 677 | $this->logger->error($e->getMessage()); |
678 | 678 | |
@@ -710,9 +710,11 @@ discard block |
||
710 | 710 | foreach ($_backup_files_list as $file) { |
711 | 711 | //processing rule folder capacity |
712 | 712 | if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
713 | - $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
713 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) { |
|
714 | + //bytes |
|
714 | 715 | { |
715 | 716 | $this->storage_filesystem->delete($file['path']); |
717 | + } |
|
716 | 718 | $_storage_size -= $file['size']; |
717 | 719 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
718 | 720 | "STORAGE SIZE LIMIT", |
@@ -979,7 +981,7 @@ discard block |
||
979 | 981 | if ($file['type'] == "dir") { |
980 | 982 | try { |
981 | 983 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
982 | - }catch (Exception $e) { |
|
984 | + } catch (Exception $e) { |
|
983 | 985 | $this->logger->error($e->getMessage()); |
984 | 986 | } |
985 | 987 | } |
@@ -1005,7 +1007,7 @@ discard block |
||
1005 | 1007 | |
1006 | 1008 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
1007 | 1009 | |
1008 | - }catch (Exception $e) { |
|
1010 | + } catch (Exception $e) { |
|
1009 | 1011 | |
1010 | 1012 | $this->logger->error($e->getMessage()); |
1011 | 1013 | } |
@@ -28,23 +28,16 @@ |
||
28 | 28 | |
29 | 29 | use League\Flysystem\Config; |
30 | 30 | use League\Flysystem\Filesystem; |
31 | - |
|
32 | 31 | use League\Flysystem\Adapter\Ftp as Adapter; |
33 | - |
|
34 | 32 | use League\Flysystem\Sftp\SftpAdapter; |
35 | - |
|
36 | 33 | use Srmklive\Dropbox\Client\DropboxClient; |
37 | 34 | use Srmklive\Dropbox\Adapter\DropboxAdapter; |
38 | - |
|
39 | 35 | use MicrosoftAzure\Storage\Common\ServicesBuilder; |
40 | 36 | use League\Flysystem\Azure\AzureAdapter; |
41 | - |
|
42 | 37 | use Aws\S3\S3Client; |
43 | 38 | use League\Flysystem\AwsS3v3\AwsS3Adapter; |
44 | - |
|
45 | 39 | use Mhetreramesh\Flysystem\BackblazeAdapter; |
46 | 40 | use BackblazeB2\Client as B2Client; |
47 | - |
|
48 | 41 | use Sabre\DAV\Client as SabreClient; |
49 | 42 | use League\Flysystem\WebDAV\WebDAVAdapter; |
50 | 43 |
@@ -162,26 +162,26 @@ discard block |
||
162 | 162 | private $logger; |
163 | 163 | private $xcloner; |
164 | 164 | |
165 | - public function __construct( Xcloner $xcloner_container ) { |
|
165 | + public function __construct(Xcloner $xcloner_container) { |
|
166 | 166 | $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
167 | 167 | $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
168 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName( "xcloner_remote_storage" ); |
|
168 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_remote_storage"); |
|
169 | 169 | $this->xcloner = $xcloner_container; |
170 | 170 | |
171 | - foreach($this->storage_fields as $main_key=>$array){ |
|
171 | + foreach ($this->storage_fields as $main_key=>$array) { |
|
172 | 172 | |
173 | - if(is_array($array)) { |
|
173 | + if (is_array($array)) { |
|
174 | 174 | foreach ($array as $key => $type) { |
175 | 175 | |
176 | - if( $type == "raw") { |
|
177 | - add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key, |
|
178 | - function ($value) { |
|
176 | + if ($type == "raw") { |
|
177 | + add_filter("pre_update_option_".$this->storage_fields['option_prefix'].$key, |
|
178 | + function($value) { |
|
179 | 179 | |
180 | 180 | return $this->simple_crypt($value, 'e'); |
181 | 181 | |
182 | 182 | }, 10, 1); |
183 | 183 | |
184 | - add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) { |
|
184 | + add_filter("option_".$this->storage_fields['option_prefix'].$key, function($value) { |
|
185 | 185 | |
186 | 186 | return $this->simple_crypt($value, 'd'); |
187 | 187 | |
@@ -201,22 +201,22 @@ discard block |
||
201 | 201 | * @param string $action |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - private function simple_crypt( $string, $action = 'e' ) { |
|
204 | + private function simple_crypt($string, $action = 'e') { |
|
205 | 205 | // you may change these values to your own |
206 | 206 | $secret_key = NONCE_KEY; |
207 | 207 | $secret_iv = NONCE_SALT; |
208 | 208 | |
209 | 209 | $output = $string; |
210 | 210 | $encrypt_method = "AES-256-CBC"; |
211 | - $key = hash( 'sha256', $secret_key ); |
|
212 | - $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 ); |
|
211 | + $key = hash('sha256', $secret_key); |
|
212 | + $iv = substr(hash('sha256', $secret_iv), 0, 16); |
|
213 | 213 | |
214 | - if( $action == 'e' && function_exists('openssl_encrypt')) { |
|
215 | - $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); |
|
214 | + if ($action == 'e' && function_exists('openssl_encrypt')) { |
|
215 | + $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv)); |
|
216 | 216 | } |
217 | - else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
218 | - $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); |
|
219 | - if($decrypt) { |
|
217 | + else if ($action == 'd' && function_exists('openssl_decrypt') && base64_decode($string)) { |
|
218 | + $decrypt = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); |
|
219 | + if ($decrypt) { |
|
220 | 220 | //we check if decrypt was succesful |
221 | 221 | $output = $decrypt; |
222 | 222 | } |
@@ -231,121 +231,121 @@ discard block |
||
231 | 231 | |
232 | 232 | public function get_available_storages() { |
233 | 233 | $return = array(); |
234 | - foreach ( $this->storage_fields as $storage => $data ) { |
|
235 | - $check_field = $this->storage_fields["option_prefix"] . $storage . "_enable"; |
|
236 | - if ( get_option( $check_field ) ) { |
|
237 | - $return[ $storage ] = $data['text']; |
|
234 | + foreach ($this->storage_fields as $storage => $data) { |
|
235 | + $check_field = $this->storage_fields["option_prefix"].$storage."_enable"; |
|
236 | + if (get_option($check_field)) { |
|
237 | + $return[$storage] = $data['text']; |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | 241 | return $return; |
242 | 242 | } |
243 | 243 | |
244 | - public function save( $action = "ftp" ) { |
|
245 | - if ( ! $action ) { |
|
244 | + public function save($action = "ftp") { |
|
245 | + if (!$action) { |
|
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | |
249 | - $storage = $this->xcloner_sanitization->sanitize_input_as_string( $action ); |
|
250 | - $this->logger->debug( sprintf( "Saving the remote storage %s options", strtoupper( $action ) ) ); |
|
249 | + $storage = $this->xcloner_sanitization->sanitize_input_as_string($action); |
|
250 | + $this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action))); |
|
251 | 251 | |
252 | - if ( is_array( $this->storage_fields[ $storage ] ) ) { |
|
253 | - foreach ( $this->storage_fields[ $storage ] as $field => $validation ) { |
|
254 | - $check_field = $this->storage_fields["option_prefix"] . $field; |
|
255 | - $sanitize_method = "sanitize_input_as_" . $validation; |
|
252 | + if (is_array($this->storage_fields[$storage])) { |
|
253 | + foreach ($this->storage_fields[$storage] as $field => $validation) { |
|
254 | + $check_field = $this->storage_fields["option_prefix"].$field; |
|
255 | + $sanitize_method = "sanitize_input_as_".$validation; |
|
256 | 256 | |
257 | - if ( ! isset( $_POST[ $check_field ] ) ) { |
|
258 | - $_POST[ $check_field ] = 0; |
|
257 | + if (!isset($_POST[$check_field])) { |
|
258 | + $_POST[$check_field] = 0; |
|
259 | 259 | } |
260 | 260 | |
261 | - if ( ! method_exists( $this->xcloner_sanitization, $sanitize_method ) ) { |
|
261 | + if (!method_exists($this->xcloner_sanitization, $sanitize_method)) { |
|
262 | 262 | $sanitize_method = "sanitize_input_as_string"; |
263 | 263 | } |
264 | 264 | |
265 | - $sanitized_value = $this->xcloner_sanitization->$sanitize_method( stripslashes( $_POST[ $check_field ] ) ); |
|
266 | - update_option( $check_field, $sanitized_value ); |
|
265 | + $sanitized_value = $this->xcloner_sanitization->$sanitize_method(stripslashes($_POST[$check_field])); |
|
266 | + update_option($check_field, $sanitized_value); |
|
267 | 267 | } |
268 | 268 | |
269 | - $this->xcloner->trigger_message( __( "%s storage settings saved.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] ); |
|
269 | + $this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | } |
273 | 273 | |
274 | - public function check( $action = "ftp" ) { |
|
274 | + public function check($action = "ftp") { |
|
275 | 275 | try { |
276 | - $this->verify_filesystem( $action ); |
|
277 | - $this->xcloner->trigger_message( __( "%s connection is valid.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] ); |
|
278 | - $this->logger->debug( sprintf( "Connection to remote storage %s is valid", strtoupper( $action ) ) ); |
|
279 | - } catch ( Exception $e ) { |
|
280 | - $this->xcloner->trigger_message( "%s connection error: " . $e->getMessage(), "error", $this->storage_fields[ $action ]['text'] ); |
|
276 | + $this->verify_filesystem($action); |
|
277 | + $this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']); |
|
278 | + $this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action))); |
|
279 | + }catch (Exception $e) { |
|
280 | + $this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", $this->storage_fields[$action]['text']); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | 285 | * @param string $storage_type |
286 | 286 | */ |
287 | - public function verify_filesystem( $storage_type ) { |
|
288 | - $method = "get_" . $storage_type . "_filesystem"; |
|
287 | + public function verify_filesystem($storage_type) { |
|
288 | + $method = "get_".$storage_type."_filesystem"; |
|
289 | 289 | |
290 | - $this->logger->info( sprintf( "Checking validity of the remote storage %s filesystem", strtoupper( $storage_type ) ) ); |
|
290 | + $this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type))); |
|
291 | 291 | |
292 | - if ( ! method_exists( $this, $method ) ) { |
|
292 | + if (!method_exists($this, $method)) { |
|
293 | 293 | return false; |
294 | 294 | } |
295 | 295 | |
296 | - list( $adapter, $filesystem ) = $this->$method(); |
|
296 | + list($adapter, $filesystem) = $this->$method(); |
|
297 | 297 | |
298 | - $test_file = substr( ".xcloner_" . md5( time() ), 0, 15 ); |
|
298 | + $test_file = substr(".xcloner_".md5(time()), 0, 15); |
|
299 | 299 | |
300 | - if ( $storage_type == "gdrive" ) { |
|
301 | - if ( ! is_array( $filesystem->listContents() ) ) { |
|
302 | - throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) ); |
|
300 | + if ($storage_type == "gdrive") { |
|
301 | + if (!is_array($filesystem->listContents())) { |
|
302 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
303 | 303 | } |
304 | - $this->logger->debug( sprintf( "I can list data from remote storage %s", strtoupper( $storage_type ) ) ); |
|
304 | + $this->logger->debug(sprintf("I can list data from remote storage %s", strtoupper($storage_type))); |
|
305 | 305 | |
306 | 306 | return true; |
307 | 307 | } |
308 | 308 | |
309 | 309 | //testing write access |
310 | - if ( ! $filesystem->write( $test_file, "data" ) ) { |
|
311 | - throw new Exception( __( "Could not write data", 'xcloner-backup-and-restore' ) ); |
|
310 | + if (!$filesystem->write($test_file, "data")) { |
|
311 | + throw new Exception(__("Could not write data", 'xcloner-backup-and-restore')); |
|
312 | 312 | } |
313 | - $this->logger->debug( sprintf( "I can write data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
313 | + $this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type))); |
|
314 | 314 | |
315 | 315 | //testing read access |
316 | - if ( ! $filesystem->has( $test_file ) ) { |
|
317 | - throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) ); |
|
316 | + if (!$filesystem->has($test_file)) { |
|
317 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
318 | 318 | } |
319 | - $this->logger->debug( sprintf( "I can read data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
319 | + $this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type))); |
|
320 | 320 | |
321 | 321 | //delete test file |
322 | - if ( ! $filesystem->delete( $test_file ) ) { |
|
323 | - throw new Exception( __( "Could not delete data", 'xcloner-backup-and-restore' ) ); |
|
322 | + if (!$filesystem->delete($test_file)) { |
|
323 | + throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore')); |
|
324 | 324 | } |
325 | - $this->logger->debug( sprintf( "I can delete data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
325 | + $this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type))); |
|
326 | 326 | |
327 | 327 | return true; |
328 | 328 | } |
329 | 329 | |
330 | - public function upload_backup_to_storage( $file, $storage ) { |
|
331 | - if ( ! $this->xcloner_file_system->get_storage_filesystem()->has( $file ) ) { |
|
332 | - $this->logger->info( sprintf( "File not found %s in local storage", $file ) ); |
|
330 | + public function upload_backup_to_storage($file, $storage) { |
|
331 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) { |
|
332 | + $this->logger->info(sprintf("File not found %s in local storage", $file)); |
|
333 | 333 | |
334 | 334 | return false; |
335 | 335 | } |
336 | 336 | |
337 | - $method = "get_" . $storage . "_filesystem"; |
|
337 | + $method = "get_".$storage."_filesystem"; |
|
338 | 338 | |
339 | - if ( ! method_exists( $this, $method ) ) { |
|
339 | + if (!method_exists($this, $method)) { |
|
340 | 340 | return false; |
341 | 341 | } |
342 | 342 | |
343 | - list( $remote_storage_adapter, $remote_storage_filesystem ) = $this->$method(); |
|
343 | + list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
|
344 | 344 | |
345 | 345 | //doing remote storage cleaning here |
346 | - $this->clean_remote_storage( $storage, $remote_storage_filesystem ); |
|
346 | + $this->clean_remote_storage($storage, $remote_storage_filesystem); |
|
347 | 347 | |
348 | - $this->logger->info( sprintf( "Transferring backup %s to remote storage %s", $file, strtoupper( $storage ) ), array( "" ) ); |
|
348 | + $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)), array("")); |
|
349 | 349 | |
350 | 350 | /*if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
351 | 351 | { |
@@ -213,8 +213,7 @@ |
||
213 | 213 | |
214 | 214 | if( $action == 'e' && function_exists('openssl_encrypt')) { |
215 | 215 | $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); |
216 | - } |
|
217 | - else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
216 | + } else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
218 | 217 | $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); |
219 | 218 | if($decrypt) { |
220 | 219 | //we check if decrypt was succesful |
@@ -31,10 +31,13 @@ |
||
31 | 31 | <?php if ($storage_selection): ?> |
32 | 32 | <option value="" |
33 | 33 | selected><?php echo __('Change To Local Storage...', 'xcloner-backup-and-restore') ?></option> |
34 | - <?php else: ?> |
|
34 | + <?php else { |
|
35 | + : ?> |
|
35 | 36 | <option value="" |
36 | 37 | selected><?php echo __('Change To Remote Storage...', 'xcloner-backup-and-restore') ?></option> |
37 | - <?php endif; ?> |
|
38 | + <?php endif; |
|
39 | +} |
|
40 | +?> |
|
38 | 41 | |
39 | 42 | <?php foreach ($available_storages as $storage => $text): ?> |
40 | 43 | <option value="<?php echo $storage ?>"<?php if ($storage == $storage_selection) |
@@ -149,6 +149,9 @@ |
||
149 | 149 | return $this->file_format_size(disk_free_space($this->xcloner_settings->get_xcloner_store_path())); |
150 | 150 | } |
151 | 151 | |
152 | + /** |
|
153 | + * @param double $bytes |
|
154 | + */ |
|
152 | 155 | public function file_format_size($bytes, $decimals = 2) { |
153 | 156 | $unit_list = array('B', 'KB', 'MB', 'GB', 'PB'); |
154 | 157 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | <label> |
27 | 27 | Off |
28 | 28 | <input type="checkbox" name="xcloner_ftp_enable" class="status" |
29 | - value="1" <?php if (get_option("xcloner_ftp_enable")) |
|
29 | + value="1" <?php if (get_option("xcloner_ftp_enable")) { |
|
30 | 30 | echo "checked" ?> \> |
31 | 31 | <span class="lever"></span> |
32 | 32 | On |
@@ -340,6 +340,7 @@ discard block |
||
340 | 340 | value=""><?php echo __("Please Select AWS S3 Region or Leave Unselected for Custom Endpoint") ?></option> |
341 | 341 | <?php |
342 | 342 | $aws_regions = $remote_storage->get_aws_regions(); |
343 | +} |
|
343 | 344 | |
344 | 345 | foreach ($aws_regions as $key => $region) { |
345 | 346 | ?> |
@@ -423,7 +424,7 @@ discard block |
||
423 | 424 | <label> |
424 | 425 | Off |
425 | 426 | <input type="checkbox" name="xcloner_dropbox_enable" class="status" |
426 | - value="1" <?php if (get_option("xcloner_dropbox_enable")) |
|
427 | + value="1" <?php if (get_option("xcloner_dropbox_enable")) { |
|
427 | 428 | echo "checked" ?> \> |
428 | 429 | <span class="lever"></span> |
429 | 430 | On |
@@ -957,6 +958,7 @@ discard block |
||
957 | 958 | <div class="center"> |
958 | 959 | <?php |
959 | 960 | $url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=xcloner-google-drive'), 'install-plugin_xcloner-google-drive'); |
961 | +} |
|
960 | 962 | ?> |
961 | 963 | <h6><?php echo __("This storage option requires the XCloner-Google-Drive Wordpress Plugin to be installed and activated.") ?></h6> |
962 | 964 | <h6><?php echo __("PHP 5.5 minimum version is required.") ?></h6> |
@@ -110,7 +110,8 @@ discard block |
||
110 | 110 | echo date($date_format." ".$time_format, $latest_backup['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
111 | 111 | ?> |
112 | 112 | </div> |
113 | - <?php else: ?> |
|
113 | + <?php else { |
|
114 | + : ?> |
|
114 | 115 | <div class="item"> |
115 | 116 | <div class="title"><?php echo __("No Backup Yet", 'xcloner-backup-and-restore') ?></div> |
116 | 117 | </div> |
@@ -123,7 +124,9 @@ discard block |
||
123 | 124 | <div class="title"><?php echo __("Total Size", 'xcloner-backup-and-restore') ?> |
124 | 125 | : |
125 | 126 | </div> |
126 | - <?php echo size_format($xcloner_file_system->get_storage_usage()); ?> |
|
127 | + <?php echo size_format($xcloner_file_system->get_storage_usage()); |
|
128 | +} |
|
129 | +?> |
|
127 | 130 | </div> |
128 | 131 | </blockquote> |
129 | 132 | <h5><?php echo __("Next Scheduled Backup", 'xcloner-backup-and-restore') ?></h5> |
@@ -54,7 +54,7 @@ |
||
54 | 54 | if (is_a($xcloner_plugin, 'Xcloner')) { |
55 | 55 | try { |
56 | 56 | $xcloner_plugin->get_xcloner_filesystem()->cleanup_tmp_directories(); |
57 | - }catch (Exception $e) { |
|
57 | + } catch (Exception $e) { |
|
58 | 58 | $xcloner_plugin->trigger_message_notice($e->getMessage()); |
59 | 59 | } |
60 | 60 |