Project

General

Profile

Download (10.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	status_ntpd.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *	Copyright (c)  2013 Dagorlad
8
 *
9
 *	Some or all of this file is based on the m0n0wall project which is
10
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
11
 *
12
 *	Redistribution and use in source and binary forms, with or without modification,
13
 *	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
20
 *		the documentation and/or other materials provided with the
21
 *		distribution.
22
 *
23
 *	3. All advertising materials mentioning features or use of this software
24
 *		must display the following acknowledgment:
25
 *		"This product includes software developed by the pfSense Project
26
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
27
 *
28
 *	4. The names "pfSense" and "pfSense Project" must not be used to
29
 *		 endorse or promote products derived from this software without
30
 *		 prior written permission. For written permission, please contact
31
 *		 coreteam@pfsense.org.
32
 *
33
 *	5. Products derived from this software may not be called "pfSense"
34
 *		nor may "pfSense" appear in their names without prior written
35
 *		permission of the Electric Sheep Fencing, LLC.
36
 *
37
 *	6. Redistributions of any form whatsoever must retain the following
38
 *		acknowledgment:
39
 *
40
 *	"This product includes software developed by the pfSense Project
41
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
42
 *
43
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
44
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
47
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
52
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
55
 *
56
 *	====================================================================
57
 *
58
 */
59

    
60
##|+PRIV
61
##|*IDENT=page-status-ntp
62
##|*NAME=Status: NTP
63
##|*DESCR=Allow access to the 'Status: NTP' page.
64
##|*MATCH=status_ntpd.php*
65
##|-PRIV
66

    
67
require_once("guiconfig.inc");
68

    
69
if (!isset($config['ntpd']['noquery'])) {
70
	if (isset($config['system']['ipv6allow'])) {
71
		$inet_version = "";
72
	} else {
73
		$inet_version = " -4";
74
	}
75

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

    
78
	$ntpq_servers = array();
79
	foreach ($ntpq_output as $line) {
80
		$server = array();
81

    
82
		switch (substr($line, 0, 1)) {
83
			case " ":
84
				$server['status'] = gettext("Unreach/Pending");
85
				break;
86
			case "*":
87
				$server['status'] = gettext("Active Peer");
88
				break;
89
			case "+":
90
				$server['status'] = gettext("Candidate");
91
				break;
92
			case "o":
93
				$server['status'] = gettext("PPS Peer");
94
				break;
95
			case "#":
96
				$server['status'] = gettext("Selected");
97
				break;
98
			case ".":
99
				$server['status'] = gettext("Excess Peer");
100
				break;
101
			case "x":
102
				$server['status'] = gettext("False Ticker");
103
				break;
104
			case "-":
105
				$server['status'] = gettext("Outlier");
106
				break;
107
		}
108

    
109
		$line = substr($line, 1);
110
		$peerinfo = preg_split("/[\s\t]+/", $line);
111

    
112
		$server['server'] = $peerinfo[0];
113
		$server['refid'] = $peerinfo[1];
114
		$server['stratum'] = $peerinfo[2];
115
		$server['type'] = $peerinfo[3];
116
		$server['when'] = $peerinfo[4];
117
		$server['poll'] = $peerinfo[5];
118
		$server['reach'] = $peerinfo[6];
119
		$server['delay'] = $peerinfo[7];
120
		$server['offset'] = $peerinfo[8];
121
		$server['jitter'] = $peerinfo[9];
122

    
123
		$ntpq_servers[] = $server;
124
	}
125

    
126
	exec("/usr/local/sbin/ntpq -c clockvar $inet_version", $ntpq_clockvar_output);
127
	foreach ($ntpq_clockvar_output as $line) {
128
		if (substr($line, 0, 9) == "timecode=") {
129
			$tmp = explode('"', $line);
130
			$tmp = $tmp[1];
131
			if (substr($tmp, 0, 6) == '$GPRMC') {
132
				$gps_vars = explode(",", $tmp);
133
				$gps_ok = ($gps_vars[2] == "A");
134
				$gps_lat_deg = substr($gps_vars[3], 0, 2);
135
				$gps_lat_min = substr($gps_vars[3], 2) / 60.0;
136
				$gps_lon_deg = substr($gps_vars[5], 0, 3);
137
				$gps_lon_min = substr($gps_vars[5], 3) / 60.0;
138
				$gps_lat = $gps_lat_deg + $gps_lat_min;
139
				$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
140
				$gps_lon = $gps_lon_deg + $gps_lon_min;
141
				$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
142
			} elseif (substr($tmp, 0, 6) == '$GPGGA') {
143
				$gps_vars = explode(",", $tmp);
144
				$gps_ok = $gps_vars[6];
145
				$gps_lat_deg = substr($gps_vars[2], 0, 2);
146
				$gps_lat_min = substr($gps_vars[2], 2) / 60.0;
147
				$gps_lon_deg = substr($gps_vars[4], 0, 3);
148
				$gps_lon_min = substr($gps_vars[4], 3) / 60.0;
149
				$gps_lat = $gps_lat_deg + $gps_lat_min;
150
				$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
151
				$gps_lon = $gps_lon_deg + $gps_lon_min;
152
				$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
153
				$gps_alt = $gps_vars[9];
154
				$gps_alt_unit = $gps_vars[10];
155
				$gps_sat = $gps_vars[7];
156
			} elseif (substr($tmp, 0, 6) == '$GPGLL') {
157
				$gps_vars = explode(",", $tmp);
158
				$gps_ok = ($gps_vars[6] == "A");
159
				$gps_lat_deg = substr($gps_vars[1], 0, 2);
160
				$gps_lat_min = substr($gps_vars[1], 2) / 60.0;
161
				$gps_lon_deg = substr($gps_vars[3], 0, 3);
162
				$gps_lon_min = substr($gps_vars[3], 3) / 60.0;
163
				$gps_lat = $gps_lat_deg + $gps_lat_min;
164
				$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
165
				$gps_lon = $gps_lon_deg + $gps_lon_min;
166
				$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
167
			}
168
		}
169
	}
170
}
171

    
172
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
173
	//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
174
	$gpsport = fopen("/dev/gps0", "r+");
175
	while ($gpsport) {
176
		$buffer = fgets($gpsport);
177
		if (substr($buffer, 0, 6) == '$GPGSV') {
178
			//echo $buffer."\n";
179
			$gpgsv = explode(',', $buffer);
180
			$gps_satview = $gpgsv[3];
181
			break;
182
		}
183
	}
184
}
185

    
186
$pgtitle = array(gettext("Status"), gettext("NTP"));
187
$shortcut_section = "ntp";
188

    
189
include("head.inc");
190
?>
191

    
192
<div class="panel panel-default">
193
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("Network Time Protocol Status");?></h2></div>
194
	<div class="panel-body">
195
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
196
			<thead>
197
				<tr>
198
					<th><?=gettext("Status"); ?></th>
199
					<th><?=gettext("Server"); ?></th>
200
					<th><?=gettext("Ref ID"); ?></th>
201
					<th><?=gettext("Stratum"); ?></th>
202
					<th><?=gettext("Type"); ?></th>
203
					<th><?=gettext("When"); ?></th>
204
					<th><?=gettext("Poll"); ?></th>
205
					<th><?=gettext("Reach"); ?></th>
206
					<th><?=gettext("Delay"); ?></th>
207
					<th><?=gettext("Offset"); ?></th>
208
					<th><?=gettext("Jitter"); ?></th>
209
				</tr>
210
			</thead>
211
			<tbody>
212
<?php
213
	if (isset($config['ntpd']['noquery'])):
214
?>
215
				<tr>
216
					<td class="warning" colspan="11">
217
						<?=sprintf(gettext("Statistics unavailable because ntpq and ntpdc queries are disabled in the %sNTP service settings%s"), '<a href="services_ntpd.php">', '</a>');?>
218
					</td>
219
				</tr>
220
<?php
221
	elseif (count($ntpq_servers) == 0):
222
?>
223
				<tr>
224
					<td class="warning" colspan="11">
225
						<?=sprintf(gettext("No peers found, %sis the ntp service running?%s"), '<a href="status_services.php">', '</a>');?>
226
					</td>
227
				</tr>
228
<?php
229
	else:
230

    
231
		$i = 0;
232
		foreach ($ntpq_servers as $server):
233
?>
234
				<tr>
235
					<td><?=$server['status']?></td>
236
					<td><?=$server['server']?></td>
237
					<td><?=$server['refid']?></td>
238
					<td><?=$server['stratum']?></td>
239
					<td><?=$server['type']?></td>
240
					<td><?=$server['when']?></td>
241
					<td><?=$server['poll']?></td>
242
					<td><?=$server['reach']?></td>
243
					<td><?=$server['delay']?></td>
244
					<td><?=$server['offset']?></td>
245
					<td><?=$server['jitter']?></td>
246
				</tr>
247
<?php
248
			$i++;
249
		endforeach;
250
	endif;
251
?>
252
			</tbody>
253
		</table>
254
	</div>
255
</div>
256

    
257

    
258
<?php
259

    
260
// GPS satellite information (if available)
261
if (($gps_ok) && ($gps_lat) && ($gps_lon)):
262
	$gps_goo_lnk = 2;
263
?>
264

    
265
<div class="panel panel-default">
266
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("GPS Information");?></h2></div>
267
	<div class="panel-body">
268
		<table class="table table-striped table-hover table-condensed">
269
			<thead>
270
				<tr>
271
					<th>
272
						 <?=gettext("Clock Latitude"); ?>
273
					</th>
274
					<th>
275
						<?=gettext("Clock Longitude"); ?>
276
					</th>
277
<?php
278
	if (isset($gps_alt)) {
279
?>
280
					<th>
281
						<?=gettext("Clock Altitude")?>
282
					</th>
283
<?php
284
		$gps_goo_lnk++;
285
	}
286

    
287
	if (isset($gps_sat) || isset($gps_satview)) {
288
?>
289
					<th>
290
						<?=gettext("Satellites")?>
291
					</th>
292
<?php
293
		$gps_goo_lnk++;
294
	}
295
?>
296
				</tr>
297
			</thead>
298

    
299
			<tbody>
300
				<tr>
301
					<td>
302
						<?=sprintf("%.5f", $gps_lat); ?> (<?=sprintf("%d", $gps_lat_deg); ?>&deg; <?=sprintf("%.5f", $gps_lat_min*60); ?><?=$gps_vars[4]; ?>)
303
					</td>
304
					<td>
305
						<?=sprintf("%.5f", $gps_lon); ?> (<?=sprintf("%d", $gps_lon_deg); ?>&deg; <?=sprintf("%.5f", $gps_lon_min*60); ?><?=$gps_vars[6]; ?>)
306
					</td>
307

    
308
<?php
309
	if (isset($gps_alt)) {
310
?>
311
					<td>
312
						<?=$gps_alt . ' ' . $gps_alt_unit?>
313
					</td>
314
<?php
315
	}
316

    
317
	if (isset($gps_sat) || isset($gps_satview)) {
318
?>
319
					<td class="text-center">
320
<?php
321
		if (isset($gps_satview)) {
322
			print(gettext('in view ') . intval($gps_satview));
323
		}
324

    
325
		if (isset($gps_sat) && isset($gps_satview)) {
326
			print(', ');
327
		}
328
		if (isset($gps_sat)) {
329
			print(gettext('in use ') . $gps_sat);
330
		}
331
?>
332
					</td>
333
<?php
334
	}
335
?>
336
				</tr>
337
				<tr>
338
					<td colspan="<?=$gps_goo_lnk; ?>"><a target="_gmaps" href="http://maps.google.com/?q=<?=$gps_lat; ?>,<?=$gps_lon; ?>"><?=gettext("Google Maps Link");?></a></td>
339
				</tr>
340
			</tbody>
341
		</table>
342
	</div>
343
</div>
344

    
345
<?php
346
endif;
347

    
348
include("foot.inc");
349
?>
(177-177/229)