2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
15 require("luci.tools.webadmin")
17 w = Template("mini/index")
19 f = SimpleForm("main", translate("system"))
23 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
24 local uptime = luci.sys.uptime()
25 f:field(DummyValue, "_system", translate("system")).value = system
26 f:field(DummyValue, "_cpu", translate("m_i_processor")).value = model
28 local load1, load5, load15 = luci.sys.loadavg()
29 f:field(DummyValue, "_la", translate("load")).value =
30 string.format("%.2f, %.2f, %.2f", load1, load5, load15)
32 f:field(DummyValue, "_memtotal", translate("m_i_memory")).value =
33 string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
34 tonumber(memtotal) / 1024,
35 100 * memcached / memtotal,
36 translate("mem_cached") or "",
37 100 * membuffers / memtotal,
38 translate("mem_buffered") or "",
39 100 * memfree / memtotal,
40 translate("mem_free") or "")
42 f:field(DummyValue, "_systime", translate("m_i_systemtime")).value =
45 f:field(DummyValue, "_uptime", translate("m_i_uptime")).value =
46 luci.tools.webadmin.date_format(tonumber(uptime))
49 m = Map("network", translate("interfaces"))
51 local netstat = luci.sys.net.deviceinfo()
53 m.parse = function() end
55 s = m:section(TypedSection, "interface", "")
56 s.template = "cbi/tblsection"
58 function s.filter(self, section)
59 return section ~= "loopback" and section
62 hwaddr = s:option(DummyValue, "_hwaddr")
63 function hwaddr.cfgvalue(self, section)
64 local ix = self.map:get(section, "ifname") or ""
65 return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
69 s:option(DummyValue, "ipaddr", translate("ipaddress"))
71 s:option(DummyValue, "netmask", translate("netmask"))
74 txrx = s:option(DummyValue, "_txrx")
76 function txrx.cfgvalue(self, section)
77 local ix = self.map:get(section, "ifname")
79 local rx = netstat and netstat[ix] and netstat[ix][1]
80 rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
82 local tx = netstat and netstat[ix] and netstat[ix][9]
83 tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
85 return string.format("%s / %s", tx, rx)
88 errors = s:option(DummyValue, "_err")
90 function errors.cfgvalue(self, section)
91 local ix = self.map:get(section, "ifname")
93 local rx = netstat and netstat[ix] and netstat[ix][3]
94 local tx = netstat and netstat[ix] and netstat[ix][11]
96 rx = rx and tostring(rx) or "-"
97 tx = tx and tostring(tx) or "-"
99 return string.format("%s / %s", tx, rx)
104 w2 = Template("mini/index2")