mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 07:59:35 +00:00
Split configsets in multiple sections, based on the subdir
This commit is contained in:
parent
61ddcd9730
commit
17f86d162b
5 changed files with 76 additions and 109 deletions
|
|
@ -30,7 +30,7 @@ user_scripts.field_units = {
|
|||
local CALLBACKS_DIR = plugins_utils.PLUGINS_RUNTIME_PATH .. "/callbacks"
|
||||
local NON_TRAFFIC_ELEMENT_CONF_KEY = "all"
|
||||
local NON_TRAFFIC_ELEMENT_ENTITY = "no_entity"
|
||||
local CONFIGSETS_KEY = "ntopng.prefs.user_scripts.configsets"
|
||||
local CONFIGSETS_KEY = "ntopng.prefs.user_scripts.configsets.%s"
|
||||
user_scripts.DEFAULT_CONFIGSET_ID = 0
|
||||
|
||||
-- Hook points for flow/periodic modules
|
||||
|
|
@ -984,15 +984,21 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
local function saveConfigsets(configsets)
|
||||
local rv = json.encode(configsets)
|
||||
ntop.setPref(CONFIGSETS_KEY, rv)
|
||||
local function getConfigsetsKey(subdir)
|
||||
return(string.format(CONFIGSETS_KEY, subdir))
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function user_scripts.getConfigsets()
|
||||
local configsets = ntop.getPref(CONFIGSETS_KEY) or ""
|
||||
local function saveConfigsets(subdir, configsets)
|
||||
local rv = json.encode(configsets)
|
||||
ntop.setPref(getConfigsetsKey(subdir), rv)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function user_scripts.getConfigsets(subdir)
|
||||
local configsets = ntop.getPref(getConfigsetsKey(subdir)) or ""
|
||||
local rv = {}
|
||||
|
||||
configsets = json.decode(configsets) or {}
|
||||
|
|
@ -1007,57 +1013,29 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Creates a new configset.
|
||||
-- @params name the unique config set name
|
||||
-- @returns a tuple <configset, errmsg>. If configset is nil, errmsg
|
||||
-- will contain a localized error describing the problem.
|
||||
function user_scripts.newConfigset(name)
|
||||
local configsets = user_scripts.getConfigsets()
|
||||
local existing = findConfigSet(configsets, name)
|
||||
|
||||
if existing then
|
||||
return nil, i18n("configsets.error_exists", {name=name})
|
||||
end
|
||||
|
||||
local confid = getNewConfigSetId(configsets)
|
||||
|
||||
local newconfset = {
|
||||
id = confid,
|
||||
name = name,
|
||||
config = {},
|
||||
}
|
||||
|
||||
configsets[confid] = newconfset
|
||||
saveConfigsets(configsets)
|
||||
|
||||
return newconfset
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function user_scripts.deleteConfigset(confid)
|
||||
function user_scripts.deleteConfigset(subdir, confid)
|
||||
confid = tonumber(confid)
|
||||
|
||||
if(confid == user_scripts.DEFAULT_CONFIGSET_ID) then
|
||||
return false, "Cannot delete default configset"
|
||||
end
|
||||
|
||||
local configsets = user_scripts.getConfigsets()
|
||||
local configsets = user_scripts.getConfigsets(subdir)
|
||||
|
||||
if(configsets[confid] == nil) then
|
||||
return false, i18n("configsets.unknown_id", {confid=confid})
|
||||
end
|
||||
|
||||
configsets[confid] = nil
|
||||
saveConfigsets(configsets)
|
||||
saveConfigsets(subdir, configsets)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function user_scripts.renameConfigset(confid, new_name)
|
||||
local configsets = user_scripts.getConfigsets()
|
||||
function user_scripts.renameConfigset(subdir, confid, new_name)
|
||||
local configsets = user_scripts.getConfigsets(subdir)
|
||||
|
||||
if(configsets[confid] == nil) then
|
||||
return false, i18n("configsets.unknown_id", {confid=confid})
|
||||
|
|
@ -1070,15 +1048,15 @@ function user_scripts.renameConfigset(confid, new_name)
|
|||
end
|
||||
|
||||
configsets[confid].name = new_name
|
||||
saveConfigsets(configsets)
|
||||
saveConfigsets(subdir, configsets)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function user_scripts.cloneConfigset(confid, new_name)
|
||||
local configsets = user_scripts.getConfigsets()
|
||||
function user_scripts.cloneConfigset(subdir, confid, new_name)
|
||||
local configsets = user_scripts.getConfigsets(subdir)
|
||||
|
||||
if(configsets[confid] == nil) then
|
||||
return false, i18n("configsets.unknown_id", {confid=confid})
|
||||
|
|
@ -1096,7 +1074,7 @@ function user_scripts.cloneConfigset(confid, new_name)
|
|||
configsets[new_confid].id = new_confid
|
||||
configsets[new_confid].name = new_name
|
||||
|
||||
saveConfigsets(configsets)
|
||||
saveConfigsets(subdir, configsets)
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
@ -1104,7 +1082,7 @@ end
|
|||
-- ##############################################
|
||||
|
||||
function user_scripts.updateScriptConfig(confid, script_key, subdir, new_config)
|
||||
local configsets = user_scripts.getConfigsets()
|
||||
local configsets = user_scripts.getConfigsets(subdir)
|
||||
|
||||
if(configsets[confid] == nil) then
|
||||
return false, i18n("configsets.unknown_id", {confid=confid})
|
||||
|
|
@ -1115,7 +1093,7 @@ function user_scripts.updateScriptConfig(confid, script_key, subdir, new_config)
|
|||
config[subdir] = config[subdir] or {}
|
||||
config[subdir][script_key] = new_config
|
||||
|
||||
saveConfigsets(configsets)
|
||||
saveConfigsets(subdir, configsets)
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
@ -1123,12 +1101,13 @@ end
|
|||
-- ##############################################
|
||||
|
||||
function user_scripts.loadDefaultConfig()
|
||||
local configsets = user_scripts.getConfigsets()
|
||||
local ifid = getSystemInterfaceId()
|
||||
local default_conf = configsets[user_scripts.DEFAULT_CONFIGSET_ID] or {}
|
||||
|
||||
for type_id, script_type in pairs(user_scripts.script_types) do
|
||||
for _, subdir in pairs(script_type.subdirs) do
|
||||
local configsets = user_scripts.getConfigsets()
|
||||
local default_conf = configsets[user_scripts.DEFAULT_CONFIGSET_ID] or {}
|
||||
|
||||
local scripts = user_scripts.load(ifid, script_type, subdir, {return_all = true})
|
||||
default_conf[subdir] = default_conf[subdir] or {}
|
||||
|
||||
|
|
@ -1148,16 +1127,16 @@ function user_scripts.loadDefaultConfig()
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
configsets[user_scripts.DEFAULT_CONFIGSET_ID] = {
|
||||
id = user_scripts.DEFAULT_CONFIGSET_ID,
|
||||
name = i18n("policy_presets.default"),
|
||||
config = default_conf,
|
||||
}
|
||||
|
||||
saveConfigsets(subdir, configsets)
|
||||
end
|
||||
end
|
||||
|
||||
configsets[user_scripts.DEFAULT_CONFIGSET_ID] = {
|
||||
id = user_scripts.DEFAULT_CONFIGSET_ID,
|
||||
name = i18n("policy_presets.default"),
|
||||
config = default_conf,
|
||||
}
|
||||
|
||||
saveConfigsets(configsets)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue