Changeset 5371

Show
Ignore:
Timestamp:
10/08/09 01:36:22 (4 years ago)
Author:
jow
Message:

modules/admin-full: use firewall picker in interface config pages

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua

    r5356 r5371  
    1414]]-- 
    1515 
    16 local wa = require "luci.tools.webadmin" 
    1716local fs = require "nixio.fs" 
     17local fw = require "luci.model.firewall" 
    1818 
    1919arg[1] = arg[1] or "" 
     
    2727 
    2828m = Map("network", translate("interfaces"), translate("a_n_ifaces1")) 
     29m:chain("firewall") 
     30 
     31fw.init(m.uci) 
    2932 
    3033s = m:section(NamedSection, arg[1], "interface") 
     
    9295end 
    9396 
    94 local zones = wa.network_get_zones(arg[1]) 
    95 if zones then 
    96     if #zones == 0 then 
    97         m:chain("firewall") 
    98  
    99         fwzone = s:taboption("general", Value, "_fwzone", 
    100             translate("network_interface_fwzone"), 
    101             translate("network_interface_fwzone_desc")) 
    102         fwzone.rmempty = true 
    103         fwzone:value("", "- " .. translate("none") .. " -") 
    104         fwzone:value(arg[1]) 
    105         m.uci:load("firewall") 
    106         m.uci:foreach("firewall", "zone", 
    107             function (section) 
    108                 fwzone:value(section.name) 
    109             end 
    110         ) 
    111  
    112         function fwzone.write(self, section, value) 
    113             local zone = wa.firewall_find_zone(value) 
    114             local stat 
    115  
    116             if not zone then 
    117                 stat = m.uci:section("firewall", "zone", nil, { 
    118                     name = value, 
    119                     network = section 
    120                 }) 
    121             else 
    122                 local net = m.uci:get("firewall", zone, "network") 
    123                 net = (net or value) .. " " .. section 
    124                 stat = m.uci:set("firewall", zone, "network", net) 
    125             end 
    126  
    127             if stat then 
    128                 self.render = function() end 
    129             end 
     97 
     98fwzone = s:taboption("general", Value, "_fwzone", 
     99    translate("network_interface_fwzone"), 
     100    translate("network_interface_fwzone_desc")) 
     101 
     102fwzone.template = "cbi/firewall_zonelist" 
     103fwzone.rmempty = false 
     104 
     105function fwzone.cfgvalue(self, section) 
     106    self.iface = section 
     107    local z = fw.get_zones_by_network(section)[1] 
     108    return z and z:name() 
     109end 
     110 
     111function fwzone.write(self, section, value) 
     112 
     113    fw.del_network(section) 
     114 
     115    local zone = fw.get_zone(value) 
     116 
     117    if not zone then 
     118        value = m:formvalue(self:cbid(section) .. ".newzone") 
     119        if value and #value > 0 and value:match("^[a-zA-Z0-9_]+$") then 
     120            zone = fw.add_zone(value) 
    130121        end 
    131     else 
    132         fwzone = s:taboption("general", DummyValue, "_fwzone", translate("zone")) 
    133         fwzone.value = table.concat(zones, ", ") 
    134     end 
    135     fwzone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones") 
    136     m.uci:unload("firewall") 
     122    end 
     123 
     124    if zone then 
     125        zone:add_network(section) 
     126    end 
    137127end 
    138128