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
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/ntpd	/usr/local/sbin/ntpq
61
	pfSense_MODULE: ntpd
62
*/
63

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

    
71
require_once("guiconfig.inc");
72

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

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

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

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

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

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

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

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

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

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

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

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

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

    
254

    
255
<?php
256

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

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

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

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

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

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

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

    
328
<?php	endif;
329

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