From b8f810092b585e0e21e6c6a2e6a6e8e27b335b66 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 7 Nov 2010 19:30:55 +0000 Subject: [PATCH] applications/luci-upnp: enable/disable service, live status, allow removing single forwards --- applications/luci-upnp/luasrc/controller/upnp.lua | 64 +++++++++++++++-- applications/luci-upnp/luasrc/view/upnp_status.htm | 84 ++++++++++++++++++++++ 2 files changed, 142 insertions(+), 6 deletions(-) create mode 100644 applications/luci-upnp/luasrc/view/upnp_status.htm diff --git a/applications/luci-upnp/luasrc/controller/upnp.lua b/applications/luci-upnp/luasrc/controller/upnp.lua index fd3175553..fe9d3d8f5 100644 --- a/applications/luci-upnp/luasrc/controller/upnp.lua +++ b/applications/luci-upnp/luasrc/controller/upnp.lua @@ -18,13 +18,65 @@ function index() if not nixio.fs.access("/etc/config/upnpd") then return end - - local page = entry({"admin", "services", "upnp"}, cbi("upnp/upnp"), "UPNP") + + local page + + page = entry({"admin", "services", "upnp"}, cbi("upnp/upnp"), "UPNP") page.i18n = "upnp" page.dependent = true - - - local page = entry({"mini", "network", "upnp"}, cbi("upnp/upnpmini", {autoapply=true}), "UPNP") + + page = entry({"mini", "network", "upnp"}, cbi("upnp/upnpmini", {autoapply=true}), "UPNP") page.i18n = "upnp" page.dependent = true -end \ No newline at end of file + + entry({"admin", "services", "upnp", "status"}, call("act_status")).leaf = true + entry({"admin", "services", "upnp", "delete"}, call("act_delete")).leaf = true +end + +function act_status() + local ipt = io.popen("iptables --line-numbers -t nat -xnvL MINIUPNPD") + if ipt then + local fwd = { } + while true do + local ln = ipt:read("*l") + if not ln then + break + elseif ln:match("^%d+") then + local num, proto, extport, intaddr, intport = + ln:match("^(%d+).-([a-z]+).-dpt:(%d+) to:(%S-):(%d+)") + + if num and proto and extport and intaddr and intport then + num = tonumber(num) + extport = tonumber(extport) + intport = tonumber(intport) + + fwd[#fwd+1] = { + num = num, + proto = proto:upper(), + extport = extport, + intaddr = intaddr, + intport = intport + } + end + end + end + + ipt:close() + + luci.http.prepare_content("application/json") + luci.http.write_json(fwd) + end +end + +function act_delete() + local path = luci.dispatcher.context.requestpath + local idx = tonumber(path[#path]) + + if idx and idx > 0 then + luci.sys.call("iptables -t filter -D MINIUPNPD %d 2>/dev/null" % idx) + luci.sys.call("iptables -t nat -D MINIUPNPD %d 2>/dev/null" % idx) + return + end + + luci.http.status(400, "Bad request") +end diff --git a/applications/luci-upnp/luasrc/view/upnp_status.htm b/applications/luci-upnp/luasrc/view/upnp_status.htm new file mode 100644 index 000000000..ed1632b0a --- /dev/null +++ b/applications/luci-upnp/luasrc/view/upnp_status.htm @@ -0,0 +1,84 @@ + + +
+ <%:Active UPnP Redirects%> + + + + + + + + + + + +
<%:Protocol%><%:External Port%><%:Client Address%><%:Client Port%> 

<%:Collecting data...%>
+
-- 2.11.0