mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
Added aliases REST API (#8053)
This commit is contained in:
parent
309e025c59
commit
2336ea1762
7 changed files with 1227 additions and 896 deletions
34
scripts/lua/rest/v2/set/device/alias.lua
Normal file
34
scripts/lua/rest/v2/set/device/alias.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
--
|
||||
-- (C) 2013-23 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
--
|
||||
-- Set host alias
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"device" : "FF:FF:FF:FF:FF:FF", "custom_name" : "Mario"}' http://localhost:3000/lua/rest/v2/set/device/alias.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
if isEmptyString(_POST["device"]) or isEmptyString(_POST["custom_name"]) then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
local device = url2hostinfo(_POST)["host"]
|
||||
local custom_name = _POST["custom_name"]
|
||||
|
||||
setHostAltName(device, custom_name)
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok)
|
||||
|
||||
38
scripts/lua/rest/v2/set/interface/alias.lua
Normal file
38
scripts/lua/rest/v2/set/interface/alias.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
--
|
||||
-- (C) 2013-23 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
--
|
||||
-- Set host alias
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid" : "9", "custom_name" : "Mario's Interface"}' http://localhost:3000/lua/rest/v2/set/interface/alias.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
if isEmptyString(_POST["ifid"]) or isEmptyString(_POST["custom_name"]) then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
local interface = _POST["ifid"]
|
||||
local custom_name = _POST["custom_name"]
|
||||
|
||||
local res = setInterfaceAlias(interface, custom_name)
|
||||
|
||||
if res then
|
||||
rest_utils.answer(rest_utils.consts.success.ok)
|
||||
else
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
end
|
||||
|
||||
34
scripts/lua/rest/v2/set/network/alias.lua
Normal file
34
scripts/lua/rest/v2/set/network/alias.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
--
|
||||
-- (C) 2013-23 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
--
|
||||
-- Set host alias
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"network_cidr" : "192.168.2.0/24", "custom_name" : "Mario's Network"}' http://localhost:3000/lua/rest/v2/set/network/alias.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
if isEmptyString(_POST["network_cidr"]) or isEmptyString(_POST["custom_name"]) then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
local network = _POST["network_cidr"]
|
||||
local custom_name = _POST["custom_name"]
|
||||
|
||||
setLocalNetworkAlias(network, custom_name)
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue