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
16 local sys = require "luci.sys"
17 local zones = require "luci.sys.zoneinfo"
18 local fs = require "nixio.fs"
19 local conf = require "luci.config"
22 local has_ntpd = fs.access("/usr/sbin/ntpd")
24 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
28 s = m:section(TypedSection, "system", translate("System Properties"))
32 s:tab("general", translate("General Settings"))
33 s:tab("logging", translate("Logging"))
34 s:tab("language", translate("Language and Style"))
41 o = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
42 o.template = "admin_system/clock_status"
45 o = s:taboption("general", Value, "hostname", translate("Hostname"))
46 o.datatype = "hostname"
48 function o.write(self, section, value)
49 Value.write(self, section, value)
54 o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
57 for i, zone in ipairs(zones.TZ) do
61 function o.write(self, section, value)
62 local function lookup_zone(title)
63 for _, zone in ipairs(zones.TZ) do
64 if zone[1] == title then return zone[2] end
68 AbstractValue.write(self, section, value)
69 local timezone = lookup_zone(value) or "GMT0"
70 self.map.uci:set("system", section, "timezone", timezone)
71 fs.writefile("/etc/TZ", timezone .. "\n")
79 o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), "kiB")
82 o.datatype = "uinteger"
84 o = s:taboption("logging", Value, "log_ip", translate("External system log server"))
86 o.placeholder = "0.0.0.0"
87 o.datatype = "ip4addr"
89 o = s:taboption("logging", Value, "log_port", translate("External system log server port"))
94 o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
95 o:value(8, translate("Debug"))
96 o:value(7, translate("Info"))
97 o:value(6, translate("Notice"))
98 o:value(5, translate("Warning"))
99 o:value(4, translate("Error"))
100 o:value(3, translate("Critical"))
101 o:value(2, translate("Alert"))
102 o:value(1, translate("Emergency"))
104 o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
106 o:value(5, translate("Debug"))
107 o:value(8, translate("Normal"))
108 o:value(9, translate("Warning"))
115 o = s:taboption("language", ListValue, "_lang", translate("Language"))
118 local i18ndir = luci.i18n.i18ndir .. "base."
119 for k, v in luci.util.kspairs(conf.languages) do
120 local file = i18ndir .. k:gsub("_", "-")
121 if k:sub(1, 1) ~= "." and fs.access(file .. ".lmo") then
126 function o.cfgvalue(...)
127 return m.uci:get("luci", "main", "lang")
130 function o.write(self, section, value)
131 m.uci:set("luci", "main", "lang", value)
135 o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
136 for k, v in pairs(conf.themes) do
137 if k:sub(1, 1) ~= "." then
142 function o.cfgvalue(...)
143 return m.uci:get("luci", "main", "mediaurlbase")
146 function o.write(self, section, value)
147 m.uci:set("luci", "main", "mediaurlbase", value)
157 -- timeserver setup was requested, create section and reload page
158 if m:formvalue("cbid.system._timeserver._enable") then
159 m.uci:section("system", "timeserver", "ntp",
161 server = { "0.openwrt.pool.ntp.org", "1.openwrt.pool.ntp.org", "2.openwrt.pool.ntp.org", "3.openwrt.pool.ntp.org" }
166 luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1]))
170 local has_section = false
171 m.uci:foreach("system", "timeserver",
177 if not has_section then
179 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
181 s.cfgsections = function() return { "_timeserver" } end
183 x = s:option(Button, "_enable")
184 x.title = translate("Time Synchronization is not configured yet.")
185 x.inputtitle = translate("Set up Time Synchronization")
186 x.inputstyle = "apply"
190 s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
194 o = s:option(Flag, "enable", translate("Enable NTP client"))
197 function o.cfgvalue(self)
198 return sys.init.enabled("sysntpd")
199 and self.enabled or self.disabled
202 function o.write(self, section, value)
203 if value == self.enabled then
204 sys.init.enable("sysntpd")
205 sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
207 sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
208 sys.init.disable("sysntpd")
213 o = s:option(Flag, "enable_server", translate("Provide NTP server"))
214 o:depends("enable", "1")
217 o = s:option(DynamicList, "server", translate("NTP server candidates"))
219 o:depends("enable", "1")
221 -- retain server list even if disabled
222 function o.remove() end