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

(legacy) cleanup status_ntpd.php

parent a70e1e97
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2013 Dagorlad
Copyright (C) 2012 Jim Pingle
All rights reserved.
......@@ -33,13 +33,10 @@ require_once("services.inc");
require_once("interfaces.inc");
if(!isset($config['ntpd']['noquery'])) {
exec("/usr/local/sbin/ntpq -pn | /usr/bin/tail +3", $ntpq_output);
$ntpq_servers = array();
foreach ($ntpq_output as $line) {
$server = array();
switch (substr($line, 0, 1)) {
case " ":
$server['status'] = "Unreach/Pending";
......@@ -66,10 +63,8 @@ if(!isset($config['ntpd']['noquery'])) {
$server['status'] = "Outlier";
break;
}
$line = substr($line, 1);
$peerinfo = preg_split("/[\s\t]+/", $line);
$server['server'] = $peerinfo[0];
$server['refid'] = $peerinfo[1];
$server['stratum'] = $peerinfo[2];
......@@ -80,7 +75,6 @@ if(!isset($config['ntpd']['noquery'])) {
$server['delay'] = $peerinfo[7];
$server['offset'] = $peerinfo[8];
$server['jitter'] = $peerinfo[9];
$ntpq_servers[] = $server;
}
......@@ -100,7 +94,7 @@ if(!isset($config['ntpd']['noquery'])) {
$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
$gps_lon = $gps_lon_deg + $gps_lon_min;
$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
}elseif (substr($tmp, 0, 6) == '$GPGGA') {
} elseif (substr($tmp, 0, 6) == '$GPGGA') {
$gps_vars = explode(",", $tmp);
$gps_ok = $gps_vars[6];
$gps_lat_deg = substr($gps_vars[2], 0, 2);
......@@ -128,7 +122,6 @@ if(!isset($config['ntpd']['noquery'])) {
}
}
}
}
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
......@@ -137,7 +130,6 @@ if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] ==
while($gpsport){
$buffer = fgets($gpsport);
if(substr($buffer, 0, 6)=='$GPGSV'){
//echo $buffer."\n";
$gpgsv = explode(',',$buffer);
$gps_satview = $gpgsv[3];
break;
......@@ -146,114 +138,94 @@ if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] ==
}
$service_hook = 'ntpd';
include("head.inc");
?>
<body>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<section class="col-xs-12">
<div class="content-box">
<header class="content-box-head container-fluid">
<h3>Network Time Protocol Status</h3>
<h3><?=gettext("Network Time Protocol Status");?></h3>
</header>
<div class="content-box-main">
<div class="table-responsive">
<table class="table table-striped table-sort sortable __nomb">
<table class="table table-striped">
<thead>
<tr>
<th class="listhdrr"><?=gettext("Status"); ?></th>
<th class="listhdrr"><?=gettext("Server"); ?></th>
<th class="listhdrr"><?=gettext("Ref ID"); ?></th>
<th class="listhdrr"><?=gettext("Stratum"); ?></th>
<th class="listhdrr"><?=gettext("Type"); ?></th>
<th class="listhdrr"><?=gettext("When"); ?></th>
<th class="listhdrr"><?=gettext("Poll"); ?></th>
<th class="listhdrr"><?=gettext("Reach"); ?></th>
<th class="listhdrr"><?=gettext("Delay"); ?></th>
<th class="listhdrr"><?=gettext("Offset"); ?></th>
<th class="listhdr"><?=gettext("Jitter"); ?></th>
<th><?=gettext("Status"); ?></th>
<th><?=gettext("Server"); ?></th>
<th><?=gettext("Ref ID"); ?></th>
<th><?=gettext("Stratum"); ?></th>
<th><?=gettext("Type"); ?></th>
<th><?=gettext("When"); ?></th>
<th><?=gettext("Poll"); ?></th>
<th><?=gettext("Reach"); ?></th>
<th><?=gettext("Delay"); ?></th>
<th><?=gettext("Offset"); ?></th>
<th><?=gettext("Jitter"); ?></th>
</tr>
</thead>
<tbody>
<?php if (isset($config['ntpd']['noquery'])): ?>
<tr><td class="listlr" colspan="11" align="center">
<?= sprintf(gettext('Statistics unavailable because ntpq and ntpdc queries are disabled in the %sNTP service settings%s.'), '<a href="services_ntpd.php">','</a>') ?>
</td></tr>
<?php elseif (count($ntpq_servers) == 0): ?>
<tr><td class="listlr" colspan="11" align="center">
<?= sprintf(gettext('No peers found, %sis the ntp service running%s?'), '<a href="status_services.php">','</a>') ?>
</td></tr>
<?php else: ?>
<?php $i = 0; foreach ($ntpq_servers as $server): ?>
<?php
if (isset($config['ntpd']['noquery'])): ?>
<tr>
<td class="listlr nowrap">
<?=$server['status'];?>
</td>
<td class="listr">
<?=$server['server'];?>
</td>
<td class="listr">
<?=$server['refid'];?>
</td>
<td class="listr">
<?=$server['stratum'];?>
</td>
<td class="listr">
<?=$server['type'];?>
</td>
<td class="listr">
<?=$server['when'];?>
</td>
<td class="listr">
<?=$server['poll'];?>
</td>
<td class="listr">
<?=$server['reach'];?>
</td>
<td class="listr">
<?=$server['delay'];?>
</td>
<td class="listr">
<?=$server['offset'];?>
<td colspan="11">
<?= sprintf(gettext('Statistics unavailable because ntpq and ntpdc queries are disabled in the %sNTP service settings%s.'), '<a href="services_ntpd.php">','</a>') ?>
</td>
<td class="listr">
<?=$server['jitter'];?>
</tr>
<?php
elseif (count($ntpq_servers) == 0): ?>
<tr>
<td colspan="11">
<?= sprintf(gettext('No peers found, %sis the ntp service running%s?'), '<a href="status_services.php">','</a>') ?>
</td>
</tr>
<?php $i++; endforeach; endif; ?>
<?php
else:
$i = 0;
foreach ($ntpq_servers as $server): ?>
<tr>
<td><?=$server['status'];?></td>
<td><?=$server['server'];?></td>
<td><?=$server['refid'];?></td>
<td><?=$server['stratum'];?></td>
<td><?=$server['type'];?></td>
<td><?=$server['when'];?></td>
<td><?=$server['poll'];?></td>
<td><?=$server['reach'];?></td>
<td><?=$server['delay'];?></td>
<td><?=$server['offset'];?></td>
<td><?=$server['jitter'];?></td>
</tr>
<?php
$i++;
endforeach;
endif; ?>
</tbody>
</table>
<?php if (($gps_ok) && ($gps_lat) && ($gps_lon)): ?>
<?php $gps_goo_lnk = 2; ?>
<table class="table table-striped table-sort sortable">
<?php
if (($gps_ok) && ($gps_lat) && ($gps_lon)):
$gps_goo_lnk = 2; ?>
<table class="table table-striped">
<thead>
<tr>
<th class="listhdrr"><?=gettext("Clock Latitude"); ?></th>
<th class="listhdrr"><?=gettext("Clock Longitude"); ?></th>
<?php if (isset($gps_alt)) { echo '<th class="listhdrr">' . gettext("Clock Altitude") . '</th>'; $gps_goo_lnk++;}?>
<?php if (isset($gps_sat) || isset($gps_satview)) { echo '<th class="listhdrr">' . gettext("Satellites") . '</th>'; $gps_goo_lnk++;}?>
<th><?=gettext("Clock Latitude"); ?></th>
<th><?=gettext("Clock Longitude"); ?></th>
<?php if (isset($gps_alt)) { echo '<th>' . gettext("Clock Altitude") . '</th>'; $gps_goo_lnk++;}?>
<?php if (isset($gps_sat) || isset($gps_satview)) { echo '<th>' . gettext("Satellites") . '</th>'; $gps_goo_lnk++;}?>
</tr>
</thead>
<tbody>
<tr>
<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>
<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 if (isset($gps_alt)) { echo '<td class="listlr" align="center">' . $gps_alt . ' ' . $gps_alt_unit . '</td>';}?>
<td class="listr" align="center">
<?php
<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>
<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 (isset($gps_alt)) { echo '<td>' . $gps_alt . ' ' . $gps_alt_unit . '</td>';}?>
<td>
<?php
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;}
......@@ -261,11 +233,12 @@ include("head.inc");
</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>
<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>
</tr>
</tbody>
</table>
<?php endif; ?>
<?php
endif; ?>
</div>
</div>
</div>
......@@ -273,5 +246,4 @@ include("head.inc");
</div>
</div>
</section>
<?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