diff --git a/src/www/services_ntpd.php b/src/www/services_ntpd.php index 1b9734969..1ea6b32f0 100644 --- a/src/www/services_ntpd.php +++ b/src/www/services_ntpd.php @@ -1,31 +1,31 @@ 15 || !is_numeric($pconfig['orphan']))) { + $input_errors[] = gettext("Orphan mode must be a value between 0..15"); + } + + // swap fields, really stupid field usage which we are not going to change now.... + foreach (array('kod', 'nomodify', 'nopeer', 'notrap') as $fieldname) { + $pconfig[$fieldname] = empty($pconfig[$fieldname]); + } + + if (count($input_errors) == 0) { + // copy fields + foreach ($copy_fields as $fieldname) { + if (!empty($pconfig[$fieldname])) { + $a_ntpd[$fieldname] = $pconfig[$fieldname]; + } elseif (isset($a_ntpd[$fieldname])) { + unset($a_ntpd[$fieldname]); + } } - if (!empty($_POST['ntporphan']) && ($_POST['ntporphan'] < 17) && ($_POST['ntporphan'] != '12')) - $config['ntpd']['orphan'] = $_POST['ntporphan']; - elseif (isset($config['ntpd']['orphan'])) - unset($config['ntpd']['orphan']); + // list types + $config['system']['timeservers'] = trim(implode(' ', $pconfig['timeservers_host'])); + $a_ntpd['noselect'] = !empty($pconfig['timeservers_noselect']) ? trim(implode(' ', $pconfig['timeservers_noselect'])) : null; + $a_ntpd['prefer'] = ""; + if (!empty($pconfig['timeservers_prefer'])) { + foreach ($pconfig['timeservers_prefer'] as $timeserver) { + if (!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']); + $a_ntpd['interface'] = implode(',', $pconfig['interface']); - if (!empty($_POST['logpeer'])) - $config['ntpd']['logpeer'] = $_POST['logpeer']; - elseif (isset($config['ntpd']['logpeer'])) - unset($config['ntpd']['logpeer']); + // unset empty + foreach (array('noselect', 'prefer', 'interface') as $fieldname) { + if (empty($a_ntpd[$fieldname])) { + unset($a_ntpd[$fieldname]); + } + } + if (empty($config['system']['timeservers'])) { + unset($config['system']['timeservers']); + } - if (!empty($_POST['logsys'])) - $config['ntpd']['logsys'] = $_POST['logsys']; - elseif (isset($config['ntpd']['logsys'])) - unset($config['ntpd']['logsys']); + if (!empty($a_ntpd['leapsec'])) { + $a_ntpd['leapsec'] = base64_encode($a_ntpd['leapsec']); + } elseif(isset($config['ntpd']['leapsec'])) { + unset($config['ntpd']['leapsec']); + } - if (!empty($_POST['clockstats'])) - $config['ntpd']['clockstats'] = $_POST['clockstats']; - elseif (isset($config['ntpd']['clockstats'])) - unset($config['ntpd']['clockstats']); - - if (!empty($_POST['loopstats'])) - $config['ntpd']['loopstats'] = $_POST['loopstats']; - elseif (isset($config['ntpd']['loopstats'])) - unset($config['ntpd']['loopstats']); - - if (!empty($_POST['peerstats'])) - $config['ntpd']['peerstats'] = $_POST['peerstats']; - elseif (isset($config['ntpd']['peerstats'])) - unset($config['ntpd']['peerstats']); - - if (empty($_POST['kod'])) - $config['ntpd']['kod'] = 'on'; - elseif (isset($config['ntpd']['kod'])) - unset($config['ntpd']['kod']); - - if (empty($_POST['nomodify'])) - $config['ntpd']['nomodify'] = 'on'; - elseif (isset($config['ntpd']['nomodify'])) - unset($config['ntpd']['nomodify']); - - if (!empty($_POST['noquery'])) - $config['ntpd']['noquery'] = $_POST['noquery']; - elseif (isset($config['ntpd']['noquery'])) - unset($config['ntpd']['noquery']); - - if (!empty($_POST['noserve'])) - $config['ntpd']['noserve'] = $_POST['noserve']; - elseif (isset($config['ntpd']['noserve'])) - unset($config['ntpd']['noserve']); - - if (empty($_POST['nopeer'])) - $config['ntpd']['nopeer'] = 'on'; - elseif (isset($config['ntpd']['nopeer'])) - unset($config['ntpd']['nopeer']); - - if (empty($_POST['notrap'])) - $config['ntpd']['notrap'] = 'on'; - elseif (isset($config['ntpd']['notrap'])) - unset($config['ntpd']['notrap']); - - if ((empty($_POST['statsgraph'])) != (isset($config['ntpd']['statsgraph']))); - enable_rrd_graphing(); - if (!empty($_POST['statsgraph'])) - $config['ntpd']['statsgraph'] = $_POST['statsgraph']; - elseif (isset($config['ntpd']['statsgraph'])) - unset($config['ntpd']['statsgraph']); - - if (!empty($_POST['leaptxt'])) - $config['ntpd']['leapsec'] = base64_encode($_POST['leaptxt']); - elseif (isset($config['ntpd']['leapsec'])) - unset($config['ntpd']['leapsec']); - - if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) - $config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name'])); - - write_config("Updated NTP Server Settings"); - - $retval = 0; - $retval = system_ntp_configure(); - $savemsg = get_std_save_message(); - -} - -$pconfig = &$config['ntpd']; -if (empty($pconfig['interface'])) { - $pconfig['interface'] = array(); -} else { - $pconfig['interface'] = explode(",", $pconfig['interface']); + if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) { + $a_ntpd['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name'])); + } + write_config("Updated NTP Server Settings"); + system_ntp_configure(); + header("Location: services_ntpd.php"); + exit; + } } $service_hook = 'ntpd'; - +legacy_html_escape_form_data($pconfig); include("head.inc"); - ?>
+ - -