1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
5 module("luci.controller.upnp", package.seeall)
8 if not nixio.fs.access("/etc/config/upnpd") then
14 page = entry({"admin", "services", "upnp"}, cbi("upnp/upnp"), _("UPNP"))
17 entry({"admin", "services", "upnp", "status"}, call("act_status")).leaf = true
18 entry({"admin", "services", "upnp", "delete"}, call("act_delete")).leaf = true
22 local ipt = io.popen("iptables --line-numbers -t nat -xnvL MINIUPNPD")
26 local ln = ipt:read("*l")
29 elseif ln:match("^%d+") then
30 local num, proto, extport, intaddr, intport =
31 ln:match("^(%d+).-([a-z]+).-dpt:(%d+) to:(%S-):(%d+)")
33 if num and proto and extport and intaddr and intport then
35 extport = tonumber(extport)
36 intport = tonumber(intport)
40 proto = proto:upper(),
51 luci.http.prepare_content("application/json")
52 luci.http.write_json(fwd)
56 function act_delete(num)
57 local idx = tonumber(num)
58 local uci = luci.model.uci.cursor()
60 if idx and idx > 0 then
61 luci.sys.call("iptables -t filter -D MINIUPNPD %d 2>/dev/null" % idx)
62 luci.sys.call("iptables -t nat -D MINIUPNPD %d 2>/dev/null" % idx)
64 local lease_file = uci:get("upnpd", "config", "upnp_lease_file")
65 if lease_file and nixio.fs.access(lease_file) then
66 luci.sys.call("sed -i -e '%dd' %q" %{ idx, lease_file })
69 luci.http.status(200, "OK")
73 luci.http.status(400, "Bad request")