Projet

Général

Profil

Télécharger (6,38 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / status_ntpd.php @ 2d1e985d

1
<?php
2
/* $Id$ */
3
/*
4
	status_ntpd.php
5
	part of pfSense (https://www.pfsense.org/)
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/local/sbin/ntpd	/usr/local/sbin/ntpq
33
	pfSense_MODULE:	ntpd
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/local/sbin/ntpq -pn | /usr/bin/tail +3", $ntpq_output);
46

    
47
$ntpq_servers = array();
48
foreach ($ntpq_output as $line) {
49
	$server = array();
50

    
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
	$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
exec("/usr/local/sbin/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_deg = substr($gps_vars[3], 0, 2);
104
			$gps_lat_min = substr($gps_vars[3], 2) / 60.0;
105
			$gps_lon_deg = substr($gps_vars[5], 0, 3);
106
			$gps_lon_min = substr($gps_vars[5], 3) / 60.0;
107
			$gps_lat = $gps_lat_deg + $gps_lat_min;
108
			$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
109
			$gps_lon = $gps_lon_deg + $gps_lon_min;
110
			$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
111
		}
112
	}
113
}
114

    
115
$pgtitle = array(gettext("Status"),gettext("NTP"));
116
$shortcut_section = "ntp";
117
include("head.inc");
118
?>
119
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
120
<?php include("fbegin.inc"); ?>
121
<table width="100%" border="0" cellpadding="0" cellspacing="0">
122
<tr><td><div id="mainarea">
123
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
124
		<tr><td class="listtopic">Network Time Protocol Status</td></tr>
125
	</table>
126
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
127
	<thead>
128
	<tr>
129
		<th class="listhdrr"><?=gettext("Status"); ?></th>
130
		<th class="listhdrr"><?=gettext("Server"); ?></th>
131
		<th class="listhdrr"><?=gettext("Ref ID"); ?></th>
132
		<th class="listhdrr"><?=gettext("Stratum"); ?></th>
133
		<th class="listhdrr"><?=gettext("Type"); ?></th>
134
		<th class="listhdrr"><?=gettext("When"); ?></th>
135
		<th class="listhdrr"><?=gettext("Poll"); ?></th>
136
		<th class="listhdrr"><?=gettext("Reach"); ?></th>
137
		<th class="listhdrr"><?=gettext("Delay"); ?></th>
138
		<th class="listhdrr"><?=gettext("Offset"); ?></th>
139
		<th class="listhdr"><?=gettext("Jitter"); ?></th>
140
	</tr>
141
	</thead>
142
	<tbody>
143
	<?php if (count($ntpq_servers) == 0): ?>
144
	<tr><td class="listlr" colspan="11" align="center">
145
		No peers found, <a href="status_services.php">is the ntp service running?</a>.
146
	</td></tr>
147
	<?php else: ?>
148
	<?php $i = 0; foreach ($ntpq_servers as $server): ?>
149
	<tr>
150
	<td class="listlr" nowrap="nowrap">
151
		<?=$server['status'];?>
152
	</td>
153
	<td class="listlr">
154
		<?=$server['server'];?>
155
	</td>
156
	<td class="listlr">
157
		<?=$server['refid'];?>
158
	</td>
159
	<td class="listlr">
160
		<?=$server['stratum'];?>
161
	</td>
162
	<td class="listlr">
163
		<?=$server['type'];?>
164
	</td>
165
	<td class="listlr">
166
		<?=$server['when'];?>
167
	</td>
168
	<td class="listlr">
169
		<?=$server['poll'];?>
170
	</td>
171
	<td class="listlr">
172
		<?=$server['reach'];?>
173
	</td>
174
	<td class="listlr">
175
		<?=$server['delay'];?>
176
	</td>
177
	<td class="listlr">
178
		<?=$server['offset'];?>
179
	</td>
180
	<td class="listlr">
181
		<?=$server['jitter'];?>
182
	</td>
183
	</tr>
184
<?php $i++; endforeach; endif; ?>
185
	</tbody>
186
	</table>
187
<?php if (($gps_ok) && ($gps_lat) && ($gps_lon)): ?>
188
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
189
	<thead>
190
	<tr>
191
		<th class="listhdrr"><?=gettext("Clock Latitude"); ?></th>
192
		<th class="listhdrr"><?=gettext("Clock Longitude"); ?></th>
193
	</tr>
194
	</thead>
195
	<tbody>
196
		<tr>
197
			<td class="listlr" align="center"><?php echo sprintf("%.5f", $gps_lat); ?> (<?php echo sprintf("%d", $gps_lat_deg); ?>&deg; <?php echo sprintf("%.5f", $gps_lat_min*60); ?><?php echo $gps_vars[4]; ?>)</td>
198
			<td class="listlr" align="center"><?php echo sprintf("%.5f", $gps_lon); ?> (<?php echo sprintf("%d", $gps_lon_deg); ?>&deg; <?php echo sprintf("%.5f", $gps_lon_min*60); ?><?php echo $gps_vars[6]; ?>)</td>
199
		</tr>
200
		<tr>
201
			<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>
202
		</tr>
203
	</tbody>
204
	</table>
205
<?php endif; ?>
206
</div></td></tr>
207
</table>
208
<?php include("fend.inc"); ?>
209
</body>
210
</html>
(186-186/246)