Changeset 5718

Show
Ignore:
Timestamp:
03/06/10 20:15:58 (3 years ago)
Author:
jow
Message:

luci-0.9: merge r5716

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/branches/luci-0.9/modules/admin-full/luasrc/model/cbi/admin_network/vlan.lua

    r2808 r5718  
    33 
    44Copyright 2008 Steven Barth <steven@midlink.org> 
     5Copyright 2010 Jo-Philipp Wich <xm@subsignal.org> 
    56 
    67Licensed under the Apache License, Version 2.0 (the "License"); 
     
    1415m = Map("network", translate("a_n_switch"), translate("a_n_switch1")) 
    1516 
    16 s = m:section(TypedSection, "switch", "") 
     17m.uci:foreach("network", "switch", 
     18    function(x) 
    1719 
    18 for i = 0, 15 do 
    19     s:option(Value, "vlan"..i, "ethX."..i).optional = true 
    20 end 
     20        -- Switch properties 
     21        s = m:section(NamedSection, x['.name'], "switch", "Switch: %s" % x['.name']) 
     22        s.addremove = false 
     23 
     24        s:option(Flag, "enable", "Enable this switch") 
     25            .cfgvalue = function(self, section) return Flag.cfgvalue(self, section) or self.enabled end 
     26 
     27        s:option(Flag, "enable_vlan", "Enable VLAN functionality") 
     28            .cfgvalue = function(self, section) return Flag.cfgvalue(self, section) or self.enabled end 
     29 
     30        s:option(Flag, "reset", "Reset switch during setup") 
     31            .cfgvalue = function(self, section) return Flag.cfgvalue(self, section) or self.enabled end 
     32 
     33 
     34        -- VLAN table 
     35        s = m:section(TypedSection, "switch_vlan", "VLANs: %s" % x['.name']) 
     36        s.template = "cbi/tblsection" 
     37        s.rowcolors = true 
     38        s.addremove = true 
     39 
     40        s.sectiontitle = function(self, section) 
     41            return "VLAN #%d" % (m.uci:get("network", section, "vlan") or 0) 
     42        end 
     43 
     44        s.filter = function(self, section) 
     45            return m.uci:get("network", section, "device") == x['.name'] 
     46                or m.uci:get("network", section, "device") == nil -- needed for just created vlan sections 
     47        end 
     48 
     49        s.cfgsections = function(self) 
     50            local osections = TypedSection.cfgsections(self) 
     51            local sections = { } 
     52            local section    
     53 
     54            for _, section in luci.util.spairs( 
     55                osections, 
     56                function(a, b) 
     57                    return (tonumber(m.uci:get("network", osections[a], "vlan")) or 0) 
     58                        <  (tonumber(m.uci:get("network", osections[b], "vlan")) or 0) 
     59                end 
     60            ) do 
     61                sections[#sections+1] = section 
     62            end 
     63 
     64            return sections 
     65        end 
     66 
     67        s.create = function(self, section) 
     68            local n = tonumber(section) 
     69            if n ~= nil and n >= 0 then 
     70                local sn = "%s_%d" %{ x['.name'], n } 
     71                local rv = TypedSection.create(self, sn) 
     72                m.uci:set("network", sn, "device", x['.name']) 
     73                m.uci:set("network", sn, "vlan", n) 
     74                return rv 
     75            end 
     76            return nil 
     77        end 
     78 
     79 
     80        p0 = s:option(Flag, "0", "Port 0") 
     81        p1 = s:option(Flag, "1", "Port 1") 
     82        p2 = s:option(Flag, "2", "Port 2") 
     83        p3 = s:option(Flag, "3", "Port 3") 
     84        p4 = s:option(Flag, "4", "Port 4") 
     85        p5 = s:option(Flag, "5", "CPU"   ) 
     86 
     87 
     88        p0.cfgvalue = function(self, section) 
     89            local pts = (m.uci:get("network", section, "ports") or "") 
     90            return (pts:match("%f[%w]" .. self.option .. "%f[%W]") and self.enabled or self.disabled) 
     91        end 
     92 
     93        p1.cfgvalue = p0.cfgvalue 
     94        p2.cfgvalue = p0.cfgvalue 
     95        p3.cfgvalue = p0.cfgvalue 
     96        p4.cfgvalue = p0.cfgvalue 
     97        p5.cfgvalue = p0.cfgvalue 
     98 
     99 
     100        p0.parse = function(self, section) 
     101            local pts = { } 
     102            if p0:formvalue(section) then pts[#pts+1] = 0 end 
     103            if p1:formvalue(section) then pts[#pts+1] = 1 end 
     104            if p2:formvalue(section) then pts[#pts+1] = 2 end 
     105            if p3:formvalue(section) then pts[#pts+1] = 3 end 
     106            if p4:formvalue(section) then pts[#pts+1] = 4 end 
     107            if p5:formvalue(section) then pts[#pts+1] = 5 end 
     108            m.uci:set("network", section, "ports", table.concat(pts, " ")) 
     109        end 
     110 
     111        p1.parse = function() end 
     112        p2.parse = p1.parse 
     113        p3.parse = p1.parse 
     114        p4.parse = p1.parse 
     115        p5.parse = p1.parse 
     116    end 
     117) 
    21118 
    22119return m