Project

General

Profile

Download (9.27 KB) Statistics
| Branch: | Tag: | Revision:
1 e078c882 jim-p
<?php
2
/* $Id$ */
3
/*
4
	status_ntpd.php
5 c7281770 Chris Buechler
	part of pfSense (https://www.pfsense.org/)
6 e078c882 jim-p
7 c56d07dc nagyrobi
	Copyright (C) 2013 Dagorlad
8 e078c882 jim-p
	Copyright (C) 2012 Jim Pingle
9 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
10 e078c882 jim-p
	All rights reserved.
11
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34 fdfa8f43 jim-p
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/ntpd	/usr/local/sbin/ntpq
35 cf180ccc jim-p
	pfSense_MODULE:	ntpd
36 e078c882 jim-p
*/
37
38
##|+PRIV
39
##|*IDENT=page-status-ntp
40
##|*NAME=Status: NTP page
41
##|*DESCR=Allow access to the 'Status: NTP' page.
42
##|*MATCH=status_ntpd.php*
43
##|-PRIV
44
45
require_once("guiconfig.inc");
46
47 c56d07dc nagyrobi
if(!isset($config['ntpd']['noquery'])) {
48 e4a496ae Phil Davis
	if (isset($config['system']['ipv6allow']))
49
		$inet_version = "";
50
	else
51
		$inet_version = " -4";
52 5c8843d5 jim-p
53 e4a496ae Phil Davis
	exec("/usr/local/sbin/ntpq -pn $inet_version | /usr/bin/tail +3", $ntpq_output);
54 25890c50 jim-p
55 c56d07dc nagyrobi
	$ntpq_servers = array();
56
	foreach ($ntpq_output as $line) {
57
		$server = array();
58
59
		switch (substr($line, 0, 1)) {
60
			case " ":
61
				$server['status'] = "Unreach/Pending";
62
				break;
63
			case "*":
64
				$server['status'] = "Active Peer";
65
				break;
66
			case "+":
67
				$server['status'] = "Candidate";
68
				break;
69
			case "o":
70
				$server['status'] = "PPS Peer";
71
				break;
72
			case "#":
73
				$server['status'] = "Selected";
74
				break;
75
			case ".":
76
				$server['status'] = "Excess Peer";
77
				break;
78
			case "x":
79
				$server['status'] = "False Ticker";
80
				break;
81
			case "-":
82
				$server['status'] = "Outlier";
83
				break;
84
		}
85
86
		$line = substr($line, 1);
87
		$peerinfo = preg_split("/[\s\t]+/", $line);
88
89
		$server['server'] = $peerinfo[0];
90
		$server['refid'] = $peerinfo[1];
91
		$server['stratum'] = $peerinfo[2];
92
		$server['type'] = $peerinfo[3];
93
		$server['when'] = $peerinfo[4];
94
		$server['poll'] = $peerinfo[5];
95
		$server['reach'] = $peerinfo[6];
96
		$server['delay'] = $peerinfo[7];
97
		$server['offset'] = $peerinfo[8];
98
		$server['jitter'] = $peerinfo[9];
99
100
		$ntpq_servers[] = $server;
101
	}
102
103 62a407da Phil Davis
	exec("/usr/local/sbin/ntpq -c clockvar $inet_version", $ntpq_clockvar_output);
104 c56d07dc nagyrobi
	foreach ($ntpq_clockvar_output as $line) {
105
		if (substr($line, 0, 9) == "timecode=") {
106
			$tmp = explode('"', $line);
107
			$tmp = $tmp[1];
108
			if (substr($tmp, 0, 6) == '$GPRMC') {
109
				$gps_vars = explode(",", $tmp);
110
				$gps_ok  = ($gps_vars[2] == "A");
111
				$gps_lat_deg = substr($gps_vars[3], 0, 2);
112
				$gps_lat_min = substr($gps_vars[3], 2) / 60.0;
113
				$gps_lon_deg = substr($gps_vars[5], 0, 3);
114
				$gps_lon_min = substr($gps_vars[5], 3) / 60.0;
115
				$gps_lat = $gps_lat_deg + $gps_lat_min;
116
				$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
117
				$gps_lon = $gps_lon_deg + $gps_lon_min;
118
				$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
119
			}elseif (substr($tmp, 0, 6) == '$GPGGA') {
120
				$gps_vars = explode(",", $tmp);
121
				$gps_ok  = $gps_vars[6];
122
				$gps_lat_deg = substr($gps_vars[2], 0, 2);
123
				$gps_lat_min = substr($gps_vars[2], 2) / 60.0;
124
				$gps_lon_deg = substr($gps_vars[4], 0, 3);
125
				$gps_lon_min = substr($gps_vars[4], 3) / 60.0;
126
				$gps_lat = $gps_lat_deg + $gps_lat_min;
127
				$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
128
				$gps_lon = $gps_lon_deg + $gps_lon_min;
129
				$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
130
				$gps_alt = $gps_vars[9];
131
				$gps_alt_unit = $gps_vars[10];
132
				$gps_sat = $gps_vars[7];
133
			}elseif (substr($tmp, 0, 6) == '$GPGLL') {
134
				$gps_vars = explode(",", $tmp);
135
				$gps_ok  = ($gps_vars[6] == "A");
136
				$gps_lat_deg = substr($gps_vars[1], 0, 2);
137
				$gps_lat_min = substr($gps_vars[1], 2) / 60.0;
138
				$gps_lon_deg = substr($gps_vars[3], 0, 3);
139
				$gps_lon_min = substr($gps_vars[3], 3) / 60.0;
140
				$gps_lat = $gps_lat_deg + $gps_lat_min;
141
				$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
142
				$gps_lon = $gps_lon_deg + $gps_lon_min;
143
				$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
144
			}
145
		}
146 25890c50 jim-p
	}
147
148 e078c882 jim-p
}
149
150 c56d07dc nagyrobi
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
151
	//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
152
	$gpsport = fopen("/dev/gps0", "r+");
153
	while($gpsport){
154
		$buffer = fgets($gpsport);
155
		if(substr($buffer, 0, 6)=='$GPGSV'){
156
			//echo $buffer."\n";
157
			$gpgsv = explode(',',$buffer);
158
			$gps_satview = $gpgsv[3];
159
			break;
160 5c8843d5 jim-p
		}
161
	}
162
}
163
164 e078c882 jim-p
$pgtitle = array(gettext("Status"),gettext("NTP"));
165 b32dd0a6 jim-p
$shortcut_section = "ntp";
166 e078c882 jim-p
include("head.inc");
167
?>
168
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
169
<?php include("fbegin.inc"); ?>
170 64feeb74 Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status ntpd">
171 e078c882 jim-p
<tr><td><div id="mainarea">
172 64feeb74 Colin Fleming
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="heading">
173 cf180ccc jim-p
		<tr><td class="listtopic">Network Time Protocol Status</td></tr>
174 e078c882 jim-p
	</table>
175 64feeb74 Colin Fleming
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
176 e078c882 jim-p
	<thead>
177
	<tr>
178 ec18e696 bcyrill
		<th class="listhdrr"><?=gettext("Status"); ?></th>
179
		<th class="listhdrr"><?=gettext("Server"); ?></th>
180
		<th class="listhdrr"><?=gettext("Ref ID"); ?></th>
181
		<th class="listhdrr"><?=gettext("Stratum"); ?></th>
182
		<th class="listhdrr"><?=gettext("Type"); ?></th>
183
		<th class="listhdrr"><?=gettext("When"); ?></th>
184
		<th class="listhdrr"><?=gettext("Poll"); ?></th>
185
		<th class="listhdrr"><?=gettext("Reach"); ?></th>
186
		<th class="listhdrr"><?=gettext("Delay"); ?></th>
187
		<th class="listhdrr"><?=gettext("Offset"); ?></th>
188
		<th class="listhdr"><?=gettext("Jitter"); ?></th>
189 e078c882 jim-p
	</tr>
190
	</thead>
191
	<tbody>
192 c56d07dc nagyrobi
	<?php if (isset($config['ntpd']['noquery'])): ?>
193
	<tr><td class="listlr" colspan="11" align="center">
194
		Statistics unavailable because ntpq and ntpdc queries are disabled in the <a href="services_ntpd.php">NTP service settings</a>.
195
	</td></tr>
196
	<?php elseif (count($ntpq_servers) == 0): ?>
197 e078c882 jim-p
	<tr><td class="listlr" colspan="11" align="center">
198
		No peers found, <a href="status_services.php">is the ntp service running?</a>.
199
	</td></tr>
200
	<?php else: ?>
201
	<?php $i = 0; foreach ($ntpq_servers as $server): ?>
202
	<tr>
203 64feeb74 Colin Fleming
	<td class="listlr nowrap">
204 25890c50 jim-p
		<?=$server['status'];?>
205 e078c882 jim-p
	</td>
206 64feeb74 Colin Fleming
	<td class="listr">
207 e078c882 jim-p
		<?=$server['server'];?>
208
	</td>
209 64feeb74 Colin Fleming
	<td class="listr">
210 e078c882 jim-p
		<?=$server['refid'];?>
211
	</td>
212 64feeb74 Colin Fleming
	<td class="listr">
213 e078c882 jim-p
		<?=$server['stratum'];?>
214
	</td>
215 64feeb74 Colin Fleming
	<td class="listr">
216 e078c882 jim-p
		<?=$server['type'];?>
217
	</td>
218 64feeb74 Colin Fleming
	<td class="listr">
219 e078c882 jim-p
		<?=$server['when'];?>
220
	</td>
221 64feeb74 Colin Fleming
	<td class="listr">
222 e078c882 jim-p
		<?=$server['poll'];?>
223
	</td>
224 64feeb74 Colin Fleming
	<td class="listr">
225 e078c882 jim-p
		<?=$server['reach'];?>
226
	</td>
227 64feeb74 Colin Fleming
	<td class="listr">
228 e078c882 jim-p
		<?=$server['delay'];?>
229
	</td>
230 64feeb74 Colin Fleming
	<td class="listr">
231 e078c882 jim-p
		<?=$server['offset'];?>
232
	</td>
233 64feeb74 Colin Fleming
	<td class="listr">
234 e078c882 jim-p
		<?=$server['jitter'];?>
235
	</td>
236
	</tr>
237
<?php $i++; endforeach; endif; ?>
238
	</tbody>
239
	</table>
240 5c8843d5 jim-p
<?php if (($gps_ok) && ($gps_lat) && ($gps_lon)): ?>
241 c56d07dc nagyrobi
	<?php $gps_goo_lnk = 2; ?>
242 64feeb74 Colin Fleming
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="gps status">
243 5c8843d5 jim-p
	<thead>
244
	<tr>
245
		<th class="listhdrr"><?=gettext("Clock Latitude"); ?></th>
246
		<th class="listhdrr"><?=gettext("Clock Longitude"); ?></th>
247 64feeb74 Colin Fleming
		<?php if (isset($gps_alt)) { echo '<th class="listhdrr">' . gettext("Clock Altitude") . '</th>'; $gps_goo_lnk++;}?>
248
		<?php if (isset($gps_sat) || isset($gps_satview)) { echo '<th class="listhdrr">' . gettext("Satellites") . '</th>'; $gps_goo_lnk++;}?>
249 5c8843d5 jim-p
	</tr>
250
	</thead>
251
	<tbody>
252
		<tr>
253 96a7ddb7 jim-p
			<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>
254
			<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>
255 64feeb74 Colin Fleming
			<?php if (isset($gps_alt)) { echo '<td class="listlr" align="center">' . $gps_alt . ' ' . $gps_alt_unit . '</td>';}?>
256 c56d07dc nagyrobi
			<?php 
257 c7fa58ac Jean Cyr
			if (isset($gps_sat) || isset($gps_satview)) {
258
				echo '<td class="listr" align="center">';
259
				if (isset($gps_satview)) {echo 'in view ' . intval($gps_satview);}
260
				if (isset($gps_sat) && isset($gps_satview)) {echo ', ';}
261
				if (isset($gps_sat)) {echo 'in use ' . $gps_sat;}
262
				echo '</td>';
263
			}
264 c56d07dc nagyrobi
			?>
265 5c8843d5 jim-p
		</tr>
266
		<tr>
267 c56d07dc nagyrobi
			<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>
268 5c8843d5 jim-p
		</tr>
269
	</tbody>
270
	</table>
271
<?php endif; ?>
272 e078c882 jim-p
</div></td></tr>
273
</table>
274
<?php include("fend.inc"); ?>
275
</body>
276
</html>