Project

General

Profile

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

    
65
##|+PRIV
66
##|*IDENT=page-status-ntp
67
##|*NAME=Status: NTP page
68
##|*DESCR=Allow access to the 'Status: NTP' page.
69
##|*MATCH=status_ntpd.php*
70
##|-PRIV
71

    
72
require_once("guiconfig.inc");
73

    
74
if (!isset($config['ntpd']['noquery'])) {
75
	if (isset($config['system']['ipv6allow'])) {
76
		$inet_version = "";
77
	} else {
78
		$inet_version = " -4";
79
	}
80

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

    
83
	$ntpq_servers = array();
84
	foreach ($ntpq_output as $line) {
85
		$server = array();
86

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

    
114
		$line = substr($line, 1);
115
		$peerinfo = preg_split("/[\s\t]+/", $line);
116

    
117
		$server['server'] = $peerinfo[0];
118
		$server['refid'] = $peerinfo[1];
119
		$server['stratum'] = $peerinfo[2];
120
		$server['type'] = $peerinfo[3];
121
		$server['when'] = $peerinfo[4];
122
		$server['poll'] = $peerinfo[5];
123
		$server['reach'] = $peerinfo[6];
124
		$server['delay'] = $peerinfo[7];
125
		$server['offset'] = $peerinfo[8];
126
		$server['jitter'] = $peerinfo[9];
127

    
128
		$ntpq_servers[] = $server;
129
	}
130

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

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

    
191
$pgtitle = array(gettext("Status"), gettext("NTP"));
192
$shortcut_section = "ntp";
193

    
194
include("head.inc");
195
?>
196

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

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

    
255

    
256
<?php
257

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

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

    
281
					 if (isset($gps_sat) || isset($gps_satview)) { ?>
282
						<th>
283
							<?=gettext("Satellites")?>
284
						</th> <?php
285
						$gps_goo_lnk++;
286
					 }?>
287
					</tr>
288
				</thead>
289

    
290
				<tbody>
291
					<tr>
292
						<td>
293
							<?=printf("%.5f", $gps_lat); ?> (<?=printf("%d", $gps_lat_deg); ?>&deg; <?=printf("%.5f", $gps_lat_min*60); ?><?=$gps_vars[4]; ?>)
294
						</td>
295
						<td>
296
							<?=printf("%.5f", $gps_lon); ?> (<?=printf("%d", $gps_lon_deg); ?>&deg; <?=printf("%.5f", $gps_lon_min*60); ?><?=$gps_vars[6]; ?>)
297
						</td>
298

    
299
						<?php if (isset($gps_alt)) { ?>
300
							<td>
301
								<?=$gps_alt . ' ' . $gps_alt_unit?>
302
							</td>
303
							}
304

    
305
						if (isset($gps_sat) || isset($gps_satview)) { ?>
306
							<td align="center"> <?php
307
								if (isset($gps_satview)) {
308
									print('in view ' . intval($gps_satview));
309
								}
310

    
311
							if (isset($gps_sat) && isset($gps_satview)) {
312
								print(', ');
313
							}
314
							if (isset($gps_sat)) {
315
								print('in use ' . $gps_sat);
316
							} ?>
317
							</td> <?php
318
						}
319
						?>
320
					</tr>
321
					<tr>
322
						<td colspan="<?=$gps_goo_lnk; ?>"><a target="_gmaps" href="http://maps.google.com/?q=<?=$gps_lat; ?>,<?=$gps_lon; ?>">Google Maps Link</a></td>
323
					</tr>
324
				</tbody>
325
			</table>
326
		</div>
327
	</div>
328

    
329
<?php	endif;
330

    
331
include("foot.inc"); ?>
(177-177/234)