Project

General

Profile

Download (5.8 KB) Statistics
| Branch: | Tag: | Revision:
1 e078c882 jim-p
<?php
2
/* $Id$ */
3
/*
4
	status_ntpd.php
5
	part of pfSense (http://www.pfsense.com/)
6
7
	Copyright (C) 2012 Jim Pingle
8
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32 cf180ccc jim-p
	pfSense_BUILDER_BINARIES:	/usr/local/bin/ntpd	/usr/local/bin/ntpq
33
	pfSense_MODULE:	ntpd
34 e078c882 jim-p
*/
35
36
##|+PRIV
37
##|*IDENT=page-status-ntp
38
##|*NAME=Status: NTP page
39
##|*DESCR=Allow access to the 'Status: NTP' page.
40
##|*MATCH=status_ntpd.php*
41
##|-PRIV
42
43
require_once("guiconfig.inc");
44
45 cf180ccc jim-p
exec("/usr/local/bin/ntpq -pn | /usr/bin/tail +3", $ntpq_output);
46 5c8843d5 jim-p
47 e078c882 jim-p
$ntpq_servers = array();
48
foreach ($ntpq_output as $line) {
49
	$server = array();
50 25890c50 jim-p
51
	switch (substr($line, 0, 1)) {
52
		case " ":
53
			$server['status'] = "Unreach/Pending";
54
			break;
55
		case "*":
56
			$server['status'] = "Active Peer";
57
			break;
58
		case "+":
59
			$server['status'] = "Candidate";
60
			break;
61
		case "o":
62
			$server['status'] = "PPS Peer";
63
			break;
64
		case "#":
65
			$server['status'] = "Selected";
66
			break;
67
		case ".":
68
			$server['status'] = "Excess Peer";
69
			break;
70
		case "x":
71
			$server['status'] = "False Ticker";
72
			break;
73
		case "-":
74
			$server['status'] = "Outlier";
75
			break;
76
	}
77
78 e078c882 jim-p
	$line = substr($line, 1);
79
	$peerinfo = preg_split("/[\s\t]+/", $line);
80
81
	$server['server'] = $peerinfo[0];
82
	$server['refid'] = $peerinfo[1];
83
	$server['stratum'] = $peerinfo[2];
84
	$server['type'] = $peerinfo[3];
85
	$server['when'] = $peerinfo[4];
86
	$server['poll'] = $peerinfo[5];
87
	$server['reach'] = $peerinfo[6];
88
	$server['delay'] = $peerinfo[7];
89
	$server['offset'] = $peerinfo[8];
90
	$server['jitter'] = $peerinfo[9];
91
92
	$ntpq_servers[] = $server;
93
}
94
95 5c8843d5 jim-p
exec("/usr/local/bin/ntpq -c clockvar", $ntpq_clockvar_output);
96
foreach ($ntpq_clockvar_output as $line) {
97
	if (substr($line, 0, 9) == "timecode=") {
98
		$tmp = explode('"', $line);
99
		$tmp = $tmp[1];
100
		if (substr($tmp, 0, 6) == '$GPRMC') {
101
			$gps_vars = explode(",", $tmp);
102
			$gps_ok  = ($gps_vars[2] == "A");
103
			$gps_lat = $gps_vars[3] / 100.0 . $gps_vars[4];
104
			$gps_lon = $gps_vars[5] / 100.0 . $gps_vars[6];
105
		}
106
	}
107
}
108
109 e078c882 jim-p
$pgtitle = array(gettext("Status"),gettext("NTP"));
110 b32dd0a6 jim-p
$shortcut_section = "ntp";
111 e078c882 jim-p
include("head.inc");
112
?>
113
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
114
<?php include("fbegin.inc"); ?>
115
<table width="100%" border="0" cellpadding="0" cellspacing="0">
116
<tr><td><div id="mainarea">
117
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
118 cf180ccc jim-p
		<tr><td class="listtopic">Network Time Protocol Status</td></tr>
119 e078c882 jim-p
	</table>
120
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
121
	<thead>
122
	<tr>
123 ec18e696 bcyrill
		<th class="listhdrr"><?=gettext("Status"); ?></th>
124
		<th class="listhdrr"><?=gettext("Server"); ?></th>
125
		<th class="listhdrr"><?=gettext("Ref ID"); ?></th>
126
		<th class="listhdrr"><?=gettext("Stratum"); ?></th>
127
		<th class="listhdrr"><?=gettext("Type"); ?></th>
128
		<th class="listhdrr"><?=gettext("When"); ?></th>
129
		<th class="listhdrr"><?=gettext("Poll"); ?></th>
130
		<th class="listhdrr"><?=gettext("Reach"); ?></th>
131
		<th class="listhdrr"><?=gettext("Delay"); ?></th>
132
		<th class="listhdrr"><?=gettext("Offset"); ?></th>
133
		<th class="listhdr"><?=gettext("Jitter"); ?></th>
134 e078c882 jim-p
	</tr>
135
	</thead>
136
	<tbody>
137
	<?php if (count($ntpq_servers) == 0): ?>
138
	<tr><td class="listlr" colspan="11" align="center">
139
		No peers found, <a href="status_services.php">is the ntp service running?</a>.
140
	</td></tr>
141
	<?php else: ?>
142
	<?php $i = 0; foreach ($ntpq_servers as $server): ?>
143
	<tr>
144 25890c50 jim-p
	<td class="listlr" nowrap>
145
		<?=$server['status'];?>
146 e078c882 jim-p
	</td>
147
	<td class="listlr">
148
		<?=$server['server'];?>
149
	</td>
150
	<td class="listlr">
151
		<?=$server['refid'];?>
152
	</td>
153
	<td class="listlr">
154
		<?=$server['stratum'];?>
155
	</td>
156
	<td class="listlr">
157
		<?=$server['type'];?>
158
	</td>
159
	<td class="listlr">
160
		<?=$server['when'];?>
161
	</td>
162
	<td class="listlr">
163
		<?=$server['poll'];?>
164
	</td>
165
	<td class="listlr">
166
		<?=$server['reach'];?>
167
	</td>
168
	<td class="listlr">
169
		<?=$server['delay'];?>
170
	</td>
171
	<td class="listlr">
172
		<?=$server['offset'];?>
173
	</td>
174
	<td class="listlr">
175
		<?=$server['jitter'];?>
176
	</td>
177
	</tr>
178
<?php $i++; endforeach; endif; ?>
179
	</tbody>
180
	</table>
181 5c8843d5 jim-p
<?php if (($gps_ok) && ($gps_lat) && ($gps_lon)): ?>
182
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
183
	<thead>
184
	<tr>
185
		<th class="listhdrr"><?=gettext("Clock Latitude"); ?></th>
186
		<th class="listhdrr"><?=gettext("Clock Longitude"); ?></th>
187
	</tr>
188
	</thead>
189
	<tbody>
190
		<tr>
191
			<td class="listlr" align="center"><?php echo $gps_lat; ?></td>
192
			<td class="listlr" align="center"><?php echo $gps_lon; ?></td>
193
		</tr>
194
		<tr>
195
			<td class="listlr" colspan="2" align="center"><a href="http://maps.google.com/?q=<?php echo $gps_lat; ?>,<?php echo $gps_lon; ?>">Google Maps Link</a></td>
196
		</tr>
197
	</tbody>
198
	</table>
199
<?php endif; ?>
200 e078c882 jim-p
</div></td></tr>
201
</table>
202
<?php include("fend.inc"); ?>
203
</body>
204
</html>