Commit 0ede7b89 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) cleanup status_ntpd.php

parent a70e1e97
<?php <?php
/* /*
Copyright (C) 2014-2015 Deciso B.V. Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2013 Dagorlad Copyright (C) 2013 Dagorlad
Copyright (C) 2012 Jim Pingle Copyright (C) 2012 Jim Pingle
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("guiconfig.inc"); require_once("guiconfig.inc");
...@@ -33,245 +33,217 @@ require_once("services.inc"); ...@@ -33,245 +33,217 @@ require_once("services.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
if(!isset($config['ntpd']['noquery'])) { if(!isset($config['ntpd']['noquery'])) {
exec("/usr/local/sbin/ntpq -pn | /usr/bin/tail +3", $ntpq_output);
exec("/usr/local/sbin/ntpq -pn | /usr/bin/tail +3", $ntpq_output); $ntpq_servers = array();
foreach ($ntpq_output as $line) {
$ntpq_servers = array(); $server = array();
foreach ($ntpq_output as $line) { switch (substr($line, 0, 1)) {
$server = array(); case " ":
$server['status'] = "Unreach/Pending";
switch (substr($line, 0, 1)) { break;
case " ": case "*":
$server['status'] = "Unreach/Pending"; $server['status'] = "Active Peer";
break; break;
case "*": case "+":
$server['status'] = "Active Peer"; $server['status'] = "Candidate";
break; break;
case "+": case "o":
$server['status'] = "Candidate"; $server['status'] = "PPS Peer";
break; break;
case "o": case "#":
$server['status'] = "PPS Peer"; $server['status'] = "Selected";
break; break;
case "#": case ".":
$server['status'] = "Selected"; $server['status'] = "Excess Peer";
break; break;
case ".": case "x":
$server['status'] = "Excess Peer"; $server['status'] = "False Ticker";
break; break;
case "x": case "-":
$server['status'] = "False Ticker"; $server['status'] = "Outlier";
break; break;
case "-": }
$server['status'] = "Outlier"; $line = substr($line, 1);
break; $peerinfo = preg_split("/[\s\t]+/", $line);
} $server['server'] = $peerinfo[0];
$server['refid'] = $peerinfo[1];
$line = substr($line, 1); $server['stratum'] = $peerinfo[2];
$peerinfo = preg_split("/[\s\t]+/", $line); $server['type'] = $peerinfo[3];
$server['when'] = $peerinfo[4];
$server['server'] = $peerinfo[0]; $server['poll'] = $peerinfo[5];
$server['refid'] = $peerinfo[1]; $server['reach'] = $peerinfo[6];
$server['stratum'] = $peerinfo[2]; $server['delay'] = $peerinfo[7];
$server['type'] = $peerinfo[3]; $server['offset'] = $peerinfo[8];
$server['when'] = $peerinfo[4]; $server['jitter'] = $peerinfo[9];
$server['poll'] = $peerinfo[5]; $ntpq_servers[] = $server;
$server['reach'] = $peerinfo[6]; }
$server['delay'] = $peerinfo[7];
$server['offset'] = $peerinfo[8]; exec("/usr/local/sbin/ntpq -c clockvar", $ntpq_clockvar_output);
$server['jitter'] = $peerinfo[9]; foreach ($ntpq_clockvar_output as $line) {
if (substr($line, 0, 9) == "timecode=") {
$ntpq_servers[] = $server; $tmp = explode('"', $line);
} $tmp = $tmp[1];
if (substr($tmp, 0, 6) == '$GPRMC') {
exec("/usr/local/sbin/ntpq -c clockvar", $ntpq_clockvar_output); $gps_vars = explode(",", $tmp);
foreach ($ntpq_clockvar_output as $line) { $gps_ok = ($gps_vars[2] == "A");
if (substr($line, 0, 9) == "timecode=") { $gps_lat_deg = substr($gps_vars[3], 0, 2);
$tmp = explode('"', $line); $gps_lat_min = substr($gps_vars[3], 2) / 60.0;
$tmp = $tmp[1]; $gps_lon_deg = substr($gps_vars[5], 0, 3);
if (substr($tmp, 0, 6) == '$GPRMC') { $gps_lon_min = substr($gps_vars[5], 3) / 60.0;
$gps_vars = explode(",", $tmp); $gps_lat = $gps_lat_deg + $gps_lat_min;
$gps_ok = ($gps_vars[2] == "A"); $gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
$gps_lat_deg = substr($gps_vars[3], 0, 2); $gps_lon = $gps_lon_deg + $gps_lon_min;
$gps_lat_min = substr($gps_vars[3], 2) / 60.0; $gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
$gps_lon_deg = substr($gps_vars[5], 0, 3); } elseif (substr($tmp, 0, 6) == '$GPGGA') {
$gps_lon_min = substr($gps_vars[5], 3) / 60.0; $gps_vars = explode(",", $tmp);
$gps_lat = $gps_lat_deg + $gps_lat_min; $gps_ok = $gps_vars[6];
$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1); $gps_lat_deg = substr($gps_vars[2], 0, 2);
$gps_lon = $gps_lon_deg + $gps_lon_min; $gps_lat_min = substr($gps_vars[2], 2) / 60.0;
$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1); $gps_lon_deg = substr($gps_vars[4], 0, 3);
}elseif (substr($tmp, 0, 6) == '$GPGGA') { $gps_lon_min = substr($gps_vars[4], 3) / 60.0;
$gps_vars = explode(",", $tmp); $gps_lat = $gps_lat_deg + $gps_lat_min;
$gps_ok = $gps_vars[6]; $gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
$gps_lat_deg = substr($gps_vars[2], 0, 2); $gps_lon = $gps_lon_deg + $gps_lon_min;
$gps_lat_min = substr($gps_vars[2], 2) / 60.0; $gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
$gps_lon_deg = substr($gps_vars[4], 0, 3); $gps_alt = $gps_vars[9];
$gps_lon_min = substr($gps_vars[4], 3) / 60.0; $gps_alt_unit = $gps_vars[10];
$gps_lat = $gps_lat_deg + $gps_lat_min; $gps_sat = $gps_vars[7];
$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1); }elseif (substr($tmp, 0, 6) == '$GPGLL') {
$gps_lon = $gps_lon_deg + $gps_lon_min; $gps_vars = explode(",", $tmp);
$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1); $gps_ok = ($gps_vars[6] == "A");
$gps_alt = $gps_vars[9]; $gps_lat_deg = substr($gps_vars[1], 0, 2);
$gps_alt_unit = $gps_vars[10]; $gps_lat_min = substr($gps_vars[1], 2) / 60.0;
$gps_sat = $gps_vars[7]; $gps_lon_deg = substr($gps_vars[3], 0, 3);
}elseif (substr($tmp, 0, 6) == '$GPGLL') { $gps_lon_min = substr($gps_vars[3], 3) / 60.0;
$gps_vars = explode(",", $tmp); $gps_lat = $gps_lat_deg + $gps_lat_min;
$gps_ok = ($gps_vars[6] == "A"); $gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
$gps_lat_deg = substr($gps_vars[1], 0, 2); $gps_lon = $gps_lon_deg + $gps_lon_min;
$gps_lat_min = substr($gps_vars[1], 2) / 60.0; $gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
$gps_lon_deg = substr($gps_vars[3], 0, 3); }
$gps_lon_min = substr($gps_vars[3], 3) / 60.0; }
$gps_lat = $gps_lat_deg + $gps_lat_min; }
$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
$gps_lon = $gps_lon_deg + $gps_lon_min;
$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
}
}
}
} }
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) { if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board //GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
$gpsport = fopen("/dev/gps0", "r+"); $gpsport = fopen("/dev/gps0", "r+");
while($gpsport){ while($gpsport){
$buffer = fgets($gpsport); $buffer = fgets($gpsport);
if(substr($buffer, 0, 6)=='$GPGSV'){ if(substr($buffer, 0, 6)=='$GPGSV'){
//echo $buffer."\n"; $gpgsv = explode(',',$buffer);
$gpgsv = explode(',',$buffer); $gps_satview = $gpgsv[3];
$gps_satview = $gpgsv[3]; break;
break; }
} }
}
} }
$service_hook = 'ntpd'; $service_hook = 'ntpd';
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"> <section class="col-xs-12">
<div class="content-box">
<section class="col-xs-12"> <header class="content-box-head container-fluid">
<div class="content-box"> <h3><?=gettext("Network Time Protocol Status");?></h3>
<header class="content-box-head container-fluid"> </header>
<h3>Network Time Protocol Status</h3> <div class="content-box-main">
</header> <div class="table-responsive">
<table class="table table-striped">
<div class="content-box-main"> <thead>
<div class="table-responsive"> <tr>
<table class="table table-striped table-sort sortable __nomb"> <th><?=gettext("Status"); ?></th>
<th><?=gettext("Server"); ?></th>
<th><?=gettext("Ref ID"); ?></th>
<thead> <th><?=gettext("Stratum"); ?></th>
<tr> <th><?=gettext("Type"); ?></th>
<th class="listhdrr"><?=gettext("Status"); ?></th> <th><?=gettext("When"); ?></th>
<th class="listhdrr"><?=gettext("Server"); ?></th> <th><?=gettext("Poll"); ?></th>
<th class="listhdrr"><?=gettext("Ref ID"); ?></th> <th><?=gettext("Reach"); ?></th>
<th class="listhdrr"><?=gettext("Stratum"); ?></th> <th><?=gettext("Delay"); ?></th>
<th class="listhdrr"><?=gettext("Type"); ?></th> <th><?=gettext("Offset"); ?></th>
<th class="listhdrr"><?=gettext("When"); ?></th> <th><?=gettext("Jitter"); ?></th>
<th class="listhdrr"><?=gettext("Poll"); ?></th> </tr>
<th class="listhdrr"><?=gettext("Reach"); ?></th> </thead>
<th class="listhdrr"><?=gettext("Delay"); ?></th> <tbody>
<th class="listhdrr"><?=gettext("Offset"); ?></th> <?php
<th class="listhdr"><?=gettext("Jitter"); ?></th> if (isset($config['ntpd']['noquery'])): ?>
</tr> <tr>
</thead> <td colspan="11">
<tbody> <?= sprintf(gettext('Statistics unavailable because ntpq and ntpdc queries are disabled in the %sNTP service settings%s.'), '<a href="services_ntpd.php">','</a>') ?>
<?php if (isset($config['ntpd']['noquery'])): ?> </td>
<tr><td class="listlr" colspan="11" align="center"> </tr>
<?= sprintf(gettext('Statistics unavailable because ntpq and ntpdc queries are disabled in the %sNTP service settings%s.'), '<a href="services_ntpd.php">','</a>') ?> <?php
</td></tr> elseif (count($ntpq_servers) == 0): ?>
<?php elseif (count($ntpq_servers) == 0): ?> <tr>
<tr><td class="listlr" colspan="11" align="center"> <td colspan="11">
<?= sprintf(gettext('No peers found, %sis the ntp service running%s?'), '<a href="status_services.php">','</a>') ?> <?= sprintf(gettext('No peers found, %sis the ntp service running%s?'), '<a href="status_services.php">','</a>') ?>
</td></tr> </td>
<?php else: ?> </tr>
<?php $i = 0; foreach ($ntpq_servers as $server): ?> <?php
<tr> else:
<td class="listlr nowrap"> $i = 0;
<?=$server['status'];?> foreach ($ntpq_servers as $server): ?>
</td> <tr>
<td class="listr"> <td><?=$server['status'];?></td>
<?=$server['server'];?> <td><?=$server['server'];?></td>
</td> <td><?=$server['refid'];?></td>
<td class="listr"> <td><?=$server['stratum'];?></td>
<?=$server['refid'];?> <td><?=$server['type'];?></td>
</td> <td><?=$server['when'];?></td>
<td class="listr"> <td><?=$server['poll'];?></td>
<?=$server['stratum'];?> <td><?=$server['reach'];?></td>
</td> <td><?=$server['delay'];?></td>
<td class="listr"> <td><?=$server['offset'];?></td>
<?=$server['type'];?> <td><?=$server['jitter'];?></td>
</td> </tr>
<td class="listr"> <?php
<?=$server['when'];?> $i++;
</td> endforeach;
<td class="listr"> endif; ?>
<?=$server['poll'];?> </tbody>
</td> </table>
<td class="listr"> <?php
<?=$server['reach'];?> if (($gps_ok) && ($gps_lat) && ($gps_lon)):
</td> $gps_goo_lnk = 2; ?>
<td class="listr"> <table class="table table-striped">
<?=$server['delay'];?> <thead>
</td> <tr>
<td class="listr"> <th><?=gettext("Clock Latitude"); ?></th>
<?=$server['offset'];?> <th><?=gettext("Clock Longitude"); ?></th>
</td> <?php if (isset($gps_alt)) { echo '<th>' . gettext("Clock Altitude") . '</th>'; $gps_goo_lnk++;}?>
<td class="listr"> <?php if (isset($gps_sat) || isset($gps_satview)) { echo '<th>' . gettext("Satellites") . '</th>'; $gps_goo_lnk++;}?>
<?=$server['jitter'];?> </tr>
</td> </thead>
</tr> <tbody>
<?php $i++; endforeach; endif; ?> <tr>
</tbody> <td><?php echo sprintf("%.5f", $gps_lat); ?> (<?php echo sprintf("%d", $gps_lat_deg); ?>&deg; <?php echo sprintf("%.5f", $gps_lat_min*60); ?><?php echo $gps_vars[4]; ?>)</td>
</table> <td><?php echo sprintf("%.5f", $gps_lon); ?> (<?php echo sprintf("%d", $gps_lon_deg); ?>&deg; <?php echo sprintf("%.5f", $gps_lon_min*60); ?><?php echo $gps_vars[6]; ?>)</td>
<?php if (($gps_ok) && ($gps_lat) && ($gps_lon)): ?> <?php if (isset($gps_alt)) { echo '<td>' . $gps_alt . ' ' . $gps_alt_unit . '</td>';}?>
<?php $gps_goo_lnk = 2; ?> <td>
<table class="table table-striped table-sort sortable"> <?php
<thead> if (isset($gps_satview)) {echo 'in view ' . intval($gps_satview);}
<tr> if (isset($gps_sat) && isset($gps_satview)) {echo ', ';}
<th class="listhdrr"><?=gettext("Clock Latitude"); ?></th> if (isset($gps_sat)) {echo 'in use ' . $gps_sat;}
<th class="listhdrr"><?=gettext("Clock Longitude"); ?></th> ?>
<?php if (isset($gps_alt)) { echo '<th class="listhdrr">' . gettext("Clock Altitude") . '</th>'; $gps_goo_lnk++;}?> </td>
<?php if (isset($gps_sat) || isset($gps_satview)) { echo '<th class="listhdrr">' . gettext("Satellites") . '</th>'; $gps_goo_lnk++;}?> </tr>
</tr> <tr>
</thead> <td colspan="<?php echo $gps_goo_lnk; ?>"><a target="_gmaps" href="http://maps.google.com/?q=<?php echo $gps_lat; ?>,<?php echo $gps_lon; ?>">Google Maps Link</a></td>
<tbody> </tr>
<tr> </tbody>
<td class="listlr" align="center"><?php echo sprintf("%.5f", $gps_lat); ?> (<?php echo sprintf("%d", $gps_lat_deg); ?>&deg; <?php echo sprintf("%.5f", $gps_lat_min*60); ?><?php echo $gps_vars[4]; ?>)</td> </table>
<td class="listlr" align="center"><?php echo sprintf("%.5f", $gps_lon); ?> (<?php echo sprintf("%d", $gps_lon_deg); ?>&deg; <?php echo sprintf("%.5f", $gps_lon_min*60); ?><?php echo $gps_vars[6]; ?>)</td> <?php
<?php if (isset($gps_alt)) { echo '<td class="listlr" align="center">' . $gps_alt . ' ' . $gps_alt_unit . '</td>';}?> endif; ?>
<td class="listr" align="center"> </div>
<?php </div>
if (isset($gps_satview)) {echo 'in view ' . intval($gps_satview);}
if (isset($gps_sat) && isset($gps_satview)) {echo ', ';}
if (isset($gps_sat)) {echo 'in use ' . $gps_sat;}
?>
</td>
</tr>
<tr>
<td class="listlr" colspan="<?php echo $gps_goo_lnk; ?>" align="center"><a target="_gmaps" href="http://maps.google.com/?q=<?php echo $gps_lat; ?>,<?php echo $gps_lon; ?>">Google Maps Link</a></td>
</tr>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
</div>
</section>
</div> </div>
</div> </section>
</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