Commit 7915b0b7 authored by Franco Fichtner's avatar Franco Fichtner

ntp: correct select behaviour; closes #818

o When servers are empty, show prefer and noselect as disabled.
o Tighten the config write by using the same code idiom as the
  frontend, which is the safer method.
o Untangle noselect and prefer, ntpd.conf will handle it.

(cherry picked from commit 80eba3c2)
parent 1aebb723
...@@ -1608,14 +1608,17 @@ function system_ntp_configure($start_ntpd = true) ...@@ -1608,14 +1608,17 @@ function system_ntp_configure($start_ntpd = true)
} }
/* End GPS configuration */ /* End GPS configuration */
$noselect = isset($config['ntpd']['noselect']) ? explode(' ', $config['ntpd']['noselect']) : array();
$prefer = isset($config['ntpd']['prefer']) ? explode(' ', $config['ntpd']['prefer']) : array();
$ntpcfg .= "\n\n# Upstream Servers\n"; $ntpcfg .= "\n\n# Upstream Servers\n";
/* foreach through ntp servers and write out to ntpd.conf */ /* foreach through ntp servers and write out to ntpd.conf */
foreach (explode(' ', $config['system']['timeservers']) as $ts) { foreach (explode(' ', $config['system']['timeservers']) as $ts) {
$ntpcfg .= "server {$ts} iburst maxpoll 9"; $ntpcfg .= "server {$ts} iburst maxpoll 9";
if (isset($config['ntpd']['prefer']) && substr_count($config['ntpd']['prefer'], $ts)) { if (in_array($ts, $prefer)) {
$ntpcfg .= ' prefer'; $ntpcfg .= ' prefer';
} }
if (isset($config['ntpd']['noselect']) && substr_count($config['ntpd']['noselect'], $ts)) { if (in_array($ts, $noselect)) {
$ntpcfg .= ' noselect'; $ntpcfg .= ' noselect';
} }
$ntpcfg .= "\n"; $ntpcfg .= "\n";
......
...@@ -90,20 +90,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -90,20 +90,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// list types // list types
$config['system']['timeservers'] = trim(implode(' ', $pconfig['timeservers_host'])); $config['system']['timeservers'] = trim(implode(' ', $pconfig['timeservers_host']));
$a_ntpd['noselect'] = !empty($pconfig['timeservers_noselect']) ? trim(implode(' ', $pconfig['timeservers_noselect'])) : null; $a_ntpd['noselect'] = !empty($pconfig['timeservers_noselect']) ? trim(implode(' ', $pconfig['timeservers_noselect'])) : null;
$a_ntpd['prefer'] = ""; $a_ntpd['prefer'] = !empty($pconfig['timeservers_prefer']) ? trim(implode(' ', $pconfig['timeservers_prefer'])) : null;
if (!empty($pconfig['timeservers_prefer'])) { $a_ntpd['interface'] = !empty($pconfig['interface']) ? implode(',', $pconfig['interface']) : null;
foreach ($pconfig['timeservers_prefer'] as $timeserver) {
if (!is_array($pconfig['timeservers_noselect']) || !in_array($timeserver, $pconfig['timeservers_noselect'])) {
// a timeserver can't be both preferred and disabled, don't set preferred when disabled
$a_ntpd['prefer'] .= $timeserver . " ";
}
}
}
$a_ntpd['prefer'] = trim($a_ntpd['prefer']);
if (!empty($pconfig['interface'])) {
$a_ntpd['interface'] = implode(',', $pconfig['interface']);
}
// unset empty // unset empty
foreach (array('noselect', 'prefer', 'interface') as $fieldname) { foreach (array('noselect', 'prefer', 'interface') as $fieldname) {
...@@ -258,8 +246,6 @@ include("head.inc"); ...@@ -258,8 +246,6 @@ include("head.inc");
<?php <?php
if (count($pconfig['timeservers_host']) == 0 ) { if (count($pconfig['timeservers_host']) == 0 ) {
$pconfig['timeservers_host'][] = ""; $pconfig['timeservers_host'][] = "";
$pconfig['timeservers_prefer'][] = false;
$pconfig['timeservers_noselect'][] = false;
} }
foreach($pconfig['timeservers_host'] as $item_idx => $timeserver):?> foreach($pconfig['timeservers_host'] as $item_idx => $timeserver):?>
<tr> <tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment