--
-- (C) 2017-18 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
require "graph_utils"
local template = require "template_utils"
local proto_filter = _GET["l7proto"]
local category_filter = _GET["category"]
local ifId = getInterfaceId(ifname)
if not haveAdminPrivileges() then
return
end
local base_url = ntop.getHttpPrefix() .. "/lua/admin/edit_categories.lua"
local page_params = {
l7proto = proto_filter,
category = category_filter,
tab = "protocols"
}
local catid = nil
if not isEmptyString(category_filter) then
catid = split(category_filter, "cat_")[2]
end
if not table.empty(_POST) then
local custom_categories = getCustomnDPIProtoCategories(ifname)
for k, new_cat in pairs(_POST) do
if starts(k, "proto_") then
local id = split(k, "proto_")[2]
local old_cat
new_cat = tonumber(split(new_cat, "cat_")[2])
-- get the current category
if custom_categories[id] ~= nil then
old_cat = custom_categories[id]
else
old_cat = interface.getnDPIProtoCategory(tonumber(id))
old_cat = old_cat and old_cat.id or 0
end
if old_cat ~= new_cat then
-- io.write("Changing nDPI category for " .. id .. ": " .. old_cat .. " -> " .. new_cat .. "\n")
setCustomnDPIProtoCategory(ifname, tonumber(id), new_cat)
end
end
end
end
print [[
]]
if catid ~= nil then
print(""..i18n("users.cat_protocols", {cat=interface.getnDPICategoryName(tonumber(catid))}).."") end print[[ | ]]
if not isEmptyString(proto_filter) then
local proto_name = interface.getnDPIProtoName(tonumber(proto_filter))
print[[]] end print[[ | ]] print( template.gen("typeahead_input.html", { typeahead={ base_id = "t_app", action = base_url, parameters = { ifid = tostring(ifId), category = category_filter, tab = "protocols" }, json_key = "key", query_field = "l7proto", query_url = ntop.getHttpPrefix() .. "/lua/find_app.lua", query_title = i18n("categories_page.search_application"), style = "margin-left:1em; width:25em;", } }) ) print[[ |