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")
12 local has_zram = fs.access("/etc/init.d/zram")
14 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
18 s = m:section(TypedSection, "system", translate("System Properties"))
22 s:tab("general", translate("General Settings"))
23 s:tab("logging", translate("Logging"))
24 s:tab("language", translate("Language and Style"))
25 s:tab("advanced", translate("Advanced"))
26 if has_zram then s:tab("zram", translate("ZRam Settings")) end
32 o = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
33 o.template = "admin_system/clock_status"
36 o = s:taboption("general", Value, "hostname", translate("Hostname"))
37 o.datatype = "hostname"
39 function o.write(self, section, value)
40 Value.write(self, section, value)
45 o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
48 for i, zone in ipairs(zones.TZ) do
52 function o.write(self, section, value)
53 local function lookup_zone(title)
54 for _, zone in ipairs(zones.TZ) do
55 if zone[1] == title then return zone[2] end
59 AbstractValue.write(self, section, value)
60 local timezone = lookup_zone(value) or "GMT0"
61 self.map.uci:set("system", section, "timezone", timezone)
62 fs.writefile("/etc/TZ", timezone .. "\n")
70 o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), translate("KiB"))
73 o.datatype = "uinteger"
75 o = s:taboption("logging", Value, "log_ip", translate("External system log server"))
77 o.placeholder = "0.0.0.0"
78 o.datatype = "ip4addr"
80 o = s:taboption("logging", Value, "log_port", translate("External system log server port"))
85 o = s:taboption("logging", ListValue, "log_proto", translate("External system log server protocol"))
89 o = s:taboption("logging", Value, "log_file", translate("Write system log to file"))
91 o.placeholder = "/tmp/system.log"
93 o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
94 o:value(8, translate("Debug"))
95 o:value(7, translate("Info"))
96 o:value(6, translate("Notice"))
97 o:value(5, translate("Warning"))
98 o:value(4, translate("Error"))
99 o:value(3, translate("Critical"))
100 o:value(2, translate("Alert"))
101 o:value(1, translate("Emergency"))
103 o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
105 o:value(5, translate("Debug"))
106 o:value(8, translate("Normal"))
107 o:value(9, translate("Warning"))
114 o = s:taboption("zram", Value, "zram_size_mb", translate("ZRam Size"), translate("Size of the ZRam device in megabytes"))
117 o.datatype = "uinteger"
119 o = s:taboption("zram", ListValue, "zram_comp_algo", translate("ZRam Compression Algorithm"))
122 o:value("lzo", "lzo")
123 o:value("lz4", "lz4")
124 o:value("deflate", "deflate")
126 o = s:taboption("zram", Value, "zram_comp_streams", translate("ZRam Compression Streams"), translate("Number of parallel threads used for compression"))
129 o.datatype = "uinteger"
137 o = s:taboption("language", ListValue, "_lang", translate("Language"))
140 local i18ndir = luci.i18n.i18ndir .. "base."
141 for k, v in luci.util.kspairs(conf.languages) do
142 local file = i18ndir .. k:gsub("_", "-")
143 if k:sub(1, 1) ~= "." and fs.access(file .. ".lmo") then
148 function o.cfgvalue(...)
149 return m.uci:get("luci", "main", "lang")
152 function o.write(self, section, value)
153 m.uci:set("luci", "main", "lang", value)
157 o = s:taboption("language", ListValue, "_mediaurlbase", translate("Theme"))
158 for k, v in pairs(conf.themes) do
159 if k:sub(1, 1) ~= "." then
164 function o.cfgvalue(...)
165 return m.uci:get("luci", "main", "mediaurlbase")
168 function o.write(self, section, value)
169 m.uci:set("luci", "main", "mediaurlbase", value)
177 o = s:taboption("advanced", Value, "_pollinterval",
178 translate("Polling interval"),
179 translate("Polling interval for status queries in seconds"))
180 o.datatype = "range(3, 20)"
186 function o.cfgvalue(...)
187 return m.uci:get("luci", "main", "pollinterval")
190 function o.write(self, section, value)
191 m.uci:set("luci", "main", "pollinterval", value)
201 -- timeserver setup was requested, create section and reload page
202 if m:formvalue("cbid.system._timeserver._enable") then
203 m.uci:section("system", "timeserver", "ntp",
205 server = { "0.openwrt.pool.ntp.org", "1.openwrt.pool.ntp.org", "2.openwrt.pool.ntp.org", "3.openwrt.pool.ntp.org" }
210 luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1]))
214 local has_section = false
215 m.uci:foreach("system", "timeserver",
221 if not has_section then
223 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
225 s.cfgsections = function() return { "_timeserver" } end
227 x = s:option(Button, "_enable")
228 x.title = translate("Time Synchronization is not configured yet.")
229 x.inputtitle = translate("Set up Time Synchronization")
230 x.inputstyle = "apply"
234 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
238 o = s:option(Flag, "enable", translate("Enable NTP client"))
241 function o.cfgvalue(self)
242 return sys.init.enabled("sysntpd")
243 and self.enabled or self.disabled
246 function o.write(self, section, value)
247 if value == self.enabled then
248 sys.init.enable("sysntpd")
249 sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
251 sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
252 sys.init.disable("sysntpd")
257 o = s:option(Flag, "enable_server", translate("Provide NTP server"))
258 o:depends("enable", "1")
261 o = s:option(DynamicList, "server", translate("NTP server candidates"))
262 o.datatype = "host(0)"
263 o:depends("enable", "1")
265 -- retain server list even if disabled
266 function o.remove() end