mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
[VS] Fix module scan result and rework scan periodic and scan all info.
This commit is contained in:
parent
b8b26ebd73
commit
e6580e79d1
7 changed files with 80 additions and 48 deletions
|
|
@ -48,11 +48,14 @@ local scanned_hosts_changes_key = "ntopng.alerts.scanned_hosts_changes
|
|||
local host_in_scanning_hash_key = "ntopng.prefs.host_to_scan.in_scanning"
|
||||
|
||||
-- redis keys for periodic scan info
|
||||
local host_periodic_scan_info = "ntopng.prefs.host_to_scan.periodicity_scan.info"
|
||||
local host_periodic_scan_cve_num_key = "ntopng.prefs.host_to_scan.periodicity_scan.info.cve_num"
|
||||
local host_periodic_scan_udp_ports_key = "ntopng.prefs.host_to_scan.periodicity_scan.info.udp_ports"
|
||||
local host_periodic_scan_tcp_ports_key = "ntopng.prefs.host_to_scan.periodicity_scan.info.tcp_ports"
|
||||
|
||||
-- redis keys for scan all info
|
||||
local host_scan_all_info = "ntopng.prefs.host_to_scan.scan_all.info"
|
||||
|
||||
local host_scan_all_cve_num_key = "ntopng.prefs.host_to_scan.scan_all.info.cve_num"
|
||||
local host_scan_all_udp_ports_key = "ntopng.prefs.host_to_scan.scan_all.info.udp_ports"
|
||||
local host_scan_all_tcp_ports_key = "ntopng.prefs.host_to_scan.scan_all.info.tcp_ports"
|
||||
|
|
@ -63,7 +66,7 @@ local recipients = require("recipients")
|
|||
local cve_utils = require("cve_utils")
|
||||
|
||||
local debug_print = false
|
||||
local debug_me = true
|
||||
local debug_me = false
|
||||
|
||||
local vs_utils = {}
|
||||
|
||||
|
|
@ -634,9 +637,9 @@ end
|
|||
local function get_counter_periodic_all_scan_keys(is_periodic)
|
||||
|
||||
if (is_periodic) then
|
||||
return host_periodic_scan_cve_num_key,host_periodic_scan_udp_ports_key,host_periodic_scan_tcp_ports_key
|
||||
return host_periodic_scan_info --host_periodic_scan_cve_num_key,host_periodic_scan_udp_ports_key,host_periodic_scan_tcp_ports_key
|
||||
else
|
||||
return host_scan_all_cve_num_key,host_scan_all_udp_ports_key,host_scan_all_tcp_ports_key
|
||||
return host_scan_all_info --host_scan_all_cve_num_key,host_scan_all_udp_ports_key,host_scan_all_tcp_ports_key
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -649,34 +652,48 @@ local function update_periodicity_or_all_scan_info(is_periodic, new_item)
|
|||
|
||||
|
||||
-- select correctly redis keys
|
||||
local cve_num_redis_key, udp_ports_redis_key, tcp_ports_redis_key = get_counter_periodic_all_scan_keys(is_periodic)
|
||||
local redis_info_key = get_counter_periodic_all_scan_keys(is_periodic)
|
||||
|
||||
local info_string = ntop.getCache(redis_info_key)
|
||||
local info_json = nil
|
||||
if (info_string ~= nil) then
|
||||
info_json = json.decode(info_string)
|
||||
end
|
||||
|
||||
|
||||
if (info_json == nil) then
|
||||
info_json = {}
|
||||
end
|
||||
|
||||
if (new_item.num_vulnerabilities_found ~= nil) then
|
||||
local cve_num_string = ntop.getCache(cve_num_redis_key)
|
||||
local old_saved_cve_num = tonumber(cve_num_string or 0)
|
||||
local new_cve_num = new_item.num_vulnerabilities_found + old_saved_cve_num
|
||||
if (new_cve_num ~= old_saved_cve_num) then
|
||||
ntop.setCache(cve_num_redis_key, tostring(new_cve_num))
|
||||
|
||||
if (info_json ~= {} and info_json.cves ~= nil) then
|
||||
info_json.cves = tonumber(info_json.cves) + new_item.num_vulnerabilities_found
|
||||
else
|
||||
info_json.cves = 0
|
||||
end
|
||||
end
|
||||
|
||||
if (new_item.udp_ports ~= nil) then
|
||||
local udp_ports_num_string = ntop.getCache(udp_ports_redis_key)
|
||||
local old_udp_ports_num = tonumber(udp_ports_num_string or 0)
|
||||
local new_udp_ports_num = old_udp_ports_num + new_item.udp_ports
|
||||
if (old_udp_ports_num ~= new_udp_ports_num) then
|
||||
ntop.setCache(udp_ports_redis_key, tostring(new_udp_ports_num))
|
||||
|
||||
if (info_json ~= {} and info_json.udp_ports ~= nil) then
|
||||
info_json.udp_ports = tonumber(info_json.udp_ports) + new_item.udp_ports
|
||||
else
|
||||
info_json.udp_ports = 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if (new_item.tcp_ports ~= nil) then
|
||||
local tcp_ports_num_string = ntop.getCache(tcp_ports_redis_key)
|
||||
local old_tcp_ports_num = tonumber(tcp_ports_num_string or 0)
|
||||
|
||||
local new_tcp_ports_num = old_tcp_ports_num + new_item.tcp_ports
|
||||
if (old_tcp_ports_num ~= new_tcp_ports_num) then
|
||||
ntop.setCache(tcp_ports_redis_key, tostring(new_tcp_ports_num))
|
||||
if (info_json ~= {} and info_json.tcp_ports ~= nil) then
|
||||
info_json.tcp_ports = tonumber(info_json.tcp_ports) + new_item.tcp_ports
|
||||
else
|
||||
info_json.tcp_ports = 0
|
||||
end
|
||||
end
|
||||
|
||||
ntop.setCache(redis_info_key, json.encode(info_json))
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -961,17 +978,23 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
|
|||
|
||||
local notification_message = ""
|
||||
|
||||
local cve_num_redis_key, udp_ports_redis_key, tcp_ports_redis_key = get_counter_periodic_all_scan_keys(is_periodic)
|
||||
local info_redis_key = get_counter_periodic_all_scan_keys(is_periodic)
|
||||
|
||||
|
||||
local cve_num_string = ntop.getCache(cve_num_redis_key)
|
||||
local cve_num = tonumber(cve_num_string) or 0
|
||||
|
||||
local udp_ports_string = ntop.getCache(udp_ports_redis_key)
|
||||
local udp_ports = tonumber(udp_ports_string) or 0
|
||||
|
||||
local tcp_ports_string = ntop.getCache(tcp_ports_redis_key)
|
||||
local tcp_ports = tonumber(tcp_ports_string) or 0
|
||||
local info_string = ntop.getCache(info_redis_key)
|
||||
|
||||
local info_json = nil
|
||||
if (info_string ~= nil) then
|
||||
info_json = json.decode(info_string) or {}
|
||||
else
|
||||
info_json = {
|
||||
cves = 0,
|
||||
udp_ports = 0,
|
||||
tcp_ports = 0
|
||||
}
|
||||
end
|
||||
local cve_num = tonumber(info_json.cves) or 0
|
||||
local udp_ports = tonumber(info_json.udp_ports) or 0
|
||||
local tcp_ports = tonumber(info_json.tcp_ports) or 0
|
||||
|
||||
local title = i18n("hosts_stats.page_scan_hosts.email.vulnerability_scan_report_title",{host = getHttpHost()})
|
||||
|
||||
|
|
@ -1005,9 +1028,11 @@ function vs_utils.notify_end_periodicity_or_all_scan(is_periodic, periodicity)
|
|||
|
||||
recipients.sendMessageByNotificationType({periodicity = periodicity, success=true, message = notification_message, title = title}, "vulnerability_scans")
|
||||
|
||||
ntop.setCache(cve_num_redis_key,"0")
|
||||
ntop.setCache(udp_ports_redis_key,"0")
|
||||
ntop.setCache(tcp_ports_redis_key,"0")
|
||||
ntop.setCache(info_redis_key,json.encode({
|
||||
cves = 0,
|
||||
udp_ports = 0,
|
||||
tcp_ports = 0
|
||||
}))
|
||||
|
||||
|
||||
|
||||
|
|
@ -1418,9 +1443,11 @@ function vs_utils.schedule_all_hosts_scan()
|
|||
ntop.setCache(host_to_scan_all_key , "1")
|
||||
end
|
||||
|
||||
ntop.setCache(host_scan_all_cve_num_key,"0")
|
||||
ntop.setCache(host_scan_all_udp_ports_key,"0")
|
||||
ntop.setCache(host_scan_all_tcp_ports_key,"0")
|
||||
ntop.setCache(host_scan_all_info,json.encode({
|
||||
cves = 0,
|
||||
udp_ports = 0,
|
||||
tcp_ports = 0
|
||||
}))
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
@ -1453,9 +1480,11 @@ function vs_utils.schedule_periodic_scan(periodicity)
|
|||
ntop.setCache(host_to_scan_periodicity_key.."type", periodicity)
|
||||
|
||||
|
||||
ntop.setCache(host_periodic_scan_cve_num_key , "0")
|
||||
ntop.setCache(host_periodic_scan_udp_ports_key , "0")
|
||||
ntop.setCache(host_periodic_scan_tcp_ports_key , "0")
|
||||
ntop.setCache(host_periodic_scan_info , json.encode({
|
||||
cves = 0,
|
||||
udp_ports = 0,
|
||||
tcp_ports = 0
|
||||
}))
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue