Skip to content

Commit

Permalink
Merge branch 'dev' into scan-log-to-clipboard-and-pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
svfcode authored Oct 31, 2024
2 parents c0ad72d + ebfff9b commit 5c9a161
Show file tree
Hide file tree
Showing 58 changed files with 1,156 additions and 1,832 deletions.
14 changes: 7 additions & 7 deletions inc/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<a href="' . $spbc->settings_link . '&spbc_tab=critical_updates">' . __('Critical updates', 'security-malware-firewall') . '</a>',
));

// FireWall
if ( (int) $spbc->settings['secfw__enabled'] ) {
$wp_admin_bar->add_node(array(
Expand Down Expand Up @@ -306,13 +313,6 @@ function spbc_admin__admin_bar__add_child_nodes($wp_admin_bar)
'title' => '<a href="' . $spbc->settings_link . '&spbc_tab=summary">' . __('Summary', 'security-malware-firewall') . '</a>',
));

// Critical updates
$wp_admin_bar->add_node(array(
'parent' => 'spbc__parent_node',
'id' => 'spbc_admin_bar__critical_updates_link',
'title' => '<a href="' . $spbc->settings_link . '&spbc_tab=critical_updates">' . __('Critical updates', 'security-malware-firewall') . '</a>',
));

// Support link
$wp_admin_bar->add_node(array(
'parent' => 'spbc__parent_node',
Expand Down
1 change: 1 addition & 0 deletions inc/spbc-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
111 changes: 61 additions & 50 deletions inc/spbc-scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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'];
Expand All @@ -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'));
Expand Down
6 changes: 4 additions & 2 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -1934,7 +1935,7 @@ function spbc_field_key()
echo '<a id="spbc-key-manually-link" target="_blank" href="https://cleantalk.org/register?platform=wordpress&email=' . urlencode(spbc_get_admin_email()) . '&website=' . urlencode(parse_url(get_option('home'), PHP_URL_HOST)) . '&product_name=security" style="display: inline-block;">
<input style="color:#666;" type="button" class="spbc_auto_link" value="' . __('Get access key manually', 'security-malware-firewall') . '" />
</a>';
echo '&nbsp;' . __('or', 'security-malware-firewall') . '&nbsp;';
echo '<span id="spbc_get_key_or_text">&nbsp;' . __('or', 'security-malware-firewall') . '&nbsp;</span>';
echo '<button class="spbc_manual_link" id="spbc_setting_get_key_auto" name="spbc_get_apikey_auto" type="button" value="get_key_auto">'
. __('Get access key automatically', 'security-malware-firewall')
. '<img style="margin-left: 10px;" class="spbc_preloader_button" src="' . SPBC_PATH . '/images/preloader2.gif" />'
Expand Down Expand Up @@ -4295,6 +4296,7 @@ function spbc_list_table__get_args_by_type($table_type)
),
'bulk_actions' => array(
'cure' => array('name' => 'Cure',),
'restore' => array('name' => 'Restore',),
),
'func_data_total' => 'spbc_scanner__cure_log_get_count_total',
'func_data_get' => 'spbc_scanner__get_cure_log_data',
Expand Down
Loading

0 comments on commit 5c9a161

Please sign in to comment.