[VS] Improve email report and fix spaces and sort on networks issues.

This commit is contained in:
Nicolo Maio 2023-12-18 16:08:36 +01:00
parent 2b45e59f6f
commit 2ae78f5b27
2 changed files with 39 additions and 6 deletions

View file

@ -843,7 +843,15 @@ local function update_scan_info_for_report(type_of_scan_execution, new_item, hos
info_json.net_scanned = {}
end
info_json.net_scanned[new_item.host] = new_item.discovered_hosts
if (info_json.net_scanned_no_hosts_found == nil) then
info_json.net_scanned_no_hosts_found = {}
end
if (new_item.discovered_hosts_num == 0) then
info_json.net_scanned_no_hosts_found[new_item.host] = true
else
info_json.net_scanned[new_item.host] = new_item.discovered_hosts
end
end
end
@ -1159,7 +1167,8 @@ function vs_utils.save_host_to_scan(scan_type, host, scan_result, last_scan_time
discovered_hosts_comma_list_string = table.concat(discovered_hosts,",")
end
new_item.discovered_hosts = discovered_hosts_comma_list_string
new_item.discovered_hosts_num = table.len(discovered_hosts) or 0
if tcp_ports ~= nil then
new_item.tcp_ports = tcp_ports.num_ports
new_item.tcp_ports_list = tcp_ports.ports
@ -1456,7 +1465,8 @@ local function retrieve_email_info(exec_type)
has_discrepancy = ((info_json.new_open_ports or 0) > 0) or ((info_json.num_cve_solved or 0) > 0),
hosts_down_list = info_json.hosts_down_list,
hosts_was_down_list = info_json.hosts_was_down_list,
scanned_networks = info_json.net_scanned or {}
scanned_networks = info_json.net_scanned or {},
scanned_networks_no_hosts_found = info_json.net_scanned_no_hosts_found or {}
}
if (email_info.has_discrepancy) then
@ -1690,13 +1700,34 @@ function vs_utils.notify_scan_results(exec_type, periodicity)
})
end
local net_scan_without_hosts_discovered = ""
if (email_info.scanned_networks_no_hosts_found ~= nil and next(email_info.scanned_networks_no_hosts_found)) then
if (add_new_configured_hosts_br) then
net_scan_without_hosts_discovered = net_scan_without_hosts_discovered .. "<br>"
end
add_new_configured_hosts_br = false
local net_scan_list = ""
for net, v in pairsByKeys(email_info.scanned_networks_no_hosts_found, asc) do
net_scan_list = net_scan_list .. i18n("hosts_stats.page_scan_hosts.email.host_down_item", {host_id = net.."/24"})
end
local no_discovered_hosts_list = i18n("hosts_stats.page_scan_hosts.email.host_down_list", {host_down_items = net_scan_list})
net_scan_without_hosts_discovered = i18n("hosts_stats.page_scan_hosts.email.no_new_hosts_detected", {subnets = no_discovered_hosts_list})
end
local discovered_hosts_list = ""
local discovered_hosts = false
if email_info.scanned_networks ~= nil and next(email_info.scanned_networks) then
-- hosts not configured but discovered by the netscan
discovered_hosts = true
for net in pairs(email_info.scanned_networks) do
if (add_new_configured_hosts_br) then
discovered_hosts_list = discovered_hosts_list .. "<br>"
end
for net, v in pairsByKeys(email_info.scanned_networks, asc) do
local hosts_string = email_info.scanned_networks[net]
local net_scan = net.."/24"
@ -1722,7 +1753,7 @@ function vs_utils.notify_scan_results(exec_type, periodicity)
net_scan = net_scan,
num_hosts = num_hosts,
host_list = discovered_formatted_hosts_list,
add_br = ternary(add_new_configured_hosts_br ,"<br>","")
add_br = ""
})
end
end
@ -1732,7 +1763,7 @@ function vs_utils.notify_scan_results(exec_type, periodicity)
possible_discrepancies_info = i18n("hosts_stats.page_scan_hosts.email.no_discrepancy")
end
notification_message = notification_message .. possible_discrepancies_info .. no_longer_down_now .. discovered_hosts_list
notification_message = notification_message .. possible_discrepancies_info .. no_longer_down_now .. net_scan_without_hosts_discovered .. discovered_hosts_list
local report_link_line = i18n("hosts_stats.page_scan_hosts.email.report_link_line",
{url = string.format(getHttpHost() .. ntop.getHttpPrefix() .. "/lua/enterprise/vulnerability_scan_report.lua?epoch_end=%u&epoch_begin=%u",