Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTPD configuration cleanups #7841

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/etc/inc/plugins.inc.d/ntpd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,11 @@ function ntpd_configure_do($verbose = 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}";
$is_pool = true;
} else {
$ntpcfg .= "server {$ts}";
}
Expand All @@ -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)) && ($is_pool === false)) {
$ntpcfg .= ' noselect';
}
$ntpcfg .= "\n";
Expand Down Expand Up @@ -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';
}
Expand Down
26 changes: 25 additions & 1 deletion src/www/services_ntpd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -307,7 +331,7 @@ function removeRow() {
<br />
<?= gettext('The "iburst" option enables faster clock synchronisation on startup at the expense of the peer.') ?>
<br />
<?= 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.') ?>
</div>
</td>
</tr>
Expand Down