-- -- (C) 2013-20 - ntop.org -- local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path package.path = dirs.installdir .. "/scripts/lua/pro/modules/?.lua;" .. package.path package.path = dirs.installdir .. "/scripts/lua/pro/?.lua;" .. package.path package.path = dirs.installdir .. "/pro/scripts/callbacks/?.lua;" .. package.path require "lua_utils" local template = require "template_utils" local os_utils = require "os_utils" local page_utils = require("page_utils") sendHTTPContentTypeHeader('text/html') page_utils.set_active_menu_entry(page_utils.menu_entries.profiles) dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") local ntop_info = ntop.getInfo() local max_profiles_num = ntop_info["constants.max_num_profiles"] print [[
]] hashname = "ntopng.prefs.profiles" function forEachRedisCounter(ifid, callback) local key = "ntopng.profiles_counters.ifid_"..ifid local counters = ntop.getHashKeysCache(key) if counters ~= nil then for profile,_ in pairs(counters) do if not callback(profile) then ntop.delHashCache(key, profile) end end end end function forEachRRDCounter(ifid, callback) local base = os_utils.fixPath(dirs.workingdir .. "/" .. ifid .. '/profilestats') for profile, _ in pairs(ntop.readdir(base)) do if not callback(profile) then ntop.rmdir(base.."/"..profile) end end end if _POST["delete_profile"] ~= nil then -- delete a single profile ntop.delHashCache(hashname, _POST["delete_profile"]) -- delete the associated counter forEachRedisCounter(ifId, function(profile) if profile == _POST["delete_profile"] then -- remove return false else return true end end) -- delete the associated RRDs forEachRRDCounter(ifId, function(profile) if profile == _POST["delete_profile"] then -- remove return false else return true end end) ntop.reloadProfiles() elseif _POST["edit_profiles"] ~= nil then local config = paramsPairsDecode(_POST, true) -- delete unused counters forEachRedisCounter(ifId, function(profile) if config[profile] == nil then -- remove return false else return true end end) -- delete unused RRDs forEachRRDCounter(ifId, function(profile) if config[profile] == nil then -- remove return false else return true end end) -- Delete existing profiles ntop.delCache(hashname) local num = 0 for profile, filter in pairs(config) do if http_lint.validateTrafficProfile(profile) and ntop.checkProfileSyntax(filter) then ntop.setHashCache(hashname, profile, filter) num = num + 1 end if num >= max_profiles_num then break end end ntop.reloadProfiles() end print( template.gen("modal_confirm_dialog.html", { dialog={ id = "delete_profile_dialog", action = "deleteProfile(delete_profile_name)", title = i18n("traffic_profiles.delete_profile"), message = i18n("traffic_profiles.confirm_delete_profile") .. ' "" ', confirm = i18n("delete"), } }) ) print [[

]] print(i18n("traffic_profiles.simple_filter_examples")) print[[: ]] print(i18n("traffic_profiles.advanced_filter_examples")) print[[: ]] print(i18n("traffic_profiles.note")) print[[: ]] dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")