Merge pull request #2620 from TDT-AG/pr/20190311-luci-mod-system

luci-mod-system: add button to sync with ntp server
This commit is contained in:
Florian Eckert 2019-04-30 08:22:50 +02:00 committed by GitHub
commit 18cde3535d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View 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

View file

@ -28,9 +28,29 @@
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%>