ntopng/scripts/lua/vulnerability_scan.lua

149 lines
5.3 KiB
Lua

--
-- (C) 2013-23 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
package.path = dirs.installdir .. "/scripts/lua/modules/vulnerability_scan/?.lua;" .. package.path
if(ntop.isPro()) then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
end
require "lua_utils"
local page_utils = require("page_utils")
local template = require("template_utils")
local graph_utils = require("graph_utils")
local json = require("dkjson")
local page = _GET["page"]
local auth = require "auth"
if not isAllowedSystemInterface() then return end
sendHTTPContentTypeHeader('text/html')
page_utils.print_header_and_set_active_menu_entry(page_utils.menu_entries.vulnerability_scan)
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
local base_url = ntop.getHttpPrefix() .. "/lua/vulnerability_scan.lua"
local charts_available = areHostTimeseriesEnabled(ifId, nil)
local host_result = _GET["host"]
local ifid = _GET["ifid"]
if (isEmptyString(ifid) or ifid == nil) then
ifid = interface.getId()
end
page_utils.print_navbar(i18n("scan_hosts"), base_url .. "?", {{
active = page == "overview" or page == nil,
page_name = "overview",
label = "<i class=\"fas fa-lg fa-home\"></i>"
},{
hidden = not areAlertsEnabled() or not auth.has_capability(auth.capabilities.alerts),
active = page == "alerts",
page_name = "alerts",
label = "<i class='fas fa-lg fa-exclamation-triangle' title='" .. i18n("alerts_dashboard.alerts") .. "'></i>",
url = ntop.getHttpPrefix() .."/lua/alert_stats.lua?page=am_host&alert_id=4184%3Beq&is_va=true"
}, {
hidden = not ntop.isPro(),--not charts_available or page == "overview" or page == nil,
active = page == "va_historical",
page_name = "va_historical",
--url = ntop.getHttpPrefix() .."/lua/vulnerability_scan.lua?page=historical&timeseries_groups_mode=1_chart_x_metric&timeseries_groups=am_vuln_scan%3Anum_open_ports%3Dtrue%3Afalse%3Afalse%3Afalse%3Anum_configured_hosts%3Dtrue%3Afalse%3Afalse%3Afalse%3Anum_scans%3Dtrue%3Afalse%3Afalse%3Afalse%3Anum_cve%3Dtrue%3Afalse%3Afalse%3Afalse",
label = "<i class='fas fa-lg fa-chart-area' title='" .. i18n("historical") .. "'></i>"
}, {
active = page == "open_ports",
hidden = not ntop.isEnterpriseL(), -- disable the entry when the user is in the overview page
page_name = "open_ports",
label = i18n('hosts_stats.page_scan_hosts.num_open_ports')
},
{
active = page == "show_result",
hidden = page ~= "show_result", -- disable the entry when the user is in the overview page
page_name = "show_result",
label = i18n('scan_details')
},{
active = page == "report",
page_name = "report",
hidden = not ntop.isEnterpriseL(),
url = ntop.getHttpPrefix() .."/lua/vulnerability_scan.lua?page=report&report_template=vs_result&ifid="..ifid,
label = i18n('hosts_stats.page_scan_hosts.download_page')
}})
local page = _GET["page"] or ('overview')
local ifid = interface.getId()
local scan_type = _GET["scan_type"]
local scan_date = _GET["scan_date"]
-- #######################################################
if (page == "scan_hosts" or page == "overview") then
local json_context = {
csrf = ntop.getRandomCSRFValue(),
ifid = ifid,
is_enterprise_l = ntop.isEnterpriseL(),
host = host_result
}
template.render("pages/vue_page.template", { vue_page_name = "PageHostsToScan", page_context = json.encode(json_context) })
elseif (page == "show_result") then
local json_context = {
csrf = ntop.getRandomCSRFValue(),
ifid = ifid,
host = host_result,
scan_type = scan_type,
date = scan_date
}
template.render("pages/vue_page.template", { vue_page_name = "PageHostVsResult", page_context = json.encode(json_context) })
elseif (page == "add_notification_rec") then
local json_context = {
csrf = ntop.getRandomCSRFValue(),
ifid = ifid,
host = host_result
}
template.render("pages/vue_page.template", { vue_page_name = "PageHostsVARecipient", page_context = json.encode(json_context) })
elseif (page == "open_ports") then
local json_context = {
csrf = ntop.getRandomCSRFValue(),
ifid = ifid,
is_enterprise_l = ntop.isEnterpriseL()
}
template.render("pages/vue_page.template", { vue_page_name = "PageOpenPorts", page_context = json.encode(json_context) })
elseif (page == "va_historical") then
local source_value_object = {
ifid = ifid,
is_va = true
--host = host_result
}
graph_utils.drawNewGraphs(source_value_object)
elseif (page == "report") then
local context = {
ifid = ifid,
page = "vs-report",
title = "Last Scan Report",
template = "vs_result",
printable = true,
csrf = ntop.getRandomCSRFValue(),
template_endpoint = ntop.getHttpPrefix() .. "/lua/pro/rest/v2/get/report/template/data.lua",
template_list_endpoint = ntop.getHttpPrefix() .. "/lua/pro/rest/v2/get/report/template/list.lua"
}
local json_context = json.encode(context)
template.render("pages/vue_page.template", { vue_page_name = "Dashboard", page_context = json_context })
end
-- #######################################################
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")