Project

General

Profile

Download (18.2 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-2014 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();
153
		if (!empty($_POST['statsgraph']))
154
			$config['ntpd']['statsgraph'] = $_POST['statsgraph'];
155
		elseif (isset($config['ntpd']['statsgraph']))
156
			unset($config['ntpd']['statsgraph']);
157

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

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

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

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

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

    
184
?>
185

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

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

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

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

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