luci-0.9: merge r5920-5922
[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 require("luci.fs")
19
20 m = Map("system", translate("system"), translate("a_s_desc"))
21
22 s = m:section(TypedSection, "system", "")
23 s.anonymous = true
24 s.addremove = false
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 tostring(translate("mem_cached", "")),
41 100 * membuffers / memtotal,
42 tostring(translate("mem_buffered", "")),
43 100 * memfree / memtotal,
44 tostring(translate("mem_free", ""))
45 )
46
47 s:option(DummyValue, "_systime", translate("m_i_systemtime")).value =
48 os.date("%c")
49
50 s:option(DummyValue, "_uptime", translate("m_i_uptime")).value =
51 luci.tools.webadmin.date_format(tonumber(uptime))
52
53 hn = s:option(Value, "hostname", translate("hostname"))
54
55 function hn.write(self, section, value)
56 Value.write(self, section, value)
57 luci.sys.hostname(value)
58 end
59
60
61 tz = s:option(ListValue, "zonename", translate("timezone"))
62 tz:value("UTC")
63
64 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
65 tz:value(zone[1])
66 end
67
68 function tz.write(self, section, value)
69 local function lookup_zone(title)
70 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
71 if zone[1] == title then return zone[2] end
72 end
73 end
74
75 AbstractValue.write(self, section, value)
76 local timezone = lookup_zone(value) or "GMT0"
77 self.map.uci:set("system", section, "timezone", timezone)
78 luci.fs.writefile("/etc/TZ", timezone .. "\n")
79 end
80
81 s:option(Value, "log_size", nil, "kiB").optional = true
82 s:option(Value, "log_ip").optional = true
83 s:option(Value, "conloglevel").optional = true
84 s:option(Value, "cronloglevel").optional = true
85 return m