eb7d77eb1728a194f7ff9d00dedcb4cb81c61fbb
[project/luci.git] / modules / admin-mini / luasrc / model / cbi / mini / index.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 require("luci.sys")
15 require("luci.tools.webadmin")
16
17 w = Template("mini/index")
18
19 f = SimpleForm("main", translate("system"))
20 f.reset = false
21 f.submit = false
22
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
27
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)
31
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 "")
41
42 f:field(DummyValue, "_systime", translate("m_i_systemtime")).value =
43 os.date("%c")
44
45 f:field(DummyValue, "_uptime", translate("m_i_uptime")).value =
46 luci.tools.webadmin.date_format(tonumber(uptime))
47
48
49 m = Map("network", translate("interfaces"))
50 local netstat = luci.sys.net.deviceinfo()
51
52 m.parse = function() end
53
54 s = m:section(TypedSection, "interface", "")
55 s.template = "cbi/tblsection"
56
57 function s.filter(self, section)
58 return section ~= "loopback" and section
59 end
60
61 hwaddr = s:option(DummyValue, "_hwaddr")
62 function hwaddr.cfgvalue(self, section)
63 local ix = self.map:stateget(section, "ifname") or ""
64 return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
65 end
66
67
68 ipaddr = s:option(DummyValue, "ipaddr", translate("ipaddress"))
69 ipaddr.stateful = true
70
71 ipaddr = s:option(DummyValue, "netmask", translate("netmask"))
72 ipaddr.stateful = true
73
74 txrx = s:option(DummyValue, "_txrx")
75
76 function txrx.cfgvalue(self, section)
77 local ix = self.map:stateget(section, "ifname")
78
79 local rx = netstat and netstat[ix] and netstat[ix][1]
80 rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
81
82 local tx = netstat and netstat[ix] and netstat[ix][9]
83 tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-"
84
85 return string.format("%s / %s", tx, rx)
86 end
87
88 errors = s:option(DummyValue, "_err")
89
90 function errors.cfgvalue(self, section)
91 local ix = self.map:stateget(section, "ifname")
92
93 local rx = netstat and netstat[ix] and netstat[ix][3]
94 local tx = netstat and netstat[ix] and netstat[ix][11]
95
96 rx = rx and tostring(rx) or "-"
97 tx = tx and tostring(tx) or "-"
98
99 return string.format("%s / %s", tx, rx)
100 end
101
102
103
104 w2 = Template("mini/index2")
105 return w, f, m, w2