Globally reduce copyright headers
[project/luci.git] / modules / luci-mod-admin-mini / luasrc / model / cbi / mini / system.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 require("luci.sys")
5 require("luci.sys.zoneinfo")
6 require("luci.tools.webadmin")
7 require("luci.util")
8
9
10 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
11
12 s = m:section(TypedSection, "system", "")
13 s.anonymous = true
14 s.addremove = false
15
16
17 local sysinfo = luci.util.ubus("system", "info") or { }
18 local boardinfo = luci.util.ubus("system", "board") or { }
19
20 local uptime = sysinfo.uptime or 0
21 local loads = sysinfo.load or { 0, 0, 0 }
22 local memory = sysinfo.memory or {
23         total = 0,
24         free = 0,
25         buffered = 0,
26         shared = 0
27 }
28
29 s:option(DummyValue, "_system", translate("Model")).value = boardinfo.model or "?"
30 s:option(DummyValue, "_cpu", translate("System")).value = boardinfo.system or "?"
31
32 s:option(DummyValue, "_la", translate("Load")).value =
33  string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0)
34
35 s:option(DummyValue, "_memtotal", translate("Memory")).value =
36  string.format("%.2f MB (%.0f%% %s, %.0f%% %s)",
37   tonumber(memory.total) / 1024 / 1024,
38   100 * memory.buffered / memory.total,
39   tostring(translate("buffered")),
40   100 * memory.free / memory.total,
41   tostring(translate("free"))
42 )
43
44 s:option(DummyValue, "_systime", translate("Local Time")).value =
45  os.date("%c")
46
47 s:option(DummyValue, "_uptime", translate("Uptime")).value =
48  luci.tools.webadmin.date_format(tonumber(uptime))
49
50 hn = s:option(Value, "hostname", translate("Hostname"))
51
52 function hn.write(self, section, value)
53         Value.write(self, section, value)
54         luci.sys.hostname(value)
55 end
56
57
58 tz = s:option(ListValue, "zonename", translate("Timezone"))
59 tz:value("UTC")
60
61 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
62         tz:value(zone[1])
63 end
64
65 function tz.write(self, section, value)
66         local function lookup_zone(title)
67                 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
68                         if zone[1] == title then return zone[2] end
69                 end
70         end
71
72         AbstractValue.write(self, section, value)
73         self.map.uci:set("system", section, "timezone", lookup_zone(value) or "GMT0")
74 end
75
76 return m