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")
25 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
29 s = m:section(TypedSection, "system", translate("System Properties"))
33 s:tab("general", translate("General Settings"))
34 s:tab("logging", translate("Logging"))
35 s:tab("language", translate("Language and Style"))
42 o = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
43 o.template = "admin_system/clock_status"
46 o = s:taboption("general", Value, "hostname", translate("Hostname"))
47 o.datatype = "hostname"
49 function o.write(self, section, value)
50 Value.write(self, section, value)
51 luci.sys.hostname(value)
55 o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
58 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
62 function o.write(self, section, value)
63 local function lookup_zone(title)
64 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
65 if zone[1] == title then return zone[2] end
69 AbstractValue.write(self, section, value)
70 local timezone = lookup_zone(value) or "GMT0"
71 self.map.uci:set("system", section, "timezone", timezone)
72 luci.fs.writefile("/etc/TZ", timezone .. "\n")
80 o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), "kiB")
83 o.datatype = "uinteger"
85 o = s:taboption("logging", Value, "log_ip", translate("External system log server"))
87 o.placeholder = "0.0.0.0"
88 o.datatype = "ip4addr"
90 o = s:taboption("logging", Value, "log_port", translate("External system log server port"))
95 o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
96 o:value(8, translate("Debug"))
97 o:value(7, translate("Info"))
98 o:value(6, translate("Notice"))
99 o:value(5, translate("Warning"))
100 o:value(4, translate("Error"))
101 o:value(3, translate("Critical"))
102 o:value(2, translate("Alert"))
103 o:value(1, translate("Emergency"))
105 o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
107 o:value(5, translate("Debug"))
108 o:value(8, translate("Normal"))
109 o:value(9, translate("Warning"))
116 o = s:taboption("language", ListValue, "_lang", translate("Language"))
119 local i18ndir = luci.i18n.i18ndir .. "base."
120 for k, v in luci.util.kspairs(luci.config.languages) do
121 local file = i18ndir .. k:gsub("_", "-")
122 if k:sub(1, 1) ~= "." and luci.fs.access(file .. ".lmo") then
127 function o.cfgvalue(...)
128 return m.uci:get("luci", "main", "lang")
131 function o.write(self, section, value)
132 m.uci:set("luci", "main", "lang", value)
136 o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
137 for k, v in pairs(luci.config.themes) do
138 if k:sub(1, 1) ~= "." then
143 function o.cfgvalue(...)
144 return m.uci:get("luci", "main", "mediaurlbase")
147 function o.write(self, section, value)
148 m.uci:set("luci", "main", "mediaurlbase", value)
158 -- timeserver setup was requested, create section and reload page
159 if m:formvalue("cbid.system._timeserver._enable") then
160 m.uci:section("system", "timeserver", "ntp",
162 server = { "0.openwrt.pool.ntp.org", "1.openwrt.pool.ntp.org", "2.openwrt.pool.ntp.org", "3.openwrt.pool.ntp.org" }
167 luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1]))
171 local has_section = false
172 m.uci:foreach("system", "timeserver",
178 if not has_section then
180 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
182 s.cfgsections = function() return { "_timeserver" } end
184 x = s:option(Button, "_enable")
185 x.title = translate("Time Synchronization is not configured yet.")
186 x.inputtitle = translate("Setup Time Synchronization")
187 x.inputstyle = "apply"
191 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
195 o = s:option(Flag, "enable", translate("Enable builtin NTP server"))
198 function o.cfgvalue(self)
199 return luci.sys.init.enabled("sysntpd")
200 and self.enabled or self.disabled
203 function o.write(self, section, value)
204 if value == self.enabled then
205 luci.sys.init.enable("sysntpd")
206 luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
208 luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
209 luci.sys.init.disable("sysntpd")
214 o = s:option(DynamicList, "server", translate("NTP server candidates"))
216 o:depends("enable", "1")
218 -- retain server list even if disabled
219 function o.remove() end