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 luci.model.uci.load_state("network")
19 local netstate = luci.model.uci.get_all("network")
20 luci.model.uci.unload("network")
23 m = Map("network", translate("interfaces"))
26 local netstat = luci.sys.net.deviceinfo()
28 s = m:section(TypedSection, "interface", "")
30 s.extedit = luci.http.getenv("REQUEST_URI") .. "/%s"
31 s.template = "cbi/tblsection"
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
43 function s.parse(self, ...)
44 TypedSection.parse(self, ...)
46 luci.http.redirect(luci.http.getenv("REQUEST_URI") .. "/" .. created)
50 up = s:option(Flag, "up")
51 function up.cfgvalue(self, section)
52 return netstate[section] and netstate[section].up or "0"
55 function up.write(self, section, value)
59 elseif value == "0" then
62 os.execute(call .. " " .. section .. " >/dev/null 2>&1")
65 ifname = s:option(DummyValue, "ifname", translate("device"))
66 function ifname.cfgvalue(self, section)
67 return netstate[section] and netstate[section].ifname
70 ifname.titleref = luci.dispatcher.build_url("admin", "network", "vlan")
72 if luci.model.uci.load("firewall") then
73 zone = s:option(DummyValue, "_zone", translate("zone"))
74 zone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
76 function zone.cfgvalue(self, section)
77 local zones = luci.tools.webadmin.network_get_zones(section)
78 return zones and table.concat(zones, ", ") or "-"
82 hwaddr = s:option(DummyValue, "_hwaddr")
83 function hwaddr.cfgvalue(self, section)
84 local ix = self.map:get(section, "ifname") or ""
85 return luci.fs.readfile("/sys/class/net/" .. ix .. "/address")
86 or luci.util.exec("ifconfig " .. ix):match(" ([A-F0-9:]+)%s*\n")
92 ipaddr = s:option(DummyValue, "ipaddr", translate("addresses"))
93 function ipaddr.cfgvalue(self, section)
94 local addr = luci.tools.webadmin.network_get_addresses(section)
95 return table.concat(addr, ", ")
98 txrx = s:option(DummyValue, "_txrx")
100 function txrx.cfgvalue(self, section)
101 local ix = self.map:get(section, "ifname")
103 local rx = netstat and netstat[ix] and netstat[ix][1]
104 rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
106 local tx = netstat and netstat[ix] and netstat[ix][9]
107 tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
109 return string.format("%s / %s", tx, rx)
112 errors = s:option(DummyValue, "_err")
114 function errors.cfgvalue(self, section)
115 local ix = self.map:get(section, "ifname")
117 local rx = netstat and netstat[ix] and netstat[ix][3]
118 local tx = netstat and netstat[ix] and netstat[ix][11]
120 rx = rx and tostring(rx) or "-"
121 tx = tx and tostring(tx) or "-"
123 return string.format("%s / %s", tx, rx)