From 74be6f39748a4f441e54e6bdfc768306a3c8b91f Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 8 Jun 2018 08:19:20 +0200 Subject: treewide: switch firewall zone, network and iface lists to dropdown code Also switch the weekday and monthday lists in the firewall rule details to cbi dropdowns, vastly uncluttering the form. Signed-off-by: Jo-Philipp Wich --- .../luasrc/view/cbi/firewall_zonelist.htm | 79 +++++++++------- .../luasrc/view/cbi/network_ifacelist.htm | 102 ++++++++++----------- .../luci-base/luasrc/view/cbi/network_netlist.htm | 90 +++++++++--------- .../luasrc/model/cbi/admin_network/ifaces.lua | 17 +--- .../luasrc/model/cbi/admin_network/wifi.lua | 35 +++---- .../luasrc/model/cbi/admin_network/wifi_add.lua | 11 +-- 6 files changed, 165 insertions(+), 169 deletions(-) (limited to 'modules') diff --git a/modules/luci-base/luasrc/view/cbi/firewall_zonelist.htm b/modules/luci-base/luasrc/view/cbi/firewall_zonelist.htm index b4260707e..3a108020b 100644 --- a/modules/luci-base/luasrc/view/cbi/firewall_zonelist.htm +++ b/modules/luci-base/luasrc/view/cbi/firewall_zonelist.htm @@ -24,26 +24,42 @@ end -%> - -
    +
    > + +
      <% if self.allowlocal then %> -
    • - />   - > - style="background-color:<%=fwm.zone.get_color()%>" class="zonebadge"> +
    • > + <%:Device%> - <% if self.allowany and self.allowlocal then %>(<%:input%>)<% end %> - + <% if self.allowany and self.allowlocal then -%> + (<%= self.alias ~= "dest" + and translate("output") or translate("input") %>) + <%- end %> + +
    • + <% elseif self.widget ~= "checkbox" and (self.rmempty or self.optional) then %> +
    • > + + <%:unspecified%> +
    • <% end %> <% if self.allowany then %> -
    • - />   - > - style="background-color:<%=fwm.zone.get_color()%>" class="zonebadge"> +
    • > + <%:Any zone%> <% if self.allowany and self.allowlocal then %>(<%:forward%>)<% end %> - +
    • <% end %> <% @@ -51,45 +67,42 @@ if zone:name() ~= self.exclude then selected = selected or (value == zone:name()) %> -
    • - />   - > - style="background-color:<%=zone:get_color()%>" class="zonebadge"> + > + <%=zone:name()%>: - <% + <%- local zempty = true for _, net in ipairs(zone:get_networks()) do net = nwm:get_network(net) if net then zempty = false - %> + -%> <%=net:name()%>: - <% + <%- local nempty = true for _, iface in ipairs(net:is_bridge() and net:get_interfaces() or { net:get_interface() }) do nempty = false %> - style="width:16px; height:16px; vertical-align:middle" src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" /> + src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" /> <% end %> - <% if nempty then %><%:(empty)%><% end %> + <% if nempty then %><%:(empty)%><% end -%> - <% end end %> - <% if zempty then %><%:(empty)%><% end %> - + <%- end end -%> + <%- if zempty then %><%:(empty)%><% end -%> +
    • <% end end %> <% if self.widget ~= "checkbox" and not self.nocreate then %> -
    • - />   - > -
      - <%:unspecified -or- create:%>  - onfocus="document.getElementById('<%=cbid%>_new').checked=true" /> -
      +
    • + + <%:create%>: + + +
    • <% end %>
    - +
    <%+cbi/valuefooter%> diff --git a/modules/luci-base/luasrc/view/cbi/network_ifacelist.htm b/modules/luci-base/luasrc/view/cbi/network_ifacelist.htm index 62dbde7dd..abfa33e1e 100644 --- a/modules/luci-base/luasrc/view/cbi/network_ifacelist.htm +++ b/modules/luci-base/luasrc/view/cbi/network_ifacelist.htm @@ -19,7 +19,9 @@ if value then for value in utl.imatch(value) do - checked[value] = true + for value in utl.imatch(value) do + checked[value] = true + end end else local n = self.network and net:get_network(self.network) @@ -33,57 +35,51 @@ -%> -
      - <% for _, iface in ipairs(ifaces) do - local link = iface:adminlink() - if (not self.nobridges or not iface:is_bridge()) and - (not self.noinactive or iface:is_up()) and - iface:name() ~= self.exclude - then %> -
    • - " data-update="click change"<%= - attr("type", self.widget or "radio") .. - attr("id", cbid .. "." .. iface:name()) .. - attr("name", cbid) .. attr("value", iface:name()) .. - ifattr(checked[iface:name()], "checked", "checked") - %> /> - <%- if not self.widget or self.widget == "checkbox" or self.widget == "radio" then -%> - > - <%- end -%> -   - > - <% if link then -%><% end -%> - style="width:16px; height:16px; vertical-align:middle" src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" /> - <% if link then -%><% end -%> - <%=pcdata(iface:get_i18n())%> - <% local ns = iface:get_networks(); if #ns > 0 then %>( - <%- local i, n; for i, n in ipairs(ns) do -%> - <%-= (i>1) and ', ' -%> - <%=n:name()%> - <%- end -%> - )<% end %> - -
    • - <% end end %> - <% if not self.nocreate then %> -
    • - " data-update="click change"<%= - attr("type", self.widget or "radio") .. - attr("id", cbid .. "_custom") .. - attr("name", cbid) .. - attr("value", " ") - %> /> - <%- if not self.widget or self.widget == "checkbox" or self.widget == "radio" then -%> - > - <%- end -%> -   - > - - <%:Custom Interface%>: - - -
    • - <% end %> -
    + +
    > + +
      + <% for _, iface in ipairs(ifaces) do + if (not self.nobridges or not iface:is_bridge()) and + (not self.noinactive or iface:is_up()) and + iface:name() ~= self.exclude + then %> + > + src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" /> + <%=pcdata(iface:name())%> + + <%=pcdata(iface:get_i18n())%> + <% local ns = iface:get_networks(); if #ns > 0 then %>( + <%- local i, n; for i, n in ipairs(ns) do -%> + <%-= (i>1) and ', ' -%> + <%=n:name()%> + <%- end -%> + )<% end %> + + + <% end end %> + <% if not self.nocreate then %> +
    • + + <%:Custom Interface%>: + + +
    • + <% end %> +
    +
    <%+cbi/valuefooter%> diff --git a/modules/luci-base/luasrc/view/cbi/network_netlist.htm b/modules/luci-base/luasrc/view/cbi/network_netlist.htm index 8bf1a70a2..ba6ebb843 100644 --- a/modules/luci-base/luasrc/view/cbi/network_netlist.htm +++ b/modules/luci-base/luasrc/view/cbi/network_netlist.htm @@ -20,66 +20,62 @@ end -%> -
      - <% for _, net in ipairs(networks) do - if (net:name() ~= "loopback") and - (net:name() ~= self.exclude) and - (not self.novirtual or not net:is_virtual()) - then %> -
    • - " data-update="click change"<%= - attr("type", self.widget or "radio") .. - attr("id", cbid .. "." .. net:name()) .. - attr("name", cbid) .. attr("value", net:name()) .. - ifattr(checked[net:name()], "checked", "checked") - %> />   - > +
      > + +
        + <% if self.widget ~= "checkbox" then %> +
      • > + <%:unspecified%> +
      • + <% end %> + + <% for _, net in ipairs(networks) do + if (net:name() ~= "loopback") and + (net:name() ~= self.exclude) and + (not self.novirtual or not net:is_virtual()) + then %> + > <%=net:name()%>: <% local empty = true for _, iface in ipairs(net:is_bridge() and net:get_interfaces() or { net:get_interface() }) do if not iface:is_bridge() then empty = false - %> + -%> style="width:16px; height:16px; vertical-align:middle" src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" /> - <% end end %> - <% if empty then %><%:(no interfaces attached)%><% end %> + <%- end end %> + <% if empty then %> + <%:(no interfaces attached)%> + - + <% end %> - - - <% end end %> + + <% end end %> - <% if not self.nocreate then %> -
      • - " data-update="click change"<%=attr("type", self.widget or "radio") .. attr("id", cbid .. "_new") .. attr("name", cbid) .. attr("value", "-") .. ifattr(not value and self.widget ~= "checkbox", "checked", "checked")%> />   - <%- if not self.widget or self.widget == "checkbox" or self.widget == "radio" then -%> - > - <%- end -%> -
        - > + <% if not self.nocreate then %> +
      • > + <%- if self.widget == "checkbox" then -%> <%:create:%> <%- else -%> <%:unspecified -or- create:%> - <%- end -%>  + <%- end -%> + - onfocus="document.getElementById('<%=cbid%>_new').checked=true" /> -
      -
    • - <% elseif self.widget ~= "checkbox" and self.unspecified then %> -
    • - " data-update="click change"<%= - attr("type", self.widget or "radio") .. - attr("id", cbid .. "_uns") .. - attr("name", cbid) .. - attr("value", "") .. - ifattr(not value or #value == 0, "checked", "checked") - %> />   -
      - ><%:unspecified%> -
      -
    • - <% end %> -
    + + + <% end %> +
+ <%+cbi/valuefooter%> diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/ifaces.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/ifaces.lua index 38e5de7b3..5c630bb5c 100644 --- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/ifaces.lua +++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/ifaces.lua @@ -351,7 +351,6 @@ if has_firewall then fwzone.template = "cbi/firewall_zonelist" fwzone.network = arg[1] - fwzone.rmempty = false function fwzone.cfgvalue(self, section) self.iface = section @@ -360,22 +359,16 @@ if has_firewall then end function fwzone.write(self, section, value) - local zone = fw:get_zone(value) - - if not zone and value == '-' then - value = m:formvalue(self:cbid(section) .. ".newzone") - if value and #value > 0 then - zone = fw:add_zone(value) - else - fw:del_network(section) - end - end - + local zone = fw:get_zone(value) or fw:add_zone(value) if zone then fw:del_network(section) zone:add_network(section) end end + + function fwzone.remove(self, section) + fw:del_network(section) + end end diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua index cacaa2595..d51a72aba 100644 --- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua +++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi.lua @@ -390,22 +390,16 @@ network.novirtual = true function network.write(self, section, value) local i = nw:get_interface(section) if i then - if value == '-' then - value = m:formvalue(self:cbid(section) .. ".newnet") - if value and #value > 0 then - local n = nw:add_network(value, {proto="none"}) - if n then n:add_interface(i) end - else - local n = i:get_network() - if n then n:del_interface(i) end - end - else - local v - for _, v in ipairs(i:get_networks()) do - v:del_interface(i) - end - for v in ut.imatch(value) do - local n = nw:get_network(v) + local _, net, old, new = nil, nil, {}, {} + + for _, net in ipairs(i:get_networks()) do + old[net:name()] = true + end + + for net in ut.imatch(value) do + new[net] = true + if not old[net] then + local n = nw:get_network(net) or nw:add_network(net, { proto = "none" }) if n then if not n:is_empty() then n:set("type", "bridge") @@ -414,6 +408,15 @@ function network.write(self, section, value) end end end + + for net, _ in pairs(old) do + if not new[net] then + local n = nw:get_network(net) + if n then + n:del_interface(i) + end + end + end end end diff --git a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi_add.lua b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi_add.lua index 8277deb2f..e8a305882 100644 --- a/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi_add.lua +++ b/modules/luci-mod-admin-full/luasrc/model/cbi/admin_network/wifi_add.lua @@ -94,14 +94,9 @@ function newnet.parse(self, section) local net, zone if has_firewall then - local zval = fwzone:formvalue(section) - zone = fw:get_zone(zval) - - if not zone and zval == '-' then - zval = m:formvalue(fwzone:cbid(section) .. ".newzone") - if zval and #zval > 0 then - zone = fw:add_zone(zval) - end + local value = fwzone:formvalue(section) + if value and #value > 0 then + zone = fw:get_zone(value) or fw:add_zone(value) end end -- cgit v1.2.3