mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
Reworked blacklists page
This commit is contained in:
parent
cd425b384d
commit
0fecdee1e4
19 changed files with 829 additions and 21 deletions
39
scripts/lua/rest/v2/edit/system/edit_blacklist.lua
Normal file
39
scripts/lua/rest/v2/edit/system/edit_blacklist.lua
Normal 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)
|
||||
|
|
@ -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"]
|
||||
|
|
|
|||
63
scripts/lua/rest/v2/get/system/blacklists/blacklists.lua
Normal file
63
scripts/lua/rest/v2/get/system/blacklists/blacklists.lua
Normal 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
|
||||
})
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue