Project

General

Profile

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