Project

General

Profile

Download (9.16 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-2014 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

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

    
51
	$ntpq_servers = array();
52
	foreach ($ntpq_output as $line) {
53
		$server = array();
54

    
55
		switch (substr($line, 0, 1)) {
56
			case " ":
57
				$server['status'] = "Unreach/Pending";
58
				break;
59
			case "*":
60
				$server['status'] = "Active Peer";
61
				break;
62
			case "+":
63
				$server['status'] = "Candidate";
64
				break;
65
			case "o":
66
				$server['status'] = "PPS Peer";
67
				break;
68
			case "#":
69
				$server['status'] = "Selected";
70
				break;
71
			case ".":
72
				$server['status'] = "Excess Peer";
73
				break;
74
			case "x":
75
				$server['status'] = "False Ticker";
76
				break;
77
			case "-":
78
				$server['status'] = "Outlier";
79
				break;
80
		}
81

    
82
		$line = substr($line, 1);
83
		$peerinfo = preg_split("/[\s\t]+/", $line);
84

    
85
		$server['server'] = $peerinfo[0];
86
		$server['refid'] = $peerinfo[1];
87
		$server['stratum'] = $peerinfo[2];
88
		$server['type'] = $peerinfo[3];
89
		$server['when'] = $peerinfo[4];
90
		$server['poll'] = $peerinfo[5];
91
		$server['reach'] = $peerinfo[6];
92
		$server['delay'] = $peerinfo[7];
93
		$server['offset'] = $peerinfo[8];
94
		$server['jitter'] = $peerinfo[9];
95

    
96
		$ntpq_servers[] = $server;
97
	}
98

    
99
	exec("/usr/local/sbin/ntpq -c clockvar", $ntpq_clockvar_output);
100
	foreach ($ntpq_clockvar_output as $line) {
101
		if (substr($line, 0, 9) == "timecode=") {
102
			$tmp = explode('"', $line);
103
			$tmp = $tmp[1];
104
			if (substr($tmp, 0, 6) == '$GPRMC') {
105
				$gps_vars = explode(",", $tmp);
106
				$gps_ok  = ($gps_vars[2] == "A");
107
				$gps_lat_deg = substr($gps_vars[3], 0, 2);
108
				$gps_lat_min = substr($gps_vars[3], 2) / 60.0;
109
				$gps_lon_deg = substr($gps_vars[5], 0, 3);
110
				$gps_lon_min = substr($gps_vars[5], 3) / 60.0;
111
				$gps_lat = $gps_lat_deg + $gps_lat_min;
112
				$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
113
				$gps_lon = $gps_lon_deg + $gps_lon_min;
114
				$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
115
			}elseif (substr($tmp, 0, 6) == '$GPGGA') {
116
				$gps_vars = explode(",", $tmp);
117
				$gps_ok  = $gps_vars[6];
118
				$gps_lat_deg = substr($gps_vars[2], 0, 2);
119
				$gps_lat_min = substr($gps_vars[2], 2) / 60.0;
120
				$gps_lon_deg = substr($gps_vars[4], 0, 3);
121
				$gps_lon_min = substr($gps_vars[4], 3) / 60.0;
122
				$gps_lat = $gps_lat_deg + $gps_lat_min;
123
				$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
124
				$gps_lon = $gps_lon_deg + $gps_lon_min;
125
				$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
126
				$gps_alt = $gps_vars[9];
127
				$gps_alt_unit = $gps_vars[10];
128
				$gps_sat = $gps_vars[7];
129
			}elseif (substr($tmp, 0, 6) == '$GPGLL') {
130
				$gps_vars = explode(",", $tmp);
131
				$gps_ok  = ($gps_vars[6] == "A");
132
				$gps_lat_deg = substr($gps_vars[1], 0, 2);
133
				$gps_lat_min = substr($gps_vars[1], 2) / 60.0;
134
				$gps_lon_deg = substr($gps_vars[3], 0, 3);
135
				$gps_lon_min = substr($gps_vars[3], 3) / 60.0;
136
				$gps_lat = $gps_lat_deg + $gps_lat_min;
137
				$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
138
				$gps_lon = $gps_lon_deg + $gps_lon_min;
139
				$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
140
			}
141
		}
142
	}
143

    
144
}
145

    
146
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
147
	//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
148
	$gpsport = fopen("/dev/gps0", "r+");
149
	while($gpsport){
150
		$buffer = fgets($gpsport);
151
		if(substr($buffer, 0, 6)=='$GPGSV'){
152
			//echo $buffer."\n";
153
			$gpgsv = explode(',',$buffer);
154
			$gps_satview = $gpgsv[3];
155
			break;
156
		}
157
	}
158
}
159

    
160
$pgtitle = array(gettext("Status"),gettext("NTP"));
161
$shortcut_section = "ntp";
162
include("head.inc");
163
?>
164
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
165
<?php include("fbegin.inc"); ?>
166
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status ntpd">
167
<tr><td><div id="mainarea">
168
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="heading">
169
		<tr><td class="listtopic">Network Time Protocol Status</td></tr>
170
	</table>
171
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
172
	<thead>
173
	<tr>
174
		<th class="listhdrr"><?=gettext("Status"); ?></th>
175
		<th class="listhdrr"><?=gettext("Server"); ?></th>
176
		<th class="listhdrr"><?=gettext("Ref ID"); ?></th>
177
		<th class="listhdrr"><?=gettext("Stratum"); ?></th>
178
		<th class="listhdrr"><?=gettext("Type"); ?></th>
179
		<th class="listhdrr"><?=gettext("When"); ?></th>
180
		<th class="listhdrr"><?=gettext("Poll"); ?></th>
181
		<th class="listhdrr"><?=gettext("Reach"); ?></th>
182
		<th class="listhdrr"><?=gettext("Delay"); ?></th>
183
		<th class="listhdrr"><?=gettext("Offset"); ?></th>
184
		<th class="listhdr"><?=gettext("Jitter"); ?></th>
185
	</tr>
186
	</thead>
187
	<tbody>
188
	<?php if (isset($config['ntpd']['noquery'])): ?>
189
	<tr><td class="listlr" colspan="11" align="center">
190
		Statistics unavailable because ntpq and ntpdc queries are disabled in the <a href="services_ntpd.php">NTP service settings</a>.
191
	</td></tr>
192
	<?php elseif (count($ntpq_servers) == 0): ?>
193
	<tr><td class="listlr" colspan="11" align="center">
194
		No peers found, <a href="status_services.php">is the ntp service running?</a>.
195
	</td></tr>
196
	<?php else: ?>
197
	<?php $i = 0; foreach ($ntpq_servers as $server): ?>
198
	<tr>
199
	<td class="listlr nowrap">
200
		<?=$server['status'];?>
201
	</td>
202
	<td class="listr">
203
		<?=$server['server'];?>
204
	</td>
205
	<td class="listr">
206
		<?=$server['refid'];?>
207
	</td>
208
	<td class="listr">
209
		<?=$server['stratum'];?>
210
	</td>
211
	<td class="listr">
212
		<?=$server['type'];?>
213
	</td>
214
	<td class="listr">
215
		<?=$server['when'];?>
216
	</td>
217
	<td class="listr">
218
		<?=$server['poll'];?>
219
	</td>
220
	<td class="listr">
221
		<?=$server['reach'];?>
222
	</td>
223
	<td class="listr">
224
		<?=$server['delay'];?>
225
	</td>
226
	<td class="listr">
227
		<?=$server['offset'];?>
228
	</td>
229
	<td class="listr">
230
		<?=$server['jitter'];?>
231
	</td>
232
	</tr>
233
<?php $i++; endforeach; endif; ?>
234
	</tbody>
235
	</table>
236
<?php if (($gps_ok) && ($gps_lat) && ($gps_lon)): ?>
237
	<?php $gps_goo_lnk = 2; ?>
238
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="gps status">
239
	<thead>
240
	<tr>
241
		<th class="listhdrr"><?=gettext("Clock Latitude"); ?></th>
242
		<th class="listhdrr"><?=gettext("Clock Longitude"); ?></th>
243
		<?php if (isset($gps_alt)) { echo '<th class="listhdrr">' . gettext("Clock Altitude") . '</th>'; $gps_goo_lnk++;}?>
244
		<?php if (isset($gps_sat) || isset($gps_satview)) { echo '<th class="listhdrr">' . gettext("Satellites") . '</th>'; $gps_goo_lnk++;}?>
245
	</tr>
246
	</thead>
247
	<tbody>
248
		<tr>
249
			<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>
250
			<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>
251
			<?php if (isset($gps_alt)) { echo '<td class="listlr" align="center">' . $gps_alt . ' ' . $gps_alt_unit . '</td>';}?>
252
			<?php 
253
			if (isset($gps_sat) || isset($gps_satview)) {
254
				echo '<td class="listr" align="center">';
255
				if (isset($gps_satview)) {echo 'in view ' . intval($gps_satview);}
256
				if (isset($gps_sat) && isset($gps_satview)) {echo ', ';}
257
				if (isset($gps_sat)) {echo 'in use ' . $gps_sat;}
258
				echo '</td>';
259
			}
260
			?>
261
		</tr>
262
		<tr>
263
			<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>
264
		</tr>
265
	</tbody>
266
	</table>
267
<?php endif; ?>
268
</div></td></tr>
269
</table>
270
<?php include("fend.inc"); ?>
271
</body>
272
</html>
(195-195/256)