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 function ipaddr.cfgvalue(self, section)
56 local ip = self.map:stateget(section, "ipaddr")
57 local nm = self.map:stateget(section, "netmask")
59 local parsed = ip and luci.ip.IPv4(ip, nm)
60 return parsed and parsed:string() or ""
63 rx = s:option(DummyValue, "_rx")
65 function rx.cfgvalue(self, section)
66 local ix = self.map:stateget(section, "ifname")
67 local bt = netstat and netstat[ix] and netstat[ix][1]
68 return bt and string.format("%.2f MB", tonumber(bt) / 1024 / 1024)
71 tx = s:option(DummyValue, "_tx")
73 function tx.cfgvalue(self, section)
74 local ix = self.map:stateget(section, "ifname")
75 local bt = netstat and netstat[ix] and netstat[ix][9]
76 return bt and string.format("%.2f MB", tonumber(bt) / 1024 / 1024)