2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
17 require("luci.sys.zoneinfo")
18 require("luci.tools.webadmin")
20 require("luci.config")
23 local has_ntpd = luci.fs.access("/usr/sbin/ntpd")
26 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
30 s = m:section(TypedSection, "system", translate("System Properties"))
34 s:tab("general", translate("General Settings"))
35 s:tab("logging", translate("Logging"))
36 s:tab("language", translate("Language and Style"))
43 o = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
44 o.template = "admin_system/clock_status"
47 o = s:taboption("general", Value, "hostname", translate("Hostname"))
48 o.datatype = "hostname"
50 function o.write(self, section, value)
51 Value.write(self, section, value)
52 luci.sys.hostname(value)
56 o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
59 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
63 function o.write(self, section, value)
64 local function lookup_zone(title)
65 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
66 if zone[1] == title then return zone[2] end
70 AbstractValue.write(self, section, value)
71 local timezone = lookup_zone(value) or "GMT0"
72 self.map.uci:set("system", section, "timezone", timezone)
73 luci.fs.writefile("/etc/TZ", timezone .. "\n")
81 o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), "kiB")
84 o.datatype = "uinteger"
86 o = s:taboption("logging", Value, "log_ip", translate("External system log server"))
88 o.placeholder = "0.0.0.0"
89 o.datatype = "ip4addr"
91 o = s:taboption("logging", Value, "log_port", translate("External system log server port"))
96 o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
97 o:value(8, translate("Debug"))
98 o:value(7, translate("Info"))
99 o:value(6, translate("Notice"))
100 o:value(5, translate("Warning"))
101 o:value(4, translate("Error"))
102 o:value(3, translate("Critical"))
103 o:value(2, translate("Alert"))
104 o:value(1, translate("Emergency"))
106 o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
108 o:value(5, translate("Debug"))
109 o:value(8, translate("Normal"))
110 o:value(9, translate("Warning"))
117 o = s:taboption("language", ListValue, "_lang", translate("Language"))
120 local i18ndir = luci.i18n.i18ndir .. "base."
121 for k, v in luci.util.kspairs(luci.config.languages) do
122 local file = i18ndir .. k:gsub("_", "-")
123 if k:sub(1, 1) ~= "." and luci.fs.access(file .. ".lmo") then
128 function o.cfgvalue(...)
129 return m.uci:get("luci", "main", "lang")
132 function o.write(self, section, value)
133 m.uci:set("luci", "main", "lang", value)
137 o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
138 for k, v in pairs(luci.config.themes) do
139 if k:sub(1, 1) ~= "." then
144 function o.cfgvalue(...)
145 return m.uci:get("luci", "main", "mediaurlbase")
148 function o.write(self, section, value)
149 m.uci:set("luci", "main", "mediaurlbase", value)
158 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
162 o = s:option(Flag, "enable", translate("Enable builtin NTP server"))
165 function o.cfgvalue(self)
166 return luci.sys.init.enabled("sysntpd")
167 and self.enabled or self.disabled
170 function o.write(self, section, value)
171 if value == self.enabled then
172 luci.sys.init.enable("sysntpd")
173 luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
175 luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
176 luci.sys.init.disable("sysntpd")
181 o = s:option(DynamicList, "server", translate("NTP server candidates"))
183 o:depends("enable", "1")
185 -- retain server list even if disabled
186 function o.remove() end