summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-upnp/luasrc/controller/upnp.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2017-11-10 13:06:10 +0100
committerGitHub <noreply@github.com>2017-11-10 13:06:10 +0100
commitb2274e5d6d27cdd0819d9e35058ebcd2cb8b55f5 (patch)
treef7d9aef2fe1ec73c86e68b61887c8d4752924882 /applications/luci-app-upnp/luasrc/controller/upnp.lua
parent37f4a3b90c56fea8d06833092ce6a5e2e2c2d1d1 (diff)
parentdd0b5cfd16eaea51b3653a91a1e136898d685849 (diff)
Merge pull request #980 from NvrBst/pull-request-upnp_description
luci-app-upnp: Adding and displaying "Description" to upnp data
Diffstat (limited to 'applications/luci-app-upnp/luasrc/controller/upnp.lua')
-rw-r--r--applications/luci-app-upnp/luasrc/controller/upnp.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/applications/luci-app-upnp/luasrc/controller/upnp.lua b/applications/luci-app-upnp/luasrc/controller/upnp.lua
index c60b7c4969..e485708f0e 100644
--- a/applications/luci-app-upnp/luasrc/controller/upnp.lua
+++ b/applications/luci-app-upnp/luasrc/controller/upnp.lua
@@ -19,8 +19,12 @@ function index()
end
function act_status()
+ local uci = luci.model.uci.cursor()
+ local lease_file = uci:get("upnpd", "config", "upnp_lease_file")
+
local ipt = io.popen("iptables --line-numbers -t nat -xnvL MINIUPNPD 2>/dev/null")
if ipt then
+ local upnpf = lease_file and io.open(lease_file, "r")
local fwd = { }
while true do
local ln = ipt:read("*l")
@@ -29,23 +33,32 @@ function act_status()
elseif ln:match("^%d+") then
local num, proto, extport, intaddr, intport =
ln:match("^(%d+).-([a-z]+).-dpt:(%d+) to:(%S-):(%d+)")
+ local descr = ""
if num and proto and extport and intaddr and intport then
num = tonumber(num)
extport = tonumber(extport)
intport = tonumber(intport)
+
+ if upnpf then
+ local uln = upnpf:read("*l")
+ if uln then descr = uln:match(string.format("^%s:%d:%s:%d:%%d*:(.*)$", proto:upper(), extport, intaddr, intport)) end
+ if not descr then descr = "" end
+ end
fwd[#fwd+1] = {
num = num,
proto = proto:upper(),
extport = extport,
intaddr = intaddr,
- intport = intport
+ intport = intport,
+ descr = descr
}
end
end
end
+ if upnpf then upnpf:close() end
ipt:close()
luci.http.prepare_content("application/json")