| 157 | | s = m:section(TypedSection, "timeserver", translate("Time Synchronization")) |
| 158 | | s.anonymous = true |
| 159 | | s.addremove = false |
| 160 | | |
| 161 | | function m.on_parse() |
| 162 | | local has_section = false |
| 163 | | |
| 164 | | m.uci:foreach("system", "timeserver", |
| 165 | | function(s) |
| 166 | | has_section = true |
| 167 | | return false |
| 168 | | end) |
| 169 | | |
| 170 | | if not has_section then |
| 171 | | m.uci:section("system", "timeserver", "ntp") |
| | 157 | |
| | 158 | -- timeserver setup was requested, create section and reload page |
| | 159 | if m:formvalue("cbid.system._timeserver._enable") then |
| | 160 | m.uci:section("system", "timeserver", "ntp") |
| | 161 | m.uci:save("system") |
| | 162 | luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1])) |
| | 163 | return |
| | 164 | end |
| | 165 | |
| | 166 | local has_section = false |
| | 167 | m.uci:foreach("system", "timeserver", |
| | 168 | function(s) |
| | 169 | has_section = true |
| | 170 | return false |
| | 171 | end) |
| | 172 | |
| | 173 | if not has_section then |
| | 174 | |
| | 175 | s = m:section(TypedSection, "timeserver", translate("Time Synchronization")) |
| | 176 | s.anonymous = true |
| | 177 | s.cfgsections = function() return { "_timeserver" } end |
| | 178 | |
| | 179 | x = s:option(Button, "_enable") |
| | 180 | x.title = translate("Time Synchronization is not configured yet.") |
| | 181 | x.inputtitle = translate("Setup Time Synchronization") |
| | 182 | x.inputstyle = "apply" |
| | 183 | |
| | 184 | else |
| | 185 | |
| | 186 | s = m:section(TypedSection, "timeserver", translate("Time Synchronization")) |
| | 187 | s.anonymous = true |
| | 188 | s.addremove = false |
| | 189 | |
| | 190 | o = s:option(Flag, "enable", translate("Enable builtin NTP server")) |
| | 191 | o.rmempty = false |
| | 192 | |
| | 193 | function o.cfgvalue(self) |
| | 194 | return luci.sys.init.enabled("sysntpd") |
| | 195 | and self.enabled or self.disabled |
| 173 | | end |
| 174 | | |
| 175 | | o = s:option(Flag, "enable", translate("Enable builtin NTP server")) |
| 176 | | o.rmempty = false |
| 177 | | |
| 178 | | function o.cfgvalue(self) |
| 179 | | return luci.sys.init.enabled("sysntpd") |
| 180 | | and self.enabled or self.disabled |
| 181 | | end |
| 182 | | |
| 183 | | function o.write(self, section, value) |
| 184 | | if value == self.enabled then |
| 185 | | luci.sys.init.enable("sysntpd") |
| 186 | | luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null") |
| 187 | | else |
| 188 | | luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null") |
| 189 | | luci.sys.init.disable("sysntpd") |
| | 197 | |
| | 198 | function o.write(self, section, value) |
| | 199 | if value == self.enabled then |
| | 200 | luci.sys.init.enable("sysntpd") |
| | 201 | luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null") |
| | 202 | else |
| | 203 | luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null") |
| | 204 | luci.sys.init.disable("sysntpd") |
| | 205 | end |