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
Changes from 1 commit
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 @@ -330,13 +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;
doktornotor marked this conversation as resolved.
Show resolved Hide resolved

$ntpcfg .= "\n\n# Upstream Servers\n";
/* foreach through ntp servers and write out to ntpd.conf */
foreach (explode(' ', $config['system']['timeservers']) as $ts) {
/* 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}";
}
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)) && ($have_pools === 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