1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
5 local sys = require "luci.sys"
6 local zones = require "luci.sys.zoneinfo"
7 local fs = require "nixio.fs"
8 local conf = require "luci.config"
11 local has_ntpd = fs.access("/usr/sbin/ntpd")
13 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
17 s = m:section(TypedSection, "system", translate("System Properties"))
21 s:tab("general", translate("General Settings"))
22 s:tab("logging", translate("Logging"))
23 s:tab("language", translate("Language and Style"))
30 o = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
31 o.template = "admin_system/clock_status"
34 o = s:taboption("general", Value, "hostname", translate("Hostname"))
35 o.datatype = "hostname"
37 function o.write(self, section, value)
38 Value.write(self, section, value)
43 o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
46 for i, zone in ipairs(zones.TZ) do
50 function o.write(self, section, value)
51 local function lookup_zone(title)
52 for _, zone in ipairs(zones.TZ) do
53 if zone[1] == title then return zone[2] end
57 AbstractValue.write(self, section, value)
58 local timezone = lookup_zone(value) or "GMT0"
59 self.map.uci:set("system", section, "timezone", timezone)
60 fs.writefile("/etc/TZ", timezone .. "\n")
68 o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), "kiB")
71 o.datatype = "uinteger"
73 o = s:taboption("logging", Value, "log_ip", translate("External system log server"))
75 o.placeholder = "0.0.0.0"
76 o.datatype = "ip4addr"
78 o = s:taboption("logging", Value, "log_port", translate("External system log server port"))
83 o = s:taboption("logging", ListValue, "log_proto", translate("External system log server protocol"))
87 o = s:taboption("logging", Value, "log_file", translate("Write system log to file"))
89 o.placeholder = "/tmp/system.log"
91 o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
92 o:value(8, translate("Debug"))
93 o:value(7, translate("Info"))
94 o:value(6, translate("Notice"))
95 o:value(5, translate("Warning"))
96 o:value(4, translate("Error"))
97 o:value(3, translate("Critical"))
98 o:value(2, translate("Alert"))
99 o:value(1, translate("Emergency"))
101 o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
103 o:value(5, translate("Debug"))
104 o:value(8, translate("Normal"))
105 o:value(9, translate("Warning"))
112 o = s:taboption("language", ListValue, "_lang", translate("Language"))
115 local i18ndir = luci.i18n.i18ndir .. "base."
116 for k, v in luci.util.kspairs(conf.languages) do
117 local file = i18ndir .. k:gsub("_", "-")
118 if k:sub(1, 1) ~= "." and fs.access(file .. ".lmo") then
123 function o.cfgvalue(...)
124 return m.uci:get("luci", "main", "lang")
127 function o.write(self, section, value)
128 m.uci:set("luci", "main", "lang", value)
132 o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
133 for k, v in pairs(conf.themes) do
134 if k:sub(1, 1) ~= "." then
139 function o.cfgvalue(...)
140 return m.uci:get("luci", "main", "mediaurlbase")
143 function o.write(self, section, value)
144 m.uci:set("luci", "main", "mediaurlbase", value)
154 -- timeserver setup was requested, create section and reload page
155 if m:formvalue("cbid.system._timeserver._enable") then
156 m.uci:section("system", "timeserver", "ntp",
158 server = { "0.openwrt.pool.ntp.org", "1.openwrt.pool.ntp.org", "2.openwrt.pool.ntp.org", "3.openwrt.pool.ntp.org" }
163 luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1]))
167 local has_section = false
168 m.uci:foreach("system", "timeserver",
174 if not has_section then
176 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
178 s.cfgsections = function() return { "_timeserver" } end
180 x = s:option(Button, "_enable")
181 x.title = translate("Time Synchronization is not configured yet.")
182 x.inputtitle = translate("Set up Time Synchronization")
183 x.inputstyle = "apply"
187 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
191 o = s:option(Flag, "enable", translate("Enable NTP client"))
194 function o.cfgvalue(self)
195 return sys.init.enabled("sysntpd")
196 and self.enabled or self.disabled
199 function o.write(self, section, value)
200 if value == self.enabled then
201 sys.init.enable("sysntpd")
202 sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
204 sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
205 sys.init.disable("sysntpd")
210 o = s:option(Flag, "enable_server", translate("Provide NTP server"))
211 o:depends("enable", "1")
214 o = s:option(DynamicList, "server", translate("NTP server candidates"))
215 o.datatype = "host(0)"
216 o:depends("enable", "1")
218 -- retain server list even if disabled
219 function o.remove() end