Commit b7345eb4 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) refactor services_ntpd_pps.php

(cherry picked from commit f4b773de)
parent 14f7dd4b
<?php <?php
/* /*
Copyright (C) 2014-2015 Deciso B.V. Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2013 Dagorlad Copyright (C) 2013 Dagorlad
All rights reserved. All rights reserved.
...@@ -32,180 +32,177 @@ require_once("services.inc"); ...@@ -32,180 +32,177 @@ require_once("services.inc");
require_once("system.inc"); require_once("system.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
if (!isset($config['ntpd']) || !is_array($config['ntpd'])) if (!isset($config['ntpd']) || !is_array($config['ntpd'])) {
$config['ntpd'] = array(); $config['ntpd'] = array();
if (!isset($config['ntpd']['pps'])) }
if (!isset($config['ntpd']['pps'])) {
$config['ntpd']['pps'] = array(); $config['ntpd']['pps'] = array();
}
if ($_POST) {
unset($input_errors);
if (!empty($_POST['ppsport']) && file_exists('/dev/'.$_POST['ppsport']))
$config['ntpd']['pps']['port'] = $_POST['ppsport'];
/* if port is not set, remove all the pps config */
else unset($config['ntpd']['pps']);
if (!empty($_POST['ppsfudge1']))
$config['ntpd']['pps']['fudge1'] = $_POST['ppsfudge1'];
elseif (isset($config['ntpd']['pps']['fudge1']))
unset($config['ntpd']['pps']['fudge1']);
if (!empty($_POST['ppsstratum']) && ($_POST['ppsstratum']) < 17 )
$config['ntpd']['pps']['stratum'] = $_POST['ppsstratum'];
elseif (isset($config['ntpd']['pps']['stratum']))
unset($config['ntpd']['pps']['stratum']);
if (!empty($_POST['ppsselect']))
$config['ntpd']['pps']['noselect'] = $_POST['ppsselect'];
elseif (isset($config['ntpd']['pps']['noselect']))
unset($config['ntpd']['pps']['noselect']);
if (!empty($_POST['ppsflag2']))
$config['ntpd']['pps']['flag2'] = $_POST['ppsflag2'];
elseif (isset($config['ntpd']['pps']['flag2']))
unset($config['ntpd']['pps']['flag2']);
if (!empty($_POST['ppsflag3']))
$config['ntpd']['pps']['flag3'] = $_POST['ppsflag3'];
elseif (isset($config['ntpd']['pps']['flag3']))
unset($config['ntpd']['pps']['flag3']);
if (!empty($_POST['ppsflag4']))
$config['ntpd']['pps']['flag4'] = $_POST['ppsflag4'];
elseif (isset($config['ntpd']['pps']['flag4']))
unset($config['ntpd']['pps']['flag4']);
if (!empty($_POST['ppsrefid']))
$config['ntpd']['pps']['refid'] = $_POST['ppsrefid'];
elseif (isset($config['ntpd']['pps']['refid']))
unset($config['ntpd']['pps']['refid']);
$copy_fields = array('port', 'fudge1', 'stratum', 'flag2', 'flag3', 'flag4', 'refid');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
foreach ($copy_fields as $fieldname) {
if (isset($config['ntpd']['pps'][$fieldname])) {
$pconfig[$fieldname] = $config['ntpd']['pps'][$fieldname];
} else {
$pconfig[$fieldname] = null;
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST;
$input_errors = array();
if (!empty($pconfig['stratum']) && ($pconfig['stratum'] > 17 || $pconfig['stratum'] < 0 || !is_numeric($pconfig['stratum']))) {
$input_errors[] = gettext("Clock stratum must be a number in the range 0..16");
}
if (count($input_errors) == 0) {
$pps = array();
foreach ($copy_fields as $fieldname) {
if (!empty($pconfig[$fieldname])) {
$pps[$fieldname] = $pconfig[$fieldname];
}
}
$config['ntpd']['pps'] = $pps;
write_config("Updated NTP PPS Settings"); write_config("Updated NTP PPS Settings");
system_ntp_configure();
$retval = 0; header("Location: services_ntpd_pps.php");
$retval = system_ntp_configure(); exit;
$savemsg = get_std_save_message(); }
} }
$pconfig = &$config['ntpd']['pps'];
$service_hook = 'ntpd'; $service_hook = 'ntpd';
legacy_html_escape_form_data($pconfig);
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
<?php include("fbegin.inc"); ?> <?php include("fbegin.inc"); ?>
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?> <?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<section class="col-xs-12"> <section class="col-xs-12">
<div class="tab-content content-box col-xs-12"> <div class="tab-content content-box col-xs-12">
<form method="post" name="iform" id="iform">
<form action="services_ntpd_pps.php" method="post" name="iform" id="iform">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
<thead>
<tr> <tr>
<td colspan="2" valign="top" class="listtopic"><?=gettext("NTP PPS Configuration"); ?></td> <td width="22%">
</tr> <strong><?=gettext("NTP PPS Configuration"); ?></strong>
<tr>
<td width="22%" valign="top" class="vncellreq">
</td> </td>
<td width="78%" class="vtable"><?php echo gettext("Devices with a Pulse Per Second output such as radios that receive a time signal from DCF77 (DE), JJY (JP), MSF (GB) or WWVB (US) may be used as a PPS reference for NTP.");?> <td width="78%" align="right">
<?php echo gettext("A serial GPS may also be used, but the serial GPS driver would usually be the better option.");?> <small><?=gettext("full help"); ?> </small>
<?php echo gettext("A PPS signal only provides a reference to the change of a second, so at least one other source to number the seconds is required.");?> <i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
<br /> &nbsp;&nbsp;
<br /><strong><?php echo gettext("Note");?>:</strong> <?php echo gettext("At least 3 additional time sources should be configured under"); ?> <a href="services_ntpd.php"><?php echo gettext("Services > NTP"); ?></a> <?php echo gettext("to reliably supply the time of each PPS pulse."); ?>
</td> </td>
</tr> </tr>
<?php $serialports = glob("/dev/cua?[0-9]{,.[0-9]}", GLOB_BRACE); ?> </thead>
<?php if (!empty($serialports)): ?> <tbody>
<?php
$serialports = glob("/dev/cua?[0-9]{,.[0-9]}", GLOB_BRACE);
if (!empty($serialports)):?>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Serial port') ?></td> <td><a id="help_for_gpsport" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Serial port') ?></td>
<td width="78%" class="vtable"> <td>
<select name="ppsport" class="formselect"> <select name="port" class="selectpicker">
<option value="">none</option> <option value=""><?=gettext("none");?></option>
<?php foreach ($serialports as $port): <?php
$shortport = substr($port,5); foreach ($serialports as $port):?>
$selected = ($shortport == isset($pconfig['port'])?$pconfig['port']:null) ? " selected=\"selected\"" : "";?> <option value="<?=substr($port,5);?>" <?=substr($port,5) === $pconfig['port'] ? 'selected="selected"' : "";?>>
<option value="<?php echo $shortport;?>"<?php echo $selected;?>><?php echo $shortport;?></option> <?=substr($port,5);?>
<?php endforeach; ?> </option>
</select>&nbsp; <?php
<?php echo gettext("All serial ports are listed, be sure to pick the port with the PPS source attached."); ?> endforeach; ?>
</select>
<div class="hidden" for="help_for_gpsport">
<?=gettext("All serial ports are listed, be sure to pick the port with the PPS source attached."); ?>
</div>
</td> </td>
</tr> </tr>
<?php endif; ?> <?php
endif;?>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Fudge time') ?></td> <td><a id="help_for_fudge1" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Fudge time') ?> (<?=gettext("seconds");?>)</td>
<td width="78%" class="vtable"> <td>
<input name="ppsfudge1" type="text" class="formfld unknown" id="ppsfudge1" min="-1" max="1" size="20" value="<?=htmlspecialchars(isset($pconfig['fudge1'])?$pconfig['fudge1']:"");?>" />(<?php echo gettext("seconds");?>)<br /> <input name="fudge1" type="text" value="<?=$pconfig['fudge1'];?>" />
<?php echo gettext("Fudge time is used to specify the PPS signal offset from the actual second such as the transmission delay between the transmitter and the receiver.");?> (<?php echo gettext("default");?>: 0.0).</td> <div class="hidden" for="help_for_fudge1">
<?=gettext("Fudge time is used to specify the PPS signal offset from the actual second such as the transmission delay between the transmitter and the receiver.");?> (<?=gettext("default");?>: 0.0).</td>
</div>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Stratum') ?></td> <td><a id="help_for_stratum" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Stratum') ?></td>
<td width="78%" class="vtable"> <td>
<input name="ppsstratum" type="text" class="formfld unknown" id="ppsstratum" max="16" size="20" value="<?=htmlspecialchars(isset($pconfig['stratum'])?$pconfig['stratum']:"");?>" /><?php echo gettext("(0-16)");?><br /> <input name="stratum" type="text" value="<?=$pconfig['stratum'];?>" />
<?php echo gettext("This may be used to change the PPS Clock stratum");?> (<?php echo gettext("default");?>: 0). <?php echo gettext("This may be useful if, for some reason, you want ntpd to prefer a different clock and just monitor this source."); ?></td> <div class="hidden" for="help_for_stratum">
<?=gettext("(0-16)");?><br />
<?=gettext("This may be used to change the PPS Clock stratum");?> (<?=gettext("default");?>: 0). <?=gettext("This may be useful if, for some reason, you want ntpd to prefer a different clock and just monitor this source."); ?></td>
</div>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Flags') ?></td> <td><a id="help_for_flags" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Flags') ?></td>
<td width="78%" class="vtable">
<table summary="flags">
<tr>
<td> <td>
<?php echo gettext("Normally there should be no need to change these options from the defaults."); ?><br /> <table class="table table-condensed">
</td>
</tr>
</table>
<table>
<tr> <tr>
<td> <td>
<input name="ppsflag2" type="checkbox" class="formcheckbox" id="ppsflag2"<?php if(!empty($pconfig['flag2'])) echo " checked=\"checked\""; ?> /> <input name="flag2" type="checkbox" <?=!empty($pconfig['flag2']) ? " checked=\"checked\"" : ""; ?> />
</td> </td>
<td> <td>
<span class="vexpl"><?php echo gettext("Enable falling edge PPS signal processing (default: rising edge)."); ?></span> <?=gettext("Enable falling edge PPS signal processing (default: rising edge)."); ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<input name="ppsflag3" type="checkbox" class="formcheckbox" id="ppsflag3"<?php if(!empty($pconfig['flag3'])) echo " checked=\"checked\""; ?> /> <input name="flag3" type="checkbox" <?=!empty($pconfig['flag3']) ? " checked=\"checked\"" : ""; ?> />
</td> </td>
<td> <td>
<span class="vexpl"><?php echo gettext("Enable kernel PPS clock discipline (default: disabled)."); ?></span> <?=gettext("Enable kernel PPS clock discipline (default: disabled)."); ?>
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<input name="ppsflag4" type="checkbox" class="formcheckbox" id="ppsflag4"<?php if(!empty($pconfig['flag4'])) echo " checked=\"checked\""; ?> /> <input name="flag4" type="checkbox" <?=!empty($pconfig['flag4']) ? " checked=\"checked\"" : ""; ?> />
</td> </td>
<td> <td>
<span class="vexpl"><?php echo gettext("Record a timestamp once for each second, useful for constructing Allan deviation plots (default: disabled)."); ?></span> <?=gettext("Record a timestamp once for each second, useful for constructing Allan deviation plots (default: disabled)."); ?>
</td> </td>
</tr> </tr>
</table> </table>
<div class="hidden" for="help_for_flags">
<?=gettext("Normally there should be no need to change these options from the defaults."); ?><br />
</div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Clock ID') ?></td> <td><a id="help_for_refid" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Clock ID') ?></td>
<td width="78%" class="vtable"> <td>
<input name="ppsrefid" type="text" class="formfld unknown" id="ppsrefid" maxlength= "4" size="20" value="<?php htmlspecialchars(isset($pconfig['refid'])?$pconfig['refid']:"");?>" /><?php echo gettext("(1 to 4 charactors)");?><br /> <input name="refid" type="text" value="<?=$pconfig['refid'];?>" />
<?php echo gettext("This may be used to change the PPS Clock ID");?> (<?php echo gettext("default");?>: PPS).</td> <div class="hidden" for="help_for_refid">
<?=gettext("(1 to 4 charactors)");?><br />
<?=gettext("This may be used to change the PPS Clock ID");?> (<?=gettext("default");?>: PPS).
</div>
</td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top">&nbsp;</td> <td></td>
<td width="78%"> <td>
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" /> <input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
</td> </td>
</tr> </tr>
</tbody>
<tfoot>
<tr>
<td colspan="2">
<?=gettext("Devices with a Pulse Per Second output such as radios that receive a time signal from DCF77 (DE), JJY (JP), MSF (GB) or WWVB (US) may be used as a PPS reference for NTP.");?>
<?=gettext("A serial GPS may also be used, but the serial GPS driver would usually be the better option.");?>
<?=gettext("A PPS signal only provides a reference to the change of a second, so at least one other source to number the seconds is required.");?>
<br />
<br /><strong><?=gettext("Note");?>:</strong> <?=gettext("At least 3 additional time sources should be configured under"); ?> <a href="services_ntpd.php"><?=gettext("Services > NTP"); ?></a> <?=gettext("to reliably supply the time of each PPS pulse."); ?>
</td>
</tr>
</tfoot>
</table> </table>
</div> </div>
</form> </form>
...@@ -215,5 +212,4 @@ include("head.inc"); ...@@ -215,5 +212,4 @@ include("head.inc");
</div> </div>
</div> </div>
</section> </section>
<?php include("foot.inc"); ?> <?php include("foot.inc"); ?>
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