diff --git a/inc/admin-bar.php b/inc/admin-bar.php index 0e2b9c1d7..3404fac5d 100644 --- a/inc/admin-bar.php +++ b/inc/admin-bar.php @@ -244,6 +244,13 @@ function spbc_admin__admin_bar__add_child_nodes($wp_admin_bar) )); } + // Critical updates + $wp_admin_bar->add_node(array( + 'parent' => 'spbc__parent_node', + 'id' => 'spbc_admin_bar__critical_updates_link', + 'title' => '' . __('Critical updates', 'security-malware-firewall') . '', + )); + // FireWall if ( (int) $spbc->settings['secfw__enabled'] ) { $wp_admin_bar->add_node(array( @@ -306,13 +313,6 @@ function spbc_admin__admin_bar__add_child_nodes($wp_admin_bar) 'title' => '' . __('Summary', 'security-malware-firewall') . '', )); - // Critical updates - $wp_admin_bar->add_node(array( - 'parent' => 'spbc__parent_node', - 'id' => 'spbc_admin_bar__critical_updates_link', - 'title' => '' . __('Critical updates', 'security-malware-firewall') . '', - )); - // Support link $wp_admin_bar->add_node(array( 'parent' => 'spbc__parent_node', diff --git a/inc/spbc-admin.php b/inc/spbc-admin.php index a5f233c54..57668a57a 100644 --- a/inc/spbc-admin.php +++ b/inc/spbc-admin.php @@ -102,6 +102,7 @@ function spbc_admin_init() add_action('wp_ajax_spbc_tbl-sort', array(ListTable::class, 'ajaxSortHandler')); add_action('wp_ajax_spbc_tbl-switch', array(ListTable::class, 'ajaxSwitchTable')); add_action('wp_ajax_spbc_cure_selected', array(Cure::class, 'cureSelectedAction')); + add_action('wp_ajax_spbc_restore_selected', array(Cure::class, 'restoreSelectedAction')); // Send logs_mscan add_action('wp_ajax_spbc_send_traffic_control', 'spbc_send_firewall_logs', 1, 0); diff --git a/inc/spbc-scanner.php b/inc/spbc-scanner.php index 0ba1838cf..c0720c0e5 100644 --- a/inc/spbc-scanner.php +++ b/inc/spbc-scanner.php @@ -2205,28 +2205,25 @@ function spbc_cure_file($file_fast_hash) return esc_html__('Success!', 'security-malware-firewall'); } -function spbc_restore_file_from_backup_ajax_action() +function spbc_restore_file_from_backup_ajax_action_handler($id) { global $wpdb; - spbc_check_ajax_referer('spbc_secret_nonce', 'security'); - - $file_fast_hash = isset($_POST['file_fast_hash']) ? esc_sql($_POST['file_fast_hash']) : null; - - if (is_null($file_fast_hash)) { - wp_send_json_error(esc_html__('Error: File not found.', 'security-malware-firewall')); + if (is_null($id)) { + return array('error' => esc_html__('Error: File not found.', 'security-malware-firewall')); } // Getting file path - $file_path = $wpdb->get_row( + $file_path_sql_prepared = $wpdb->prepare( 'SELECT path ' . ' FROM ' . SPBC_TBL_SCAN_FILES - . ' WHERE fast_hash="' . $file_fast_hash . '";', - ARRAY_A + . ' WHERE fast_hash=%s;', + $id ); + $file_path = $wpdb->get_row($file_path_sql_prepared, ARRAY_A); if (is_null($file_path)) { - wp_send_json_error(esc_html__('Error: File path not found.', 'security-malware-firewall')); + return array('error' => esc_html__('Error: File path not found.', 'security-malware-firewall')); } $file_path = $file_path['path']; @@ -2243,7 +2240,7 @@ function spbc_restore_file_from_backup_ajax_action() $backup_path = $wpdb->get_row($sql_prepared, ARRAY_A); if (is_null($backup_path)) { - wp_send_json_error(esc_html__('Error: Backup not found.', 'security-malware-firewall')); + return array('error' => esc_html__('Error: Backup not found.', 'security-malware-firewall')); } $backup_path = $backup_path['back_path']; @@ -2253,54 +2250,68 @@ function spbc_restore_file_from_backup_ajax_action() $backup_content = file_get_contents($full_backup_path); if ($backup_content === false) { - wp_send_json_error(esc_html__('Error: File not exists or permissions denied.', 'security-malware-firewall')); + return array('error' => esc_html__('Error: File not exists or permissions denied.', 'security-malware-firewall')); } - if (file_exists($full_file_path)) { - $result = file_put_contents($full_file_path, $backup_content); + if (!file_exists($full_file_path)) { + return array('error' => esc_html__('Error: Original file not exists.', 'security-malware-firewall')); + } - if ($result === false) { - wp_send_json_error(esc_html__('Error: Permissions denied.', 'security-malware-firewall')); - } + $result = file_put_contents($full_file_path, $backup_content); - // Success: remove all data about backup - try { - $backup_deleted = unlink($full_backup_path); + if ($result === false) { + return array('error' => esc_html__('Error: Permissions denied.', 'security-malware-firewall')); + } - if ($backup_deleted === false) { - wp_send_json_error(esc_html__('Error: Permissions denied.', 'security-malware-firewall')); - } + // Success: remove all data about backup + try { + $backup_deleted = unlink($full_backup_path); - // Remove from backup - $sql_prepared = $wpdb->prepare( - 'DELETE ' - . ' FROM ' . SPBC_TBL_BACKUPED_FILES - . ' WHERE real_path="%s";', - $file_path - ); - $delete = $wpdb->query($sql_prepared); + if ($backup_deleted === false) { + return array('error' => esc_html__('Deleting backup error: Permissions denied.', 'security-malware-firewall')); + } - if (is_null($delete)) { - wp_send_json_error(esc_html__('Error: Something is wrong.', 'security-malware-firewall')); - } + // Remove from backup + $sql_prepared = $wpdb->prepare( + 'DELETE ' + . ' FROM ' . SPBC_TBL_BACKUPED_FILES + . ' WHERE real_path="%s";', + $file_path + ); + $delete = $wpdb->query($sql_prepared); - // Remove from cure log - $sql_prepared = $wpdb->prepare( - 'DELETE ' - . ' FROM ' . SPBC_TBL_CURE_LOG - . ' WHERE real_path="%s";', - $file_path - ); - $delete = $wpdb->query($sql_prepared); + if (is_null($delete)) { + return array('error' => esc_html__('Error: Something is wrong.', 'security-malware-firewall')); + } - if (is_null($delete)) { - wp_send_json_error(esc_html__('Error: Something is wrong.', 'security-malware-firewall')); - } - } catch (\Exception $e) { - wp_send_json_error(esc_html__('Error: Something is wrong.', 'security-malware-firewall')); + // Remove from cure log + $sql_prepared = $wpdb->prepare( + 'DELETE ' + . ' FROM ' . SPBC_TBL_CURE_LOG + . ' WHERE real_path="%s";', + $file_path + ); + $delete = $wpdb->query($sql_prepared); + + if (is_null($delete)) { + return array('error' => esc_html__('Error: Something is wrong.', 'security-malware-firewall')); } - } else { - wp_send_json_error(esc_html__('Error: Original file not exists.', 'security-malware-firewall')); + } catch (\Exception $e) { + return array('error' => esc_html__('Error: Something is wrong.', 'security-malware-firewall')); + } + + return array('success' => true); +} + +function spbc_restore_file_from_backup_ajax_action() +{ + spbc_check_ajax_referer('spbc_secret_nonce', 'security'); + + $file_fast_hash = isset($_POST['file_fast_hash']) ? esc_sql($_POST['file_fast_hash']) : null; + + $result = spbc_restore_file_from_backup_ajax_action_handler($file_fast_hash); + if (isset($result['error'])) { + wp_send_json_error($result['error']); } wp_send_json_success(esc_html__('Success!', 'security-malware-firewall')); diff --git a/inc/spbc-settings.php b/inc/spbc-settings.php index 1752e9a02..19a458967 100644 --- a/inc/spbc-settings.php +++ b/inc/spbc-settings.php @@ -1090,7 +1090,8 @@ function spbc_settings__register() ), ), ), - 'display' => $spbc->settings['scanner__fs_watcher'] + 'display' => $spbc->settings['scanner__fs_watcher'], + 'js_after' => 'settings_tab--fswatcher.min.js', ), // Debug 'debug' => array( @@ -1934,7 +1935,7 @@ function spbc_field_key() echo ' '; - echo ' ' . __('or', 'security-malware-firewall') . ' '; + echo ' ' . __('or', 'security-malware-firewall') . ' '; echo '