mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
Added listening ports frontend
This commit is contained in:
parent
a5cec61280
commit
20f7a4ed59
4 changed files with 121 additions and 1 deletions
45
scripts/lua/rest/v2/get/host/processes/listening_ports.lua
Normal file
45
scripts/lua/rest/v2/get/host/processes/listening_ports.lua
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
--
|
||||
-- (C) 2013-22 - 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")
|
||||
|
||||
--
|
||||
-- Retrieves all ntopng interfaces of a given host
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"host" : "192.168.1.1"}' http://localhost:3000/lua/rest/v1/get/host/interfaces.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
local rc = rest_utils.consts.success.ok
|
||||
local res = {}
|
||||
local ip = _GET["host"] or ""
|
||||
local vlan = _GET["vlan"] or ""
|
||||
|
||||
if isEmptyString(ip) and isEmptyString(vlan) then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
local host = interface.getHostInfo(ip, vlan)
|
||||
|
||||
for listening_type, data in pairs(host.listening_ports or {}) do
|
||||
local process = {}
|
||||
|
||||
for port, process_info in pairs(data) do
|
||||
process["tcp_udp"] = listening_type
|
||||
process["port"] = port
|
||||
process["package"] = process_info["package"]
|
||||
process["process"] = process_info["process"]
|
||||
end
|
||||
|
||||
if table.len(process) > 0 then
|
||||
res[#res + 1] = process
|
||||
end
|
||||
end
|
||||
|
||||
rest_utils.answer(rc, res)
|
||||
Loading…
Add table
Add a link
Reference in a new issue