diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-12-03 15:17:05 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-08 16:26:20 +0100 |
commit | 1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch) | |
tree | 35e16f100466e4e00657199b38bb3d87d52bf73f /applications/luci-app-upnp/luasrc | |
parent | 9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff) |
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names
* Make each LuCI module its own standalone package
* Deploy a shared luci.mk which is used by each module Makefile
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'applications/luci-app-upnp/luasrc')
4 files changed, 266 insertions, 0 deletions
diff --git a/applications/luci-app-upnp/luasrc/controller/upnp.lua b/applications/luci-app-upnp/luasrc/controller/upnp.lua new file mode 100644 index 0000000000..83fa94154b --- /dev/null +++ b/applications/luci-app-upnp/luasrc/controller/upnp.lua @@ -0,0 +1,84 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +]]-- + +module("luci.controller.upnp", package.seeall) + +function index() + if not nixio.fs.access("/etc/config/upnpd") then + return + end + + local page + + page = entry({"admin", "services", "upnp"}, cbi("upnp/upnp"), _("UPNP")) + page.dependent = true + + entry({"admin", "services", "upnp", "status"}, call("act_status")).leaf = true + entry({"admin", "services", "upnp", "delete"}, call("act_delete")).leaf = true +end + +function act_status() + local ipt = io.popen("iptables --line-numbers -t nat -xnvL MINIUPNPD") + if ipt then + local fwd = { } + while true do + local ln = ipt:read("*l") + if not ln then + break + elseif ln:match("^%d+") then + local num, proto, extport, intaddr, intport = + ln:match("^(%d+).-([a-z]+).-dpt:(%d+) to:(%S-):(%d+)") + + if num and proto and extport and intaddr and intport then + num = tonumber(num) + extport = tonumber(extport) + intport = tonumber(intport) + + fwd[#fwd+1] = { + num = num, + proto = proto:upper(), + extport = extport, + intaddr = intaddr, + intport = intport + } + end + end + end + + ipt:close() + + luci.http.prepare_content("application/json") + luci.http.write_json(fwd) + end +end + +function act_delete(num) + local idx = tonumber(num) + local uci = luci.model.uci.cursor() + + if idx and idx > 0 then + luci.sys.call("iptables -t filter -D MINIUPNPD %d 2>/dev/null" % idx) + luci.sys.call("iptables -t nat -D MINIUPNPD %d 2>/dev/null" % idx) + + 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 }) + end + + luci.http.status(200, "OK") + return + end + + luci.http.status(400, "Bad request") +end diff --git a/applications/luci-app-upnp/luasrc/model/cbi/upnp/upnp.lua b/applications/luci-app-upnp/luasrc/model/cbi/upnp/upnp.lua new file mode 100644 index 0000000000..3d98d6682f --- /dev/null +++ b/applications/luci-app-upnp/luasrc/model/cbi/upnp/upnp.lua @@ -0,0 +1,114 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +m = Map("upnpd", luci.util.pcdata(translate("Universal Plug & Play")), + translate("UPnP allows clients in the local network to automatically configure the router.")) + +m:section(SimpleSection).template = "upnp_status" + +s = m:section(NamedSection, "config", "upnpd", translate("MiniUPnP settings")) +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.rmempty = false + +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 +end + +s:taboption("general", Flag, "enable_upnp", translate("Enable UPnP functionality")).default = "1" +s:taboption("general", Flag, "enable_natpmp", translate("Enable NAT-PMP functionality")).default = "1" + +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, "log_output", translate("Enable additional logging"), + translate("Puts extra debugging information into the system log")) + +s:taboption("general", Value, "download", translate("Downlink"), + translate("Value in KByte/s, informational only")).rmempty = true + +s:taboption("general", Value, "upload", translate("Uplink"), + translate("Value in KByte/s, informational only")).rmempty = true + +port = s:taboption("general", Value, "port", translate("Port")) +port.datatype = "port" +port.default = 5000 + + +s:taboption("advanced", Flag, "system_uptime", translate("Report system instead of daemon uptime")).default = "1" + +s:taboption("advanced", Value, "uuid", translate("Device UUID")) +s:taboption("advanced", Value, "serial_number", translate("Announced serial number")) +s:taboption("advanced", Value, "model_number", translate("Announced model number")) + +ni = s:taboption("advanced", Value, "notify_interval", translate("Notify interval")) +ni.datatype = "uinteger" +ni.placeholder = 30 + +ct = s:taboption("advanced", Value, "clean_ruleset_threshold", translate("Clean rules threshold")) +ct.datatype = "uinteger" +ct.placeholder = 20 + +ci = s:taboption("advanced", Value, "clean_ruleset_interval", translate("Clean rules interval")) +ci.datatype = "uinteger" +ci.placeholder = 600 + +pu = s:taboption("advanced", Value, "presentation_url", translate("Presentation URL")) +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" + + +s2 = m:section(TypedSection, "perm_rule", translate("MiniUPnP ACLs"), + translate("ACLs specify which external ports may be redirected to which internal addresses and ports")) + +s2.template = "cbi/tblsection" +s2.sortable = true +s2.anonymous = true +s2.addremove = true + +s2:option(Value, "comment", translate("Comment")) + +ep = s2:option(Value, "ext_ports", translate("External ports")) +ep.datatype = "portrange" +ep.placeholder = "0-65535" + +ia = s2:option(Value, "int_addr", translate("Internal addresses")) +ia.datatype = "ip4addr" +ia.placeholder = "0.0.0.0/0" + +ip = s2:option(Value, "int_ports", translate("Internal ports")) +ip.datatype = "portrange" +ip.placeholder = "0-65535" + +ac = s2:option(ListValue, "action", translate("Action")) +ac:value("allow") +ac:value("deny") + +return m diff --git a/applications/luci-app-upnp/luasrc/view/admin_status/index/upnp.htm b/applications/luci-app-upnp/luasrc/view/admin_status/index/upnp.htm new file mode 100644 index 0000000000..d0c2e2ed50 --- /dev/null +++ b/applications/luci-app-upnp/luasrc/view/admin_status/index/upnp.htm @@ -0,0 +1 @@ +<%+upnp_status%> diff --git a/applications/luci-app-upnp/luasrc/view/upnp_status.htm b/applications/luci-app-upnp/luasrc/view/upnp_status.htm new file mode 100644 index 0000000000..d50ed0c4d7 --- /dev/null +++ b/applications/luci-app-upnp/luasrc/view/upnp_status.htm @@ -0,0 +1,67 @@ +<script type="text/javascript">//<![CDATA[ + function upnp_delete_fwd(idx) { + XHR.get('<%=luci.dispatcher.build_url("admin", "services", "upnp", "delete")%>/' + idx, null, + function(x) + { + var tb = document.getElementById('upnp_status_table'); + if (tb && (idx < tb.rows.length)) + tb.rows[0].parentNode.removeChild(tb.rows[idx]); + } + ); + } + + XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "upnp", "status")%>', null, + function(x, st) + { + var tb = document.getElementById('upnp_status_table'); + if (st && tb) + { + /* clear all rows */ + while( tb.rows.length > 1 ) + tb.deleteRow(1); + + for( var i = 0; i < st.length; i++ ) + { + var tr = tb.insertRow(-1); + tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); + + 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>'; + } + } + } + ); +//]]></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"> </th> + </tr> + <tr class="cbi-section-table-row"> + <td colspan="5"><em><br /><%:Collecting data...%></em></td> + </tr> + </table> +</fieldset> |