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
18 m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
21 local netstat = luci.sys.net.deviceinfo()
23 s = m:section(TypedSection, "interface", translate("interfaces"))
25 s.extedit = luci.http.getenv("REQUEST_URI") .. "/%s"
26 s.template = "cbi/tblsection"
28 function s.filter(self, section)
29 return section ~= "loopback" and section
32 function s.create(self, section)
33 if TypedSection.create(self, section) then
38 function s.parse(self, ...)
39 TypedSection.parse(self, ...)
41 luci.http.redirect(luci.http.getenv("REQUEST_URI") .. "/" .. created)
45 up = s:option(Flag, "up")
47 function up.write(self, section, value)
48 local call = value == "1" and "ifdown" or "ifup"
49 os.execute(call .. " " .. section)
52 ipaddr = s:option(DummyValue, "ipaddr", translate("ipaddress"))
53 ipaddr.stateful = true
55 ip6addr = s:option(DummyValue, "ip6addr", translate("ip6address"))
56 ip6addr.stateful = true
58 function ipaddr.cfgvalue(self, section)
59 local ip = self.map:stateget(section, "ipaddr")
60 local nm = self.map:stateget(section, "netmask")
62 local parsed = ip and luci.ip.IPv4(ip, nm)
63 return parsed and parsed:string() or ""
66 rx = s:option(DummyValue, "_rx")
68 function rx.cfgvalue(self, section)
69 local ix = self.map:stateget(section, "ifname")
70 local bt = netstat and netstat[ix] and netstat[ix][1]
71 return bt and string.format("%.2f MB", tonumber(bt) / 1024 / 1024)
74 tx = s:option(DummyValue, "_tx")
76 function tx.cfgvalue(self, section)
77 local ix = self.map:stateget(section, "ifname")
78 local bt = netstat and netstat[ix] and netstat[ix][9]
79 return bt and string.format("%.2f MB", tonumber(bt) / 1024 / 1024)