[VS] Fix scan status and other minor fix.

This commit is contained in:
Nicolo Maio 2023-09-18 14:52:05 +02:00
parent 38f0047dc1
commit 53b0d52fc0
7 changed files with 127 additions and 38 deletions

View file

@ -63,8 +63,9 @@ end
vs_utils.scan_status = {
error = 0,
ok = 1,
in_progress = 2,
not_scanned = 3
scheduled = 2,
not_scanned = 3,
scanning = 4
}
-- **********************************************************
@ -501,7 +502,7 @@ function vs_utils.notify_end_periodicity()
if (periodicity_scan_in_progress) then
local hosts_details = vs_utils.retrieve_hosts_to_scan()
for _,item in ipairs(hosts_details) do
if(item.is_periodicity and item.is_ok_last_scan == vs_utils.scan_status.in_progress) then
if(item.is_periodicity and item.is_ok_last_scan == vs_utils.scan_status.scheduled) then
return
end
end
@ -570,7 +571,7 @@ function vs_utils.check_in_progress_status()
if (not isEmptyString(hash_value_string)) then
local hash_value = json.decode(hash_value_string)
-- Check IN PROGRESS --> FIX ME with enums
if hash_value and hash_value.is_ok_last_scan == vs_utils.scan_status.in_progress then
if hash_value and (hash_value.is_ok_last_scan == vs_utils.scan_status.scheduled or hash_value.is_ok_last_scan == vs_utils.scan_status.scanning) then
total_in_progress = total_in_progress + 1
end
total = total + 1
@ -738,6 +739,8 @@ function vs_utils.scan_host(scan_type, host, ports, scan_id)
ports = vs_utils.discover_open_ports(host)
end
vs_utils.set_status_scan(scan_type, host, ports, id, nil, vs_utils.scan_status.scanning)
local scan_module = vs_utils.load_module(scan_type)
local result,duration,scan_result,num_open_ports,num_vulnerabilities_found, cve, udp_ports, tcp_ports = scan_module:scan_host(host, ports)
@ -763,7 +766,7 @@ end
-- **********************************************************
-- Function to update single host status
function vs_utils.set_status_scan(scan_type, host, ports, id, is_periodicity)
function vs_utils.set_status_scan(scan_type, host, ports, id, is_periodicity, status)
local host_hash_key = vs_utils.get_host_hash_key(host, scan_type)
local host_hash_value_string = ntop.getHashCache(host_to_scan_key, host_hash_key)
@ -771,8 +774,10 @@ function vs_utils.set_status_scan(scan_type, host, ports, id, is_periodicity)
local host_hash_value = json.decode(host_hash_value_string)
host_hash_value.is_ok_last_scan = vs_utils.scan_status.in_progress
host_hash_value.is_periodicity = is_periodicity
host_hash_value.is_ok_last_scan = status
if (is_periodicity ~= nil) then
host_hash_value.is_periodicity = is_periodicity
end
ntop.setHashCache(host_to_scan_key, host_hash_key, json.encode(host_hash_value))
end
@ -784,7 +789,7 @@ end
function vs_utils.schedule_host_scan(scan_type, host, ports, scan_id, is_periodicity)
local scan = { scan_type = scan_type, host = host, ports = ports, id= scan_id}
vs_utils.set_status_scan(scan_type, host, ports, scan_id, is_periodicity)
vs_utils.set_status_scan(scan_type, host, ports, scan_id, is_periodicity, vs_utils.scan_status.scheduled)
ntop.rpushCache(host_scan_queue_key, json.encode(scan))