Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ public static function getPendingQueueFiles()
);
}

/**
* Get fast hashes of the files known to the cloud analysis
* @return array
*/
public static function getCloudAnalysisFilesFastHashes()
{
global $wpdb;

return (array) $wpdb->get_col(
'SELECT DISTINCT fast_hash FROM ' . SPBC_TBL_SCAN_FILES
. ' WHERE pscan_file_id IS NOT NULL AND fast_hash IS NOT NULL AND fast_hash <> ""'
);
}
Comment thread
Copilot marked this conversation as resolved.

/**
* Get file info by fast_hash
* @return array|null
Expand Down
37 changes: 37 additions & 0 deletions lib/CleantalkSP/SpbctWP/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace CleantalkSP\SpbctWP;

use CleantalkSP\SpbctWP\AdjustToEnvironmentModule\AdjustToEnvironmentHandler;
use CleantalkSP\SpbctWP\Scanner\ScannerAjaxEndpoints;
use CleantalkSP\SpbctWP\Scanner\ScanRepository;
use CleantalkSP\SpbctWP\Settings\FilesScanPathExclusion;

class Sync
Expand All @@ -17,6 +19,7 @@ class Sync
'settings_exclusions' => 'Handling exclusions...',
'adjust_env' => 'Adjusting environment...',
'vulnerability_check' => 'Running vulnerability check...',
'analysis_log_update' => 'Updating cloud analysis verdicts...',
'finalize' => 'Sync end...',
);

Expand Down Expand Up @@ -101,6 +104,7 @@ public static function run()
self::stepSettingsExclusions();
self::stepAdjustEnv();
self::stepVulnerabilityCheck();
self::stepAnalysisLogUpdate($account_is_ok);

$out = array(
'success' => true,
Expand Down Expand Up @@ -179,6 +183,9 @@ public static function runCurrentStep()
case 'vulnerability_check':
self::stepVulnerabilityCheck();
break;
case 'analysis_log_update':
self::stepAnalysisLogUpdate($account_is_ok);
break;
case 'finalize':
self::stepFinalize();

Expand Down Expand Up @@ -392,6 +399,36 @@ private static function stepVulnerabilityCheck()
Cron::updateTask('check_vulnerabilities', 'spbc_security_check_vulnerabilities', 86400, time());
}

/**
* Pull actual cloud verdicts for the scan results files.
* The cloud verdict may be changed after the file processing is done,
* so the files with the final verdict have to be re-checked too.
*
* @param bool $account_is_ok
*/
private static function stepAnalysisLogUpdate($account_is_ok)
{
global $spbc;

if ( ! $account_is_ok || ! is_main_site() ) {
return;
}

$file_ids = ScanRepository::getCloudAnalysisFilesFastHashes();

if ( empty($file_ids) ) {
return;
}

$result = ScannerAjaxEndpoints::checkFilesAnalysisStatus(true, $file_ids);

if ( ! empty($result['error']) ) {
$spbc->error_add('analysis_log_update', $result);
} else {
$spbc->error_delete('analysis_log_update');
}
}
Comment thread
Copilot marked this conversation as resolved.

private static function stepFinalize()
{
global $spbc;
Expand Down
Loading