Project

General

Profile

Download (18.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	services_ntpd.php
4

    
5
	Copyright (C) 2013	Dagorlad
6
	Copyright (C) 2012	Jim Pingle
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
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_MODULE:	ntpd
33
*/
34

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

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

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

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

    
60
if ($_POST) {
61

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
160
		if (!empty($_POST['leaptxt']))
161
			$config['ntpd']['leapsec'] = base64_encode($_POST['leaptxt']);
162
		elseif (isset($config['ntpd']['leapsec']))
163
			unset($config['ntpd']['leapsec']);
164

    
165
		if (is_uploaded_file($_FILES['leapfile']['tmp_name']))
166
			$config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name']));
167

    
168
		write_config("Updated NTP Server Settings");
169

    
170
		$retval = 0;
171
		$retval = system_ntp_configure();
172
		$savemsg = get_std_save_message($retval);
173

    
174
	}
175
}
176
$closehead = false;
177
$pconfig = &$config['ntpd'];
178
if (empty($pconfig['interface']))
179
	$pconfig['interface'] = array();
180
else
181
	$pconfig['interface'] = explode(",", $pconfig['interface']);
182
$pgtitle = array(gettext("Services"),gettext("NTP"));
183
$shortcut_section = "ntp";
184
include("head.inc");
185

    
186
?>
187

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

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

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

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

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