mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 07:29:32 +00:00
Add optional script_subdir parameter to toggle all user scripts in toggle_all_user_scripts.lua
This commit is contained in:
parent
f68555ee35
commit
f5532815f4
3 changed files with 30 additions and 21 deletions
|
|
@ -12,9 +12,9 @@ local alert_consts = require("alert_consts")
|
|||
|
||||
sendHTTPContentTypeHeader('application/json')
|
||||
|
||||
local subdir = _POST["script_subdir"]
|
||||
local confset_id = tonumber(_POST["confset_id"] or user_scripts.DEFAULT_CONFIGSET_ID)
|
||||
local action = _POST["action"]
|
||||
local subdir = _POST["script_subdir"] -- optional (all subdirs if not specified)
|
||||
local confset_id = tonumber(_POST["confset_id"] or user_scripts.DEFAULT_CONFIGSET_ID) -- optional (default config if not specified)
|
||||
local action = _POST["action"] -- enable/disable
|
||||
|
||||
if(not isAdministrator()) then
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, "Admin privileges required")
|
||||
|
|
@ -28,30 +28,41 @@ if(action == nil) then
|
|||
return
|
||||
end
|
||||
|
||||
local subdirs = {}
|
||||
if(subdir == nil) then
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, "Missing 'script_subdir' parameter")
|
||||
return
|
||||
end
|
||||
|
||||
local script_type = user_scripts.getScriptType(subdir)
|
||||
|
||||
if(script_type == nil) then
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, "Bad subdir: " .. subdir)
|
||||
return
|
||||
local all_subdirs = user_scripts.listSubdirs()
|
||||
for _, subdir in ipairs(all_subdirs) do
|
||||
subdirs[#subdirs+1] = subdir.id
|
||||
end
|
||||
else
|
||||
subdirs[#subdirs+1] = subdir
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
local result = {}
|
||||
local success
|
||||
|
||||
local success, err = user_scripts.toggleAllScripts(confset_id, subdir, (action == "enable"))
|
||||
for _, subdir in ipairs(subdirs) do
|
||||
|
||||
result.success = success
|
||||
local script_type = user_scripts.getScriptType(subdir)
|
||||
|
||||
if not success then
|
||||
result.error = err
|
||||
if(script_type == nil) then
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, "Bad subdir: " .. subdir)
|
||||
return
|
||||
end
|
||||
|
||||
local succ, err = user_scripts.toggleAllScripts(confset_id, subdir, (action == "enable"))
|
||||
|
||||
if not succ then
|
||||
result.error = err
|
||||
end
|
||||
end
|
||||
|
||||
if not result.error then
|
||||
result.success = true
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
print(json.encode(result))
|
||||
print(json.encode(result))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue