Project

General

Profile

Download (23.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_ntpd.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9
 * Copyright (c) 2013 Dagorlad
10
 * All rights reserved.
11
 *
12
 * Licensed under the Apache License, Version 2.0 (the "License");
13
 * you may not use this file except in compliance with the License.
14
 * You may obtain a copy of the License at
15
 *
16
 * http://www.apache.org/licenses/LICENSE-2.0
17
 *
18
 * Unless required by applicable law or agreed to in writing, software
19
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 * See the License for the specific language governing permissions and
22
 * limitations under the License.
23
 */
24

    
25
##|+PRIV
26
##|*IDENT=page-services-ntpd
27
##|*NAME=Services: NTP Settings
28
##|*DESCR=Allow access to the 'Services: NTP Settings' page.
29
##|*MATCH=services_ntpd.php*
30
##|-PRIV
31

    
32
define('NUMTIMESERVERS', 10);		// The maximum number of configurable time servers
33
require_once("guiconfig.inc");
34
require_once('rrd.inc');
35
require_once("shaper.inc");
36

    
37
global $ntp_poll_min_default, $ntp_poll_max_default, $ntp_server_types;
38
$ntp_poll_values = system_ntp_poll_values();
39
$auto_pool_suffix = "pool.ntp.org";
40
$max_candidate_peers = 25;
41
$min_candidate_peers = 4;
42

    
43
config_init_path('ntpd');
44

    
45
if (empty(config_get_path('ntpd/interface'))) {
46
	$old_ifs = config_get_path('installedpackages/openntpd/config/0/interface');
47
	if (!empty($old_ifs)) {
48
		config_set_path('ntpd/interface', $old_ifs);
49
		$pconfig['interface'] = explode(",", $old_ifs);
50
		config_del_path('installedpackages/openntpd');
51
		write_config(gettext("Upgraded settings from openntpd"));
52
	} else {
53
		$pconfig['interface'] = array();
54
	}
55
} else {
56
	$pconfig['interface'] = explode(",", config_get_path('ntpd/interface'));
57
}
58

    
59
if ($_POST) {
60
	unset($input_errors);
61
	$pconfig = $_POST;
62

    
63
	if (!empty($_POST['ntpmaxpeers']) && (!is_numericint($_POST['ntpmaxpeers']) ||
64
	    ($_POST['ntpmaxpeers'] < $min_candidate_peers) || ($_POST['ntpmaxpeers'] > $max_candidate_peers))) {
65
		$input_errors[] = sprintf(gettext("Max candidate pool peers must be a number between %d and %d"), $min_candidate_peers, $max_candidate_peers);
66
	}
67
	
68
	if ((strlen($pconfig['ntporphan']) > 0) && (!is_numericint($pconfig['ntporphan']) || ($pconfig['ntporphan'] < 1) || ($pconfig['ntporphan'] > 15))) {
69
		$input_errors[] = gettext("The supplied value for NTP Orphan Mode is invalid.");
70
	}
71

    
72
	if (!array_key_exists($pconfig['ntpminpoll'], $ntp_poll_values)) {
73
		$input_errors[] = gettext("The supplied value for Minimum Poll Interval is invalid.");
74
	}
75

    
76
	if (!array_key_exists($pconfig['ntpmaxpoll'], $ntp_poll_values)) {
77
		$input_errors[] = gettext("The supplied value for Maximum Poll Interval is invalid.");
78
	}
79

    
80
	for ($i = 0; $i < NUMTIMESERVERS; $i++) {
81
		if (isset($pconfig["servselect{$i}"]) && (($pconfig["servistype{$i}"] == 'pool') || 
82
		    (substr_compare($pconfig["server{$i}"], $auto_pool_suffix, strlen($pconfig["server{$i}"]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0))) {
83
			$input_errors[] = gettext("It is not possible to use 'No Select' for pools.");
84
		}
85
		if (!empty($pconfig["server{$i}"]) && !is_domain($pconfig["server{$i}"]) &&
86
		    !is_ipaddr($pconfig["server{$i}"])) {
87
			$input_errors[] = gettext("NTP Time Server names must be valid domain names, IPv4 addresses, or IPv6 addresses");
88
		}
89
		if (isset($pconfig["servauth{$i}"]) && (($pconfig["servistype{$i}"] == 'pool') ||
90
		    (substr_compare($pconfig["server{$i}"], $auto_pool_suffix, strlen($pconfig["server{$i}"]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0))) {
91
			$input_errors[] = gettext("It is not possible to use 'Authenticated' for pools.");
92
		}
93
		if (isset($pconfig["servauth{$i}"]) && empty($pconfig['serverauth'])) {
94
			$input_errors[] = gettext("The NTP authentication key information must be set to use 'Authenticated' for a server or peer.");
95
		}
96
	}
97

    
98
	if (is_numericint($pconfig['ntpminpoll']) &&
99
	    is_numericint($pconfig['ntpmaxpoll']) &&
100
	    ($pconfig['ntpmaxpoll'] < $pconfig['ntpminpoll'])) {
101
		$input_errors[] = gettext("The supplied value for Minimum Poll Interval is higher than NTP Maximum Poll Interval.");
102
	}
103

    
104
	if (isset($pconfig['serverauth'])) {
105
		if (empty($pconfig['serverauthkey'])) {
106
			$input_errors[] = gettext("The supplied value for NTP Authentication key can't be empty.");
107
		} elseif (empty($pconfig['serverauthkeyid'])) {
108
			$input_errors[] = gettext("The authentication Key ID can't be empty.");
109
		} elseif (!ctype_digit($pconfig['serverauthkeyid'])) {
110
			$input_errors[] = gettext("The authentication Key ID must be a positive integer.");
111
		} elseif ($pconfig['serverauthkeyid'] < 1 || $pconfig['serverauthkeyid'] > 65535) {
112
			$input_errors[] = gettext("The authentication Key ID must be between 1-65535.");
113
		} elseif (($pconfig['serverauthalgo'] == 'md5') && ((strlen($pconfig['serverauthkey']) > 20) ||
114
		    !ctype_print($pconfig['serverauthkey']))) {
115
			$input_errors[] = gettext("The supplied value for NTP Authentication key for MD5 digest must be from 1 to 20 printable characters.");
116
		} elseif (($pconfig['serverauthalgo'] == 'sha1') && ((strlen($pconfig['serverauthkey']) != 40) ||
117
		    !ctype_xdigit($pconfig['serverauthkey']))) {
118
			$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA1 digest must be hex-encoded string of 40 characters.");
119
		} elseif (($pconfig['serverauthalgo'] == 'sha256') && ((strlen($pconfig['serverauthkey']) != 64) ||
120
		    !ctype_xdigit($pconfig['serverauthkey']))) {
121
			$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA256 digest must be hex-encoded string of 64 characters.");
122
		}
123
	}
124

    
125
	if (!$input_errors) {
126
		config_set_path('ntpd/enable', isset($_POST['enable']) ? 'enabled' : 'disabled');
127
		if (is_array($_POST['interface'])) {
128
			config_set_path('ntpd/interface', implode(",", $_POST['interface']));
129
		} else {
130
			config_del_path('ntpd/interface');
131
		}
132

    
133
		config_del_path('ntpd/prefer');
134
		config_del_path('ntpd/noselect');
135
		config_del_path('ntpd/ispool');
136
		config_del_path('ntpd/ispeer');
137
		config_del_path('ntpd/isauth');
138
		$timeservers = '';
139

    
140
		for ($i = 0; $i < NUMTIMESERVERS; $i++) {
141
			$tserver = trim($_POST["server{$i}"]);
142
			if (!empty($tserver)) {
143
				$timeservers .= "{$tserver} ";
144
				if (isset($_POST["servprefer{$i}"])) {
145
					config_set_path('ntpd/prefer', (config_get_path('ntpd/prefer') . "{$tserver} "));
146
				}
147
				if (isset($_POST["servselect{$i}"])) {
148
					config_set_path('ntpd/noselect', (config_get_path('ntpd/noselect') . "{$tserver} "));
149
				}
150
				if (isset($_POST["servauth{$i}"])) {
151
					config_set_path('ntpd/isauth', (config_get_path('ntpd/isauth') . "{$tserver} "));
152
				}
153
				if ($_POST["servistype{$i}"] == 'pool') {
154
					config_set_path('ntpd/ispool', (config_get_path('ntpd/ispool') . "{$tserver} "));
155
				} elseif ($_POST["servistype{$i}"] == 'peer') {
156
					config_set_path('ntpd/ispeer', (config_get_path('ntpd/ispeer') . "{$tserver} "));
157
				}
158
			}
159
		}
160
		if (trim($timeservers) == "") {
161
			$timeservers = "pool.ntp.org";
162
		}
163
		config_set_path('system/timeservers', trim($timeservers));
164

    
165
		if (!empty($pconfig['ntpmaxpeers'])) {
166
			config_set_path('ntpd/ntpmaxpeers', $pconfig['ntpmaxpeers']);
167
		} else {
168
			config_del_path('ntpd/ntpmaxpeers');
169
		}
170
		config_set_path('ntpd/orphan', trim($pconfig['ntporphan']));
171
		config_set_path('ntpd/ntpminpoll', $pconfig['ntpminpoll']);
172
		config_set_path('ntpd/ntpmaxpoll', $pconfig['ntpmaxpoll']);
173
		config_set_path('ntpd/dnsresolv', $pconfig['dnsresolv']);
174

    
175
		if (!empty($_POST['logpeer'])) {
176
			config_set_path('ntpd/logpeer', $_POST['logpeer']);
177
		} elseif (config_path_enabled('ntpd', 'logpeer')) {
178
			config_del_path('ntpd/logpeer');
179
		}
180

    
181
		if (!empty($_POST['logsys'])) {
182
			config_set_path('ntpd/logsys', $_POST['logsys']);
183
		} elseif (config_path_enabled('ntpd', 'logsys')) {
184
			config_del_path('ntpd/logsys');
185
		}
186

    
187
		if (!empty($_POST['clockstats'])) {
188
			config_set_path('ntpd/clockstats', $_POST['clockstats']);
189
		} elseif (config_path_enabled('ntpd', 'clockstats')) {
190
			config_del_path('ntpd/clockstats');
191
		}
192

    
193
		if (!empty($_POST['loopstats'])) {
194
			config_set_path('ntpd/loopstats', $_POST['loopstats']);
195
		} elseif (config_path_enabled('ntpd', 'loopstats')) {
196
			config_del_path('ntpd/loopstats');
197
		}
198

    
199
		if (!empty($_POST['peerstats'])) {
200
			config_set_path('ntpd/peerstats', $_POST['peerstats']);
201
		} elseif (config_path_enabled('ntpd', 'peerstats')) {
202
			config_del_path('ntpd/peerstats');
203
		}
204

    
205
		if ((empty($_POST['statsgraph'])) == (config_path_enabled('ntpd', 'statsgraph'))) {
206
			$enable_rrd_graphing = true;
207
		}
208
		if (!empty($_POST['statsgraph'])) {
209
			config_set_path('ntpd/statsgraph', $_POST['statsgraph']);
210
		} elseif (config_path_enabled('ntpd', 'statsgraph')) {
211
			config_del_path('ntpd/statsgraph');
212
		}
213
		if (isset($enable_rrd_graphing)) {
214
			enable_rrd_graphing();
215
		}
216

    
217
		if (!empty($_POST['leaptext'])) {
218
			config_set_path('ntpd/leapsec', base64_encode($_POST['leaptext']));
219
		} elseif (config_path_enabled('ntpd', 'leapsec')) {
220
			config_del_path('ntpd/leapsec');
221
		}
222

    
223
		if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) {
224
			config_set_path('ntpd/leapsec', base64_encode(file_get_contents($_FILES['leapfile']['tmp_name'])));
225
		}
226

    
227
		if (!empty($_POST['serverauth'])) {
228
			config_set_path('ntpd/serverauth', $_POST['serverauth']);
229
			config_set_path('ntpd/serverauthkey', base64_encode(trim($_POST['serverauthkey'])));
230
			config_set_path('ntpd/serverauthkeyid', $_POST['serverauthkeyid']);
231
			config_set_path('ntpd/serverauthalgo', $_POST['serverauthalgo']);
232
		} elseif (config_path_enabled('ntpd', 'serverauth')) {
233
			config_del_path('ntpd/serverauth');
234
			config_del_path('ntpd/serverauthkey');
235
			config_del_path('ntpd/serverauthkeyid');
236
			config_del_path('ntpd/serverauthalgo');
237
		}
238

    
239
		write_config("Updated NTP Server Settings");
240

    
241
		$changes_applied = true;
242
		$retval = 0;
243
		$retval |= system_ntp_configure();
244
	}
245
}
246

    
247
function build_interface_list() {
248
	global $pconfig;
249

    
250
	$iflist = array('options' => array(), 'selected' => array());
251

    
252
	$interfaces = get_configured_interface_with_descr();
253
	$interfaces['lo0'] = "Localhost";
254

    
255
	foreach ($interfaces as $iface => $ifacename) {
256
		if (!is_ipaddr(get_interface_ip($iface)) &&
257
		    !is_ipaddrv6(get_interface_ipv6($iface))) {
258
			continue;
259
		}
260

    
261
		$iflist['options'][$iface] = $ifacename;
262

    
263
		if (in_array($iface, $pconfig['interface'])) {
264
			array_push($iflist['selected'], $iface);
265
		}
266
	}
267

    
268
	return($iflist);
269
}
270

    
271
$pconfig = config_get_path('ntpd');
272
$pconfig['enable'] = ($pconfig['enable'] != 'disabled') ? 'enabled' : 'disabled';
273
if (empty($pconfig['interface'])) {
274
	$pconfig['interface'] = array();
275
} else {
276
	$pconfig['interface'] = explode(",", $pconfig['interface']);
277
}
278
config_set_path('ntpd', $pconfig);
279
$pgtitle = array(gettext("Services"), gettext("NTP"), gettext("Settings"));
280
$pglinks = array("", "@self", "@self");
281
$shortcut_section = "ntp";
282
include("head.inc");
283

    
284
if ($input_errors) {
285
	print_input_errors($input_errors);
286
}
287

    
288
if ($changes_applied) {
289
	print_apply_result_box($retval);
290
}
291

    
292
$tab_array = array();
293
$tab_array[] = array(gettext("Settings"), true, "services_ntpd.php");
294
$tab_array[] = array(gettext("ACLs"), false, "services_ntpd_acls.php");
295
$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
296
$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
297
display_top_tabs($tab_array);
298

    
299
$form = new Form;
300
$form->setMultipartEncoding();	// Allow file uploads
301

    
302
$section = new Form_Section('NTP Server Configuration');
303

    
304
$section->addInput(new Form_Checkbox(
305
	'enable',
306
	'Enable',
307
	'Enable NTP Server',
308
	($pconfig['enable'] == 'enabled')
309
))->setHelp('You may need to disable NTP if %1$s is running in a virtual machine and the host is responsible for the clock.', g_get('product_label'));
310

    
311
$iflist = build_interface_list();
312

    
313
$section->addInput(new Form_Select(
314
	'interface',
315
	'Interface',
316
	$iflist['selected'],
317
	$iflist['options'],
318
	true
319
))->setHelp('Interfaces without an IP address will not be shown.%1$s' .
320
			'Selecting no interfaces will listen on all interfaces with a wildcard.%1$s' .
321
			'Selecting all interfaces will explicitly listen on only the interfaces/IPs specified.', '<br />');
322

    
323
$timeservers = explode(' ', config_get_path('system/timeservers'));
324
$maxrows = max(count($timeservers), 1);
325
for ($counter=0; $counter < $maxrows; $counter++) {
326
	$group = new Form_Group($counter == 0 ? 'Time Servers':'');
327
	$group->addClass('repeatable');
328
	$group->setAttribute('max_repeats', NUMTIMESERVERS);
329
	$group->setAttribute('max_repeats_alert', sprintf(gettext('%d is the maximum number of configured servers.'), NUMTIMESERVERS));
330

    
331
	$group->add(new Form_Input(
332
		'server' . $counter,
333
		null,
334
		'text',
335
		$timeservers[$counter],
336
		['placeholder' => 'Hostname']
337
	 ))->setWidth(3);
338

    
339
	 $group->add(new Form_Checkbox(
340
		'servprefer' . $counter,
341
		null,
342
		null,
343
		config_path_enabled('ntpd', 'prefer') && isset($timeservers[$counter]) && substr_count(config_get_path('ntpd/prefer'), $timeservers[$counter])
344
	 ))->sethelp('Prefer');
345

    
346
	 $group->add(new Form_Checkbox(
347
		'servselect' . $counter,
348
		null,
349
		null,
350
		config_path_enabled('ntpd', 'noselect') && isset($timeservers[$counter]) && substr_count(config_get_path('ntpd/noselect'), $timeservers[$counter])
351
	 ))->sethelp('No Select');
352

    
353
	 $group->add(new Form_Checkbox(
354
		'servauth' . $counter,
355
		null,
356
		null,
357
		config_path_enabled('ntpd', 'isauth') && isset($timeservers[$counter]) && substr_count(config_get_path('ntpd/isauth', ''), $timeservers[$counter])
358
	 ))->setHelp('Authenticated');
359

    
360
	if ((substr_compare($timeservers[$counter], $auto_pool_suffix, strlen($timeservers[$counter]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0) ||
361
	    ((config_get_path('ntpd/ispool') !== null) && isset($timeservers[$counter]) &&
362
	    substr_count(config_get_path('ntpd/ispool'), $timeservers[$counter]))) {
363
		$servertype = 'pool';
364
	} elseif ((config_get_path('ntpd/ispeer') !== null) && isset($timeservers[$counter]) && substr_count(config_get_path('ntpd/ispeer'), $timeservers[$counter])) {
365
		$servertype = 'peer';
366
	} else {
367
		$servertype = 'server';
368
	}
369

    
370
	$group->add(new Form_Select(
371
		'servistype' . $counter,
372
		null,
373
		$servertype,
374
		$ntp_server_types
375
	 ))->sethelp('Type')->setWidth(2);
376

    
377
	$group->add(new Form_Button(
378
		'deleterow' . $counter,
379
		'Delete',
380
		null,
381
		'fa-solid fa-trash-can'
382
	))->addClass('btn-warning');
383

    
384
	 $section->add($group);
385
}
386

    
387
$section->addInput(new Form_Button(
388
	'addrow',
389
	'Add',
390
	null,
391
	'fa-solid fa-plus'
392
))->addClass('btn-success');
393

    
394
$section->addInput(new Form_StaticText(
395
	null,
396
	$btnaddrow
397
))->setHelp(
398
	'NTP will only sync if a majority of the servers agree on the time.  For best results you should configure between 3 and 5 servers ' .
399
	'(%4$sNTP support pages recommend at least 4 or 5%5$s), or a pool. If only one server is configured, it %2$swill%3$s be believed, and if 2 servers ' .
400
	'are configured and they disagree, %2$sneither%3$s will be believed. Options:%1$s' .
401
	'%2$sPrefer%3$s - NTP should favor the use of this server more than all others.%1$s' .
402
	'%2$sNo Select%3$s - NTP should not use this server for time, but stats for this server will be collected and displayed.%1$s' .
403
	'%2$sType%3$s - Server, Peer or a Pool of NTP servers and not a single address. This is assumed for *.pool.ntp.org.',
404
	'<br />',
405
	'<b>',
406
	'</b>',
407
	'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
408
	'</a>'
409
	);
410

    
411
$section->addInput(new Form_Input(
412
	'ntpmaxpeers',
413
	'Max candidate pool peers',
414
	'number',
415
	$pconfig['ntpmaxpeers'],
416
	['min' => $min_candidate_peers, 'max' => $max_candidate_peers]
417
))->setHelp('Maximum number of candidate peers in the NTP pool. This value should be set low enough to provide sufficient alternate sources ' .
418
	    'while not contacting an excessively large number of peers. ' .
419
	    'Many servers inside public pools are provided by volunteers, ' .
420
	    'and a large candidate pool places unnecessary extra load ' .
421
	    'on the volunteer time servers for little to no added benefit. (Default: 5).');
422

    
423
$section->addInput(new Form_Input(
424
	'ntporphan',
425
	'Orphan Mode',
426
	'text',
427
	$pconfig['orphan'],
428
	['placeholder' => "12"]
429
))->setHelp('Orphan mode allows the system clock to be used when no other clocks are available. ' .
430
			'The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough ' .
431
			'to insure that any other servers available to clients are preferred over this server (default: 12).');
432

    
433
$section->addInput(new Form_Select(
434
	'ntpminpoll',
435
	'Minimum Poll Interval',
436
	$pconfig['ntpminpoll'],
437
	$ntp_poll_values
438
))->setHelp('Minimum poll interval for NTP messages. If set, must be less than or equal to Maximum Poll Interval.');
439

    
440
$section->addInput(new Form_Select(
441
	'ntpmaxpoll',
442
	'Maximum Poll Interval',
443
	$pconfig['ntpmaxpoll'],
444
	$ntp_poll_values
445
))->setHelp('Maximum poll interval for NTP messages. If set, must be greater than or equal to Minimum Poll Interval.');
446

    
447
$section->addInput(new Form_Checkbox(
448
	'statsgraph',
449
	'NTP Graphs',
450
	'Enable RRD graphs of NTP statistics (default: disabled).',
451
	$pconfig['statsgraph']
452
));
453

    
454
$section->addInput(new Form_Checkbox(
455
	'logpeer',
456
	'Logging',
457
	'Log peer messages (default: disabled).',
458
	$pconfig['logpeer']
459
));
460

    
461
$section->addInput(new Form_Checkbox(
462
	'logsys',
463
	null,
464
	'Log system messages (default: disabled).',
465
	$pconfig['logsys']
466
))->setHelp('These options enable additional messages from NTP to be written to the System Log %1$sStatus > System Logs > NTP%2$s',
467
			'<a href="status_logs.php?logfile=ntpd">', '</a>.');
468

    
469
// Statistics logging section
470
$btnadv = new Form_Button(
471
	'btnadvstats',
472
	gettext('Display Advanced'),
473
	null,
474
	'fa-solid fa-cog'
475
);
476

    
477
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
478

    
479
$section->addInput(new Form_StaticText(
480
	'Statistics Logging',
481
	$btnadv
482
))->setHelp('Warning: These options will create persistent daily log files in /var/log/ntp.');
483

    
484
$section->addInput(new Form_Checkbox(
485
	'clockstats',
486
	null,
487
	'Log reference clock statistics (default: disabled).',
488
	$pconfig['clockstats']
489
));
490

    
491
$section->addInput(new Form_Checkbox(
492
	'loopstats',
493
	null,
494
	'Log clock discipline statistics (default: disabled).',
495
	$pconfig['loopstats']
496
));
497

    
498
$section->addInput(new Form_Checkbox(
499
	'peerstats',
500
	null,
501
	'Log NTP peer statistics (default: disabled).',
502
	$pconfig['peerstats']
503
));
504

    
505
// Leap seconds section
506
$btnadv = new Form_Button(
507
	'btnadvleap',
508
	gettext('Display Advanced'),
509
	null,
510
	'fa-solid fa-cog'
511
);
512

    
513
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
514

    
515
$section->addInput(new Form_StaticText(
516
	'Leap seconds',
517
	$btnadv
518
))->setHelp(
519
	'Leap seconds may be added or subtracted at the end of June or December. Leap seconds are administered by the ' .
520
	'%1$sIERS%2$s, who publish them in their Bulletin C approximately 6 - 12 months in advance.  Normally this correction ' .
521
	'should only be needed if the server is a stratum 1 NTP server, but many NTP servers do not advertise an upcoming leap ' .
522
	'second when other NTP servers synchronise to them.%3$s%4$sIf the leap second is important to your network services, ' .
523
	'it is %6$sgood practice%2$s to download and add the leap second file at least a day in advance of any time correction%5$s.%3$s ' .
524
	'More information and files for downloading can be found on their %1$swebsite%2$s, and also on the %7$sNIST%2$s and %8$sNTP%2$s websites.',
525
	'<a target="_blank" href="https://www.iers.org">',
526
	'</a>',
527
	'<br />',
528
	'<b>',
529
	'</b>',
530
	'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
531
	'<a target="_blank" href="https://www.nist.gov">',
532
	'<a target="_blank" href="https://www.ntp.org">'
533
);
534

    
535
$section->addInput(new Form_Textarea(
536
	'leaptext',
537
	null,
538
	base64_decode(chunk_split($pconfig['leapsec']))
539
))->setHelp('Enter Leap second configuration as text OR select a file to upload.');
540

    
541
$section->addInput(new Form_Input(
542
	'leapfile',
543
	null,
544
	'file'
545
))->addClass('btn-default');
546

    
547
$section->addInput(new Form_Select(
548
	'dnsresolv',
549
	'DNS Resolution',
550
	$pconfig['dnsresolv'],
551
	array(
552
		'auto' => 'Auto',
553
		'inet' => 'IPv4',
554
		'inet6' => 'IPv6',
555
	)
556
))->setHelp('Force NTP peers DNS resolution IP protocol. Do not affect pools.');
557

    
558
$section->addInput(new Form_Checkbox(
559
	'serverauth',
560
	'Enable NTP Server Authentication',
561
	'Enable NTPv3 authentication (RFC 1305)',
562
	$pconfig['serverauth']
563
))->setHelp('Authentication allows the NTP client to confirm it is communicating with the intended server, ' .
564
	    'which protects against man-in-the-middle attacks.');
565

    
566
$group = new Form_Group('Authentication key');
567
$group->addClass('ntpserverauth');
568

    
569
$group->add(new Form_Input(
570
	'serverauthkeyid',
571
	'Key ID',
572
	null,
573
	$pconfig['serverauthkeyid'],
574
	['placeholder' => 'Key ID', 'type' => 'number', 'min' => 1, 'max' => 65535, 'step' => 1]
575
))->setWidth(2)->setHelp('ID associated with the authentication key');
576

    
577
$group->add(new Form_Input(
578
	'serverauthkey',
579
	'NTP Authentication key',
580
	'text',
581
	base64_decode($pconfig['serverauthkey']),
582
	['placeholder' => 'NTP Authentication key']
583
))->setHelp(
584
	'Key format: %1$s MD5 - The key is 1 to 20 printable characters %1$s' .
585
	'SHA1 - The key is a hex-encoded ASCII string of 40 characters %1$s' .
586
	'SHA256 - The key is a hex-encoded ASCII string of 64 characters',
587
	'<br />'
588
);
589

    
590
$group->add(new Form_Select(
591
	'serverauthalgo',
592
	null,
593
	$pconfig['serverauthalgo'],
594
	$ntp_auth_halgos
595
))->setWidth(2)->setHelp('Digest algorithm');
596

    
597
$section->add($group);
598

    
599
$form->add($section);
600

    
601
print($form);
602

    
603
?>
604

    
605
<script type="text/javascript">
606
//<![CDATA[
607
	// If this variable is declared, any help text will not be deleted when rows are added
608
	// IOW the help text will appear on every row
609
	retainhelp = true;
610
</script>
611

    
612
<script type="text/javascript">
613
//<![CDATA[
614
events.push(function() {
615

    
616
	// Show advanced stats options ============================================
617
	var showadvstats = false;
618

    
619
	function show_advstats(ispageload) {
620
		var text;
621
		// On page load decide the initial state based on the data.
622
		if (ispageload) {
623
<?php
624
			if (!$pconfig['clockstats'] && !$pconfig['loopstats'] && !$pconfig['peerstats']) {
625
				$showadv = false;
626
			} else {
627
				$showadv = true;
628
			}
629
?>
630
			showadvstats = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
631
		} else {
632
			// It was a click, swap the state.
633
			showadvstats = !showadvstats;
634
		}
635

    
636
		hideCheckbox('clockstats', !showadvstats);
637
		hideCheckbox('loopstats', !showadvstats);
638
		hideCheckbox('peerstats', !showadvstats);
639

    
640
		if (showadvstats) {
641
			text = "<?=gettext('Hide Advanced');?>";
642
		} else {
643
			text = "<?=gettext('Display Advanced');?>";
644
		}
645
		var children = $('#btnadvstats').children();
646
		$('#btnadvstats').text(text).prepend(children);
647
	}
648

    
649
	$('#btnadvstats').click(function(event) {
650
		show_advstats();
651
	});
652

    
653
	// Show advanced leap second options ======================================
654
	var showadvleap = false;
655

    
656
	function show_advleap(ispageload) {
657
		var text;
658
		// On page load decide the initial state based on the data.
659
		if (ispageload) {
660
<?php
661
			// Note: leapfile is not a field saved in the config, so no need to test for it here.
662
			// leapsec is the encoded text in the config, leaptext is not a pconfig[] key.
663
			if (empty($pconfig['leapsec'])) {
664
				$showadv = false;
665
			} else {
666
				$showadv = true;
667
			}
668
?>
669
			showadvleap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
670
		} else {
671
			// It was a click, swap the state.
672
			showadvleap = !showadvleap;
673
		}
674

    
675
		hideInput('leaptext', !showadvleap);
676
		hideInput('leapfile', !showadvleap);
677

    
678
		if (showadvleap) {
679
			text = "<?=gettext('Hide Advanced');?>";
680
		} else {
681
			text = "<?=gettext('Display Advanced');?>";
682
		}
683
		var children = $('#btnadvleap').children();
684
		$('#btnadvleap').text(text).prepend(children);
685
	}
686

    
687
	function change_serverauth() {
688
		hideClass('ntpserverauth', !($('#serverauth').prop('checked')));
689
	}
690

    
691
	$('#btnadvleap').click(function(event) {
692
		show_advleap();
693
	});
694

    
695
	$('#serverauth').change(function () {
696
		change_serverauth();
697
	});
698

    
699
	// Set initial states
700
	show_advstats(true);
701
	show_advleap(true);
702
	change_serverauth();
703

    
704
	// Suppress "Delete row" button if there are fewer than two rows
705
	checkLastRow();
706
});
707
//]]>
708
</script>
709

    
710
<?php include("foot.inc");
(135-135/232)