Added listening ports frontend

This commit is contained in:
MatteoBiscosi 2022-06-21 10:39:34 +02:00
parent a5cec61280
commit 20f7a4ed59
4 changed files with 121 additions and 1 deletions

View 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)