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
15 module("luci.controller.upnp", package.seeall)
18 if not nixio.fs.access("/etc/config/upnpd") then
24 page = entry({"admin", "services", "upnp"}, cbi("upnp/upnp"), "UPNP")
28 page = entry({"mini", "network", "upnp"}, cbi("upnp/upnpmini", {autoapply=true}), "UPNP")
32 entry({"admin", "services", "upnp", "status"}, call("act_status")).leaf = true
33 entry({"admin", "services", "upnp", "delete"}, call("act_delete")).leaf = true
37 local ipt = io.popen("iptables --line-numbers -t nat -xnvL MINIUPNPD")
41 local ln = ipt:read("*l")
44 elseif ln:match("^%d+") then
45 local num, proto, extport, intaddr, intport =
46 ln:match("^(%d+).-([a-z]+).-dpt:(%d+) to:(%S-):(%d+)")
48 if num and proto and extport and intaddr and intport then
50 extport = tonumber(extport)
51 intport = tonumber(intport)
55 proto = proto:upper(),
66 luci.http.prepare_content("application/json")
67 luci.http.write_json(fwd)
72 local path = luci.dispatcher.context.requestpath
73 local idx = tonumber(path[#path])
75 if idx and idx > 0 then
76 luci.sys.call("iptables -t filter -D MINIUPNPD %d 2>/dev/null" % idx)
77 luci.sys.call("iptables -t nat -D MINIUPNPD %d 2>/dev/null" % idx)
81 luci.http.status(400, "Bad request")