@@ -63,7 +63,7 @@ discard block |
||
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 |
||
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 |
@@ -61,22 +61,22 @@ discard block |
||
61 | 61 | |
62 | 62 | global $wpdb; |
63 | 63 | |
64 | - if ( version_compare( phpversion(), Xcloner_Activator::xcloner_minimum_version, '<' ) ) { |
|
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, |
|
64 | + if (version_compare(phpversion(), Xcloner_Activator::xcloner_minimum_version, '<')) { |
|
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 | 66 | 'back_link' => true |
67 | - ) ); |
|
67 | + )); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $charset_collate = $wpdb->get_charset_collate(); |
71 | 71 | |
72 | - $installed_ver = get_option( "xcloner_db_version" ); |
|
72 | + $installed_ver = get_option("xcloner_db_version"); |
|
73 | 73 | |
74 | 74 | $xcloner_db_version = Xcloner_Activator::xcloner_db_version; |
75 | 75 | |
76 | - $xcloner_scheduler_table = $wpdb->prefix . "xcloner_scheduler"; |
|
76 | + $xcloner_scheduler_table = $wpdb->prefix."xcloner_scheduler"; |
|
77 | 77 | |
78 | - if ( $installed_ver != $xcloner_db_version ) { |
|
79 | - $xcloner_schedule_sql = "CREATE TABLE `" . $xcloner_scheduler_table . "` ( |
|
78 | + if ($installed_ver != $xcloner_db_version) { |
|
79 | + $xcloner_schedule_sql = "CREATE TABLE `".$xcloner_scheduler_table."` ( |
|
80 | 80 | `id` int(11) NOT NULL AUTO_INCREMENT, |
81 | 81 | `name` varchar(255) NOT NULL, |
82 | 82 | `recurrence` varchar(25) NOT NULL, |
@@ -87,73 +87,73 @@ discard block |
||
87 | 87 | `status` int(1) NOT NULL, |
88 | 88 | `last_backup` varchar(100) DEFAULT NULL, |
89 | 89 | PRIMARY KEY (`id`) |
90 | - ) " . $charset_collate . "; |
|
90 | + ) " . $charset_collate."; |
|
91 | 91 | "; |
92 | 92 | |
93 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
94 | - dbDelta( $xcloner_schedule_sql ); |
|
93 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
94 | + dbDelta($xcloner_schedule_sql); |
|
95 | 95 | |
96 | - update_option( "xcloner_db_version", $xcloner_db_version ); |
|
96 | + update_option("xcloner_db_version", $xcloner_db_version); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( get_option( 'xcloner_backup_compression_level' ) === false ) { |
|
100 | - update_option( 'xcloner_backup_compression_level', 0 ); |
|
99 | + if (get_option('xcloner_backup_compression_level') === false) { |
|
100 | + update_option('xcloner_backup_compression_level', 0); |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( get_option( 'xcloner_enable_log' ) === false ) { |
|
104 | - update_option( 'xcloner_enable_log', 1 ); |
|
103 | + if (get_option('xcloner_enable_log') === false) { |
|
104 | + update_option('xcloner_enable_log', 1); |
|
105 | 105 | } |
106 | 106 | |
107 | - if ( get_option( 'xcloner_enable_mysql_backup' ) === false ) { |
|
108 | - update_option( 'xcloner_enable_mysql_backup', 1 ); |
|
107 | + if (get_option('xcloner_enable_mysql_backup') === false) { |
|
108 | + update_option('xcloner_enable_mysql_backup', 1); |
|
109 | 109 | } |
110 | 110 | |
111 | - if ( get_option( 'xcloner_system_settings_page' ) === false ) { |
|
112 | - update_option( 'xcloner_system_settings_page', 100 ); |
|
111 | + if (get_option('xcloner_system_settings_page') === false) { |
|
112 | + update_option('xcloner_system_settings_page', 100); |
|
113 | 113 | } |
114 | 114 | |
115 | - if ( get_option( 'xcloner_files_to_process_per_request' ) === false ) { |
|
116 | - update_option( 'xcloner_files_to_process_per_request', 250 ); |
|
115 | + if (get_option('xcloner_files_to_process_per_request') === false) { |
|
116 | + update_option('xcloner_files_to_process_per_request', 250); |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( get_option( 'xcloner_database_records_per_request' ) === false ) { |
|
120 | - update_option( 'xcloner_database_records_per_request', 10000 ); |
|
119 | + if (get_option('xcloner_database_records_per_request') === false) { |
|
120 | + update_option('xcloner_database_records_per_request', 10000); |
|
121 | 121 | } |
122 | 122 | |
123 | - if ( get_option( 'xcloner_exclude_files_larger_than_mb' ) === false ) { |
|
124 | - update_option( 'xcloner_exclude_files_larger_than_mb', 0 ); |
|
123 | + if (get_option('xcloner_exclude_files_larger_than_mb') === false) { |
|
124 | + update_option('xcloner_exclude_files_larger_than_mb', 0); |
|
125 | 125 | } |
126 | 126 | |
127 | - if ( get_option( 'xcloner_split_backup_limit' ) === false ) { |
|
128 | - update_option( 'xcloner_split_backup_limit', 2048 ); |
|
127 | + if (get_option('xcloner_split_backup_limit') === false) { |
|
128 | + update_option('xcloner_split_backup_limit', 2048); |
|
129 | 129 | } |
130 | 130 | |
131 | - if ( get_option( 'xcloner_size_limit_per_request' ) === false ) { |
|
132 | - update_option( 'xcloner_size_limit_per_request', 50 ); |
|
131 | + if (get_option('xcloner_size_limit_per_request') === false) { |
|
132 | + update_option('xcloner_size_limit_per_request', 50); |
|
133 | 133 | } |
134 | 134 | |
135 | - if ( get_option( 'xcloner_cleanup_retention_limit_days' ) === false ) { |
|
136 | - update_option( 'xcloner_cleanup_retention_limit_days', 60 ); |
|
135 | + if (get_option('xcloner_cleanup_retention_limit_days') === false) { |
|
136 | + update_option('xcloner_cleanup_retention_limit_days', 60); |
|
137 | 137 | } |
138 | 138 | |
139 | - if ( get_option( 'xcloner_cleanup_retention_limit_archives' ) === false ) { |
|
140 | - update_option( 'xcloner_cleanup_retention_limit_archives', 100 ); |
|
139 | + if (get_option('xcloner_cleanup_retention_limit_archives') === false) { |
|
140 | + update_option('xcloner_cleanup_retention_limit_archives', 100); |
|
141 | 141 | } |
142 | 142 | |
143 | - if ( get_option( 'xcloner_directories_to_scan_per_request' ) === false ) { |
|
144 | - update_option( 'xcloner_directories_to_scan_per_request', 25 ); |
|
143 | + if (get_option('xcloner_directories_to_scan_per_request') === false) { |
|
144 | + update_option('xcloner_directories_to_scan_per_request', 25); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /*if(!get_option('xcloner_diff_backup_recreate_period')) |
148 | 148 | update_option('xcloner_diff_backup_recreate_period', 10); |
149 | 149 | * */ |
150 | 150 | |
151 | - if ( ! get_option( 'xcloner_regex_exclude' ) ) { |
|
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$" ); |
|
151 | + if (!get_option('xcloner_regex_exclude')) { |
|
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$" ); |
|
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 | 157 | } |
158 | 158 | |
159 | 159 | } |
@@ -43,903 +43,903 @@ discard block |
||
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 |
||
949 | 949 | <label for="checkbox_<?php echo $i ?>"> </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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->xcloner_remote_storage = $xcloner_container->get_xcloner_remote_storage(); |
90 | 90 | |
91 | 91 | if (isset($_POST['API_ID'])) { |
92 | - $this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), |
|
92 | + $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), |
|
93 | 93 | 0, 15)); |
94 | 94 | } |
95 | 95 | |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | |
132 | 132 | |
133 | 133 | $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
134 | - $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database"; |
|
135 | - $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql"; |
|
134 | + $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
135 | + $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
136 | 136 | |
137 | 137 | try { |
138 | 138 | $this->xcloner_database->init($data); |
139 | 139 | |
140 | - } catch (Exception $e) { |
|
140 | + }catch (Exception $e) { |
|
141 | 141 | |
142 | 142 | $this->send_response($e->getMessage()); |
143 | 143 | $this->logger->error($e->getMessage()); |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | } else { |
224 | 224 | |
225 | 225 | $schedule['status'] = 1; |
226 | - $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
|
227 | - " " . $this->form_params['backup_params']['schedule_start_time']); |
|
226 | + $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date']. |
|
227 | + " ".$this->form_params['backup_params']['schedule_start_time']); |
|
228 | 228 | |
229 | 229 | if ($schedule['start_at'] <= time()) { |
230 | 230 | $schedule['start_at'] = ""; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | if (!isset($_POST['id'])) { |
251 | 251 | $wpdb->insert( |
252 | - $wpdb->prefix . 'xcloner_scheduler', |
|
252 | + $wpdb->prefix.'xcloner_scheduler', |
|
253 | 253 | $schedule, |
254 | 254 | array( |
255 | 255 | '%s', |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | ); |
259 | 259 | } else { |
260 | 260 | $wpdb->update( |
261 | - $wpdb->prefix . 'xcloner_scheduler', |
|
261 | + $wpdb->prefix.'xcloner_scheduler', |
|
262 | 262 | $schedule, |
263 | 263 | array('id' => $_POST['id']), |
264 | 264 | array( |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | try { |
310 | 310 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], |
311 | 311 | $this->form_params['extra'], $init); |
312 | - } catch (Exception $e) { |
|
312 | + }catch (Exception $e) { |
|
313 | 313 | $return = array(); |
314 | 314 | $return['error'] = true; |
315 | 315 | $return['status'] = 500; |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $additional['lines_total'] = $return['extra']['lines_total']; |
337 | 337 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], |
338 | 338 | $this->form_params, "", $additional); |
339 | - } catch (Exception $e) { |
|
339 | + }catch (Exception $e) { |
|
340 | 340 | $this->logger->error($e->getMessage()); |
341 | 341 | } |
342 | 342 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | if (isset($params->backup_params)) { |
431 | 431 | foreach ($params->backup_params as $param) { |
432 | 432 | $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value); |
433 | - $this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array( |
|
433 | + $this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array( |
|
434 | 434 | 'POST', |
435 | 435 | 'fields filter' |
436 | 436 | )); |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | if (isset($params->table_params)) { |
443 | 443 | foreach ($params->table_params as $param) { |
444 | 444 | $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id); |
445 | - $this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array( |
|
445 | + $this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array( |
|
446 | 446 | 'POST', |
447 | 447 | 'database filter' |
448 | 448 | )); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | if (!in_array($param->parent, $this->form_params['excluded_files'])) { |
462 | 462 | //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
463 | 463 | $unique_exclude_files[] = $param->id; |
464 | - $this->logger->debug("Adding file filter " . $param->id . "\n", array( |
|
464 | + $this->logger->debug("Adding file filter ".$param->id."\n", array( |
|
465 | 465 | 'POST', |
466 | 466 | 'exclude files filter' |
467 | 467 | )); |
@@ -509,13 +509,13 @@ discard block |
||
509 | 509 | 'text' => $this->xcloner_settings->get_xcloner_start_path(), |
510 | 510 | //'children' => true, |
511 | 511 | 'state' => array('selected' => false, 'opened' => true), |
512 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png" |
|
512 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-root.png" |
|
513 | 513 | ); |
514 | 514 | } |
515 | 515 | |
516 | 516 | try { |
517 | 517 | $files = $this->xcloner_file_system->list_directory($folder); |
518 | - } catch (Exception $e) { |
|
518 | + }catch (Exception $e) { |
|
519 | 519 | |
520 | 520 | print $e->getMessage(); |
521 | 521 | $this->logger->error($e->getMessage()); |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | if ($file['type'] == "dir") { |
537 | 537 | $children = true; |
538 | 538 | } else { |
539 | - $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")"; |
|
539 | + $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")"; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | if ($this->xcloner_file_system->is_excluded($file)) { |
@@ -552,8 +552,8 @@ discard block |
||
552 | 552 | //'title' => "test", |
553 | 553 | 'children' => $children, |
554 | 554 | 'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected), |
555 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'], |
|
556 | - 0, 1)) . ".png" |
|
555 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-".strtolower(substr($file['type'], |
|
556 | + 0, 1)).".png" |
|
557 | 557 | ); |
558 | 558 | } |
559 | 559 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | if ($database == "#") { |
580 | 580 | try { |
581 | 581 | $return = $this->xcloner_database->get_all_databases(); |
582 | - } catch (Exception $e) { |
|
582 | + }catch (Exception $e) { |
|
583 | 583 | $this->logger->error($e->getMessage()); |
584 | 584 | } |
585 | 585 | |
@@ -600,10 +600,10 @@ discard block |
||
600 | 600 | $data[] = array( |
601 | 601 | 'id' => $database['name'], |
602 | 602 | 'parent' => '#', |
603 | - 'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")", |
|
603 | + 'text' => $database['name']." (".(int)$database['num_tables'].")", |
|
604 | 604 | 'children' => true, |
605 | 605 | 'state' => $state, |
606 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png" |
|
606 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/database-icon.png" |
|
607 | 607 | ); |
608 | 608 | } |
609 | 609 | |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | |
612 | 612 | try { |
613 | 613 | $return = $this->xcloner_database->list_tables($database, "", 1); |
614 | - } catch (Exception $e) { |
|
614 | + }catch (Exception $e) { |
|
615 | 615 | $this->logger->error($e->getMessage()); |
616 | 616 | } |
617 | 617 | |
@@ -628,12 +628,12 @@ discard block |
||
628 | 628 | } |
629 | 629 | |
630 | 630 | $data[] = array( |
631 | - 'id' => $database . "." . $table['name'], |
|
631 | + 'id' => $database.".".$table['name'], |
|
632 | 632 | 'parent' => $database, |
633 | - 'text' => $table['name'] . " (" . (int)$table['records'] . ")", |
|
633 | + 'text' => $table['name']." (".(int)$table['records'].")", |
|
634 | 634 | 'children' => false, |
635 | 635 | 'state' => $state, |
636 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png" |
|
636 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/table-icon.png" |
|
637 | 637 | ); |
638 | 638 | } |
639 | 639 | } |
@@ -677,17 +677,17 @@ discard block |
||
677 | 677 | $return['data'] = array(); |
678 | 678 | |
679 | 679 | foreach ($data as $res) { |
680 | - $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
|
681 | - <a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
|
680 | + $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
|
681 | + <a href=\"#" . $res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
|
682 | 682 | if ($res->status) { |
683 | 683 | $status = '<i class="material-icons active status">timer</i>'; |
684 | 684 | } else { |
685 | 685 | $status = '<i class="material-icons status inactive">timer_off</i>'; |
686 | 686 | } |
687 | 687 | |
688 | - $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id)); |
|
688 | + $next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)); |
|
689 | 689 | |
690 | - $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time); |
|
690 | + $next_run = date(get_option('date_format')." ".get_option('time_format'), $next_run_time); |
|
691 | 691 | |
692 | 692 | $remote_storage = $res->remote_storage; |
693 | 693 | |
@@ -696,16 +696,16 @@ discard block |
||
696 | 696 | } |
697 | 697 | |
698 | 698 | if (trim($next_run)) { |
699 | - $date_text = date(get_option('date_format') . " " . get_option('time_format'), |
|
699 | + $date_text = date(get_option('date_format')." ".get_option('time_format'), |
|
700 | 700 | $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
701 | 701 | |
702 | 702 | if ($next_run_time >= time()) { |
703 | - $next_run = "in " . human_time_diff($next_run_time, time()); |
|
703 | + $next_run = "in ".human_time_diff($next_run_time, time()); |
|
704 | 704 | } else { |
705 | 705 | $next_run = __("executed", 'xcloner-backup-and-restore'); |
706 | 706 | } |
707 | 707 | |
708 | - $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>"; |
|
708 | + $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>"; |
|
709 | 709 | //$next_run .=" ($date_text)"; |
710 | 710 | } |
711 | 711 | |
@@ -717,11 +717,11 @@ discard block |
||
717 | 717 | if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) { |
718 | 718 | $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup); |
719 | 719 | $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup)); |
720 | - $backup_time = date(get_option('date_format') . " " . get_option('time_format'), |
|
720 | + $backup_time = date(get_option('date_format')." ".get_option('time_format'), |
|
721 | 721 | $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
722 | 722 | } |
723 | 723 | |
724 | - $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>"; |
|
724 | + $backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>"; |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | $schedules = wp_get_schedules(); |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | $return['data'][] = array( |
734 | 734 | $res->id, |
735 | 735 | $res->name, |
736 | - $res->recurrence,/*$res->start_at,*/ |
|
736 | + $res->recurrence, /*$res->start_at,*/ |
|
737 | 737 | $next_run, |
738 | 738 | $remote_storage, |
739 | 739 | $backup_text, |
@@ -795,25 +795,25 @@ discard block |
||
795 | 795 | $this->process_params($params); |
796 | 796 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($this->form_params['extra']['backup_parent']); |
797 | 797 | |
798 | - if(isset($this->form_params['extra']['start'])) { |
|
798 | + if (isset($this->form_params['extra']['start'])) { |
|
799 | 799 | $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']); |
800 | - }else{ |
|
800 | + } else { |
|
801 | 801 | $start = 0; |
802 | 802 | } |
803 | 803 | |
804 | - if(isset($this->form_params['extra']['iv'])) { |
|
804 | + if (isset($this->form_params['extra']['iv'])) { |
|
805 | 805 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']); |
806 | - }else{ |
|
806 | + } else { |
|
807 | 807 | $iv = ""; |
808 | 808 | } |
809 | 809 | |
810 | - if(isset($this->form_params['extra']['part'])) { |
|
810 | + if (isset($this->form_params['extra']['part'])) { |
|
811 | 811 | $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']); |
812 | - }else{ |
|
812 | + } else { |
|
813 | 813 | $return['part'] = 0; |
814 | 814 | } |
815 | 815 | |
816 | - }else{ |
|
816 | + } else { |
|
817 | 817 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
818 | 818 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
819 | 819 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
@@ -828,14 +828,14 @@ discard block |
||
828 | 828 | } |
829 | 829 | |
830 | 830 | $return['processing_file'] = $backup_file; |
831 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
831 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
832 | 832 | |
833 | 833 | try { |
834 | 834 | $this->logger->info(json_encode($_POST)); |
835 | 835 | $this->logger->info($iv); |
836 | 836 | $return = array_merge($return, |
837 | 837 | $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv))); |
838 | - }catch(\Exception $e){ |
|
838 | + }catch (\Exception $e) { |
|
839 | 839 | $return['error'] = true; |
840 | 840 | $return['message'] = $e->getMessage(); |
841 | 841 | $return['error_message'] = $e->getMessage(); |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | |
844 | 844 | //echo strlen($return['iv']);exit; |
845 | 845 | |
846 | - if($return['finished']) { |
|
846 | + if ($return['finished']) { |
|
847 | 847 | if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
848 | 848 | $return['start'] = 0; |
849 | 849 | |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | } |
858 | 858 | |
859 | 859 | if (isset($_POST['data'])) { |
860 | - $return['extra'] = array_merge($this->form_params['extra'], $return); |
|
860 | + $return['extra'] = array_merge($this->form_params['extra'], $return); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | $this->send_response($return, 0); |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
877 | 877 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
878 | 878 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
879 | - $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']);; |
|
879 | + $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']); ; |
|
880 | 880 | $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
881 | 881 | |
882 | 882 | $backup_file = $source_backup_file; |
@@ -887,17 +887,17 @@ discard block |
||
887 | 887 | } |
888 | 888 | |
889 | 889 | $return['processing_file'] = $backup_file; |
890 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
890 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
891 | 891 | |
892 | 892 | try { |
893 | 893 | $return = array_merge($return, |
894 | 894 | $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv))); |
895 | - }catch(\Exception $e){ |
|
895 | + }catch (\Exception $e) { |
|
896 | 896 | $return['error'] = true; |
897 | 897 | $return['message'] = $e->getMessage(); |
898 | 898 | } |
899 | 899 | |
900 | - if($return['finished']) { |
|
900 | + if ($return['finished']) { |
|
901 | 901 | if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
902 | 902 | $return['start'] = 0; |
903 | 903 | |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | foreach ($backup_list as $file_info):?> |
930 | 930 | <?php |
931 | 931 | if ($storage_selection == "gdrive") { |
932 | - $file_info['path'] = $file_info['filename'] . "." . $file_info['extension']; |
|
932 | + $file_info['path'] = $file_info['filename'].".".$file_info['extension']; |
|
933 | 933 | } |
934 | 934 | $file_exists_on_local_storage = true; |
935 | 935 | |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | <a href="#<?php echo $child[0]; ?>" class="download" |
990 | 990 | title="Download Backup"><i class="material-icons">file_download</i></a> |
991 | 991 | |
992 | - <?php if($this->xcloner_encryption->is_encrypted_file($child[0])) :?> |
|
992 | + <?php if ($this->xcloner_encryption->is_encrypted_file($child[0])) :?> |
|
993 | 993 | <a href="#<?php echo $child[0] ?>" class="backup-decryption" |
994 | 994 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
995 | 995 | <i class="material-icons">enhanced_encryption</i> |
@@ -1050,10 +1050,10 @@ discard block |
||
1050 | 1050 | <?php endif ?> |
1051 | 1051 | <?php |
1052 | 1052 | $basename = $file_info['basename']; |
1053 | - if(isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1053 | + if (isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1054 | 1054 | $basename = $file_info['childs'][0][0]; |
1055 | 1055 | ?> |
1056 | - <?php if($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
|
1056 | + <?php if ($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
|
1057 | 1057 | <a href="#<?php echo $file_info['basename'] ?>" class="backup-decryption" |
1058 | 1058 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
1059 | 1059 | <i class="material-icons">enhanced_encryption</i> |
@@ -1110,7 +1110,7 @@ discard block |
||
1110 | 1110 | $backup_file = $backup_parts[$return['part']]; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - if($this->xcloner_encryption->is_encrypted_file($backup_file)) { |
|
1113 | + if ($this->xcloner_encryption->is_encrypted_file($backup_file)) { |
|
1114 | 1114 | $return['error'] = true; |
1115 | 1115 | $return['message'] = __("Backup archive is encrypted, please decrypt it first before you can list it's content.", "xcloner-backup-and-restore"); |
1116 | 1116 | $this->send_response($return, 0); |
@@ -1118,10 +1118,10 @@ discard block |
||
1118 | 1118 | |
1119 | 1119 | try { |
1120 | 1120 | $tar = new Tar(); |
1121 | - $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start); |
|
1121 | + $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
|
1122 | 1122 | |
1123 | 1123 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
1124 | - } catch (Exception $e) { |
|
1124 | + }catch (Exception $e) { |
|
1125 | 1125 | $return['error'] = true; |
1126 | 1126 | $return['message'] = $e->getMessage(); |
1127 | 1127 | $this->send_response($return, 0); |
@@ -1129,14 +1129,14 @@ discard block |
||
1129 | 1129 | |
1130 | 1130 | $return['files'] = array(); |
1131 | 1131 | $return['finished'] = 1; |
1132 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
1132 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
1133 | 1133 | $i = 0; |
1134 | 1134 | |
1135 | 1135 | if (isset($data['extracted_files']) and is_array($data['extracted_files'])) { |
1136 | 1136 | foreach ($data['extracted_files'] as $file) { |
1137 | 1137 | $return['files'][$i]['path'] = $file->getPath(); |
1138 | 1138 | $return['files'][$i]['size'] = $file->getSize(); |
1139 | - $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'), |
|
1139 | + $return['files'][$i]['mtime'] = date(get_option('date_format')." ".get_option('time_format'), |
|
1140 | 1140 | $file->getMtime()); |
1141 | 1141 | |
1142 | 1142 | $i++; |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | "copy_backup_remote_to_local" |
1185 | 1185 | ), array($backup_file, $storage_type)); |
1186 | 1186 | } |
1187 | - } catch (Exception $e) { |
|
1187 | + }catch (Exception $e) { |
|
1188 | 1188 | |
1189 | 1189 | $return['error'] = 1; |
1190 | 1190 | $return['message'] = $e->getMessage(); |
@@ -1223,7 +1223,7 @@ discard block |
||
1223 | 1223 | "upload_backup_to_storage" |
1224 | 1224 | ), array($backup_file, $storage_type)); |
1225 | 1225 | } |
1226 | - } catch (Exception $e) { |
|
1226 | + }catch (Exception $e) { |
|
1227 | 1227 | |
1228 | 1228 | $return['error'] = 1; |
1229 | 1229 | $return['message'] = $e->getMessage(); |
@@ -1283,21 +1283,21 @@ discard block |
||
1283 | 1283 | $phar2->setStub($phar2->createDefaultStub('vendor/autoload.php', 'vendor/autoload.php')); |
1284 | 1284 | * */ |
1285 | 1285 | |
1286 | - $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz"; |
|
1286 | + $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path().DS."xcloner-restore.tgz"; |
|
1287 | 1287 | |
1288 | 1288 | $tar = new Tar(); |
1289 | 1289 | $tar->create($tmp_file); |
1290 | 1290 | |
1291 | - $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar"); |
|
1291 | + $tar->addFile(dirname(__DIR__)."/restore/vendor.build.txt", "vendor.phar"); |
|
1292 | 1292 | //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz"); |
1293 | 1293 | |
1294 | 1294 | $files = $xcloner_plugin_filesystem->listContents("vendor/", true); |
1295 | 1295 | foreach ($files as $file) { |
1296 | - $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']); |
|
1296 | + $tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | - $content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php"); |
|
1300 | - $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content); |
|
1299 | + $content = file_get_contents(dirname(__DIR__)."/restore/xcloner_restore.php"); |
|
1300 | + $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '".md5(AUTH_KEY)."');", $content); |
|
1301 | 1301 | |
1302 | 1302 | $tar->addData("xcloner_restore.php", $content); |
1303 | 1303 | |
@@ -1306,11 +1306,11 @@ discard block |
||
1306 | 1306 | if (file_exists($tmp_file)) { |
1307 | 1307 | header('Content-Description: File Transfer'); |
1308 | 1308 | header('Content-Type: application/octet-stream'); |
1309 | - header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"'); |
|
1309 | + header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"'); |
|
1310 | 1310 | header('Expires: 0'); |
1311 | 1311 | header('Cache-Control: must-revalidate'); |
1312 | 1312 | header('Pragma: public'); |
1313 | - header('Content-Length: ' . filesize($tmp_file)); |
|
1313 | + header('Content-Length: '.filesize($tmp_file)); |
|
1314 | 1314 | readfile($tmp_file); |
1315 | 1315 | |
1316 | 1316 | } |
@@ -1342,9 +1342,9 @@ discard block |
||
1342 | 1342 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
1343 | 1343 | header('Cache-Control: private', false); |
1344 | 1344 | header('Content-Transfer-Encoding: binary'); |
1345 | - header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";'); |
|
1345 | + header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
|
1346 | 1346 | header('Content-Type: application/octet-stream'); |
1347 | - header('Content-Length: ' . $metadata['size']); |
|
1347 | + header('Content-Length: '.$metadata['size']); |
|
1348 | 1348 | |
1349 | 1349 | @ob_end_clean(); |
1350 | 1350 | |
@@ -1404,12 +1404,12 @@ discard block |
||
1404 | 1404 | $xcloner_file_transfer->set_target($target_url); |
1405 | 1405 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
1406 | 1406 | |
1407 | - } catch (Exception $e) { |
|
1407 | + }catch (Exception $e) { |
|
1408 | 1408 | |
1409 | 1409 | $return = array(); |
1410 | 1410 | $return['error'] = true; |
1411 | 1411 | $return['status'] = 500; |
1412 | - $return['message'] = "CURL communication error with the restore host. " . $e->getMessage(); |
|
1412 | + $return['message'] = "CURL communication error with the restore host. ".$e->getMessage(); |
|
1413 | 1413 | $this->send_response($return, 0); |
1414 | 1414 | |
1415 | 1415 | } |
@@ -1433,7 +1433,7 @@ discard block |
||
1433 | 1433 | $this->check_access(); |
1434 | 1434 | |
1435 | 1435 | define("XCLONER_PLUGIN_ACCESS", 1); |
1436 | - include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php"); |
|
1436 | + include_once(dirname(__DIR__).DS."restore".DS."xcloner_restore.php"); |
|
1437 | 1437 | |
1438 | 1438 | return; |
1439 | 1439 | } |
@@ -797,23 +797,23 @@ discard block |
||
797 | 797 | |
798 | 798 | if(isset($this->form_params['extra']['start'])) { |
799 | 799 | $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']); |
800 | - }else{ |
|
800 | + } else{ |
|
801 | 801 | $start = 0; |
802 | 802 | } |
803 | 803 | |
804 | 804 | if(isset($this->form_params['extra']['iv'])) { |
805 | 805 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']); |
806 | - }else{ |
|
806 | + } else{ |
|
807 | 807 | $iv = ""; |
808 | 808 | } |
809 | 809 | |
810 | 810 | if(isset($this->form_params['extra']['part'])) { |
811 | 811 | $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']); |
812 | - }else{ |
|
812 | + } else{ |
|
813 | 813 | $return['part'] = 0; |
814 | 814 | } |
815 | 815 | |
816 | - }else{ |
|
816 | + } else{ |
|
817 | 817 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
818 | 818 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
819 | 819 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | $this->logger->info($iv); |
836 | 836 | $return = array_merge($return, |
837 | 837 | $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv))); |
838 | - }catch(\Exception $e){ |
|
838 | + } catch(\Exception $e){ |
|
839 | 839 | $return['error'] = true; |
840 | 840 | $return['message'] = $e->getMessage(); |
841 | 841 | $return['error_message'] = $e->getMessage(); |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | try { |
893 | 893 | $return = array_merge($return, |
894 | 894 | $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv))); |
895 | - }catch(\Exception $e){ |
|
895 | + } catch(\Exception $e){ |
|
896 | 896 | $return['error'] = true; |
897 | 897 | $return['message'] = $e->getMessage(); |
898 | 898 | } |
@@ -994,7 +994,8 @@ discard block |
||
994 | 994 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
995 | 995 | <i class="material-icons">enhanced_encryption</i> |
996 | 996 | </a> |
997 | - <?php else: ?> |
|
997 | + <?php else { |
|
998 | + : ?> |
|
998 | 999 | <a href="#<?php echo $child[0] ?>" class="list-backup-content" |
999 | 1000 | title="<?php echo __('List Backup Content', |
1000 | 1001 | 'xcloner-backup-and-restore') ?>"><i |
@@ -1013,7 +1014,9 @@ discard block |
||
1013 | 1014 | class="material-icons">file_upload</i></a> |
1014 | 1015 | <?php endif ?> |
1015 | 1016 | </li> |
1016 | - <?php endforeach; ?> |
|
1017 | + <?php endforeach; |
|
1018 | +} |
|
1019 | +?> |
|
1017 | 1020 | </ul> |
1018 | 1021 | <?php endif; ?> |
1019 | 1022 | <?php |
@@ -1021,11 +1024,12 @@ discard block |
||
1021 | 1024 | ob_end_clean(); |
1022 | 1025 | ?> |
1023 | 1026 | <?php ob_start(); ?> |
1024 | - <?php if (isset($file_info['timestamp'])) |
|
1027 | + <?php if (isset($file_info['timestamp'])) { |
|
1025 | 1028 | echo date("Y-m-d H:i", $file_info['timestamp']) |
1026 | 1029 | ?> |
1027 | 1030 | <?php |
1028 | 1031 | $return['data'][$i][] = ob_get_contents(); |
1032 | +} |
|
1029 | 1033 | ob_end_clean(); |
1030 | 1034 | ?> |
1031 | 1035 | |
@@ -1050,15 +1054,17 @@ discard block |
||
1050 | 1054 | <?php endif ?> |
1051 | 1055 | <?php |
1052 | 1056 | $basename = $file_info['basename']; |
1053 | - if(isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1054 | - $basename = $file_info['childs'][0][0]; |
|
1057 | + if(isset($file_info['childs']) and sizeof($file_info['childs'])) { |
|
1058 | + $basename = $file_info['childs'][0][0]; |
|
1059 | + } |
|
1055 | 1060 | ?> |
1056 | 1061 | <?php if($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
1057 | 1062 | <a href="#<?php echo $file_info['basename'] ?>" class="backup-decryption" |
1058 | 1063 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
1059 | 1064 | <i class="material-icons">enhanced_encryption</i> |
1060 | 1065 | </a> |
1061 | - <?php else: ?> |
|
1066 | + <?php else { |
|
1067 | + : ?> |
|
1062 | 1068 | <a href="#<?php echo $file_info['basename'] ?>" class="list-backup-content" |
1063 | 1069 | title="<?php echo __('List Backup Content', 'xcloner-backup-and-restore') ?>"><i |
1064 | 1070 | class="material-icons">folder_open</i></a> |
@@ -1068,7 +1074,9 @@ discard block |
||
1068 | 1074 | <i class="material-icons">no_encryption</i> |
1069 | 1075 | </a> |
1070 | 1076 | <?php endif?> |
1071 | - <?php endif; ?> |
|
1077 | + <?php endif; |
|
1078 | +} |
|
1079 | +?> |
|
1072 | 1080 | |
1073 | 1081 | <a href="#<?php echo $file_info['basename'] ?>" class="delete" |
1074 | 1082 | title="<?php echo __('Delete Backup', 'xcloner-backup-and-restore') ?>"> |
@@ -188,7 +188,7 @@ discard block |
||
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 |
||
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 |
||
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 ) { |
@@ -13,13 +13,13 @@ discard block |
||
13 | 13 | private $xcloner_file_system; |
14 | 14 | private $xcloner_encryption; |
15 | 15 | |
16 | - private $allowed_schedules = array( "hourly", "twicedaily", "daily", "weekly", "monthly" ); |
|
16 | + private $allowed_schedules = array("hourly", "twicedaily", "daily", "weekly", "monthly"); |
|
17 | 17 | |
18 | 18 | /*public function __call($method, $args) { |
19 | 19 | echo "$method is not defined"; |
20 | 20 | }*/ |
21 | 21 | |
22 | - public function __construct( Xcloner $xcloner_container ) { |
|
22 | + public function __construct(Xcloner $xcloner_container) { |
|
23 | 23 | global $wpdb; |
24 | 24 | |
25 | 25 | $this->db = $wpdb; |
@@ -28,26 +28,26 @@ discard block |
||
28 | 28 | $this->xcloner_container = $xcloner_container; |
29 | 29 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
30 | 30 | |
31 | - $this->scheduler_table = $this->db->prefix . $this->scheduler_table; |
|
31 | + $this->scheduler_table = $this->db->prefix.$this->scheduler_table; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | private function get_xcloner_container() { |
35 | 35 | return $this->xcloner_container; |
36 | 36 | } |
37 | 37 | |
38 | - private function set_xcloner_container( Xcloner $container ) { |
|
38 | + private function set_xcloner_container(Xcloner $container) { |
|
39 | 39 | $this->xcloner_container = $container; |
40 | 40 | } |
41 | 41 | |
42 | - public function get_scheduler_list( $return_only_enabled = 0 ) { |
|
43 | - $list = $this->db->get_results( "SELECT * FROM " . $this->scheduler_table ); |
|
42 | + public function get_scheduler_list($return_only_enabled = 0) { |
|
43 | + $list = $this->db->get_results("SELECT * FROM ".$this->scheduler_table); |
|
44 | 44 | |
45 | - if ( $return_only_enabled ) { |
|
45 | + if ($return_only_enabled) { |
|
46 | 46 | $new_list = array(); |
47 | 47 | |
48 | - foreach ( $list as $res ) { |
|
49 | - if ( $res->status ) { |
|
50 | - $res->next_run_time = wp_next_scheduled( 'xcloner_scheduler_' . $res->id, array( $res->id ) ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
48 | + foreach ($list as $res) { |
|
49 | + if ($res->status) { |
|
50 | + $res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)) + (get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
51 | 51 | $new_list[] = $res; |
52 | 52 | } |
53 | 53 | } |
@@ -57,41 +57,41 @@ discard block |
||
57 | 57 | return $list; |
58 | 58 | } |
59 | 59 | |
60 | - public function get_next_run_schedule( $xcloner_file_system = "" ) { |
|
61 | - $list = $this->get_scheduler_list( $return_only_enabled = 1 ); |
|
60 | + public function get_next_run_schedule($xcloner_file_system = "") { |
|
61 | + $list = $this->get_scheduler_list($return_only_enabled = 1); |
|
62 | 62 | |
63 | 63 | return $list; |
64 | 64 | } |
65 | 65 | |
66 | - public function get_schedule_by_id_object( $id ) { |
|
67 | - $data = $this->db->get_row( "SELECT * FROM " . $this->scheduler_table . " WHERE id=" . $id ); |
|
66 | + public function get_schedule_by_id_object($id) { |
|
67 | + $data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id); |
|
68 | 68 | |
69 | 69 | return $data; |
70 | 70 | } |
71 | 71 | |
72 | - public function get_schedule_by_id( $id ) { |
|
73 | - $data = $this->db->get_row( "SELECT * FROM " . $this->scheduler_table . " WHERE id=" . $id, ARRAY_A ); |
|
72 | + public function get_schedule_by_id($id) { |
|
73 | + $data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id, ARRAY_A); |
|
74 | 74 | |
75 | - if ( ! $data ) { |
|
75 | + if (!$data) { |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
79 | - $params = json_decode( $data['params'] ); |
|
79 | + $params = json_decode($data['params']); |
|
80 | 80 | |
81 | 81 | //print_r($params); |
82 | 82 | $data['params'] = ""; |
83 | 83 | $data['backup_params'] = $params->backup_params; |
84 | - $data['table_params'] = json_encode( $params->database ); |
|
85 | - $data['excluded_files'] = json_encode( $params->excluded_files ); |
|
84 | + $data['table_params'] = json_encode($params->database); |
|
85 | + $data['excluded_files'] = json_encode($params->excluded_files); |
|
86 | 86 | |
87 | 87 | return $data; |
88 | 88 | } |
89 | 89 | |
90 | - public function delete_schedule_by_id( $id ) { |
|
91 | - $hook = 'xcloner_scheduler_' . $id; |
|
92 | - wp_clear_scheduled_hook( $hook, array( $id ) ); |
|
90 | + public function delete_schedule_by_id($id) { |
|
91 | + $hook = 'xcloner_scheduler_'.$id; |
|
92 | + wp_clear_scheduled_hook($hook, array($id)); |
|
93 | 93 | |
94 | - $data = $this->db->delete( $this->scheduler_table, array( 'id' => $id ) ); |
|
94 | + $data = $this->db->delete($this->scheduler_table, array('id' => $id)); |
|
95 | 95 | |
96 | 96 | return $data; |
97 | 97 | } |
@@ -99,68 +99,68 @@ discard block |
||
99 | 99 | public function deactivate_wp_cron_hooks() { |
100 | 100 | $list = $this->get_scheduler_list(); |
101 | 101 | |
102 | - foreach ( $list as $schedule ) { |
|
103 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
102 | + foreach ($list as $schedule) { |
|
103 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
104 | 104 | |
105 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
106 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
105 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
106 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | 110 | public function update_wp_cron_hooks() { |
111 | 111 | $list = $this->get_scheduler_list(); |
112 | 112 | |
113 | - foreach ( $list as $schedule ) { |
|
114 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
113 | + foreach ($list as $schedule) { |
|
114 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
115 | 115 | |
116 | 116 | //adding the xcloner_scheduler hook with xcloner_scheduler_callback callback |
117 | - add_action( $hook, array( $this, 'xcloner_scheduler_callback' ), 10, 1 ); |
|
117 | + add_action($hook, array($this, 'xcloner_scheduler_callback'), 10, 1); |
|
118 | 118 | |
119 | - if ( ! wp_next_scheduled( $hook, array( $schedule->id ) ) and $schedule->status ) { |
|
119 | + if (!wp_next_scheduled($hook, array($schedule->id)) and $schedule->status) { |
|
120 | 120 | |
121 | - if ( $schedule->recurrence == "single" ) { |
|
122 | - wp_schedule_single_event( strtotime( $schedule->start_at ), $hook, array( $schedule->id ) ); |
|
121 | + if ($schedule->recurrence == "single") { |
|
122 | + wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
123 | 123 | } else { |
124 | - wp_schedule_event( strtotime( $schedule->start_at ), $schedule->recurrence, $hook, array( $schedule->id ) ); |
|
124 | + wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id)); |
|
125 | 125 | } |
126 | 126 | |
127 | - } elseif ( ! $schedule->status ) { |
|
128 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
129 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
127 | + } elseif (!$schedule->status) { |
|
128 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
129 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | - public function update_cron_hook( $id ) { |
|
136 | - $schedule = $this->get_schedule_by_id_object( $id ); |
|
137 | - $hook = 'xcloner_scheduler_' . $schedule->id; |
|
135 | + public function update_cron_hook($id) { |
|
136 | + $schedule = $this->get_schedule_by_id_object($id); |
|
137 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
138 | 138 | |
139 | - $timestamp = wp_next_scheduled( $hook, array( $schedule->id ) ); |
|
140 | - wp_unschedule_event( $timestamp, $hook, array( $schedule->id ) ); |
|
139 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
140 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
141 | 141 | |
142 | - if ( $schedule->status ) { |
|
142 | + if ($schedule->status) { |
|
143 | 143 | |
144 | - if ( $schedule->recurrence == "single" ) { |
|
145 | - wp_schedule_single_event( strtotime( $schedule->start_at ), $hook, array( $schedule->id ) ); |
|
144 | + if ($schedule->recurrence == "single") { |
|
145 | + wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
146 | 146 | } else { |
147 | - wp_schedule_event( strtotime( $schedule->start_at ), $schedule->recurrence, $hook, array( $schedule->id ) ); |
|
147 | + wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id)); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
151 | 151 | } |
152 | 152 | |
153 | - public function disable_single_cron( $schedule_id ) { |
|
154 | - $hook = 'xcloner_scheduler_' . $schedule_id; |
|
155 | - $timestamp = wp_next_scheduled( $hook, array( $schedule_id ) ); |
|
156 | - wp_unschedule_event( $timestamp, $hook, array( $schedule_id ) ); |
|
153 | + public function disable_single_cron($schedule_id) { |
|
154 | + $hook = 'xcloner_scheduler_'.$schedule_id; |
|
155 | + $timestamp = wp_next_scheduled($hook, array($schedule_id)); |
|
156 | + wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
|
157 | 157 | |
158 | 158 | $schedule['status'] = 0; |
159 | 159 | |
160 | 160 | $update = $this->db->update( |
161 | 161 | $this->scheduler_table, |
162 | 162 | $schedule, |
163 | - array( 'id' => $schedule_id ), |
|
163 | + array('id' => $schedule_id), |
|
164 | 164 | array( |
165 | 165 | '%s', |
166 | 166 | '%s' |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | return $update; |
171 | 171 | } |
172 | 172 | |
173 | - public function update_hash( $schedule_id, $hash ) { |
|
173 | + public function update_hash($schedule_id, $hash) { |
|
174 | 174 | $schedule['hash'] = $hash; |
175 | 175 | |
176 | 176 | $update = $this->db->update( |
177 | 177 | $this->scheduler_table, |
178 | 178 | $schedule, |
179 | - array( 'id' => $schedule_id ), |
|
179 | + array('id' => $schedule_id), |
|
180 | 180 | array( |
181 | 181 | '%s', |
182 | 182 | '%s' |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | return $update; |
187 | 187 | } |
188 | 188 | |
189 | - public function update_last_backup( $schedule_id, $last_backup ) { |
|
189 | + public function update_last_backup($schedule_id, $last_backup) { |
|
190 | 190 | |
191 | 191 | $this->logger->info(sprintf('Updating last backup %s for schedule id #%s', $last_backup, $schedule_id)); |
192 | 192 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $update = $this->db->update( |
196 | 196 | $this->scheduler_table, |
197 | 197 | $schedule, |
198 | - array( 'id' => $schedule_id ), |
|
198 | + array('id' => $schedule_id), |
|
199 | 199 | array( |
200 | 200 | '%s', |
201 | 201 | '%s' |
@@ -205,91 +205,91 @@ discard block |
||
205 | 205 | return $update; |
206 | 206 | } |
207 | 207 | |
208 | - private function _xcloner_scheduler_callback( $id, $schedule ) { |
|
209 | - set_time_limit( 0 ); |
|
208 | + private function _xcloner_scheduler_callback($id, $schedule) { |
|
209 | + set_time_limit(0); |
|
210 | 210 | |
211 | 211 | $xcloner = new XCloner(); |
212 | 212 | $xcloner->init(); |
213 | - $this->set_xcloner_container( $xcloner ); |
|
213 | + $this->set_xcloner_container($xcloner); |
|
214 | 214 | |
215 | 215 | #$hash = $this->xcloner_settings->get_hash(); |
216 | 216 | #$this->get_xcloner_container()->get_xcloner_settings()->set_hash($hash); |
217 | 217 | |
218 | 218 | //$this->xcloner_settings = $this->get_xcloner_container()->get_xcloner_settings(); |
219 | 219 | $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
220 | - $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
220 | + $this->xcloner_encryption = $this->get_xcloner_container()->get_xcloner_encryption(); |
|
221 | 221 | $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
222 | 222 | $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
223 | - $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName( "xcloner_scheduler" ); |
|
223 | + $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
|
224 | 224 | $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
225 | 225 | |
226 | - $this->logger->info( sprintf( "New schedule hash is %s", $this->xcloner_settings->get_hash() ) ); |
|
226 | + $this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash())); |
|
227 | 227 | |
228 | - if ( isset( $schedule['backup_params']->diff_start_date ) && $schedule['backup_params']->diff_start_date ) { |
|
229 | - $this->xcloner_file_system->set_diff_timestamp_start( $schedule['backup_params']->diff_start_date ); |
|
228 | + if (isset($schedule['backup_params']->diff_start_date) && $schedule['backup_params']->diff_start_date) { |
|
229 | + $this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( $schedule['recurrence'] == "single" ) { |
|
233 | - $this->disable_single_cron( $schedule['id'] ); |
|
232 | + if ($schedule['recurrence'] == "single") { |
|
233 | + $this->disable_single_cron($schedule['id']); |
|
234 | 234 | } |
235 | 235 | |
236 | - if ( ! $schedule ) { |
|
237 | - $this->logger->info( sprintf( "Could not load schedule with id'%s'", $id ), array( "CRON" ) ); |
|
236 | + if (!$schedule) { |
|
237 | + $this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON")); |
|
238 | 238 | |
239 | 239 | return; |
240 | 240 | } |
241 | 241 | |
242 | 242 | //echo $this->get_xcloner_container()->get_xcloner_settings()->get_hash(); exit; |
243 | 243 | |
244 | - $this->update_hash( $schedule['id'], $this->xcloner_settings->get_hash() ); |
|
244 | + $this->update_hash($schedule['id'], $this->xcloner_settings->get_hash()); |
|
245 | 245 | |
246 | - $this->logger->info( sprintf( "Starting cron schedule '%s'", $schedule['name'] ), array( "CRON" ) ); |
|
246 | + $this->logger->info(sprintf("Starting cron schedule '%s'", $schedule['name']), array("CRON")); |
|
247 | 247 | |
248 | - $this->xcloner_file_system->set_excluded_files( json_decode( $schedule['excluded_files'] ) ); |
|
248 | + $this->xcloner_file_system->set_excluded_files(json_decode($schedule['excluded_files'])); |
|
249 | 249 | |
250 | 250 | $init = 1; |
251 | 251 | $continue = 1; |
252 | 252 | |
253 | - while ( $continue ) { |
|
254 | - $continue = $this->xcloner_file_system->start_file_recursion( $init ); |
|
253 | + while ($continue) { |
|
254 | + $continue = $this->xcloner_file_system->start_file_recursion($init); |
|
255 | 255 | |
256 | 256 | $init = 0; |
257 | 257 | } |
258 | 258 | |
259 | - $this->logger->info( sprintf( "File scan finished" ), array( "CRON" ) ); |
|
259 | + $this->logger->info(sprintf("File scan finished"), array("CRON")); |
|
260 | 260 | |
261 | - $this->logger->info( sprintf( "Starting the database backup" ), array( "CRON" ) ); |
|
261 | + $this->logger->info(sprintf("Starting the database backup"), array("CRON")); |
|
262 | 262 | |
263 | 263 | $init = 1; |
264 | 264 | $return['finished'] = 0; |
265 | 265 | |
266 | - while ( ! $return['finished'] ) { |
|
267 | - $return = $this->xcloner_database->start_database_recursion( (array) json_decode( $schedule['table_params'] ), $return, $init ); |
|
266 | + while (!$return['finished']) { |
|
267 | + $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
|
268 | 268 | $init = 0; |
269 | 269 | } |
270 | 270 | |
271 | - $this->logger->info( sprintf( "Database backup done" ), array( "CRON" ) ); |
|
271 | + $this->logger->info(sprintf("Database backup done"), array("CRON")); |
|
272 | 272 | |
273 | - $this->logger->info( sprintf( "Starting file archive process" ), array( "CRON" ) ); |
|
273 | + $this->logger->info(sprintf("Starting file archive process"), array("CRON")); |
|
274 | 274 | |
275 | 275 | $init = 0; |
276 | 276 | $return['finished'] = 0; |
277 | 277 | $return['extra'] = array(); |
278 | 278 | |
279 | - while ( ! $return['finished'] ) { |
|
280 | - $return = $this->archive_system->start_incremental_backup( (array) $schedule['backup_params'], $return['extra'], $init ); |
|
279 | + while (!$return['finished']) { |
|
280 | + $return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init); |
|
281 | 281 | $init = 0; |
282 | 282 | } |
283 | - $this->logger->info( sprintf( "File archive process FINISHED." ), array( "CRON" ) ); |
|
283 | + $this->logger->info(sprintf("File archive process FINISHED."), array("CRON")); |
|
284 | 284 | |
285 | 285 | //getting the last backup archive file |
286 | 286 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
287 | - if ( $this->xcloner_file_system->is_part( $this->archive_system->get_archive_name_with_extension() ) ) { |
|
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 | 295 | $return_encrypted['finished'] = 0; |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | $part = 0; |
300 | 300 | $backup_parts = array(); |
301 | 301 | |
302 | - if( $schedule['backup_params']->backup_encrypt){ |
|
303 | - $this->logger->info( sprintf( "Encrypting backup archive %s.", $return['extra']['backup_parent'] ), array( "CRON" ) ); |
|
302 | + if ($schedule['backup_params']->backup_encrypt) { |
|
303 | + $this->logger->info(sprintf("Encrypting backup archive %s.", $return['extra']['backup_parent']), array("CRON")); |
|
304 | 304 | |
305 | 305 | $backup_file = $return['extra']['backup_parent']; |
306 | 306 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | $backup_file = $backup_parts[$part]; |
310 | 310 | } |
311 | 311 | |
312 | - while ( ! $return_encrypted['finished'] ) { |
|
312 | + while (!$return_encrypted['finished']) { |
|
313 | 313 | $return_encrypted = $this->xcloner_encryption->encrypt_file( |
314 | 314 | $backup_file, |
315 | 315 | "", |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | true |
321 | 321 | ); |
322 | 322 | |
323 | - if($return_encrypted['finished']) { |
|
323 | + if ($return_encrypted['finished']) { |
|
324 | 324 | ++$part; |
325 | 325 | |
326 | 326 | if ($part < sizeof($backup_parts)) { |
@@ -332,37 +332,37 @@ discard block |
||
332 | 332 | } |
333 | 333 | |
334 | 334 | //Sending backup to remote storage |
335 | - if ( isset( $schedule['remote_storage'] ) && $schedule['remote_storage'] && array_key_exists( $schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages() ) ) { |
|
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 | |
338 | - $this->logger->info( sprintf( "Transferring backup to remote storage %s", strtoupper( $schedule['remote_storage'] ) ), array( "CRON" ) ); |
|
338 | + $this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); |
|
339 | 339 | |
340 | - if ( method_exists( $this->xcloner_remote_storage, "upload_backup_to_storage" ) ) { |
|
341 | - call_user_func_array( array( |
|
340 | + if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) { |
|
341 | + call_user_func_array(array( |
|
342 | 342 | $this->xcloner_remote_storage, |
343 | 343 | "upload_backup_to_storage" |
344 | - ), array( $backup_file, $schedule['remote_storage'] ) ); |
|
344 | + ), array($backup_file, $schedule['remote_storage'])); |
|
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
348 | 348 | //Sending email notification |
349 | - if ( isset( $schedule['backup_params']->email_notification ) and $to = $schedule['backup_params']->email_notification ) { |
|
349 | + if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) { |
|
350 | 350 | try { |
351 | 351 | $from = ""; |
352 | 352 | $additional['lines_total'] = $return['extra']['lines_total']; |
353 | - $subject = sprintf( __( "%s - new backup generated %s" ), $schedule['name'], $return['extra']['backup_parent'] ); |
|
353 | + $subject = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']); |
|
354 | 354 | |
355 | - $this->archive_system->send_notification( $to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional ); |
|
355 | + $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional); |
|
356 | 356 | |
357 | - } catch ( Exception $e ) { |
|
358 | - $this->logger->error( $e->getMessage() ); |
|
357 | + }catch (Exception $e) { |
|
358 | + $this->logger->error($e->getMessage()); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
362 | 362 | //CHECK IF WE SHOULD DELETE BACKUP AFTER REMOTE TRANSFER IS DONE |
363 | - if ( $schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option( 'xcloner_cleanup_delete_after_remote_transfer' ) ) { |
|
364 | - $this->logger->info( sprintf( "Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'] ) ); |
|
365 | - $this->xcloner_file_system->delete_backup_by_name( $return['extra']['backup_parent'] ); |
|
363 | + if ($schedule['remote_storage'] && $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_delete_after_remote_transfer')) { |
|
364 | + $this->logger->info(sprintf("Deleting %s from local storage matching rule xcloner_cleanup_delete_after_remote_transfer", $return['extra']['backup_parent'])); |
|
365 | + $this->xcloner_file_system->delete_backup_by_name($return['extra']['backup_parent']); |
|
366 | 366 | |
367 | 367 | } |
368 | 368 | |
@@ -376,28 +376,28 @@ discard block |
||
376 | 376 | $this->xcloner_file_system->cleanup_tmp_directories(); |
377 | 377 | } |
378 | 378 | |
379 | - public function xcloner_scheduler_callback( $id, $schedule = "" ) { |
|
380 | - if ( $id ) { |
|
381 | - $schedule = $this->get_schedule_by_id( $id ); |
|
379 | + public function xcloner_scheduler_callback($id, $schedule = "") { |
|
380 | + if ($id) { |
|
381 | + $schedule = $this->get_schedule_by_id($id); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | try { |
385 | - if( get_option('xcloner_disable_email_notification') ) { |
|
385 | + if (get_option('xcloner_disable_email_notification')) { |
|
386 | 386 | //we disable email notifications |
387 | 387 | $schedule['backup_params']->email_notification = ""; |
388 | 388 | } |
389 | - $this->_xcloner_scheduler_callback( $id, $schedule ); |
|
389 | + $this->_xcloner_scheduler_callback($id, $schedule); |
|
390 | 390 | |
391 | - } catch ( Exception $e ) { |
|
391 | + }catch (Exception $e) { |
|
392 | 392 | |
393 | 393 | //send email to site admin if email notification is not set in the scheduler |
394 | - if ( ! isset( $schedule['backup_params']->email_notification ) || ! $schedule['backup_params']->email_notification ) { |
|
395 | - $schedule['backup_params']->email_notification = get_option( 'admin_email' ); |
|
394 | + if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) { |
|
395 | + $schedule['backup_params']->email_notification = get_option('admin_email'); |
|
396 | 396 | } |
397 | 397 | |
398 | - if ( isset( $schedule['backup_params']->email_notification ) && $to = $schedule['backup_params']->email_notification ) { |
|
398 | + if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) { |
|
399 | 399 | $from = ""; |
400 | - $this->archive_system->send_notification( $to, $from, $schedule['name'] . " - backup error", "", "", $e->getMessage() ); |
|
400 | + $this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage()); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | } |
@@ -408,14 +408,14 @@ discard block |
||
408 | 408 | $schedules = wp_get_schedules(); |
409 | 409 | $new_schedules = array(); |
410 | 410 | |
411 | - foreach ( $schedules as $key => $row ) { |
|
412 | - if ( in_array( $key, $this->allowed_schedules ) ) { |
|
413 | - $new_schedules[ $key ] = $row; |
|
414 | - $intervals[ $key ] = $row['interval']; |
|
411 | + foreach ($schedules as $key => $row) { |
|
412 | + if (in_array($key, $this->allowed_schedules)) { |
|
413 | + $new_schedules[$key] = $row; |
|
414 | + $intervals[$key] = $row['interval']; |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | - array_multisort( $intervals, SORT_ASC, $new_schedules ); |
|
418 | + array_multisort($intervals, SORT_ASC, $new_schedules); |
|
419 | 419 | |
420 | 420 | return $new_schedules; |
421 | 421 | } |
@@ -162,26 +162,26 @@ discard block |
||
162 | 162 | private $logger; |
163 | 163 | private $xcloner; |
164 | 164 | |
165 | - public function __construct( Xcloner $xcloner_container ) { |
|
165 | + public function __construct(Xcloner $xcloner_container) { |
|
166 | 166 | $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
167 | 167 | $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
168 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName( "xcloner_remote_storage" ); |
|
168 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_remote_storage"); |
|
169 | 169 | $this->xcloner = $xcloner_container; |
170 | 170 | |
171 | - foreach($this->storage_fields as $main_key=>$array){ |
|
171 | + foreach ($this->storage_fields as $main_key=>$array) { |
|
172 | 172 | |
173 | - if(is_array($array)) { |
|
173 | + if (is_array($array)) { |
|
174 | 174 | foreach ($array as $key => $type) { |
175 | 175 | |
176 | - if( $type == "raw") { |
|
177 | - add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key, |
|
178 | - function ($value) { |
|
176 | + if ($type == "raw") { |
|
177 | + add_filter("pre_update_option_".$this->storage_fields['option_prefix'].$key, |
|
178 | + function($value) { |
|
179 | 179 | |
180 | 180 | return $this->simple_crypt($value, 'e'); |
181 | 181 | |
182 | 182 | }, 10, 1); |
183 | 183 | |
184 | - add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) { |
|
184 | + add_filter("option_".$this->storage_fields['option_prefix'].$key, function($value) { |
|
185 | 185 | |
186 | 186 | return $this->simple_crypt($value, 'd'); |
187 | 187 | |
@@ -201,22 +201,22 @@ discard block |
||
201 | 201 | * @param string $action |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - private function simple_crypt( $string, $action = 'e' ) { |
|
204 | + private function simple_crypt($string, $action = 'e') { |
|
205 | 205 | // you may change these values to your own |
206 | 206 | $secret_key = NONCE_KEY; |
207 | 207 | $secret_iv = NONCE_SALT; |
208 | 208 | |
209 | 209 | $output = $string; |
210 | 210 | $encrypt_method = "AES-256-CBC"; |
211 | - $key = hash( 'sha256', $secret_key ); |
|
212 | - $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 ); |
|
211 | + $key = hash('sha256', $secret_key); |
|
212 | + $iv = substr(hash('sha256', $secret_iv), 0, 16); |
|
213 | 213 | |
214 | - if( $action == 'e' && function_exists('openssl_encrypt')) { |
|
215 | - $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); |
|
214 | + if ($action == 'e' && function_exists('openssl_encrypt')) { |
|
215 | + $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv)); |
|
216 | 216 | } |
217 | - else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
218 | - $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); |
|
219 | - if($decrypt) { |
|
217 | + else if ($action == 'd' && function_exists('openssl_decrypt') && base64_decode($string)) { |
|
218 | + $decrypt = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); |
|
219 | + if ($decrypt) { |
|
220 | 220 | //we check if decrypt was succesful |
221 | 221 | $output = $decrypt; |
222 | 222 | } |
@@ -231,118 +231,118 @@ discard block |
||
231 | 231 | |
232 | 232 | public function get_available_storages() { |
233 | 233 | $return = array(); |
234 | - foreach ( $this->storage_fields as $storage => $data ) { |
|
235 | - $check_field = $this->storage_fields["option_prefix"] . $storage . "_enable"; |
|
236 | - if ( get_option( $check_field ) ) { |
|
237 | - $return[ $storage ] = $data['text']; |
|
234 | + foreach ($this->storage_fields as $storage => $data) { |
|
235 | + $check_field = $this->storage_fields["option_prefix"].$storage."_enable"; |
|
236 | + if (get_option($check_field)) { |
|
237 | + $return[$storage] = $data['text']; |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | 241 | return $return; |
242 | 242 | } |
243 | 243 | |
244 | - public function save( $action = "ftp" ) { |
|
245 | - if ( ! $action ) { |
|
244 | + public function save($action = "ftp") { |
|
245 | + if (!$action) { |
|
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | |
249 | - $storage = $this->xcloner_sanitization->sanitize_input_as_string( $action ); |
|
250 | - $this->logger->debug( sprintf( "Saving the remote storage %s options", strtoupper( $action ) ) ); |
|
249 | + $storage = $this->xcloner_sanitization->sanitize_input_as_string($action); |
|
250 | + $this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action))); |
|
251 | 251 | |
252 | - if ( is_array( $this->storage_fields[ $storage ] ) ) { |
|
253 | - foreach ( $this->storage_fields[ $storage ] as $field => $validation ) { |
|
254 | - $check_field = $this->storage_fields["option_prefix"] . $field; |
|
255 | - $sanitize_method = "sanitize_input_as_" . $validation; |
|
252 | + if (is_array($this->storage_fields[$storage])) { |
|
253 | + foreach ($this->storage_fields[$storage] as $field => $validation) { |
|
254 | + $check_field = $this->storage_fields["option_prefix"].$field; |
|
255 | + $sanitize_method = "sanitize_input_as_".$validation; |
|
256 | 256 | |
257 | - if ( ! isset( $_POST[ $check_field ] ) ) { |
|
258 | - $_POST[ $check_field ] = 0; |
|
257 | + if (!isset($_POST[$check_field])) { |
|
258 | + $_POST[$check_field] = 0; |
|
259 | 259 | } |
260 | 260 | |
261 | - if ( ! method_exists( $this->xcloner_sanitization, $sanitize_method ) ) { |
|
261 | + if (!method_exists($this->xcloner_sanitization, $sanitize_method)) { |
|
262 | 262 | $sanitize_method = "sanitize_input_as_string"; |
263 | 263 | } |
264 | 264 | |
265 | - $sanitized_value = $this->xcloner_sanitization->$sanitize_method( stripslashes( $_POST[ $check_field ] ) ); |
|
266 | - update_option( $check_field, $sanitized_value ); |
|
265 | + $sanitized_value = $this->xcloner_sanitization->$sanitize_method(stripslashes($_POST[$check_field])); |
|
266 | + update_option($check_field, $sanitized_value); |
|
267 | 267 | } |
268 | 268 | |
269 | - $this->xcloner->trigger_message( __( "%s storage settings saved.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] ); |
|
269 | + $this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | } |
273 | 273 | |
274 | - public function check( $action = "ftp" ) { |
|
274 | + public function check($action = "ftp") { |
|
275 | 275 | try { |
276 | - $this->verify_filesystem( $action ); |
|
277 | - $this->xcloner->trigger_message( __( "%s connection is valid.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] ); |
|
278 | - $this->logger->debug( sprintf( "Connection to remote storage %s is valid", strtoupper( $action ) ) ); |
|
279 | - } catch ( Exception $e ) { |
|
280 | - $this->xcloner->trigger_message( "%s connection error: " . $e->getMessage(), "error", $this->storage_fields[ $action ]['text'] ); |
|
276 | + $this->verify_filesystem($action); |
|
277 | + $this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']); |
|
278 | + $this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action))); |
|
279 | + }catch (Exception $e) { |
|
280 | + $this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", $this->storage_fields[$action]['text']); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | - public function verify_filesystem( $storage_type ) { |
|
285 | - $method = "get_" . $storage_type . "_filesystem"; |
|
284 | + public function verify_filesystem($storage_type) { |
|
285 | + $method = "get_".$storage_type."_filesystem"; |
|
286 | 286 | |
287 | - $this->logger->info( sprintf( "Checking validity of the remote storage %s filesystem", strtoupper( $storage_type ) ) ); |
|
287 | + $this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type))); |
|
288 | 288 | |
289 | - if ( ! method_exists( $this, $method ) ) { |
|
289 | + if (!method_exists($this, $method)) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | - list( $adapter, $filesystem ) = $this->$method(); |
|
293 | + list($adapter, $filesystem) = $this->$method(); |
|
294 | 294 | |
295 | - $test_file = substr( ".xcloner_" . md5( time() ), 0, 15 ); |
|
295 | + $test_file = substr(".xcloner_".md5(time()), 0, 15); |
|
296 | 296 | |
297 | - if ( $storage_type == "gdrive" ) { |
|
298 | - if ( ! is_array( $filesystem->listContents() ) ) { |
|
299 | - throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) ); |
|
297 | + if ($storage_type == "gdrive") { |
|
298 | + if (!is_array($filesystem->listContents())) { |
|
299 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
300 | 300 | } |
301 | - $this->logger->debug( sprintf( "I can list data from remote storage %s", strtoupper( $storage_type ) ) ); |
|
301 | + $this->logger->debug(sprintf("I can list data from remote storage %s", strtoupper($storage_type))); |
|
302 | 302 | |
303 | 303 | return true; |
304 | 304 | } |
305 | 305 | |
306 | 306 | //testing write access |
307 | - if ( ! $filesystem->write( $test_file, "data" ) ) { |
|
308 | - throw new Exception( __( "Could not write data", 'xcloner-backup-and-restore' ) ); |
|
307 | + if (!$filesystem->write($test_file, "data")) { |
|
308 | + throw new Exception(__("Could not write data", 'xcloner-backup-and-restore')); |
|
309 | 309 | } |
310 | - $this->logger->debug( sprintf( "I can write data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
310 | + $this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type))); |
|
311 | 311 | |
312 | 312 | //testing read access |
313 | - if ( ! $filesystem->has( $test_file ) ) { |
|
314 | - throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) ); |
|
313 | + if (!$filesystem->has($test_file)) { |
|
314 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
315 | 315 | } |
316 | - $this->logger->debug( sprintf( "I can read data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
316 | + $this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type))); |
|
317 | 317 | |
318 | 318 | //delete test file |
319 | - if ( ! $filesystem->delete( $test_file ) ) { |
|
320 | - throw new Exception( __( "Could not delete data", 'xcloner-backup-and-restore' ) ); |
|
319 | + if (!$filesystem->delete($test_file)) { |
|
320 | + throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore')); |
|
321 | 321 | } |
322 | - $this->logger->debug( sprintf( "I can delete data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
322 | + $this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type))); |
|
323 | 323 | |
324 | 324 | return true; |
325 | 325 | } |
326 | 326 | |
327 | - public function upload_backup_to_storage( $file, $storage ) { |
|
328 | - if ( ! $this->xcloner_file_system->get_storage_filesystem()->has( $file ) ) { |
|
329 | - $this->logger->info( sprintf( "File not found %s in local storage", $file ) ); |
|
327 | + public function upload_backup_to_storage($file, $storage) { |
|
328 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) { |
|
329 | + $this->logger->info(sprintf("File not found %s in local storage", $file)); |
|
330 | 330 | |
331 | 331 | return false; |
332 | 332 | } |
333 | 333 | |
334 | - $method = "get_" . $storage . "_filesystem"; |
|
334 | + $method = "get_".$storage."_filesystem"; |
|
335 | 335 | |
336 | - if ( ! method_exists( $this, $method ) ) { |
|
336 | + if (!method_exists($this, $method)) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | - list( $remote_storage_adapter, $remote_storage_filesystem ) = $this->$method(); |
|
340 | + list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
|
341 | 341 | |
342 | 342 | //doing remote storage cleaning here |
343 | - $this->clean_remote_storage( $storage, $remote_storage_filesystem ); |
|
343 | + $this->clean_remote_storage($storage, $remote_storage_filesystem); |
|
344 | 344 | |
345 | - $this->logger->info( sprintf( "Transferring backup %s to remote storage %s", $file, strtoupper( $storage ) ), array( "" ) ); |
|
345 | + $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)), array("")); |
|
346 | 346 | |
347 | 347 | /*if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
348 | 348 | { |
@@ -350,104 +350,104 @@ discard block |
||
350 | 350 | return false; |
351 | 351 | }*/ |
352 | 352 | |
353 | - $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream( $file ); |
|
353 | + $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($file); |
|
354 | 354 | |
355 | - if ( ! $remote_storage_filesystem->writeStream( $file, $backup_file_stream ) ) { |
|
356 | - $this->logger->info( sprintf( "Could not transfer file %s", $file ) ); |
|
355 | + if (!$remote_storage_filesystem->writeStream($file, $backup_file_stream)) { |
|
356 | + $this->logger->info(sprintf("Could not transfer file %s", $file)); |
|
357 | 357 | |
358 | 358 | return false; |
359 | 359 | } |
360 | 360 | |
361 | - if ( $this->xcloner_file_system->is_multipart( $file ) ) { |
|
362 | - $parts = $this->xcloner_file_system->get_multipart_files( $file ); |
|
363 | - if ( is_array( $parts ) ) { |
|
364 | - foreach ( $parts as $part_file ) { |
|
365 | - $this->logger->info( sprintf( "Transferring backup %s to remote storage %s", $part_file, strtoupper( $storage ) ), array( "" ) ); |
|
361 | + if ($this->xcloner_file_system->is_multipart($file)) { |
|
362 | + $parts = $this->xcloner_file_system->get_multipart_files($file); |
|
363 | + if (is_array($parts)) { |
|
364 | + foreach ($parts as $part_file) { |
|
365 | + $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file, strtoupper($storage)), array("")); |
|
366 | 366 | |
367 | - $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream( $part_file ); |
|
368 | - if ( ! $remote_storage_filesystem->writeStream( $part_file, $backup_file_stream ) ) { |
|
367 | + $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file); |
|
368 | + if (!$remote_storage_filesystem->writeStream($part_file, $backup_file_stream)) { |
|
369 | 369 | return false; |
370 | 370 | } |
371 | 371 | } |
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | - $this->logger->info( sprintf( "Upload done, disconnecting from remote storage %s", strtoupper( $storage ) ) ); |
|
375 | + $this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage))); |
|
376 | 376 | |
377 | 377 | return true; |
378 | 378 | |
379 | 379 | } |
380 | 380 | |
381 | - public function copy_backup_remote_to_local( $file, $storage ) { |
|
382 | - $method = "get_" . $storage . "_filesystem"; |
|
381 | + public function copy_backup_remote_to_local($file, $storage) { |
|
382 | + $method = "get_".$storage."_filesystem"; |
|
383 | 383 | |
384 | 384 | $target_filename = $file; |
385 | 385 | |
386 | - if ( ! method_exists( $this, $method ) ) { |
|
386 | + if (!method_exists($this, $method)) { |
|
387 | 387 | return false; |
388 | 388 | } |
389 | 389 | |
390 | - list( $remote_storage_adapter, $remote_storage_filesystem ) = $this->$method(); |
|
390 | + list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
|
391 | 391 | |
392 | - if ( ! $remote_storage_filesystem->has( $file ) ) { |
|
393 | - $this->logger->info( sprintf( "File not found %s in remote storage %s", $file, strtoupper( $storage ) ) ); |
|
392 | + if (!$remote_storage_filesystem->has($file)) { |
|
393 | + $this->logger->info(sprintf("File not found %s in remote storage %s", $file, strtoupper($storage))); |
|
394 | 394 | |
395 | 395 | return false; |
396 | 396 | } |
397 | 397 | |
398 | - if ( $storage == "gdrive" ) { |
|
399 | - $metadata = $remote_storage_filesystem->getMetadata( $file ); |
|
400 | - $target_filename = $metadata['filename'] . "." . $metadata['extension']; |
|
398 | + if ($storage == "gdrive") { |
|
399 | + $metadata = $remote_storage_filesystem->getMetadata($file); |
|
400 | + $target_filename = $metadata['filename'].".".$metadata['extension']; |
|
401 | 401 | } |
402 | 402 | |
403 | - $this->logger->info( sprintf( "Transferring backup %s to local storage from %s storage", $file, strtoupper( $storage ) ), array( "" ) ); |
|
403 | + $this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $file, strtoupper($storage)), array("")); |
|
404 | 404 | |
405 | - $backup_file_stream = $remote_storage_filesystem->readStream( $file ); |
|
405 | + $backup_file_stream = $remote_storage_filesystem->readStream($file); |
|
406 | 406 | |
407 | - if ( ! $this->xcloner_file_system->get_storage_filesystem()->writeStream( $target_filename, $backup_file_stream ) ) { |
|
408 | - $this->logger->info( sprintf( "Could not transfer file %s", $file ) ); |
|
407 | + if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($target_filename, $backup_file_stream)) { |
|
408 | + $this->logger->info(sprintf("Could not transfer file %s", $file)); |
|
409 | 409 | |
410 | 410 | return false; |
411 | 411 | } |
412 | 412 | |
413 | - if ( $this->xcloner_file_system->is_multipart( $target_filename ) ) { |
|
414 | - $parts = $this->xcloner_file_system->get_multipart_files( $file, $storage ); |
|
415 | - if ( is_array( $parts ) ) { |
|
416 | - foreach ( $parts as $part_file ) { |
|
417 | - $this->logger->info( sprintf( "Transferring backup %s to local storage from %s storage", $part_file, strtoupper( $storage ) ), array( "" ) ); |
|
413 | + if ($this->xcloner_file_system->is_multipart($target_filename)) { |
|
414 | + $parts = $this->xcloner_file_system->get_multipart_files($file, $storage); |
|
415 | + if (is_array($parts)) { |
|
416 | + foreach ($parts as $part_file) { |
|
417 | + $this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $part_file, strtoupper($storage)), array("")); |
|
418 | 418 | |
419 | - $backup_file_stream = $remote_storage_filesystem->readStream( $part_file ); |
|
420 | - if ( ! $this->xcloner_file_system->get_storage_filesystem()->writeStream( $part_file, $backup_file_stream ) ) { |
|
419 | + $backup_file_stream = $remote_storage_filesystem->readStream($part_file); |
|
420 | + if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($part_file, $backup_file_stream)) { |
|
421 | 421 | return false; |
422 | 422 | } |
423 | 423 | } |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - $this->logger->info( sprintf( "Upload done, disconnecting from remote storage %s", strtoupper( $storage ) ) ); |
|
427 | + $this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage))); |
|
428 | 428 | |
429 | 429 | return true; |
430 | 430 | |
431 | 431 | } |
432 | 432 | |
433 | - public function clean_remote_storage( $storage, $remote_storage_filesystem ) { |
|
434 | - $check_field = $this->storage_fields["option_prefix"] . $storage . "_cleanup_days"; |
|
435 | - if ( $expire_days = get_option( $check_field ) ) { |
|
436 | - $this->logger->info( sprintf( "Doing %s remote storage cleanup for %s days limit", strtoupper( $storage ), $expire_days ) ); |
|
433 | + public function clean_remote_storage($storage, $remote_storage_filesystem) { |
|
434 | + $check_field = $this->storage_fields["option_prefix"].$storage."_cleanup_days"; |
|
435 | + if ($expire_days = get_option($check_field)) { |
|
436 | + $this->logger->info(sprintf("Doing %s remote storage cleanup for %s days limit", strtoupper($storage), $expire_days)); |
|
437 | 437 | $files = $remote_storage_filesystem->listContents(); |
438 | 438 | |
439 | - $current_timestamp = strtotime( "-" . $expire_days . " days" ); |
|
439 | + $current_timestamp = strtotime("-".$expire_days." days"); |
|
440 | 440 | |
441 | - if ( is_array( $files ) ) { |
|
442 | - foreach ( $files as $file ) { |
|
443 | - $file['timestamp'] = $remote_storage_filesystem->getTimestamp( $file['path'] ); |
|
441 | + if (is_array($files)) { |
|
442 | + foreach ($files as $file) { |
|
443 | + $file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']); |
|
444 | 444 | |
445 | - if ( $current_timestamp >= $file['timestamp'] ) { |
|
446 | - $remote_storage_filesystem->delete( $file['path'] ); |
|
447 | - $this->logger->info( "Deleting remote file " . $file['path'] . " matching rule", array( |
|
445 | + if ($current_timestamp >= $file['timestamp']) { |
|
446 | + $remote_storage_filesystem->delete($file['path']); |
|
447 | + $this->logger->info("Deleting remote file ".$file['path']." matching rule", array( |
|
448 | 448 | "RETENTION LIMIT TIMESTAMP", |
449 | - $file['timestamp'] . " =< " . $expire_days |
|
450 | - ) ); |
|
449 | + $file['timestamp']." =< ".$expire_days |
|
450 | + )); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | } |
@@ -456,153 +456,153 @@ discard block |
||
456 | 456 | } |
457 | 457 | |
458 | 458 | public function get_azure_filesystem() { |
459 | - $this->logger->info( sprintf( "Creating the AZURE BLOB remote storage connection" ), array( "" ) ); |
|
459 | + $this->logger->info(sprintf("Creating the AZURE BLOB remote storage connection"), array("")); |
|
460 | 460 | |
461 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
462 | - throw new Exception( "AZURE BLOB requires PHP 5.6 to be installed!" ); |
|
461 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
462 | + throw new Exception("AZURE BLOB requires PHP 5.6 to be installed!"); |
|
463 | 463 | } |
464 | 464 | |
465 | - if ( ! class_exists( 'XmlWriter' ) ) { |
|
466 | - throw new Exception( "AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!" ); |
|
465 | + if (!class_exists('XmlWriter')) { |
|
466 | + throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!"); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | $endpoint = sprintf( |
470 | 470 | 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', |
471 | - get_option( "xcloner_azure_account_name" ), |
|
472 | - get_option( "xcloner_azure_api_key" ) |
|
471 | + get_option("xcloner_azure_account_name"), |
|
472 | + get_option("xcloner_azure_api_key") |
|
473 | 473 | ); |
474 | 474 | |
475 | - $blobRestProxy = ServicesBuilder::getInstance()->createBlobService( $endpoint ); |
|
475 | + $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint); |
|
476 | 476 | |
477 | - $adapter = new AzureAdapter( $blobRestProxy, get_option( "xcloner_azure_container" ) ); |
|
477 | + $adapter = new AzureAdapter($blobRestProxy, get_option("xcloner_azure_container")); |
|
478 | 478 | |
479 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
479 | + $filesystem = new Filesystem($adapter, new Config([ |
|
480 | 480 | 'disable_asserts' => true, |
481 | - ] ) ); |
|
481 | + ])); |
|
482 | 482 | |
483 | - return array( $adapter, $filesystem ); |
|
483 | + return array($adapter, $filesystem); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | public function get_dropbox_filesystem() { |
487 | - $this->logger->info( sprintf( "Creating the DROPBOX remote storage connection" ), array( "" ) ); |
|
487 | + $this->logger->info(sprintf("Creating the DROPBOX remote storage connection"), array("")); |
|
488 | 488 | |
489 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
490 | - throw new Exception( "DROPBOX requires PHP 5.6 to be installed!" ); |
|
489 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
490 | + throw new Exception("DROPBOX requires PHP 5.6 to be installed!"); |
|
491 | 491 | } |
492 | 492 | |
493 | - $client = new DropboxClient( get_option( "xcloner_dropbox_access_token" ) ); |
|
494 | - $adapter = new DropboxAdapter( $client, get_option( "xcloner_dropbox_prefix" ) ); |
|
493 | + $client = new DropboxClient(get_option("xcloner_dropbox_access_token")); |
|
494 | + $adapter = new DropboxAdapter($client, get_option("xcloner_dropbox_prefix")); |
|
495 | 495 | |
496 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
496 | + $filesystem = new Filesystem($adapter, new Config([ |
|
497 | 497 | 'disable_asserts' => true, |
498 | - ] ) ); |
|
498 | + ])); |
|
499 | 499 | |
500 | - return array( $adapter, $filesystem ); |
|
500 | + return array($adapter, $filesystem); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | public function get_aws_filesystem() { |
504 | - $this->logger->info( sprintf( "Creating the S3 remote storage connection" ), array( "" ) ); |
|
504 | + $this->logger->info(sprintf("Creating the S3 remote storage connection"), array("")); |
|
505 | 505 | |
506 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
507 | - throw new Exception( "S3 class requires PHP 5.6 to be installed!" ); |
|
506 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
507 | + throw new Exception("S3 class requires PHP 5.6 to be installed!"); |
|
508 | 508 | } |
509 | 509 | |
510 | - if ( ! class_exists( 'XmlWriter' ) ) { |
|
511 | - throw new Exception( "AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!" ); |
|
510 | + if (!class_exists('XmlWriter')) { |
|
511 | + throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!"); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | |
515 | 515 | $credentials = array( |
516 | 516 | 'credentials' => array( |
517 | - 'key' => get_option( "xcloner_aws_key" ), |
|
518 | - 'secret' => get_option( "xcloner_aws_secret" ) |
|
517 | + 'key' => get_option("xcloner_aws_key"), |
|
518 | + 'secret' => get_option("xcloner_aws_secret") |
|
519 | 519 | ), |
520 | - 'region' => get_option( "xcloner_aws_region" ), |
|
520 | + 'region' => get_option("xcloner_aws_region"), |
|
521 | 521 | 'version' => 'latest', |
522 | 522 | ); |
523 | 523 | |
524 | - if ( get_option( 'xcloner_aws_endpoint' ) != "" && ! get_option( "xcloner_aws_region" ) ) { |
|
524 | + if (get_option('xcloner_aws_endpoint') != "" && !get_option("xcloner_aws_region")) { |
|
525 | 525 | |
526 | - $credentials['endpoint'] = get_option( 'xcloner_aws_endpoint' ); |
|
526 | + $credentials['endpoint'] = get_option('xcloner_aws_endpoint'); |
|
527 | 527 | #$credentials['use_path_style_endpoint'] = true; |
528 | 528 | #$credentials['bucket_endpoint'] = false; |
529 | 529 | |
530 | 530 | |
531 | 531 | } |
532 | 532 | |
533 | - $client = new S3Client( $credentials ); |
|
533 | + $client = new S3Client($credentials); |
|
534 | 534 | |
535 | - $adapter = new AwsS3Adapter( $client, get_option( "xcloner_aws_bucket_name" ), get_option( "xcloner_aws_prefix" ) ); |
|
536 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
535 | + $adapter = new AwsS3Adapter($client, get_option("xcloner_aws_bucket_name"), get_option("xcloner_aws_prefix")); |
|
536 | + $filesystem = new Filesystem($adapter, new Config([ |
|
537 | 537 | 'disable_asserts' => true, |
538 | - ] ) ); |
|
538 | + ])); |
|
539 | 539 | |
540 | - return array( $adapter, $filesystem ); |
|
540 | + return array($adapter, $filesystem); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | public function get_backblaze_filesystem() { |
544 | - $this->logger->info( sprintf( "Creating the BACKBLAZE remote storage connection" ), array( "" ) ); |
|
544 | + $this->logger->info(sprintf("Creating the BACKBLAZE remote storage connection"), array("")); |
|
545 | 545 | |
546 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
547 | - throw new Exception( "BACKBLAZE API requires PHP 5.6 to be installed!" ); |
|
546 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
547 | + throw new Exception("BACKBLAZE API requires PHP 5.6 to be installed!"); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | |
551 | - $client = new B2Client( get_option( "xcloner_backblaze_account_id" ), get_option( "xcloner_backblaze_application_key" ) ); |
|
552 | - $adapter = new BackblazeAdapter( $client, get_option( "xcloner_backblaze_bucket_name" ) ); |
|
551 | + $client = new B2Client(get_option("xcloner_backblaze_account_id"), get_option("xcloner_backblaze_application_key")); |
|
552 | + $adapter = new BackblazeAdapter($client, get_option("xcloner_backblaze_bucket_name")); |
|
553 | 553 | |
554 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
554 | + $filesystem = new Filesystem($adapter, new Config([ |
|
555 | 555 | 'disable_asserts' => true, |
556 | - ] ) ); |
|
556 | + ])); |
|
557 | 557 | |
558 | - return array( $adapter, $filesystem ); |
|
558 | + return array($adapter, $filesystem); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | public function get_webdav_filesystem() { |
562 | - $this->logger->info( sprintf( "Creating the WEBDAV remote storage connection" ), array( "" ) ); |
|
562 | + $this->logger->info(sprintf("Creating the WEBDAV remote storage connection"), array("")); |
|
563 | 563 | |
564 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
565 | - throw new Exception( "WEBDAV API requires PHP 5.6 to be installed!" ); |
|
564 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
565 | + throw new Exception("WEBDAV API requires PHP 5.6 to be installed!"); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | $settings = array( |
569 | - 'baseUri' => get_option( "xcloner_webdav_url" ), |
|
570 | - 'userName' => get_option( "xcloner_webdav_username" ), |
|
571 | - 'password' => get_option( "xcloner_webdav_password" ), |
|
569 | + 'baseUri' => get_option("xcloner_webdav_url"), |
|
570 | + 'userName' => get_option("xcloner_webdav_username"), |
|
571 | + 'password' => get_option("xcloner_webdav_password"), |
|
572 | 572 | //'proxy' => 'locahost:8888', |
573 | 573 | ); |
574 | 574 | |
575 | 575 | |
576 | - $client = new SabreClient( $settings ); |
|
577 | - $adapter = new WebDAVAdapter( $client, get_option( "xcloner_webdav_target_folder" ) ); |
|
578 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
576 | + $client = new SabreClient($settings); |
|
577 | + $adapter = new WebDAVAdapter($client, get_option("xcloner_webdav_target_folder")); |
|
578 | + $filesystem = new Filesystem($adapter, new Config([ |
|
579 | 579 | 'disable_asserts' => true, |
580 | - ] ) ); |
|
580 | + ])); |
|
581 | 581 | |
582 | - return array( $adapter, $filesystem ); |
|
582 | + return array($adapter, $filesystem); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | |
586 | 586 | public function gdrive_construct() { |
587 | 587 | |
588 | 588 | //if((function_exists("is_plugin_active") && !is_plugin_active("xcloner-google-drive/xcloner-google-drive.php")) || !file_exists(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php")) |
589 | - if ( ! class_exists( 'Google_Client' ) ) { |
|
589 | + if (!class_exists('Google_Client')) { |
|
590 | 590 | return false; |
591 | 591 | } |
592 | 592 | |
593 | 593 | //require_once(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php"); |
594 | 594 | |
595 | 595 | $client = new \Google_Client(); |
596 | - $client->setApplicationName( $this->gdrive_app_name ); |
|
597 | - $client->setClientId( get_option( "xcloner_gdrive_client_id" ) ); |
|
598 | - $client->setClientSecret( get_option( "xcloner_gdrive_client_secret" ) ); |
|
596 | + $client->setApplicationName($this->gdrive_app_name); |
|
597 | + $client->setClientId(get_option("xcloner_gdrive_client_id")); |
|
598 | + $client->setClientSecret(get_option("xcloner_gdrive_client_secret")); |
|
599 | 599 | |
600 | 600 | //$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']."?page=xcloner_remote_storage_page&action=set_gdrive_code"; |
601 | 601 | $redirect_uri = "urn:ietf:wg:oauth:2.0:oob"; |
602 | 602 | |
603 | - $client->setRedirectUri( $redirect_uri ); //urn:ietf:wg:oauth:2.0:oob |
|
604 | - $client->addScope( "https://www.googleapis.com/auth/drive" ); |
|
605 | - $client->setAccessType( 'offline' ); |
|
603 | + $client->setRedirectUri($redirect_uri); //urn:ietf:wg:oauth:2.0:oob |
|
604 | + $client->addScope("https://www.googleapis.com/auth/drive"); |
|
605 | + $client->setAccessType('offline'); |
|
606 | 606 | |
607 | 607 | return $client; |
608 | 608 | } |
@@ -610,30 +610,30 @@ discard block |
||
610 | 610 | public function get_gdrive_auth_url() { |
611 | 611 | $client = $this->gdrive_construct(); |
612 | 612 | |
613 | - if ( ! $client ) { |
|
613 | + if (!$client) { |
|
614 | 614 | return false; |
615 | 615 | } |
616 | 616 | |
617 | 617 | return $authUrl = $client->createAuthUrl(); |
618 | 618 | } |
619 | 619 | |
620 | - public function set_access_token( $code ) { |
|
620 | + public function set_access_token($code) { |
|
621 | 621 | $client = $this->gdrive_construct(); |
622 | 622 | |
623 | - if ( ! $client ) { |
|
623 | + if (!$client) { |
|
624 | 624 | $error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled..."; |
625 | - $this->logger->error( $error_msg ); |
|
625 | + $this->logger->error($error_msg); |
|
626 | 626 | |
627 | 627 | return false; |
628 | 628 | } |
629 | 629 | |
630 | - $token = $client->fetchAccessTokenWithAuthCode( $code ); |
|
631 | - $client->setAccessToken( $token ); |
|
630 | + $token = $client->fetchAccessTokenWithAuthCode($code); |
|
631 | + $client->setAccessToken($token); |
|
632 | 632 | |
633 | - update_option( "xcloner_gdrive_access_token", $token['access_token'] ); |
|
634 | - update_option( "xcloner_gdrive_refresh_token", $token['refresh_token'] ); |
|
633 | + update_option("xcloner_gdrive_access_token", $token['access_token']); |
|
634 | + update_option("xcloner_gdrive_refresh_token", $token['refresh_token']); |
|
635 | 635 | |
636 | - $redirect_url = ( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?page=xcloner_remote_storage_page#gdrive" ); |
|
636 | + $redirect_url = ('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?page=xcloner_remote_storage_page#gdrive"); |
|
637 | 637 | |
638 | 638 | ?> |
639 | 639 | <script> |
@@ -649,126 +649,126 @@ discard block |
||
649 | 649 | */ |
650 | 650 | public function get_gdrive_filesystem() { |
651 | 651 | |
652 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
653 | - throw new Exception( "Google Drive API requires PHP 5.6 to be installed!" ); |
|
652 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
653 | + throw new Exception("Google Drive API requires PHP 5.6 to be installed!"); |
|
654 | 654 | } |
655 | 655 | |
656 | - $this->logger->info( sprintf( "Creating the Google Drive remote storage connection" ), array( "" ) ); |
|
656 | + $this->logger->info(sprintf("Creating the Google Drive remote storage connection"), array("")); |
|
657 | 657 | |
658 | 658 | $client = $this->gdrive_construct(); |
659 | 659 | |
660 | - if ( ! $client ) { |
|
660 | + if (!$client) { |
|
661 | 661 | $error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled..."; |
662 | - $this->logger->error( $error_msg ); |
|
663 | - throw new Exception( $error_msg ); |
|
662 | + $this->logger->error($error_msg); |
|
663 | + throw new Exception($error_msg); |
|
664 | 664 | } |
665 | 665 | |
666 | - $client->refreshToken( get_option( "xcloner_gdrive_refresh_token" ) ); |
|
666 | + $client->refreshToken(get_option("xcloner_gdrive_refresh_token")); |
|
667 | 667 | |
668 | - $service = new \Google_Service_Drive( $client ); |
|
668 | + $service = new \Google_Service_Drive($client); |
|
669 | 669 | |
670 | - if( get_option("xcloner_gdrive_empty_trash",0) ){ |
|
670 | + if (get_option("xcloner_gdrive_empty_trash", 0)) { |
|
671 | 671 | $this->logger->info(sprintf("Doing a Google Drive emptyTrash call"), array("")); |
672 | 672 | $service->files->emptyTrash(); |
673 | 673 | } |
674 | 674 | |
675 | 675 | $parent = 'root'; |
676 | - $dir = basename( get_option( "xcloner_gdrive_target_folder" ) ); |
|
676 | + $dir = basename(get_option("xcloner_gdrive_target_folder")); |
|
677 | 677 | |
678 | - $folderID = get_option( "xcloner_gdrive_target_folder" ); |
|
678 | + $folderID = get_option("xcloner_gdrive_target_folder"); |
|
679 | 679 | |
680 | - $tmp = parse_url( $folderID ); |
|
680 | + $tmp = parse_url($folderID); |
|
681 | 681 | |
682 | - if ( isset( $tmp['query'] ) ) { |
|
683 | - $folderID = str_replace( "id=", "", $tmp['query'] ); |
|
682 | + if (isset($tmp['query'])) { |
|
683 | + $folderID = str_replace("id=", "", $tmp['query']); |
|
684 | 684 | } |
685 | 685 | |
686 | - if ( stristr( $folderID, "/" ) ) { |
|
687 | - $query = sprintf( 'mimeType = \'application/vnd.google-apps.folder\' and \'%s\' in parents and name contains \'%s\'', $parent, $dir ); |
|
688 | - $response = $service->files->listFiles( [ |
|
686 | + if (stristr($folderID, "/")) { |
|
687 | + $query = sprintf('mimeType = \'application/vnd.google-apps.folder\' and \'%s\' in parents and name contains \'%s\'', $parent, $dir); |
|
688 | + $response = $service->files->listFiles([ |
|
689 | 689 | 'pageSize' => 1, |
690 | 690 | 'q' => $query |
691 | - ] ); |
|
691 | + ]); |
|
692 | 692 | |
693 | - if ( sizeof( $response ) ) { |
|
694 | - foreach ( $response as $obj ) { |
|
693 | + if (sizeof($response)) { |
|
694 | + foreach ($response as $obj) { |
|
695 | 695 | $folderID = $obj->getId(); |
696 | 696 | } |
697 | 697 | } else { |
698 | - $this->xcloner->trigger_message( sprintf( __( "Could not find folder ID by name %s", 'xcloner-backup-and-restore' ), $folderID ), "error" ); |
|
698 | + $this->xcloner->trigger_message(sprintf(__("Could not find folder ID by name %s", 'xcloner-backup-and-restore'), $folderID), "error"); |
|
699 | 699 | } |
700 | 700 | } |
701 | 701 | |
702 | - $this->logger->info( sprintf( "Using target folder with ID %s on the remote storage", $folderID ) ); |
|
702 | + $this->logger->info(sprintf("Using target folder with ID %s on the remote storage", $folderID)); |
|
703 | 703 | |
704 | - if ( class_exists( 'XCloner_Google_Drive_Adapter' ) ) { |
|
705 | - $adapter = new XCloner_Google_Drive_Adapter( $service, $folderID ); |
|
704 | + if (class_exists('XCloner_Google_Drive_Adapter')) { |
|
705 | + $adapter = new XCloner_Google_Drive_Adapter($service, $folderID); |
|
706 | 706 | } else { |
707 | - $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter( $service, $folderID ); |
|
707 | + $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $folderID); |
|
708 | 708 | } |
709 | 709 | |
710 | - $filesystem = new \League\Flysystem\Filesystem( $adapter, new Config( [ |
|
710 | + $filesystem = new \League\Flysystem\Filesystem($adapter, new Config([ |
|
711 | 711 | 'disable_asserts' => true, |
712 | - ] ) ); |
|
712 | + ])); |
|
713 | 713 | |
714 | 714 | |
715 | - return array( $adapter, $filesystem ); |
|
715 | + return array($adapter, $filesystem); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | public function get_ftp_filesystem() { |
719 | - $this->logger->info( sprintf( "Creating the FTP remote storage connection" ), array( "" ) ); |
|
719 | + $this->logger->info(sprintf("Creating the FTP remote storage connection"), array("")); |
|
720 | 720 | |
721 | - $adapter = new Adapter( [ |
|
722 | - 'host' => get_option( "xcloner_ftp_hostname" ), |
|
723 | - 'username' => get_option( "xcloner_ftp_username" ), |
|
724 | - 'password' => get_option( "xcloner_ftp_password" ), |
|
721 | + $adapter = new Adapter([ |
|
722 | + 'host' => get_option("xcloner_ftp_hostname"), |
|
723 | + 'username' => get_option("xcloner_ftp_username"), |
|
724 | + 'password' => get_option("xcloner_ftp_password"), |
|
725 | 725 | |
726 | 726 | /** optional config settings */ |
727 | - 'port' => get_option( "xcloner_ftp_port", 21 ), |
|
728 | - 'root' => get_option( "xcloner_ftp_path" ), |
|
729 | - 'passive' => get_option( "xcloner_ftp_transfer_mode" ), |
|
730 | - 'ssl' => get_option( "xcloner_ftp_ssl_mode" ), |
|
731 | - 'timeout' => get_option( "xcloner_ftp_timeout", 30 ), |
|
732 | - ] ); |
|
727 | + 'port' => get_option("xcloner_ftp_port", 21), |
|
728 | + 'root' => get_option("xcloner_ftp_path"), |
|
729 | + 'passive' => get_option("xcloner_ftp_transfer_mode"), |
|
730 | + 'ssl' => get_option("xcloner_ftp_ssl_mode"), |
|
731 | + 'timeout' => get_option("xcloner_ftp_timeout", 30), |
|
732 | + ]); |
|
733 | 733 | |
734 | 734 | $adapter->connect(); |
735 | 735 | |
736 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
736 | + $filesystem = new Filesystem($adapter, new Config([ |
|
737 | 737 | 'disable_asserts' => true, |
738 | - ] ) ); |
|
738 | + ])); |
|
739 | 739 | |
740 | - return array( $adapter, $filesystem ); |
|
740 | + return array($adapter, $filesystem); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | public function get_sftp_filesystem() { |
744 | - $this->logger->info( sprintf( "Creating the SFTP remote storage connection" ), array( "" ) ); |
|
744 | + $this->logger->info(sprintf("Creating the SFTP remote storage connection"), array("")); |
|
745 | 745 | |
746 | - $adapter = new SftpAdapter( [ |
|
747 | - 'host' => get_option( "xcloner_sftp_hostname" ), |
|
748 | - 'username' => get_option( "xcloner_sftp_username" ), |
|
749 | - 'password' => get_option( "xcloner_sftp_password" ), |
|
746 | + $adapter = new SftpAdapter([ |
|
747 | + 'host' => get_option("xcloner_sftp_hostname"), |
|
748 | + 'username' => get_option("xcloner_sftp_username"), |
|
749 | + 'password' => get_option("xcloner_sftp_password"), |
|
750 | 750 | |
751 | 751 | /** optional config settings */ |
752 | - 'port' => get_option( "xcloner_sftp_port", 22 ), |
|
753 | - 'root' => get_option( "xcloner_sftp_path" ), |
|
754 | - 'privateKey' => get_option( "xcloner_sftp_private_key" ), |
|
755 | - 'timeout' => get_option( "xcloner_ftp_timeout", 30 ), |
|
756 | - ] ); |
|
752 | + 'port' => get_option("xcloner_sftp_port", 22), |
|
753 | + 'root' => get_option("xcloner_sftp_path"), |
|
754 | + 'privateKey' => get_option("xcloner_sftp_private_key"), |
|
755 | + 'timeout' => get_option("xcloner_ftp_timeout", 30), |
|
756 | + ]); |
|
757 | 757 | |
758 | 758 | $adapter->connect(); |
759 | 759 | |
760 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
760 | + $filesystem = new Filesystem($adapter, new Config([ |
|
761 | 761 | 'disable_asserts' => true, |
762 | - ] ) ); |
|
762 | + ])); |
|
763 | 763 | |
764 | - return array( $adapter, $filesystem ); |
|
764 | + return array($adapter, $filesystem); |
|
765 | 765 | } |
766 | 766 | |
767 | - public function change_storage_status( $field, $value ) { |
|
768 | - $field = $this->xcloner_sanitization->sanitize_input_as_string( $field ); |
|
769 | - $value = $this->xcloner_sanitization->sanitize_input_as_int( $value ); |
|
767 | + public function change_storage_status($field, $value) { |
|
768 | + $field = $this->xcloner_sanitization->sanitize_input_as_string($field); |
|
769 | + $value = $this->xcloner_sanitization->sanitize_input_as_int($value); |
|
770 | 770 | |
771 | - return update_option( $field, $value ); |
|
771 | + return update_option($field, $value); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | public function get_aws_regions() { |
@@ -29,137 +29,137 @@ |
||
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 | } |
@@ -301,10 +301,10 @@ discard block |
||
301 | 301 | */ |
302 | 302 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php'; |
303 | 303 | |
304 | - /** |
|
305 | - * The class responsible for the XCloner Encryption methods. |
|
306 | - */ |
|
307 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php'; |
|
304 | + /** |
|
305 | + * The class responsible for the XCloner Encryption methods. |
|
306 | + */ |
|
307 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php'; |
|
308 | 308 | |
309 | 309 | /** |
310 | 310 | * The class responsible for defining all actions that occur in the public-facing |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
333 | 333 | |
334 | 334 | //wp_localize_script( 'ajax-script', 'my_ajax_object', |
335 | - // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
|
335 | + // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
|
336 | 336 | |
337 | 337 | } |
338 | 338 | |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | |
369 | 369 | private function define_plugin_settings(){ |
370 | 370 | /** |
371 | - * register wporg_settings_init to the admin_init action hook |
|
372 | - */ |
|
371 | + * register wporg_settings_init to the admin_init action hook |
|
372 | + */ |
|
373 | 373 | |
374 | 374 | $this->xcloner_settings = new XCloner_Settings($this); |
375 | 375 | |
@@ -524,15 +524,15 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | function friendly_error_type($type) { |
527 | - static $levels=null; |
|
528 | - if ($levels===null) { |
|
529 | - $levels=[]; |
|
530 | - foreach (get_defined_constants() as $key=>$value) { |
|
531 | - if (strpos($key,'E_')!==0) {continue;} |
|
527 | + static $levels=null; |
|
528 | + if ($levels===null) { |
|
529 | + $levels=[]; |
|
530 | + foreach (get_defined_constants() as $key=>$value) { |
|
531 | + if (strpos($key,'E_')!==0) {continue;} |
|
532 | 532 | $levels[$value]= $key; //substr($key,2); |
533 | - } |
|
534 | - } |
|
535 | - return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
|
533 | + } |
|
534 | + } |
|
535 | + return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | private function define_ajax_hooks() |
@@ -578,24 +578,24 @@ discard block |
||
578 | 578 | add_action( 'wp_ajax_get_manage_backups_list', array($xcloner_api,'get_manage_backups_list') ); |
579 | 579 | add_action( 'admin_notices', array($this, 'xcloner_error_admin_notices' )); |
580 | 580 | |
581 | - } |
|
581 | + } |
|
582 | 582 | |
583 | - //Do a pre-update backup of targeted files |
|
584 | - if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
|
585 | - { |
|
583 | + //Do a pre-update backup of targeted files |
|
584 | + if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
|
585 | + { |
|
586 | 586 | add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3); |
587 | 587 | } |
588 | 588 | } |
589 | 589 | |
590 | 590 | function add_plugin_action_links($links, $file) { |
591 | - if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) |
|
591 | + if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) |
|
592 | 592 | { |
593 | 593 | $links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; |
594 | 594 | $links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; |
595 | 595 | } |
596 | 596 | |
597 | - return $links; |
|
598 | - } |
|
597 | + return $links; |
|
598 | + } |
|
599 | 599 | |
600 | 600 | public function xcloner_error_admin_notices() { |
601 | 601 | settings_errors( 'xcloner_error_message' ); |
@@ -679,9 +679,9 @@ discard block |
||
679 | 679 | function xcloner_display() |
680 | 680 | { |
681 | 681 | // check user capabilities |
682 | - if (!current_user_can('manage_options')) { |
|
683 | - return; |
|
684 | - } |
|
682 | + if (!current_user_can('manage_options')) { |
|
683 | + return; |
|
684 | + } |
|
685 | 685 | |
686 | 686 | $page = sanitize_key($_GET['page']); |
687 | 687 |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | return $this->xcloner_encryption; |
169 | 169 | } |
170 | 170 | |
171 | - public function check_dependencies(){ |
|
171 | + public function check_dependencies() { |
|
172 | 172 | |
173 | 173 | $backup_storage_path = realpath(__DIR__.DS."..".DS."..".DS."..").DS."backups".DS; |
174 | 174 | |
175 | 175 | define("XCLONER_STORAGE_PATH", realpath($backup_storage_path)); |
176 | 176 | |
177 | - if(!is_dir($backup_storage_path)) |
|
177 | + if (!is_dir($backup_storage_path)) |
|
178 | 178 | { |
179 | - if(!@mkdir($backup_storage_path)) |
|
179 | + if (!@mkdir($backup_storage_path)) |
|
180 | 180 | { |
181 | 181 | $status = "error"; |
182 | 182 | $message = sprintf(__("Unable to create the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | return; |
185 | 185 | } |
186 | 186 | } |
187 | - if(!is_writable($backup_storage_path)) |
|
187 | + if (!is_writable($backup_storage_path)) |
|
188 | 188 | { |
189 | 189 | $status = "error"; |
190 | 190 | $message = sprintf(__("Unable to write to the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
@@ -198,15 +198,15 @@ discard block |
||
198 | 198 | public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "") |
199 | 199 | { |
200 | 200 | $message = sprintf(__($message), $message_param1, $message_param2, $message_param3); |
201 | - add_action( 'xcloner_admin_notices', array($this,"trigger_message_notice"), 10, 2); |
|
202 | - do_action( 'xcloner_admin_notices', $message, $status); |
|
201 | + add_action('xcloner_admin_notices', array($this, "trigger_message_notice"), 10, 2); |
|
202 | + do_action('xcloner_admin_notices', $message, $status); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | public function trigger_message_notice($message, $status = "success") |
206 | 206 | { |
207 | 207 | ?> |
208 | 208 | <div class="notice notice-<?php echo $status?> is-dismissible"> |
209 | - <p><?php _e( $message, 'xcloner-backup-and-restore' ); ?></p> |
|
209 | + <p><?php _e($message, 'xcloner-backup-and-restore'); ?></p> |
|
210 | 210 | </div> |
211 | 211 | <?php |
212 | 212 | } |
@@ -233,84 +233,84 @@ discard block |
||
233 | 233 | * The class responsible for orchestrating the actions and filters of the |
234 | 234 | * core plugin. |
235 | 235 | */ |
236 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-loader.php'; |
|
236 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-loader.php'; |
|
237 | 237 | |
238 | 238 | /** |
239 | 239 | * The class responsible for defining internationalization functionality |
240 | 240 | * of the plugin. |
241 | 241 | */ |
242 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-i18n.php'; |
|
242 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-i18n.php'; |
|
243 | 243 | |
244 | 244 | /** |
245 | 245 | * The class responsible for defining all actions that occur in the admin area. |
246 | 246 | */ |
247 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-xcloner-admin.php'; |
|
247 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-xcloner-admin.php'; |
|
248 | 248 | |
249 | 249 | /** |
250 | 250 | * The class responsible for debugging XCloner. |
251 | 251 | */ |
252 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-logger.php'; |
|
252 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-logger.php'; |
|
253 | 253 | |
254 | 254 | /** |
255 | 255 | * The class responsible for defining the admin settings area. |
256 | 256 | */ |
257 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-settings.php'; |
|
257 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-settings.php'; |
|
258 | 258 | |
259 | 259 | /** |
260 | 260 | * The class responsible for defining the Remote Storage settings area. |
261 | 261 | */ |
262 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-remote-storage.php'; |
|
262 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-remote-storage.php'; |
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * The class responsible for implementing the database backup methods. |
266 | 266 | */ |
267 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-database.php'; |
|
267 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-database.php'; |
|
268 | 268 | |
269 | 269 | /** |
270 | 270 | * The class responsible for sanitization of users input. |
271 | 271 | */ |
272 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-sanitization.php'; |
|
272 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-sanitization.php'; |
|
273 | 273 | |
274 | 274 | /** |
275 | 275 | * The class responsible for XCloner system requirements validation. |
276 | 276 | */ |
277 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-requirements.php'; |
|
277 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-requirements.php'; |
|
278 | 278 | |
279 | 279 | /** |
280 | 280 | * The class responsible for XCloner backup archive creation. |
281 | 281 | */ |
282 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-archive.php'; |
|
282 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-archive.php'; |
|
283 | 283 | |
284 | 284 | /** |
285 | 285 | * The class responsible for XCloner API requests. |
286 | 286 | */ |
287 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-api.php'; |
|
287 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-api.php'; |
|
288 | 288 | |
289 | 289 | /** |
290 | 290 | * The class responsible for the XCloner File System methods. |
291 | 291 | */ |
292 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-system.php'; |
|
292 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-system.php'; |
|
293 | 293 | |
294 | 294 | /** |
295 | 295 | * The class responsible for the XCloner File Transfer methods. |
296 | 296 | */ |
297 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-transfer.php'; |
|
297 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-transfer.php'; |
|
298 | 298 | |
299 | 299 | /** |
300 | 300 | * The class responsible for the XCloner Scheduler methods. |
301 | 301 | */ |
302 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php'; |
|
302 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-scheduler.php'; |
|
303 | 303 | |
304 | 304 | /** |
305 | 305 | * The class responsible for the XCloner Encryption methods. |
306 | 306 | */ |
307 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php'; |
|
307 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-encryption.php'; |
|
308 | 308 | |
309 | 309 | /** |
310 | 310 | * The class responsible for defining all actions that occur in the public-facing |
311 | 311 | * side of the site. |
312 | 312 | */ |
313 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-xcloner-public.php'; |
|
313 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-xcloner-public.php'; |
|
314 | 314 | |
315 | 315 | $this->loader = new Xcloner_Loader($this); |
316 | 316 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | |
330 | 330 | $plugin_i18n = new Xcloner_i18n(); |
331 | 331 | |
332 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
332 | + $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
|
333 | 333 | |
334 | 334 | //wp_localize_script( 'ajax-script', 'my_ajax_object', |
335 | 335 | // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
@@ -345,13 +345,13 @@ discard block |
||
345 | 345 | */ |
346 | 346 | private function define_admin_hooks() { |
347 | 347 | |
348 | - $plugin_admin = new Xcloner_Admin( $this ); |
|
348 | + $plugin_admin = new Xcloner_Admin($this); |
|
349 | 349 | $this->plugin_admin = $plugin_admin; |
350 | 350 | |
351 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
352 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
351 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
|
352 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
|
353 | 353 | |
354 | - add_action( 'backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2); |
|
354 | + add_action('backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -360,31 +360,31 @@ discard block |
||
360 | 360 | * @access private |
361 | 361 | * |
362 | 362 | */ |
363 | - private function define_admin_menu(){ |
|
363 | + private function define_admin_menu() { |
|
364 | 364 | |
365 | 365 | add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu')); |
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | - private function define_plugin_settings(){ |
|
369 | + private function define_plugin_settings() { |
|
370 | 370 | /** |
371 | 371 | * register wporg_settings_init to the admin_init action hook |
372 | 372 | */ |
373 | 373 | |
374 | 374 | $this->xcloner_settings = new XCloner_Settings($this); |
375 | 375 | |
376 | - if(defined('DOING_CRON') || isset($_POST['hash'])){ |
|
376 | + if (defined('DOING_CRON') || isset($_POST['hash'])) { |
|
377 | 377 | |
378 | - if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){ |
|
378 | + if (defined('DOING_CRON') || $_POST['hash'] == "generate_hash") { |
|
379 | 379 | $this->xcloner_settings->generate_new_hash(); |
380 | - }else{ |
|
380 | + } else { |
|
381 | 381 | $this->xcloner_settings->set_hash($_POST['hash']); |
382 | 382 | } |
383 | 383 | } |
384 | 384 | |
385 | - if(defined('DOING_CRON') || !isset($_POST['hash'])) |
|
385 | + if (defined('DOING_CRON') || !isset($_POST['hash'])) |
|
386 | 386 | { |
387 | - add_action( 'shutdown', function(){ |
|
387 | + add_action('shutdown', function() { |
|
388 | 388 | $this->xcloner_filesystem = new Xcloner_File_System($this); |
389 | 389 | $this->xcloner_filesystem->remove_tmp_filesystem(); |
390 | 390 | }); |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | */ |
408 | 408 | public function pre_auto_update($type, $item, $context) |
409 | 409 | { |
410 | - if(!$type) |
|
410 | + if (!$type) |
|
411 | 411 | { |
412 | 412 | return false; |
413 | 413 | } |
@@ -416,10 +416,10 @@ discard block |
||
416 | 416 | |
417 | 417 | $content_dir = str_replace(ABSPATH, "", WP_CONTENT_DIR); |
418 | 418 | $plugins_dir = str_replace(ABSPATH, "", WP_PLUGIN_DIR); |
419 | - $langs_dir = $content_dir . DS . "languages"; |
|
420 | - $themes_dir = $content_dir . DS . "themes"; |
|
419 | + $langs_dir = $content_dir.DS."languages"; |
|
420 | + $themes_dir = $content_dir.DS."themes"; |
|
421 | 421 | |
422 | - switch ( $type ) { |
|
422 | + switch ($type) { |
|
423 | 423 | case 'core': |
424 | 424 | $exclude_files = array( |
425 | 425 | "^(?!(wp-admin|wp-includes|(?!.*\/.*.php)))(.*)$", |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | |
430 | 430 | $dir_array = explode(DS, $plugins_dir); |
431 | 431 | |
432 | - foreach($dir_array as $dir) |
|
432 | + foreach ($dir_array as $dir) |
|
433 | 433 | { |
434 | 434 | $data .= "\/".$dir; |
435 | 435 | $regex .= $data."$|"; |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | |
446 | 446 | $dir_array = explode(DS, $themes_dir); |
447 | 447 | |
448 | - foreach($dir_array as $dir) |
|
448 | + foreach ($dir_array as $dir) |
|
449 | 449 | { |
450 | 450 | $data .= "\/".$dir; |
451 | 451 | $regex .= $data."$|"; |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | |
462 | 462 | $dir_array = explode(DS, $langs_dir); |
463 | 463 | |
464 | - foreach($dir_array as $dir) |
|
464 | + foreach ($dir_array as $dir) |
|
465 | 465 | { |
466 | 466 | $data .= "\/".$dir; |
467 | 467 | $regex .= $data."$|"; |
@@ -487,9 +487,9 @@ discard block |
||
487 | 487 | $schedule['backup_params']->email_notification = get_option('admin_email'); |
488 | 488 | $schedule['backup_params']->backup_name = "backup_pre_auto_update_".$type."_[domain]-[time]-sql"; |
489 | 489 | |
490 | - try{ |
|
490 | + try { |
|
491 | 491 | $this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule); |
492 | - }catch(Exception $e){ |
|
492 | + }catch (Exception $e) { |
|
493 | 493 | $this->get_xcloner_logger()->error($e->getMessage()); |
494 | 494 | } |
495 | 495 | |
@@ -504,10 +504,10 @@ discard block |
||
504 | 504 | */ |
505 | 505 | private function define_public_hooks() { |
506 | 506 | |
507 | - $plugin_public = new Xcloner_Public( $this ); |
|
507 | + $plugin_public = new Xcloner_Public($this); |
|
508 | 508 | |
509 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
510 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
509 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); |
|
510 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); |
|
511 | 511 | |
512 | 512 | } |
513 | 513 | |
@@ -516,20 +516,20 @@ discard block |
||
516 | 516 | $logger = new XCloner_Logger($this, "php_system"); |
517 | 517 | $error = error_get_last(); |
518 | 518 | |
519 | - if($error['type'] and $logger) |
|
519 | + if ($error['type'] and $logger) |
|
520 | 520 | { |
521 | - $logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true)); |
|
521 | + $logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true)); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | } |
525 | 525 | |
526 | 526 | function friendly_error_type($type) { |
527 | - static $levels=null; |
|
528 | - if ($levels===null) { |
|
529 | - $levels=[]; |
|
527 | + static $levels = null; |
|
528 | + if ($levels === null) { |
|
529 | + $levels = []; |
|
530 | 530 | foreach (get_defined_constants() as $key=>$value) { |
531 | - if (strpos($key,'E_')!==0) {continue;} |
|
532 | - $levels[$value]= $key; //substr($key,2); |
|
531 | + if (strpos($key, 'E_') !== 0) {continue; } |
|
532 | + $levels[$value] = $key; //substr($key,2); |
|
533 | 533 | } |
534 | 534 | } |
535 | 535 | return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
@@ -539,56 +539,56 @@ discard block |
||
539 | 539 | { |
540 | 540 | //adding the pre-update hook |
541 | 541 | |
542 | - if(is_admin() || defined('DOING_CRON')) |
|
542 | + if (is_admin() || defined('DOING_CRON')) |
|
543 | 543 | { |
544 | - $this->xcloner_logger = new XCloner_Logger($this, "xcloner_api"); |
|
545 | - $this->xcloner_filesystem = new Xcloner_File_System($this); |
|
544 | + $this->xcloner_logger = new XCloner_Logger($this, "xcloner_api"); |
|
545 | + $this->xcloner_filesystem = new Xcloner_File_System($this); |
|
546 | 546 | |
547 | 547 | //$this->xcloner_filesystem->set_diff_timestamp_start (strtotime("-15 days")); |
548 | 548 | |
549 | - $this->archive_system = new Xcloner_Archive($this); |
|
550 | - $this->xcloner_database = new Xcloner_Database($this); |
|
551 | - $this->xcloner_scheduler = new Xcloner_Scheduler($this); |
|
552 | - $this->xcloner_remote_storage = new Xcloner_Remote_Storage($this); |
|
549 | + $this->archive_system = new Xcloner_Archive($this); |
|
550 | + $this->xcloner_database = new Xcloner_Database($this); |
|
551 | + $this->xcloner_scheduler = new Xcloner_Scheduler($this); |
|
552 | + $this->xcloner_remote_storage = new Xcloner_Remote_Storage($this); |
|
553 | 553 | $this->xcloner_file_transfer = new Xcloner_File_Transfer($this); |
554 | 554 | $this->xcloner_encryption = new Xcloner_Encryption($this); |
555 | 555 | |
556 | - $xcloner_api = new Xcloner_Api($this); |
|
557 | - |
|
558 | - add_action( 'wp_ajax_get_database_tables_action', array($xcloner_api,'get_database_tables_action') ); |
|
559 | - add_action( 'wp_ajax_get_file_system_action', array($xcloner_api,'get_file_system_action') ); |
|
560 | - add_action( 'wp_ajax_scan_filesystem', array($xcloner_api,'scan_filesystem') ); |
|
561 | - add_action( 'wp_ajax_backup_database', array($xcloner_api,'backup_database') ); |
|
562 | - add_action( 'wp_ajax_backup_files' , array($xcloner_api,'backup_files') ); |
|
563 | - add_action( 'wp_ajax_save_schedule' , array($xcloner_api,'save_schedule') ); |
|
564 | - add_action( 'wp_ajax_get_schedule_by_id', array($xcloner_api,'get_schedule_by_id') ); |
|
565 | - add_action( 'wp_ajax_get_scheduler_list', array($xcloner_api,'get_scheduler_list') ); |
|
566 | - add_action( 'wp_ajax_delete_schedule_by_id' , array($xcloner_api,'delete_schedule_by_id') ); |
|
567 | - add_action( 'wp_ajax_delete_backup_by_name' , array($xcloner_api,'delete_backup_by_name') ); |
|
568 | - add_action( 'wp_ajax_download_backup_by_name', array($xcloner_api,'download_backup_by_name') ); |
|
569 | - add_action( 'wp_ajax_remote_storage_save_status', array($xcloner_api,'remote_storage_save_status') ); |
|
570 | - add_action( 'wp_ajax_upload_backup_to_remote', array($xcloner_api,'upload_backup_to_remote') ); |
|
571 | - add_action( 'wp_ajax_list_backup_files' , array($xcloner_api,'list_backup_files') ); |
|
572 | - add_action( 'wp_ajax_restore_upload_backup' , array($xcloner_api,'restore_upload_backup') ); |
|
573 | - add_action( 'wp_ajax_download_restore_script', array($xcloner_api,'download_restore_script') ); |
|
574 | - add_action( 'wp_ajax_copy_backup_remote_to_local', array($xcloner_api,'copy_backup_remote_to_local') ); |
|
575 | - add_action( 'wp_ajax_restore_backup', array($xcloner_api,'restore_backup') ); |
|
576 | - add_action( 'wp_ajax_backup_encryption', array($xcloner_api,'backup_encryption') ); |
|
577 | - add_action( 'wp_ajax_backup_decryption', array($xcloner_api,'backup_decryption') ); |
|
578 | - add_action( 'wp_ajax_get_manage_backups_list', array($xcloner_api,'get_manage_backups_list') ); |
|
579 | - add_action( 'admin_notices', array($this, 'xcloner_error_admin_notices' )); |
|
556 | + $xcloner_api = new Xcloner_Api($this); |
|
557 | + |
|
558 | + add_action('wp_ajax_get_database_tables_action', array($xcloner_api, 'get_database_tables_action')); |
|
559 | + add_action('wp_ajax_get_file_system_action', array($xcloner_api, 'get_file_system_action')); |
|
560 | + add_action('wp_ajax_scan_filesystem', array($xcloner_api, 'scan_filesystem')); |
|
561 | + add_action('wp_ajax_backup_database', array($xcloner_api, 'backup_database')); |
|
562 | + add_action('wp_ajax_backup_files', array($xcloner_api, 'backup_files')); |
|
563 | + add_action('wp_ajax_save_schedule', array($xcloner_api, 'save_schedule')); |
|
564 | + add_action('wp_ajax_get_schedule_by_id', array($xcloner_api, 'get_schedule_by_id')); |
|
565 | + add_action('wp_ajax_get_scheduler_list', array($xcloner_api, 'get_scheduler_list')); |
|
566 | + add_action('wp_ajax_delete_schedule_by_id', array($xcloner_api, 'delete_schedule_by_id')); |
|
567 | + add_action('wp_ajax_delete_backup_by_name', array($xcloner_api, 'delete_backup_by_name')); |
|
568 | + add_action('wp_ajax_download_backup_by_name', array($xcloner_api, 'download_backup_by_name')); |
|
569 | + add_action('wp_ajax_remote_storage_save_status', array($xcloner_api, 'remote_storage_save_status')); |
|
570 | + add_action('wp_ajax_upload_backup_to_remote', array($xcloner_api, 'upload_backup_to_remote')); |
|
571 | + add_action('wp_ajax_list_backup_files', array($xcloner_api, 'list_backup_files')); |
|
572 | + add_action('wp_ajax_restore_upload_backup', array($xcloner_api, 'restore_upload_backup')); |
|
573 | + add_action('wp_ajax_download_restore_script', array($xcloner_api, 'download_restore_script')); |
|
574 | + add_action('wp_ajax_copy_backup_remote_to_local', array($xcloner_api, 'copy_backup_remote_to_local')); |
|
575 | + add_action('wp_ajax_restore_backup', array($xcloner_api, 'restore_backup')); |
|
576 | + add_action('wp_ajax_backup_encryption', array($xcloner_api, 'backup_encryption')); |
|
577 | + add_action('wp_ajax_backup_decryption', array($xcloner_api, 'backup_decryption')); |
|
578 | + add_action('wp_ajax_get_manage_backups_list', array($xcloner_api, 'get_manage_backups_list')); |
|
579 | + add_action('admin_notices', array($this, 'xcloner_error_admin_notices')); |
|
580 | 580 | |
581 | 581 | } |
582 | 582 | |
583 | 583 | //Do a pre-update backup of targeted files |
584 | - if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
|
584 | + if ($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
|
585 | 585 | { |
586 | 586 | add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3); |
587 | 587 | } |
588 | 588 | } |
589 | 589 | |
590 | 590 | function add_plugin_action_links($links, $file) { |
591 | - if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) |
|
591 | + if ($file == plugin_basename(dirname(dirname(__FILE__)).'/xcloner.php')) |
|
592 | 592 | { |
593 | 593 | $links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; |
594 | 594 | $links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; |
@@ -598,13 +598,13 @@ discard block |
||
598 | 598 | } |
599 | 599 | |
600 | 600 | public function xcloner_error_admin_notices() { |
601 | - settings_errors( 'xcloner_error_message' ); |
|
601 | + settings_errors('xcloner_error_message'); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | public function define_cron_hooks() |
605 | 605 | { |
606 | 606 | //registering new schedule intervals |
607 | - add_filter( 'cron_schedules', array($this, 'add_new_intervals')); |
|
607 | + add_filter('cron_schedules', array($this, 'add_new_intervals')); |
|
608 | 608 | |
609 | 609 | |
610 | 610 | $xcloner_scheduler = $this->get_xcloner_scheduler(); |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | |
686 | 686 | $page = sanitize_key($_GET['page']); |
687 | 687 | |
688 | - if($page) |
|
688 | + if ($page) |
|
689 | 689 | { |
690 | 690 | $this->display($page); |
691 | 691 | } |