2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
15 m = Map("network", translate("Switch"), translate("The network ports on your router can be combined to several <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s in which computers can communicate directly with each other. <abbr title=\"Virtual Local Area Network\">VLAN</abbr>s are often used to separate different network segments. Often there is by default one Uplink port for a connection to the next greater network like the internet and other ports for a local network."))
17 m.uci:foreach("network", "switch",
21 s = m:section(NamedSection, x['.name'], "switch", "Switch: %s" % x['.name'])
24 s:option(Flag, "enable", "Enable this switch")
25 .cfgvalue = function(self, section) return Flag.cfgvalue(self, section) or self.enabled end
27 s:option(Flag, "enable_vlan", "Enable VLAN functionality")
28 .cfgvalue = function(self, section) return Flag.cfgvalue(self, section) or self.enabled end
30 s:option(Flag, "reset", "Reset switch during setup")
31 .cfgvalue = function(self, section) return Flag.cfgvalue(self, section) or self.enabled end
35 s = m:section(TypedSection, "switch_vlan", "VLANs: %s" % x['.name'])
36 s.template = "cbi/tblsection"
40 s.sectiontitle = function(self, section)
41 return "VLAN #%d" % (m.uci:get("network", section, "vlan") or 0)
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
49 s.cfgsections = function(self)
50 local osections = TypedSection.cfgsections(self)
54 for _, section in luci.util.spairs(
57 return (tonumber(m.uci:get("network", osections[a], "vlan")) or 0)
58 < (tonumber(m.uci:get("network", osections[b], "vlan")) or 0)
61 sections[#sections+1] = section
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)
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" )
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)
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
100 p0.parse = function(self, section)
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, " "))
111 p1.parse = function() end