2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
16 module("luci.controller.upnp", package.seeall)
19 if not nixio.fs.access("/etc/config/upnpd") then
25 page = entry({"admin", "services", "upnp"}, cbi("upnp/upnp"), _("UPNP"))
29 page = entry({"mini", "network", "upnp"}, cbi("upnp/upnpmini", {autoapply=true}), _("UPNP"))
33 entry({"admin", "services", "upnp", "status"}, call("act_status")).leaf = true
34 entry({"admin", "services", "upnp", "delete"}, call("act_delete")).leaf = true
38 local ipt = io.popen("iptables --line-numbers -t nat -xnvL MINIUPNPD")
42 local ln = ipt:read("*l")
45 elseif ln:match("^%d+") then
46 local num, proto, extport, intaddr, intport =
47 ln:match("^(%d+).-([a-z]+).-dpt:(%d+) to:(%S-):(%d+)")
49 if num and proto and extport and intaddr and intport then
51 extport = tonumber(extport)
52 intport = tonumber(intport)
56 proto = proto:upper(),
67 luci.http.prepare_content("application/json")
68 luci.http.write_json(fwd)
72 function act_delete(idx)
74 if idx and idx > 0 then
75 luci.sys.call("iptables -t filter -D MINIUPNPD %d 2>/dev/null" % idx)
76 luci.sys.call("iptables -t nat -D MINIUPNPD %d 2>/dev/null" % idx)
80 luci.http.status(400, "Bad request")