X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-app-upnp%2Fluasrc%2Fcontroller%2Fupnp.lua;fp=applications%2Fluci-app-upnp%2Fluasrc%2Fcontroller%2Fupnp.lua;h=e485708f0ec0c97658b2d33986c0161d9599b22f;hp=c60b7c4969a6ce76c70d07deb0750c2622900ca7;hb=dd0b5cfd16eaea51b3653a91a1e136898d685849;hpb=f5461669afa4aba943ecc5800d9a468fb0ce1cd0 diff --git a/applications/luci-app-upnp/luasrc/controller/upnp.lua b/applications/luci-app-upnp/luasrc/controller/upnp.lua index c60b7c496..e485708f0 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")