modules/admin-full: display kernel version
[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("Here you can configure the basic aspects of your device like its hostname or the timezone."))
21
22 local has_rdate = false
23
24 m.uci:foreach("system", "rdate",
25         function()
26                 has_rdate = true
27                 return false
28         end)
29
30
31 s = m:section(TypedSection, "system", "")
32 s.anonymous = true
33 s.addremove = false
34
35 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
36 local uptime = luci.sys.uptime()
37
38 s:option(DummyValue, "_system", translate("System")).value = system
39 s:option(DummyValue, "_cpu", translate("Processor")).value = model
40
41 s:option(DummyValue, "_kernel", translate("Kernel")).value =
42  luci.util.exec("uname -r") or "?"
43
44 local load1, load5, load15 = luci.sys.loadavg()
45 s:option(DummyValue, "_la", translate("Load")).value =
46  string.format("%.2f, %.2f, %.2f", load1, load5, load15)
47
48 s:option(DummyValue, "_memtotal", translate("Memory")).value =
49  string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
50   tonumber(memtotal) / 1024,
51   100 * memcached / memtotal,
52   tostring(translate("cached")),
53   100 * membuffers / memtotal,
54   tostring(translate("buffered")),
55   100 * memfree / memtotal,
56   tostring(translate("free"))
57 )
58
59 s:option(DummyValue, "_systime", translate("Local Time")).value =
60  os.date("%c")
61
62 s:option(DummyValue, "_uptime", translate("Uptime")).value =
63  luci.tools.webadmin.date_format(tonumber(uptime))
64
65 hn = s:option(Value, "hostname", translate("Hostname"))
66
67 function hn.write(self, section, value)
68         Value.write(self, section, value)
69         luci.sys.hostname(value)
70 end
71
72
73 tz = s:option(ListValue, "zonename", translate("Timezone"))
74 tz:value("UTC")
75
76 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
77         tz:value(zone[1])
78 end
79
80 function tz.write(self, section, value)
81         local function lookup_zone(title)
82                 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
83                         if zone[1] == title then return zone[2] end
84                 end
85         end
86
87         AbstractValue.write(self, section, value)
88         local timezone = lookup_zone(value) or "GMT0"
89         self.map.uci:set("system", section, "timezone", timezone)
90         luci.fs.writefile("/etc/TZ", timezone .. "\n")
91 end
92
93 s:option(Value, "log_size", translate("System log buffer size"), "kiB").optional = true
94 s:option(Value, "log_ip", translate("External system log server")).optional = true
95 s:option(Value, "log_port", translate("External system log server port")).optional = true
96 s:option(Value, "conloglevel", translate("Log output level")).optional = true
97 s:option(Value, "cronloglevel", translate("Cron Log Level")).optional = true
98
99 if has_rdate then
100         s2 = m:section(TypedSection, "rdate", translate("Time Server (rdate)"))
101         s2.anonymous = true
102         s2.addremove = false
103
104         s2:option(DynamicList, "server", translate("Server"))
105 end
106
107 return m