Add secondary ntp server option (#1583)

This commit is contained in:
Tim Wilkinson 2024-10-08 20:57:58 -07:00 committed by GitHub
parent 04f3fb154c
commit b627a6f63d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 3 deletions

View File

@ -45,6 +45,9 @@ if (request.env.REQUEST_METHOD === "PUT") {
if ("ntp_server" in request.args) {
configuration.setSetting("ntp_server", request.args.ntp_server);
}
if ("ntp_server2" in request.args) {
configuration.setSetting("ntp_server2", request.args.ntp_server2);
}
if ("ntp_mode" in request.args) {
switch (request.args.ntp_mode) {
case "daily":
@ -84,6 +87,7 @@ if (f) {
f.close();
}
const ntp_server = configuration.getSettingAsString("ntp_server", "");
const ntp_server2 = configuration.getSettingAsString("ntp_server2", "");
const ntp_mode = uciMesh.get("aredn", "@ntp[0]", "period") || "daily";
%}
<div class="dialog">
@ -114,8 +118,10 @@ const ntp_mode = uciMesh.get("aredn", "@ntp[0]", "period") || "daily";
</div>
<div style="flex:0">
<input hx-put="{{request.env.REQUEST_URI}}" name="ntp_server" type="text" size="20" value="{{ntp_server}}">
<input hx-put="{{request.env.REQUEST_URI}}" name="ntp_server2" type="text" size="20" value="{{ntp_server2}}">
</div>
</div>
<br>
{{_H("The default NTP server to use when syncing the node's time. If this cannot be found and the NTP frequency is hourly or daily, the node will search for one on the mesh.")}}
<div class="cols">
<div>

View File

@ -35,5 +35,6 @@ dtdlink_ip=10.<DTDMAC>
time_zone = UTC
time_zone_name = UTC
ntp_server = us.pool.ntp.org
ntp_server2 = time.cloudflare.com
description_node =
compat_version = 1.0

View File

@ -47,6 +47,7 @@ dtdlink_ip=10.<DTDMAC>
time_zone = UTC
time_zone_name = UTC
ntp_server = us.pool.ntp.org
ntp_server2 = time.cloudflare.com
description_node =

View File

@ -10,6 +10,7 @@ config system
config timeserver 'ntp'
list server '<ntp_server>'
list server '<ntp_server2>'
option enable_server '0'
option enabled '<ntp_enabled>'

View File

@ -45,14 +45,14 @@ if [ "$(pidof ntpd)" != "" ]; then
exit 0
fi
candidate=$(uci -q get system.ntp.server)
if [ "${candidate}" != "" ]; then
for candidate in $(uci -q get system.ntp.server)
do
if $(ntpd -n -q -p ${candidate}); then
echo -n "ntp" > /tmp/timesync
logger -p notice -t update-time "Update clock from ${candidate}"
exit 0
fi
fi
done
# NTP servers tend to be poorly advertised, so we have to use a bit of
# heuristics to find them