Project

General

Profile

Download (9.27 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	status_ntpd.php
5
	part of pfSense (https://www.pfsense.org/)
6

    
7
	Copyright (C) 2013 Dagorlad
8
	Copyright (C) 2012 Jim Pingle
9
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
10
	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
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/ntpd	/usr/local/sbin/ntpq
35
	pfSense_MODULE:	ntpd
36
*/
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
if(!isset($config['ntpd']['noquery'])) {
48
	if (isset($config['system']['ipv6allow']))
49
		$inet_version = "";
50
	else
51
		$inet_version = " -4";
52

    
53
	exec("/usr/local/sbin/ntpq -pn $inet_version | /usr/bin/tail +3", $ntpq_output);
54

    
55
	$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
	exec("/usr/local/sbin/ntpq -c clockvar $inet_version", $ntpq_clockvar_output);
104
	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
	}
147

    
148
}
149

    
150
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
		}
161
	}
162
}
163

    
164
$pgtitle = array(gettext("Status"),gettext("NTP"));
165
$shortcut_section = "ntp";
166
include("head.inc");
167
?>
168
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
169
<?php include("fbegin.inc"); ?>
170
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status ntpd">
171
<tr><td><div id="mainarea">
172
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="heading">
173
		<tr><td class="listtopic">Network Time Protocol Status</td></tr>
174
	</table>
175
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
176
	<thead>
177
	<tr>
178
		<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
	</tr>
190
	</thead>
191
	<tbody>
192
	<?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
	<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
	<td class="listlr nowrap">
204
		<?=$server['status'];?>
205
	</td>
206
	<td class="listr">
207
		<?=$server['server'];?>
208
	</td>
209
	<td class="listr">
210
		<?=$server['refid'];?>
211
	</td>
212
	<td class="listr">
213
		<?=$server['stratum'];?>
214
	</td>
215
	<td class="listr">
216
		<?=$server['type'];?>
217
	</td>
218
	<td class="listr">
219
		<?=$server['when'];?>
220
	</td>
221
	<td class="listr">
222
		<?=$server['poll'];?>
223
	</td>
224
	<td class="listr">
225
		<?=$server['reach'];?>
226
	</td>
227
	<td class="listr">
228
		<?=$server['delay'];?>
229
	</td>
230
	<td class="listr">
231
		<?=$server['offset'];?>
232
	</td>
233
	<td class="listr">
234
		<?=$server['jitter'];?>
235
	</td>
236
	</tr>
237
<?php $i++; endforeach; endif; ?>
238
	</tbody>
239
	</table>
240
<?php if (($gps_ok) && ($gps_lat) && ($gps_lon)): ?>
241
	<?php $gps_goo_lnk = 2; ?>
242
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="gps status">
243
	<thead>
244
	<tr>
245
		<th class="listhdrr"><?=gettext("Clock Latitude"); ?></th>
246
		<th class="listhdrr"><?=gettext("Clock Longitude"); ?></th>
247
		<?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
	</tr>
250
	</thead>
251
	<tbody>
252
		<tr>
253
			<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
			<?php if (isset($gps_alt)) { echo '<td class="listlr" align="center">' . $gps_alt . ' ' . $gps_alt_unit . '</td>';}?>
256
			<?php 
257
			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
			?>
265
		</tr>
266
		<tr>
267
			<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
		</tr>
269
	</tbody>
270
	</table>
271
<?php endif; ?>
272
</div></td></tr>
273
</table>
274
<?php include("fend.inc"); ?>
275
</body>
276
</html>
(192-192/252)