mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-02 17:00:10 +00:00
parent
4a28134e82
commit
fff6d90f10
7 changed files with 406 additions and 202 deletions
|
|
@ -1,94 +1,53 @@
|
|||
--
|
||||
-- (C) 2021 - ntop.org
|
||||
-- (C) 2021-26 - ntop.org
|
||||
--
|
||||
|
||||
-- TODO: reset custom callback
|
||||
-- TODO: /scripts/lua/module/checks/templates
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
local page_utils = require("page_utils")
|
||||
local ui_utils = require("ui_utils")
|
||||
local template = require("template_utils")
|
||||
local json = require("dkjson")
|
||||
local checks = require("checks")
|
||||
local rest_utils = require "rest_utils"
|
||||
local auth = require "auth"
|
||||
local checks_utils = require("checks_utils")
|
||||
local alert_severities = require("alert_severities")
|
||||
require "lua_utils"
|
||||
|
||||
local function format_exclusion_list_filters(filters)
|
||||
|
||||
local formatted = {}
|
||||
|
||||
for _, filter in ipairs(filters.current_filters) do
|
||||
for key, filter_value in pairs(filter) do
|
||||
formatted[#formatted+1] = key .. "=" .. filter_value
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(formatted, '\n')
|
||||
end
|
||||
local page_utils = require "page_utils"
|
||||
local json = require "dkjson"
|
||||
local template_utils = require "template_utils"
|
||||
local auth = require "auth"
|
||||
|
||||
if not auth.has_capability(auth.capabilities.checks) then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
return
|
||||
end
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
return
|
||||
end
|
||||
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
page_utils.print_header_and_set_active_menu_entry(page_utils.menu_entries.scripts_config)
|
||||
|
||||
-- append the menu above the page
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
|
||||
|
||||
local check_subdir = _GET["subdir"]
|
||||
local script_key = _GET["script_key"]
|
||||
local check_subdir = _GET["subdir"] or "flow"
|
||||
local script_key = _GET["script_key"] or ""
|
||||
|
||||
local configset = checks.getConfigset()
|
||||
local script_type = checks.getScriptType(check_subdir)
|
||||
local selected_script = checks.loadModule(getSystemInterfaceId(), script_type, check_subdir, script_key)
|
||||
local script_title = i18n(selected_script.gui.i18n_title) or selected_script.gui.i18n_title
|
||||
page_utils.print_navbar(i18n("edit_check.hooks_config"), ntop.getHttpPrefix() .. "/lua/admin/edit_check.lua", {
|
||||
{
|
||||
active = true,
|
||||
page_name = "edit",
|
||||
label = i18n("edit_check.hooks_config"),
|
||||
},
|
||||
})
|
||||
|
||||
local confset_name = configset.name
|
||||
local titles = checks_utils.load_configset_titles()
|
||||
|
||||
local hooks_config = checks.getScriptConfig(configset, selected_script, check_subdir)
|
||||
local generated_templates = selected_script.template:render(hooks_config)
|
||||
|
||||
local generated_breadcrumb = ui_utils.render_breadcrumb(i18n("about.checks"), {
|
||||
{
|
||||
label = titles[check_subdir],
|
||||
},
|
||||
{
|
||||
href = ntop.getHttpPrefix() .. "/lua/admin/edit_configset.lua?subdir=" .. check_subdir,
|
||||
label = i18n("scripts_list.config", {}) .. " " .. confset_name
|
||||
},
|
||||
{
|
||||
active = true,
|
||||
label = script_title
|
||||
}
|
||||
|
||||
}, "fab fa-superpowers")
|
||||
|
||||
local base_context = {
|
||||
info = ntop.getInfo(),
|
||||
json = json,
|
||||
edit_check = {
|
||||
breadcrumb = generated_breadcrumb,
|
||||
script = selected_script,
|
||||
alert_severities = alert_severities,
|
||||
script_title = script_title,
|
||||
rendered_hooks = generated_templates,
|
||||
|
||||
hooks_config = hooks_config,
|
||||
check_subdir = check_subdir,
|
||||
script_key = script_key,
|
||||
filters = format_exclusion_list_filters(checks.getDefaultFilters(interface.getId(), check_subdir, script_key))
|
||||
}
|
||||
local context = {
|
||||
check_subdir = check_subdir,
|
||||
script_key = script_key,
|
||||
page_csrf = ntop.getRandomCSRFValue(),
|
||||
ifid = interface.getId(),
|
||||
back_url = ntop.getHttpPrefix() .. "/lua/admin/edit_configset.lua?subdir=" .. check_subdir,
|
||||
}
|
||||
|
||||
print(template.gen("pages/edit_check.template", base_context))
|
||||
template_utils.render("pages/vue_page.template", {
|
||||
vue_page_name = "PageEditCheck",
|
||||
page_context = json.encode(context),
|
||||
})
|
||||
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|
||||
|
|
|
|||
|
|
@ -7,154 +7,67 @@ package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
|||
|
||||
require "lua_utils"
|
||||
|
||||
local ts_utils = require("ts_utils")
|
||||
local info = ntop.getInfo()
|
||||
local page_utils = require("page_utils")
|
||||
local format_utils = require("format_utils")
|
||||
local os_utils = require "os_utils"
|
||||
local template = require "template_utils"
|
||||
local checks = require "checks"
|
||||
local json = require "dkjson"
|
||||
local discover = require "discover_utils"
|
||||
local rest_utils = require "rest_utils"
|
||||
local auth = require "auth"
|
||||
local checks_utils = require("checks_utils")
|
||||
local page_utils = require "page_utils"
|
||||
local json = require "dkjson"
|
||||
local template_utils = require "template_utils"
|
||||
local rest_utils = require "rest_utils"
|
||||
local auth = require "auth"
|
||||
local checks_utils = require "checks_utils"
|
||||
|
||||
if not auth.has_capability(auth.capabilities.checks) then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
return
|
||||
end
|
||||
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
-- get config parameters like the id and name
|
||||
local check_subdir = _GET["subdir"]
|
||||
local script_filter = _GET["check"]
|
||||
local search_filter = _GET["search_script"]
|
||||
local ifid = _GET["ifid"]
|
||||
|
||||
local configset = checks.getConfigset()
|
||||
|
||||
if not isAdministratorOrPrintErr() or not configset then
|
||||
return
|
||||
end
|
||||
|
||||
-- create a table that holds localization about hooks name
|
||||
local titles = checks_utils.load_configset_titles()
|
||||
local check_subdir = _GET["subdir"] or "flow"
|
||||
|
||||
local sub_menu_entries = {
|
||||
['all'] = {
|
||||
order = 0,
|
||||
entry = page_utils.menu_entries.scripts_config_all
|
||||
},
|
||||
['host'] = {
|
||||
order = 1,
|
||||
entry = page_utils.menu_entries.scripts_config_hosts
|
||||
},
|
||||
['interface'] = {
|
||||
order = 2,
|
||||
entry = page_utils.menu_entries.scripts_config_interfaces
|
||||
},
|
||||
['network'] = {
|
||||
order = 3,
|
||||
entry = page_utils.menu_entries.scripts_config_networks
|
||||
},
|
||||
['snmp_device'] = {
|
||||
order = 4,
|
||||
entry = page_utils.menu_entries.scripts_config_snmp_devices
|
||||
},
|
||||
['flow'] = {
|
||||
order = 5,
|
||||
entry = page_utils.menu_entries.scripts_config_flows
|
||||
},
|
||||
['system'] = {
|
||||
order = 6,
|
||||
entry = page_utils.menu_entries.scripts_config_system
|
||||
},
|
||||
['active_monitoring'] = {
|
||||
order = 7,
|
||||
entry = page_utils.menu_entries.scripts_config_active_monitoring
|
||||
},
|
||||
['syslog'] = {
|
||||
order = 8,
|
||||
entry = page_utils.menu_entries.scripts_config_syslog
|
||||
},
|
||||
['as'] = {
|
||||
order = 9,
|
||||
entry = page_utils.menu_entries.scripts_config_as
|
||||
},
|
||||
['all'] = { order = 0, entry = page_utils.menu_entries.scripts_config_all },
|
||||
['host'] = { order = 1, entry = page_utils.menu_entries.scripts_config_hosts },
|
||||
['interface'] = { order = 2, entry = page_utils.menu_entries.scripts_config_interfaces },
|
||||
['network'] = { order = 3, entry = page_utils.menu_entries.scripts_config_networks },
|
||||
['snmp_device'] = { order = 4, entry = page_utils.menu_entries.scripts_config_snmp_devices },
|
||||
['flow'] = { order = 5, entry = page_utils.menu_entries.scripts_config_flows },
|
||||
['system'] = { order = 6, entry = page_utils.menu_entries.scripts_config_system },
|
||||
['active_monitoring']= { order = 7, entry = page_utils.menu_entries.scripts_config_active_monitoring },
|
||||
['syslog'] = { order = 8, entry = page_utils.menu_entries.scripts_config_syslog },
|
||||
['as'] = { order = 9, entry = page_utils.menu_entries.scripts_config_as },
|
||||
}
|
||||
local active_entry = sub_menu_entries[check_subdir].entry or page_utils.menu_entries.scripts_config
|
||||
|
||||
local active_entry = (sub_menu_entries[check_subdir] and sub_menu_entries[check_subdir].entry)
|
||||
or page_utils.menu_entries.scripts_config
|
||||
page_utils.print_header_and_set_active_menu_entry(active_entry)
|
||||
--page_utils.print_header(i18n("scripts_list.scripts_x", { subdir=titles[check_subdir], config=confset_name }))
|
||||
|
||||
-- append the menu above the page
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
|
||||
|
||||
-- APP/Categories types
|
||||
|
||||
-- Initialize apps_and_categories
|
||||
-- Check out generate_multi_select in scripts-list-utils.js for the format
|
||||
local cat_groups = {label = i18n("categories"), elements = {}}
|
||||
local app_groups = {label = i18n("applications"), elements = {}}
|
||||
local elems = {}
|
||||
|
||||
for cat, _ in pairsByKeys(interface.getnDPICategories(), asc_insensitive) do
|
||||
cat_groups.elements[#cat_groups.elements + 1] = {cat, getCategoryLabel(cat)}
|
||||
end
|
||||
|
||||
for app, _ in pairsByKeys(interface.getnDPIProtocols(), asc_insensitive) do
|
||||
app_groups.elements[#app_groups.elements + 1] = {app, app}
|
||||
end
|
||||
|
||||
apps_and_categories = {cat_groups, app_groups}
|
||||
|
||||
-- Device types
|
||||
|
||||
local device_types = {}
|
||||
|
||||
for type_id in discover.sortedDeviceTypeLabels() do
|
||||
local label = discover.devtype2string(type_id)
|
||||
local devtype = discover.id2devtype(type_id)
|
||||
|
||||
device_types[#device_types + 1] = {devtype, label}
|
||||
end
|
||||
|
||||
local device_types_list = {{elements = device_types}}
|
||||
|
||||
local url = ntop.getHttpPrefix() .. "/lua/admin/edit_configset.lua"
|
||||
local navbar_menu = {}
|
||||
for key, sub_menu in pairsByField(sub_menu_entries, 'order', asc) do
|
||||
navbar_menu[#navbar_menu+1] = {
|
||||
active = (check_subdir == key),
|
||||
navbar_menu[#navbar_menu + 1] = {
|
||||
active = (check_subdir == key),
|
||||
page_name = key,
|
||||
label = i18n(sub_menu.entry.i18n_title),
|
||||
url = url .. "?subdir="..key
|
||||
}
|
||||
label = i18n(sub_menu.entry.i18n_title),
|
||||
url = url .. "?subdir=" .. key,
|
||||
}
|
||||
end
|
||||
|
||||
page_utils.print_navbar(i18n("internals.checks"), '#', navbar_menu)
|
||||
page_utils.print_navbar(i18n("internals.checks"), url, navbar_menu)
|
||||
|
||||
local context = {
|
||||
script_list = {
|
||||
subdir = check_subdir,
|
||||
template_utils = template,
|
||||
hooks_localizated = titles,
|
||||
check_subdir = check_subdir,
|
||||
script_filter = script_filter,
|
||||
search_filter = search_filter,
|
||||
page_url = ntop.getHttpPrefix() .. string.format("/lua/admin/edit_configset.lua?subdir=%s", check_subdir),
|
||||
apps_and_categories = json.encode(apps_and_categories),
|
||||
device_types = json.encode(device_types_list),
|
||||
},
|
||||
check_categories = checks.check_categories,
|
||||
info = ntop.getInfo(),
|
||||
json = json,
|
||||
ifid = ifid or interface.getId()
|
||||
check_subdir = check_subdir,
|
||||
page_csrf = ntop.getRandomCSRFValue(),
|
||||
ifid = interface.getId(),
|
||||
}
|
||||
|
||||
-- print config_list.html template
|
||||
template.render("pages/edit_configset.template", context)
|
||||
template_utils.render("pages/vue_page.template", {
|
||||
vue_page_name = "PageEditConfigset",
|
||||
page_context = json.encode(context),
|
||||
})
|
||||
|
||||
-- append the menu below the page
|
||||
dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue