X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-app-upnp%2Fluasrc%2Fcontroller%2Fupnp.lua;h=95a0ef4862a7cd1157e028fd89062da9e575ef65;hp=83fa94154bd01ef3998e819630896c9b198490ab;hb=c0d9c4f3c;hpb=1bb4822dca6113f73e3bc89e2acf15935e6f8e92 diff --git a/applications/luci-app-upnp/luasrc/controller/upnp.lua b/applications/luci-app-upnp/luasrc/controller/upnp.lua index 83fa94154..95a0ef486 100644 --- a/applications/luci-app-upnp/luasrc/controller/upnp.lua +++ b/applications/luci-app-upnp/luasrc/controller/upnp.lua @@ -1,16 +1,6 @@ ---[[ -LuCI - Lua Configuration Interface - -Copyright 2008 Steven Barth -Copyright 2008 Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -]]-- +-- Copyright 2008 Steven Barth +-- Copyright 2008 Jo-Philipp Wich +-- Licensed to the public under the Apache License 2.0. module("luci.controller.upnp", package.seeall) @@ -21,16 +11,20 @@ function index() local page - page = entry({"admin", "services", "upnp"}, cbi("upnp/upnp"), _("UPNP")) + page = entry({"admin", "services", "upnp"}, cbi("upnp/upnp"), _("UPnP")) page.dependent = true entry({"admin", "services", "upnp", "status"}, call("act_status")).leaf = true - entry({"admin", "services", "upnp", "delete"}, call("act_delete")).leaf = true + entry({"admin", "services", "upnp", "delete"}, post("act_delete")).leaf = true end function act_status() - local ipt = io.popen("iptables --line-numbers -t nat -xnvL MINIUPNPD") + 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") @@ -39,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") @@ -73,7 +76,7 @@ function act_delete(num) local lease_file = uci:get("upnpd", "config", "upnp_lease_file") if lease_file and nixio.fs.access(lease_file) then - luci.sys.call("sed -i -e '%dd' %q" %{ idx, lease_file }) + luci.sys.call("sed -i -e '%dd' %s" %{ idx, luci.util.shellquote(lease_file) }) end luci.http.status(200, "OK")