admin-full: Better fix for the last change (timeserver setup), add button to add the missing section

This commit is contained in:
Manuel Munz 2011-11-10 12:57:13 +00:00
parent a196198fb9
commit 525da459d7

View file

@ -154,50 +154,66 @@ end
-- --
if has_ntpd then if has_ntpd then
s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
s.anonymous = true
s.addremove = false
function m.on_parse() -- timeserver setup was requested, create section and reload page
local has_section = false if m:formvalue("cbid.system._timeserver._enable") then
m.uci:section("system", "timeserver", "ntp")
m.uci:save("system")
luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1]))
return
end
m.uci:foreach("system", "timeserver", local has_section = false
function(s) m.uci:foreach("system", "timeserver",
has_section = true function(s)
return false has_section = true
end) return false
end)
if not has_section then if not has_section then
m.uci:section("system", "timeserver", "ntp")
s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
s.anonymous = true
s.cfgsections = function() return { "_timeserver" } end
x = s:option(Button, "_enable")
x.title = translate("Time Synchronization is not configured yet.")
x.inputtitle = translate("Setup Time Synchronization")
x.inputstyle = "apply"
else
s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
s.anonymous = true
s.addremove = false
o = s:option(Flag, "enable", translate("Enable builtin NTP server"))
o.rmempty = false
function o.cfgvalue(self)
return luci.sys.init.enabled("sysntpd")
and self.enabled or self.disabled
end end
end
o = s:option(Flag, "enable", translate("Enable builtin NTP server")) function o.write(self, section, value)
o.rmempty = false if value == self.enabled then
luci.sys.init.enable("sysntpd")
function o.cfgvalue(self) luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
return luci.sys.init.enabled("sysntpd") else
and self.enabled or self.disabled luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
end luci.sys.init.disable("sysntpd")
end
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
luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
luci.sys.init.disable("sysntpd")
end end
o = s:option(DynamicList, "server", translate("NTP server candidates"))
o.datatype = "host"
o:depends("enable", "1")
-- retain server list even if disabled
function o.remove() end
end end
o = s:option(DynamicList, "server", translate("NTP server candidates"))
o.datatype = "host"
o:depends("enable", "1")
-- retain server list even if disabled
function o.remove() end
end end
return m return m