Reworked blacklists page

This commit is contained in:
Matteo Biscosi 2024-04-11 12:48:48 -04:00
parent cd425b384d
commit 0fecdee1e4
19 changed files with 829 additions and 21 deletions

View file

@ -0,0 +1,45 @@
--
-- (C) 2013-24 - ntop.org
--
-- trace_script_duration = true
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local json = require "dkjson"
local template = require "template_utils"
local page_utils = require("page_utils")
local page = _GET["page"] or 'overview'
local base_url = ntop.getHttpPrefix() .. "/lua/admin/blacklists.lua"
sendHTTPContentTypeHeader('text/html')
page_utils.print_header_and_set_active_menu_entry(page_utils.menu_entries.category_lists)
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
page_utils.print_navbar(i18n("category_lists.category_lists"), base_url .. "?", {{
active = page == "overview" or page == nil,
page_name = "overview",
label = "<i class=\"fas fa-lg fa-home\"></i>"
}, {
active = page == "charts",
page_name = "charts",
label = "<i class='fas fa-lg fa-chart-area' title='" .. i18n("historical") .. "'></i>"
}})
if page == "overview" or not page then
local json_context = json.encode({
csrf = ntop.getRandomCSRFValue()
})
template.render("pages/vue_page.template", {
vue_page_name = "PageBlacklists",
page_context = json_context
})
else
local graph_utils = require("graph_utils")
graph_utils.drawNewGraphs({
ifid = getSystemInterfaceId()
})
end
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")

View file

@ -49,6 +49,11 @@ if _POST["action"] == "edit" then
url = string.gsub(url, "http:__", "http://")
url = string.gsub(url, "https:__", "https://")
tprint(list_name)
tprint(enabled)
tprint(category)
tprint(url)
tprint(list_update)
lists_utils.editList(list_name, {
enabled = enabled,

View file

@ -825,7 +825,7 @@ else
i18n("details.label_system_ip") .. '\"></i></span>')
end
if (host["is_blacklisted"] == true) then
print(" <a href='"..ntop.getHttpPrefix().."/lua/admin/edit_category_lists.lua'><span class='badge bg-danger'>" .. i18n("details.label_blacklisted_host"))
print(" <a href='"..ntop.getHttpPrefix().."/lua/admin/blacklists.lua?enabled_status=enabled'><span class='badge bg-danger'>" .. i18n("details.label_blacklisted_host"))
if (host.blacklist_name ~= nil) then
print(' (' .. host.blacklist_name .. ')')

View file

@ -663,7 +663,7 @@ page_utils.add_menubar_section({
}, {
entry = page_utils.menu_entries.category_lists,
hidden = not is_admin,
url = '/lua/admin/edit_category_lists.lua'
url = '/lua/admin/blacklists.lua?enabled_status=enabled'
}, {
entry = page_utils.menu_entries.divider
}, {

View file

@ -39,7 +39,7 @@ function alert_list_download_failed:init(list_name, last_error)
self.alert_type_params = {
name = list_name,
err = last_error,
url = ntop.getHttpPrefix().."/lua/admin/edit_category_lists.lua"
url = ntop.getHttpPrefix().."/lua/admin/blacklists.lua?enabled_status=enabled"
}
end

View file

@ -243,6 +243,7 @@ end
-- NOTE: this function is called by the web pages in order to
-- set the active entry and section and highlight it into the menu
function page_utils.print_header_and_set_active_menu_entry(entry, i18n_params, alt_title)
require "locales_utils"
entry = entry or page_utils.menu_entries.traffic_dashboard
active_section = entry.section

View file

@ -159,20 +159,21 @@ local community_timeseries = {{
}
}, {
schema = "top:blacklist:hits",
chart_type = "line",
id = timeseries_id.blacklist,
label = i18n('graphs.metric_labels.top_blacklist_hits'),
priority = 0,
type = "top",
draw_stacked = true,
priority = 2,
measure_unit = "hitss",
scale = i18n('graphs.metric_labels.blacklist_hits'),
draw_stacked = true,
chart_type = "line",
timeseries = {
hits = {
use_serie_name = true,
label = i18n('graphs.metric_labels.blacklist_num_hits'),
color = timeseries_info.get_timeseries_color('')
}
}
},
default_visible = true
}, {
schema = "iface:new_flows",
id = timeseries_id.iface,
@ -2111,17 +2112,8 @@ local function add_top_blacklist_hits_timeseries(tags, timeseries)
end
for _, serie in pairs(series or {}) do
tmp_tags.blacklist_name = serie.blacklist_name
local tot = 0
local tot_serie = ts_utils.queryTotal("blacklist:hits", tags.epoch_begin, tags.epoch_end, tmp_tags)
for _, value in pairs(tot_serie or {}) do
tot = tot + tonumber(value)
end
-- Uncomment to return only timeseries with values
-- if tot <= 0 then
-- return
-- end
timeseries[#timeseries + 1] = {
schema = "top:blacklist:hits",
schema = "blacklist:hits",
id = timeseries_id.blacklist,
group = i18n("graphs.metric_labels.blacklist_num_hits"),
priority = 0,
@ -2134,7 +2126,6 @@ local function add_top_blacklist_hits_timeseries(tags, timeseries)
hits = {
use_serie_name = true,
label = i18n('graphs.metric_labels.blacklist_num_hits'),
color = timeseries_info.get_timeseries_color('')
}
}
}

View file

@ -0,0 +1,39 @@
--
-- (C) 2013-24 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "ntop_utils"
require "http_lint"
local rest_utils = require "rest_utils"
local lists_utils = require "lists_utils"
local enabled = _POST["list_enabled"]
local list_name = _POST["list_name"]
local category = tonumber(_POST["category"])
local url = _POST["url"]
local list_update = tonumber(_POST["list_update"])
if enabled == "on" then
enabled = true
else
enabled = false
end
if isEmptyString(enabled) or isEmptyString(list_name) or isEmptyString(category) or isEmptyString(url) or
isEmptyString(list_update) then
rest_utils.answer(rest_utils.consts.err.bad_content)
return
end
url = string.gsub(url, "http:__", "http://")
url = string.gsub(url, "https:__", "https://")
lists_utils.editList(list_name, {
enabled = enabled,
category = nil,
url = url,
update_interval = list_update
})
rest_utils.answer(rest_utils.consts.success.ok)

View file

@ -88,6 +88,13 @@ local rsp = {}
local flows_stats = interface.getFlowsInfo(flows_filter["hostFilter"], flows_filter, flows_filter["talkingWith"],
flows_filter["client"], flows_filter["server"], flows_filter["flow_info"])
if not flows_stats then
rest_utils.extended_answer(rest_utils.consts.success.ok, {}, {
["recordsTotal"] = 0
})
return
end
for _, value in ipairs(flows_stats.flows) do
local record = {}
local key = value["ntopng.key"]

View file

@ -0,0 +1,63 @@
--
-- (C) 2013-24 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "ntop_utils"
require "lua_utils_get"
local rest_utils = require "rest_utils"
local lists_utils = require "lists_utils"
local rsp = {}
local category_filter = _GET["category"]
local enabled_status = _GET["enabled_status"]
local lists = lists_utils.getCategoryLists()
-- ################################################
local function getListStatusLabel(list)
if not list.enabled then
return "disabled"
end
if list.status.last_error then
return "error"
end
return "enabled"
end
-- ################################################
for list_name, list in pairs(lists) do
local catname = interface.getnDPICategoryName(tonumber(list.category))
if ((not isEmptyString(category_filter)) and (category_filter ~= catname)) then
goto continue
end
if enabled_status == "disabled" and list.enabled then
goto continue
elseif enabled_status == "enabled" and not list.enabled then
goto continue
end
rsp[#rsp + 1] = {
name = list_name,
status = getListStatusLabel(list),
category = getCategoryLabel(catname, list.category),
update_frequency = list.update_interval,
last_update = list.status.last_update,
entries = list.status.num_hosts,
hits = list.status.num_hits.current,
url = list.url,
category_id = list.category
}
::continue::
end
rest_utils.extended_answer(rest_utils.consts.success.ok, rsp, {
["recordsTotal"] = 0
})

View file

@ -0,0 +1,61 @@
--
-- (C) 2013-24 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils_get"
local rest_utils = require "rest_utils"
local lists_utils = require "lists_utils"
local rsp = {}
local lists = lists_utils.getCategoryLists()
local list = {{
key = "enabled_status",
value = "enabled",
label = i18n("category_lists.enabled")
}, {
key = "enabled_status",
value = "disabled",
label = i18n("disabled")
}, {
key = "enabled_status",
value = "all",
label = i18n("all")
}}
rsp[#rsp + 1] = {
action = "enabled_status",
label = i18n("status"),
name = "enabled_status",
value = list
}
list = {{
key = "category",
value = "",
label = i18n("all")
}}
local category_list = {}
for list_name, list in pairsByKeys(lists) do
local catname = interface.getnDPICategoryName(tonumber(list.category))
local category = getCategoryLabel(catname, list.category)
category_list[category] = (category_list[category] or 0) + 1
end
for category, _ in pairs(category_list) do
list[#list + 1] = {
key = "category",
value = category,
label = category
}
end
rsp[#rsp + 1] = {
action = "category",
label = i18n("category"),
name = "category",
value = list
}
rest_utils.answer(rest_utils.consts.success.ok, rsp)

View file

@ -0,0 +1,18 @@
--
-- (C) 2013-24 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "ntop_utils"
local rest_utils = require "rest_utils"
local lists_utils = require "lists_utils"
local list_name = _GET["list_name"]
if isEmptyString(list_name) then
rest_utils.answer(rest_utils.consts.err.bad_content)
return
end
lists_utils.updateList(list_name)
rest_utils.answer(rest_utils.consts.success.ok)