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