Skip to content

Commit d6d2cd8

Browse files
1 parent 70ea537 commit d6d2cd8

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

lib/CleantalkSP/SpbctWP/Scanner/ScanRepository.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ public static function getPendingQueueFiles()
3535
);
3636
}
3737

38+
/**
39+
* Get fast hashes of the files known to the cloud analysis
40+
* @return array
41+
*/
42+
public static function getCloudAnalysisFilesFastHashes()
43+
{
44+
global $wpdb;
45+
46+
return (array) $wpdb->get_col(
47+
'SELECT DISTINCT fast_hash FROM ' . SPBC_TBL_SCAN_FILES
48+
. ' WHERE pscan_file_id IS NOT NULL AND fast_hash IS NOT NULL AND fast_hash <> ""'
49+
);
50+
}
51+
3852
/**
3953
* Get file info by fast_hash
4054
* @return array|null

lib/CleantalkSP/SpbctWP/Sync.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace CleantalkSP\SpbctWP;
44

55
use CleantalkSP\SpbctWP\AdjustToEnvironmentModule\AdjustToEnvironmentHandler;
6+
use CleantalkSP\SpbctWP\Scanner\ScannerAjaxEndpoints;
7+
use CleantalkSP\SpbctWP\Scanner\ScanRepository;
68
use CleantalkSP\SpbctWP\Settings\FilesScanPathExclusion;
79

810
class Sync
@@ -17,6 +19,7 @@ class Sync
1719
'settings_exclusions' => 'Handling exclusions...',
1820
'adjust_env' => 'Adjusting environment...',
1921
'vulnerability_check' => 'Running vulnerability check...',
22+
'analysis_log_update' => 'Updating cloud analysis verdicts...',
2023
'finalize' => 'Sync end...',
2124
);
2225

@@ -101,6 +104,7 @@ public static function run()
101104
self::stepSettingsExclusions();
102105
self::stepAdjustEnv();
103106
self::stepVulnerabilityCheck();
107+
self::stepAnalysisLogUpdate($account_is_ok);
104108

105109
$out = array(
106110
'success' => true,
@@ -179,6 +183,9 @@ public static function runCurrentStep()
179183
case 'vulnerability_check':
180184
self::stepVulnerabilityCheck();
181185
break;
186+
case 'analysis_log_update':
187+
self::stepAnalysisLogUpdate($account_is_ok);
188+
break;
182189
case 'finalize':
183190
self::stepFinalize();
184191

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

402+
/**
403+
* Pull actual cloud verdicts for the scan results files.
404+
* The cloud verdict may be changed after the file processing is done,
405+
* so the files with the final verdict have to be re-checked too.
406+
*
407+
* @param bool $account_is_ok
408+
*/
409+
private static function stepAnalysisLogUpdate($account_is_ok)
410+
{
411+
global $spbc;
412+
413+
if ( ! $account_is_ok || ! is_main_site() ) {
414+
return;
415+
}
416+
417+
$file_ids = ScanRepository::getCloudAnalysisFilesFastHashes();
418+
419+
if ( empty($file_ids) ) {
420+
return;
421+
}
422+
423+
$result = ScannerAjaxEndpoints::checkFilesAnalysisStatus(true, $file_ids);
424+
425+
if ( ! empty($result['error']) ) {
426+
$spbc->error_add('analysis_log_update', $result);
427+
} else {
428+
$spbc->error_delete('analysis_log_update');
429+
}
430+
}
431+
395432
private static function stepFinalize()
396433
{
397434
global $spbc;

0 commit comments

Comments
 (0)