From f7cb0f2f0015733751a40b901bf5077dfd8ac992 Mon Sep 17 00:00:00 2001 From: bergware Date: Fri, 1 Nov 2024 21:47:05 +0100 Subject: [PATCH] NTP enhancements - Add new parameter "NTP interval", this can be useful when you run your own NTP servers - Add pool support, this allows a round-robin selection of NTP servers out of a pool, and improves server availability --- emhttp/plugins/dynamix/DateTime.page | 10 +++++++++ emhttp/plugins/dynamix/sheets/DateTime.css | 1 + etc/rc.d/rc.ntpd | 24 +++++++++++++++++----- 3 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 emhttp/plugins/dynamix/sheets/DateTime.css diff --git a/emhttp/plugins/dynamix/DateTime.page b/emhttp/plugins/dynamix/DateTime.page index d7fdaae60..3c1c13f5a 100644 --- a/emhttp/plugins/dynamix/DateTime.page +++ b/emhttp/plugins/dynamix/DateTime.page @@ -59,6 +59,14 @@ _(Use NTP)_: :use_ntp_help: +_(NTP interval)_: +: _(Use DEFAULT setting when public NTP servers are defined)_ + _(NTP server)_ 1: : @@ -107,12 +115,14 @@ function presetTime(form) { function checkDateTimeSettings(form) { if (form.USE_NTP.value=="yes") { form.newDateTime.disabled=true; + form.display_ntppoll.disabled=false; form.NTP_SERVER1.disabled=false; form.NTP_SERVER2.disabled=false; form.NTP_SERVER3.disabled=false; form.NTP_SERVER4.disabled=false; } else { form.newDateTime.disabled=false; + form.display_ntppoll.disabled=true; form.NTP_SERVER1.disabled=true; form.NTP_SERVER2.disabled=true; form.NTP_SERVER3.disabled=true; diff --git a/emhttp/plugins/dynamix/sheets/DateTime.css b/emhttp/plugins/dynamix/sheets/DateTime.css new file mode 100644 index 000000000..b2eb5cbbe --- /dev/null +++ b/emhttp/plugins/dynamix/sheets/DateTime.css @@ -0,0 +1 @@ +span.ntp{margin-left:40px} diff --git a/etc/rc.d/rc.ntpd b/etc/rc.d/rc.ntpd index 75f76c146..deedfedc9 100755 --- a/etc/rc.d/rc.ntpd +++ b/etc/rc.d/rc.ntpd @@ -13,6 +13,7 @@ NTPD="/usr/sbin/ntpd" OPTIONS="-g -u ntp:ntp" CONF="/etc/ntp.conf" IDENT="/boot/config/ident.cfg" +CONFIG="/boot/config/plugins/dynamix/dynamix.cfg" # run & log functions . /etc/rc.d/rc.runlog @@ -38,11 +39,24 @@ ntpd_build(){ echo "interface listen $NET" >>$CONF done fi - # add configured NTP servers - [[ -n $NTP_SERVER1 ]] && echo "server $NTP_SERVER1 iburst" >>$CONF - [[ -n $NTP_SERVER2 ]] && echo "server $NTP_SERVER2 iburst" >>$CONF - [[ -n $NTP_SERVER3 ]] && echo "server $NTP_SERVER3 iburst" >>$CONF - [[ -n $NTP_SERVER4 ]] && echo "server $NTP_SERVER4 iburst" >>$CONF + # ntp poll interval may be adjusted to predefined values + if [[ -f $CONFIG ]]; then + NTP_POLL=$(grep -Po '^ntppoll="\K[^"]+' $CONFIG) + if [[ -n $NTP_POLL ]]; then + MINPOLL="minpoll $NTP_POLL" + MAXPOLL="maxpoll $NTP_POLL" + fi + fi + # add configured ntp servers or pools + for n in {1..4}; do + NTP="NTP_SERVER$n" + if [[ -n ${!NTP} ]]; then + # use either server or pool peers depending on remote ntp name + # pools use a round-robin mechanism to get a server out of the pool + [[ ${!NTP} =~ "pool" ]] && PEER=pool || PEER=server + echo "$PEER ${!NTP} iburst $MINPOLL $MAXPOLL" >>$CONF + fi + done } ntpd_start(){