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 require("luci.tools.webadmin")
19 m = Map("network", translate("interfaces"))
22 local netstat = luci.sys.net.deviceinfo()
24 s = m:section(TypedSection, "interface", "")
26 s.extedit = luci.http.getenv("REQUEST_URI") .. "/%s"
27 s.template = "cbi/tblsection"
29 function s.filter(self, section)
30 return section ~= "loopback" and section
33 function s.create(self, section)
34 if TypedSection.create(self, section) then
39 function s.parse(self, ...)
40 TypedSection.parse(self, ...)
42 luci.http.redirect(luci.http.getenv("REQUEST_URI") .. "/" .. created)
46 up = s:option(Flag, "up")
48 function up.write(self, section, value)
49 local call = value == "1" and "ifdown" or "ifup"
50 os.execute(call .. " " .. section)
53 ifname = s:option(DummyValue, "ifname", translate("device"))
54 ifname.stateful = true
56 if luci.model.uci.load("firewall") then
57 zone = s:option(DummyValue, "_zone", translate("zone"))
59 function zone.cfgvalue(self, section)
60 local zones = luci.tools.webadmin.network_get_zones(section)
61 return zones and table.concat(zones, ", ") or "-"
65 hwaddr = s:option(DummyValue, "_hwaddr")
66 function hwaddr.cfgvalue(self, section)
67 local ix = self.map:stateget(section, "ifname") or ""
68 return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
72 ipaddr = s:option(DummyValue, "ipaddr", translate("addresses"))
74 function ipaddr.cfgvalue(self, section)
75 local addr = luci.tools.webadmin.network_get_addresses(section)
76 return table.concat(addr, ", ")
79 txrx = s:option(DummyValue, "_txrx")
81 function txrx.cfgvalue(self, section)
82 local ix = self.map:stateget(section, "ifname")
84 local rx = netstat and netstat[ix] and netstat[ix][1]
85 rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
87 local tx = netstat and netstat[ix] and netstat[ix][9]
88 tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
90 return string.format("%s / %s", tx, rx)
93 errors = s:option(DummyValue, "_err")
95 function errors.cfgvalue(self, section)
96 local ix = self.map:stateget(section, "ifname")
98 local rx = netstat and netstat[ix] and netstat[ix][3]
99 local tx = netstat and netstat[ix] and netstat[ix][11]
101 rx = rx and tostring(rx) or "-"
102 tx = tx and tostring(tx) or "-"
104 return string.format("%s / %s", tx, rx)