.
* 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.
*
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgment:
* "This product includes software developed by the pfSense Project
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
*
* 4. The names "pfSense" and "pfSense Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* coreteam@pfsense.org.
*
* 5. Products derived from this software may not be called "pfSense"
* nor may "pfSense" appear in their names without prior written
* permission of the Electric Sheep Fencing, LLC.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
*
* "This product includes software developed by the pfSense Project
* for use in the pfSense software distribution (http://www.pfsense.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
* EXPRESSED 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 pfSense PROJECT OR
* ITS CONTRIBUTORS 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.
*/
##|+PRIV
##|*IDENT=page-status-ntp
##|*NAME=Status: NTP
##|*DESCR=Allow access to the 'Status: NTP' page.
##|*MATCH=status_ntpd.php*
##|-PRIV
require_once("guiconfig.inc");
if (!isset($config['ntpd']['noquery'])) {
if (isset($config['system']['ipv6allow'])) {
$inet_version = "";
} else {
$inet_version = " -4";
}
exec("/usr/local/sbin/ntpq -pn $inet_version | /usr/bin/tail +3", $ntpq_output);
$ntpq_servers = array();
foreach ($ntpq_output as $line) {
$server = array();
switch (substr($line, 0, 1)) {
case " ":
$server['status'] = gettext("Unreach/Pending");
break;
case "*":
$server['status'] = gettext("Active Peer");
break;
case "+":
$server['status'] = gettext("Candidate");
break;
case "o":
$server['status'] = gettext("PPS Peer");
break;
case "#":
$server['status'] = gettext("Selected");
break;
case ".":
$server['status'] = gettext("Excess Peer");
break;
case "x":
$server['status'] = gettext("False Ticker");
break;
case "-":
$server['status'] = gettext("Outlier");
break;
}
$line = substr($line, 1);
$peerinfo = preg_split("/[\s\t]+/", $line);
$server['server'] = $peerinfo[0];
$server['refid'] = $peerinfo[1];
$server['stratum'] = $peerinfo[2];
$server['type'] = $peerinfo[3];
$server['when'] = $peerinfo[4];
$server['poll'] = $peerinfo[5];
$server['reach'] = $peerinfo[6];
$server['delay'] = $peerinfo[7];
$server['offset'] = $peerinfo[8];
$server['jitter'] = $peerinfo[9];
$ntpq_servers[] = $server;
}
exec("/usr/local/sbin/ntpq -c clockvar $inet_version", $ntpq_clockvar_output);
foreach ($ntpq_clockvar_output as $line) {
if (substr($line, 0, 9) == "timecode=") {
$tmp = explode('"', $line);
$tmp = $tmp[1];
if (substr($tmp, 0, 6) == '$GPRMC') {
$gps_vars = explode(",", $tmp);
$gps_ok = ($gps_vars[2] == "A");
$gps_lat_deg = substr($gps_vars[3], 0, 2);
$gps_lat_min = substr($gps_vars[3], 2);
$gps_lon_deg = substr($gps_vars[5], 0, 3);
$gps_lon_min = substr($gps_vars[5], 3);
$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
$gps_lat_dir = $gps_vars[4];
$gps_lon_dir = $gps_vars[6];
} elseif (substr($tmp, 0, 6) == '$GPGGA') {
$gps_vars = explode(",", $tmp);
$gps_ok = $gps_vars[6];
$gps_lat_deg = substr($gps_vars[2], 0, 2);
$gps_lat_min = substr($gps_vars[2], 2);
$gps_lon_deg = substr($gps_vars[4], 0, 3);
$gps_lon_min = substr($gps_vars[4], 3);
$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
$gps_alt = $gps_vars[9];
$gps_alt_unit = $gps_vars[10];
$gps_sat = (int)$gps_vars[7];
$gps_lat_dir = $gps_vars[3];
$gps_lon_dir = $gps_vars[5];
} elseif (substr($tmp, 0, 6) == '$GPGLL') {
$gps_vars = preg_split('/[,\*]+/', $tmp);
$gps_ok = ($gps_vars[6] == "A");
$gps_lat_deg = substr($gps_vars[1], 0, 2);
$gps_lat_min = substr($gps_vars[1], 2);
$gps_lon_deg = substr($gps_vars[3], 0, 3);
$gps_lon_min = substr($gps_vars[3], 3);
$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
$gps_lat_dir = $gps_vars[2];
$gps_lon_dir = $gps_vars[4];
}
}
}
}
if (isset($gps_ok) && isset($config['ntpd']['gps']['extstatus']) && ($config['ntpd']['gps']['nmeaset']['gpgsv'] || $config['ntpd']['gps']['nmeaset']['gpgga'])) {
$lookfor['GPGSV'] = $config['ntpd']['gps']['nmeaset']['gpgsv'];
$lookfor['GPGGA'] = !isset($gps_sat) && $config['ntpd']['gps']['nmeaset']['gpgga'];
$gpsport = fopen('/dev/gps0', 'r+');
while ($gpsport && ($lookfor['GPGSV'] || $lookfor['GPGGA'])) {
$buffer = fgets($gpsport);
if ($lookfor['GPGSV'] && substr($buffer, 0, 6) == '$GPGSV') {
$gpgsv = explode(',', $buffer);
$gps_satview = (int)$gpgsv[3];
$lookfor['GPGSV'] = 0;
} elseif ($lookfor['GPGGA'] && substr($buffer, 0, 6) == '$GPGGA') {
$gpgga = explode(',', $buffer);
$gps_sat = (int)$gpgga[7];
$gps_alt = $gpgga[9];
$gps_alt_unit = $gpgga[10];
$lookfor['GPGGA'] = 0;
}
}
}
// Responding to an AJAX call, we return the GPS data or the status data depending on $_REQUEST['dogps']
if ($_REQUEST['ajax']) {
if ($_REQUEST['dogps'] == "yes") {
print_gps();
} else {
print_status();
}
exit;
}
function print_status() {
global $config, $ntpq_servers;
if (isset($config['ntpd']['noquery'])):
print("
\n");
print('');
printf(gettext("Statistics unavailable because ntpq and ntpdc queries are disabled in the %sNTP service settings%s"), '', '');
print(" | \n");
print("
\n");
elseif (count($ntpq_servers) == 0):
print("\n");
print('');
printf(gettext("No peers found, %sis the ntp service running?%s"), '', '');
print(" | \n");
print("
\n");
else:
$i = 0;
foreach ($ntpq_servers as $server):
print("\n");
print("" . $server['status'] . " | \n");
print("" . $server['server'] . " | \n");
print("" . $server['refid'] . " | \n");
print("" . $server['stratum'] . " | \n");
print("" . $server['type'] . " | \n");
print("" . $server['when'] . " | \n");
print("" . $server['poll'] . " | \n");
print("" . $server['reach'] . " | \n");
print("" . $server['delay'] . " | \n");
print("" . $server['offset'] . " | \n");
print("" . $server['jitter'] . " | \n");
print("
\n");
$i++;
endforeach;
endif;
}
function print_gps() {
global $gps_lat, $gps_lon, $gps_lat_deg, $gps_lon_deg, $gps_lat_min, $gps_lon_min, $gps_lat_dir, $gps_lon_dir,
$gps_alt, $gps_alt_unit, $gps_sat, $gps_satview, $gps_goo_lnk;
print("\n");
print("\n");
printf("%.5f", $gps_lat);
print(" (");
printf("%d%s", $gps_lat_deg, "°");
printf("%.5f", $gps_lat_min);
print($gps_lat_dir);
print(")");
print(" | \n");
print("\n");
printf("%.5f", $gps_lon);
print(" (");
printf("%d%s", $gps_lon_deg, "°");
printf("%.5f", $gps_lon_min);
print($gps_lon_dir);
print(")");
print(" | \n");
if (isset($gps_alt)) {
print("\n");
print($gps_alt . ' ' . $gps_alt_unit);
print(" | \n");
}
if (isset($gps_sat) || isset($gps_satview)) {
print('');
if (isset($gps_satview)) {
print(gettext('in view ') . intval($gps_satview));
}
if (isset($gps_sat) && isset($gps_satview)) {
print(', ');
}
if (isset($gps_sat)) {
print(gettext('in use ') . $gps_sat);
}
print(" | \n");
}
print("
\n");
print("\n");
print('' . gettext("Google Maps Link") . ' | ');
print("
\n");
}
$pgtitle = array(gettext("Status"), gettext("NTP"));
$shortcut_section = "ntp";
include("head.inc");
?>
=gettext("Network Time Protocol Status");?>
=gettext("Status")?> |
=gettext("Server")?> |
=gettext("Ref ID")?> |
=gettext("Stratum")?> |
=gettext("Type")?> |
=gettext("When")?> |
=gettext("Poll")?> |
=gettext("Reach")?> |
=gettext("Delay")?> |
=gettext("Offset")?> |
=gettext("Jitter")?> |
=print_status()?>
=gettext("GPS Information");?>
=gettext("Clock Latitude")?> |
=gettext("Clock Longitude")?> |
=gettext("Clock Altitude")?> |
=gettext("Satellites")?> |
=print_gps()?>