2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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
16 local sys = require "luci.sys"
17 local wa = require "luci.tools.webadmin"
18 local fs = require "nixio.fs"
20 local netstate = luci.model.uci.cursor_state():get_all("network")
21 m = Map("network", translate("Interfaces"))
24 local netstat = sys.net.deviceinfo()
26 s = m:section(TypedSection, "interface", "")
29 s.extedit = luci.dispatcher.build_url("admin", "network", "network") .. "/%s"
30 s.template = "cbi/tblsection"
31 s.override_scheme = true
33 function s.filter(self, section)
34 return section ~= "loopback" and section
37 function s.create(self, section)
38 if TypedSection.create(self, section) then
41 self.invalid_cts = true
45 function s.parse(self, ...)
46 TypedSection.parse(self, ...)
49 luci.http.redirect(luci.dispatcher.build_url("admin", "network", "network")
54 up = s:option(Flag, "up")
55 function up.cfgvalue(self, section)
56 return netstate[section] and netstate[section].up or "0"
59 function up.write(self, section, value)
63 elseif value == "0" then
66 os.execute(call .. " " .. section .. " >/dev/null 2>&1")
69 ifname = s:option(DummyValue, "ifname", translate("Device"))
70 function ifname.cfgvalue(self, section)
71 return netstate[section] and netstate[section].ifname
74 ifname.titleref = luci.dispatcher.build_url("admin", "network", "vlan")
77 if luci.model.uci.cursor():load("firewall") then
78 zone = s:option(DummyValue, "_zone", translate("Zone"))
79 zone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
81 function zone.cfgvalue(self, section)
82 return table.concat(wa.network_get_zones(section) or { "-" }, ", ")
86 hwaddr = s:option(DummyValue, "_hwaddr",
87 translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"),
88 translate("Hardware Address"))
90 function hwaddr.cfgvalue(self, section)
91 local ix = self.map:get(section, "ifname") or ""
92 ix = (type(ix) == "table") and ix[1] or ix
94 local mac = fs.readfile("/sys/class/net/" .. ix .. "/address")
97 mac = luci.util.exec("ifconfig " .. ix)
98 mac = mac and mac:match(" ([A-F0-9:]+)%s*\n")
101 if mac and #mac > 0 then
109 ipaddr = s:option(DummyValue, "ipaddr",
110 translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>" ..
112 function ipaddr.cfgvalue(self, section)
113 return table.concat(wa.network_get_addresses(section), ", ")
116 txrx = s:option(DummyValue, "_txrx", translate("Traffic"),
117 translate("transmitted / received"))
119 function txrx.cfgvalue(self, section)
120 local ix = self.map:get(section, "ifname")
122 local rx = netstat and netstat[ix] and netstat[ix][1]
123 rx = rx and wa.byte_format(tonumber(rx)) or "-"
125 local tx = netstat and netstat[ix] and netstat[ix][9]
126 tx = tx and wa.byte_format(tonumber(tx)) or "-"
128 return string.format("%s / %s", tx, rx)
131 errors = s:option(DummyValue, "_err", translate("Errors"),
132 translate("TX / RX"))
134 function errors.cfgvalue(self, section)
135 local ix = self.map:get(section, "ifname")
137 local rx = netstat and netstat[ix] and netstat[ix][3]
138 local tx = netstat and netstat[ix] and netstat[ix][11]
140 rx = rx and tostring(rx) or "-"
141 tx = tx and tostring(tx) or "-"
143 return string.format("%s / %s", tx, rx)
146 -- Show ATM bridge section if we have the capabilities
147 if fs.access("/usr/sbin/br2684ctl") then
148 atm = m:section(TypedSection, "atm-bridge", translate("ATM Bridges"),
149 translate("ATM bridges expose encapsulated ethernet in AAL5 " ..
150 "connections as virtual Linux network interfaces which can " ..
151 "be used in conjunction with DHCP or PPP to dial into the " ..
152 "provider network."))
157 atm.create = function(self, section)
158 local sid = TypedSection.create(self, section)
161 m.uci:foreach("network", "atm-bridge",
163 local u = tonumber(s.unit)
164 if u ~= nil and u > max_unit then
169 m.uci:set("network", sid, "unit", max_unit + 1)
170 m.uci:set("network", sid, "atmdev", 0)
171 m.uci:set("network", sid, "encaps", "llc")
172 m.uci:set("network", sid, "payload", "bridged")
173 m.uci:set("network", sid, "vci", 35)
174 m.uci:set("network", sid, "vpi", 8)
179 atm:tab("general", translate("General Setup"))
180 atm:tab("advanced", translate("Advanced Settings"))
182 vci = atm:taboption("general", Value, "vci", translate("ATM Virtual Channel Identifier (VCI)"))
183 vpi = atm:taboption("general", Value, "vpi", translate("ATM Virtual Path Identifier (VPI)"))
184 encaps = atm:taboption("general", ListValue, "encaps", translate("Encapsulation mode"))
185 encaps:value("llc", translate("LLC"))
186 encaps:value("vc", translate("VC-Mux"))
188 atmdev = atm:taboption("advanced", Value, "atmdev", translate("ATM device number"))
189 unit = atm:taboption("advanced", Value, "unit", translate("Bridge unit number"))
190 payload = atm:taboption("advanced", ListValue, "payload", translate("Forwarding mode"))
191 payload:value("bridged", translate("bridged"))
192 payload:value("routed", translate("routed"))