* luci/modules/admin-{core,mini,full}: implement new zoneinfo in system models
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_system / 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 m = Map("system", translate("system"), translate("a_s_desc"))
20
21 s = m:section(TypedSection, "system", "")
22 s.anonymous = true
23
24 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
25 local uptime = luci.sys.uptime()
26
27 s:option(DummyValue, "_system", translate("system")).value = system
28 s:option(DummyValue, "_cpu", translate("m_i_processor")).value = model
29
30 local load1, load5, load15 = luci.sys.loadavg()
31 s:option(DummyValue, "_la", translate("load")).value =
32 string.format("%.2f, %.2f, %.2f", load1, load5, load15)
33
34 s:option(DummyValue, "_memtotal", translate("m_i_memory")).value =
35 string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
36 tonumber(memtotal) / 1024,
37 100 * memcached / memtotal,
38 translate("mem_cached") or "",
39 100 * membuffers / memtotal,
40 translate("mem_buffered") or "",
41 100 * memfree / memtotal,
42 translate("mem_free") or "")
43
44 s:option(DummyValue, "_systime", translate("m_i_systemtime")).value =
45 os.date("%c")
46
47 s:option(DummyValue, "_uptime", translate("m_i_uptime")).value =
48 luci.tools.webadmin.date_format(tonumber(uptime))
49
50 s:option(Value, "hostname", translate("hostname"))
51
52 tz = s:option(ListValue, "zonename", translate("timezone"))
53 tz:value("UTC")
54
55 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
56 tz:value(zone[1])
57 end
58
59 function tz.write(self, section, value)
60 local function lookup_zone(title)
61 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
62 if zone[1] == title then return zone[2] end
63 end
64 end
65
66 AbstractValue.write(self, section, value)
67 self.map.uci:set("system", section, "timezone", lookup_zone(value) or "GMT0")
68 end
69
70 s:option(Value, "log_size", nil, "kiB").optional = true
71 s:option(Value, "log_ip").optional = true
72 s:option(Value, "conloglevel").optional = true
73 return m