Skip to content

Commit

Permalink
Mod. ButtonAction. Checking for the existence of a file and deleting …
Browse files Browse the repository at this point in the history
…it from the log
  • Loading branch information
AntonV1211 committed Oct 10, 2024
1 parent e5f72ae commit cb89e1e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inc/spbc-scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function spbc_scanner_links_get_scanned__domains($offset = 0, $amount = 20, $ord

/**
* Remove file from the database
* @param int $file_id
* @param int|string $file_id
* @return bool
*/
function spbc_scanner_file_remove_from_log($file_id)
Expand Down
52 changes: 52 additions & 0 deletions lib/CleantalkSP/SpbctWP/ListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,60 @@ public static function ajaxBulkActionHandler()
wp_send_json($out);
}

public static function spbcCheckFileExist()
{
global $wpdb;

$root_path = spbc_get_root_path();
$file_id = preg_match('@[a-zA-Z0-9]{32}@', Post::get('id', null, 'word')) ? Post::get('id', null, 'word') : null;

$sql = 'SELECT fast_hash, path, source_type, source, source_status, version, mtime, weak_spots, full_hash, real_full_hash, status, checked_signatures, checked_heuristic
FROM ' . SPBC_TBL_SCAN_FILES . '
WHERE fast_hash = %s
LIMIT %d';
$sql_result = $file_id !== null ? $wpdb->get_results($wpdb->prepare($sql, $file_id, 1), ARRAY_A) : null;

if ($sql_result[0]) {
$file_info = $sql_result[0];
$file_not_exists = !file_exists($root_path . $file_info['path']);

if ($file_not_exists) {
$res = spbc_scanner_file_remove_from_log($file_id);

if ($res === false) {
return array(
'error' => __('File not exists and must be removed from log, but something went wrong.', 'security-malware-firewall'),
'error_type' => 'FILE_NOT_EXISTS_DB_ERROR'
);
}

return array(
'error' => __('File not exists and will be removed from log.', 'security-malware-firewall'),
'error_type' => 'FILE_NOT_EXISTS'
);
}
}

return false;
}

public static function ajaxRowActionHandler()
{
$check_file_exist_result = self::spbcCheckFileExist();

if (isset($check_file_exist_result['error'])) {
$out = array(
'html' => '<div class="spbc-popup-msg popup--red">'
. $check_file_exist_result['error']
. '</div>',
'success' => true,
'color' => 'black',
'background' => 'rgba(110, 110, 240, 0.7)',
);

wp_send_json($out);
}

spbc_check_ajax_referer('spbc_secret_nonce', 'security');

try {
Expand Down

0 comments on commit cb89e1e

Please sign in to comment.