-- -- (C) 2013-18 - ntop.org -- dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path package.path = dirs.installdir .. "/scripts/lua/pro/modules/?.lua;" .. package.path require "lua_utils" require "graph_utils" local template = require "template_utils" local host_pools_utils = require "host_pools_utils" local template = require "template_utils" local presets_utils = require "presets_utils" local discover = require "discover_utils" -- Administrator check if not isAdministrator() then return end local page = _GET["page"] or "" local policy_filter = _GET["policy_filter"] or "" local proto_filter = _GET["l7proto"] or "" local device_type = _GET["device_type"] or "0" -- unknown by default local category = _GET["category"] or "" local is_nedge = ntop.isnEdge() interface.select(ifname) presets_utils.init() local base_url = "" if is_nedge then base_url = "/lua/pro/nedge/admin/nf_edit_user.lua" else base_url = "/lua/admin/edit_device_protocols.lua" end -- ################################################################### local page_params = {} local filter_msg = "" page_params["page"] = page if not isEmptyString(policy_filter) then page_params["policy_filter"] = policy_filter local action = presets_utils.actionIDToAction(policy_filter) filter_msg = action.text end if not isEmptyString(category) then page_params["category"] = category filter_msg = filter_msg.." "..category end if not isEmptyString(proto_filter) then page_params["l7proto"] = proto_filter end if not isEmptyString(device_type) then page_params["device_type"] = device_type end -- ################################################################### function editDeviceProtocols() local reload = false for k,v in pairs(_POST) do if starts(k, "client_policy_") then local proto = split(k, "client_policy_")[2] local action_id = v presets_utils.updateDeviceProto(device_type, "client", proto, action_id) reload = true end if starts(k, "server_policy_") then local proto = split(k, "server_policy_")[2] local action_id = v presets_utils.updateDeviceProto(device_type, "server", proto, action_id) reload = true end end if reload then presets_utils.reloadDevicePolicies(device_type) end end -- ################################################################### local function printDevicePolicyLegenda() print[[
]] end -- ################################################################### local function printDeviceProtocolsPage() local form_id = "device-protocols-form" local table_id = "device-protocols-table" print[[

]] if is_nedge then local pool_name = host_pools_utils.DEFAULT_POOL_NAME print(i18n("nedge.user_device_protocols", {user=pool_name})) else print(i18n("device_protocols.filter_device_protocols", {filter=filter_msg})) end print[[

]] -- Active protocol filter if not isEmptyString(proto_filter) then local proto_name = interface.getnDPIProtoName(tonumber(proto_filter)) local proto_filter_params = table.clone(page_params) proto_filter_params.device_type = device_type proto_filter_params.l7proto = nil print[[]] end print[[
]] -- Device type selector print(i18n("details.device_type")) print(':
]] for k,v in pairs(proto_filter_params) do print[[]] end print[[
]] -- Remove policy filter on search local after_search_params = table.clone(page_params) after_search_params.device_type = device_type after_search_params.l7proto = nil after_search_params.policy_filter = nil after_search_params.category = nil -- Protocol search form print( template.gen("typeahead_input.html", { typeahead={ base_id = "t_app", action = base_url, parameters = after_search_params, json_key = "key", query_field = "l7proto", query_url = ntop.getHttpPrefix() .. "/lua/find_app.lua?skip_critical=true", query_title = i18n("nedge.search_protocols"), style = "margin-left:1em; width:25em;", } }) ) print[[
]] print( template.gen("modal_confirm_dialog.html", { dialog={ id = "presetsResetDefaults", action = "presetsResetDefaults()", title = i18n("users.reset_to_defaults"), message = i18n("users.reset_to_defaults_confirm", {devtype=""}), confirm = i18n("reset") } }) ) if is_nedge and (ntop.getPref("ntopng.prefs.device_protocols_policing") ~= "1") then print([[
]]..i18n("warning")..[[: ]].. i18n("nedge.device_protocols_blocked_warning", { device_protocols_policies = ''.. i18n("nedge.enable_device_protocols_policies") .. '', }) ..[[

]]) end -- Table form print[[

]] print[[ ]] print[[ ]] end -- ################################################################### if _POST["edit_device_policy"] ~= nil then editDeviceProtocols() elseif (_POST["action"] == "reset") and (_POST["device_type"] ~= nil) then local device_type = tonumber(_POST["device_type"]) presets_utils.resetDevicePoliciesFromPresets(device_type) presets_utils.reloadDevicePolicies(device_type) end printDeviceProtocolsPage()