593af04f25f3db2e81b9fbc73ace886b9adb6798
[project/luci.git] / modules / luci-mod-admin-mini / luasrc / model / cbi / mini / system.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
15 require("luci.sys")
16 require("luci.sys.zoneinfo")
17 require("luci.tools.webadmin")
18
19
20 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
21
22 s = m:section(TypedSection, "system", "")
23 s.anonymous = true
24 s.addremove = false
25
26
27 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
28 local uptime = luci.sys.uptime()
29
30 s:option(DummyValue, "_system", translate("System")).value = model
31 s:option(DummyValue, "_cpu", translate("Processor")).value = system
32
33 local load1, load5, load15 = luci.sys.loadavg()
34 s:option(DummyValue, "_la", translate("Load")).value =
35  string.format("%.2f, %.2f, %.2f", load1, load5, load15)
36
37 s:option(DummyValue, "_memtotal", translate("Memory")).value =
38  string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
39   tonumber(memtotal) / 1024,
40   100 * memcached / memtotal,
41   tostring(translate("cached")),
42   100 * membuffers / memtotal,
43   tostring(translate("buffered")),
44   100 * memfree / memtotal,
45   tostring(translate("free"))
46 )
47
48 s:option(DummyValue, "_systime", translate("Local Time")).value =
49  os.date("%c")
50
51 s:option(DummyValue, "_uptime", translate("Uptime")).value =
52  luci.tools.webadmin.date_format(tonumber(uptime))
53
54 hn = s:option(Value, "hostname", translate("Hostname"))
55
56 function hn.write(self, section, value)
57         Value.write(self, section, value)
58         luci.sys.hostname(value)
59 end
60
61
62 tz = s:option(ListValue, "zonename", translate("Timezone"))
63 tz:value("UTC")
64
65 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
66         tz:value(zone[1])
67 end
68
69 function tz.write(self, section, value)
70         local function lookup_zone(title)
71                 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
72                         if zone[1] == title then return zone[2] end
73                 end
74         end
75
76         AbstractValue.write(self, section, value)
77         self.map.uci:set("system", section, "timezone", lookup_zone(value) or "GMT0")
78 end
79
80 return m