From: Jo-Philipp Wich Date: Thu, 12 Jul 2018 14:50:40 +0000 (+0200) Subject: luci-mod-admin-full: rework interface overview page X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c4dca36795f00fefa7337f66d4b42191350f4a2c;p=oweals%2Fluci.git luci-mod-admin-full: rework interface overview page Convert interface enable, disable and delete actions to proper cbi operations so that we can benefit from the apply/rollback workflow when performing critical interface operations. Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-mod-admin-full/luasrc/controller/admin/network.lua b/modules/luci-mod-admin-full/luasrc/controller/admin/network.lua index 4605ffaf3..468068788 100644 --- a/modules/luci-mod-admin-full/luasrc/controller/admin/network.lua +++ b/modules/luci-mod-admin-full/luasrc/controller/admin/network.lua @@ -1,5 +1,5 @@ -- Copyright 2008 Steven Barth --- Copyright 2011-2015 Jo-Philipp Wich +-- Copyright 2011-2018 Jo-Philipp Wich -- Licensed to the public under the Apache License 2.0. module("luci.controller.admin.network", package.seeall) @@ -82,18 +82,12 @@ function index() page = entry({"admin", "network", "iface_add"}, form("admin_network/iface_add"), nil) page.leaf = true - page = entry({"admin", "network", "iface_delete"}, post("iface_delete"), nil) - page.leaf = true - page = entry({"admin", "network", "iface_status"}, call("iface_status"), nil) page.leaf = true page = entry({"admin", "network", "iface_reconnect"}, post("iface_reconnect"), nil) page.leaf = true - page = entry({"admin", "network", "iface_shutdown"}, post("iface_shutdown"), nil) - page.leaf = true - page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), _("Interfaces"), 10) page.leaf = true page.subindex = true @@ -276,34 +270,6 @@ function iface_reconnect(iface) luci.http.status(404, "No such interface") end -function iface_shutdown(iface) - local netmd = require "luci.model.network".init() - local net = netmd:get_network(iface) - if net then - luci.sys.call("env -i /sbin/ifdown %s >/dev/null 2>/dev/null" - % luci.util.shellquote(iface)) - luci.http.status(200, "Shutdown") - return - end - - luci.http.status(404, "No such interface") -end - -function iface_delete(iface) - local netmd = require "luci.model.network".init() - local net = netmd:del_network(iface) - if net then - luci.sys.call("env -i /sbin/ifdown %s >/dev/null 2>/dev/null" - % luci.util.shellquote(iface)) - luci.http.redirect(luci.dispatcher.build_url("admin/network/network")) - netmd:commit("network") - netmd:commit("wireless") - return - end - - luci.http.status(404, "No such interface") -end - function wifi_status(devs) local s = require "luci.tools.status" local rv = { } diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/network.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/network.lua index 2bfe974af..08494644b 100644 --- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/network.lua +++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/network.lua @@ -3,11 +3,143 @@ -- Licensed to the public under the Apache License 2.0. local fs = require "nixio.fs" +local tpl = require "luci.template" +local ntm = require "luci.model.network".init() +local fwm = require "luci.model.firewall".init() local json = require "luci.jsonc" m = Map("network", translate("Interfaces")) +m:chain("wireless") +m:chain("firewall") +m:chain("dhcp") m.pageaction = false -m:section(SimpleSection).template = "admin_network/iface_overview" + + +local tpl_networks = tpl.Template(nil, [[ +
+
+ <% + for i, net in ipairs(netlist) do + local z = net[3] + local c = z and z:get_color() or "#EEEEEE" + local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned") + local disabled = (net[4]:get("auto") == "0") + local dynamic = net[4]:is_dynamic() + %> +
+
+
+
+ <%=net[1]:upper()%> +
+
+
+ ? +
+
+
+
+ <%:Collecting data...%> +
+
+ /> + + <% if disabled then %> + + /> + <% else %> + + /> + <% end %> + + '" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net[1]%>-ifc-edit"<%=ifattr(dynamic, "disabled", "disabled")%> /> + + + /> +
+
+ <% end %> +
+
+ + '" /> +]]) + +local _, net +local ifaces, netlist = { }, { } + +for _, net in ipairs(ntm:get_networks()) do + if net:name() ~= "loopback" then + local zn = net:zonename() + local z = zn and fwm:get_zone(zn) or fwm:get_zone_by_network(net:name()) + + local w = 1 + if net:is_alias() then + w = 2 + elseif net:is_dynamic() then + w = 3 + end + + ifaces[#ifaces+1] = net:name() + netlist[#netlist+1] = { + net:name(), z and z:name() or "-", z, net, w + } + end +end + +table.sort(netlist, + function(a, b) + if a[2] ~= b[2] then + return a[2] < b[2] + elseif a[5] ~= b[5] then + return a[5] < b[5] + else + return a[1] < b[1] + end + end) + +s = m:section(TypedSection, "interface", translate("Interface Overview")) + +function s.sections(self) + local _, net, sl = nil, nil, { } + + for _, net in ipairs(netlist) do + sl[#sl+1] = net[1] + end + + return sl +end + +function s.render(self) + tpl_networks:render({ + netlist = netlist + }) +end + +o = s:option(Value, "__disable__") + +function o.cfgvalue(self, sid) + return (m:get(sid, "auto") == "0") and "1" or "0" +end + +function o.write(self, sid, value) + if value ~= "1" then + m:set(sid, "auto", "") + else + m:set(sid, "auto", "0") + end +end + +o.remove = o.write + +o = s:option(Value, "__delete__") + +function o.write(self, sid, value) + ntm:del_network(sid) +end + + +m:section(SimpleSection).template = "admin_network/iface_overview_status" if fs.access("/etc/init.d/dsl_control") then local ok, boarddata = pcall(json.parse, fs.readfile("/etc/board.json")) diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_network/iface_overview.htm b/modules/luci-mod-admin-full/luasrc/view/admin_network/iface_overview.htm deleted file mode 100644 index 00ef8944c..000000000 --- a/modules/luci-mod-admin-full/luasrc/view/admin_network/iface_overview.htm +++ /dev/null @@ -1,250 +0,0 @@ -<%# - Copyright 2010 Jo-Philipp Wich - Licensed to the public under the Apache License 2.0. --%> - -<%- - local ntm = require "luci.model.network".init() - local fwm = require "luci.model.firewall".init() - - local net - local ifaces = { } - local netlist = { } - for _, net in ipairs(ntm:get_networks()) do - if net:name() ~= "loopback" then - local z = fwm:get_zone_by_network(net:name()) - ifaces[#ifaces+1] = net:name() - netlist[#netlist+1] = { - net:name(), z and z:name() or "-", z - } - end - end - - table.sort(netlist, - function(a, b) - if a[2] ~= b[2] then - return a[2] < b[2] - else - return a[1] < b[1] - end - end) --%> - - - - - -
-
- <%:Interface Overview%> - -
-
- <% - for i, net in ipairs(netlist) do - local z = net[3] - local c = z and z:get_color() or "#EEEEEE" - local t = z and translate("Part of zone %q" % z:name()) or translate("No zone assigned") - %> -
-
-
-
- <%=net[1]:upper()%> -
-
-
- ? -
-
-
-
- <%:Collecting data...%> -
-
- - - '" title="<%:Edit this interface%>" value="<%:Edit%>" id="<%=net[1]%>-ifc-edit" /> - -
-
- <% end %> -
-
- - '" /> -
-
diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_network/iface_overview_status.htm b/modules/luci-mod-admin-full/luasrc/view/admin_network/iface_overview_status.htm new file mode 100644 index 000000000..f56b3e0ad --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_network/iface_overview_status.htm @@ -0,0 +1,182 @@ +<%# + Copyright 2010-2018 Jo-Philipp Wich + Licensed to the public under the Apache License 2.0. +-%> + +