Projet

Général

Profil

Télécharger (9,03 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / status_ntpd.php @ 64feeb74

1
<?php
2
/* $Id$ */
3
/*
4
	status_ntpd.php
5
	part of pfSense (https://www.pfsense.org/)
6

    
7
	Copyright (C) 2013 Dagorlad
8
	Copyright (C) 2012 Jim Pingle
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
/*
33
	pfSense_BUILDER_BINARIES:	/usr/local/sbin/ntpd	/usr/local/sbin/ntpq
34
	pfSense_MODULE:	ntpd
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-status-ntp
39
##|*NAME=Status: NTP page
40
##|*DESCR=Allow access to the 'Status: NTP' page.
41
##|*MATCH=status_ntpd.php*
42
##|-PRIV
43

    
44
require_once("guiconfig.inc");
45

    
46
if(!isset($config['ntpd']['noquery'])) {
47

    
48
	exec("/usr/local/sbin/ntpq -pn | /usr/bin/tail +3", $ntpq_output);
49

    
50
	$ntpq_servers = array();
51
	foreach ($ntpq_output as $line) {
52
		$server = array();
53

    
54
		switch (substr($line, 0, 1)) {
55
			case " ":
56
				$server['status'] = "Unreach/Pending";
57
				break;
58
			case "*":
59
				$server['status'] = "Active Peer";
60
				break;
61
			case "+":
62
				$server['status'] = "Candidate";
63
				break;
64
			case "o":
65
				$server['status'] = "PPS Peer";
66
				break;
67
			case "#":
68
				$server['status'] = "Selected";
69
				break;
70
			case ".":
71
				$server['status'] = "Excess Peer";
72
				break;
73
			case "x":
74
				$server['status'] = "False Ticker";
75
				break;
76
			case "-":
77
				$server['status'] = "Outlier";
78
				break;
79
		}
80

    
81
		$line = substr($line, 1);
82
		$peerinfo = preg_split("/[\s\t]+/", $line);
83

    
84
		$server['server'] = $peerinfo[0];
85
		$server['refid'] = $peerinfo[1];
86
		$server['stratum'] = $peerinfo[2];
87
		$server['type'] = $peerinfo[3];
88
		$server['when'] = $peerinfo[4];
89
		$server['poll'] = $peerinfo[5];
90
		$server['reach'] = $peerinfo[6];
91
		$server['delay'] = $peerinfo[7];
92
		$server['offset'] = $peerinfo[8];
93
		$server['jitter'] = $peerinfo[9];
94

    
95
		$ntpq_servers[] = $server;
96
	}
97

    
98
	exec("/usr/local/sbin/ntpq -c clockvar", $ntpq_clockvar_output);
99
	foreach ($ntpq_clockvar_output as $line) {
100
		if (substr($line, 0, 9) == "timecode=") {
101
			$tmp = explode('"', $line);
102
			$tmp = $tmp[1];
103
			if (substr($tmp, 0, 6) == '$GPRMC') {
104
				$gps_vars = explode(",", $tmp);
105
				$gps_ok  = ($gps_vars[2] == "A");
106
				$gps_lat_deg = substr($gps_vars[3], 0, 2);
107
				$gps_lat_min = substr($gps_vars[3], 2) / 60.0;
108
				$gps_lon_deg = substr($gps_vars[5], 0, 3);
109
				$gps_lon_min = substr($gps_vars[5], 3) / 60.0;
110
				$gps_lat = $gps_lat_deg + $gps_lat_min;
111
				$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
112
				$gps_lon = $gps_lon_deg + $gps_lon_min;
113
				$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
114
			}elseif (substr($tmp, 0, 6) == '$GPGGA') {
115
				$gps_vars = explode(",", $tmp);
116
				$gps_ok  = $gps_vars[6];
117
				$gps_lat_deg = substr($gps_vars[2], 0, 2);
118
				$gps_lat_min = substr($gps_vars[2], 2) / 60.0;
119
				$gps_lon_deg = substr($gps_vars[4], 0, 3);
120
				$gps_lon_min = substr($gps_vars[4], 3) / 60.0;
121
				$gps_lat = $gps_lat_deg + $gps_lat_min;
122
				$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
123
				$gps_lon = $gps_lon_deg + $gps_lon_min;
124
				$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
125
				$gps_alt = $gps_vars[9];
126
				$gps_alt_unit = $gps_vars[10];
127
				$gps_sat = $gps_vars[7];
128
			}elseif (substr($tmp, 0, 6) == '$GPGLL') {
129
				$gps_vars = explode(",", $tmp);
130
				$gps_ok  = ($gps_vars[6] == "A");
131
				$gps_lat_deg = substr($gps_vars[1], 0, 2);
132
				$gps_lat_min = substr($gps_vars[1], 2) / 60.0;
133
				$gps_lon_deg = substr($gps_vars[3], 0, 3);
134
				$gps_lon_min = substr($gps_vars[3], 3) / 60.0;
135
				$gps_lat = $gps_lat_deg + $gps_lat_min;
136
				$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
137
				$gps_lon = $gps_lon_deg + $gps_lon_min;
138
				$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
139
			}
140
		}
141
	}
142

    
143
}
144

    
145
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
146
	//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
147
	$gpsport = fopen("/dev/gps0", "r+");
148
	while($gpsport){
149
		$buffer = fgets($gpsport);
150
		if(substr($buffer, 0, 6)=='$GPGSV'){
151
			//echo $buffer."\n";
152
			$gpgsv = explode(',',$buffer);
153
			$gps_satview = $gpgsv[3];
154
			break;
155
		}
156
	}
157
}
158

    
159
$pgtitle = array(gettext("Status"),gettext("NTP"));
160
$shortcut_section = "ntp";
161
include("head.inc");
162
?>
163
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
164
<?php include("fbegin.inc"); ?>
165
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="status ntpd">
166
<tr><td><div id="mainarea">
167
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="heading">
168
		<tr><td class="listtopic">Network Time Protocol Status</td></tr>
169
	</table>
170
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
171
	<thead>
172
	<tr>
173
		<th class="listhdrr"><?=gettext("Status"); ?></th>
174
		<th class="listhdrr"><?=gettext("Server"); ?></th>
175
		<th class="listhdrr"><?=gettext("Ref ID"); ?></th>
176
		<th class="listhdrr"><?=gettext("Stratum"); ?></th>
177
		<th class="listhdrr"><?=gettext("Type"); ?></th>
178
		<th class="listhdrr"><?=gettext("When"); ?></th>
179
		<th class="listhdrr"><?=gettext("Poll"); ?></th>
180
		<th class="listhdrr"><?=gettext("Reach"); ?></th>
181
		<th class="listhdrr"><?=gettext("Delay"); ?></th>
182
		<th class="listhdrr"><?=gettext("Offset"); ?></th>
183
		<th class="listhdr"><?=gettext("Jitter"); ?></th>
184
	</tr>
185
	</thead>
186
	<tbody>
187
	<?php if (isset($config['ntpd']['noquery'])): ?>
188
	<tr><td class="listlr" colspan="11" align="center">
189
		Statistics unavailable because ntpq and ntpdc queries are disabled in the <a href="services_ntpd.php">NTP service settings</a>.
190
	</td></tr>
191
	<?php elseif (count($ntpq_servers) == 0): ?>
192
	<tr><td class="listlr" colspan="11" align="center">
193
		No peers found, <a href="status_services.php">is the ntp service running?</a>.
194
	</td></tr>
195
	<?php else: ?>
196
	<?php $i = 0; foreach ($ntpq_servers as $server): ?>
197
	<tr>
198
	<td class="listlr nowrap">
199
		<?=$server['status'];?>
200
	</td>
201
	<td class="listr">
202
		<?=$server['server'];?>
203
	</td>
204
	<td class="listr">
205
		<?=$server['refid'];?>
206
	</td>
207
	<td class="listr">
208
		<?=$server['stratum'];?>
209
	</td>
210
	<td class="listr">
211
		<?=$server['type'];?>
212
	</td>
213
	<td class="listr">
214
		<?=$server['when'];?>
215
	</td>
216
	<td class="listr">
217
		<?=$server['poll'];?>
218
	</td>
219
	<td class="listr">
220
		<?=$server['reach'];?>
221
	</td>
222
	<td class="listr">
223
		<?=$server['delay'];?>
224
	</td>
225
	<td class="listr">
226
		<?=$server['offset'];?>
227
	</td>
228
	<td class="listr">
229
		<?=$server['jitter'];?>
230
	</td>
231
	</tr>
232
<?php $i++; endforeach; endif; ?>
233
	</tbody>
234
	</table>
235
<?php if (($gps_ok) && ($gps_lat) && ($gps_lon)): ?>
236
	<?php $gps_goo_lnk = 2; ?>
237
	<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="gps status">
238
	<thead>
239
	<tr>
240
		<th class="listhdrr"><?=gettext("Clock Latitude"); ?></th>
241
		<th class="listhdrr"><?=gettext("Clock Longitude"); ?></th>
242
		<?php if (isset($gps_alt)) { echo '<th class="listhdrr">' . gettext("Clock Altitude") . '</th>'; $gps_goo_lnk++;}?>
243
		<?php if (isset($gps_sat) || isset($gps_satview)) { echo '<th class="listhdrr">' . gettext("Satellites") . '</th>'; $gps_goo_lnk++;}?>
244
	</tr>
245
	</thead>
246
	<tbody>
247
		<tr>
248
			<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>
249
			<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>
250
			<?php if (isset($gps_alt)) { echo '<td class="listlr" align="center">' . $gps_alt . ' ' . $gps_alt_unit . '</td>';}?>
251
			<td class="listr" align="center">
252
			<?php 
253
			if (isset($gps_satview)) {echo 'in view ' . intval($gps_satview);}
254
			if (isset($gps_sat) && isset($gps_satview)) {echo ', ';}
255
			if (isset($gps_sat)) {echo 'in use ' . $gps_sat;} 
256
			?>
257
			</td>
258
		</tr>
259
		<tr>
260
			<td class="listlr" colspan="<?php echo $gps_goo_lnk; ?>" align="center"><a target="_gmaps" href="http://maps.google.com/?q=<?php echo $gps_lat; ?>,<?php echo $gps_lon; ?>">Google Maps Link</a></td>
261
		</tr>
262
	</tbody>
263
	</table>
264
<?php endif; ?>
265
</div></td></tr>
266
</table>
267
<?php include("fend.inc"); ?>
268
</body>
269
</html>
(193-193/254)