summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-upnp/luasrc
diff options
context:
space:
mode:
Diffstat (limited to 'applications/luci-app-upnp/luasrc')
-rw-r--r--applications/luci-app-upnp/luasrc/controller/upnp.lua29
-rw-r--r--applications/luci-app-upnp/luasrc/model/cbi/upnp/upnp.lua17
-rw-r--r--applications/luci-app-upnp/luasrc/view/upnp_status.htm75
3 files changed, 68 insertions, 53 deletions
diff --git a/applications/luci-app-upnp/luasrc/controller/upnp.lua b/applications/luci-app-upnp/luasrc/controller/upnp.lua
index c60b7c4969..c4762434c5 100644
--- a/applications/luci-app-upnp/luasrc/controller/upnp.lua
+++ b/applications/luci-app-upnp/luasrc/controller/upnp.lua
@@ -19,8 +19,14 @@ function index()
end
function act_status()
+ local uci = luci.model.uci.cursor()
+ local lease_file = uci:get("upnpd", "config", "upnp_lease_file")
+
+ local ipv4_hints = luci.sys.net.ipv4_hints()
+
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")
@@ -29,23 +35,42 @@ 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
+
+ local host_hint, _, e
+
+ for _,e in pairs(ipv4_hints) do
+ if e[1] == intaddr then
+ host_hint = e[2]
+ break
+ end
+ end
+
fwd[#fwd+1] = {
num = num,
proto = proto:upper(),
extport = extport,
intaddr = intaddr,
- intport = intport
+ host_hint = host_hint,
+ intport = intport,
+ descr = descr
}
end
end
end
+ if upnpf then upnpf:close() end
ipt:close()
luci.http.prepare_content("application/json")
@@ -63,7 +88,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")
diff --git a/applications/luci-app-upnp/luasrc/model/cbi/upnp/upnp.lua b/applications/luci-app-upnp/luasrc/model/cbi/upnp/upnp.lua
index f1bb450dd5..a2023926e0 100644
--- a/applications/luci-app-upnp/luasrc/model/cbi/upnp/upnp.lua
+++ b/applications/luci-app-upnp/luasrc/model/cbi/upnp/upnp.lua
@@ -12,21 +12,21 @@ s.addremove = false
s:tab("general", translate("General Settings"))
s:tab("advanced", translate("Advanced Settings"))
-e = s:taboption("general", Flag, "_init", translate("Start UPnP and NAT-PMP service"))
+e = s:taboption("general", Flag, "enabled", translate("Start UPnP and NAT-PMP service"))
e.rmempty = false
-function e.cfgvalue(self, section)
- return luci.sys.init.enabled("miniupnpd") and self.enabled or self.disabled
-end
+--function e.cfgvalue(self, section)
+-- return luci.sys.init.enabled("miniupnpd") and self.enabled or self.disabled
+--end
function e.write(self, section, value)
if value == "1" then
- luci.sys.call("/etc/init.d/miniupnpd enable >/dev/null")
luci.sys.call("/etc/init.d/miniupnpd start >/dev/null")
else
luci.sys.call("/etc/init.d/miniupnpd stop >/dev/null")
- luci.sys.call("/etc/init.d/miniupnpd disable >/dev/null")
end
+
+ return Flag.write(self, section, value)
end
s:taboption("general", Flag, "enable_upnp", translate("Enable UPnP functionality")).default = "1"
@@ -35,6 +35,9 @@ s:taboption("general", Flag, "enable_natpmp", translate("Enable NAT-PMP function
s:taboption("general", Flag, "secure_mode", translate("Enable secure mode"),
translate("Allow adding forwards only to requesting ip addresses")).default = "1"
+s:taboption("general", Flag, "igdv1", translate("Enable IGDv1 mode"),
+ translate("Advertise as IGDv1 device instead of IGDv2")).default = "0"
+
s:taboption("general", Flag, "log_output", translate("Enable additional logging"),
translate("Puts extra debugging information into the system log"))
@@ -71,7 +74,7 @@ pu = s:taboption("advanced", Value, "presentation_url", translate("Presentation
pu.placeholder = "http://192.168.1.1/"
lf = s:taboption("advanced", Value, "upnp_lease_file", translate("UPnP lease file"))
-lf.placeholder = "/var/log/upnp.leases"
+lf.placeholder = "/var/run/miniupnpd.leases"
s2 = m:section(TypedSection, "perm_rule", translate("MiniUPnP ACLs"),
diff --git a/applications/luci-app-upnp/luasrc/view/upnp_status.htm b/applications/luci-app-upnp/luasrc/view/upnp_status.htm
index e358dcded3..ea79e57a6a 100644
--- a/applications/luci-app-upnp/luasrc/view/upnp_status.htm
+++ b/applications/luci-app-upnp/luasrc/view/upnp_status.htm
@@ -4,8 +4,8 @@
function(x)
{
var tb = document.getElementById('upnp_status_table');
- if (tb && (idx < tb.rows.length))
- tb.rows[0].parentNode.removeChild(tb.rows[idx]);
+ if (tb && (idx + 1 < tb.childNodes.length))
+ tb.removeChild(tb.childNodes[idx + 1]);
}
);
}
@@ -16,52 +16,39 @@
var tb = document.getElementById('upnp_status_table');
if (st && tb)
{
- /* clear all rows */
- while( tb.rows.length > 1 )
- tb.deleteRow(1);
+ var rows = [];
- for( var i = 0; i < st.length; i++ )
- {
- var tr = tb.insertRow(-1);
- tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
+ for (var i = 0; i < st.length; i++)
+ rows.push([
+ st[i].proto,
+ st[i].extport,
+ st[i].intaddr,
+ st[i].host_hint || "<%:Unknown%>",
+ st[i].intport,
+ st[i].descr,
+ E('<div><input class="cbi-button cbi-button-remove" type="button" value="<%:Delete%>" onclick="upnp_delete_fwd(%d)" /></div>'.format(st[i].num))
+ ]);
- tr.insertCell(-1).innerHTML = st[i].proto;
- tr.insertCell(-1).innerHTML = st[i].extport;
- tr.insertCell(-1).innerHTML = st[i].intaddr;
- tr.insertCell(-1).innerHTML = st[i].intport;
-
- tr.insertCell(-1).innerHTML = String.format(
- '<input class="cbi-button cbi-input-remove" type="button" value="<%:Delete Redirect%>" onclick="upnp_delete_fwd(%d)" />',
- st[i].num
- );
- }
-
- if( tb.rows.length == 1 )
- {
- var tr = tb.insertRow(-1);
- tr.className = 'cbi-section-table-row';
-
- var td = tr.insertCell(-1);
- td.colSpan = 5;
- td.innerHTML = '<em><br /><%:There are no active redirects.%></em>';
- }
+ cbi_update_table(tb, rows, '<em><%:There are no active redirects.%></em>');
}
}
);
//]]></script>
-<fieldset class="cbi-section">
- <legend><%:Active UPnP Redirects%></legend>
- <table class="cbi-section-table" id="upnp_status_table">
- <tr class="cbi-section-table-titles">
- <th class="cbi-section-table-cell"><%:Protocol%></th>
- <th class="cbi-section-table-cell"><%:External Port%></th>
- <th class="cbi-section-table-cell"><%:Client Address%></th>
- <th class="cbi-section-table-cell"><%:Client Port%></th>
- <th class="cbi-section-table-cell">&#160;</th>
- </tr>
- <tr class="cbi-section-table-row">
- <td colspan="5"><em><br /><%:Collecting data...%></em></td>
- </tr>
- </table>
-</fieldset>
+<div class="cbi-section">
+ <h3><%:Active UPnP Redirects%></h3>
+ <div class="table" id="upnp_status_table">
+ <div class="tr table-titles">
+ <div class="th"><%:Protocol%></div>
+ <div class="th"><%:External Port%></div>
+ <div class="th"><%:Client Address%></div>
+ <div class="th"><%:Host%></div>
+ <div class="th"><%:Client Port%></div>
+ <div class="th"><%:Description%></div>
+ <div class="th cbi-section-actions">&#160;</div>
+ </div>
+ <div class="tr placeholder">
+ <div class="td"><em><%:Collecting data...%></em></div>
+ </div>
+ </div>
+</div>