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
|
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
|
150
|
//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
|
151
|
$gpsport = fopen("/dev/gps0", "r+");
|
152
|
while($gpsport){
|
153
|
$buffer = fgets($gpsport);
|
154
|
if(substr($buffer, 0, 6)=='$GPGSV'){
|
155
|
//echo $buffer."\n";
|
156
|
$gpgsv = explode(',',$buffer);
|
157
|
$gps_satview = $gpgsv[3];
|
158
|
break;
|
159
|
}
|
160
|
}
|
161
|
}
|
162
|
|
163
|
$pgtitle = array(gettext("Status"),gettext("NTP"));
|
164
|
$shortcut_section = "ntp";
|
165
|
|
166
|
include("head.inc");
|
167
|
?>
|
168
|
|
169
|
<div class="panel panel-default">
|
170
|
<div class="panel-heading">Network Time Protocol Status</div>
|
171
|
<div class="panel-body">
|
172
|
<table class="table table-striped table-hover table-condensed">
|
173
|
<thead>
|
174
|
<tr>
|
175
|
<th><?=gettext("Status"); ?></th>
|
176
|
<th><?=gettext("Server"); ?></th>
|
177
|
<th><?=gettext("Ref ID"); ?></th>
|
178
|
<th><?=gettext("Stratum"); ?></th>
|
179
|
<th><?=gettext("Type"); ?></th>
|
180
|
<th><?=gettext("When"); ?></th>
|
181
|
<th><?=gettext("Poll"); ?></th>
|
182
|
<th><?=gettext("Reach"); ?></th>
|
183
|
<th><?=gettext("Delay"); ?></th>
|
184
|
<th><?=gettext("Offset"); ?></th>
|
185
|
<th><?=gettext("Jitter"); ?></th>
|
186
|
</tr>
|
187
|
</thead>
|
188
|
<tbody>
|
189
|
<?php if (isset($config['ntpd']['noquery'])): ?>
|
190
|
<tr>
|
191
|
<td class="warning" colspan="11">
|
192
|
Statistics unavailable because ntpq and ntpdc queries are disabled in the <a href="services_ntpd.php">NTP service settings</a>.
|
193
|
</td>
|
194
|
</tr>
|
195
|
<?php elseif (count($ntpq_servers) == 0): ?>
|
196
|
<tr>
|
197
|
<td class="warning" colspan="11">
|
198
|
No peers found, <a href="status_services.php">is the ntp service running?</a>
|
199
|
</td>
|
200
|
</tr>
|
201
|
<?php else:
|
202
|
|
203
|
$i = 0;
|
204
|
foreach ($ntpq_servers as $server): ?>
|
205
|
<tr>
|
206
|
<td><?=$server['status']?></td>
|
207
|
<td><?=$server['server']?></td>
|
208
|
<td><?=$server['refid']?></td>
|
209
|
<td><?=$server['stratum']?></td>
|
210
|
<td><?=$server['type']?></td>
|
211
|
<td><?=$server['when']?></td>
|
212
|
<td><?=$server['poll']?></td>
|
213
|
<td><?=$server['reach']?></td>
|
214
|
<td><?=$server['delay']?></td>
|
215
|
<td><?=$server['offset']?></td>
|
216
|
<td><?=$server['jitter']?></td>
|
217
|
</tr> <?php
|
218
|
$i++;
|
219
|
endforeach;
|
220
|
endif;
|
221
|
?>
|
222
|
</tbody>
|
223
|
</table>
|
224
|
</div>
|
225
|
</div>
|
226
|
|
227
|
|
228
|
<?php
|
229
|
|
230
|
// GPS satellite information (if available)
|
231
|
if (($gps_ok) && ($gps_lat) && ($gps_lon)):
|
232
|
$gps_goo_lnk = 2; ?>
|
233
|
|
234
|
<div class="panel panel-default">
|
235
|
<div class="panel-heading">GPS information</div>
|
236
|
<div class="panel-body">
|
237
|
<table class="table table-striped table-hover table-condensed">
|
238
|
<thead>
|
239
|
<tr>
|
240
|
<th>
|
241
|
<?=gettext("Clock Latitude"); ?>
|
242
|
</th>
|
243
|
<th>
|
244
|
<?=gettext("Clock Longitude"); ?>
|
245
|
</th>
|
246
|
<?php if (isset($gps_alt)) { ?>
|
247
|
<th>
|
248
|
<?=gettext("Clock Altitude")?>
|
249
|
</th>
|
250
|
<?php $gps_goo_lnk++;
|
251
|
}
|
252
|
|
253
|
if (isset($gps_sat) || isset($gps_satview)) { ?>
|
254
|
<th>
|
255
|
<?=gettext("Satellites")?>
|
256
|
</th> <?php
|
257
|
$gps_goo_lnk++;
|
258
|
}?>
|
259
|
</tr>
|
260
|
</thead>
|
261
|
|
262
|
<tbody>
|
263
|
<tr>
|
264
|
<td>
|
265
|
<?=printf("%.5f", $gps_lat); ?> (<?=printf("%d", $gps_lat_deg); ?>° <?=printf("%.5f", $gps_lat_min*60); ?><?=$gps_vars[4]; ?>)
|
266
|
</td>
|
267
|
<td>
|
268
|
<?=printf("%.5f", $gps_lon); ?> (<?=printf("%d", $gps_lon_deg); ?>° <?=printf("%.5f", $gps_lon_min*60); ?><?=$gps_vars[6]; ?>)
|
269
|
</td>
|
270
|
|
271
|
<?php if (isset($gps_alt)) { ?>
|
272
|
<td>
|
273
|
<?=$gps_alt . ' ' . $gps_alt_unit?>
|
274
|
</td>
|
275
|
}
|
276
|
|
277
|
if (isset($gps_sat) || isset($gps_satview)) { ?>
|
278
|
<td align="center"> <?php
|
279
|
if (isset($gps_satview)) {
|
280
|
print('in view ' . intval($gps_satview));
|
281
|
}
|
282
|
|
283
|
if (isset($gps_sat) && isset($gps_satview)) {
|
284
|
print(', ');
|
285
|
}
|
286
|
if (isset($gps_sat)) {
|
287
|
print('in use ' . $gps_sat);
|
288
|
} ?>
|
289
|
</td> <?php
|
290
|
}
|
291
|
?>
|
292
|
</tr>
|
293
|
<tr>
|
294
|
<td colspan="<?=$gps_goo_lnk; ?>"><a target="_gmaps" href="http://maps.google.com/?q=<?=$gps_lat; ?>,<?=$gps_lon; ?>">Google Maps Link</a></td>
|
295
|
</tr>
|
296
|
</tbody>
|
297
|
</table>
|
298
|
</div>
|
299
|
</div>
|
300
|
|
301
|
<?php endif;
|
302
|
|
303
|
include("foot.inc"); ?>
|