From 0d70b4a9dbde2889063fba177a06f5fb139d87f4 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Thu, 25 Feb 2016 22:03:57 +0100 Subject: [PATCH] ntp: disable when no servers are set; closes #332 This will make a few good people very happy. :) --- src/etc/inc/services.inc | 16 +++++++++------- src/etc/inc/system.inc | 17 +++++++++++------ src/www/services_ntpd.php | 5 +++-- src/www/system_general.php | 17 +++++++++++------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index b865c395a..557eef9d7 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -2543,13 +2543,15 @@ function services_get() $services[] = $pconfig; } - $pconfig = array(); - $pconfig['name'] = "ntpd"; - $pconfig['description'] = gettext("NTP clock sync"); - $pconfig['php']['restart'] = array('system_ntp_configure'); - $pconfig['php']['start'] = array('system_ntp_configure'); - $pconfig['pidfile'] = '/var/run/ntpd.pid'; - $services[] = $pconfig; + if (isset($config['system']['timeservers'])) { + $pconfig = array(); + $pconfig['name'] = "ntpd"; + $pconfig['description'] = gettext("NTP clock sync"); + $pconfig['php']['restart'] = array('system_ntp_configure'); + $pconfig['php']['start'] = array('system_ntp_configure'); + $pconfig['pidfile'] = '/var/run/ntpd.pid'; + $services[] = $pconfig; + } $iflist = array(); $ifdescrs = get_configured_interface_list(); diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 5662da145..0d03afb09 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -1474,6 +1474,17 @@ function system_ntp_configure($start_ntpd = true) { global $config; + /* if ntpd is running, kill it when restart is not delayed */ + while ($start_ntpd && isvalidpid('/var/run/ntpd.pid')) { + killbypid('/var/run/ntpd.pid'); + usleep(200 * 1000); + } + + if (!isset($config['system']['timeservers'])) { + /* use this field for on/off toggle */ + return; + } + $driftfile = '/var/db/ntpd.drift'; $statsdir = '/var/log/ntp'; $gps_device = '/dev/gps0'; @@ -1719,12 +1730,6 @@ function system_ntp_configure($start_ntpd = true) return; } - /* if ntpd is running, kill it */ - while (isvalidpid('/var/run/ntpd.pid')) { - killbypid('/var/run/ntpd.pid'); - usleep(200 * 1000); - } - /* if /var/empty does not exist, create it */ @mkdir('/var/empty', 0775, true); diff --git a/src/www/services_ntpd.php b/src/www/services_ntpd.php index e1f77b82f..1b9734969 100644 --- a/src/www/services_ntpd.php +++ b/src/www/services_ntpd.php @@ -63,9 +63,10 @@ if ($_POST) { if (!empty($_POST["servselect{$i}"])) $config['ntpd']['noselect'].= "{$tserver} "; } } - if (trim($timeservers) == "") - $timeservers = "pool.ntp.org"; $config['system']['timeservers'] = trim($timeservers); + if (empty($config['system']['timeservers'])) { + unset($config['system']['timeservers']); + } if (!empty($_POST['ntporphan']) && ($_POST['ntporphan'] < 17) && ($_POST['ntporphan'] != '12')) $config['ntpd']['orphan'] = $_POST['ntporphan']; diff --git a/src/www/system_general.php b/src/www/system_general.php index ecda65ceb..7fa5e65c0 100644 --- a/src/www/system_general.php +++ b/src/www/system_general.php @@ -159,9 +159,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { # it's easy to have a little too much whitespace in the field, clean it up for the user before processing. $pconfig['timeservers'] = preg_replace('/[[:blank:]]+/', ' ', $pconfig['timeservers']); $pconfig['timeservers'] = trim($pconfig['timeservers']); - foreach (explode(' ', $pconfig['timeservers']) as $ts) { - if (!is_domain($ts)) { - $input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'."); + if (!empty($pconfig['timeservers'])) { + foreach (explode(' ', $pconfig['timeservers']) as $ts) { + if (!is_domain($ts)) { + $input_errors[] = gettext("A NTP Time Server name may only contain the characters a-z, 0-9, '-' and '.'."); + } } } @@ -170,6 +172,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $config['system']['domain'] = $pconfig['domain']; $config['system']['timezone'] = $pconfig['timezone']; $config['system']['timeservers'] = strtolower($pconfig['timeservers']); + if (empty($config['system']['timeservers'])) { + unset($config['system']['timeservers']); + } $config['theme'] = $pconfig['theme']; if (!empty($pconfig['language']) && $pconfig['language'] != $config['system']['language']) { @@ -448,9 +453,9 @@ include("head.inc");