require("luci.fs")
require("luci.config")
+local m, s, o
+local has_ntpd = luci.fs.access("/usr/sbin/ntpd")
+
m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
m:chain("luci")
-local has_rdate = false
-
-m.uci:foreach("system", "rdate",
- function()
- has_rdate = true
- return false
- end)
-
s = m:section(TypedSection, "system", translate("System Properties"))
s.anonymous = true
-- System Properties
--
-local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
-local uptime = luci.sys.uptime()
-
-s:taboption("general", DummyValue, "_system", translate("System")).value = system
-s:taboption("general", DummyValue, "_cpu", translate("Processor")).value = model
+o = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
+o.template = "admin_system/clock_status"
-s:taboption("general", DummyValue, "_kernel", translate("Kernel")).value =
- luci.util.exec("uname -r") or "?"
-local load1, load5, load15 = luci.sys.loadavg()
-s:taboption("general", DummyValue, "_la", translate("Load")).value =
- string.format("%.2f, %.2f, %.2f", load1, load5, load15)
+o = s:taboption("general", Value, "hostname", translate("Hostname"))
+o.datatype = "hostname"
-s:taboption("general", DummyValue, "_memtotal", translate("Memory")).value =
- string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
- tonumber(memtotal) / 1024,
- 100 * memcached / memtotal,
- tostring(translate("cached")),
- 100 * membuffers / memtotal,
- tostring(translate("buffered")),
- 100 * memfree / memtotal,
- tostring(translate("free"))
-)
-
-s:taboption("general", DummyValue, "_systime", translate("Local Time")).value =
- os.date("%c")
-
-s:taboption("general", DummyValue, "_uptime", translate("Uptime")).value =
- luci.tools.webadmin.date_format(tonumber(uptime))
-
-hn = s:taboption("general", Value, "hostname", translate("Hostname"))
-hn.datatype = "hostname"
-function hn.write(self, section, value)
+function o.write(self, section, value)
Value.write(self, section, value)
luci.sys.hostname(value)
end
-tz = s:taboption("general", ListValue, "zonename", translate("Timezone"))
-tz:value("UTC")
+o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
+o:value("UTC")
for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
- tz:value(zone[1])
+ o:value(zone[1])
end
-function tz.write(self, section, value)
+function o.write(self, section, value)
local function lookup_zone(title)
for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
if zone[1] == title then return zone[2] end
o.datatype = "port"
o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
-o:value(7, translate("Debug"))
-o:value(6, translate("Info"))
-o:value(5, translate("Notice"))
-o:value(4, translate("Warning"))
-o:value(3, translate("Error"))
-o:value(2, translate("Critical"))
-o:value(1, translate("Alert"))
-o:value(0, translate("Emergency"))
+o:value(8, translate("Debug"))
+o:value(7, translate("Info"))
+o:value(6, translate("Notice"))
+o:value(5, translate("Warning"))
+o:value(4, translate("Error"))
+o:value(3, translate("Critical"))
+o:value(2, translate("Alert"))
+o:value(1, translate("Emergency"))
o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
o.default = 8
--
--- Rdate
+-- NTP
--
-if has_rdate then
- s2 = m:section(TypedSection, "rdate", translate("Time Server (rdate)"))
- s2.anonymous = true
- s2.addremove = false
+if has_ntpd then
- s2:option(DynamicList, "server", translate("Server"))
-end
+ -- timeserver setup was requested, create section and reload page
+ if m:formvalue("cbid.system._timeserver._enable") then
+ m.uci:section("system", "timeserver", "ntp",
+ {
+ server = { "0.openwrt.pool.ntp.org", "1.openwrt.pool.ntp.org", "2.openwrt.pool.ntp.org", "3.openwrt.pool.ntp.org" }
+ }
+ )
+ m.uci:save("system")
+ luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1]))
+ return
+ end
-m2 = Map("luci")
+ local has_section = false
+ m.uci:foreach("system", "timeserver",
+ function(s)
+ has_section = true
+ return false
+ end)
-f = m2:section(NamedSection, "main", "core", translate("Files to be kept when flashing a new firmware"))
+ if not has_section then
-f:tab("detected", translate("Detected Files"),
- translate("The following files are detected by the system and will be kept automatically during sysupgrade"))
+ s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
+ s.anonymous = true
+ s.cfgsections = function() return { "_timeserver" } end
-f:tab("custom", translate("Custom Files"),
- translate("This is a list of shell glob patterns for matching files and directories to include during sysupgrade"))
+ x = s:option(Button, "_enable")
+ x.title = translate("Time Synchronization is not configured yet.")
+ x.inputtitle = translate("Setup Time Synchronization")
+ x.inputstyle = "apply"
-d = f:taboption("detected", DummyValue, "_detected", translate("Detected files"))
-d.rawhtml = true
-d.cfgvalue = function(s)
- local list = io.popen(
- "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
- "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
- "opkg list-changed-conffiles ) | sort -u"
- )
+ else
+
+ s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
+ s.anonymous = true
+ s.addremove = false
- if list then
- local files = { "<ul>" }
+ o = s:option(Flag, "enable", translate("Enable NTP client"))
+ o.rmempty = false
+
+ function o.cfgvalue(self)
+ return luci.sys.init.enabled("sysntpd")
+ and self.enabled or self.disabled
+ end
- while true do
- local ln = list:read("*l")
- if not ln then
- break
+ function o.write(self, section, value)
+ if value == self.enabled then
+ luci.sys.init.enable("sysntpd")
+ luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
else
- files[#files+1] = "<li>"
- files[#files+1] = luci.util.pcdata(ln)
- files[#files+1] = "</li>"
+ luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
+ luci.sys.init.disable("sysntpd")
end
end
- list:close()
- files[#files+1] = "</ul>"
- return table.concat(files, "")
- end
+ o = s:option(Flag, "enable_server", translate("Provide NTP server"))
+ o:depends("enable", "1")
- return "<em>" .. translate("No files found") .. "</em>"
-end
-c = f:taboption("custom", TextValue, "_custom", translate("Custom files"))
-c.rmempty = false
-c.cols = 70
-c.rows = 30
+ o = s:option(DynamicList, "server", translate("NTP server candidates"))
+ o.datatype = "host"
+ o:depends("enable", "1")
-c.cfgvalue = function(self, section)
- return nixio.fs.readfile("/etc/sysupgrade.conf")
-end
+ -- retain server list even if disabled
+ function o.remove() end
-c.write = function(self, section, value)
- value = value:gsub("\r\n?", "\n")
- return nixio.fs.writefile("/etc/sysupgrade.conf", value)
+ end
end
-
-return m, m2
+return m