Projet

Général

Profil

Télécharger (18 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / services_ntpd.php @ 88c24958

1
<?php
2
/*
3
	services_ntpd.php
4

    
5
	Copyright (C) 2013	Dagorlad
6
	Copyright (C) 2012	Jim Pingle
7
	All rights reserved.
8

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

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

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

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

    
34
##|+PRIV
35
##|*IDENT=page-services-ntpd
36
##|*NAME=Services: NTP
37
##|*DESCR=Allow access to the 'Services: NTP' page.
38
##|*MATCH=services_ntpd.php*
39
##|-PRIV
40

    
41
require("guiconfig.inc");
42
require_once('rrd.inc');
43
require_once("shaper.inc");
44

    
45
if (!is_array($config['ntpd']))
46
	$config['ntpd'] = array();
47

    
48
if (empty($config['ntpd']['interface'])) {
49
	if (is_array($config['installedpackages']['openntpd']) && is_array($config['installedpackages']['openntpd']['config']) &&
50
	    is_array($config['installedpackages']['openntpd']['config'][0]) && !empty($config['installedpackages']['openntpd']['config'][0]['interface'])) {
51
		$pconfig['interface'] = explode(",", $config['installedpackages']['openntpd']['config'][0]['interface']);
52
		unset($config['installedpackages']['openntpd']);
53
		write_config("Upgraded settings from openttpd");
54
	} else
55
		$pconfig['interface'] = array();
56
} else
57
	$pconfig['interface'] = explode(",", $config['ntpd']['interface']);
58

    
59
if ($_POST) {
60

    
61
	unset($input_errors);
62
	$pconfig = $_POST;
63

    
64
	if (!$input_errors) {
65
		if (is_array($_POST['interface']))
66
			$config['ntpd']['interface'] = implode(",", $_POST['interface']);
67
		elseif (isset($config['ntpd']['interface']))
68
			unset($config['ntpd']['interface']);
69

    
70
		if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport']))
71
			$config['ntpd']['gpsport'] = $_POST['gpsport'];
72
		elseif (isset($config['ntpd']['gpsport']))
73
			unset($config['ntpd']['gpsport']);
74

    
75
		unset($config['ntpd']['prefer']);
76
		unset($config['ntpd']['noselect']);
77
		$timeservers = '';
78
		for ($i = 0; $i < 10; $i++) {
79
			$tserver = trim($_POST["server{$i}"]);
80
			if (!empty($tserver)) {
81
				$timeservers .= "{$tserver} ";
82
				if (!empty($_POST["servprefer{$i}"])) $config['ntpd']['prefer'] .= "{$tserver} ";
83
				if (!empty($_POST["servselect{$i}"])) $config['ntpd']['noselect'].= "{$tserver} ";
84
			}
85
		}
86
		if (trim($timeservers) == "")
87
			$timeservers = "pool.ntp.org";
88
		$config['system']['timeservers'] = trim($timeservers);
89

    
90
		if (!empty($_POST['ntporphan']) && ($_POST['ntporphan'] < 17) && ($_POST['ntporphan'] != '12'))
91
			$config['ntpd']['orphan'] = $_POST['ntporphan'];
92
		elseif (isset($config['ntpd']['orphan']))
93
			unset($config['ntpd']['orphan']);
94

    
95
		if (!empty($_POST['logpeer']))
96
			$config['ntpd']['logpeer'] = $_POST['logpeer'];
97
		elseif (isset($config['ntpd']['logpeer']))
98
			unset($config['ntpd']['logpeer']);
99

    
100
		if (!empty($_POST['logsys']))
101
			$config['ntpd']['logsys'] = $_POST['logsys'];
102
		elseif (isset($config['ntpd']['logsys']))
103
			unset($config['ntpd']['logsys']);
104

    
105
		if (!empty($_POST['clockstats']))
106
			$config['ntpd']['clockstats'] = $_POST['clockstats'];
107
		elseif (isset($config['ntpd']['clockstats']))
108
			unset($config['ntpd']['clockstats']);
109

    
110
		if (!empty($_POST['loopstats']))
111
			$config['ntpd']['loopstats'] = $_POST['loopstats'];
112
		elseif (isset($config['ntpd']['loopstats']))
113
			unset($config['ntpd']['loopstats']);
114

    
115
		if (!empty($_POST['peerstats']))
116
			$config['ntpd']['peerstats'] = $_POST['peerstats'];
117
		elseif (isset($config['ntpd']['peerstats']))
118
			unset($config['ntpd']['peerstats']);
119

    
120
		if (empty($_POST['kod']))
121
			$config['ntpd']['kod'] = 'on';
122
		elseif (isset($config['ntpd']['kod']))
123
			unset($config['ntpd']['kod']);
124

    
125
		if (empty($_POST['nomodify']))
126
			$config['ntpd']['nomodify'] = 'on';
127
		elseif (isset($config['ntpd']['nomodify']))
128
			unset($config['ntpd']['nomodify']);
129

    
130
		if (!empty($_POST['noquery']))
131
			$config['ntpd']['noquery'] = $_POST['noquery'];
132
		elseif (isset($config['ntpd']['noquery']))
133
			unset($config['ntpd']['noquery']);
134

    
135
		if (!empty($_POST['noserve']))
136
			$config['ntpd']['noserve'] = $_POST['noserve'];
137
		elseif (isset($config['ntpd']['noserve']))
138
			unset($config['ntpd']['noserve']);
139

    
140
		if (empty($_POST['nopeer']))
141
			$config['ntpd']['nopeer'] = 'on';
142
		elseif (isset($config['ntpd']['nopeer']))
143
			unset($config['ntpd']['nopeer']);
144

    
145
		if (empty($_POST['notrap']))
146
			$config['ntpd']['notrap'] = 'on';
147
		elseif (isset($config['ntpd']['notrap']))
148
			unset($config['ntpd']['notrap']);
149

    
150
		if ((empty($_POST['statsgraph'])) != (isset($config['ntpd']['statsgraph'])));
151
			enable_rrd_graphing();
152
		if (!empty($_POST['statsgraph']))
153
			$config['ntpd']['statsgraph'] = $_POST['statsgraph'];
154
		elseif (isset($config['ntpd']['statsgraph']))
155
			unset($config['ntpd']['statsgraph']);
156

    
157
		if (!empty($_POST['leaptxt']))
158
			$config['ntpd']['leapsec'] = base64_encode($_POST['leaptxt']);
159
		elseif (isset($config['ntpd']['leapsec']))
160
			unset($config['ntpd']['leapsec']);
161

    
162
		if (is_uploaded_file($_FILES['leapfile']['tmp_name']))
163
			$config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name']));
164

    
165
		write_config("Updated NTP Server Settings");
166

    
167
		$retval = 0;
168
		$retval = system_ntp_configure();
169
		$savemsg = get_std_save_message($retval);
170

    
171
	}
172
}
173
$closehead = false;
174
$pconfig = &$config['ntpd'];
175
$pgtitle = array(gettext("Services"),gettext("NTP"));
176
$shortcut_section = "ntp";
177
include("head.inc");
178

    
179
?>
180

    
181
<script type="text/javascript">
182
//<![CDATA[
183
	//Generic show an advanced option function
184
	function show_advanced(showboxID, configvalueID) {
185
		document.getElementById(showboxID).innerHTML='';
186
		aodiv = document.getElementById(configvalueID);
187
		aodiv.style.display = "block";
188
	}
189

    
190
	//Insure only one of two mutually exclusive options are checked
191
	function CheckOffOther(clicked, checkOff) {
192
		if (document.getElementById(clicked).checked) {
193
			document.getElementById(checkOff).checked=false;
194
		}
195
	}
196

    
197
	//Show another time server line, limited to 10 servers
198
	function NewTimeServer(add) {
199
		//If the last line has a value
200
		var CheckServer = 'server' + (add - 1);
201
		var LastId = document.getElementById(CheckServer);
202
		if (document.getElementById(CheckServer).value != '') {
203
			if (add < 10) {
204
				var TimeServerID = 'timeserver' + add;
205
				document.getElementById(TimeServerID).style.display = 'block';
206
				//then revise the add another server line
207
				if (add < 9) {
208
					var next = add + 1;
209
					var newdiv = '<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?php echo gettext("Add another Time server");?>" onclick="NewTimeServer(' + next + ')" alt="add" />\n';
210
					document.getElementById('addserver').innerHTML=newdiv;
211
				}else{
212
					document.getElementById('addserver').style.display = 'none';
213
				}
214
			}
215
		}
216
	}
217
//]]>
218
</script>
219
</head>
220

    
221
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
222
<?php include("fbegin.inc"); ?>
223
<form action="services_ntpd.php" method="post" name="iform" id="iform" enctype="multipart/form-data" accept-charset="utf-8">
224
<?php if ($input_errors) print_input_errors($input_errors); ?>
225
<?php if ($savemsg) print_info_box($savemsg); ?>
226

    
227
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="ntpd">
228
  <tr>
229
	<td>
230
<?php
231
	$tab_array = array();
232
	$tab_array[] = array(gettext("NTP"), true, "services_ntpd.php");
233
	$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
234
	$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
235
	display_top_tabs($tab_array);
236
?>
237
	</td>
238
  </tr>
239
  <tr>
240
	<td>
241
		<div id="mainarea">
242
		<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
243
			<tr>
244
				<td colspan="2" valign="top" class="listtopic"><?=gettext("NTP Server Configuration"); ?></td>
245
			</tr>
246
			<tr>
247
				<td width="22%" valign="top" class="vncellreq">Interface(s)</td>
248
				<td width="78%" class="vtable">
249
<?php
250
	$interfaces = get_configured_interface_with_descr();
251
	$carplist = get_configured_carp_interface_list();
252
	foreach ($carplist as $cif => $carpip)
253
		$interfaces[$cif] = $carpip." (".get_vip_descr($carpip).")";
254
	$aliaslist = get_configured_ip_aliases_list();
255
	foreach ($aliaslist as $aliasip => $aliasif)
256
		$interfaces[$aliasip] = $aliasip." (".get_vip_descr($aliasip).")";
257
	$size = (count($interfaces) < 10) ? count($interfaces) : 10;
258
?>
259
			<select id="interface" name="interface[]" multiple="multiple" class="formselect" size="<?php echo $size; ?>">
260
<?php	
261
	foreach ($interfaces as $iface => $ifacename) {
262
		if (!is_ipaddr(get_interface_ip($iface)) && !is_ipaddr($iface))
263
			continue;
264
		echo "<option value='{$iface}'";
265
		if (is_array($pconfig['interface']))
266
			if (in_array($iface, $pconfig['interface'])) echo " selected=\"selected\"";
267
		echo ">" . htmlspecialchars($ifacename) . "</option>\n";
268
	} ?>
269
					</select>
270
					<br />
271
					<br /><?php echo gettext("Interfaces without an IP address will not be shown."); ?>
272
					<br />
273
					<br /><?php echo gettext("Selecting no interfaces will listen on all interfaces with a wildcard."); ?>
274
					<br /><?php echo gettext("Selecting all interfaces will explicitly listen on only the interfaces/IPs specified."); ?>
275
				</td>
276
			</tr>
277
			<tr>
278
				<td width="22%" valign="top" class="vncellreq">Time servers</td>
279
				<td width="78%" class="vtable">
280
					<?php
281
					$timeservers = explode( ' ', $config['system']['timeservers']);
282
					for ($i = $j = 0; $i < 10; $i++){
283
						echo "<div id=\"timeserver{$i}\"";
284
						if ((isset($timeservers[$i])) || ($i < 3)) {
285
							$j++;
286
						}else{
287
							echo " style=\"display:none\"";
288
						}
289
						echo ">\n";
290
						
291
						echo "<input name=\"server{$i}\" class=\"formfld unknown\" id=\"server{$i}\" size=\"30\" value=\"{$timeservers[$i]}\" type=\"text\" />&emsp;";
292
						echo "\n<input name=\"servprefer{$i}\" class=\"formcheckbox\" id=\"servprefer{$i}\" onclick=\"CheckOffOther('servprefer{$i}', 'servselect{$i}')\" type=\"checkbox\"";
293
						if (substr_count($config['ntpd']['prefer'], $timeservers[$i])) echo " checked=\"checked\"";
294
						echo " />&nbsp;prefer&emsp;";
295
						echo "\n<input name=\"servselect{$i}\" class=\"formcheckbox\" id=\"servselect{$i}\" onclick=\"CheckOffOther('servselect{$i}', 'servprefer{$i}')\" type=\"checkbox\"";
296
						if (substr_count($config['ntpd']['noselect'], $timeservers[$i])) echo " checked=\"checked\"";
297
						echo " />&nbsp;noselect\n<br />\n</div>\n";
298
					}
299
					?>
300
					<div id="addserver">
301
					<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?php echo gettext("Add another Time server");?>" onclick="NewTimeServer(<?php echo $j;?>)" alt="add" />
302
					</div>
303
					<br />
304
					<?php echo gettext('For best results three to five servers should be configured here.'); ?>
305
					<br />
306
					<?php echo gettext('The <i>prefer</i> option indicates that NTP should favor the use of this server more than all others.'); ?>
307
					<br />
308
					<?php echo gettext('The <i>noselect</i> option indicates that NTP should not use this server for time, but stats for this server will be collected and displayed.'); ?>
309
				</td>
310
			</tr>
311
			<tr>
312
				<td width="22%" valign="top" class="vncellreq">Orphan mode</td>
313
				<td width="78%" class="vtable">
314
					<input name="ntporphan" type="text" class="formfld unknown" id="ntporphan" min="1" max="16" size="20" value="<?=htmlspecialchars($pconfig['orphan']);?>" /><?php echo gettext("(0-15)");?><br />
315
					<?php echo gettext("Orphan mode allows the system clock to be used when no other clocks are available. The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough to insure that any other servers available to clients are preferred over this server. (default: 12)."); ?>
316
				</td>
317
			</tr>
318
			<tr>
319
				<td width="22%" valign="top" class="vncellreq">NTP graphs</td>
320
				<td width="78%" class="vtable">
321
					<input name="statsgraph" type="checkbox" class="formcheckbox" id="statsgraph" <?php if($pconfig['statsgraph']) echo " checked=\"checked\""; ?> />
322
					<?php echo gettext("Enable rrd graphs of NTP statistics (default: disabled)."); ?>
323
				</td>
324
			</tr>
325
			<tr>
326
				<td width="22%" valign="top" class="vncellreq">Syslog logging</td>
327
				<td width="78%" class="vtable">
328
					<?php echo gettext("These options enable additional messages from NTP to be written to the System Log");?> (<a href="diag_logs_ntpd.php"><?php echo gettext("Status > System Logs > NTP"); ?></a>).
329
					<br /><br />
330
					<input name="logpeer" type="checkbox" class="formcheckbox" id="logpeer"<?php if($pconfig['logpeer']) echo " checked=\"checked\""; ?> />
331
					<?php echo gettext("Enable logging of peer messages (default: disabled)."); ?>
332
					<br />
333
					<input name="logsys" type="checkbox" class="formcheckbox" id="logsys"<?php if($pconfig['logsys']) echo " checked=\"checked\""; ?> />
334
					<?php echo gettext("Enable logging of system messages (default: disabled)."); ?>
335
				</td>
336
			</tr>
337
			<tr>
338
				<td width="22%" valign="top" class="vncellreq">Statistics logging</td>
339
				<td width="78%" class="vtable">
340
					<div id="showstatisticsbox">
341
					<input type="button" onclick="show_advanced('showstatisticsbox', 'showstatistics')" value="<?=gettext("Advanced");?>" /> - <?=gettext("Show statistics logging options");?>
342
					</div>
343
					<div id="showstatistics" style="display:none">
344
					<strong><?php echo gettext("Warning: ")?></strong><?php echo gettext("these options will create persistant daily log files in /var/log/ntp."); ?>
345
					<br /><br />
346
					<input name="clockstats" type="checkbox" class="formcheckbox" id="clockstats"<?php if($pconfig['clockstats']) echo " checked=\"checked\""; ?> />
347
					<?php echo gettext("Enable logging of reference clock statistics (default: disabled)."); ?>
348
					<br />
349
					<input name="loopstats" type="checkbox" class="formcheckbox" id="loopstats"<?php if($pconfig['loopstats']) echo " checked=\"checked\""; ?> />
350
					<?php echo gettext("Enable logging of clock discipline statistics (default: disabled)."); ?>
351
					<br />
352
					<input name="peerstats" type="checkbox" class="formcheckbox" id="peerstats"<?php if($pconfig['peerstats']) echo " checked=\"checked\""; ?> />
353
					<?php echo gettext("Enable logging of NTP peer statistics (default: disabled)."); ?>
354
					</div>
355
				</td>
356
			</tr>
357
			<tr>
358
				<td width="22%" valign="top" class="vncellreq">Access restrictions</td>
359
				<td width="78%" class="vtable">
360
					<div id="showrestrictbox">
361
					<input type="button" onclick="show_advanced('showrestrictbox', 'showrestrict')" value="<?=gettext("Advanced");?>" /> - <?=gettext("Show access restriction options");?>
362
					</div>
363
					<div id="showrestrict" style="display:none">
364
					<?php echo gettext("these options control access to NTP from the WAN."); ?>
365
					<br /><br />
366
					<input name="kod" type="checkbox" class="formcheckbox" id="kod"<?php if(!$pconfig['kod']) echo " checked=\"checked\""; ?> />
367
					<?php echo gettext("Enable Kiss-o'-death packets (default: enabled)."); ?>
368
					<br />
369
					<input name="nomodify" type="checkbox" class="formcheckbox" id="nomodify"<?php if(!$pconfig['nomodify']) echo " checked=\"checked\""; ?> />
370
					<?php echo gettext("Deny state modifications (i.e. run time configuration) by ntpq and ntpdc (default: enabled)."); ?>
371
					<br />
372
					<input name="noquery" type="checkbox" class="formcheckbox" id="noquery"<?php if($pconfig['noquery']) echo " checked=\"checked\""; ?> />>
373
					<?php echo gettext("Disable ntpq and ntpdc queries (default: disabled)."); ?>
374
					<br />
375
					<input name="noserve" type="checkbox" class="formcheckbox" id="noserve"<?php if($pconfig['noserve']) echo " checked=\"checked\""; ?> />
376
					<?php echo gettext("Disable all except ntpq and ntpdc queries (default: disabled)."); ?>
377
					<br />
378
					<input name="nopeer" type="checkbox" class="formcheckbox" id="nopeer"<?php if(!$pconfig['nopeer']) echo " checked=\"checked\""; ?> />
379
					<?php echo gettext("Deny packets that attempt a peer association (default: enabled)."); ?>
380
					<br />
381
					<input name="notrap" type="checkbox" class="formcheckbox" id="notrap"<?php if(!$pconfig['notrap']) echo " checked=\"checked\""; ?> />
382
					<?php echo gettext("Deny mode 6 control message trap service (default: enabled)."); ?>
383
					</div>
384
				</td>
385
			</tr>
386
			<tr>
387
				<td width="22%" valign="top" class="vncellreq">Leap seconds</td>
388
				<td width="78%" class="vtable">
389
					<div id="showleapsecbox">
390
					<input type="button" onclick="show_advanced('showleapsecbox', 'showleapsec')" value="<?=gettext("Advanced");?>" /> - <?=gettext("Show Leap second configuration");?>
391
					</div>
392
					<div id="showleapsec" style="display:none">
393
					<?php echo gettext("A leap second file allows NTP to advertize an upcoming leap second addition or subtraction.");?>
394
					<?php echo gettext("Normally this is only useful if this server is a stratum 1 time server.");?>
395
					<br /><br />
396
					<?php echo gettext("Enter Leap second configuration as text:");?><br />
397
					<textarea name="leaptxt" class="formpre" id="leaptxt" cols="65" rows="7"><?php $text = base64_decode(chunk_split($pconfig['leapsec'])); echo $text;?></textarea><br />
398
					<strong><?php echo gettext("Or");?></strong>, <?php echo gettext("select a file to upload:");?>
399
					<input type="file" name="leapfile" class="formfld file" id="leapfile" />
400
					</div>
401
				</td>
402
			</tr>
403
			<tr>
404
				<td width="22%" valign="top">&nbsp;</td>
405
				<td width="78%">
406
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
407
				</td>
408
			</tr>
409
		</table>
410
</div></td></tr></table>
411
</form>
412
<?php include("fend.inc"); ?>
413
</body>
414
</html>
(162-162/255)