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"))
27 entry({"admin", "services", "upnp", "status"}, call("act_status")).leaf = true
28 entry({"admin", "services", "upnp", "delete"}, call("act_delete")).leaf = true
32 local ipt = io.popen("iptables --line-numbers -t nat -xnvL MINIUPNPD")
36 local ln = ipt:read("*l")
39 elseif ln:match("^%d+") then
40 local num, proto, extport, intaddr, intport =
41 ln:match("^(%d+).-([a-z]+).-dpt:(%d+) to:(%S-):(%d+)")
43 if num and proto and extport and intaddr and intport then
45 extport = tonumber(extport)
46 intport = tonumber(intport)
50 proto = proto:upper(),
61 luci.http.prepare_content("application/json")
62 luci.http.write_json(fwd)
66 function act_delete(num)
67 local idx = tonumber(num)
68 local uci = luci.model.uci.cursor()
70 if idx and idx > 0 then
71 luci.sys.call("iptables -t filter -D MINIUPNPD %d 2>/dev/null" % idx)
72 luci.sys.call("iptables -t nat -D MINIUPNPD %d 2>/dev/null" % idx)
74 local lease_file = uci:get("upnpd", "config", "upnp_lease_file")
75 if lease_file and nixio.fs.access(lease_file) then
76 luci.sys.call("sed -i -e '%dd' %q" %{ idx, lease_file })
79 luci.http.status(200, "OK")
83 luci.http.status(400, "Bad request")