GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch dev (953bb6)
by Liuta
01:57
created
restore/xcloner_restore.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 	private $backup_storage_dir;
107 107
 	private $parent_api;
108 108
 
109
-    /**
110
-     * Xcloner_Restore constructor.
111
-     * @param string $parent_api
112
-     * @throws Exception
113
-     */
109
+	/**
110
+	 * Xcloner_Restore constructor.
111
+	 * @param string $parent_api
112
+	 * @throws Exception
113
+	 */
114 114
 	public function __construct($parent_api = "")
115 115
 	{
116 116
 		register_shutdown_function(array($this, 'exception_handler'));
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
 
151 151
 	}
152 152
 
153
-    /**
154
-     * Exception handler method
155
-     */
153
+	/**
154
+	 * Exception handler method
155
+	 */
156 156
 	public function exception_handler() {
157 157
 		
158 158
 		$error = error_get_last();
@@ -164,20 +164,20 @@  discard block
 block discarded – undo
164 164
 	
165 165
 	}
166 166
 
167
-    /**
168
-     * @param $type
169
-     * @return mixed|string
170
-     */
167
+	/**
168
+	 * @param $type
169
+	 * @return mixed|string
170
+	 */
171 171
 	private function friendly_error_type($type) {
172
-	    static $levels=null;
173
-	    if ($levels===null) {
174
-	        $levels=[];
175
-	        foreach (get_defined_constants() as $key=>$value) {
176
-	            if (strpos($key,'E_')!==0) {continue;}
172
+		static $levels=null;
173
+		if ($levels===null) {
174
+			$levels=[];
175
+			foreach (get_defined_constants() as $key=>$value) {
176
+				if (strpos($key,'E_')!==0) {continue;}
177 177
 					$levels[$value]= $key; //substr($key,2);
178
-	        }
179
-	    }
180
-	    return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
178
+			}
179
+		}
180
+		return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}");
181 181
 	}
182 182
 	
183 183
 	public function get_logger_filename()
@@ -187,12 +187,12 @@  discard block
 block discarded – undo
187 187
 		return $filename;
188 188
 	}
189 189
 
190
-    /**
191
-     * Init method
192
-     *
193
-     * @return mixed|void
194
-     * @throws Exception
195
-     */
190
+	/**
191
+	 * Init method
192
+	 *
193
+	 * @return mixed|void
194
+	 * @throws Exception
195
+	 */
196 196
 	public function init()
197 197
 	{
198 198
 		if(isset($_POST['xcloner_action']) and $_POST['xcloner_action'])
@@ -216,12 +216,12 @@  discard block
 block discarded – undo
216 216
 		return $this->check_system();
217 217
 	}
218 218
 
219
-    /**
220
-     * Write file method
221
-     *
222
-     * @return bool|int
223
-     * @throws Exception
224
-     */
219
+	/**
220
+	 * Write file method
221
+	 *
222
+	 * @return bool|int
223
+	 * @throws Exception
224
+	 */
225 225
 	public function write_file_action()
226 226
 	{
227 227
 		if(isset($_POST['file']))
@@ -266,16 +266,16 @@  discard block
 block discarded – undo
266 266
 		
267 267
 	}
268 268
 
269
-    /**
270
-     * Connect to mysql server method
271
-     *
272
-     * @param $remote_mysql_host
273
-     * @param $remote_mysql_user
274
-     * @param $remote_mysql_pass
275
-     * @param $remote_mysql_db
276
-     * @return mysqli
277
-     * @throws Exception
278
-     */
269
+	/**
270
+	 * Connect to mysql server method
271
+	 *
272
+	 * @param $remote_mysql_host
273
+	 * @param $remote_mysql_user
274
+	 * @param $remote_mysql_pass
275
+	 * @param $remote_mysql_db
276
+	 * @return mysqli
277
+	 * @throws Exception
278
+	 */
279 279
 	public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db )
280 280
 	{
281 281
 		$this->logger->info(sprintf('Connecting to mysql database %s with %s@%s', $remote_mysql_db, $remote_mysql_user, $remote_mysql_host));
@@ -297,11 +297,11 @@  discard block
 block discarded – undo
297 297
 		return $mysqli;	
298 298
 	}
299 299
 
300
-    /**
301
-     * Restore mysql backup file
302
-     *
303
-     * @throws Exception
304
-     */
300
+	/**
301
+	 * Restore mysql backup file
302
+	 *
303
+	 * @throws Exception
304
+	 */
305 305
 	public function restore_mysql_backup_action()
306 306
 	{
307 307
 		$mysqldump_file 	= filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING);
@@ -432,14 +432,14 @@  discard block
 block discarded – undo
432 432
 		$this->send_response(200, $return);
433 433
 	}
434 434
 
435
-    /**
436
-     * Url replace method inside database backup file
437
-     *
438
-     * @param $search
439
-     * @param $replace
440
-     * @param $query
441
-     * @return mixed|string|string[]|null
442
-     */
435
+	/**
436
+	 * Url replace method inside database backup file
437
+	 *
438
+	 * @param $search
439
+	 * @param $replace
440
+	 * @param $query
441
+	 * @return mixed|string|string[]|null
442
+	 */
443 443
 	private function url_replace($search, $replace, $query)
444 444
 	{
445 445
 		$this->logger->info(sprintf("Doing url replace on query with length %s", strlen($query)), array("QUERY_REPLACE"));
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
 		return $query;
463 463
 	}
464 464
 
465
-    /**
466
-     * List backup files method
467
-     *
468
-     * @throws \League\Flysystem\FileNotFoundException
469
-     */
465
+	/**
466
+	 * List backup files method
467
+	 *
468
+	 * @throws \League\Flysystem\FileNotFoundException
469
+	 */
470 470
 	public function list_backup_files_action()
471 471
 	{
472 472
 		$backup_parts = array();
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 		$this->send_response(200, $return);
533 533
 	}
534 534
 
535
-    /**
536
-     * Finish backup restore method
537
-     *
538
-     * @throws \League\Flysystem\FileNotFoundException
539
-     */
535
+	/**
536
+	 * Finish backup restore method
537
+	 *
538
+	 * @throws \League\Flysystem\FileNotFoundException
539
+	 */
540 540
 	public function restore_finish_action()
541 541
 	{
542 542
 		$remote_path 		= filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING);
@@ -577,12 +577,12 @@  discard block
 block discarded – undo
577 577
 		$this->send_response(200, $return);
578 578
 	}
579 579
 
580
-    /**
581
-     * Delete backup temporary folder
582
-     *
583
-     * @param $remote_path
584
-     * @return bool
585
-     */
580
+	/**
581
+	 * Delete backup temporary folder
582
+	 *
583
+	 * @param $remote_path
584
+	 * @return bool
585
+	 */
586 586
 	private function delete_backup_temporary_folder($remote_path)
587 587
 	{
588 588
 		$this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS');
@@ -610,11 +610,11 @@  discard block
 block discarded – undo
610 610
 	
611 611
 	}
612 612
 
613
-    /**
614
-     * Delete restore script method
615
-     *
616
-     * @throws \League\Flysystem\FileNotFoundException
617
-     */
613
+	/**
614
+	 * Delete restore script method
615
+	 *
616
+	 * @throws \League\Flysystem\FileNotFoundException
617
+	 */
618 618
 	private function delete_self()
619 619
 	{
620 620
 		if($this->filesystem->has("vendor.phar"))
@@ -647,14 +647,14 @@  discard block
 block discarded – undo
647 647
 		
648 648
 	}
649 649
 
650
-    /**
651
-     * Update Wordpress url in wp-config.php method
652
-     * @param $wp_path
653
-     * @param $url
654
-     * @param $mysqli
655
-     * @return bool
656
-     * @throws Exception
657
-     */
650
+	/**
651
+	 * Update Wordpress url in wp-config.php method
652
+	 * @param $wp_path
653
+	 * @param $url
654
+	 * @param $mysqli
655
+	 * @return bool
656
+	 * @throws Exception
657
+	 */
658 658
 	private function update_wp_url($wp_path, $url, $mysqli)
659 659
 	{
660 660
 		$wp_config = $wp_path.DS."wp-config.php";
@@ -682,17 +682,17 @@  discard block
 block discarded – undo
682 682
 		return true;
683 683
 	}
684 684
 
685
-    /**
686
-     * Update local wp-config.php file method
687
-     *
688
-     * @param $remote_path
689
-     * @param $remote_mysql_host
690
-     * @param $remote_mysql_user
691
-     * @param $remote_mysql_pass
692
-     * @param $remote_mysql_db
693
-     * @return string
694
-     * @throws Exception
695
-     */
685
+	/**
686
+	 * Update local wp-config.php file method
687
+	 *
688
+	 * @param $remote_path
689
+	 * @param $remote_mysql_host
690
+	 * @param $remote_mysql_user
691
+	 * @param $remote_mysql_pass
692
+	 * @param $remote_mysql_db
693
+	 * @return string
694
+	 * @throws Exception
695
+	 */
696 696
 	private function update_wp_config($remote_path, $remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db)
697 697
 	{
698 698
 		$wp_config = $remote_path.DS."wp-config.php";
@@ -724,10 +724,10 @@  discard block
 block discarded – undo
724 724
 		
725 725
 	}
726 726
 
727
-    /**
728
-     * List mysqldump database backup files
729
-     *
730
-     */
727
+	/**
728
+	 * List mysqldump database backup files
729
+	 *
730
+	 */
731 731
 	public function list_mysqldump_backups_action()
732 732
 	{
733 733
 		$source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING);
@@ -777,12 +777,12 @@  discard block
 block discarded – undo
777 777
 		$this->send_response(200, $return);
778 778
 	}
779 779
 
780
-    /**
781
-     * Get backup hash method
782
-     *
783
-     * @param $backup_file
784
-     * @return bool
785
-     */
780
+	/**
781
+	 * Get backup hash method
782
+	 *
783
+	 * @param $backup_file
784
+	 * @return bool
785
+	 */
786 786
 	private function get_hash_from_backup($backup_file)
787 787
 	{
788 788
 		if(!$backup_file)
@@ -796,11 +796,11 @@  discard block
 block discarded – undo
796 796
 		return false;
797 797
 	}
798 798
 
799
-    /**
800
-     * List backup archives found on local system
801
-     *
802
-     * @throws \League\Flysystem\FileNotFoundException
803
-     */
799
+	/**
800
+	 * List backup archives found on local system
801
+	 *
802
+	 * @throws \League\Flysystem\FileNotFoundException
803
+	 */
804 804
 	public function list_backup_archives_action()
805 805
 	{
806 806
 		$local_backup_file = filter_input(INPUT_POST, 'local_backup_file', FILTER_SANITIZE_STRING);
@@ -859,12 +859,12 @@  discard block
 block discarded – undo
859 859
 		
860 860
 	}
861 861
 
862
-    /**
863
-     * Restore backup archive to local path
864
-     *
865
-     * @throws \League\Flysystem\FileNotFoundException
866
-     * @throws \splitbrain\PHPArchive\ArchiveIOException
867
-     */
862
+	/**
863
+	 * Restore backup archive to local path
864
+	 *
865
+	 * @throws \League\Flysystem\FileNotFoundException
866
+	 * @throws \splitbrain\PHPArchive\ArchiveIOException
867
+	 */
868 868
 	public function restore_backup_to_path_action()
869 869
 	{
870 870
 		$source_backup_file 	= filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING);
@@ -939,9 +939,9 @@  discard block
 block discarded – undo
939 939
 		$this->send_response(200, $return);
940 940
 	}
941 941
 
942
-    /**
943
-     * Get current directory method
944
-     */
942
+	/**
943
+	 * Get current directory method
944
+	 */
945 945
 	public function get_current_directory_action()
946 946
 	{	
947 947
 		global $wpdb;
@@ -975,11 +975,11 @@  discard block
 block discarded – undo
975 975
 		$this->send_response(200, $return);
976 976
 	}
977 977
 
978
-    /**
979
-     * Check current filesystem
980
-     *
981
-     * @throws Exception
982
-     */
978
+	/**
979
+	 * Check current filesystem
980
+	 *
981
+	 * @throws Exception
982
+	 */
983 983
 	public function check_system()
984 984
 	{
985 985
 		//check if i can write
@@ -1001,35 +1001,35 @@  discard block
 block discarded – undo
1001 1001
 		$this->send_response(200, $return);
1002 1002
 	}
1003 1003
 
1004
-    /**
1005
-     * Return bytes from human readable value
1006
-     *
1007
-     * @param $val
1008
-     * @return int
1009
-     *
1010
-     */
1011
-    private function return_bytes($val) {
1012
-        $numeric_val = (int)trim($val);
1013
-        $last = strtolower($val[strlen($val)-1]);
1014
-        switch($last) {
1015
-            // The 'G' modifier is available since PHP 5.1.0
1016
-            case 'g':
1017
-                $numeric_val *= 1024;
1018
-            case 'm':
1019
-                $numeric_val *= 1024;
1020
-            case 'k':
1021
-                $numeric_val *= 1024;
1022
-        }
1004
+	/**
1005
+	 * Return bytes from human readable value
1006
+	 *
1007
+	 * @param $val
1008
+	 * @return int
1009
+	 *
1010
+	 */
1011
+	private function return_bytes($val) {
1012
+		$numeric_val = (int)trim($val);
1013
+		$last = strtolower($val[strlen($val)-1]);
1014
+		switch($last) {
1015
+			// The 'G' modifier is available since PHP 5.1.0
1016
+			case 'g':
1017
+				$numeric_val *= 1024;
1018
+			case 'm':
1019
+				$numeric_val *= 1024;
1020
+			case 'k':
1021
+				$numeric_val *= 1024;
1022
+		}
1023 1023
 
1024
-        return $numeric_val;
1025
-    }
1024
+		return $numeric_val;
1025
+	}
1026 1026
 
1027
-    /**
1028
-     * Check if backup archive os multipart
1029
-     *
1030
-     * @param $backup_name
1031
-     * @return bool
1032
-     */
1027
+	/**
1028
+	 * Check if backup archive os multipart
1029
+	 *
1030
+	 * @param $backup_name
1031
+	 * @return bool
1032
+	 */
1033 1033
 	public function is_multipart($backup_name)
1034 1034
 	{
1035 1035
 		if(stristr($backup_name, "-multipart"))
@@ -1038,13 +1038,13 @@  discard block
 block discarded – undo
1038 1038
 		return false;	
1039 1039
 	}
1040 1040
 
1041
-    /**
1042
-     * Get backup archive size
1043
-     *
1044
-     * @param $backup_name
1045
-     * @return bool|false|int
1046
-     * @throws \League\Flysystem\FileNotFoundException
1047
-     */
1041
+	/**
1042
+	 * Get backup archive size
1043
+	 *
1044
+	 * @param $backup_name
1045
+	 * @return bool|false|int
1046
+	 * @throws \League\Flysystem\FileNotFoundException
1047
+	 */
1048 1048
 	public function get_backup_size($backup_name)
1049 1049
 	{
1050 1050
 		$backup_size = $this->filesystem->getSize($backup_name);
@@ -1058,12 +1058,12 @@  discard block
 block discarded – undo
1058 1058
 		return $backup_size;
1059 1059
 	}
1060 1060
 
1061
-    /**
1062
-     * Get multipart backup files list
1063
-     * @param $backup_name
1064
-     * @return array
1065
-     * @throws \League\Flysystem\FileNotFoundException
1066
-     */
1061
+	/**
1062
+	 * Get multipart backup files list
1063
+	 * @param $backup_name
1064
+	 * @return array
1065
+	 * @throws \League\Flysystem\FileNotFoundException
1066
+	 */
1067 1067
 	public function get_multipart_files($backup_name)
1068 1068
 	{
1069 1069
 		$files = array();
@@ -1084,58 +1084,58 @@  discard block
 block discarded – undo
1084 1084
 		return $files;
1085 1085
 	}
1086 1086
 
1087
-    /**
1088
-     * Sort_by method
1089
-     *
1090
-     * @param $array
1091
-     * @param $field
1092
-     * @param string $direction
1093
-     * @return bool
1094
-     */
1095
-    private function sort_by( &$array, $field, $direction = 'asc')
1096
-    {
1097
-        $direction = strtolower($direction);
1087
+	/**
1088
+	 * Sort_by method
1089
+	 *
1090
+	 * @param $array
1091
+	 * @param $field
1092
+	 * @param string $direction
1093
+	 * @return bool
1094
+	 */
1095
+	private function sort_by( &$array, $field, $direction = 'asc')
1096
+	{
1097
+		$direction = strtolower($direction);
1098 1098
 
1099
-        usort($array,
1100
-            function($a, $b) use($field, $direction){
1099
+		usort($array,
1100
+			function($a, $b) use($field, $direction){
1101 1101
 
1102
-                $a = $a[$field];
1103
-                $b = $b[$field];
1102
+				$a = $a[$field];
1103
+				$b = $b[$field];
1104 1104
 
1105
-                if ($a == $b)
1106
-                {
1107
-                    return 0;
1108
-                }
1105
+				if ($a == $b)
1106
+				{
1107
+					return 0;
1108
+				}
1109 1109
 
1110
-                if($direction == 'desc') {
1111
-                    if($a > $b) {
1112
-                        return -1;
1113
-                    }
1114
-                    else{
1115
-                        return 1;
1116
-                    }
1117
-                }else {
1118
-                    if($a < $b) {
1119
-                        return -1;
1120
-                    }
1121
-                    else{
1122
-                        return 1;
1123
-                    }
1124
-                }
1110
+				if($direction == 'desc') {
1111
+					if($a > $b) {
1112
+						return -1;
1113
+					}
1114
+					else{
1115
+						return 1;
1116
+					}
1117
+				}else {
1118
+					if($a < $b) {
1119
+						return -1;
1120
+					}
1121
+					else{
1122
+						return 1;
1123
+					}
1124
+				}
1125 1125
 
1126
-                //return ($a.($direction == 'desc' ? '>' : '<').$b) ? -1 : 1;
1127
-            }
1128
-        );
1126
+				//return ($a.($direction == 'desc' ? '>' : '<').$b) ? -1 : 1;
1127
+			}
1128
+		);
1129 1129
 
1130
-        return true;
1131
-    }
1130
+		return true;
1131
+	}
1132 1132
 
1133
-    /**
1134
-     * Send response method
1135
-     *
1136
-     * @param int $status
1137
-     * @param $response
1138
-     */
1133
+	/**
1134
+	 * Send response method
1135
+	 *
1136
+	 * @param int $status
1137
+	 * @param $response
1138
+	 */
1139 1139
 	public static function send_response($status = 200, $response)
1140 1140
 	{
1141 1141
 		header("Access-Control-Allow-Origin: *");
@@ -1158,12 +1158,12 @@  discard block
 block discarded – undo
1158 1158
 		exit;
1159 1159
 	}
1160 1160
 
1161
-    /**
1162
-     * Serialize fix methods below for mysql query lines
1163
-     *
1164
-     * @param $query
1165
-     * @return string|string[]|null
1166
-     */
1161
+	/**
1162
+	 * Serialize fix methods below for mysql query lines
1163
+	 *
1164
+	 * @param $query
1165
+	 * @return string|string[]|null
1166
+	 */
1167 1167
 	 
1168 1168
 	function do_serialized_fix($query)
1169 1169
 	{
@@ -1176,51 +1176,51 @@  discard block
 block discarded – undo
1176 1176
 					$m[3] = "";
1177 1177
 					
1178 1178
 					$data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";';
1179
-	              //return $this->unescape_quotes($data);
1179
+				  //return $this->unescape_quotes($data);
1180 1180
 	              
1181
-	              return $data;
1182
-	            }, $query);
1181
+				  return $data;
1182
+				}, $query);
1183 1183
 	}
1184 1184
 
1185
-    /**
1186
-     * Unescape quotes method
1187
-     *
1188
-     * @param $value
1189
-     * @return mixed
1190
-     */
1185
+	/**
1186
+	 * Unescape quotes method
1187
+	 *
1188
+	 * @param $value
1189
+	 * @return mixed
1190
+	 */
1191 1191
 	private function unescape_quotes($value) {
1192 1192
 		return str_replace('\"', '"', $value);
1193 1193
 	}
1194 1194
 
1195
-    /**
1196
-     * Unescape mysql method
1197
-     *
1198
-     * @param $value
1199
-     * @return mixed
1200
-     */
1195
+	/**
1196
+	 * Unescape mysql method
1197
+	 *
1198
+	 * @param $value
1199
+	 * @return mixed
1200
+	 */
1201 1201
 	private function unescape_mysql($value) {
1202 1202
 		return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z",  "\'", '\"'),
1203 1203
 						   array("\\",   "\0",  "\n",  "\r",  "\x1a", "'", '"'), 
1204 1204
 						   $value);
1205 1205
 	}
1206 1206
 
1207
-    /**
1208
-     * Check if string is in serialized format
1209
-     *
1210
-     * @param $s
1211
-     * @return bool
1212
-     */
1207
+	/**
1208
+	 * Check if string is in serialized format
1209
+	 *
1210
+	 * @param $s
1211
+	 * @return bool
1212
+	 */
1213 1213
 	private function has_serialized($s)
1214 1214
 	{
1215 1215
 		if(
1216
-		    stristr($s, '{' ) != false &&
1217
-		    stristr($s, '}' ) != false &&
1218
-		    stristr($s, ';' ) != false &&
1219
-		    stristr($s, ':' ) != false
1220
-		    ){
1221
-		    return true;
1216
+			stristr($s, '{' ) != false &&
1217
+			stristr($s, '}' ) != false &&
1218
+			stristr($s, ';' ) != false &&
1219
+			stristr($s, ':' ) != false
1220
+			){
1221
+			return true;
1222 1222
 		}else{
1223
-		    return false;
1223
+			return false;
1224 1224
 		}
1225 1225
 
1226 1226
 	}
Please login to merge, or discard this patch.
admin/partials/xcloner_manage_backups_page.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 $storage_selection = "";
8 8
 
9 9
 if (isset($_GET['storage_selection']) and $_GET['storage_selection']) {
10
-    $storage_selection = $xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']);
10
+	$storage_selection = $xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']);
11 11
 }
12 12
 
13 13
 //$backup_list = $xcloner_file_system->get_backup_archives_list($storage_selection);
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 
39 39
             <?php foreach ($available_storages as $storage => $text): ?>
40 40
                 <option value="<?php echo $storage ?>"<?php if ($storage == $storage_selection)
41
-                    echo "selected" ?>><?php echo $text ?></option>
41
+					echo "selected" ?>><?php echo $text ?></option>
42 42
             <?php endforeach ?>
43 43
         </select>
44 44
         <?php endif ?>
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
 
67 67
         <?php
68
-        /*$i = 0;
68
+		/*$i = 0;
69 69
         foreach ($backup_list as $file_info):?>
70 70
             <?php
71 71
             if ($storage_selection == "gdrive") {
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
                 <div class="row">
303 303
                     <div class="col s12 label">
304 304
                         <label><?php echo sprintf(__('Send %s to remote storage', 'xcloner-backup-and-restore'),
305
-                                "<span class='backup_name'></span>") ?></label>
305
+								"<span class='backup_name'></span>") ?></label>
306 306
                     </div>
307 307
                     <div class="input-field col s8 m10">
308 308
                         <select name="transfer_storage" id="transfer_storage" class="validate" required>
Please login to merge, or discard this patch.
includes/class-xcloner-settings.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -56,30 +56,30 @@  discard block
 block discarded – undo
56 56
 
57 57
 	public function get_xcloner_encryption_key() {
58 58
 
59
-	    if(!get_option('xcloner_encryption_key') )
60
-        {
61
-	        return $this->randomString(35);
62
-        }
63
-
64
-	    return get_option('xcloner_encryption_key');
65
-    }
66
-
67
-    /**
68
-     * Create a random string
69
-     * @author	XEWeb <>
70
-     * @param $length the length of the string to create
71
-     * @return $str the string
72
-     */
73
-    private function randomString($length = 6) {
74
-        $str = "";
75
-        $characters = array_merge(range('A','Z'), range('a','z'), range('0','9'));
76
-        $max = count($characters) - 1;
77
-        for ($i = 0; $i < $length; $i++) {
78
-            $rand = mt_rand(0, $max);
79
-            $str .= $characters[$rand];
80
-        }
81
-        return $str;
82
-    }
59
+		if(!get_option('xcloner_encryption_key') )
60
+		{
61
+			return $this->randomString(35);
62
+		}
63
+
64
+		return get_option('xcloner_encryption_key');
65
+	}
66
+
67
+	/**
68
+	 * Create a random string
69
+	 * @author	XEWeb <>
70
+	 * @param $length the length of the string to create
71
+	 * @return $str the string
72
+	 */
73
+	private function randomString($length = 6) {
74
+		$str = "";
75
+		$characters = array_merge(range('A','Z'), range('a','z'), range('0','9'));
76
+		$max = count($characters) - 1;
77
+		for ($i = 0; $i < $length; $i++) {
78
+			$rand = mt_rand(0, $max);
79
+			$str .= $characters[$rand];
80
+		}
81
+		return $str;
82
+	}
83 83
 
84 84
 	public function get_xcloner_tmp_path_suffix() {
85 85
 		return "xcloner" . $this->get_hash();
@@ -328,40 +328,40 @@  discard block
 block discarded – undo
328 328
 		);
329 329
 
330 330
 		register_setting( 'xcloner_general_settings_group', 'xcloner_store_path', array(
331
-            $this->xcloner_sanitization,
332
-            "sanitize_input_as_absolute_path"
333
-        ) );
334
-        add_settings_field(
335
-            'xcloner_store_path',
336
-            __( 'Backup Storage Location', 'xcloner-backup-and-restore' ),
337
-            array( $this, 'do_form_text_field' ),
338
-            'xcloner_settings_page',
339
-            'xcloner_general_settings_group',
340
-            array(
341
-                'xcloner_store_path',
342
-                __( 'Location where XCloner will store the Backup archives.', 'xcloner-backup-and-restore' ),
343
-                $this->get_xcloner_store_path(),
344
-                //'disabled'
345
-            )
346
-        );
347
-
348
-        register_setting( 'xcloner_general_settings_group', 'xcloner_encryption_key', array(
349
-            $this->xcloner_sanitization,
350
-            "sanitize_input_as_string"
351
-        ) );
352
-        add_settings_field(
353
-            'xcloner_encryption_key',
354
-            __( 'Backup Encryption Key', 'xcloner-backup-and-restore' ),
355
-            array( $this, 'do_form_text_field' ),
356
-            'xcloner_settings_page',
357
-            'xcloner_general_settings_group',
358
-            array(
359
-                'xcloner_encryption_key',
360
-                __( 'Backup Encryption Key used to Encrypt/Decrypt backups, you might want to save this somewhere else as well.', 'xcloner-backup-and-restore' ),
361
-                $this->get_xcloner_encryption_key(),
362
-                //'disabled'
363
-            )
364
-        );
331
+			$this->xcloner_sanitization,
332
+			"sanitize_input_as_absolute_path"
333
+		) );
334
+		add_settings_field(
335
+			'xcloner_store_path',
336
+			__( 'Backup Storage Location', 'xcloner-backup-and-restore' ),
337
+			array( $this, 'do_form_text_field' ),
338
+			'xcloner_settings_page',
339
+			'xcloner_general_settings_group',
340
+			array(
341
+				'xcloner_store_path',
342
+				__( 'Location where XCloner will store the Backup archives.', 'xcloner-backup-and-restore' ),
343
+				$this->get_xcloner_store_path(),
344
+				//'disabled'
345
+			)
346
+		);
347
+
348
+		register_setting( 'xcloner_general_settings_group', 'xcloner_encryption_key', array(
349
+			$this->xcloner_sanitization,
350
+			"sanitize_input_as_string"
351
+		) );
352
+		add_settings_field(
353
+			'xcloner_encryption_key',
354
+			__( 'Backup Encryption Key', 'xcloner-backup-and-restore' ),
355
+			array( $this, 'do_form_text_field' ),
356
+			'xcloner_settings_page',
357
+			'xcloner_general_settings_group',
358
+			array(
359
+				'xcloner_encryption_key',
360
+				__( 'Backup Encryption Key used to Encrypt/Decrypt backups, you might want to save this somewhere else as well.', 'xcloner-backup-and-restore' ),
361
+				$this->get_xcloner_encryption_key(),
362
+				//'disabled'
363
+			)
364
+		);
365 365
 
366 366
 		register_setting( 'xcloner_general_settings_group', 'xcloner_enable_log', array(
367 367
 			$this->xcloner_sanitization,
@@ -627,18 +627,18 @@  discard block
 block discarded – undo
627 627
 			)
628 628
 		);
629 629
 
630
-        register_setting( 'xcloner_system_settings_group', 'xcloner_disable_email_notification' );
631
-        add_settings_field(
632
-            'xcloner_disable_email_notification',
633
-            __( 'Disable Email Notifications', 'xcloner-backup-and-restore' ),
634
-            array( $this, 'do_form_switch_field' ),
635
-            'xcloner_system_settings_page',
636
-            'xcloner_system_settings_group',
637
-            array(
638
-                'xcloner_disable_email_notification',
639
-                sprintf( __( 'Enable this option if you want the XCloner to NOT send email notifications on successful backups', 'xcloner-backup-and-restore' ), $this->get_table_prefix() )
640
-            )
641
-        );
630
+		register_setting( 'xcloner_system_settings_group', 'xcloner_disable_email_notification' );
631
+		add_settings_field(
632
+			'xcloner_disable_email_notification',
633
+			__( 'Disable Email Notifications', 'xcloner-backup-and-restore' ),
634
+			array( $this, 'do_form_switch_field' ),
635
+			'xcloner_system_settings_page',
636
+			'xcloner_system_settings_group',
637
+			array(
638
+				'xcloner_disable_email_notification',
639
+				sprintf( __( 'Enable this option if you want the XCloner to NOT send email notifications on successful backups', 'xcloner-backup-and-restore' ), $this->get_table_prefix() )
640
+			)
641
+		);
642 642
 
643 643
 		//REGISTERING THE 'CLEANUP SECTION' FIELDS
644 644
 		register_setting( 'xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_days', array(
Please login to merge, or discard this patch.
includes/class-xcloner-activator.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 
64 64
 		if ( version_compare( phpversion(), Xcloner_Activator::xcloner_minimum_version, '<' ) ) {
65 65
 			wp_die( '<p>' . sprintf( __( "XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s" ), Xcloner_Activator::xcloner_minimum_version, phpversion() ) . '</p>', __( "XCloner Activation Error" ), array( 'response'  => 500,
66
-			                                                                                                                                                                                                                                                       'back_link' => true
66
+																																																																   'back_link' => true
67 67
 			) );
68 68
 		}
69 69
 
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 			update_option( 'xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$" . PHP_EOL . "(.*)\.(svn|git)(.*)$" . PHP_EOL . "wp-content\/cache(.*)$" . PHP_EOL . "(.*)error_log$" );
153 153
 		}
154 154
 
155
-        if ( ! get_option( 'xcloner_regex_exclude' ) ) {
156
-            update_option( 'xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$" . PHP_EOL . "(.*)\.(svn|git)(.*)$" . PHP_EOL . "wp-content\/cache(.*)$" . PHP_EOL . "(.*)error_log$" );
157
-        }
155
+		if ( ! get_option( 'xcloner_regex_exclude' ) ) {
156
+			update_option( 'xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$" . PHP_EOL . "(.*)\.(svn|git)(.*)$" . PHP_EOL . "wp-content\/cache(.*)$" . PHP_EOL . "(.*)error_log$" );
157
+		}
158 158
 
159 159
 	}
160 160
 
Please login to merge, or discard this patch.
includes/class-xcloner-api.php 1 patch
Indentation   +1100 added lines, -1100 removed lines patch added patch discarded remove patch
@@ -43,903 +43,903 @@  discard block
 block discarded – undo
43 43
 class Xcloner_Api
44 44
 {
45 45
 
46
-    private $xcloner_database;
47
-    private $xcloner_settings;
48
-    private $xcloner_file_system;
49
-    private $xcloner_requirements;
50
-    private $xcloner_sanitization;
51
-    private $xcloner_encryption;
52
-    private $xcloner_remote_storage;
53
-    private $archive_system;
54
-    private $form_params;
55
-    private $logger;
56
-    private $xcloner_container;
57
-
58
-    /**
59
-     * XCloner_Api construct class
60
-     *
61
-     * @param Xcloner $xcloner_container [description]
62
-     */
63
-    public function __construct(Xcloner $xcloner_container)
64
-    {
65
-        global $wpdb;
66
-
67
-        if (WP_DEBUG) {
68
-            error_reporting(0);
69
-        }
70
-
71
-        if (ob_get_length()) {
72
-            ob_end_clean();
73
-        }
74
-        ob_start();
75
-
76
-        $wpdb->show_errors = false;
77
-
78
-        $this->xcloner_container = $xcloner_container;
79
-
80
-        $this->xcloner_settings         = $xcloner_container->get_xcloner_settings();
81
-        $this->logger                   = $xcloner_container->get_xcloner_logger()->withName("xcloner_api");
82
-        $this->xcloner_file_system      = $xcloner_container->get_xcloner_filesystem();
83
-        $this->xcloner_sanitization     = $xcloner_container->get_xcloner_sanitization();
84
-        $this->xcloner_requirements     = $xcloner_container->get_xcloner_requirements();
85
-        $this->archive_system           = $xcloner_container->get_archive_system();
86
-        $this->xcloner_database         = $xcloner_container->get_xcloner_database();
87
-        $this->xcloner_scheduler        = $xcloner_container->get_xcloner_scheduler();
88
-        $this->xcloner_encryption       = $xcloner_container->get_xcloner_encryption();
89
-        $this->xcloner_remote_storage   = $xcloner_container->get_xcloner_remote_storage();
90
-
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']),
93
-                    0, 15));
94
-        }
95
-
96
-    }
97
-
98
-    /**
99
-     * Get XCloner Container
100
-     * @return XCloner return the XCloner container
101
-     */
102
-    public function get_xcloner_container()
103
-    {
104
-        return $this->xcloner_container;
105
-    }
106
-
107
-    /**
108
-     * Check if user has access to this class
109
-     * @return die() returns die() if user is not allowed
110
-     * @link http://www.wordpress.org
111
-     */
112
-    private function check_access()
113
-    {
114
-        if (function_exists('current_user_can') && !current_user_can('manage_options')) {
115
-            die("Not allowed access here!");
116
-        }
117
-    }
118
-
119
-    /**
120
-     * Initialize the database connection
121
-     */
122
-    public function init_db()
123
-    {
124
-        return;
125
-
126
-
127
-        $data['dbHostname'] = $this->xcloner_settings->get_db_hostname();
128
-        $data['dbUsername'] = $this->xcloner_settings->get_db_username();
129
-        $data['dbPassword'] = $this->xcloner_settings->get_db_password();
130
-        $data['dbDatabase'] = $this->xcloner_settings->get_db_database();
131
-
132
-
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";
136
-
137
-        try {
138
-            $this->xcloner_database->init($data);
139
-
140
-        } catch (Exception $e) {
141
-
142
-            $this->send_response($e->getMessage());
143
-            $this->logger->error($e->getMessage());
144
-
145
-        }
146
-
147
-        return $this->xcloner_database;
148
-
149
-
150
-    }
151
-
152
-    /*
46
+	private $xcloner_database;
47
+	private $xcloner_settings;
48
+	private $xcloner_file_system;
49
+	private $xcloner_requirements;
50
+	private $xcloner_sanitization;
51
+	private $xcloner_encryption;
52
+	private $xcloner_remote_storage;
53
+	private $archive_system;
54
+	private $form_params;
55
+	private $logger;
56
+	private $xcloner_container;
57
+
58
+	/**
59
+	 * XCloner_Api construct class
60
+	 *
61
+	 * @param Xcloner $xcloner_container [description]
62
+	 */
63
+	public function __construct(Xcloner $xcloner_container)
64
+	{
65
+		global $wpdb;
66
+
67
+		if (WP_DEBUG) {
68
+			error_reporting(0);
69
+		}
70
+
71
+		if (ob_get_length()) {
72
+			ob_end_clean();
73
+		}
74
+		ob_start();
75
+
76
+		$wpdb->show_errors = false;
77
+
78
+		$this->xcloner_container = $xcloner_container;
79
+
80
+		$this->xcloner_settings         = $xcloner_container->get_xcloner_settings();
81
+		$this->logger                   = $xcloner_container->get_xcloner_logger()->withName("xcloner_api");
82
+		$this->xcloner_file_system      = $xcloner_container->get_xcloner_filesystem();
83
+		$this->xcloner_sanitization     = $xcloner_container->get_xcloner_sanitization();
84
+		$this->xcloner_requirements     = $xcloner_container->get_xcloner_requirements();
85
+		$this->archive_system           = $xcloner_container->get_archive_system();
86
+		$this->xcloner_database         = $xcloner_container->get_xcloner_database();
87
+		$this->xcloner_scheduler        = $xcloner_container->get_xcloner_scheduler();
88
+		$this->xcloner_encryption       = $xcloner_container->get_xcloner_encryption();
89
+		$this->xcloner_remote_storage   = $xcloner_container->get_xcloner_remote_storage();
90
+
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']),
93
+					0, 15));
94
+		}
95
+
96
+	}
97
+
98
+	/**
99
+	 * Get XCloner Container
100
+	 * @return XCloner return the XCloner container
101
+	 */
102
+	public function get_xcloner_container()
103
+	{
104
+		return $this->xcloner_container;
105
+	}
106
+
107
+	/**
108
+	 * Check if user has access to this class
109
+	 * @return die() returns die() if user is not allowed
110
+	 * @link http://www.wordpress.org
111
+	 */
112
+	private function check_access()
113
+	{
114
+		if (function_exists('current_user_can') && !current_user_can('manage_options')) {
115
+			die("Not allowed access here!");
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * Initialize the database connection
121
+	 */
122
+	public function init_db()
123
+	{
124
+		return;
125
+
126
+
127
+		$data['dbHostname'] = $this->xcloner_settings->get_db_hostname();
128
+		$data['dbUsername'] = $this->xcloner_settings->get_db_username();
129
+		$data['dbPassword'] = $this->xcloner_settings->get_db_password();
130
+		$data['dbDatabase'] = $this->xcloner_settings->get_db_database();
131
+
132
+
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";
136
+
137
+		try {
138
+			$this->xcloner_database->init($data);
139
+
140
+		} catch (Exception $e) {
141
+
142
+			$this->send_response($e->getMessage());
143
+			$this->logger->error($e->getMessage());
144
+
145
+		}
146
+
147
+		return $this->xcloner_database;
148
+
149
+
150
+	}
151
+
152
+	/*
153 153
      * Save Schedule API
154 154
      */
155
-    public function save_schedule()
156
-    {
157
-        global $wpdb;
158
-
159
-        $this->check_access();
160
-
161
-        $scheduler = $this->xcloner_scheduler;
162
-        $params = array();
163
-        $schedule = array();
164
-        $response = array();
165
-
166
-        if (isset($_POST['data'])) {
167
-            $params = json_decode(stripslashes($_POST['data']));
168
-        }
169
-
170
-        $this->process_params($params);
171
-
172
-        if (isset($_POST['id'])) {
173
-
174
-            $this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']);
175
-            $this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']);
176
-            if ($_POST['diff_start_date']) {
177
-                $this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date']));
178
-            } else {
179
-                $this->form_params['backup_params']['diff_start_date'] = "";
180
-            }
181
-            $this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']);
182
-            $this->form_params['backup_params']['backup_encrypt'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['backup_encrypt']);
183
-            $this->form_params['backup_params']['start_at'] = strtotime($_POST['schedule_start_date']);
184
-            $this->form_params['backup_params']['schedule_frequency'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_frequency']);
185
-            $this->form_params['backup_params']['schedule_storage'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_storage']);
186
-            $this->form_params['database'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['table_params'])));
187
-            $this->form_params['excluded_files'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['excluded_files'])));
188
-
189
-            //$this->form_params['backup_params']['backup_type'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_type']);
190
-
191
-            $tables = explode(PHP_EOL, $this->form_params['database']);
192
-            $return = array();
193
-
194
-            foreach ($tables as $table) {
195
-                $table = str_replace("\r", "", $table);
196
-                $data = explode(".", $table);
197
-                if (isset($data[1])) {
198
-                    $return[$data[0]][] = $data[1];
199
-                }
200
-            }
201
-
202
-            $this->form_params['database'] = ($return);
203
-
204
-            $excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']);
205
-            $return = array();
206
-
207
-            foreach ($excluded_files as $file) {
208
-                $file = str_replace("\r", "", $file);
209
-                if ($file) {
210
-                    $return[] = $file;
211
-                }
212
-            }
213
-
214
-            $this->form_params['excluded_files'] = ($return);
215
-
216
-            $schedule['start_at'] = $this->form_params['backup_params']['start_at'];
217
-
218
-            if (!isset($_POST['status'])) {
219
-                $schedule['status'] = 0;
220
-            } else {
221
-                $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
222
-            }
223
-        } else {
224
-
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']);
228
-
229
-            if ($schedule['start_at'] <= time()) {
230
-                $schedule['start_at'] = "";
231
-            }
232
-        }
233
-
234
-        if (!$schedule['start_at']) {
235
-            $schedule['start_at'] = date('Y-m-d H:i:s', time());
236
-        } else {
237
-            $schedule['start_at'] = date('Y-m-d H:i:s',
238
-                $schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS));
239
-        }
240
-
241
-        $schedule['name'] = $this->form_params['backup_params']['schedule_name'];
242
-        $schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency'];
243
-        if (!isset($this->form_params['backup_params']['schedule_storage'])) {
244
-            $this->form_params['backup_params']['schedule_storage'] = "";
245
-        }
246
-        $schedule['remote_storage'] = $this->form_params['backup_params']['schedule_storage'];
247
-        //$schedule['backup_type'] = $this->form_params['backup_params']['backup_type'];
248
-        $schedule['params'] = json_encode($this->form_params);
249
-
250
-        if (!isset($_POST['id'])) {
251
-            $wpdb->insert(
252
-                $wpdb->prefix . 'xcloner_scheduler',
253
-                $schedule,
254
-                array(
255
-                    '%s',
256
-                    '%s'
257
-                )
258
-            );
259
-        } else {
260
-            $wpdb->update(
261
-                $wpdb->prefix . 'xcloner_scheduler',
262
-                $schedule,
263
-                array('id' => $_POST['id']),
264
-                array(
265
-                    '%s',
266
-                    '%s'
267
-                )
268
-            );
269
-        }
270
-        if (isset($_POST['id'])) {
271
-            $scheduler->update_cron_hook($_POST['id']);
272
-        }
273
-
274
-        if ($wpdb->last_error) {
275
-            $response['error'] = 1;
276
-            $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/
277
-            ;
278
-
279
-        }
280
-
281
-        $scheduler->update_wp_cron_hooks();
282
-        $response['finished'] = 1;
283
-
284
-        $this->send_response($response);
285
-    }
286
-
287
-    /*
155
+	public function save_schedule()
156
+	{
157
+		global $wpdb;
158
+
159
+		$this->check_access();
160
+
161
+		$scheduler = $this->xcloner_scheduler;
162
+		$params = array();
163
+		$schedule = array();
164
+		$response = array();
165
+
166
+		if (isset($_POST['data'])) {
167
+			$params = json_decode(stripslashes($_POST['data']));
168
+		}
169
+
170
+		$this->process_params($params);
171
+
172
+		if (isset($_POST['id'])) {
173
+
174
+			$this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']);
175
+			$this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']);
176
+			if ($_POST['diff_start_date']) {
177
+				$this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date']));
178
+			} else {
179
+				$this->form_params['backup_params']['diff_start_date'] = "";
180
+			}
181
+			$this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']);
182
+			$this->form_params['backup_params']['backup_encrypt'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['backup_encrypt']);
183
+			$this->form_params['backup_params']['start_at'] = strtotime($_POST['schedule_start_date']);
184
+			$this->form_params['backup_params']['schedule_frequency'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_frequency']);
185
+			$this->form_params['backup_params']['schedule_storage'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_storage']);
186
+			$this->form_params['database'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['table_params'])));
187
+			$this->form_params['excluded_files'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['excluded_files'])));
188
+
189
+			//$this->form_params['backup_params']['backup_type'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_type']);
190
+
191
+			$tables = explode(PHP_EOL, $this->form_params['database']);
192
+			$return = array();
193
+
194
+			foreach ($tables as $table) {
195
+				$table = str_replace("\r", "", $table);
196
+				$data = explode(".", $table);
197
+				if (isset($data[1])) {
198
+					$return[$data[0]][] = $data[1];
199
+				}
200
+			}
201
+
202
+			$this->form_params['database'] = ($return);
203
+
204
+			$excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']);
205
+			$return = array();
206
+
207
+			foreach ($excluded_files as $file) {
208
+				$file = str_replace("\r", "", $file);
209
+				if ($file) {
210
+					$return[] = $file;
211
+				}
212
+			}
213
+
214
+			$this->form_params['excluded_files'] = ($return);
215
+
216
+			$schedule['start_at'] = $this->form_params['backup_params']['start_at'];
217
+
218
+			if (!isset($_POST['status'])) {
219
+				$schedule['status'] = 0;
220
+			} else {
221
+				$schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']);
222
+			}
223
+		} else {
224
+
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']);
228
+
229
+			if ($schedule['start_at'] <= time()) {
230
+				$schedule['start_at'] = "";
231
+			}
232
+		}
233
+
234
+		if (!$schedule['start_at']) {
235
+			$schedule['start_at'] = date('Y-m-d H:i:s', time());
236
+		} else {
237
+			$schedule['start_at'] = date('Y-m-d H:i:s',
238
+				$schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS));
239
+		}
240
+
241
+		$schedule['name'] = $this->form_params['backup_params']['schedule_name'];
242
+		$schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency'];
243
+		if (!isset($this->form_params['backup_params']['schedule_storage'])) {
244
+			$this->form_params['backup_params']['schedule_storage'] = "";
245
+		}
246
+		$schedule['remote_storage'] = $this->form_params['backup_params']['schedule_storage'];
247
+		//$schedule['backup_type'] = $this->form_params['backup_params']['backup_type'];
248
+		$schedule['params'] = json_encode($this->form_params);
249
+
250
+		if (!isset($_POST['id'])) {
251
+			$wpdb->insert(
252
+				$wpdb->prefix . 'xcloner_scheduler',
253
+				$schedule,
254
+				array(
255
+					'%s',
256
+					'%s'
257
+				)
258
+			);
259
+		} else {
260
+			$wpdb->update(
261
+				$wpdb->prefix . 'xcloner_scheduler',
262
+				$schedule,
263
+				array('id' => $_POST['id']),
264
+				array(
265
+					'%s',
266
+					'%s'
267
+				)
268
+			);
269
+		}
270
+		if (isset($_POST['id'])) {
271
+			$scheduler->update_cron_hook($_POST['id']);
272
+		}
273
+
274
+		if ($wpdb->last_error) {
275
+			$response['error'] = 1;
276
+			$response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/
277
+			;
278
+
279
+		}
280
+
281
+		$scheduler->update_wp_cron_hooks();
282
+		$response['finished'] = 1;
283
+
284
+		$this->send_response($response);
285
+	}
286
+
287
+	/*
288 288
      *
289 289
      * Backup Files API
290 290
      *
291 291
      */
292
-    public function backup_files()
293
-    {
294
-        $this->check_access();
295
-
296
-        $params = json_decode(stripslashes($_POST['data']));
297
-
298
-        $init = (int)$_POST['init'];
299
-
300
-        if ($params === null) {
301
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
302
-        }
303
-
304
-        $this->process_params($params);
305
-
306
-        $return['finished'] = 1;
307
-
308
-        //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
309
-        try {
310
-            $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'],
311
-                $this->form_params['extra'], $init);
312
-        } catch (Exception $e) {
313
-            $return = array();
314
-            $return['error'] = true;
315
-            $return['status'] = 500;
316
-            $return['error_message'] = $e->getMessage();
317
-
318
-            return $this->send_response($return, $hash = 1);
319
-        }
320
-
321
-        if ($return['finished']) {
322
-            $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
323
-            if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
324
-                $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
325
-            }
326
-        }
327
-
328
-        $data = $return;
329
-
330
-        //check if backup is finished
331
-        if ($return['finished']) {
332
-            if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) {
333
-                try {
334
-                    $from = "";
335
-                    $subject = "";
336
-                    $additional['lines_total'] = $return['extra']['lines_total'];
337
-                    $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'],
338
-                        $this->form_params, "", $additional);
339
-                } catch (Exception $e) {
340
-                    $this->logger->error($e->getMessage());
341
-                }
342
-            }
343
-            $this->xcloner_file_system->remove_tmp_filesystem();
344
-        }
345
-
346
-        return $this->send_response($data, $hash = 1);
347
-    }
348
-
349
-    /*
292
+	public function backup_files()
293
+	{
294
+		$this->check_access();
295
+
296
+		$params = json_decode(stripslashes($_POST['data']));
297
+
298
+		$init = (int)$_POST['init'];
299
+
300
+		if ($params === null) {
301
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
302
+		}
303
+
304
+		$this->process_params($params);
305
+
306
+		$return['finished'] = 1;
307
+
308
+		//$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init);
309
+		try {
310
+			$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'],
311
+				$this->form_params['extra'], $init);
312
+		} catch (Exception $e) {
313
+			$return = array();
314
+			$return['error'] = true;
315
+			$return['status'] = 500;
316
+			$return['error_message'] = $e->getMessage();
317
+
318
+			return $this->send_response($return, $hash = 1);
319
+		}
320
+
321
+		if ($return['finished']) {
322
+			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
323
+			if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) {
324
+				$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
325
+			}
326
+		}
327
+
328
+		$data = $return;
329
+
330
+		//check if backup is finished
331
+		if ($return['finished']) {
332
+			if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) {
333
+				try {
334
+					$from = "";
335
+					$subject = "";
336
+					$additional['lines_total'] = $return['extra']['lines_total'];
337
+					$this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'],
338
+						$this->form_params, "", $additional);
339
+				} catch (Exception $e) {
340
+					$this->logger->error($e->getMessage());
341
+				}
342
+			}
343
+			$this->xcloner_file_system->remove_tmp_filesystem();
344
+		}
345
+
346
+		return $this->send_response($data, $hash = 1);
347
+	}
348
+
349
+	/*
350 350
      *
351 351
      * Backup Database API
352 352
      *
353 353
      */
354
-    public function backup_database()
355
-    {
356
-        $this->check_access();
354
+	public function backup_database()
355
+	{
356
+		$this->check_access();
357 357
 
358
-        $params = json_decode(stripslashes($_POST['data']));
358
+		$params = json_decode(stripslashes($_POST['data']));
359 359
 
360
-        $init = (int)$_POST['init'];
360
+		$init = (int)$_POST['init'];
361 361
 
362
-        if ($params === null) {
363
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
364
-        }
362
+		if ($params === null) {
363
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
364
+		}
365 365
 
366
-        $this->process_params($params);
366
+		$this->process_params($params);
367 367
 
368
-        //$xcloner_database = $this->init_db();
369
-        $return = $this->xcloner_database->start_database_recursion($this->form_params['database'],
370
-            $this->form_params['extra'], $init);
368
+		//$xcloner_database = $this->init_db();
369
+		$return = $this->xcloner_database->start_database_recursion($this->form_params['database'],
370
+			$this->form_params['extra'], $init);
371 371
 
372
-        if (isset($return['error']) and $return['error']) {
373
-            $data['finished'] = 1;
374
-        } else {
375
-            $data['finished'] = $return['finished'];
376
-        }
372
+		if (isset($return['error']) and $return['error']) {
373
+			$data['finished'] = 1;
374
+		} else {
375
+			$data['finished'] = $return['finished'];
376
+		}
377 377
 
378
-        $data['extra'] = $return;
378
+		$data['extra'] = $return;
379 379
 
380
-        return $this->send_response($data, $hash = 1);
381
-    }
380
+		return $this->send_response($data, $hash = 1);
381
+	}
382 382
 
383
-    /*
383
+	/*
384 384
      *
385 385
      * Scan Filesystem API
386 386
      *
387 387
      */
388
-    public function scan_filesystem()
389
-    {
390
-        $this->check_access();
388
+	public function scan_filesystem()
389
+	{
390
+		$this->check_access();
391 391
 
392
-        $params = json_decode(stripslashes($_POST['data']));
393
-        $init = (int)$_POST['init'];
392
+		$params = json_decode(stripslashes($_POST['data']));
393
+		$init = (int)$_POST['init'];
394 394
 
395
-        if ($params === null) {
396
-            die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
397
-        }
395
+		if ($params === null) {
396
+			die('{"status":false,"msg":"The post_data parameter must be valid JSON"}');
397
+		}
398 398
 
399
-        $hash = $this->process_params($params);
399
+		$hash = $this->process_params($params);
400 400
 
401
-        $this->xcloner_file_system->set_excluded_files($this->form_params['excluded_files']);
401
+		$this->xcloner_file_system->set_excluded_files($this->form_params['excluded_files']);
402 402
 
403
-        $return = $this->xcloner_file_system->start_file_recursion($init);
403
+		$return = $this->xcloner_file_system->start_file_recursion($init);
404 404
 
405
-        $data["finished"] = !$return;
406
-        $data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num();
407
-        $data["last_logged_file"] = $this->xcloner_file_system->last_logged_file();
408
-        $data["total_files_size"] = sprintf("%.2f",
409
-            $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024));
405
+		$data["finished"] = !$return;
406
+		$data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num();
407
+		$data["last_logged_file"] = $this->xcloner_file_system->last_logged_file();
408
+		$data["total_files_size"] = sprintf("%.2f",
409
+			$this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024));
410 410
 
411
-        return $this->send_response($data, $hash = 1);
412
-    }
411
+		return $this->send_response($data, $hash = 1);
412
+	}
413 413
 
414
-    /*
414
+	/*
415 415
      *
416 416
      * Process params sent by the user
417 417
      *
418 418
      */
419
-    private function process_params($params)
420
-    {
421
-        if (isset($params->hash)) {
422
-            $this->xcloner_settings->set_hash($params->hash);
423
-        }
424
-
425
-        $this->form_params['extra'] = array();
426
-        $this->form_params['backup_params'] = array();
427
-
428
-        $this->form_params['database'] = array();
429
-
430
-        if (isset($params->backup_params)) {
431
-            foreach ($params->backup_params as $param) {
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(
434
-                    'POST',
435
-                    'fields filter'
436
-                ));
437
-            }
438
-        }
439
-
440
-        $this->form_params['database'] = array();
441
-
442
-        if (isset($params->table_params)) {
443
-            foreach ($params->table_params as $param) {
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(
446
-                    'POST',
447
-                    'database filter'
448
-                ));
449
-            }
450
-        }
451
-
452
-        $this->form_params['excluded_files'] = array();
453
-        if (isset($params->files_params)) {
454
-            foreach ($params->files_params as $param) {
455
-                $this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
456
-            }
457
-
458
-            $unique_exclude_files = array();
459
-
460
-            foreach ($params->files_params as $key => $param) {
461
-                if (!in_array($param->parent, $this->form_params['excluded_files'])) {
462
-                    //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
463
-                    $unique_exclude_files[] = $param->id;
464
-                    $this->logger->debug("Adding file filter " . $param->id . "\n", array(
465
-                        'POST',
466
-                        'exclude files filter'
467
-                    ));
468
-                }
469
-            }
470
-            $this->form_params['excluded_files'] = (array)$unique_exclude_files;
471
-
472
-        }
473
-
474
-        //$this->form_params['excluded_files'] =  array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default);
475
-
476
-        if (isset($params->extra)) {
477
-            foreach ($params->extra as $key => $value) {
478
-                $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
479
-            }
480
-        }
481
-
482
-        if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) {
483
-            $this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']);
484
-            $this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']);
485
-        }
486
-
487
-        return $this->xcloner_settings->get_hash();
488
-    }
489
-
490
-    /*
419
+	private function process_params($params)
420
+	{
421
+		if (isset($params->hash)) {
422
+			$this->xcloner_settings->set_hash($params->hash);
423
+		}
424
+
425
+		$this->form_params['extra'] = array();
426
+		$this->form_params['backup_params'] = array();
427
+
428
+		$this->form_params['database'] = array();
429
+
430
+		if (isset($params->backup_params)) {
431
+			foreach ($params->backup_params as $param) {
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(
434
+					'POST',
435
+					'fields filter'
436
+				));
437
+			}
438
+		}
439
+
440
+		$this->form_params['database'] = array();
441
+
442
+		if (isset($params->table_params)) {
443
+			foreach ($params->table_params as $param) {
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(
446
+					'POST',
447
+					'database filter'
448
+				));
449
+			}
450
+		}
451
+
452
+		$this->form_params['excluded_files'] = array();
453
+		if (isset($params->files_params)) {
454
+			foreach ($params->files_params as $param) {
455
+				$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
456
+			}
457
+
458
+			$unique_exclude_files = array();
459
+
460
+			foreach ($params->files_params as $key => $param) {
461
+				if (!in_array($param->parent, $this->form_params['excluded_files'])) {
462
+					//$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id);
463
+					$unique_exclude_files[] = $param->id;
464
+					$this->logger->debug("Adding file filter " . $param->id . "\n", array(
465
+						'POST',
466
+						'exclude files filter'
467
+					));
468
+				}
469
+			}
470
+			$this->form_params['excluded_files'] = (array)$unique_exclude_files;
471
+
472
+		}
473
+
474
+		//$this->form_params['excluded_files'] =  array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default);
475
+
476
+		if (isset($params->extra)) {
477
+			foreach ($params->extra as $key => $value) {
478
+				$this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value);
479
+			}
480
+		}
481
+
482
+		if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) {
483
+			$this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']);
484
+			$this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']);
485
+		}
486
+
487
+		return $this->xcloner_settings->get_hash();
488
+	}
489
+
490
+	/*
491 491
      *
492 492
      * Get file list for tree view API
493 493
      *
494 494
      */
495
-    public function get_file_system_action()
496
-    {
497
-        $this->check_access();
498
-
499
-        $folder = $this->xcloner_sanitization->sanitize_input_as_relative_path($_POST['id']);
500
-
501
-        $data = array();
502
-
503
-        if ($folder == "#") {
504
-
505
-            $folder = "/";
506
-            $data[] = array(
507
-                'id' => $folder,
508
-                'parent' => '#',
509
-                'text' => $this->xcloner_settings->get_xcloner_start_path(),
510
-                //'children' => true,
511
-                'state' => array('selected' => false, 'opened' => true),
512
-                'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png"
513
-            );
514
-        }
515
-
516
-        try {
517
-            $files = $this->xcloner_file_system->list_directory($folder);
518
-        } catch (Exception $e) {
519
-
520
-            print $e->getMessage();
521
-            $this->logger->error($e->getMessage());
522
-
523
-            return;
524
-        }
525
-
526
-        $type = array();
527
-        foreach ($files as $key => $row) {
528
-            $type[$key] = $row['type'];
529
-        }
530
-        array_multisort($type, SORT_ASC, $files);
531
-
532
-        foreach ($files as $file) {
533
-            $children = false;
534
-            $text = $file['basename'];
535
-
536
-            if ($file['type'] == "dir") {
537
-                $children = true;
538
-            } else {
539
-                $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")";
540
-            }
541
-
542
-            if ($this->xcloner_file_system->is_excluded($file)) {
543
-                $selected = true;
544
-            } else {
545
-                $selected = false;
546
-            }
547
-
548
-            $data[] = array(
549
-                'id' => $file['path'],
550
-                'parent' => $folder,
551
-                'text' => $text,
552
-                //'title' => "test",
553
-                'children' => $children,
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"
557
-            );
558
-        }
559
-
560
-
561
-        return $this->send_response($data, 0);
562
-    }
563
-
564
-    /*
495
+	public function get_file_system_action()
496
+	{
497
+		$this->check_access();
498
+
499
+		$folder = $this->xcloner_sanitization->sanitize_input_as_relative_path($_POST['id']);
500
+
501
+		$data = array();
502
+
503
+		if ($folder == "#") {
504
+
505
+			$folder = "/";
506
+			$data[] = array(
507
+				'id' => $folder,
508
+				'parent' => '#',
509
+				'text' => $this->xcloner_settings->get_xcloner_start_path(),
510
+				//'children' => true,
511
+				'state' => array('selected' => false, 'opened' => true),
512
+				'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png"
513
+			);
514
+		}
515
+
516
+		try {
517
+			$files = $this->xcloner_file_system->list_directory($folder);
518
+		} catch (Exception $e) {
519
+
520
+			print $e->getMessage();
521
+			$this->logger->error($e->getMessage());
522
+
523
+			return;
524
+		}
525
+
526
+		$type = array();
527
+		foreach ($files as $key => $row) {
528
+			$type[$key] = $row['type'];
529
+		}
530
+		array_multisort($type, SORT_ASC, $files);
531
+
532
+		foreach ($files as $file) {
533
+			$children = false;
534
+			$text = $file['basename'];
535
+
536
+			if ($file['type'] == "dir") {
537
+				$children = true;
538
+			} else {
539
+				$text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")";
540
+			}
541
+
542
+			if ($this->xcloner_file_system->is_excluded($file)) {
543
+				$selected = true;
544
+			} else {
545
+				$selected = false;
546
+			}
547
+
548
+			$data[] = array(
549
+				'id' => $file['path'],
550
+				'parent' => $folder,
551
+				'text' => $text,
552
+				//'title' => "test",
553
+				'children' => $children,
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"
557
+			);
558
+		}
559
+
560
+
561
+		return $this->send_response($data, 0);
562
+	}
563
+
564
+	/*
565 565
      *
566 566
      * Get databases/tables list for frontend tree display API
567 567
      *
568 568
      */
569
-    public function get_database_tables_action()
570
-    {
571
-        $this->check_access();
572
-
573
-        $database = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['id']);
574
-
575
-        $data = array();
576
-
577
-        $xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables');
578
-
579
-        if ($database == "#") {
580
-            try {
581
-                $return = $this->xcloner_database->get_all_databases();
582
-            } catch (Exception $e) {
583
-                $this->logger->error($e->getMessage());
584
-            }
585
-
586
-            foreach ($return as $database) {
587
-                if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) {
588
-                    continue;
589
-                }
590
-
591
-                $state = array();
592
-
593
-                if ($database['name'] == $this->xcloner_settings->get_db_database()) {
594
-                    $state['selected'] = true;
595
-                    if ($database['num_tables'] < 25) {
596
-                        $state['opened'] = false;
597
-                    }
598
-                }
599
-
600
-                $data[] = array(
601
-                    'id' => $database['name'],
602
-                    'parent' => '#',
603
-                    'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")",
604
-                    'children' => true,
605
-                    'state' => $state,
606
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png"
607
-                );
608
-            }
609
-
610
-        } else {
611
-
612
-            try {
613
-                $return = $this->xcloner_database->list_tables($database, "", 1);
614
-            } catch (Exception $e) {
615
-                $this->logger->error($e->getMessage());
616
-            }
617
-
618
-            foreach ($return as $table) {
619
-                $state = array();
620
-
621
-                if ($xcloner_backup_only_wp_tables and !stristr($table['name'],
622
-                        $this->xcloner_settings->get_table_prefix())) {
623
-                    continue;
624
-                }
625
-
626
-                if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) {
627
-                    $state = array('selected' => true);
628
-                }
629
-
630
-                $data[] = array(
631
-                    'id' => $database . "." . $table['name'],
632
-                    'parent' => $database,
633
-                    'text' => $table['name'] . " (" . (int)$table['records'] . ")",
634
-                    'children' => false,
635
-                    'state' => $state,
636
-                    'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png"
637
-                );
638
-            }
639
-        }
640
-
641
-        return $this->send_response($data, 0);
642
-    }
643
-
644
-    /*
569
+	public function get_database_tables_action()
570
+	{
571
+		$this->check_access();
572
+
573
+		$database = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['id']);
574
+
575
+		$data = array();
576
+
577
+		$xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables');
578
+
579
+		if ($database == "#") {
580
+			try {
581
+				$return = $this->xcloner_database->get_all_databases();
582
+			} catch (Exception $e) {
583
+				$this->logger->error($e->getMessage());
584
+			}
585
+
586
+			foreach ($return as $database) {
587
+				if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) {
588
+					continue;
589
+				}
590
+
591
+				$state = array();
592
+
593
+				if ($database['name'] == $this->xcloner_settings->get_db_database()) {
594
+					$state['selected'] = true;
595
+					if ($database['num_tables'] < 25) {
596
+						$state['opened'] = false;
597
+					}
598
+				}
599
+
600
+				$data[] = array(
601
+					'id' => $database['name'],
602
+					'parent' => '#',
603
+					'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")",
604
+					'children' => true,
605
+					'state' => $state,
606
+					'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png"
607
+				);
608
+			}
609
+
610
+		} else {
611
+
612
+			try {
613
+				$return = $this->xcloner_database->list_tables($database, "", 1);
614
+			} catch (Exception $e) {
615
+				$this->logger->error($e->getMessage());
616
+			}
617
+
618
+			foreach ($return as $table) {
619
+				$state = array();
620
+
621
+				if ($xcloner_backup_only_wp_tables and !stristr($table['name'],
622
+						$this->xcloner_settings->get_table_prefix())) {
623
+					continue;
624
+				}
625
+
626
+				if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) {
627
+					$state = array('selected' => true);
628
+				}
629
+
630
+				$data[] = array(
631
+					'id' => $database . "." . $table['name'],
632
+					'parent' => $database,
633
+					'text' => $table['name'] . " (" . (int)$table['records'] . ")",
634
+					'children' => false,
635
+					'state' => $state,
636
+					'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png"
637
+				);
638
+			}
639
+		}
640
+
641
+		return $this->send_response($data, 0);
642
+	}
643
+
644
+	/*
645 645
      *
646 646
      * Get schedule by id API
647 647
      *
648 648
      */
649
-    public function get_schedule_by_id()
650
-    {
651
-        $this->check_access();
649
+	public function get_schedule_by_id()
650
+	{
651
+		$this->check_access();
652 652
 
653
-        $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
654
-        $scheduler = $this->xcloner_scheduler;
655
-        $data = $scheduler->get_schedule_by_id($schedule_id);
653
+		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
654
+		$scheduler = $this->xcloner_scheduler;
655
+		$data = $scheduler->get_schedule_by_id($schedule_id);
656 656
 
657
-        $data['start_at'] = date("Y-m-d H:i",
658
-            strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS));
659
-        if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") {
660
-            $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date));
661
-        }
657
+		$data['start_at'] = date("Y-m-d H:i",
658
+			strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS));
659
+		if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") {
660
+			$data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date));
661
+		}
662 662
 
663
-        return $this->send_response($data);
664
-    }
663
+		return $this->send_response($data);
664
+	}
665 665
 
666
-    /*
666
+	/*
667 667
      *
668 668
      * Get Schedule list API
669 669
      *
670 670
      */
671
-    public function get_scheduler_list()
672
-    {
673
-        $this->check_access();
671
+	public function get_scheduler_list()
672
+	{
673
+		$this->check_access();
674 674
 
675
-        $scheduler = $this->xcloner_scheduler;
676
-        $data = $scheduler->get_scheduler_list();
677
-        $return['data'] = array();
675
+		$scheduler = $this->xcloner_scheduler;
676
+		$data = $scheduler->get_scheduler_list();
677
+		$return['data'] = array();
678 678
 
679
-        foreach ($data as $res) {
680
-            $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
679
+		foreach ($data as $res) {
680
+			$action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a>
681 681
 					<a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons  \">delete</i></a>";
682
-            if ($res->status) {
683
-                $status = '<i class="material-icons active status">timer</i>';
684
-            } else {
685
-                $status = '<i class="material-icons status inactive">timer_off</i>';
686
-            }
687
-
688
-            $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id));
689
-
690
-            $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time);
691
-
692
-            $remote_storage = $res->remote_storage;
693
-
694
-            if (!$next_run_time >= time()) {
695
-                $next_run = " ";
696
-            }
697
-
698
-            if (trim($next_run)) {
699
-                $date_text = date(get_option('date_format') . " " . get_option('time_format'),
700
-                    $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
701
-
702
-                if ($next_run_time >= time()) {
703
-                    $next_run = "in " . human_time_diff($next_run_time, time());
704
-                } else {
705
-                    $next_run = __("executed", 'xcloner-backup-and-restore');
706
-                }
707
-
708
-                $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>";
709
-                //$next_run .=" ($date_text)";
710
-            }
711
-
712
-            $backup_text = "";
713
-            $backup_size = "";
714
-            $backup_time = "";
715
-
716
-            if ($res->last_backup) {
717
-                if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) {
718
-                    $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
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'),
721
-                        $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
722
-                }
723
-
724
-                $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>";
725
-            }
726
-
727
-            $schedules = wp_get_schedules();
728
-
729
-            if (isset($schedules[$res->recurrence])) {
730
-                $res->recurrence = $schedules[$res->recurrence]['display'];
731
-            }
732
-
733
-            $return['data'][] = array(
734
-                $res->id,
735
-                $res->name,
736
-                $res->recurrence,/*$res->start_at,*/
737
-                $next_run,
738
-                $remote_storage,
739
-                $backup_text,
740
-                $status,
741
-                $action
742
-            );
743
-        }
744
-
745
-        return $this->send_response($return, 0);
746
-    }
747
-
748
-    /*
682
+			if ($res->status) {
683
+				$status = '<i class="material-icons active status">timer</i>';
684
+			} else {
685
+				$status = '<i class="material-icons status inactive">timer_off</i>';
686
+			}
687
+
688
+			$next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id));
689
+
690
+			$next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time);
691
+
692
+			$remote_storage = $res->remote_storage;
693
+
694
+			if (!$next_run_time >= time()) {
695
+				$next_run = " ";
696
+			}
697
+
698
+			if (trim($next_run)) {
699
+				$date_text = date(get_option('date_format') . " " . get_option('time_format'),
700
+					$next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS));
701
+
702
+				if ($next_run_time >= time()) {
703
+					$next_run = "in " . human_time_diff($next_run_time, time());
704
+				} else {
705
+					$next_run = __("executed", 'xcloner-backup-and-restore');
706
+				}
707
+
708
+				$next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>";
709
+				//$next_run .=" ($date_text)";
710
+			}
711
+
712
+			$backup_text = "";
713
+			$backup_size = "";
714
+			$backup_time = "";
715
+
716
+			if ($res->last_backup) {
717
+				if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) {
718
+					$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup);
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'),
721
+						$metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS));
722
+				}
723
+
724
+				$backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>";
725
+			}
726
+
727
+			$schedules = wp_get_schedules();
728
+
729
+			if (isset($schedules[$res->recurrence])) {
730
+				$res->recurrence = $schedules[$res->recurrence]['display'];
731
+			}
732
+
733
+			$return['data'][] = array(
734
+				$res->id,
735
+				$res->name,
736
+				$res->recurrence,/*$res->start_at,*/
737
+				$next_run,
738
+				$remote_storage,
739
+				$backup_text,
740
+				$status,
741
+				$action
742
+			);
743
+		}
744
+
745
+		return $this->send_response($return, 0);
746
+	}
747
+
748
+	/*
749 749
      *
750 750
      * Delete Schedule by ID API
751 751
      *
752 752
      */
753
-    public function delete_schedule_by_id()
754
-    {
755
-        $this->check_access();
753
+	public function delete_schedule_by_id()
754
+	{
755
+		$this->check_access();
756 756
 
757
-        $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
758
-        $scheduler = $this->xcloner_scheduler;
759
-        $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id);
757
+		$schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']);
758
+		$scheduler = $this->xcloner_scheduler;
759
+		$data['finished'] = $scheduler->delete_schedule_by_id($schedule_id);
760 760
 
761
-        return $this->send_response($data);
762
-    }
761
+		return $this->send_response($data);
762
+	}
763 763
 
764
-    /*
764
+	/*
765 765
      *
766 766
      * Delete backup by name from the storage path
767 767
      *
768 768
      */
769
-    public function delete_backup_by_name()
770
-    {
771
-        $this->check_access();
769
+	public function delete_backup_by_name()
770
+	{
771
+		$this->check_access();
772
+
773
+		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']);
774
+		$storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_selection']);
775
+
776
+		$data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name, $storage_selection);
777
+
778
+		return $this->send_response($data);
779
+	}
780
+
781
+	/**
782
+	 *  API Incremental Backup Encryption Method
783
+	 */
784
+	public function backup_encryption()
785
+	{
786
+		$this->check_access();
787
+
788
+		$backup_parts = array();
789
+		$return = array();
772 790
 
773
-        $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']);
774
-        $storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_selection']);
775 791
 
776
-        $data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name, $storage_selection);
792
+		if (isset($_POST['data'])) {
793
+			$params = json_decode(stripslashes($_POST['data']));
794
+
795
+			$this->process_params($params);
796
+			$source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($this->form_params['extra']['backup_parent']);
797
+
798
+			if(isset($this->form_params['extra']['start'])) {
799
+				$start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']);
800
+			}else{
801
+				$start = 0;
802
+			}
803
+
804
+			if(isset($this->form_params['extra']['iv'])) {
805
+				$iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']);
806
+			}else{
807
+				$iv = "";
808
+			}
809
+
810
+			if(isset($this->form_params['extra']['part'])) {
811
+				$return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']);
812
+			}else{
813
+				$return['part'] = 0;
814
+			}
777 815
 
778
-        return $this->send_response($data);
779
-    }
816
+		}else{
817
+			$source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
818
+			$start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
819
+			$iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']);
820
+			$return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
821
+		}
780 822
 
781
-    /**
782
-     *  API Incremental Backup Encryption Method
783
-     */
784
-    public function backup_encryption()
785
-    {
786
-        $this->check_access();
787
-
788
-        $backup_parts = array();
789
-        $return = array();
790
-
791
-
792
-        if (isset($_POST['data'])) {
793
-            $params = json_decode(stripslashes($_POST['data']));
794
-
795
-            $this->process_params($params);
796
-            $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($this->form_params['extra']['backup_parent']);
797
-
798
-            if(isset($this->form_params['extra']['start'])) {
799
-                $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']);
800
-            }else{
801
-                $start = 0;
802
-            }
803
-
804
-            if(isset($this->form_params['extra']['iv'])) {
805
-                $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']);
806
-            }else{
807
-                $iv = "";
808
-            }
809
-
810
-            if(isset($this->form_params['extra']['part'])) {
811
-                $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']);
812
-            }else{
813
-                $return['part'] = 0;
814
-            }
815
-
816
-        }else{
817
-            $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
818
-            $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
819
-            $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']);
820
-            $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
821
-        }
822
-
823
-        $backup_file = $source_backup_file;
824
-
825
-        if ($this->xcloner_file_system->is_multipart($backup_file)) {
826
-            $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
827
-            $backup_file = $backup_parts[$return['part']];
828
-        }
829
-
830
-        $return['processing_file'] = $backup_file;
831
-        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
832
-
833
-        try {
834
-            $this->logger->info(json_encode($_POST));
835
-            $this->logger->info($iv);
836
-            $return = array_merge($return,
837
-                $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv)));
838
-        }catch(\Exception $e){
839
-            $return['error'] = true;
840
-            $return['message'] = $e->getMessage();
841
-            $return['error_message'] = $e->getMessage();
842
-        }
843
-
844
-        //echo strlen($return['iv']);exit;
845
-
846
-        if($return['finished']) {
847
-            if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
848
-                $return['start'] = 0;
849
-
850
-                ++$return['part'];
851
-
852
-                if ($return['part'] < sizeof($backup_parts)) {
853
-                    $return['finished'] = 0;
854
-                }
855
-
856
-            }
857
-        }
858
-
859
-        if (isset($_POST['data'])) {
860
-            $return['extra'] = array_merge($this->form_params['extra'],  $return);
861
-        }
862
-
863
-        $this->send_response($return, 0);
864
-    }
865
-
866
-    /**
867
-     *  API Incremental Backup Decryption Method
868
-     */
869
-    public function backup_decryption()
870
-    {
871
-        $this->check_access();
823
+		$backup_file = $source_backup_file;
824
+
825
+		if ($this->xcloner_file_system->is_multipart($backup_file)) {
826
+			$backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
827
+			$backup_file = $backup_parts[$return['part']];
828
+		}
829
+
830
+		$return['processing_file'] = $backup_file;
831
+		$return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
832
+
833
+		try {
834
+			$this->logger->info(json_encode($_POST));
835
+			$this->logger->info($iv);
836
+			$return = array_merge($return,
837
+				$this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv)));
838
+		}catch(\Exception $e){
839
+			$return['error'] = true;
840
+			$return['message'] = $e->getMessage();
841
+			$return['error_message'] = $e->getMessage();
842
+		}
872 843
 
873
-        $backup_parts = array();
874
-        $return = array();
844
+		//echo strlen($return['iv']);exit;
875 845
 
876
-        $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
877
-        $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
878
-        $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']);
879
-        $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']);;
880
-        $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
846
+		if($return['finished']) {
847
+			if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
848
+				$return['start'] = 0;
881 849
 
882
-        $backup_file = $source_backup_file;
850
+				++$return['part'];
883 851
 
884
-        if ($this->xcloner_file_system->is_multipart($backup_file)) {
885
-            $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
886
-            $backup_file = $backup_parts[$return['part']];
887
-        }
852
+				if ($return['part'] < sizeof($backup_parts)) {
853
+					$return['finished'] = 0;
854
+				}
888 855
 
889
-        $return['processing_file'] = $backup_file;
890
-        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
856
+			}
857
+		}
891 858
 
892
-        try {
893
-            $return = array_merge($return,
894
-                $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv)));
895
-        }catch(\Exception $e){
896
-            $return['error'] = true;
897
-            $return['message'] = $e->getMessage();
898
-        }
859
+		if (isset($_POST['data'])) {
860
+			$return['extra'] = array_merge($this->form_params['extra'],  $return);
861
+		}
899 862
 
900
-        if($return['finished']) {
901
-            if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
902
-                $return['start'] = 0;
863
+		$this->send_response($return, 0);
864
+	}
903 865
 
904
-                ++$return['part'];
866
+	/**
867
+	 *  API Incremental Backup Decryption Method
868
+	 */
869
+	public function backup_decryption()
870
+	{
871
+		$this->check_access();
905 872
 
906
-                if ($return['part'] < sizeof($backup_parts)) {
907
-                    $return['finished'] = 0;
908
-                }
873
+		$backup_parts = array();
874
+		$return = array();
909 875
 
910
-            }
911
-        }
876
+		$source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
877
+		$start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
878
+		$iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']);
879
+		$decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']);;
880
+		$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
881
+
882
+		$backup_file = $source_backup_file;
912 883
 
913
-        $this->send_response($return, 0);
914
-    }
884
+		if ($this->xcloner_file_system->is_multipart($backup_file)) {
885
+			$backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
886
+			$backup_file = $backup_parts[$return['part']];
887
+		}
915 888
 
916
-    public function get_manage_backups_list() {
889
+		$return['processing_file'] = $backup_file;
890
+		$return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
917 891
 
918
-        $storage_selection = "";
892
+		try {
893
+			$return = array_merge($return,
894
+				$this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv)));
895
+		}catch(\Exception $e){
896
+			$return['error'] = true;
897
+			$return['message'] = $e->getMessage();
898
+		}
899
+
900
+		if($return['finished']) {
901
+			if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
902
+				$return['start'] = 0;
919 903
 
920
-        if (isset($_GET['storage_selection']) and $_GET['storage_selection']) {
921
-            $storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']);
922
-        }
923
-        $available_storages = $this->xcloner_remote_storage->get_available_storages();
904
+				++$return['part'];
905
+
906
+				if ($return['part'] < sizeof($backup_parts)) {
907
+					$return['finished'] = 0;
908
+				}
924 909
 
925
-        $backup_list = $this->xcloner_file_system->get_backup_archives_list($storage_selection);
926
-        $return = array();
910
+			}
911
+		}
927 912
 
928
-        $i = -1;
929
-        foreach ($backup_list as $file_info):?>
913
+		$this->send_response($return, 0);
914
+	}
915
+
916
+	public function get_manage_backups_list() {
917
+
918
+		$storage_selection = "";
919
+
920
+		if (isset($_GET['storage_selection']) and $_GET['storage_selection']) {
921
+			$storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']);
922
+		}
923
+		$available_storages = $this->xcloner_remote_storage->get_available_storages();
924
+
925
+		$backup_list = $this->xcloner_file_system->get_backup_archives_list($storage_selection);
926
+		$return = array();
927
+
928
+		$i = -1;
929
+		foreach ($backup_list as $file_info):?>
930 930
             <?php
931
-            if ($storage_selection == "gdrive") {
932
-                $file_info['path'] = $file_info['filename'] . "." . $file_info['extension'];
933
-            }
934
-            $file_exists_on_local_storage = true;
935
-
936
-            if ($storage_selection) {
937
-                if (!$this->xcloner_file_system->get_storage_filesystem()->has($file_info['path'])) {
938
-                    $file_exists_on_local_storage = false;
939
-                }
940
-            }
941
-
942
-            ?>
931
+			if ($storage_selection == "gdrive") {
932
+				$file_info['path'] = $file_info['filename'] . "." . $file_info['extension'];
933
+			}
934
+			$file_exists_on_local_storage = true;
935
+
936
+			if ($storage_selection) {
937
+				if (!$this->xcloner_file_system->get_storage_filesystem()->has($file_info['path'])) {
938
+					$file_exists_on_local_storage = false;
939
+				}
940
+			}
941
+
942
+			?>
943 943
             <?php if (!isset($file_info['parent'])): ?>
944 944
 
945 945
                 <?php ob_start(); ?>
@@ -949,21 +949,21 @@  discard block
 block discarded – undo
949 949
                             <label for="checkbox_<?php echo $i ?>">&nbsp;</label>
950 950
                         </p>
951 951
                 <?php
952
-                $return['data'][$i][] = ob_get_contents();
953
-                ob_end_clean();
954
-                ?>
952
+				$return['data'][$i][] = ob_get_contents();
953
+				ob_end_clean();
954
+				?>
955 955
 
956 956
                 <?php ob_start(); ?>
957 957
                         <span class=""><?php echo $file_info['path'] ?></span>
958 958
                         <?php if (!$file_exists_on_local_storage): ?>
959 959
                             <a href="#"
960 960
                                title="<?php echo __("File does not exists on local storage",
961
-                                   "xcloner-backup-and-restore") ?>"><i
961
+								   "xcloner-backup-and-restore") ?>"><i
962 962
                                         class="material-icons backup_warning">warning</i></a>
963 963
                         <?php endif ?>
964 964
                         <?php
965
-                        if (isset($file_info['childs']) and is_array($file_info['childs'])):
966
-                            ?>
965
+						if (isset($file_info['childs']) and is_array($file_info['childs'])):
966
+							?>
967 967
                             <a href="#" title="expand" class="expand-multipart add"><i
968 968
                                         class="material-icons">add</i></a>
969 969
                             <a href="#" title="collapse" class="expand-multipart remove"><i class="material-icons">remove</i></a>
@@ -972,17 +972,17 @@  discard block
 block discarded – undo
972 972
                                     <li>
973 973
                                         <?php echo $child[0] ?> (<?php echo size_format($child[2]) ?>)
974 974
                                         <?php
975
-                                        $child_exists_on_local_storage = true;
976
-                                        if ($storage_selection) {
977
-                                            if (!$this->xcloner_file_system->get_storage_filesystem()->has($child[0])) {
978
-                                                $child_exists_on_local_storage = false;
979
-                                            }
980
-                                        }
981
-                                        ?>
975
+										$child_exists_on_local_storage = true;
976
+										if ($storage_selection) {
977
+											if (!$this->xcloner_file_system->get_storage_filesystem()->has($child[0])) {
978
+												$child_exists_on_local_storage = false;
979
+											}
980
+										}
981
+										?>
982 982
                                         <?php if (!$child_exists_on_local_storage): ?>
983 983
                                             <a href="#"
984 984
                                                title="<?php echo __("File does not exists on local storage",
985
-                                                   "xcloner-backup-and-restore") ?>"><i
985
+												   "xcloner-backup-and-restore") ?>"><i
986 986
                                                         class="material-icons backup_warning">warning</i></a>
987 987
                                         <?php endif ?>
988 988
                                         <?php if (!$storage_selection) : ?>
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
                                             <?php else: ?>
998 998
                                                 <a href="#<?php echo $child[0] ?>" class="list-backup-content"
999 999
                                                    title="<?php echo __('List Backup Content',
1000
-                                                       'xcloner-backup-and-restore') ?>"><i
1000
+													   'xcloner-backup-and-restore') ?>"><i
1001 1001
                                                             class="material-icons">folder_open</i></a>
1002 1002
 
1003 1003
                                                 <a href="#<?php echo $child[0] ?>" class="backup-encryption"
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
                                         <?php elseif ($storage_selection != "gdrive" && !$this->xcloner_file_system->get_storage_filesystem()->has($child[0])): ?>
1010 1010
                                             <a href="#<?php echo $child[0] ?>" class="copy-remote-to-local"
1011 1011
                                                title="<?php echo __('Push Backup To Local Storage',
1012
-                                                   'xcloner-backup-and-restore') ?>"><i
1012
+												   'xcloner-backup-and-restore') ?>"><i
1013 1013
                                                         class="material-icons">file_upload</i></a>
1014 1014
                                         <?php endif ?>
1015 1015
                                     </li>
@@ -1017,24 +1017,24 @@  discard block
 block discarded – undo
1017 1017
                             </ul>
1018 1018
                         <?php endif; ?>
1019 1019
                 <?php
1020
-                $return['data'][$i][] = ob_get_contents();
1021
-                ob_end_clean();
1022
-                ?>
1020
+				$return['data'][$i][] = ob_get_contents();
1021
+				ob_end_clean();
1022
+				?>
1023 1023
                     <?php ob_start(); ?>
1024 1024
                         <?php if (isset($file_info['timestamp']))
1025
-                            echo date("Y-m-d H:i", $file_info['timestamp'])
1026
-                        ?>
1025
+							echo date("Y-m-d H:i", $file_info['timestamp'])
1026
+						?>
1027 1027
                     <?php
1028
-                        $return['data'][$i][] = ob_get_contents();
1029
-                        ob_end_clean();
1030
-                        ?>
1028
+						$return['data'][$i][] = ob_get_contents();
1029
+						ob_end_clean();
1030
+						?>
1031 1031
 
1032 1032
                     <?php ob_start(); ?>
1033 1033
                         <?php echo size_format($file_info['size']) ?>
1034 1034
                     <?php
1035
-                        $return['data'][$i][] = ob_get_contents();
1036
-                        ob_end_clean();
1037
-                    ?>
1035
+						$return['data'][$i][] = ob_get_contents();
1036
+						ob_end_clean();
1037
+					?>
1038 1038
 
1039 1039
                     <?php ob_start(); ?>
1040 1040
                         <?php if (!$storage_selection): ?>
@@ -1045,14 +1045,14 @@  discard block
 block discarded – undo
1045 1045
                             <?php if (sizeof($available_storages)): ?>
1046 1046
                                 <a href="#<?php echo $file_info['basename'] ?>" class="cloud-upload"
1047 1047
                                    title="<?php echo __('Send Backup To Remote Storage',
1048
-                                       'xcloner-backup-and-restore') ?>"><i
1048
+									   'xcloner-backup-and-restore') ?>"><i
1049 1049
                                             class="material-icons">cloud_upload</i></a>
1050 1050
                             <?php endif ?>
1051 1051
                             <?php
1052
-                            $basename = $file_info['basename'];
1053
-                            if(isset($file_info['childs']) and sizeof($file_info['childs']))
1054
-                                $basename = $file_info['childs'][0][0];
1055
-                            ?>
1052
+							$basename = $file_info['basename'];
1053
+							if(isset($file_info['childs']) and sizeof($file_info['childs']))
1054
+								$basename = $file_info['childs'][0][0];
1055
+							?>
1056 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') ?>">
@@ -1081,193 +1081,193 @@  discard block
 block discarded – undo
1081 1081
                         <?php endif ?>
1082 1082
 
1083 1083
                     <?php
1084
-                        $return['data'][$i][] = ob_get_contents();
1085
-                        ob_end_clean(); ?>
1084
+						$return['data'][$i][] = ob_get_contents();
1085
+						ob_end_clean(); ?>
1086 1086
 
1087 1087
             <?php endif ?>
1088 1088
         <?php endforeach ?>
1089 1089
     <?php
1090
-        $this->send_response($return, 0);
1091
-    }
1092
-
1093
-    /**
1094
-     * API method to list internal backup files
1095
-     */
1096
-    public function list_backup_files()
1097
-    {
1098
-        $this->check_access();
1099
-
1100
-        $backup_parts = array();
1101
-
1102
-        $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1103
-        $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
1104
-        $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1105
-
1106
-        $backup_file = $source_backup_file;
1107
-
1108
-        if ($this->xcloner_file_system->is_multipart($backup_file)) {
1109
-            $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
1110
-            $backup_file = $backup_parts[$return['part']];
1111
-        }
1112
-
1113
-        if($this->xcloner_encryption->is_encrypted_file($backup_file)) {
1114
-            $return['error'] = true;
1115
-            $return['message'] = __("Backup archive is encrypted, please decrypt it first before you can list it's content.", "xcloner-backup-and-restore");
1116
-            $this->send_response($return, 0);
1117
-        }
1118
-
1119
-        try {
1120
-            $tar = new Tar();
1121
-            $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start);
1122
-
1123
-            $data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
1124
-        } catch (Exception $e) {
1125
-            $return['error'] = true;
1126
-            $return['message'] = $e->getMessage();
1127
-            $this->send_response($return, 0);
1128
-        }
1129
-
1130
-        $return['files'] = array();
1131
-        $return['finished'] = 1;
1132
-        $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
1133
-        $i = 0;
1134
-
1135
-        if (isset($data['extracted_files']) and is_array($data['extracted_files'])) {
1136
-            foreach ($data['extracted_files'] as $file) {
1137
-                $return['files'][$i]['path'] = $file->getPath();
1138
-                $return['files'][$i]['size'] = $file->getSize();
1139
-                $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'),
1140
-                    $file->getMtime());
1141
-
1142
-                $i++;
1143
-            }
1144
-        }
1145
-
1146
-        if (isset($data['start'])) {
1147
-            $return['start'] = $data['start'];
1148
-            $return['finished'] = 0;
1149
-        } else {
1150
-            if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
1151
-                $return['start'] = 0;
1152
-
1153
-                ++$return['part'];
1154
-
1155
-                if ($return['part'] < sizeof($backup_parts)) {
1156
-                    $return['finished'] = 0;
1157
-                }
1158
-
1159
-            }
1160
-        }
1161
-
1162
-        $this->send_response($return, 0);
1163
-    }
1164
-
1165
-    /*
1090
+		$this->send_response($return, 0);
1091
+	}
1092
+
1093
+	/**
1094
+	 * API method to list internal backup files
1095
+	 */
1096
+	public function list_backup_files()
1097
+	{
1098
+		$this->check_access();
1099
+
1100
+		$backup_parts = array();
1101
+
1102
+		$source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1103
+		$start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']);
1104
+		$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1105
+
1106
+		$backup_file = $source_backup_file;
1107
+
1108
+		if ($this->xcloner_file_system->is_multipart($backup_file)) {
1109
+			$backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file);
1110
+			$backup_file = $backup_parts[$return['part']];
1111
+		}
1112
+
1113
+		if($this->xcloner_encryption->is_encrypted_file($backup_file)) {
1114
+			$return['error'] = true;
1115
+			$return['message'] = __("Backup archive is encrypted, please decrypt it first before you can list it's content.", "xcloner-backup-and-restore");
1116
+			$this->send_response($return, 0);
1117
+		}
1118
+
1119
+		try {
1120
+			$tar = new Tar();
1121
+			$tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start);
1122
+
1123
+			$data = $tar->contents(get_option('xcloner_files_to_process_per_request'));
1124
+		} catch (Exception $e) {
1125
+			$return['error'] = true;
1126
+			$return['message'] = $e->getMessage();
1127
+			$this->send_response($return, 0);
1128
+		}
1129
+
1130
+		$return['files'] = array();
1131
+		$return['finished'] = 1;
1132
+		$return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file);
1133
+		$i = 0;
1134
+
1135
+		if (isset($data['extracted_files']) and is_array($data['extracted_files'])) {
1136
+			foreach ($data['extracted_files'] as $file) {
1137
+				$return['files'][$i]['path'] = $file->getPath();
1138
+				$return['files'][$i]['size'] = $file->getSize();
1139
+				$return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'),
1140
+					$file->getMtime());
1141
+
1142
+				$i++;
1143
+			}
1144
+		}
1145
+
1146
+		if (isset($data['start'])) {
1147
+			$return['start'] = $data['start'];
1148
+			$return['finished'] = 0;
1149
+		} else {
1150
+			if ($this->xcloner_file_system->is_multipart($source_backup_file)) {
1151
+				$return['start'] = 0;
1152
+
1153
+				++$return['part'];
1154
+
1155
+				if ($return['part'] < sizeof($backup_parts)) {
1156
+					$return['finished'] = 0;
1157
+				}
1158
+
1159
+			}
1160
+		}
1161
+
1162
+		$this->send_response($return, 0);
1163
+	}
1164
+
1165
+	/*
1166 1166
      * Copy remote backup to local storage
1167 1167
      */
1168
-    public function copy_backup_remote_to_local()
1169
-    {
1168
+	public function copy_backup_remote_to_local()
1169
+	{
1170 1170
 
1171
-        $this->check_access();
1171
+		$this->check_access();
1172 1172
 
1173
-        $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1174
-        $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
1173
+		$backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1174
+		$storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
1175 1175
 
1176
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
1176
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
1177 1177
 
1178
-        $return = array();
1178
+		$return = array();
1179 1179
 
1180
-        try {
1181
-            if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) {
1182
-                $return = call_user_func_array(array(
1183
-                    $xcloner_remote_storage,
1184
-                    "copy_backup_remote_to_local"
1185
-                ), array($backup_file, $storage_type));
1186
-            }
1187
-        } catch (Exception $e) {
1180
+		try {
1181
+			if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) {
1182
+				$return = call_user_func_array(array(
1183
+					$xcloner_remote_storage,
1184
+					"copy_backup_remote_to_local"
1185
+				), array($backup_file, $storage_type));
1186
+			}
1187
+		} catch (Exception $e) {
1188 1188
 
1189
-            $return['error'] = 1;
1190
-            $return['message'] = $e->getMessage();
1191
-        }
1189
+			$return['error'] = 1;
1190
+			$return['message'] = $e->getMessage();
1191
+		}
1192 1192
 
1193
-        if (!$return) {
1194
-            $return['error'] = 1;
1195
-            $return['message'] = "Upload failed, please check the error log for more information!";
1196
-        }
1193
+		if (!$return) {
1194
+			$return['error'] = 1;
1195
+			$return['message'] = "Upload failed, please check the error log for more information!";
1196
+		}
1197 1197
 
1198 1198
 
1199
-        $this->send_response($return, 0);
1199
+		$this->send_response($return, 0);
1200 1200
 
1201
-    }
1201
+	}
1202 1202
 
1203
-    /*
1203
+	/*
1204 1204
      *
1205 1205
      * Upload backup to remote API
1206 1206
      *
1207 1207
      */
1208
-    public function upload_backup_to_remote()
1209
-    {
1210
-        $this->check_access();
1208
+	public function upload_backup_to_remote()
1209
+	{
1210
+		$this->check_access();
1211 1211
 
1212
-        $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1213
-        $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
1212
+		$backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1213
+		$storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']);
1214 1214
 
1215
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
1215
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
1216 1216
 
1217
-        $return = array();
1217
+		$return = array();
1218 1218
 
1219
-        try {
1220
-            if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) {
1221
-                $return = call_user_func_array(array(
1222
-                    $xcloner_remote_storage,
1223
-                    "upload_backup_to_storage"
1224
-                ), array($backup_file, $storage_type));
1225
-            }
1226
-        } catch (Exception $e) {
1219
+		try {
1220
+			if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) {
1221
+				$return = call_user_func_array(array(
1222
+					$xcloner_remote_storage,
1223
+					"upload_backup_to_storage"
1224
+				), array($backup_file, $storage_type));
1225
+			}
1226
+		} catch (Exception $e) {
1227 1227
 
1228
-            $return['error'] = 1;
1229
-            $return['message'] = $e->getMessage();
1230
-        }
1228
+			$return['error'] = 1;
1229
+			$return['message'] = $e->getMessage();
1230
+		}
1231 1231
 
1232
-        if (!$return) {
1233
-            $return['error'] = 1;
1234
-            $return['message'] = "Upload failed, please check the error log for more information!";
1235
-        }
1232
+		if (!$return) {
1233
+			$return['error'] = 1;
1234
+			$return['message'] = "Upload failed, please check the error log for more information!";
1235
+		}
1236 1236
 
1237 1237
 
1238
-        $this->send_response($return, 0);
1238
+		$this->send_response($return, 0);
1239 1239
 
1240
-    }
1240
+	}
1241 1241
 
1242
-    /*
1242
+	/*
1243 1243
      *
1244 1244
      * Remote Storage Status Save
1245 1245
      *
1246 1246
      */
1247
-    public function remote_storage_save_status()
1248
-    {
1249
-        $this->check_access();
1247
+	public function remote_storage_save_status()
1248
+	{
1249
+		$this->check_access();
1250 1250
 
1251
-        $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
1251
+		$xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage();
1252 1252
 
1253
-        $return['finished'] = $xcloner_remote_storage->change_storage_status($_POST['id'], $_POST['value']);
1253
+		$return['finished'] = $xcloner_remote_storage->change_storage_status($_POST['id'], $_POST['value']);
1254 1254
 
1255
-        $this->send_response($return, 0);
1256
-    }
1255
+		$this->send_response($return, 0);
1256
+	}
1257 1257
 
1258 1258
 
1259
-    public function download_restore_script()
1260
-    {
1261
-        $this->check_access();
1259
+	public function download_restore_script()
1260
+	{
1261
+		$this->check_access();
1262 1262
 
1263
-        @ob_end_clean();
1263
+		@ob_end_clean();
1264 1264
 
1265
-        $adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS');
1266
-        $xcloner_plugin_filesystem = new Filesystem($adapter, new Config([
1267
-            'disable_asserts' => true,
1268
-        ]));
1265
+		$adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS');
1266
+		$xcloner_plugin_filesystem = new Filesystem($adapter, new Config([
1267
+			'disable_asserts' => true,
1268
+		]));
1269 1269
 
1270
-        /* Generate PHAR FILE
1270
+		/* Generate PHAR FILE
1271 1271
         $file = 'restore/vendor.built';
1272 1272
 
1273 1273
         if(file_exists($file))
@@ -1283,178 +1283,178 @@  discard block
 block discarded – undo
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
-        $tar = new Tar();
1289
-        $tar->create($tmp_file);
1288
+		$tar = new Tar();
1289
+		$tar->create($tmp_file);
1290 1290
 
1291
-        $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar");
1292
-        //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
1291
+		$tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar");
1292
+		//$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz");
1293 1293
 
1294
-        $files = $xcloner_plugin_filesystem->listContents("vendor/", true);
1295
-        foreach ($files as $file) {
1296
-            $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']);
1297
-        }
1294
+		$files = $xcloner_plugin_filesystem->listContents("vendor/", true);
1295
+		foreach ($files as $file) {
1296
+			$tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']);
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
-        $tar->addData("xcloner_restore.php", $content);
1302
+		$tar->addData("xcloner_restore.php", $content);
1303 1303
 
1304
-        $tar->close();
1304
+		$tar->close();
1305 1305
 
1306
-        if (file_exists($tmp_file)) {
1307
-            header('Content-Description: File Transfer');
1308
-            header('Content-Type: application/octet-stream');
1309
-            header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"');
1310
-            header('Expires: 0');
1311
-            header('Cache-Control: must-revalidate');
1312
-            header('Pragma: public');
1313
-            header('Content-Length: ' . filesize($tmp_file));
1314
-            readfile($tmp_file);
1306
+		if (file_exists($tmp_file)) {
1307
+			header('Content-Description: File Transfer');
1308
+			header('Content-Type: application/octet-stream');
1309
+			header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"');
1310
+			header('Expires: 0');
1311
+			header('Cache-Control: must-revalidate');
1312
+			header('Pragma: public');
1313
+			header('Content-Length: ' . filesize($tmp_file));
1314
+			readfile($tmp_file);
1315 1315
 
1316
-        }
1316
+		}
1317 1317
 
1318
-        @unlink($tmp_file);
1319
-        exit;
1320
-    }
1318
+		@unlink($tmp_file);
1319
+		exit;
1320
+	}
1321 1321
 
1322
-    /*
1322
+	/*
1323 1323
      *
1324 1324
      * Download backup by Name from the Storage Path
1325 1325
      *
1326 1326
      */
1327
-    public function download_backup_by_name()
1328
-    {
1329
-        $this->check_access();
1327
+	public function download_backup_by_name()
1328
+	{
1329
+		$this->check_access();
1330 1330
 
1331
-        @ob_end_clean();
1331
+		@ob_end_clean();
1332 1332
 
1333
-        $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']);
1333
+		$backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']);
1334 1334
 
1335 1335
 
1336
-        $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
1337
-        $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
1336
+		$metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name);
1337
+		$read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name);
1338 1338
 
1339 1339
 
1340
-        header('Pragma: public');
1341
-        header('Expires: 0');
1342
-        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1343
-        header('Cache-Control: private', false);
1344
-        header('Content-Transfer-Encoding: binary');
1345
-        header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";');
1346
-        header('Content-Type: application/octet-stream');
1347
-        header('Content-Length: ' . $metadata['size']);
1340
+		header('Pragma: public');
1341
+		header('Expires: 0');
1342
+		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1343
+		header('Cache-Control: private', false);
1344
+		header('Content-Transfer-Encoding: binary');
1345
+		header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";');
1346
+		header('Content-Type: application/octet-stream');
1347
+		header('Content-Length: ' . $metadata['size']);
1348 1348
 
1349
-        @ob_end_clean();
1349
+		@ob_end_clean();
1350 1350
 
1351
-        $chunkSize = 1024 * 1024;
1352
-        while (!feof($read_stream)) {
1353
-            $buffer = fread($read_stream, $chunkSize);
1354
-            echo $buffer;
1355
-        }
1356
-        fclose($read_stream);
1357
-        exit;
1351
+		$chunkSize = 1024 * 1024;
1352
+		while (!feof($read_stream)) {
1353
+			$buffer = fread($read_stream, $chunkSize);
1354
+			echo $buffer;
1355
+		}
1356
+		fclose($read_stream);
1357
+		exit;
1358 1358
 
1359
-    }
1359
+	}
1360 1360
 
1361
-    /*
1361
+	/*
1362 1362
      * Restore upload backup
1363 1363
      */
1364
-    public function restore_upload_backup()
1365
-    {
1366
-        $this->check_access();
1364
+	public function restore_upload_backup()
1365
+	{
1366
+		$this->check_access();
1367 1367
 
1368
-        $return['part'] = 0;
1369
-        $return['total_parts'] = 0;
1370
-        $return['uploaded_size'] = 0;
1371
-        $is_multipart = 0;
1368
+		$return['part'] = 0;
1369
+		$return['total_parts'] = 0;
1370
+		$return['uploaded_size'] = 0;
1371
+		$is_multipart = 0;
1372 1372
 
1373
-        $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1374
-        $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
1373
+		$file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']);
1374
+		$hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']);
1375 1375
 
1376
-        if (isset($_POST['part'])) {
1377
-            $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1378
-        }
1376
+		if (isset($_POST['part'])) {
1377
+			$return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']);
1378
+		}
1379 1379
 
1380
-        if (isset($_POST['uploaded_size'])) {
1381
-            $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
1382
-        }
1380
+		if (isset($_POST['uploaded_size'])) {
1381
+			$return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']);
1382
+		}
1383 1383
 
1384
-        $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
1385
-        $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']);
1384
+		$start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']);
1385
+		$target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']);
1386 1386
 
1387
-        $return['total_size'] = $this->xcloner_file_system->get_backup_size($file);
1387
+		$return['total_size'] = $this->xcloner_file_system->get_backup_size($file);
1388 1388
 
1389
-        if ($this->xcloner_file_system->is_multipart($file)) {
1390
-            $backup_parts = $this->xcloner_file_system->get_multipart_files($file);
1389
+		if ($this->xcloner_file_system->is_multipart($file)) {
1390
+			$backup_parts = $this->xcloner_file_system->get_multipart_files($file);
1391 1391
 
1392
-            $return['total_parts'] = sizeof($backup_parts) + 1;
1392
+			$return['total_parts'] = sizeof($backup_parts) + 1;
1393 1393
 
1394
-            if ($return['part'] and isset($backup_parts[$return['part'] - 1])) {
1395
-                $file = $backup_parts[$return['part'] - 1];
1396
-            }
1394
+			if ($return['part'] and isset($backup_parts[$return['part'] - 1])) {
1395
+				$file = $backup_parts[$return['part'] - 1];
1396
+			}
1397 1397
 
1398
-            $is_multipart = 1;
1399
-        }
1398
+			$is_multipart = 1;
1399
+		}
1400 1400
 
1401
-        try {
1401
+		try {
1402 1402
 
1403
-            $xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer();
1404
-            $xcloner_file_transfer->set_target($target_url);
1405
-            $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1403
+			$xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer();
1404
+			$xcloner_file_transfer->set_target($target_url);
1405
+			$return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash);
1406 1406
 
1407
-        } catch (Exception $e) {
1407
+		} catch (Exception $e) {
1408 1408
 
1409
-            $return = array();
1410
-            $return['error'] = true;
1411
-            $return['status'] = 500;
1412
-            $return['message'] = "CURL communication error with the restore host. " . $e->getMessage();
1413
-            $this->send_response($return, 0);
1409
+			$return = array();
1410
+			$return['error'] = true;
1411
+			$return['status'] = 500;
1412
+			$return['message'] = "CURL communication error with the restore host. " . $e->getMessage();
1413
+			$this->send_response($return, 0);
1414 1414
 
1415
-        }
1415
+		}
1416 1416
 
1417
-        $return['status'] = 200;
1417
+		$return['status'] = 200;
1418 1418
 
1419
-        //we have finished the upload
1420
-        if (!$return['start'] and $is_multipart) {
1421
-            $return['part']++;
1422
-            $return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file);
1423
-        }
1419
+		//we have finished the upload
1420
+		if (!$return['start'] and $is_multipart) {
1421
+			$return['part']++;
1422
+			$return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file);
1423
+		}
1424 1424
 
1425
-        $this->send_response($return, 0);
1426
-    }
1425
+		$this->send_response($return, 0);
1426
+	}
1427 1427
 
1428
-    /*
1428
+	/*
1429 1429
      * Restore backup
1430 1430
      */
1431
-    public function restore_backup()
1432
-    {
1433
-        $this->check_access();
1431
+	public function restore_backup()
1432
+	{
1433
+		$this->check_access();
1434 1434
 
1435
-        define("XCLONER_PLUGIN_ACCESS", 1);
1436
-        include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php");
1435
+		define("XCLONER_PLUGIN_ACCESS", 1);
1436
+		include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php");
1437 1437
 
1438
-        return;
1439
-    }
1438
+		return;
1439
+	}
1440 1440
 
1441
-    /*
1441
+	/*
1442 1442
      *
1443 1443
      * Send the json response back
1444 1444
      *
1445 1445
      */
1446
-    private function send_response($data, $attach_hash = 1)
1447
-    {
1446
+	private function send_response($data, $attach_hash = 1)
1447
+	{
1448 1448
 
1449
-        if ($attach_hash and null !== $this->xcloner_settings->get_hash()) {
1450
-            $data['hash'] = $this->xcloner_settings->get_hash();
1451
-        }
1449
+		if ($attach_hash and null !== $this->xcloner_settings->get_hash()) {
1450
+			$data['hash'] = $this->xcloner_settings->get_hash();
1451
+		}
1452 1452
 
1453
-        if (ob_get_length()) {
1454
-            ob_clean();
1455
-        }
1456
-        wp_send_json($data);
1453
+		if (ob_get_length()) {
1454
+			ob_clean();
1455
+		}
1456
+		wp_send_json($data);
1457 1457
 
1458
-        die();
1459
-    }
1458
+		die();
1459
+	}
1460 1460
 }
Please login to merge, or discard this patch.
includes/class-xcloner-scheduler.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 	public function update_last_backup( $schedule_id, $last_backup ) {
190 190
 
191
-	    $this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id));
191
+		$this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id));
192 192
 
193 193
 		$schedule['last_backup'] = $last_backup;
194 194
 
@@ -282,56 +282,56 @@  discard block
 block discarded – undo
282 282
 		}
283 283
 		$this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) );
284 284
 
285
-        //getting the last backup archive file
286
-        $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
285
+		//getting the last backup archive file
286
+		$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension();
287 287
 		if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) {
288 288
 			$return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart();
289 289
 		}
290 290
 
291 291
 		//Updating schedule last backup archive
292
-        $this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] );
292
+		$this->update_last_backup( $schedule['id'], $return['extra']['backup_parent'] );
293 293
 
294 294
 		//Encrypting the backup archive
295
-        $return_encrypted['finished'] = 0;
296
-        $return_encrypted['start'] = 0;
297
-        $return_encrypted['iv'] = '';
298
-        $return_encrypted['target_file'] = '';
299
-        $part = 0;
300
-        $backup_parts = array();
301
-
302
-        if( $schedule['backup_params']->backup_encrypt){
303
-            $this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) );
304
-
305
-            $backup_file = $return['extra']['backup_parent'];
306
-
307
-            if ($this->xcloner_file_system->is_multipart($return['extra']['backup_parent'])) {
308
-                $backup_parts = $this->xcloner_file_system->get_multipart_files($return['extra']['backup_parent']);
309
-                $backup_file = $backup_parts[$part];
310
-            }
311
-
312
-            while ( ! $return_encrypted['finished'] ) {
313
-                $return_encrypted = $this->xcloner_encryption->encrypt_file(
314
-                                            $backup_file,
315
-                                            "",
316
-                                            "",
317
-                                            "",
318
-                                            "",
319
-                                            true,
320
-                                            true
321
-                );
322
-
323
-                if($return_encrypted['finished']) {
324
-                    ++$part;
325
-
326
-                    if ($part < sizeof($backup_parts)) {
327
-                        $return_encrypted['finished'] = 0;
328
-                        $backup_file = $backup_parts[$part];
329
-                    }
330
-                }
331
-            }
332
-        }
333
-
334
-        //Sending backup to remote storage
295
+		$return_encrypted['finished'] = 0;
296
+		$return_encrypted['start'] = 0;
297
+		$return_encrypted['iv'] = '';
298
+		$return_encrypted['target_file'] = '';
299
+		$part = 0;
300
+		$backup_parts = array();
301
+
302
+		if( $schedule['backup_params']->backup_encrypt){
303
+			$this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) );
304
+
305
+			$backup_file = $return['extra']['backup_parent'];
306
+
307
+			if ($this->xcloner_file_system->is_multipart($return['extra']['backup_parent'])) {
308
+				$backup_parts = $this->xcloner_file_system->get_multipart_files($return['extra']['backup_parent']);
309
+				$backup_file = $backup_parts[$part];
310
+			}
311
+
312
+			while ( ! $return_encrypted['finished'] ) {
313
+				$return_encrypted = $this->xcloner_encryption->encrypt_file(
314
+											$backup_file,
315
+											"",
316
+											"",
317
+											"",
318
+											"",
319
+											true,
320
+											true
321
+				);
322
+
323
+				if($return_encrypted['finished']) {
324
+					++$part;
325
+
326
+					if ($part < sizeof($backup_parts)) {
327
+						$return_encrypted['finished'] = 0;
328
+						$backup_file = $backup_parts[$part];
329
+					}
330
+				}
331
+			}
332
+		}
333
+
334
+		//Sending backup to remote storage
335 335
 		if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) {
336 336
 			$backup_file = $return['extra']['backup_parent'];
337 337
 
@@ -382,10 +382,10 @@  discard block
 block discarded – undo
382 382
 		}
383 383
 
384 384
 		try {
385
-            if( get_option('xcloner_disable_email_notification') ) {
386
-                //we disable email notifications
387
-                $schedule['backup_params']->email_notification = "";
388
-            }
385
+			if( get_option('xcloner_disable_email_notification') ) {
386
+				//we disable email notifications
387
+				$schedule['backup_params']->email_notification = "";
388
+			}
389 389
 			$this->_xcloner_scheduler_callback( $id, $schedule );
390 390
 
391 391
 		} catch ( Exception $e ) {
Please login to merge, or discard this patch.
includes/class-xcloner-file-system.php 1 patch
Indentation   +957 added lines, -957 removed lines patch added patch discarded remove patch
@@ -37,848 +37,848 @@  discard block
 block discarded – undo
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
-    public function get_storage_path_file_info($file)
211
-    {
212
-        return $this->getMetadataFull('storage_adapter', $file);
213
-    }
214
-
215
-    public function get_included_files_handler($metadata = 0)
216
-    {
217
-        $path = $this->included_files_handler;
218
-        if (!$metadata) {
219
-            return $path;
220
-        }
221
-
222
-        $spl_info = $this->getMetadataFull('tmp_adapter', $path);
223
-
224
-        return $spl_info;
225
-
226
-    }
227
-
228
-    public function get_temp_dir_handler()
229
-    {
230
-        return $this->temp_dir_handler;
231
-    }
232
-
233
-    public function get_latest_backup()
234
-    {
235
-        $files = $this->get_backup_archives_list();
236
-
237
-        if (is_array($files)) {
238
-            $this->sort_by($files, "timestamp", "desc");
239
-        }
240
-
241
-        $new_list = array();
242
-
243
-        foreach ($files as $key => $file) {
244
-            if (!isset($file['parent'])) {
245
-                $new_list[] = ($files[$key]);
246
-            }
247
-        }
248
-
249
-        if (isset($new_list[0])) {
250
-            return $new_list[0];
251
-        }
252
-    }
253
-
254
-    public function get_latest_backups()
255
-    {
256
-        $files = $this->get_backup_archives_list();
257
-
258
-        if (is_array($files)) {
259
-            $this->sort_by($files, "timestamp", "desc");
260
-        }
261
-
262
-        $new_list = array();
263
-
264
-        foreach ($files as $key => $file) {
265
-            if (!isset($file['parent'])) {
266
-                $new_list[] = ($files[$key]);
267
-            }
268
-        }
269
-
270
-        return $new_list;
271
-    }
272
-
273
-    public function get_storage_usage()
274
-    {
275
-        $files = $this->get_backup_archives_list();
276
-        $total = 0;
277
-
278
-        if (is_array($files)) {
279
-            foreach ($files as $file) {
280
-                $total += $file['size'];
281
-            }
282
-        }
283
-
284
-        return $total;
285
-    }
286
-
287
-    public function is_part($backup_name)
288
-    {
289
-        if (stristr($backup_name, "-part")) {
290
-            return true;
291
-        }
292
-
293
-        return false;
294
-    }
295
-
296
-    public function is_multipart($backup_name)
297
-    {
298
-        if (stristr($backup_name, "-multipart")) {
299
-            return true;
300
-        }
301
-
302
-        return false;
303
-    }
304
-
305
-    public function get_backup_size($backup_name)
306
-    {
307
-        $backup_size = $this->get_storage_filesystem()->getSize($backup_name);
308
-        if ($this->is_multipart($backup_name)) {
309
-            $backup_parts = $this->get_multipart_files($backup_name);
310
-            foreach ($backup_parts as $part_file) {
311
-                $backup_size += $this->get_storage_filesystem()->getSize($part_file);
312
-            }
313
-        }
314
-
315
-        return $backup_size;
316
-    }
317
-
318
-    public function get_multipart_files($backup_name, $storage_selection = "")
319
-    {
320
-        $files = array();
321
-
322
-        if ($this->is_multipart($backup_name)) {
323
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
324
-            foreach ($lines as $line) {
325
-                if ($line) {
326
-                    $data = str_getcsv($line);
327
-                    $files[] = $data[0];
328
-                }
329
-            }
330
-        }
331
-
332
-        return $files;
333
-    }
334
-
335
-    public function delete_backup_by_name($backup_name, $storage_selection = "")
336
-    {
337
-        if ($this->is_multipart($backup_name)) {
338
-            $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
339
-            foreach ($lines as $line) {
340
-                if ($line) {
341
-                    $data = str_getcsv($line);
342
-                    $this->get_storage_filesystem($storage_selection)->delete($data[0]);
343
-                }
344
-            }
345
-        }
346
-
347
-        if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
348
-            $return = true;
349
-        } else {
350
-            $return = false;
351
-        }
352
-
353
-        return $return;
354
-    }
355
-
356
-    public function getMetadataFull($adapter = "storage_adapter", $path)
357
-    {
358
-        $location = $this->$adapter->applyPathPrefix($path);
359
-        $spl_info = new SplFileInfo($location);
360
-
361
-        return ($spl_info);
362
-    }
363
-
364
-
365
-    public function get_backup_archives_list($storage_selection = "")
366
-    {
367
-        $list = array();
368
-
369
-
370
-        if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
371
-            $list = $this->get_storage_filesystem($storage_selection)->listContents();
372
-        }
373
-
374
-        $backup_files = array();
375
-        $parents = array();
376
-
377
-        foreach ($list as $file_info) {
378
-            if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
379
-                $data = array();
380
-
381
-                $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
382
-                foreach ($lines as $line) {
383
-                    if ($line) {
384
-                        $data = str_getcsv($line);
385
-                        if (is_array($data)) {
386
-                            $parents[$data[0]] = $file_info['basename'];
387
-                            $file_info['childs'][] = $data;
388
-                            $file_info['size'] += $data[2];
389
-                        }
390
-                    }
391
-                }
392
-
393
-            }
394
-
395
-            if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
396
-                    $this->backup_archive_extensions)) {
397
-                $backup_files[$file_info['path']] = $file_info;
398
-            }
399
-        }
400
-
401
-        foreach ($backup_files as $key => $file_info) {
402
-            if (!isset($backup_files[$key]['timestamp'])) {
403
-                //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
404
-            }
405
-
406
-            if (isset($parents[$file_info['basename']])) {
407
-                $backup_files[$key]['parent'] = $parents[$file_info['basename']];
408
-            }
409
-        }
410
-
411
-        return $backup_files;
412
-    }
413
-
414
-    public function start_file_recursion($init = 0)
415
-    {
416
-        if ($init) {
417
-            $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
418
-                $this->xcloner_settings->get_xcloner_start_path()));
419
-            $this->do_system_init();
420
-        }
421
-
422
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
423
-            //.dir exists, we presume we have files to iterate
424
-            $content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
425
-            $files = array_filter(explode("\n", $content));
426
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
427
-
428
-            $counter = 0;
429
-            foreach ($files as $file) {
430
-                if ($counter < $this->folders_to_process_per_session) {
431
-                    $this->build_files_list($file);
432
-                    $counter++;
433
-                } else {
434
-                    $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n");
435
-                }
436
-            }
437
-        } else {
438
-            $this->build_files_list();
439
-        }
440
-
441
-        if ($this->scan_finished()) {
442
-            $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
443
-            $this->store_file($metadata_dumpfile, 'tmp_filesystem');
444
-            $this->files_counter++;
445
-
446
-            //adding included dump file to the included files list
447
-            if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
448
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
449
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
450
-                $this->files_counter++;
451
-            }
452
-
453
-            //adding a default index.html to the temp xcloner folder
454
-            if (!$this->get_tmp_filesystem()->has("index.html")) {
455
-                $this->get_tmp_filesystem()->write("index.html", "");
456
-            }
457
-
458
-            //adding the default log file
459
-            if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
460
-                $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
461
-                $this->store_file($metadata_dumpfile, 'tmp_filesystem');
462
-                $this->files_counter++;
463
-            }
464
-
465
-            return false;
466
-        }
467
-
468
-        return true;
469
-    }
470
-
471
-    public function get_backup_attachments()
472
-    {
473
-        $return = array();
474
-
475
-        $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler();
476
-        if (file_exists($files_list_file)) {
477
-            $return[] = $files_list_file;
478
-        }
479
-
480
-        if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
481
-            $log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1);
482
-            if (!file_exists($log_file)) {
483
-                $log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename();
484
-            }
485
-
486
-            if (file_exists($log_file)) {
487
-                $return[] = $log_file;
488
-            }
489
-        }
490
-
491
-        return $return;
492
-    }
493
-
494
-    public function remove_tmp_filesystem()
495
-    {
496
-        //delete the temporary folder
497
-        $this->logger->debug(sprintf("Deleting the temporary storage folder %s",
498
-            $this->xcloner_settings->get_xcloner_tmp_path()));
499
-
500
-        $contents = $this->get_tmp_filesystem()->listContents();
501
-
502
-        if (is_array($contents)) {
503
-            foreach ($contents as $file_info) {
504
-                $this->get_tmp_filesystem()->delete($file_info['path']);
505
-            }
506
-        }
507
-
508
-        @rmdir($this->xcloner_settings->get_xcloner_tmp_path());
509
-
510
-        return;
511
-    }
512
-
513
-    public function cleanup_tmp_directories()
514
-    {
515
-        $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
516
-        $tmp_filesystem = new Filesystem($adapter, new Config([
517
-            'disable_asserts' => true,
518
-        ]));
519
-
520
-        $contents = $tmp_filesystem->listContents();
521
-
522
-        foreach ($contents as $file) {
523
-
524
-            if (preg_match("/.xcloner-(.*)/", $file['path'])) {
525
-                if ($file['timestamp'] < strtotime("-1days")) {
526
-                    $tmp_filesystem->deleteDir($file['path']);
527
-                    $this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
528
-                }
529
-            }
530
-        }
531
-
532
-        return true;
533
-    }
534
-
535
-    private function do_system_init()
536
-    {
537
-        $this->files_counter = 0;
538
-
539
-        if (!$this->storage_filesystem->has("index.html")) {
540
-            $this->storage_filesystem->write("index.html", "");
541
-        }
542
-
543
-        if (!$this->tmp_filesystem->has("index.html")) {
544
-            $this->tmp_filesystem->write("index.html", "");
545
-        }
546
-
547
-        if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
548
-            $this->tmp_filesystem->delete($this->get_included_files_handler());
549
-        }
550
-
551
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
552
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
553
-        }
554
-    }
555
-
556
-    public function get_scanned_files_num()
557
-    {
558
-        return $this->files_counter;
559
-    }
560
-
561
-    public function get_scanned_files_total_size()
562
-    {
563
-        return $this->files_size;
564
-    }
565
-
566
-    public function last_logged_file()
567
-    {
568
-        return $this->last_logged_file;
569
-    }
570
-
571
-    public static function is_regex($regex)
572
-    {
573
-        return preg_match("/^\^(.*)\$$/i", $regex);
574
-    }
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
+	public function get_storage_path_file_info($file)
211
+	{
212
+		return $this->getMetadataFull('storage_adapter', $file);
213
+	}
214
+
215
+	public function get_included_files_handler($metadata = 0)
216
+	{
217
+		$path = $this->included_files_handler;
218
+		if (!$metadata) {
219
+			return $path;
220
+		}
221
+
222
+		$spl_info = $this->getMetadataFull('tmp_adapter', $path);
223
+
224
+		return $spl_info;
225
+
226
+	}
227
+
228
+	public function get_temp_dir_handler()
229
+	{
230
+		return $this->temp_dir_handler;
231
+	}
232
+
233
+	public function get_latest_backup()
234
+	{
235
+		$files = $this->get_backup_archives_list();
236
+
237
+		if (is_array($files)) {
238
+			$this->sort_by($files, "timestamp", "desc");
239
+		}
240
+
241
+		$new_list = array();
242
+
243
+		foreach ($files as $key => $file) {
244
+			if (!isset($file['parent'])) {
245
+				$new_list[] = ($files[$key]);
246
+			}
247
+		}
248
+
249
+		if (isset($new_list[0])) {
250
+			return $new_list[0];
251
+		}
252
+	}
253
+
254
+	public function get_latest_backups()
255
+	{
256
+		$files = $this->get_backup_archives_list();
257
+
258
+		if (is_array($files)) {
259
+			$this->sort_by($files, "timestamp", "desc");
260
+		}
261
+
262
+		$new_list = array();
263
+
264
+		foreach ($files as $key => $file) {
265
+			if (!isset($file['parent'])) {
266
+				$new_list[] = ($files[$key]);
267
+			}
268
+		}
269
+
270
+		return $new_list;
271
+	}
272
+
273
+	public function get_storage_usage()
274
+	{
275
+		$files = $this->get_backup_archives_list();
276
+		$total = 0;
277
+
278
+		if (is_array($files)) {
279
+			foreach ($files as $file) {
280
+				$total += $file['size'];
281
+			}
282
+		}
283
+
284
+		return $total;
285
+	}
286
+
287
+	public function is_part($backup_name)
288
+	{
289
+		if (stristr($backup_name, "-part")) {
290
+			return true;
291
+		}
292
+
293
+		return false;
294
+	}
295
+
296
+	public function is_multipart($backup_name)
297
+	{
298
+		if (stristr($backup_name, "-multipart")) {
299
+			return true;
300
+		}
301
+
302
+		return false;
303
+	}
304
+
305
+	public function get_backup_size($backup_name)
306
+	{
307
+		$backup_size = $this->get_storage_filesystem()->getSize($backup_name);
308
+		if ($this->is_multipart($backup_name)) {
309
+			$backup_parts = $this->get_multipart_files($backup_name);
310
+			foreach ($backup_parts as $part_file) {
311
+				$backup_size += $this->get_storage_filesystem()->getSize($part_file);
312
+			}
313
+		}
314
+
315
+		return $backup_size;
316
+	}
317
+
318
+	public function get_multipart_files($backup_name, $storage_selection = "")
319
+	{
320
+		$files = array();
321
+
322
+		if ($this->is_multipart($backup_name)) {
323
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
324
+			foreach ($lines as $line) {
325
+				if ($line) {
326
+					$data = str_getcsv($line);
327
+					$files[] = $data[0];
328
+				}
329
+			}
330
+		}
331
+
332
+		return $files;
333
+	}
334
+
335
+	public function delete_backup_by_name($backup_name, $storage_selection = "")
336
+	{
337
+		if ($this->is_multipart($backup_name)) {
338
+			$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name));
339
+			foreach ($lines as $line) {
340
+				if ($line) {
341
+					$data = str_getcsv($line);
342
+					$this->get_storage_filesystem($storage_selection)->delete($data[0]);
343
+				}
344
+			}
345
+		}
346
+
347
+		if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) {
348
+			$return = true;
349
+		} else {
350
+			$return = false;
351
+		}
352
+
353
+		return $return;
354
+	}
355
+
356
+	public function getMetadataFull($adapter = "storage_adapter", $path)
357
+	{
358
+		$location = $this->$adapter->applyPathPrefix($path);
359
+		$spl_info = new SplFileInfo($location);
360
+
361
+		return ($spl_info);
362
+	}
363
+
364
+
365
+	public function get_backup_archives_list($storage_selection = "")
366
+	{
367
+		$list = array();
368
+
369
+
370
+		if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) {
371
+			$list = $this->get_storage_filesystem($storage_selection)->listContents();
372
+		}
373
+
374
+		$backup_files = array();
375
+		$parents = array();
376
+
377
+		foreach ($list as $file_info) {
378
+			if (isset($file_info['extension']) and $file_info['extension'] == "csv") {
379
+				$data = array();
380
+
381
+				$lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path']));
382
+				foreach ($lines as $line) {
383
+					if ($line) {
384
+						$data = str_getcsv($line);
385
+						if (is_array($data)) {
386
+							$parents[$data[0]] = $file_info['basename'];
387
+							$file_info['childs'][] = $data;
388
+							$file_info['size'] += $data[2];
389
+						}
390
+					}
391
+				}
392
+
393
+			}
394
+
395
+			if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'],
396
+					$this->backup_archive_extensions)) {
397
+				$backup_files[$file_info['path']] = $file_info;
398
+			}
399
+		}
400
+
401
+		foreach ($backup_files as $key => $file_info) {
402
+			if (!isset($backup_files[$key]['timestamp'])) {
403
+				//$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']);
404
+			}
405
+
406
+			if (isset($parents[$file_info['basename']])) {
407
+				$backup_files[$key]['parent'] = $parents[$file_info['basename']];
408
+			}
409
+		}
410
+
411
+		return $backup_files;
412
+	}
413
+
414
+	public function start_file_recursion($init = 0)
415
+	{
416
+		if ($init) {
417
+			$this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"),
418
+				$this->xcloner_settings->get_xcloner_start_path()));
419
+			$this->do_system_init();
420
+		}
421
+
422
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
423
+			//.dir exists, we presume we have files to iterate
424
+			$content = $this->tmp_filesystem->read($this->get_temp_dir_handler());
425
+			$files = array_filter(explode("\n", $content));
426
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
427
+
428
+			$counter = 0;
429
+			foreach ($files as $file) {
430
+				if ($counter < $this->folders_to_process_per_session) {
431
+					$this->build_files_list($file);
432
+					$counter++;
433
+				} else {
434
+					$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n");
435
+				}
436
+			}
437
+		} else {
438
+			$this->build_files_list();
439
+		}
440
+
441
+		if ($this->scan_finished()) {
442
+			$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html");
443
+			$this->store_file($metadata_dumpfile, 'tmp_filesystem');
444
+			$this->files_counter++;
445
+
446
+			//adding included dump file to the included files list
447
+			if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) {
448
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler());
449
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
450
+				$this->files_counter++;
451
+			}
452
+
453
+			//adding a default index.html to the temp xcloner folder
454
+			if (!$this->get_tmp_filesystem()->has("index.html")) {
455
+				$this->get_tmp_filesystem()->write("index.html", "");
456
+			}
457
+
458
+			//adding the default log file
459
+			if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) {
460
+				$metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1));
461
+				$this->store_file($metadata_dumpfile, 'tmp_filesystem');
462
+				$this->files_counter++;
463
+			}
464
+
465
+			return false;
466
+		}
467
+
468
+		return true;
469
+	}
470
+
471
+	public function get_backup_attachments()
472
+	{
473
+		$return = array();
474
+
475
+		$files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler();
476
+		if (file_exists($files_list_file)) {
477
+			$return[] = $files_list_file;
478
+		}
479
+
480
+		if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) {
481
+			$log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1);
482
+			if (!file_exists($log_file)) {
483
+				$log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename();
484
+			}
485
+
486
+			if (file_exists($log_file)) {
487
+				$return[] = $log_file;
488
+			}
489
+		}
490
+
491
+		return $return;
492
+	}
493
+
494
+	public function remove_tmp_filesystem()
495
+	{
496
+		//delete the temporary folder
497
+		$this->logger->debug(sprintf("Deleting the temporary storage folder %s",
498
+			$this->xcloner_settings->get_xcloner_tmp_path()));
499
+
500
+		$contents = $this->get_tmp_filesystem()->listContents();
501
+
502
+		if (is_array($contents)) {
503
+			foreach ($contents as $file_info) {
504
+				$this->get_tmp_filesystem()->delete($file_info['path']);
505
+			}
506
+		}
507
+
508
+		@rmdir($this->xcloner_settings->get_xcloner_tmp_path());
509
+
510
+		return;
511
+	}
512
+
513
+	public function cleanup_tmp_directories()
514
+	{
515
+		$adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS');
516
+		$tmp_filesystem = new Filesystem($adapter, new Config([
517
+			'disable_asserts' => true,
518
+		]));
519
+
520
+		$contents = $tmp_filesystem->listContents();
521
+
522
+		foreach ($contents as $file) {
523
+
524
+			if (preg_match("/.xcloner-(.*)/", $file['path'])) {
525
+				if ($file['timestamp'] < strtotime("-1days")) {
526
+					$tmp_filesystem->deleteDir($file['path']);
527
+					$this->logger->debug(sprintf("Delete temporary directory %s", $file['path']));
528
+				}
529
+			}
530
+		}
531
+
532
+		return true;
533
+	}
534
+
535
+	private function do_system_init()
536
+	{
537
+		$this->files_counter = 0;
538
+
539
+		if (!$this->storage_filesystem->has("index.html")) {
540
+			$this->storage_filesystem->write("index.html", "");
541
+		}
542
+
543
+		if (!$this->tmp_filesystem->has("index.html")) {
544
+			$this->tmp_filesystem->write("index.html", "");
545
+		}
546
+
547
+		if ($this->tmp_filesystem->has($this->get_included_files_handler())) {
548
+			$this->tmp_filesystem->delete($this->get_included_files_handler());
549
+		}
550
+
551
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
552
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
553
+		}
554
+	}
555
+
556
+	public function get_scanned_files_num()
557
+	{
558
+		return $this->files_counter;
559
+	}
560
+
561
+	public function get_scanned_files_total_size()
562
+	{
563
+		return $this->files_size;
564
+	}
565
+
566
+	public function last_logged_file()
567
+	{
568
+		return $this->last_logged_file;
569
+	}
570
+
571
+	public static function is_regex($regex)
572
+	{
573
+		return preg_match("/^\^(.*)\$$/i", $regex);
574
+	}
575 575
 
576
-    public function set_excluded_files($excluded_files = array())
577
-    {
578
-        if (!is_array($excluded_files)) {
579
-            $excluded_files = array();
580
-        }
576
+	public function set_excluded_files($excluded_files = array())
577
+	{
578
+		if (!is_array($excluded_files)) {
579
+			$excluded_files = array();
580
+		}
581 581
 
582
-        foreach ($excluded_files as $excl) {
582
+		foreach ($excluded_files as $excl) {
583 583
 
584
-            if ($this->is_regex($excl)) {
585
-                $this->additional_regex_patterns[] = $excl;
586
-            }
587
-        }
584
+			if ($this->is_regex($excl)) {
585
+				$this->additional_regex_patterns[] = $excl;
586
+			}
587
+		}
588 588
 
589
-        $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
589
+		$this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default);
590 590
 
591
-        return $this->excluded_files;
592
-    }
591
+		return $this->excluded_files;
592
+	}
593 593
 
594
-    public function get_excluded_files()
595
-    {
596
-        return $this->excluded_files_by_default;
597
-    }
594
+	public function get_excluded_files()
595
+	{
596
+		return $this->excluded_files_by_default;
597
+	}
598 598
 
599
-    public function list_directory($path)
600
-    {
601
-        return $this->start_filesystem->listContents($path);
602
-    }
599
+	public function list_directory($path)
600
+	{
601
+		return $this->start_filesystem->listContents($path);
602
+	}
603 603
 
604
-    public function build_files_list($folder = "")
605
-    {
606
-        $this->logger->debug(sprintf(("Building the files system list")));
604
+	public function build_files_list($folder = "")
605
+	{
606
+		$this->logger->debug(sprintf(("Building the files system list")));
607 607
 
608
-        //if we start with the root folder(empty value), we initializa the file system
609
-        if (!$folder) {
608
+		//if we start with the root folder(empty value), we initializa the file system
609
+		if (!$folder) {
610 610
 
611
-        }
611
+		}
612 612
 
613
-        try {
613
+		try {
614 614
 
615
-            $files = $this->start_filesystem->listContents($folder);
616
-            foreach ($files as $file) {
617
-                if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) {
618
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
619
-                        $file['path']), array(
620
-                        "FILESYSTEM SCAN",
621
-                        "NOT READABLE"
622
-                    ));
623
-                } elseif (!$matching_pattern = $this->is_excluded($file)) {
624
-                    $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
625
-                        "FILESYSTEM SCAN",
626
-                        "INCLUDE"
627
-                    ));
628
-                    $file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
629
-                    if ($this->store_file($file)) {
630
-                        $this->files_counter++;
631
-                    }
632
-                    if (isset($file['size'])) {
633
-                        $this->files_size += $file['size'];
634
-                    }
635
-
636
-                } else {
637
-                    $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
638
-                        $file['path'], $matching_pattern), array(
639
-                        "FILESYSTEM SCAN",
640
-                        "EXCLUDE"
641
-                    ));
642
-                }
643
-            }
615
+			$files = $this->start_filesystem->listContents($folder);
616
+			foreach ($files as $file) {
617
+				if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) {
618
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"),
619
+						$file['path']), array(
620
+						"FILESYSTEM SCAN",
621
+						"NOT READABLE"
622
+					));
623
+				} elseif (!$matching_pattern = $this->is_excluded($file)) {
624
+					$this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array(
625
+						"FILESYSTEM SCAN",
626
+						"INCLUDE"
627
+					));
628
+					$file['visibility'] = $this->start_filesystem->getVisibility($file['path']);
629
+					if ($this->store_file($file)) {
630
+						$this->files_counter++;
631
+					}
632
+					if (isset($file['size'])) {
633
+						$this->files_size += $file['size'];
634
+					}
635
+
636
+				} else {
637
+					$this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"),
638
+						$file['path'], $matching_pattern), array(
639
+						"FILESYSTEM SCAN",
640
+						"EXCLUDE"
641
+					));
642
+				}
643
+			}
644 644
 
645
-        } catch (Exception $e) {
645
+		} catch (Exception $e) {
646 646
 
647
-            $this->logger->error($e->getMessage());
647
+			$this->logger->error($e->getMessage());
648 648
 
649
-        }
649
+		}
650 650
 
651
-    }
651
+	}
652 652
 
653
-    public function estimate_read_write_time()
654
-    {
655
-        $tmp_file = ".xcloner" . substr(md5(time()), 0, 5);
653
+	public function estimate_read_write_time()
654
+	{
655
+		$tmp_file = ".xcloner" . substr(md5(time()), 0, 5);
656 656
 
657
-        $start_time = microtime(true);
657
+		$start_time = microtime(true);
658 658
 
659
-        $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
659
+		$data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data
660 660
 
661
-        try {
662
-            $this->tmp_filesystem->write($tmp_file, $data);
661
+		try {
662
+			$this->tmp_filesystem->write($tmp_file, $data);
663 663
 
664
-            $end_time = microtime(true) - $start_time;
664
+			$end_time = microtime(true) - $start_time;
665 665
 
666
-            $return['writing_time'] = $end_time;
666
+			$return['writing_time'] = $end_time;
667 667
 
668
-            $return['reading_time'] = $this->estimate_reading_time($tmp_file);
668
+			$return['reading_time'] = $this->estimate_reading_time($tmp_file);
669 669
 
670
-            $this->tmp_filesystem->delete($tmp_file);
670
+			$this->tmp_filesystem->delete($tmp_file);
671 671
 
672
-        } catch (Exception $e) {
672
+		} catch (Exception $e) {
673 673
 
674
-            $this->logger->error($e->getMessage());
674
+			$this->logger->error($e->getMessage());
675 675
 
676
-        }
676
+		}
677 677
 
678
-        return $return;
679
-    }
678
+		return $return;
679
+	}
680 680
 
681
-    public function backup_storage_cleanup()
682
-    {
683
-        $this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
681
+	public function backup_storage_cleanup()
682
+	{
683
+		$this->logger->info(sprintf(("Cleaning the backup storage on matching rules")));
684 684
 
685
-        $_storage_size = 0;
686
-        $_backup_files_list = array();
685
+		$_storage_size = 0;
686
+		$_backup_files_list = array();
687 687
 
688
-        //rule date limit
689
-        $current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days");
688
+		//rule date limit
689
+		$current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days");
690 690
 
691
-        $files = $this->storage_filesystem->listContents();
691
+		$files = $this->storage_filesystem->listContents();
692 692
 
693
-        if (is_array($files)) {
694
-            foreach ($files as $file) {
695
-                if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
696
-                    $_storage_size += $file['size']; //bytes
697
-                    $_backup_files_list[] = $file;
698
-                }
699
-            }
700
-        }
693
+		if (is_array($files)) {
694
+			foreach ($files as $file) {
695
+				if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) {
696
+					$_storage_size += $file['size']; //bytes
697
+					$_backup_files_list[] = $file;
698
+				}
699
+			}
700
+		}
701 701
 
702 702
 
703
-        $this->sort_by($_backup_files_list, "timestamp", "asc");
703
+		$this->sort_by($_backup_files_list, "timestamp", "asc");
704 704
 
705
-        $_backups_counter = sizeof($_backup_files_list);
705
+		$_backups_counter = sizeof($_backup_files_list);
706 706
 
707
-        foreach ($_backup_files_list as $file) {
708
-            //processing rule folder capacity
709
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
710
-                $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
711
-            {
712
-                $this->storage_filesystem->delete($file['path']);
713
-                $_storage_size -= $file['size'];
714
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
715
-                    "STORAGE SIZE LIMIT",
716
-                    $_storage_size . " >= " . $set_storage_limit
717
-                ));
718
-            }
719
-
720
-            //processing rule days limit
721
-            if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
722
-                $this->storage_filesystem->delete($file['path']);
723
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
724
-                    "RETENTION LIMIT TIMESTAMP",
725
-                    $file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
726
-                ));
727
-            }
728
-
729
-            //processing backup countert limit
730
-            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')) {
731
-                $this->storage_filesystem->delete($file['path']);
732
-                $_backups_counter--;
733
-                $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
734
-                    "BACKUP QUANTITY LIMIT",
735
-                    $_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
736
-                ));
737
-            }
707
+		foreach ($_backup_files_list as $file) {
708
+			//processing rule folder capacity
709
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') &&
710
+				$_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit')))    //bytes
711
+			{
712
+				$this->storage_filesystem->delete($file['path']);
713
+				$_storage_size -= $file['size'];
714
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
715
+					"STORAGE SIZE LIMIT",
716
+					$_storage_size . " >= " . $set_storage_limit
717
+				));
718
+			}
719
+
720
+			//processing rule days limit
721
+			if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) {
722
+				$this->storage_filesystem->delete($file['path']);
723
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
724
+					"RETENTION LIMIT TIMESTAMP",
725
+					$file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')
726
+				));
727
+			}
728
+
729
+			//processing backup countert limit
730
+			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')) {
731
+				$this->storage_filesystem->delete($file['path']);
732
+				$_backups_counter--;
733
+				$this->logger->info("Deleting backup " . $file['path'] . " matching rule", array(
734
+					"BACKUP QUANTITY LIMIT",
735
+					$_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')
736
+				));
737
+			}
738 738
 
739 739
 
740
-        }
740
+		}
741 741
 
742
-    }
742
+	}
743 743
 
744
-    public function estimate_reading_time($tmp_file)
745
-    {
746
-        $this->logger->debug(sprintf(("Estimating file system reading time")));
744
+	public function estimate_reading_time($tmp_file)
745
+	{
746
+		$this->logger->debug(sprintf(("Estimating file system reading time")));
747 747
 
748
-        $start_time = microtime(true);
748
+		$start_time = microtime(true);
749 749
 
750
-        if ($this->tmp_filesystem->has($tmp_file)) {
751
-            $this->tmp_filesystem->read($tmp_file);
752
-        }
753
-
754
-        $end_time = microtime(true) - $start_time;
755
-
756
-        return $end_time;
757
-
758
-    }
759
-
760
-    public function process_backup_name($name = "", $max_length = 100)
761
-    {
762
-        if (!$name) {
763
-            $name = $this->xcloner_settings->get_default_backup_name();
764
-        }
765
-
766
-        foreach ($this->backup_name_tags as $tag) {
767
-            if ($tag == '[time]') {
768
-                $name = str_replace($tag, date("Y-m-d_H-i"), $name);
769
-            } elseif ($tag == '[hostname]') {
770
-                $name = str_replace($tag, gethostname(), $name);
771
-            } elseif ($tag == '[domain]') {
772
-                $domain = parse_url(admin_url(), PHP_URL_HOST);
773
-                $name = str_replace($tag, $domain, $name);
774
-            }
775
-        }
776
-
777
-        if ($max_length) {
778
-            $name = substr($name, 0, $max_length);
779
-        }
780
-
781
-        return $name;
782
-    }
783
-
784
-    public function sort_by(&$array, $field, $direction = 'asc')
785
-    {
786
-        if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
787
-            $direction = SORT_DESC;
788
-        } else {
789
-            $direction = SORT_ASC;
790
-        }
791
-
792
-        $array = $this->array_orderby($array, $field, $direction);
793
-
794
-        return true;
795
-    }
796
-
797
-    private function array_orderby()
798
-    {
799
-        $args = func_get_args();
800
-        $data = array_shift($args);
801
-
802
-        foreach ($args as $n => $field) {
803
-            if (is_string($field)) {
804
-                $tmp = array();
805
-                foreach ($data as $key => $row) {
806
-                    if (is_array($row)) {
807
-                        $tmp[$key] = $row[$field];
808
-                    } else {
809
-                        $tmp[$key] = $row->$field;
810
-                    }
811
-                }
812
-                $args[$n] = $tmp;
813
-            }
814
-        }
815
-        $args[] = &$data;
816
-
817
-        call_user_func_array('array_multisort', $args);
818
-
819
-        return array_pop($args);
820
-    }
821
-
822
-    private function check_file_diff_time($file)
823
-    {
824
-        if ($this->get_diff_timestamp_start() != "") {
825
-            $fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
826
-            $timestamp = $fileMeta->getMTime();
827
-            if ($timestamp < $fileMeta->getCTime()) {
828
-                $timestamp = $fileMeta->getCTime();
829
-            }
830
-
831
-            if ($timestamp <= $this->get_diff_timestamp_start()) {
832
-                return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start;
833
-            }
834
-        }
835
-
836
-        return false;
837
-    }
838
-
839
-    public function is_excluded($file)
840
-    {
841
-        $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
842
-
843
-        if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
844
-            if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
845
-                return "> " . $xcloner_exclude_files_larger_than_mb . "MB";
846
-            }
847
-        }
848
-
849
-        if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
850
-            $this->set_excluded_files();
851
-        }
852
-
853
-        if (is_array($this->excluded_files)) {
854
-            foreach ($this->excluded_files as $excluded_file_pattern) {
855
-                if ($excluded_file_pattern == "/") {
856
-                    $needle = "$";
857
-                } else {
858
-                    $needle = "$" . $excluded_file_pattern;
859
-                }
860
-
861
-                if (strstr("$" . $file['path'], $needle)) {
862
-                    return $excluded_file_pattern;
863
-                }
864
-            }
865
-        }
866
-
867
-        if ($regex = $this->is_excluded_regex($file)) {
868
-            return $regex;
869
-        }
870
-
871
-        if ($file['type'] == "file") {
872
-            $check_file_diff_timestamp = $this->check_file_diff_time($file);
873
-            if ($check_file_diff_timestamp) {
874
-                return $check_file_diff_timestamp;
875
-            }
876
-        }
877
-
878
-        return false;
879
-    }
880
-
881
-    /*REGEX examples
750
+		if ($this->tmp_filesystem->has($tmp_file)) {
751
+			$this->tmp_filesystem->read($tmp_file);
752
+		}
753
+
754
+		$end_time = microtime(true) - $start_time;
755
+
756
+		return $end_time;
757
+
758
+	}
759
+
760
+	public function process_backup_name($name = "", $max_length = 100)
761
+	{
762
+		if (!$name) {
763
+			$name = $this->xcloner_settings->get_default_backup_name();
764
+		}
765
+
766
+		foreach ($this->backup_name_tags as $tag) {
767
+			if ($tag == '[time]') {
768
+				$name = str_replace($tag, date("Y-m-d_H-i"), $name);
769
+			} elseif ($tag == '[hostname]') {
770
+				$name = str_replace($tag, gethostname(), $name);
771
+			} elseif ($tag == '[domain]') {
772
+				$domain = parse_url(admin_url(), PHP_URL_HOST);
773
+				$name = str_replace($tag, $domain, $name);
774
+			}
775
+		}
776
+
777
+		if ($max_length) {
778
+			$name = substr($name, 0, $max_length);
779
+		}
780
+
781
+		return $name;
782
+	}
783
+
784
+	public function sort_by(&$array, $field, $direction = 'asc')
785
+	{
786
+		if (strtolower($direction) == "desc" || $direction == SORT_DESC) {
787
+			$direction = SORT_DESC;
788
+		} else {
789
+			$direction = SORT_ASC;
790
+		}
791
+
792
+		$array = $this->array_orderby($array, $field, $direction);
793
+
794
+		return true;
795
+	}
796
+
797
+	private function array_orderby()
798
+	{
799
+		$args = func_get_args();
800
+		$data = array_shift($args);
801
+
802
+		foreach ($args as $n => $field) {
803
+			if (is_string($field)) {
804
+				$tmp = array();
805
+				foreach ($data as $key => $row) {
806
+					if (is_array($row)) {
807
+						$tmp[$key] = $row[$field];
808
+					} else {
809
+						$tmp[$key] = $row->$field;
810
+					}
811
+				}
812
+				$args[$n] = $tmp;
813
+			}
814
+		}
815
+		$args[] = &$data;
816
+
817
+		call_user_func_array('array_multisort', $args);
818
+
819
+		return array_pop($args);
820
+	}
821
+
822
+	private function check_file_diff_time($file)
823
+	{
824
+		if ($this->get_diff_timestamp_start() != "") {
825
+			$fileMeta = $this->getMetadataFull("start_adapter", $file['path']);
826
+			$timestamp = $fileMeta->getMTime();
827
+			if ($timestamp < $fileMeta->getCTime()) {
828
+				$timestamp = $fileMeta->getCTime();
829
+			}
830
+
831
+			if ($timestamp <= $this->get_diff_timestamp_start()) {
832
+				return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start;
833
+			}
834
+		}
835
+
836
+		return false;
837
+	}
838
+
839
+	public function is_excluded($file)
840
+	{
841
+		$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
842
+
843
+		if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) {
844
+			if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) {
845
+				return "> " . $xcloner_exclude_files_larger_than_mb . "MB";
846
+			}
847
+		}
848
+
849
+		if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) {
850
+			$this->set_excluded_files();
851
+		}
852
+
853
+		if (is_array($this->excluded_files)) {
854
+			foreach ($this->excluded_files as $excluded_file_pattern) {
855
+				if ($excluded_file_pattern == "/") {
856
+					$needle = "$";
857
+				} else {
858
+					$needle = "$" . $excluded_file_pattern;
859
+				}
860
+
861
+				if (strstr("$" . $file['path'], $needle)) {
862
+					return $excluded_file_pattern;
863
+				}
864
+			}
865
+		}
866
+
867
+		if ($regex = $this->is_excluded_regex($file)) {
868
+			return $regex;
869
+		}
870
+
871
+		if ($file['type'] == "file") {
872
+			$check_file_diff_timestamp = $this->check_file_diff_time($file);
873
+			if ($check_file_diff_timestamp) {
874
+				return $check_file_diff_timestamp;
875
+			}
876
+		}
877
+
878
+		return false;
879
+	}
880
+
881
+	/*REGEX examples
882 882
      *
883 883
     * exclude all except .php file
884 884
     * PATTERN: ^(.*)\.(.+)$(?<!(php))
@@ -910,163 +910,163 @@  discard block
 block discarded – undo
910 910
     * exclude the backup folders
911 911
     * PATTERN: (^|^\/)(wp-content\/backups|administrator\/backups)(.*)$";
912 912
     */
913
-    private function is_excluded_regex($file)
914
-    {
915
-        //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
916
-
917
-        $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
918
-
919
-        if (is_array($this->additional_regex_patterns)) {
920
-            $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
921
-        }
922
-
923
-        //print_r($regex_patterns);exit;
924
-
925
-        if (is_array($regex_patterns)) {
926
-            //$this->excluded_files = array();
927
-            //$this->excluded_files[] ="(.*)\.(git)(.*)$";
928
-            //$this->excluded_files[] ="wp-content\/backups(.*)$";
929
-
930
-            foreach ($regex_patterns as $excluded_file_pattern) {
931
-
932
-                if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
933
-                        strlen($excluded_file_pattern)) == "\r") {
934
-                    $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
935
-                }
936
-
937
-                if ($file['path'] == "/") {
938
-                    $needle = "/";
939
-                } else {
940
-                    $needle = "/" . $file['path'];
941
-                }
942
-                //echo $needle."---".$excluded_file_pattern."---\n";
943
-
944
-                if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) {
945
-                    return $excluded_file_pattern;
946
-                }
947
-            }
948
-        }
949
-
950
-        return false;
951
-    }
952
-
953
-    public function store_file($file, $storage = 'start_filesystem')
954
-    {
955
-        $this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
956
-
957
-        if (!isset($file['size'])) {
958
-            $file['size'] = 0;
959
-        }
960
-        if (!isset($file['visibility'])) {
961
-            $file['visibility'] = "private";
962
-        }
963
-
964
-        $csv_filename = str_replace('"', '""', $file['path']);
965
-
966
-        $line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL;
967
-
968
-        $this->last_logged_file = $file['path'];
969
-
970
-        if ($file['type'] == "dir") {
971
-            try {
972
-                $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n");
973
-            } catch (Exception $e) {
974
-                $this->logger->error($e->getMessage());
975
-            }
976
-        }
977
-
978
-        if ($this->get_diff_timestamp_start()) {
979
-            if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
980
-                $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
981
-                    $response), array(
982
-                    "FILESYSTEM SCAN",
983
-                    "DIR DIFF"
984
-                ));
985
-
986
-                return false;
987
-            }
988
-        }
989
-
990
-        try {
991
-            if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
992
-                //adding fix for UTF-8 CSV preview
993
-                $start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL;
994
-                $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
995
-            }
996
-
997
-            $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
998
-
999
-        } catch (Exception $e) {
1000
-
1001
-            $this->logger->error($e->getMessage());
1002
-        }
1003
-
1004
-        return true;
1005
-    }
1006
-
1007
-    public function get_fileystem_handler()
1008
-    {
1009
-        return $this;
1010
-    }
1011
-
1012
-    public function get_filesystem($system = "")
1013
-    {
1014
-        if ($system == "storage_filesystem_append") {
1015
-            return $this->storage_filesystem_append;
1016
-        } elseif ($system == "tmp_filesystem_append") {
1017
-            return $this->tmp_filesystem_append;
1018
-        } elseif ($system == "tmp_filesystem") {
1019
-            return $this->tmp_filesystem;
1020
-        } elseif ($system == "storage_filesystem") {
1021
-            return $this->storage_filesystem;
1022
-        } else {
1023
-            return $this->start_filesystem;
1024
-        }
1025
-    }
1026
-
1027
-    public function get_adapter($system)
1028
-    {
1029
-        if ($system == "tmp_filesystem") {
1030
-            return $this->tmp_adapter;
1031
-        } elseif ($system == "storage_filesystem") {
1032
-            return $this->storage_adapter;
1033
-        } else {
1034
-            return $this->start_adapter;
1035
-        }
1036
-    }
1037
-
1038
-    /**
1039
-     * File scan finished
1040
-     * Method called when file scan is finished
1041
-     *
1042
-     * @return bool
1043
-     */
1044
-    private function scan_finished()
1045
-    {
1046
-        if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1047
-            $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1048
-            return false;
1049
-        }
1050
-
1051
-        if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1052
-            $this->tmp_filesystem->delete($this->get_temp_dir_handler());
1053
-        }
1054
-
1055
-        $this->logger->debug(sprintf(("File scan finished")));
1056
-
1057
-        return true;
1058
-    }
1059
-
1060
-    /**
1061
-     * Calculate bytes from MB value
1062
-     *
1063
-     * @param int $mb_size
1064
-     *
1065
-     * @return float|int
1066
-     */
1067
-    private function calc_to_bytes($mb_size)
1068
-    {
1069
-        return $mb_size * (1024 * 1024);
1070
-    }
913
+	private function is_excluded_regex($file)
914
+	{
915
+		//$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path']));
916
+
917
+		$regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude'));
918
+
919
+		if (is_array($this->additional_regex_patterns)) {
920
+			$regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns);
921
+		}
922
+
923
+		//print_r($regex_patterns);exit;
924
+
925
+		if (is_array($regex_patterns)) {
926
+			//$this->excluded_files = array();
927
+			//$this->excluded_files[] ="(.*)\.(git)(.*)$";
928
+			//$this->excluded_files[] ="wp-content\/backups(.*)$";
929
+
930
+			foreach ($regex_patterns as $excluded_file_pattern) {
931
+
932
+				if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1,
933
+						strlen($excluded_file_pattern)) == "\r") {
934
+					$excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1);
935
+				}
936
+
937
+				if ($file['path'] == "/") {
938
+					$needle = "/";
939
+				} else {
940
+					$needle = "/" . $file['path'];
941
+				}
942
+				//echo $needle."---".$excluded_file_pattern."---\n";
943
+
944
+				if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) {
945
+					return $excluded_file_pattern;
946
+				}
947
+			}
948
+		}
949
+
950
+		return false;
951
+	}
952
+
953
+	public function store_file($file, $storage = 'start_filesystem')
954
+	{
955
+		$this->logger->debug(sprintf("Storing %s in the backup list", $file['path']));
956
+
957
+		if (!isset($file['size'])) {
958
+			$file['size'] = 0;
959
+		}
960
+		if (!isset($file['visibility'])) {
961
+			$file['visibility'] = "private";
962
+		}
963
+
964
+		$csv_filename = str_replace('"', '""', $file['path']);
965
+
966
+		$line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL;
967
+
968
+		$this->last_logged_file = $file['path'];
969
+
970
+		if ($file['type'] == "dir") {
971
+			try {
972
+				$this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n");
973
+			} catch (Exception $e) {
974
+				$this->logger->error($e->getMessage());
975
+			}
976
+		}
977
+
978
+		if ($this->get_diff_timestamp_start()) {
979
+			if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) {
980
+				$this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'],
981
+					$response), array(
982
+					"FILESYSTEM SCAN",
983
+					"DIR DIFF"
984
+				));
985
+
986
+				return false;
987
+			}
988
+		}
989
+
990
+		try {
991
+			if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) {
992
+				//adding fix for UTF-8 CSV preview
993
+				$start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL;
994
+				$this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line);
995
+			}
996
+
997
+			$this->tmp_filesystem_append->write($this->get_included_files_handler(), $line);
998
+
999
+		} catch (Exception $e) {
1000
+
1001
+			$this->logger->error($e->getMessage());
1002
+		}
1003
+
1004
+		return true;
1005
+	}
1006
+
1007
+	public function get_fileystem_handler()
1008
+	{
1009
+		return $this;
1010
+	}
1011
+
1012
+	public function get_filesystem($system = "")
1013
+	{
1014
+		if ($system == "storage_filesystem_append") {
1015
+			return $this->storage_filesystem_append;
1016
+		} elseif ($system == "tmp_filesystem_append") {
1017
+			return $this->tmp_filesystem_append;
1018
+		} elseif ($system == "tmp_filesystem") {
1019
+			return $this->tmp_filesystem;
1020
+		} elseif ($system == "storage_filesystem") {
1021
+			return $this->storage_filesystem;
1022
+		} else {
1023
+			return $this->start_filesystem;
1024
+		}
1025
+	}
1026
+
1027
+	public function get_adapter($system)
1028
+	{
1029
+		if ($system == "tmp_filesystem") {
1030
+			return $this->tmp_adapter;
1031
+		} elseif ($system == "storage_filesystem") {
1032
+			return $this->storage_adapter;
1033
+		} else {
1034
+			return $this->start_adapter;
1035
+		}
1036
+	}
1037
+
1038
+	/**
1039
+	 * File scan finished
1040
+	 * Method called when file scan is finished
1041
+	 *
1042
+	 * @return bool
1043
+	 */
1044
+	private function scan_finished()
1045
+	{
1046
+		if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) &&
1047
+			$this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) {
1048
+			return false;
1049
+		}
1050
+
1051
+		if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) {
1052
+			$this->tmp_filesystem->delete($this->get_temp_dir_handler());
1053
+		}
1054
+
1055
+		$this->logger->debug(sprintf(("File scan finished")));
1056
+
1057
+		return true;
1058
+	}
1059
+
1060
+	/**
1061
+	 * Calculate bytes from MB value
1062
+	 *
1063
+	 * @param int $mb_size
1064
+	 *
1065
+	 * @return float|int
1066
+	 */
1067
+	private function calc_to_bytes($mb_size)
1068
+	{
1069
+		return $mb_size * (1024 * 1024);
1070
+	}
1071 1071
 
1072 1072
 }
Please login to merge, or discard this patch.
includes/class-xcloner-file-transfer.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -29,137 +29,137 @@
 block discarded – undo
29 29
 class Xcloner_File_Transfer extends Xcloner_File_System
30 30
 {
31 31
 
32
-    /**
33
-     * Target url web address of the restore script
34
-     * @var string
35
-     */
36
-    private $target_url;
37
-    /**
38
-     * Transfer data limit in bytes
39
-     * @var int
40
-     */
41
-    private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400
32
+	/**
33
+	 * Target url web address of the restore script
34
+	 * @var string
35
+	 */
36
+	private $target_url;
37
+	/**
38
+	 * Transfer data limit in bytes
39
+	 * @var int
40
+	 */
41
+	private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400
42 42
 
43 43
 
44
-    /**
45
-     * @param $target_url
46
-     *
47
-     * @return mixed
48
-     */
49
-    public function set_target($target_url)
50
-    {
51
-        return $this->target_url = $target_url;
52
-    }
44
+	/**
45
+	 * @param $target_url
46
+	 *
47
+	 * @return mixed
48
+	 */
49
+	public function set_target($target_url)
50
+	{
51
+		return $this->target_url = $target_url;
52
+	}
53 53
 
54
-    /**
55
-     * @return mixed
56
-     */
57
-    public function get_target()
58
-    {
59
-        return $this->target_url;
60
-    }
54
+	/**
55
+	 * @return mixed
56
+	 */
57
+	public function get_target()
58
+	{
59
+		return $this->target_url;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @param $file
65
-     * @param int $start
66
-     * @param string $hash
67
-     *
68
-     * @return bool|int
69
-     * @throws Exception
70
-     */
71
-    public function transfer_file($file, $start = 0, $hash = "")
72
-    {
73
-        if (!$this->target_url) {
74
-            throw new Exception("Please setup a target url for upload");
75
-        }
63
+	/**
64
+	 * @param $file
65
+	 * @param int $start
66
+	 * @param string $hash
67
+	 *
68
+	 * @return bool|int
69
+	 * @throws Exception
70
+	 */
71
+	public function transfer_file($file, $start = 0, $hash = "")
72
+	{
73
+		if (!$this->target_url) {
74
+			throw new Exception("Please setup a target url for upload");
75
+		}
76 76
 
77 77
 
78
-        $fp = $this->get_storage_filesystem()->readStream($file);
78
+		$fp = $this->get_storage_filesystem()->readStream($file);
79 79
 
80
-        fseek($fp, $start, SEEK_SET);
80
+		fseek($fp, $start, SEEK_SET);
81 81
 
82
-        $binary_data = fread($fp, $this->transfer_limit);
82
+		$binary_data = fread($fp, $this->transfer_limit);
83 83
 
84
-        $tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5);
84
+		$tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5);
85 85
 
86
-        $this->get_tmp_filesystem()->write($tmp_filename, $binary_data);
86
+		$this->get_tmp_filesystem()->write($tmp_filename, $binary_data);
87 87
 
88
-        $tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename);
88
+		$tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename);
89 89
 
90
-        $send_array = array();
90
+		$send_array = array();
91 91
 
92
-        $send_array['file'] = $file;
93
-        $send_array['start'] = $start;
94
-        $send_array['xcloner_action'] = "write_file";
95
-        $send_array['hash'] = $hash;
96
-        #$send_array['blob'] 	= $binary_data;
97
-        $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename);
92
+		$send_array['file'] = $file;
93
+		$send_array['start'] = $start;
94
+		$send_array['xcloner_action'] = "write_file";
95
+		$send_array['hash'] = $hash;
96
+		#$send_array['blob'] 	= $binary_data;
97
+		$send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename);
98 98
 
99
-        //$data = http_build_query($send_array);
99
+		//$data = http_build_query($send_array);
100 100
 
101
-        $this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s",
102
-            $this->target_url, $this->transfer_limit, $file, $start, $tmp_filename));
101
+		$this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s",
102
+			$this->target_url, $this->transfer_limit, $file, $start, $tmp_filename));
103 103
 
104 104
 
105
-        $ch = curl_init();
106
-        curl_setopt($ch, CURLOPT_URL, $this->target_url);
105
+		$ch = curl_init();
106
+		curl_setopt($ch, CURLOPT_URL, $this->target_url);
107 107
 
108
-        curl_setopt($ch, CURLOPT_POST, 1);
109
-        //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
110
-        //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
111
-        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
112
-        curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
113
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
108
+		curl_setopt($ch, CURLOPT_POST, 1);
109
+		//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
110
+		//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
111
+		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
112
+		curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
113
+		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114 114
 
115
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array);
116
-        curl_setopt($ch, CURLOPT_VERBOSE, true);
115
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array);
116
+		curl_setopt($ch, CURLOPT_VERBOSE, true);
117 117
 
118
-        $original_result = curl_exec($ch);
118
+		$original_result = curl_exec($ch);
119 119
 
120 120
 
121
-        $this->get_tmp_filesystem()->delete($tmp_filename);
121
+		$this->get_tmp_filesystem()->delete($tmp_filename);
122 122
 
123
-        $result = json_decode($original_result);
123
+		$result = json_decode($original_result);
124 124
 
125
-        if (!$result) {
126
-            throw new Exception("We have received no valid response from the remote host, original message: " . $original_result);
127
-        }
125
+		if (!$result) {
126
+			throw new Exception("We have received no valid response from the remote host, original message: " . $original_result);
127
+		}
128 128
 
129
-        if ($result->status != 200) {
130
-            throw new Exception($result->response);
131
-        }
129
+		if ($result->status != 200) {
130
+			throw new Exception($result->response);
131
+		}
132 132
 
133
-        if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) {
134
-            $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes",
135
-                $file, $this->target_url, ftell($fp)));
136
-            $this->remove_tmp_filesystem();
133
+		if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) {
134
+			$this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes",
135
+				$file, $this->target_url, ftell($fp)));
136
+			$this->remove_tmp_filesystem();
137 137
 
138
-            return false;
139
-        }
138
+			return false;
139
+		}
140 140
 
141
-        return ftell($fp);
142
-    }
141
+		return ftell($fp);
142
+	}
143 143
 
144
-    /**
145
-     * @param $filename
146
-     * @param string $mimetype
147
-     * @param string $postname
148
-     *
149
-     * @return CURLFile|string
150
-     */
151
-    private function curl_file_create($filename, $mimetype = '', $postname = '')
152
-    {
153
-        if (!function_exists('curl_file_create')) {
144
+	/**
145
+	 * @param $filename
146
+	 * @param string $mimetype
147
+	 * @param string $postname
148
+	 *
149
+	 * @return CURLFile|string
150
+	 */
151
+	private function curl_file_create($filename, $mimetype = '', $postname = '')
152
+	{
153
+		if (!function_exists('curl_file_create')) {
154 154
 
155
-            return "@$filename;filename="
156
-                . ($postname ?: basename($filename))
157
-                . ($mimetype ? ";type=$mimetype" : '');
155
+			return "@$filename;filename="
156
+				. ($postname ?: basename($filename))
157
+				. ($mimetype ? ";type=$mimetype" : '');
158 158
 
159
-        } else {
159
+		} else {
160 160
 
161
-            return curl_file_create($filename, $mimetype, $postname);
161
+			return curl_file_create($filename, $mimetype, $postname);
162 162
 
163
-        }
164
-    }
163
+		}
164
+	}
165 165
 }
Please login to merge, or discard this patch.
includes/class-xcloner-encryption.php 1 patch
Indentation   +359 added lines, -359 removed lines patch added patch discarded remove patch
@@ -10,370 +10,370 @@
 block discarded – undo
10 10
 
11 11
 class Xcloner_Encryption
12 12
 {
13
-    const FILE_ENCRYPTION_BLOCKS = 1024*1024;
14
-    const FILE_ENCRYPTION_SUFFIX = ".encrypted";
15
-    const FILE_DECRYPTION_SUFFIX = ".decrypted";
16
-
17
-    private $xcloner_settings;
18
-    private $logger;
19
-    private $verification = false;
20
-
21
-    public function __construct(Xcloner $xcloner_container)
22
-    {
23
-        $this->xcloner_container = $xcloner_container;
24
-        if(method_exists($xcloner_container, 'get_xcloner_settings')) {
25
-            $this->xcloner_settings = $xcloner_container->get_xcloner_settings();
26
-        }else{
27
-            $this->xcloner_settings = "";
28
-        }
29
-
30
-        if(method_exists($xcloner_container, 'get_xcloner_logger')) {
31
-            $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption");
32
-        }else{
33
-            $this->logger = "";
34
-        }
35
-    }
36
-
37
-    /**
38
-     * Returns the backup encryption key
39
-     *
40
-     * @return SECURE_AUTH_SALT|null
41
-     */
42
-    public function get_backup_encryption_key()
43
-    {
44
-        if(is_object($this->xcloner_settings)) {
45
-            return $this->xcloner_settings->get_xcloner_encryption_key();
46
-        }
47
-
48
-        return false;
49
-
50
-    }
51
-
52
-    /**
53
-     * Check if provided filename has encrypted suffix
54
-     *
55
-     * @param $filename
56
-     * @return bool
57
-     */
58
-    public function is_encrypted_file($filename) {
59
-        $fp = fopen($this->get_xcloner_path() .$filename, 'r');
60
-        $encryption_length = fread($fp, 16);
61
-        fclose($fp);
62
-        if(is_numeric($encryption_length)) {
63
-            return true;
64
-        }
65
-
66
-        return false;
67
-
68
-    }
69
-
70
-    /**
71
-     * Returns the filename with encrypted suffix
72
-     *
73
-     * @param $filename
74
-     * @return string
75
-     */
76
-    public function get_encrypted_target_backup_file_name( $filename ) {
77
-
78
-        return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename) . self::FILE_ENCRYPTION_SUFFIX;
79
-    }
80
-
81
-    /**
82
-     * Returns the filename without encrypted suffix
83
-     *
84
-     * @param $filename
85
-     * @return string
86
-     */
87
-    public function get_decrypted_target_backup_file_name( $filename ) {
88
-
89
-        return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename) . self::FILE_DECRYPTION_SUFFIX;
90
-    }
91
-
92
-    /**
93
-     * Encrypt the passed file and saves the result in a new file with ".enc" as suffix.
94
-     *
95
-     * @param string $source Path to file that should be encrypted
96
-     * @param string $dest   File name where the encryped file should be written to.
97
-     * @param string $key    The key used for the encryption
98
-     * @param int $start   Start position for reading when doing incremental mode.
99
-     * @param string $iv   The IV key to use.
100
-     * @param bool $verfication   Weather we should we try to verify the decryption.
101
-     * @return string|false  Returns the file name that has been created or FALSE if an error occured
102
-    */
103
-    public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false)
104
-    {
105
-        if(is_object($this->logger)) {
106
-            $this->logger->info(sprintf('Encrypting file %s at position %d IV %s', $source, $start, base64_encode($iv)));
107
-        }
108
-
109
-        //$key = substr(sha1($key, true), 0, 16);
110
-        if(!$key){
111
-            $key = self::get_backup_encryption_key();
112
-        }
113
-        $key_digest = openssl_digest ($key, "md5", true);
114
-
115
-        $keep_local = 1;
116
-        if(!$dest) {
117
-            $dest = $this->get_encrypted_target_backup_file_name($source);
118
-            $keep_local = 0;
119
-        }
120
-
121
-        if(!$iv || !$start) {
122
-            //$iv = openssl_random_pseudo_bytes(16);
123
-            $iv = str_pad(self::FILE_ENCRYPTION_BLOCKS, 16, "0000000000000000", STR_PAD_LEFT);
124
-        }
125
-
126
-        if( !$start ) {
127
-            $fpOut = fopen($this->get_xcloner_path() .$dest, 'w');
128
-        }else{
129
-            $fpOut = fopen($this->get_xcloner_path() .$dest, 'a');
130
-        }
131
-
132
-        if ( $fpOut ) {
133
-
134
-            // Put the initialization vector to the beginning of the file
135
-            if(!$start) {
136
-                fwrite($fpOut, $iv);
137
-            }
138
-
139
-            if (file_exists($this->get_xcloner_path() .$source) &&
140
-                $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) {
141
-
142
-                fseek($fpIn, (int)$start);
143
-
144
-                if (!feof($fpIn)) {
145
-
146
-                    $plaintext = fread($fpIn, 16 * self::FILE_ENCRYPTION_BLOCKS);
147
-                    $ciphertext = openssl_encrypt($plaintext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv);
148
-
149
-                    // Use the first 16 bytes of the ciphertext as the next initialization vector
150
-                    $iv = substr($ciphertext, 0, 16);
151
-                    //$iv = openssl_random_pseudo_bytes(16);
152
-
153
-                    fwrite($fpOut, $ciphertext);
154
-
155
-                    $start = ftell($fpIn);
156
-
157
-                    fclose($fpOut );
158
-
159
-                    if(!feof($fpIn)) {
160
-                        fclose($fpIn);
161
-                        //echo "\n NEW:".$key.md5($iv);
162
-                        //self::encryptFile($source, $dest, $key, $start, $iv);
163
-                        if($recursive ){
164
-                            $this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive);
165
-                        }else {
166
-
167
-                            if(($iv) != base64_decode(base64_encode($iv)))
168
-                            {
169
-                                throw new \Exception('Could not encode IV for transport');
170
-                            }
171
-
172
-                            return array(
173
-                                "start" => $start,
174
-                                "iv" => base64_encode($iv),
175
-                                "target_file" => $dest,
176
-                                "finished" => 0
177
-                            );
178
-                        }
179
-                    }
180
-
181
-                }
182
-            } else {
183
-                if(is_object($this->logger)) {
184
-                    $this->logger->error('Unable to read source file for encryption.');
185
-                }
186
-                throw new \Exception("Unable to read source file for encryption.");
187
-            }
188
-        } else {
189
-            if(is_object($this->logger)) {
190
-                $this->logger->error('Unable to write destination file for encryption.');
191
-            }
192
-            throw new \Exception("Unable to write destination file for encryption.");
193
-        }
194
-
195
-        if($verification) {
196
-            $this->verify_encrypted_file($dest);
197
-        }
198
-
199
-        //we replace the original backup with the encrypted one
200
-        if( !$keep_local && copy($this->get_xcloner_path() .$dest,
201
-             $this->get_xcloner_path() .$source) ) {
202
-            unlink($this->get_xcloner_path() .$dest);
203
-        }
204
-
205
-
206
-        return array("target_file" => $dest, "finished" => 1);
207
-    }
208
-
209
-    public function verify_encrypted_file($file) {
210
-        if(is_object($this->logger)) {
211
-            $this->logger->info(sprintf('Verifying encrypted file %s', $file));
212
-        }
213
-
214
-        $this->verification = true;
215
-        $this->decrypt_file($file);
216
-        $this->verification = false;
217
-    }
218
-
219
-    /**
220
-     * Dencrypt the passed file and saves the result in a new file, removing the
221
-     * last 4 characters from file name.
222
-     *
223
-     * @param string $source Path to file that should be decrypted
224
-     * @param string $dest   File name where the decryped file should be written to.
225
-     * @param string $key    The key used for the decryption (must be the same as for encryption)
226
-     * @param int $start   Start position for reading when doing incremental mode.
227
-     * @param string $iv   The IV key to use.
228
-     * @return string|false  Returns the file name that has been created or FALSE if an error occured
229
-     */
230
-    public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false)
231
-    {
232
-        if(is_object($this->logger)) {
233
-            $this->logger->info(sprintf('Decrypting file %s at position %d with IV %s', $source, $start, base64_encode($iv)));
234
-        }
235
-
236
-        //$key = substr(sha1($key, true), 0, 16);
237
-        if(!$key){
238
-            $key = self::get_backup_encryption_key();
239
-        }
240
-
241
-        $key_digest = openssl_digest ($key, "md5", true);
242
-
243
-        $keep_local = 1;
244
-        if(!$dest) {
245
-            $dest = $this->get_decrypted_target_backup_file_name($source);
246
-            $keep_local = 0;
247
-        }
248
-
249
-        if( !$start ) {
250
-            if($this->verification){
251
-                $fpOut = fopen("php://stdout", 'w');
252
-            }else {
253
-                $fpOut = fopen($this->get_xcloner_path() . $dest, 'w');
254
-            }
255
-        }else{
256
-            if($this->verification){
257
-                $fpOut = fopen("php://stdout", 'a');
258
-            }else {
259
-                $fpOut = fopen($this->get_xcloner_path() . $dest, 'a');
260
-            }
261
-        }
262
-
263
-        if ( $fpOut ) {
264
-            if ( file_exists($this->get_xcloner_path() .$source) &&
265
-                $fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) {
266
-
267
-                $encryption_length = (int)fread($fpIn, 16);
268
-                if(!$encryption_length) {
269
-                    $encryption_length = self::FILE_ENCRYPTION_BLOCKS;
270
-                }
271
-
272
-                fseek($fpIn, (int)$start);
273
-
274
-                // Get the initialzation vector from the beginning of the file
275
-                if(!$iv) {
276
-                    $iv = fread($fpIn, 16);
277
-                }
278
-
279
-                if (!feof($fpIn)) {
280
-
281
-                    // we have to read one block more for decrypting than for encrypting
282
-                    $ciphertext = fread($fpIn, 16 * ($encryption_length + 1));
283
-                    $plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv);
284
-
285
-                    if(!$plaintext){
286
-                        unlink($this->get_xcloner_path() . $dest);
287
-                        if(is_object($this->logger)) {
288
-                            $this->logger->error('Backup decryption failed, please check your provided Encryption Key.');
289
-                        }
290
-                        throw new \Exception("Backup decryption failed, please check your provided Encryption Key.");
291
-                    }
292
-
293
-                    // Use the first 16 bytes of the ciphertext as the next initialization vector
294
-                    $iv = substr($ciphertext, 0, 16);
295
-
296
-                    if( !$this->verification) {
297
-                        fwrite($fpOut, $plaintext);
298
-                    }
299
-
300
-                    $start = ftell($fpIn);
301
-
302
-                    fclose($fpOut );
303
-
304
-                    if(!feof($fpIn)) {
305
-                        fclose($fpIn);
306
-                        if($this->verification || $recursive) {
307
-                            $ciphertext = "";
308
-                            $plaintext = "";
309
-                            $this->decrypt_file($source, $dest, $key, $start, $iv, $recursive);
310
-                        }else {
311
-                            if(($iv) != base64_decode(base64_encode($iv)))
312
-                            {
313
-                                throw new \Exception('Could not encode IV for transport');
314
-                            }
315
-
316
-                            return array(
317
-                                "start" => $start,
318
-                                "encryption_length" => $encryption_length,
319
-                                "iv" => base64_encode($iv),
320
-                                "target_file" => $dest,
321
-                                "finished" => 0
322
-                            );
323
-                    }
324
-                    }
325
-
326
-                }
327
-            } else {
328
-                if(is_object($this->logger)) {
329
-                    $this->logger->error('Unable to read source file for decryption');
330
-                }
331
-                throw new \Exception("Unable to read source file for decryption");
332
-            }
333
-        } else {
334
-            if(is_object($this->logger)) {
335
-                $this->logger->error('Unable to write destination file for decryption');
336
-            }
337
-            throw new \Exception("Unable to write destination file for decryption");
338
-        }
339
-
340
-        //we replace the original backup with the encrypted one
341
-        if( !$keep_local && !$this->verification && copy($this->get_xcloner_path()  .$dest,
342
-            $this->get_xcloner_path()  .$source) ) {
343
-            unlink($this->get_xcloner_path()  .$dest);
344
-        }
345
-
346
-        return array("target_file" => $dest, "finished" => 1);
347
-    }
348
-
349
-    public function get_xcloner_path(){
350
-        if(is_object($this->xcloner_settings)) {
351
-            return $this->xcloner_settings->get_xcloner_store_path() . DS;
352
-        }
353
-
354
-        return null;
355
-    }
13
+	const FILE_ENCRYPTION_BLOCKS = 1024*1024;
14
+	const FILE_ENCRYPTION_SUFFIX = ".encrypted";
15
+	const FILE_DECRYPTION_SUFFIX = ".decrypted";
16
+
17
+	private $xcloner_settings;
18
+	private $logger;
19
+	private $verification = false;
20
+
21
+	public function __construct(Xcloner $xcloner_container)
22
+	{
23
+		$this->xcloner_container = $xcloner_container;
24
+		if(method_exists($xcloner_container, 'get_xcloner_settings')) {
25
+			$this->xcloner_settings = $xcloner_container->get_xcloner_settings();
26
+		}else{
27
+			$this->xcloner_settings = "";
28
+		}
29
+
30
+		if(method_exists($xcloner_container, 'get_xcloner_logger')) {
31
+			$this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_encryption");
32
+		}else{
33
+			$this->logger = "";
34
+		}
35
+	}
36
+
37
+	/**
38
+	 * Returns the backup encryption key
39
+	 *
40
+	 * @return SECURE_AUTH_SALT|null
41
+	 */
42
+	public function get_backup_encryption_key()
43
+	{
44
+		if(is_object($this->xcloner_settings)) {
45
+			return $this->xcloner_settings->get_xcloner_encryption_key();
46
+		}
47
+
48
+		return false;
49
+
50
+	}
51
+
52
+	/**
53
+	 * Check if provided filename has encrypted suffix
54
+	 *
55
+	 * @param $filename
56
+	 * @return bool
57
+	 */
58
+	public function is_encrypted_file($filename) {
59
+		$fp = fopen($this->get_xcloner_path() .$filename, 'r');
60
+		$encryption_length = fread($fp, 16);
61
+		fclose($fp);
62
+		if(is_numeric($encryption_length)) {
63
+			return true;
64
+		}
65
+
66
+		return false;
67
+
68
+	}
69
+
70
+	/**
71
+	 * Returns the filename with encrypted suffix
72
+	 *
73
+	 * @param $filename
74
+	 * @return string
75
+	 */
76
+	public function get_encrypted_target_backup_file_name( $filename ) {
77
+
78
+		return str_replace(self::FILE_DECRYPTION_SUFFIX, "", $filename) . self::FILE_ENCRYPTION_SUFFIX;
79
+	}
80
+
81
+	/**
82
+	 * Returns the filename without encrypted suffix
83
+	 *
84
+	 * @param $filename
85
+	 * @return string
86
+	 */
87
+	public function get_decrypted_target_backup_file_name( $filename ) {
88
+
89
+		return str_replace(self::FILE_ENCRYPTION_SUFFIX, "", $filename) . self::FILE_DECRYPTION_SUFFIX;
90
+	}
91
+
92
+	/**
93
+	 * Encrypt the passed file and saves the result in a new file with ".enc" as suffix.
94
+	 *
95
+	 * @param string $source Path to file that should be encrypted
96
+	 * @param string $dest   File name where the encryped file should be written to.
97
+	 * @param string $key    The key used for the encryption
98
+	 * @param int $start   Start position for reading when doing incremental mode.
99
+	 * @param string $iv   The IV key to use.
100
+	 * @param bool $verfication   Weather we should we try to verify the decryption.
101
+	 * @return string|false  Returns the file name that has been created or FALSE if an error occured
102
+	 */
103
+	public function encrypt_file($source, $dest = "" , $key= "", $start = 0, $iv = 0, $verification = true, $recursive = false)
104
+	{
105
+		if(is_object($this->logger)) {
106
+			$this->logger->info(sprintf('Encrypting file %s at position %d IV %s', $source, $start, base64_encode($iv)));
107
+		}
108
+
109
+		//$key = substr(sha1($key, true), 0, 16);
110
+		if(!$key){
111
+			$key = self::get_backup_encryption_key();
112
+		}
113
+		$key_digest = openssl_digest ($key, "md5", true);
114
+
115
+		$keep_local = 1;
116
+		if(!$dest) {
117
+			$dest = $this->get_encrypted_target_backup_file_name($source);
118
+			$keep_local = 0;
119
+		}
120
+
121
+		if(!$iv || !$start) {
122
+			//$iv = openssl_random_pseudo_bytes(16);
123
+			$iv = str_pad(self::FILE_ENCRYPTION_BLOCKS, 16, "0000000000000000", STR_PAD_LEFT);
124
+		}
125
+
126
+		if( !$start ) {
127
+			$fpOut = fopen($this->get_xcloner_path() .$dest, 'w');
128
+		}else{
129
+			$fpOut = fopen($this->get_xcloner_path() .$dest, 'a');
130
+		}
131
+
132
+		if ( $fpOut ) {
133
+
134
+			// Put the initialization vector to the beginning of the file
135
+			if(!$start) {
136
+				fwrite($fpOut, $iv);
137
+			}
138
+
139
+			if (file_exists($this->get_xcloner_path() .$source) &&
140
+				$fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) {
141
+
142
+				fseek($fpIn, (int)$start);
143
+
144
+				if (!feof($fpIn)) {
145
+
146
+					$plaintext = fread($fpIn, 16 * self::FILE_ENCRYPTION_BLOCKS);
147
+					$ciphertext = openssl_encrypt($plaintext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv);
148
+
149
+					// Use the first 16 bytes of the ciphertext as the next initialization vector
150
+					$iv = substr($ciphertext, 0, 16);
151
+					//$iv = openssl_random_pseudo_bytes(16);
152
+
153
+					fwrite($fpOut, $ciphertext);
154
+
155
+					$start = ftell($fpIn);
156
+
157
+					fclose($fpOut );
158
+
159
+					if(!feof($fpIn)) {
160
+						fclose($fpIn);
161
+						//echo "\n NEW:".$key.md5($iv);
162
+						//self::encryptFile($source, $dest, $key, $start, $iv);
163
+						if($recursive ){
164
+							$this->encrypt_file($source, $dest, $key, $start, ($iv), $verification, $recursive);
165
+						}else {
166
+
167
+							if(($iv) != base64_decode(base64_encode($iv)))
168
+							{
169
+								throw new \Exception('Could not encode IV for transport');
170
+							}
171
+
172
+							return array(
173
+								"start" => $start,
174
+								"iv" => base64_encode($iv),
175
+								"target_file" => $dest,
176
+								"finished" => 0
177
+							);
178
+						}
179
+					}
180
+
181
+				}
182
+			} else {
183
+				if(is_object($this->logger)) {
184
+					$this->logger->error('Unable to read source file for encryption.');
185
+				}
186
+				throw new \Exception("Unable to read source file for encryption.");
187
+			}
188
+		} else {
189
+			if(is_object($this->logger)) {
190
+				$this->logger->error('Unable to write destination file for encryption.');
191
+			}
192
+			throw new \Exception("Unable to write destination file for encryption.");
193
+		}
194
+
195
+		if($verification) {
196
+			$this->verify_encrypted_file($dest);
197
+		}
198
+
199
+		//we replace the original backup with the encrypted one
200
+		if( !$keep_local && copy($this->get_xcloner_path() .$dest,
201
+			 $this->get_xcloner_path() .$source) ) {
202
+			unlink($this->get_xcloner_path() .$dest);
203
+		}
204
+
205
+
206
+		return array("target_file" => $dest, "finished" => 1);
207
+	}
208
+
209
+	public function verify_encrypted_file($file) {
210
+		if(is_object($this->logger)) {
211
+			$this->logger->info(sprintf('Verifying encrypted file %s', $file));
212
+		}
213
+
214
+		$this->verification = true;
215
+		$this->decrypt_file($file);
216
+		$this->verification = false;
217
+	}
218
+
219
+	/**
220
+	 * Dencrypt the passed file and saves the result in a new file, removing the
221
+	 * last 4 characters from file name.
222
+	 *
223
+	 * @param string $source Path to file that should be decrypted
224
+	 * @param string $dest   File name where the decryped file should be written to.
225
+	 * @param string $key    The key used for the decryption (must be the same as for encryption)
226
+	 * @param int $start   Start position for reading when doing incremental mode.
227
+	 * @param string $iv   The IV key to use.
228
+	 * @return string|false  Returns the file name that has been created or FALSE if an error occured
229
+	 */
230
+	public function decrypt_file($source, $dest = "", $key = "", $start = 0, $iv = 0, $recursive = false)
231
+	{
232
+		if(is_object($this->logger)) {
233
+			$this->logger->info(sprintf('Decrypting file %s at position %d with IV %s', $source, $start, base64_encode($iv)));
234
+		}
235
+
236
+		//$key = substr(sha1($key, true), 0, 16);
237
+		if(!$key){
238
+			$key = self::get_backup_encryption_key();
239
+		}
240
+
241
+		$key_digest = openssl_digest ($key, "md5", true);
242
+
243
+		$keep_local = 1;
244
+		if(!$dest) {
245
+			$dest = $this->get_decrypted_target_backup_file_name($source);
246
+			$keep_local = 0;
247
+		}
248
+
249
+		if( !$start ) {
250
+			if($this->verification){
251
+				$fpOut = fopen("php://stdout", 'w');
252
+			}else {
253
+				$fpOut = fopen($this->get_xcloner_path() . $dest, 'w');
254
+			}
255
+		}else{
256
+			if($this->verification){
257
+				$fpOut = fopen("php://stdout", 'a');
258
+			}else {
259
+				$fpOut = fopen($this->get_xcloner_path() . $dest, 'a');
260
+			}
261
+		}
262
+
263
+		if ( $fpOut ) {
264
+			if ( file_exists($this->get_xcloner_path() .$source) &&
265
+				$fpIn = fopen($this->get_xcloner_path() .$source, 'rb')) {
266
+
267
+				$encryption_length = (int)fread($fpIn, 16);
268
+				if(!$encryption_length) {
269
+					$encryption_length = self::FILE_ENCRYPTION_BLOCKS;
270
+				}
271
+
272
+				fseek($fpIn, (int)$start);
273
+
274
+				// Get the initialzation vector from the beginning of the file
275
+				if(!$iv) {
276
+					$iv = fread($fpIn, 16);
277
+				}
278
+
279
+				if (!feof($fpIn)) {
280
+
281
+					// we have to read one block more for decrypting than for encrypting
282
+					$ciphertext = fread($fpIn, 16 * ($encryption_length + 1));
283
+					$plaintext = openssl_decrypt($ciphertext, 'AES-128-CBC', $key_digest, OPENSSL_RAW_DATA, $iv);
284
+
285
+					if(!$plaintext){
286
+						unlink($this->get_xcloner_path() . $dest);
287
+						if(is_object($this->logger)) {
288
+							$this->logger->error('Backup decryption failed, please check your provided Encryption Key.');
289
+						}
290
+						throw new \Exception("Backup decryption failed, please check your provided Encryption Key.");
291
+					}
292
+
293
+					// Use the first 16 bytes of the ciphertext as the next initialization vector
294
+					$iv = substr($ciphertext, 0, 16);
295
+
296
+					if( !$this->verification) {
297
+						fwrite($fpOut, $plaintext);
298
+					}
299
+
300
+					$start = ftell($fpIn);
301
+
302
+					fclose($fpOut );
303
+
304
+					if(!feof($fpIn)) {
305
+						fclose($fpIn);
306
+						if($this->verification || $recursive) {
307
+							$ciphertext = "";
308
+							$plaintext = "";
309
+							$this->decrypt_file($source, $dest, $key, $start, $iv, $recursive);
310
+						}else {
311
+							if(($iv) != base64_decode(base64_encode($iv)))
312
+							{
313
+								throw new \Exception('Could not encode IV for transport');
314
+							}
315
+
316
+							return array(
317
+								"start" => $start,
318
+								"encryption_length" => $encryption_length,
319
+								"iv" => base64_encode($iv),
320
+								"target_file" => $dest,
321
+								"finished" => 0
322
+							);
323
+					}
324
+					}
325
+
326
+				}
327
+			} else {
328
+				if(is_object($this->logger)) {
329
+					$this->logger->error('Unable to read source file for decryption');
330
+				}
331
+				throw new \Exception("Unable to read source file for decryption");
332
+			}
333
+		} else {
334
+			if(is_object($this->logger)) {
335
+				$this->logger->error('Unable to write destination file for decryption');
336
+			}
337
+			throw new \Exception("Unable to write destination file for decryption");
338
+		}
339
+
340
+		//we replace the original backup with the encrypted one
341
+		if( !$keep_local && !$this->verification && copy($this->get_xcloner_path()  .$dest,
342
+			$this->get_xcloner_path()  .$source) ) {
343
+			unlink($this->get_xcloner_path()  .$dest);
344
+		}
345
+
346
+		return array("target_file" => $dest, "finished" => 1);
347
+	}
348
+
349
+	public function get_xcloner_path(){
350
+		if(is_object($this->xcloner_settings)) {
351
+			return $this->xcloner_settings->get_xcloner_store_path() . DS;
352
+		}
353
+
354
+		return null;
355
+	}
356 356
 
357 357
 }
358 358
 
359 359
 
360 360
 try {
361 361
 
362
-    if(isset($argv[1])) {
363
-
364
-        class Xcloner {
365
-            public function __construct()
366
-            {
367
-            }
368
-        }
369
-        $xcloner_encryption = new Xcloner_Encryption( new Xcloner() );
370
-
371
-        if ($argv[1] == "-e") {
372
-            $xcloner_encryption->encrypt_file($argv[2], $argv[2] . ".enc", $argv[4], '', '', '', true);
373
-        } elseif ($argv[1] == "-d") {
374
-            $xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true);
375
-        }
376
-    }
362
+	if(isset($argv[1])) {
363
+
364
+		class Xcloner {
365
+			public function __construct()
366
+			{
367
+			}
368
+		}
369
+		$xcloner_encryption = new Xcloner_Encryption( new Xcloner() );
370
+
371
+		if ($argv[1] == "-e") {
372
+			$xcloner_encryption->encrypt_file($argv[2], $argv[2] . ".enc", $argv[4], '', '', '', true);
373
+		} elseif ($argv[1] == "-d") {
374
+			$xcloner_encryption->decrypt_file($argv[2], $argv[2] . ".dec", $argv[4], '', '', true);
375
+		}
376
+	}
377 377
 }catch(\Exception $e) {
378
-    echo "CAUGHT: " . $e->getMessage();
378
+	echo "CAUGHT: " . $e->getMessage();
379 379
 }
Please login to merge, or discard this patch.