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."))
22 local has_rdate = false
24 m.uci:foreach("system", "rdate",
31 s = m:section(TypedSection, "system", "")
35 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
36 local uptime = luci.sys.uptime()
38 s:option(DummyValue, "_system", translate("System")).value = system
39 s:option(DummyValue, "_cpu", translate("Processor")).value = model
41 local load1, load5, load15 = luci.sys.loadavg()
42 s:option(DummyValue, "_la", translate("Load")).value =
43 string.format("%.2f, %.2f, %.2f", load1, load5, load15)
45 s:option(DummyValue, "_memtotal", translate("Memory")).value =
46 string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
47 tonumber(memtotal) / 1024,
48 100 * memcached / memtotal,
49 tostring(translate("cached")),
50 100 * membuffers / memtotal,
51 tostring(translate("buffered")),
52 100 * memfree / memtotal,
53 tostring(translate("free"))
56 s:option(DummyValue, "_systime", translate("Local Time")).value =
59 s:option(DummyValue, "_uptime", translate("Uptime")).value =
60 luci.tools.webadmin.date_format(tonumber(uptime))
62 hn = s:option(Value, "hostname", translate("Hostname"))
64 function hn.write(self, section, value)
65 Value.write(self, section, value)
66 luci.sys.hostname(value)
70 tz = s:option(ListValue, "zonename", translate("Timezone"))
73 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
77 function tz.write(self, section, value)
78 local function lookup_zone(title)
79 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
80 if zone[1] == title then return zone[2] end
84 AbstractValue.write(self, section, value)
85 local timezone = lookup_zone(value) or "GMT0"
86 self.map.uci:set("system", section, "timezone", timezone)
87 luci.fs.writefile("/etc/TZ", timezone .. "\n")
90 s:option(Value, "log_size", translate("System log buffer size"), "kiB").optional = true
91 s:option(Value, "log_ip", translate("External system log server")).optional = true
92 s:option(Value, "log_port", translate("External system log server port")).optional = true
93 s:option(Value, "conloglevel", translate("Log output level")).optional = true
94 s:option(Value, "cronloglevel", translate("Cron Log Level")).optional = true
97 s2 = m:section(TypedSection, "rdate", translate("Time Server (rdate)"))
101 s2:option(DynamicList, "server", translate("Server"))