1 |
e078c882
|
jim-p
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
status_ntpd.php
|
5 |
c7281770
|
Chris Buechler
|
part of pfSense (https://www.pfsense.org/)
|
6 |
e078c882
|
jim-p
|
|
7 |
c56d07dc
|
nagyrobi
|
Copyright (C) 2013 Dagorlad
|
8 |
e078c882
|
jim-p
|
Copyright (C) 2012 Jim Pingle
|
9 |
ce77a9c4
|
Phil Davis
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
10 |
e078c882
|
jim-p
|
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 |
fdfa8f43
|
jim-p
|
pfSense_BUILDER_BINARIES: /usr/local/sbin/ntpd /usr/local/sbin/ntpq
|
35 |
8dff26ce
|
sbeaver
|
pfSense_MODULE: ntpd
|
36 |
e078c882
|
jim-p
|
*/
|
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 |
42b0c921
|
Phil Davis
|
if (!isset($config['ntpd']['noquery'])) {
|
48 |
|
|
if (isset($config['system']['ipv6allow'])) {
|
49 |
e4a496ae
|
Phil Davis
|
$inet_version = "";
|
50 |
42b0c921
|
Phil Davis
|
} else {
|
51 |
e4a496ae
|
Phil Davis
|
$inet_version = " -4";
|
52 |
42b0c921
|
Phil Davis
|
}
|
53 |
5c8843d5
|
jim-p
|
|
54 |
e4a496ae
|
Phil Davis
|
exec("/usr/local/sbin/ntpq -pn $inet_version | /usr/bin/tail +3", $ntpq_output);
|
55 |
25890c50
|
jim-p
|
|
56 |
c56d07dc
|
nagyrobi
|
$ntpq_servers = array();
|
57 |
|
|
foreach ($ntpq_output as $line) {
|
58 |
|
|
$server = array();
|
59 |
|
|
|
60 |
|
|
switch (substr($line, 0, 1)) {
|
61 |
|
|
case " ":
|
62 |
|
|
$server['status'] = "Unreach/Pending";
|
63 |
|
|
break;
|
64 |
|
|
case "*":
|
65 |
|
|
$server['status'] = "Active Peer";
|
66 |
|
|
break;
|
67 |
|
|
case "+":
|
68 |
|
|
$server['status'] = "Candidate";
|
69 |
|
|
break;
|
70 |
|
|
case "o":
|
71 |
|
|
$server['status'] = "PPS Peer";
|
72 |
|
|
break;
|
73 |
|
|
case "#":
|
74 |
|
|
$server['status'] = "Selected";
|
75 |
|
|
break;
|
76 |
|
|
case ".":
|
77 |
|
|
$server['status'] = "Excess Peer";
|
78 |
|
|
break;
|
79 |
|
|
case "x":
|
80 |
|
|
$server['status'] = "False Ticker";
|
81 |
|
|
break;
|
82 |
|
|
case "-":
|
83 |
|
|
$server['status'] = "Outlier";
|
84 |
|
|
break;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
$line = substr($line, 1);
|
88 |
|
|
$peerinfo = preg_split("/[\s\t]+/", $line);
|
89 |
|
|
|
90 |
|
|
$server['server'] = $peerinfo[0];
|
91 |
|
|
$server['refid'] = $peerinfo[1];
|
92 |
|
|
$server['stratum'] = $peerinfo[2];
|
93 |
|
|
$server['type'] = $peerinfo[3];
|
94 |
|
|
$server['when'] = $peerinfo[4];
|
95 |
|
|
$server['poll'] = $peerinfo[5];
|
96 |
|
|
$server['reach'] = $peerinfo[6];
|
97 |
|
|
$server['delay'] = $peerinfo[7];
|
98 |
|
|
$server['offset'] = $peerinfo[8];
|
99 |
|
|
$server['jitter'] = $peerinfo[9];
|
100 |
|
|
|
101 |
|
|
$ntpq_servers[] = $server;
|
102 |
|
|
}
|
103 |
|
|
|
104 |
62a407da
|
Phil Davis
|
exec("/usr/local/sbin/ntpq -c clockvar $inet_version", $ntpq_clockvar_output);
|
105 |
c56d07dc
|
nagyrobi
|
foreach ($ntpq_clockvar_output as $line) {
|
106 |
|
|
if (substr($line, 0, 9) == "timecode=") {
|
107 |
|
|
$tmp = explode('"', $line);
|
108 |
|
|
$tmp = $tmp[1];
|
109 |
|
|
if (substr($tmp, 0, 6) == '$GPRMC') {
|
110 |
|
|
$gps_vars = explode(",", $tmp);
|
111 |
6c07db48
|
Phil Davis
|
$gps_ok = ($gps_vars[2] == "A");
|
112 |
c56d07dc
|
nagyrobi
|
$gps_lat_deg = substr($gps_vars[3], 0, 2);
|
113 |
|
|
$gps_lat_min = substr($gps_vars[3], 2) / 60.0;
|
114 |
|
|
$gps_lon_deg = substr($gps_vars[5], 0, 3);
|
115 |
|
|
$gps_lon_min = substr($gps_vars[5], 3) / 60.0;
|
116 |
|
|
$gps_lat = $gps_lat_deg + $gps_lat_min;
|
117 |
|
|
$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
|
118 |
|
|
$gps_lon = $gps_lon_deg + $gps_lon_min;
|
119 |
|
|
$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
|
120 |
42b0c921
|
Phil Davis
|
} elseif (substr($tmp, 0, 6) == '$GPGGA') {
|
121 |
c56d07dc
|
nagyrobi
|
$gps_vars = explode(",", $tmp);
|
122 |
6c07db48
|
Phil Davis
|
$gps_ok = $gps_vars[6];
|
123 |
c56d07dc
|
nagyrobi
|
$gps_lat_deg = substr($gps_vars[2], 0, 2);
|
124 |
|
|
$gps_lat_min = substr($gps_vars[2], 2) / 60.0;
|
125 |
|
|
$gps_lon_deg = substr($gps_vars[4], 0, 3);
|
126 |
|
|
$gps_lon_min = substr($gps_vars[4], 3) / 60.0;
|
127 |
|
|
$gps_lat = $gps_lat_deg + $gps_lat_min;
|
128 |
|
|
$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
|
129 |
|
|
$gps_lon = $gps_lon_deg + $gps_lon_min;
|
130 |
|
|
$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
|
131 |
|
|
$gps_alt = $gps_vars[9];
|
132 |
|
|
$gps_alt_unit = $gps_vars[10];
|
133 |
|
|
$gps_sat = $gps_vars[7];
|
134 |
42b0c921
|
Phil Davis
|
} elseif (substr($tmp, 0, 6) == '$GPGLL') {
|
135 |
c56d07dc
|
nagyrobi
|
$gps_vars = explode(",", $tmp);
|
136 |
6c07db48
|
Phil Davis
|
$gps_ok = ($gps_vars[6] == "A");
|
137 |
c56d07dc
|
nagyrobi
|
$gps_lat_deg = substr($gps_vars[1], 0, 2);
|
138 |
|
|
$gps_lat_min = substr($gps_vars[1], 2) / 60.0;
|
139 |
|
|
$gps_lon_deg = substr($gps_vars[3], 0, 3);
|
140 |
|
|
$gps_lon_min = substr($gps_vars[3], 3) / 60.0;
|
141 |
|
|
$gps_lat = $gps_lat_deg + $gps_lat_min;
|
142 |
|
|
$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
|
143 |
|
|
$gps_lon = $gps_lon_deg + $gps_lon_min;
|
144 |
|
|
$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
|
145 |
|
|
}
|
146 |
|
|
}
|
147 |
25890c50
|
jim-p
|
}
|
148 |
e078c882
|
jim-p
|
}
|
149 |
|
|
|
150 |
c56d07dc
|
nagyrobi
|
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
|
151 |
|
|
//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
|
152 |
|
|
$gpsport = fopen("/dev/gps0", "r+");
|
153 |
42b0c921
|
Phil Davis
|
while ($gpsport) {
|
154 |
c56d07dc
|
nagyrobi
|
$buffer = fgets($gpsport);
|
155 |
6c07db48
|
Phil Davis
|
if (substr($buffer, 0, 6) == '$GPGSV') {
|
156 |
c56d07dc
|
nagyrobi
|
//echo $buffer."\n";
|
157 |
6c07db48
|
Phil Davis
|
$gpgsv = explode(',', $buffer);
|
158 |
c56d07dc
|
nagyrobi
|
$gps_satview = $gpgsv[3];
|
159 |
|
|
break;
|
160 |
5c8843d5
|
jim-p
|
}
|
161 |
|
|
}
|
162 |
|
|
}
|
163 |
|
|
|
164 |
6c07db48
|
Phil Davis
|
$pgtitle = array(gettext("Status"), gettext("NTP"));
|
165 |
b32dd0a6
|
jim-p
|
$shortcut_section = "ntp";
|
166 |
8dff26ce
|
sbeaver
|
|
167 |
e078c882
|
jim-p
|
include("head.inc");
|
168 |
|
|
?>
|
169 |
8dff26ce
|
sbeaver
|
|
170 |
|
|
<div class="panel panel-default">
|
171 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title">Network Time Protocol Status</h2></div>
|
172 |
8dff26ce
|
sbeaver
|
<div class="panel-body">
|
173 |
|
|
<table class="table table-striped table-hover table-condensed">
|
174 |
|
|
<thead>
|
175 |
|
|
<tr>
|
176 |
|
|
<th><?=gettext("Status"); ?></th>
|
177 |
|
|
<th><?=gettext("Server"); ?></th>
|
178 |
|
|
<th><?=gettext("Ref ID"); ?></th>
|
179 |
|
|
<th><?=gettext("Stratum"); ?></th>
|
180 |
|
|
<th><?=gettext("Type"); ?></th>
|
181 |
|
|
<th><?=gettext("When"); ?></th>
|
182 |
|
|
<th><?=gettext("Poll"); ?></th>
|
183 |
|
|
<th><?=gettext("Reach"); ?></th>
|
184 |
|
|
<th><?=gettext("Delay"); ?></th>
|
185 |
|
|
<th><?=gettext("Offset"); ?></th>
|
186 |
|
|
<th><?=gettext("Jitter"); ?></th>
|
187 |
|
|
</tr>
|
188 |
|
|
</thead>
|
189 |
|
|
<tbody>
|
190 |
|
|
<?php if (isset($config['ntpd']['noquery'])): ?>
|
191 |
|
|
<tr>
|
192 |
|
|
<td class="warning" colspan="11">
|
193 |
|
|
Statistics unavailable because ntpq and ntpdc queries are disabled in the <a href="services_ntpd.php">NTP service settings</a>.
|
194 |
|
|
</td>
|
195 |
|
|
</tr>
|
196 |
|
|
<?php elseif (count($ntpq_servers) == 0): ?>
|
197 |
|
|
<tr>
|
198 |
|
|
<td class="warning" colspan="11">
|
199 |
|
|
No peers found, <a href="status_services.php">is the ntp service running?</a>
|
200 |
|
|
</td>
|
201 |
|
|
</tr>
|
202 |
|
|
<?php else:
|
203 |
|
|
|
204 |
|
|
$i = 0;
|
205 |
|
|
foreach ($ntpq_servers as $server): ?>
|
206 |
1e314e79
|
sbeaver
|
<tr>
|
207 |
|
|
<td><?=$server['status']?></td>
|
208 |
|
|
<td><?=$server['server']?></td>
|
209 |
|
|
<td><?=$server['refid']?></td>
|
210 |
|
|
<td><?=$server['stratum']?></td>
|
211 |
|
|
<td><?=$server['type']?></td>
|
212 |
|
|
<td><?=$server['when']?></td>
|
213 |
|
|
<td><?=$server['poll']?></td>
|
214 |
|
|
<td><?=$server['reach']?></td>
|
215 |
|
|
<td><?=$server['delay']?></td>
|
216 |
|
|
<td><?=$server['offset']?></td>
|
217 |
|
|
<td><?=$server['jitter']?></td>
|
218 |
8dff26ce
|
sbeaver
|
</tr> <?php
|
219 |
|
|
$i++;
|
220 |
|
|
endforeach;
|
221 |
|
|
endif;
|
222 |
|
|
?>
|
223 |
|
|
</tbody>
|
224 |
|
|
</table>
|
225 |
|
|
</div>
|
226 |
|
|
</div>
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
<?php
|
230 |
|
|
|
231 |
|
|
// GPS satellite information (if available)
|
232 |
|
|
if (($gps_ok) && ($gps_lat) && ($gps_lon)):
|
233 |
|
|
$gps_goo_lnk = 2; ?>
|
234 |
|
|
|
235 |
|
|
<div class="panel panel-default">
|
236 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title">GPS information</h2></div>
|
237 |
8dff26ce
|
sbeaver
|
<div class="panel-body">
|
238 |
|
|
<table class="table table-striped table-hover table-condensed">
|
239 |
|
|
<thead>
|
240 |
|
|
<tr>
|
241 |
|
|
<th>
|
242 |
|
|
<?=gettext("Clock Latitude"); ?>
|
243 |
|
|
</th>
|
244 |
|
|
<th>
|
245 |
|
|
<?=gettext("Clock Longitude"); ?>
|
246 |
|
|
</th>
|
247 |
|
|
<?php if (isset($gps_alt)) { ?>
|
248 |
|
|
<th>
|
249 |
|
|
<?=gettext("Clock Altitude")?>
|
250 |
|
|
</th>
|
251 |
|
|
<?php $gps_goo_lnk++;
|
252 |
|
|
}
|
253 |
|
|
|
254 |
|
|
if (isset($gps_sat) || isset($gps_satview)) { ?>
|
255 |
|
|
<th>
|
256 |
|
|
<?=gettext("Satellites")?>
|
257 |
|
|
</th> <?php
|
258 |
|
|
$gps_goo_lnk++;
|
259 |
|
|
}?>
|
260 |
|
|
</tr>
|
261 |
|
|
</thead>
|
262 |
|
|
|
263 |
|
|
<tbody>
|
264 |
|
|
<tr>
|
265 |
|
|
<td>
|
266 |
|
|
<?=printf("%.5f", $gps_lat); ?> (<?=printf("%d", $gps_lat_deg); ?>° <?=printf("%.5f", $gps_lat_min*60); ?><?=$gps_vars[4]; ?>)
|
267 |
|
|
</td>
|
268 |
|
|
<td>
|
269 |
|
|
<?=printf("%.5f", $gps_lon); ?> (<?=printf("%d", $gps_lon_deg); ?>° <?=printf("%.5f", $gps_lon_min*60); ?><?=$gps_vars[6]; ?>)
|
270 |
|
|
</td>
|
271 |
|
|
|
272 |
|
|
<?php if (isset($gps_alt)) { ?>
|
273 |
|
|
<td>
|
274 |
|
|
<?=$gps_alt . ' ' . $gps_alt_unit?>
|
275 |
|
|
</td>
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
if (isset($gps_sat) || isset($gps_satview)) { ?>
|
279 |
|
|
<td align="center"> <?php
|
280 |
|
|
if (isset($gps_satview)) {
|
281 |
|
|
print('in view ' . intval($gps_satview));
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
if (isset($gps_sat) && isset($gps_satview)) {
|
285 |
|
|
print(', ');
|
286 |
|
|
}
|
287 |
|
|
if (isset($gps_sat)) {
|
288 |
|
|
print('in use ' . $gps_sat);
|
289 |
|
|
} ?>
|
290 |
|
|
</td> <?php
|
291 |
|
|
}
|
292 |
|
|
?>
|
293 |
|
|
</tr>
|
294 |
|
|
<tr>
|
295 |
|
|
<td colspan="<?=$gps_goo_lnk; ?>"><a target="_gmaps" href="http://maps.google.com/?q=<?=$gps_lat; ?>,<?=$gps_lon; ?>">Google Maps Link</a></td>
|
296 |
|
|
</tr>
|
297 |
|
|
</tbody>
|
298 |
|
|
</table>
|
299 |
|
|
</div>
|
300 |
|
|
</div>
|
301 |
|
|
|
302 |
|
|
<?php endif;
|
303 |
|
|
|
304 |
|
|
include("foot.inc"); ?>
|