Projet

Général

Profil

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

univnautes / usr / local / www / services_ntpd.php @ 63d5a5e0

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
if (empty($pconfig['interface']))
176
	$pconfig['interface'] = array();
177
else
178
	$pconfig['interface'] = explode(",", $pconfig['interface']);
179
$pgtitle = array(gettext("Services"),gettext("NTP"));
180
$shortcut_section = "ntp";
181
include("head.inc");
182

    
183
?>
184

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

    
194
	//Insure only one of two mutually exclusive options are checked
195
	function CheckOffOther(clicked, checkOff) {
196
		if (document.getElementById(clicked).checked) {
197
			document.getElementById(checkOff).checked=false;
198
		}
199
	}
200

    
201
	//Show another time server line, limited to 10 servers
202
	function NewTimeServer(add) {
203
		//If the last line has a value
204
		var CheckServer = 'server' + (add - 1);
205
		var LastId = document.getElementById(CheckServer);
206
		if (document.getElementById(CheckServer).value != '') {
207
			if (add < 10) {
208
				var TimeServerID = 'timeserver' + add;
209
				document.getElementById(TimeServerID).style.display = 'block';
210
				//then revise the add another server line
211
				if (add < 9) {
212
					var next = add + 1;
213
					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';
214
					document.getElementById('addserver').innerHTML=newdiv;
215
				}else{
216
					document.getElementById('addserver').style.display = 'none';
217
				}
218
			}
219
		}
220
	}
221
//]]>
222
</script>
223
</head>
224

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

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