2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
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
10 http://www.apache.org/licenses/LICENSE-2.0
16 require("luci.sys.zoneinfo")
17 require("luci.tools.webadmin")
20 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
23 local has_rdate = false
25 m.uci:foreach("system", "rdate",
32 m.uci:section("system", "rdate", nil, { })
38 s = m:section(TypedSection, "system", "")
42 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
43 local uptime = luci.sys.uptime()
45 s:option(DummyValue, "_system", translate("System")).value = system
46 s:option(DummyValue, "_cpu", translate("Processor")).value = model
48 local load1, load5, load15 = luci.sys.loadavg()
49 s:option(DummyValue, "_la", translate("Load")).value =
50 string.format("%.2f, %.2f, %.2f", load1, load5, load15)
52 s:option(DummyValue, "_memtotal", translate("Memory")).value =
53 string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
54 tonumber(memtotal) / 1024,
55 100 * memcached / memtotal,
56 tostring(translate("cached")),
57 100 * membuffers / memtotal,
58 tostring(translate("buffered")),
59 100 * memfree / memtotal,
60 tostring(translate("free"))
63 s:option(DummyValue, "_systime", translate("Local Time")).value =
66 s:option(DummyValue, "_uptime", translate("Uptime")).value =
67 luci.tools.webadmin.date_format(tonumber(uptime))
69 hn = s:option(Value, "hostname", translate("Hostname"))
71 function hn.write(self, section, value)
72 Value.write(self, section, value)
73 luci.sys.hostname(value)
77 tz = s:option(ListValue, "zonename", translate("Timezone"))
80 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
84 function tz.write(self, section, value)
85 local function lookup_zone(title)
86 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
87 if zone[1] == title then return zone[2] end
91 AbstractValue.write(self, section, value)
92 local timezone = lookup_zone(value) or "GMT0"
93 self.map.uci:set("system", section, "timezone", timezone)
94 luci.fs.writefile("/etc/TZ", timezone .. "\n")
97 s:option(Value, "log_size", translate("System log buffer size"), "kiB").optional = true
98 s:option(Value, "log_ip", translate("External system log server")).optional = true
99 s:option(Value, "log_port", translate("External system log server port")).optional = true
100 s:option(Value, "conloglevel", translate("Log output level")).optional = true
101 s:option(Value, "cronloglevel", translate("Cron Log Level")).optional = true
103 s2 = m:section(TypedSection, "rdate", translate("Time Server (rdate)"))
107 s2:option(DynamicList, "server", translate("Server"))