All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); require_once("rrd.inc"); require_once("services.inc"); require_once("system.inc"); require_once("interfaces.inc"); require_once("plugins.inc.d/ntpd.inc"); $a_ntpd = &config_read_array('ntpd'); $copy_fields = array('orphan', 'statsgraph', 'logpeer', 'logsys', 'clockstats', 'loopstats', 'interface', 'peerstats', 'noquery', 'noserve', 'kod', 'nomodify', 'nopeer', 'notrap', 'leapsec'); if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig = array(); foreach ($copy_fields as $fieldname) { if (isset($a_ntpd[$fieldname])) { $pconfig[$fieldname] = $a_ntpd[$fieldname]; } } // base64 encoded $pconfig['leapsec'] = base64_decode(chunk_split($pconfig['leapsec'])); // array types $pconfig['interface'] = !empty($pconfig['interface']) ? explode(",", $pconfig['interface']) : array(); // text types $pconfig['custom_options'] = !empty($a_ntpd['custom_options']) ? $a_ntpd['custom_options'] : ''; // parse timeservers $pconfig['timeservers_host'] = array(); $pconfig['timeservers_noselect'] = array(); $pconfig['timeservers_prefer'] = array(); if (!empty($config['system']['timeservers'])) { $pconfig['timeservers_noselect'] = !empty($a_ntpd['noselect']) ? explode(' ', $a_ntpd['noselect']) : array(); $pconfig['timeservers_prefer'] = !empty($a_ntpd['prefer']) ? explode(' ', $a_ntpd['prefer']) : array(); $pconfig['timeservers_host'] = explode(' ', $config['system']['timeservers']); } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { $pconfig = $_POST; $input_errors = array(); if (!empty($pconfig['orphan']) && ($pconfig['orphan'] < 0 || $pconfig['orphan'] > 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]); } } // 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'] = !empty($pconfig['timeservers_prefer']) ? trim(implode(' ', $pconfig['timeservers_prefer'])) : null; $a_ntpd['interface'] = !empty($pconfig['interface']) ? implode(',', $pconfig['interface']) : null; // 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($pconfig['leapsec'])) { $a_ntpd['leapsec'] = base64_encode($a_ntpd['leapsec']); } elseif(isset($a_ntpd['leapsec'])) { unset($a_ntpd['leapsec']); } if (!empty($pconfig['custom_options'])) { $a_ntpd['custom_options'] = str_replace("\r\n", "\n", $pconfig['custom_options']); } elseif (isset($a_ntpd['custom_options'])) { unset($a_ntpd['custom_options']); } 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"); ntpd_configure_start(); header(url_safe('Location: /services_ntpd.php')); exit; } } $service_hook = 'ntpd'; legacy_html_escape_form_data($pconfig); include("head.inc"); ?>