From e9951882f2078effd52dcae6861f4015ae44ed74 Mon Sep 17 00:00:00 2001
From: doktornotor <1075960+doktornotor@users.noreply.github.com>
Date: Wed, 4 Sep 2024 15:33:35 +0200
Subject: [PATCH 1/4] NTPD configuration cleanups
Remove some options for `restrict source` template that make no sense there.. Also, do not use `noselect` with pools.
---
src/etc/inc/plugins.inc.d/ntpd.inc | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/etc/inc/plugins.inc.d/ntpd.inc b/src/etc/inc/plugins.inc.d/ntpd.inc
index 68438a0ce5..3f0d9db781 100644
--- a/src/etc/inc/plugins.inc.d/ntpd.inc
+++ b/src/etc/inc/plugins.inc.d/ntpd.inc
@@ -330,6 +330,7 @@ function ntpd_configure_do($verbose = false)
$noselect = isset($config['ntpd']['noselect']) ? explode(' ', $config['ntpd']['noselect']) : [];
$prefer = isset($config['ntpd']['prefer']) ? explode(' ', $config['ntpd']['prefer']) : [];
$iburst = isset($config['ntpd']['iburst']) ? explode(' ', $config['ntpd']['iburst']) : [];
+ $have_pools = false;
$ntpcfg .= "\n\n# Upstream Servers\n";
/* foreach through ntp servers and write out to ntpd.conf */
@@ -337,6 +338,7 @@ function ntpd_configure_do($verbose = false)
/* Determine if Network Time Server is from the NTP Pool or not */
if (preg_match("/\.pool\.ntp\.org$/", $ts)) {
$ntpcfg .= "pool {$ts}";
+ $have_pools = true;
} else {
$ntpcfg .= "server {$ts}";
}
@@ -347,7 +349,8 @@ function ntpd_configure_do($verbose = false)
if (in_array($ts, $prefer)) {
$ntpcfg .= ' prefer';
}
- if (in_array($ts, $noselect)) {
+ /* "noselect" option is not valid with pools */
+ if ((in_array($ts, $noselect)) && ($have_pools === false)) {
$ntpcfg .= ' noselect';
}
$ntpcfg .= "\n";
@@ -402,10 +405,11 @@ function ntpd_configure_do($verbose = false)
if (empty($config['ntpd']['notrap'])) { /*note: this one works backwards */
$ntpaccess .= ' notrap';
}
+ $ntpcfg .= "\nrestrict source {$ntpaccess}";
+ /* Keep "noserve" and "nopeer" out of the restrict source template, they make no sense there */
if (!empty($config['ntpd']['noserve'])) {
$ntpaccess .= ' noserve';
}
- $ntpcfg .= "\nrestrict source {$ntpaccess}";
if (empty($config['ntpd']['nopeer'])) { /*note: this one works backwards */
$ntpaccess .= ' nopeer';
}
From 98cc530666c9e849f0280867329c47cca5b69210 Mon Sep 17 00:00:00 2001
From: doktornotor <1075960+doktornotor@users.noreply.github.com>
Date: Wed, 4 Sep 2024 18:32:20 +0200
Subject: [PATCH 2/4] Disable the "noselect" checkbox for pool.ntp.org pools
---
src/www/services_ntpd.php | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/www/services_ntpd.php b/src/www/services_ntpd.php
index 7af782da36..0c164c7623 100644
--- a/src/www/services_ntpd.php
+++ b/src/www/services_ntpd.php
@@ -192,6 +192,30 @@
$("#show_advanced_ntpd").click();
}
+ // disable the "noselect" checkbox for pool.ntp.org pools
+ $('#timeservers_table > tbody > tr').each(function() {
+ var timeserver = $(this).find('input[name="timeservers_host[]"]').val();
+ var noselectCheckbox = $(this).find('input[name="timeservers_noselect[]"]');
+ if (timeserver.includes('pool.ntp.org')) {
+ noselectCheckbox.prop('checked', false);
+ noselectCheckbox.prop('disabled', true);
+ } else {
+ noselectCheckbox.prop('disabled', false);
+ }
+ });
+ // also check for pools on input change for each row
+ $('#timeservers_table > tbody > tr').on('input', 'input[name="timeservers_host[]"]', function() {
+ var row = $(this).closest('tr');
+ var timeserver = row.find('input[name="timeservers_host[]"]').val();
+ var noselectCheckbox = row.find('input[name="timeservers_noselect[]"]');
+ if (timeserver.includes('pool.ntp.org')) {
+ noselectCheckbox.prop('checked', false);
+ noselectCheckbox.prop('disabled', true);
+ } else {
+ noselectCheckbox.prop('disabled', false);
+ }
+ });
+
/**
* Aliases
*/
From 49b0a524415f0f187f3926260fd0b627a69942c0 Mon Sep 17 00:00:00 2001
From: doktornotor <1075960+doktornotor@users.noreply.github.com>
Date: Wed, 4 Sep 2024 18:36:27 +0200
Subject: [PATCH 3/4] Move and rename variable
---
src/etc/inc/plugins.inc.d/ntpd.inc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/etc/inc/plugins.inc.d/ntpd.inc b/src/etc/inc/plugins.inc.d/ntpd.inc
index 3f0d9db781..9d58cba3a1 100644
--- a/src/etc/inc/plugins.inc.d/ntpd.inc
+++ b/src/etc/inc/plugins.inc.d/ntpd.inc
@@ -330,15 +330,15 @@ function ntpd_configure_do($verbose = false)
$noselect = isset($config['ntpd']['noselect']) ? explode(' ', $config['ntpd']['noselect']) : [];
$prefer = isset($config['ntpd']['prefer']) ? explode(' ', $config['ntpd']['prefer']) : [];
$iburst = isset($config['ntpd']['iburst']) ? explode(' ', $config['ntpd']['iburst']) : [];
- $have_pools = false;
$ntpcfg .= "\n\n# Upstream Servers\n";
/* foreach through ntp servers and write out to ntpd.conf */
foreach (explode(' ', $config['system']['timeservers']) as $ts) {
+ $is_pool = false;
/* Determine if Network Time Server is from the NTP Pool or not */
if (preg_match("/\.pool\.ntp\.org$/", $ts)) {
$ntpcfg .= "pool {$ts}";
- $have_pools = true;
+ $is_pool = true;
} else {
$ntpcfg .= "server {$ts}";
}
@@ -350,7 +350,7 @@ function ntpd_configure_do($verbose = false)
$ntpcfg .= ' prefer';
}
/* "noselect" option is not valid with pools */
- if ((in_array($ts, $noselect)) && ($have_pools === false)) {
+ if ((in_array($ts, $noselect)) && ($is_pool === false)) {
$ntpcfg .= ' noselect';
}
$ntpcfg .= "\n";
From 161727b2cd21eff30ecd7a22045601e499e5d6a6 Mon Sep 17 00:00:00 2001
From: doktornotor <1075960+doktornotor@users.noreply.github.com>
Date: Wed, 4 Sep 2024 19:05:39 +0200
Subject: [PATCH 4/4] Document the "do not use" checkbox behavior with pools
---
src/www/services_ntpd.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/www/services_ntpd.php b/src/www/services_ntpd.php
index 0c164c7623..d2dbbb1e18 100644
--- a/src/www/services_ntpd.php
+++ b/src/www/services_ntpd.php
@@ -331,7 +331,7 @@ function removeRow() {
= gettext('The "iburst" option enables faster clock synchronisation on startup at the expense of the peer.') ?>
- = gettext('The "do not use" option indicates that NTP should not use this server for time, but stats for this server will be collected and displayed.') ?>
+ = gettext('The "do not use" option indicates that NTP should not use this server for time, but stats for this server will be collected and displayed. Note: pool.ntp.org and its subdomains are always treated as pool. This option is not available for pools.') ?>