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 s:option(DummyValue, "_kernel", translate("Kernel")).value =
42 luci.util.exec("uname -r") or "?"
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)
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"))
59 s:option(DummyValue, "_systime", translate("Local Time")).value =
62 s:option(DummyValue, "_uptime", translate("Uptime")).value =
63 luci.tools.webadmin.date_format(tonumber(uptime))
65 hn = s:option(Value, "hostname", translate("Hostname"))
67 function hn.write(self, section, value)
68 Value.write(self, section, value)
69 luci.sys.hostname(value)
73 tz = s:option(ListValue, "zonename", translate("Timezone"))
76 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
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
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")
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
100 s2 = m:section(TypedSection, "rdate", translate("Time Server (rdate)"))
104 s2:option(DynamicList, "server", translate("Server"))