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")
18 local netstate = luci.model.uci.cursor_state():get_all("network")
19 m = Map("network", translate("interfaces"))
22 local netstat = luci.sys.net.deviceinfo()
24 s = m:section(TypedSection, "interface", "")
26 s.extedit = luci.dispatcher.build_url("admin", "network", "network") .. "/%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, ...)
43 luci.http.redirect(luci.dispatcher.build_url("admin", "network", "network")
48 up = s:option(Flag, "up")
49 function up.cfgvalue(self, section)
50 return netstate[section] and netstate[section].up or "0"
53 function up.write(self, section, value)
57 elseif value == "0" then
60 os.execute(call .. " " .. section .. " >/dev/null 2>&1")
63 ifname = s:option(DummyValue, "ifname", translate("device"))
64 function ifname.cfgvalue(self, section)
65 return netstate[section] and netstate[section].ifname
68 ifname.titleref = luci.dispatcher.build_url("admin", "network", "vlan")
71 if luci.model.uci.cursor():load("firewall") then
72 zone = s:option(DummyValue, "_zone", translate("zone"))
73 zone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
75 function zone.cfgvalue(self, section)
76 local zones = luci.tools.webadmin.network_get_zones(section)
77 return zones and table.concat(zones, ", ") or "-"
81 hwaddr = s:option(DummyValue, "_hwaddr")
82 function hwaddr.cfgvalue(self, section)
83 local ix = self.map:get(section, "ifname") or ""
84 return luci.fs.readfile("/sys/class/net/" .. ix .. "/address")
85 or luci.util.exec("ifconfig " .. ix):match(" ([A-F0-9:]+)%s*\n")
91 ipaddr = s:option(DummyValue, "ipaddr", translate("addresses"))
92 function ipaddr.cfgvalue(self, section)
93 local addr = luci.tools.webadmin.network_get_addresses(section)
94 return table.concat(addr, ", ")
97 txrx = s:option(DummyValue, "_txrx")
99 function txrx.cfgvalue(self, section)
100 local ix = self.map:get(section, "ifname")
102 local rx = netstat and netstat[ix] and netstat[ix][1]
103 rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
105 local tx = netstat and netstat[ix] and netstat[ix][9]
106 tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
108 return string.format("%s / %s", tx, rx)
111 errors = s:option(DummyValue, "_err")
113 function errors.cfgvalue(self, section)
114 local ix = self.map:get(section, "ifname")
116 local rx = netstat and netstat[ix] and netstat[ix][3]
117 local tx = netstat and netstat[ix] and netstat[ix][11]
119 rx = rx and tostring(rx) or "-"
120 tx = tx and tostring(tx) or "-"
122 return string.format("%s / %s", tx, rx)