luci-mod-system: add button to sync with ntp server 2620/head
authorFlorian Eckert <fe@dev.tdt.de>
Fri, 8 Mar 2019 12:26:19 +0000 (13:26 +0100)
committerFlorian Eckert <fe@dev.tdt.de>
Mon, 11 Mar 2019 15:09:13 +0000 (16:09 +0100)
Especially for systems without RTC this change has two advantages

* manual time sync with time server during configuration
* test possibility of the time sync over the configured servers

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
modules/luci-mod-system/luasrc/controller/admin/system.lua
modules/luci-mod-system/luasrc/view/admin_system/clock_status.htm

index 3e58896d63590318ea5a5de7af8bd5914578e926..49d4476c4ea536bb9ed6d913debea0f4f3bed89c 100644 (file)
@@ -9,6 +9,7 @@ function index()
 
        entry({"admin", "system", "system"}, cbi("admin_system/system"), _("System"), 1)
        entry({"admin", "system", "clock_status"}, post_on({ set = true }, "action_clock_status"))
+       entry({"admin", "system", "ntp_restart"}, call("action_ntp_restart"), nil).leaf = true
 
        entry({"admin", "system", "admin"}, firstchild(), _("Administration"), 2)
        entry({"admin", "system", "admin", "password"}, template("admin_system/password"), _("Router Password"), 1)
@@ -64,6 +65,14 @@ function action_clock_status()
        luci.http.write_json({ timestring = os.date("%c") })
 end
 
+function action_ntp_restart()
+       if nixio.fs.access("/etc/init.d/sysntpd") then
+               os.execute("/etc/init.d/sysntpd restart")
+       end
+       luci.http.prepare_content("text/plain")
+       luci.http.write("0")
+end
+
 local function image_supported(image)
        return (os.execute("sysupgrade -T %q >/dev/null" % image) == 0)
 end
index 2c96eb418094a7a5529884de8104d05e1e32debd..796aa695c68e4f45a0f798a404c502dffb18119e 100644 (file)
 
                return false;
        }
+
+       function btn_action(action)
+       {
+               if (action.name === "do_ntp_restart")
+               {
+                       new XHR.get('<%=luci.dispatcher.build_url("admin", "system", "ntp_restart")%>', null,
+                       function(x)
+                       {
+                               if (!x)
+                               {
+                                       return;
+                               }
+                       });
+               }
+       }
+
 //]]></script>
 
 <span id="<%=self.option%>-clock-status"><em><%:Collecting data...%></em></span>
 <input type="button" class="cbi-button cbi-button-apply" value="<%:Sync with browser%>" onclick="return sync_clock(this)" />
 
+<% if require("nixio.fs").access("/etc/init.d/sysntpd") then %>
+<input type="button" class="cbi-button cbi-button-apply" name="do_ntp_restart" value="<%:Sync with NTP-Server%>" onclick="btn_action(this)" />
+<% end %>
+
 <%+cbi/valuefooter%>