-local zones = wa.network_get_zones(arg[1])
-if zones then
- if #zones == 0 then
- m:chain("firewall")
-
- fwzone = s:taboption("general", Value, "_fwzone",
- translate("network_interface_fwzone"),
- translate("network_interface_fwzone_desc"))
- fwzone.rmempty = true
- fwzone:value("", "- " .. translate("none") .. " -")
- fwzone:value(arg[1])
- m.uci:load("firewall")
- m.uci:foreach("firewall", "zone",
- function (section)
- fwzone:value(section.name)
- end
- )
-
- function fwzone.write(self, section, value)
- local zone = wa.firewall_find_zone(value)
- local stat
-
- if not zone then
- stat = m.uci:section("firewall", "zone", nil, {
- name = value,
- network = section
- })
- else
- local net = m.uci:get("firewall", zone, "network")
- net = (net or value) .. " " .. section
- stat = m.uci:set("firewall", zone, "network", net)
- end
-
- if stat then
- self.render = function() end
- end
+
+fwzone = s:taboption("general", Value, "_fwzone",
+ translate("network_interface_fwzone"),
+ translate("network_interface_fwzone_desc"))
+
+fwzone.template = "cbi/firewall_zonelist"
+fwzone.rmempty = false
+
+function fwzone.cfgvalue(self, section)
+ self.iface = section
+ local z = fw.get_zones_by_network(section)[1]
+ return z and z:name()
+end
+
+function fwzone.write(self, section, value)
+
+ fw.del_network(section)
+
+ local zone = fw.get_zone(value)
+
+ if not zone then
+ value = m:formvalue(self:cbid(section) .. ".newzone")
+ if value and #value > 0 and value:match("^[a-zA-Z0-9_]+$") then
+ zone = fw.add_zone(value)