-- -- (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[[
| ]] -- Device type selector print(i18n("details.device_type")) 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[[ | ]] -- 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[[ |