* luci/modules/admin-{mini,full}: allow custom values in timezone selection
[project/luci.git] / modules / 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 require("luci.http.protocol.date")
15 require("luci.sys")
16 require("luci.tools.webadmin")
17
18
19 m = Map("system", translate("system"), translate("a_s_desc"))
20
21 s = m:section(TypedSection, "system", "")
22 s.anonymous = true
23
24
25
26 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
27 local uptime = luci.sys.uptime()
28
29 s:option(DummyValue, "_system", translate("system")).value = system
30 s:option(DummyValue, "_cpu", translate("m_i_processor")).value = model
31
32 local load1, load5, load15 = luci.sys.loadavg()
33 s:option(DummyValue, "_la", translate("load")).value =
34 string.format("%.2f, %.2f, %.2f", load1, load5, load15)
35
36 s:option(DummyValue, "_memtotal", translate("m_i_memory")).value =
37 string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
38 tonumber(memtotal) / 1024,
39 100 * memcached / memtotal,
40 translate("mem_cached") or "",
41 100 * membuffers / memtotal,
42 translate("mem_buffered") or "",
43 100 * memfree / memtotal,
44 translate("mem_free") or "")
45
46 s:option(DummyValue, "_systime", translate("m_i_systemtime")).value =
47 os.date("%c")
48
49 s:option(DummyValue, "_uptime", translate("m_i_uptime")).value =
50 luci.tools.webadmin.date_format(tonumber(uptime))
51
52
53
54
55
56 s:option(Value, "hostname", translate("hostname"))
57
58 tz = s:option(Value, "timezone", translate("timezone"))
59 for k, offset in luci.util.vspairs(luci.http.protocol.date.TZ) do
60 local zone = k:upper()
61 local osgn = (offset >= 0 and "" or "+")
62 local ohrs = math.floor(-offset / 3600)
63 local omin = (offset % 3600) / 60
64
65 local ptz = zone .. osgn .. (ohrs ~= 0 and ohrs or "") .. (omin ~= 0 and ":" .. omin or "")
66 local dtz = string.format("%+03d:%02d ", ohrs, omin) .. zone
67
68 tz:value(ptz, dtz)
69 end
70
71 return m