Project

General

Profile

« Previous | Next » 

Revision e078c882

Added by Jim Pingle about 13 years ago

Add NTP status page using ntpq.

View differences:

usr/local/www/status_ntpd.php
1
<?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
	pfSense_BUILDER_BINARIES:	/usr/sbin/ntpd	/usr/bin/ntpq
33
	pfSense_MODULE:	routing
34
*/
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
exec("/usr/bin/ntpq -pn | /usr/bin/tail +3", $ntpq_output);
46
$ntpq_servers = array();
47
foreach ($ntpq_output as $line) {
48
	$server = array();
49
	$server['tallycode'] = substr($line, 0, 1);
50
	$line = substr($line, 1);
51
	$peerinfo = preg_split("/[\s\t]+/", $line);
52

  
53
	$server['server'] = $peerinfo[0];
54
	$server['refid'] = $peerinfo[1];
55
	$server['stratum'] = $peerinfo[2];
56
	$server['type'] = $peerinfo[3];
57
	$server['when'] = $peerinfo[4];
58
	$server['poll'] = $peerinfo[5];
59
	$server['reach'] = $peerinfo[6];
60
	$server['delay'] = $peerinfo[7];
61
	$server['offset'] = $peerinfo[8];
62
	$server['jitter'] = $peerinfo[9];
63

  
64
	$ntpq_servers[] = $server;
65
}
66

  
67
$pgtitle = array(gettext("Status"),gettext("NTP"));
68
include("head.inc");
69
?>
70
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
71
<?php include("fbegin.inc"); ?>
72
<table width="100%" border="0" cellpadding="0" cellspacing="0">
73
<tr><td><div id="mainarea">
74
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
75
		<tr><td>Status of the system's Network Time Protocol servers and clock.</td></tr>
76
	</table>
77
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
78
	<thead>
79
	<tr>
80
		<th class="listhdrr"><?=gettext("Tally code"); ?></td>
81
		<th class="listhdrr"><?=gettext("Server"); ?></td>
82
		<th class="listhdrr"><?=gettext("Ref ID"); ?></td>
83
		<th class="listhdrr"><?=gettext("Stratum"); ?></td>
84
		<th class="listhdrr"><?=gettext("Type"); ?></td>
85
		<th class="listhdrr"><?=gettext("When"); ?></td>
86
		<th class="listhdrr"><?=gettext("Poll"); ?></td>
87
		<th class="listhdrr"><?=gettext("Reach"); ?></td>
88
		<th class="listhdrr"><?=gettext("Delay"); ?></td>
89
		<th class="listhdrr"><?=gettext("Offset"); ?></td>
90
		<th class="listhdr"><?=gettext("Jitter"); ?></td>
91
	</tr>
92
	</thead>
93
	<tbody>
94
	<?php if (count($ntpq_servers) == 0): ?>
95
	<tr><td class="listlr" colspan="11" align="center">
96
		No peers found, <a href="status_services.php">is the ntp service running?</a>.
97
	</td></tr>
98
	<?php else: ?>
99
	<?php $i = 0; foreach ($ntpq_servers as $server): ?>
100
	<tr>
101
	<td class="listlr">
102
		<?=$server['tallycode'];?>
103
	</td>
104
	<td class="listlr">
105
		<?=$server['server'];?>
106
	</td>
107
	<td class="listlr">
108
		<?=$server['refid'];?>
109
	</td>
110
	<td class="listlr">
111
		<?=$server['stratum'];?>
112
	</td>
113
	<td class="listlr">
114
		<?=$server['type'];?>
115
	</td>
116
	<td class="listlr">
117
		<?=$server['when'];?>
118
	</td>
119
	<td class="listlr">
120
		<?=$server['poll'];?>
121
	</td>
122
	<td class="listlr">
123
		<?=$server['reach'];?>
124
	</td>
125
	<td class="listlr">
126
		<?=$server['delay'];?>
127
	</td>
128
	<td class="listlr">
129
		<?=$server['offset'];?>
130
	</td>
131
	<td class="listlr">
132
		<?=$server['jitter'];?>
133
	</td>
134
	</tr>
135
<?php $i++; endforeach; endif; ?>
136
	<tr><td colspan="11">
137
	<br/>Tally code meanings:<br/>
138
	<ul>
139
		<li>(blank) = Peer in unreachable/unusable, or undetermined</li>
140
		<li>* = System Peer (active)</li>
141
		<li>+ = Candidate</li>
142
		<li>o = Peer with PPS</li>
143
		<li># = Survivor, but not among first six</li>
144
		<li>. = Excess peer not needed as there are too many</li>
145
		<li>x = Discarded as false ticker</li>
146
		<li>- = Discarded as an Outlier</li>
147
	</ul>
148
	</td></tr>
149
	</tbody>
150
	</table>
151
</div></td></tr>
152
</table>
153
<?php include("fend.inc"); ?>
154
</body>
155
</html>

Also available in: Unified diff