add recipient for endpoint notifications

This commit is contained in:
gabryon99 2020-05-07 18:30:27 +02:00
parent 78a6f4f8d4
commit db9f3ecc03
10 changed files with 449 additions and 2 deletions

View file

@ -0,0 +1,43 @@
--
-- (C) 2019-20 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local json = require("dkjson")
local plugins_utils = require "plugins_utils"
local notification_recipients = require("notification_recipients")
local action = _POST["action"]
local function reportError(msg)
print(json.encode({ message = msg, success = false }))
end
sendHTTPContentTypeHeader('application/json')
if (action == nil) then
traceError(TRACE_ERROR, TRACE_CONSOLE, "Missing 'action' parameter. Bad CSRF?")
reportError("Missing 'action' parameter. Bad CSRF?")
return
end
local response = {}
local recipient_name = _POST["recipient_name"]
if (action == "add") then
local endpoint_conf_name = _POST["endpoint_conf_name"]
response.result = notification_recipients.add_recipient(endpoint_conf_name, recipient_name, _POST)
elseif (action == "edit") then
response.result = notification_recipients.edit_recipient(recipient_name, _POST)
elseif (action == "remove") then
response.result = notification_recipients.delete_recipient(recipient_name)
else
traceError(TRACE_ERROR, TRACE_CONSOLE, "Invalid 'action' parameter.")
response.success = false
response.message = "Invalid 'action' parameter."
end
print(json.encode(response))