Project

General

Profile

Download (21.4 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-2021 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;
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
if (!is_array($config['ntpd'])) {
44
	$config['ntpd'] = array();
45
}
46

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

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

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

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

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

    
81
	for ($i = 0; $i < NUMTIMESERVERS; $i++) {
82
		if (isset($pconfig["servselect{$i}"]) && (isset($pconfig["servispool{$i}"]) || 
83
		    (substr_compare($pconfig["server{$i}"], $auto_pool_suffix, strlen($pconfig["server{$i}"]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0))) {
84
			$input_errors[] = gettext("It is not possible to use 'No Select' for pools.");
85
		}
86
		if (!empty($pconfig["server{$i}"]) && !is_domain($pconfig["server{$i}"]) &&
87
		    !is_ipaddr($pconfig["server{$i}"])) {
88
			$input_errors[] = gettext("NTP Time Server names must be valid domain names, IPv4 addresses, or IPv6 addresses");
89
		}
90
	}
91

    
92
	if (is_numericint($pconfig['ntpminpoll']) &&
93
	    is_numericint($pconfig['ntpmaxpoll']) &&
94
	    ($pconfig['ntpmaxpoll'] < $pconfig['ntpminpoll'])) {
95
		$input_errors[] = gettext("The supplied value for Minimum Poll Interval is higher than NTP Maximum Poll Interval.");
96
	}
97

    
98
	if (isset($pconfig['serverauth'])) {
99
		if (empty($pconfig['serverauthkey'])) {
100
			$input_errors[] = gettext("The supplied value for NTP Authentication key can't be empty.");
101
		} elseif (($pconfig['serverauthalgo'] == 'md5') && ((strlen($pconfig['serverauthkey']) > 20) ||
102
		    !ctype_print($pconfig['serverauthkey']))) {
103
			$input_errors[] = gettext("The supplied value for NTP Authentication key for MD5 digest must be from 1 to 20 printable characters.");
104
		} elseif (($pconfig['serverauthalgo'] == 'sha1') && ((strlen($pconfig['serverauthkey']) != 40) ||
105
		    !ctype_xdigit($pconfig['serverauthkey']))) {
106
			$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA1 digest must be hex-encoded string of 40 characters.");
107
		} elseif (($pconfig['serverauthalgo'] == 'sha256') && ((strlen($pconfig['serverauthkey']) != 64) ||
108
		    !ctype_xdigit($pconfig['serverauthkey']))) {
109
			$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA256 digest must be hex-encoded string of 64 characters.");
110
		}
111
	}
112

    
113
	if (!$input_errors) {
114
		$config['ntpd']['enable'] = isset($_POST['enable']) ? 'enabled' : 'disabled';
115
		if (is_array($_POST['interface'])) {
116
			$config['ntpd']['interface'] = implode(",", $_POST['interface']);
117
		} elseif (isset($config['ntpd']['interface'])) {
118
			unset($config['ntpd']['interface']);
119
		}
120

    
121
		unset($config['ntpd']['prefer']);
122
		unset($config['ntpd']['noselect']);
123
		unset($config['ntpd']['ispool']);
124
		$timeservers = '';
125

    
126
		for ($i = 0; $i < NUMTIMESERVERS; $i++) {
127
			$tserver = trim($_POST["server{$i}"]);
128
			if (!empty($tserver)) {
129
				$timeservers .= "{$tserver} ";
130
				if (isset($_POST["servprefer{$i}"])) {
131
					$config['ntpd']['prefer'] .= "{$tserver} ";
132
				}
133
				if (isset($_POST["servselect{$i}"])) {
134
					$config['ntpd']['noselect'] .= "{$tserver} ";
135
				}
136
				if (isset($_POST["servispool{$i}"])) {
137
					$config['ntpd']['ispool'] .= "{$tserver} ";
138
				}
139
			}
140
		}
141
		if (trim($timeservers) == "") {
142
			$timeservers = "pool.ntp.org";
143
		}
144
		$config['system']['timeservers'] = trim($timeservers);
145

    
146
		if (!empty($pconfig['ntpmaxpeers'])) {
147
			$config['ntpd']['ntpmaxpeers'] = $pconfig['ntpmaxpeers'];
148
		} else {
149
			unset($config['ntpd']['ntpmaxpeers']);
150
		}
151
		$config['ntpd']['orphan'] = trim($pconfig['ntporphan']);
152
		$config['ntpd']['ntpminpoll'] = $pconfig['ntpminpoll'];
153
		$config['ntpd']['ntpmaxpoll'] = $pconfig['ntpmaxpoll'];
154
		$config['ntpd']['dnsresolv'] = $pconfig['dnsresolv'];
155

    
156
		if (!empty($_POST['logpeer'])) {
157
			$config['ntpd']['logpeer'] = $_POST['logpeer'];
158
		} elseif (isset($config['ntpd']['logpeer'])) {
159
			unset($config['ntpd']['logpeer']);
160
		}
161

    
162
		if (!empty($_POST['logsys'])) {
163
			$config['ntpd']['logsys'] = $_POST['logsys'];
164
		} elseif (isset($config['ntpd']['logsys'])) {
165
			unset($config['ntpd']['logsys']);
166
		}
167

    
168
		if (!empty($_POST['clockstats'])) {
169
			$config['ntpd']['clockstats'] = $_POST['clockstats'];
170
		} elseif (isset($config['ntpd']['clockstats'])) {
171
			unset($config['ntpd']['clockstats']);
172
		}
173

    
174
		if (!empty($_POST['loopstats'])) {
175
			$config['ntpd']['loopstats'] = $_POST['loopstats'];
176
		} elseif (isset($config['ntpd']['loopstats'])) {
177
			unset($config['ntpd']['loopstats']);
178
		}
179

    
180
		if (!empty($_POST['peerstats'])) {
181
			$config['ntpd']['peerstats'] = $_POST['peerstats'];
182
		} elseif (isset($config['ntpd']['peerstats'])) {
183
			unset($config['ntpd']['peerstats']);
184
		}
185

    
186
		if ((empty($_POST['statsgraph'])) == (isset($config['ntpd']['statsgraph']))) {
187
			$enable_rrd_graphing = true;
188
		}
189
		if (!empty($_POST['statsgraph'])) {
190
			$config['ntpd']['statsgraph'] = $_POST['statsgraph'];
191
		} elseif (isset($config['ntpd']['statsgraph'])) {
192
			unset($config['ntpd']['statsgraph']);
193
		}
194
		if (isset($enable_rrd_graphing)) {
195
			enable_rrd_graphing();
196
		}
197

    
198
		if (!empty($_POST['leaptext'])) {
199
			$config['ntpd']['leapsec'] = base64_encode($_POST['leaptext']);
200
		} elseif (isset($config['ntpd']['leapsec'])) {
201
			unset($config['ntpd']['leapsec']);
202
		}
203

    
204
		if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) {
205
			$config['ntpd']['leapsec'] = base64_encode(file_get_contents($_FILES['leapfile']['tmp_name']));
206
		}
207

    
208
		if (!empty($_POST['serverauth'])) {
209
			$config['ntpd']['serverauth'] = $_POST['serverauth'];
210
			$config['ntpd']['serverauthkey'] = base64_encode(trim($_POST['serverauthkey']));
211
			$config['ntpd']['serverauthalgo'] = $_POST['serverauthalgo'];
212
		} elseif (isset($config['ntpd']['serverauth'])) {
213
			unset($config['ntpd']['serverauth']);
214
			unset($config['ntpd']['serverauthkey']);
215
			unset($config['ntpd']['serverauthalgo']);
216
		}
217

    
218
		write_config("Updated NTP Server Settings");
219

    
220
		$changes_applied = true;
221
		$retval = 0;
222
		$retval |= system_ntp_configure();
223
	}
224
}
225

    
226
function build_interface_list() {
227
	global $pconfig;
228

    
229
	$iflist = array('options' => array(), 'selected' => array());
230

    
231
	$interfaces = get_configured_interface_with_descr();
232
	$interfaces['lo0'] = "Localhost";
233

    
234
	foreach ($interfaces as $iface => $ifacename) {
235
		if (!is_ipaddr(get_interface_ip($iface)) &&
236
		    !is_ipaddrv6(get_interface_ipv6($iface))) {
237
			continue;
238
		}
239

    
240
		$iflist['options'][$iface] = $ifacename;
241

    
242
		if (in_array($iface, $pconfig['interface'])) {
243
			array_push($iflist['selected'], $iface);
244
		}
245
	}
246

    
247
	return($iflist);
248
}
249

    
250
init_config_arr(array('ntpd'));
251
$pconfig = &$config['ntpd'];
252
$pconfig['enable'] = ($config['ntpd']['enable'] != 'disabled') ? 'enabled' : 'disabled';
253
if (empty($pconfig['interface'])) {
254
	$pconfig['interface'] = array();
255
} else {
256
	$pconfig['interface'] = explode(",", $pconfig['interface']);
257
}
258
$pgtitle = array(gettext("Services"), gettext("NTP"), gettext("Settings"));
259
$pglinks = array("", "@self", "@self");
260
$shortcut_section = "ntp";
261
include("head.inc");
262

    
263
if ($input_errors) {
264
	print_input_errors($input_errors);
265
}
266

    
267
if ($changes_applied) {
268
	print_apply_result_box($retval);
269
}
270

    
271
$tab_array = array();
272
$tab_array[] = array(gettext("Settings"), true, "services_ntpd.php");
273
$tab_array[] = array(gettext("ACLs"), false, "services_ntpd_acls.php");
274
$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
275
$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
276
display_top_tabs($tab_array);
277

    
278
$form = new Form;
279
$form->setMultipartEncoding();	// Allow file uploads
280

    
281
$section = new Form_Section('NTP Server Configuration');
282

    
283
$section->addInput(new Form_Checkbox(
284
	'enable',
285
	'Enable',
286
	'Enable NTP Server',
287
	($pconfig['enable'] == 'enabled')
288
))->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['product_label']);
289

    
290
$iflist = build_interface_list();
291

    
292
$section->addInput(new Form_Select(
293
	'interface',
294
	'Interface',
295
	$iflist['selected'],
296
	$iflist['options'],
297
	true
298
))->setHelp('Interfaces without an IP address will not be shown.%1$s' .
299
			'Selecting no interfaces will listen on all interfaces with a wildcard.%1$s' .
300
			'Selecting all interfaces will explicitly listen on only the interfaces/IPs specified.', '<br />');
301

    
302
$timeservers = explode(' ', $config['system']['timeservers']);
303
$maxrows = max(count($timeservers), 1);
304
for ($counter=0; $counter < $maxrows; $counter++) {
305
	$group = new Form_Group($counter == 0 ? 'Time Servers':'');
306
	$group->addClass('repeatable');
307
	$group->setAttribute('max_repeats', NUMTIMESERVERS);
308
	$group->setAttribute('max_repeats_alert', sprintf(gettext('%d is the maximum number of configured servers.'), NUMTIMESERVERS));
309

    
310
	$group->add(new Form_Input(
311
		'server' . $counter,
312
		null,
313
		'text',
314
		$timeservers[$counter],
315
		['placeholder' => 'Hostname']
316
	 ))->setWidth(3);
317

    
318
	 $group->add(new Form_Checkbox(
319
		'servprefer' . $counter,
320
		null,
321
		null,
322
		isset($config['ntpd']['prefer']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['prefer'], $timeservers[$counter])
323
	 ))->sethelp('Prefer');
324

    
325
	 $group->add(new Form_Checkbox(
326
		'servselect' . $counter,
327
		null,
328
		null,
329
		isset($config['ntpd']['noselect']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['noselect'], $timeservers[$counter])
330
	 ))->sethelp('No Select');
331

    
332
	$group->add(new Form_Checkbox(
333
		'servispool' . $counter,
334
		null,
335
		null,
336
		(substr_compare($timeservers[$counter], $auto_pool_suffix, strlen($timeservers[$counter]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0)
337
		 || (isset($config['ntpd']['ispool']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['ispool'], $timeservers[$counter]))
338
	 ))->sethelp('Is a Pool');
339

    
340
	$group->add(new Form_Button(
341
		'deleterow' . $counter,
342
		'Delete',
343
		null,
344
		'fa-trash'
345
	))->addClass('btn-warning');
346

    
347
	 $section->add($group);
348
}
349

    
350
$section->addInput(new Form_Button(
351
	'addrow',
352
	'Add',
353
	null,
354
	'fa-plus'
355
))->addClass('btn-success');
356

    
357
$section->addInput(new Form_StaticText(
358
	null,
359
	$btnaddrow
360
))->setHelp(
361
	'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 ' .
362
	'(%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 ' .
363
	'are configured and they disagree, %2$sneither%3$s will be believed. Options:%1$s' .
364
	'%2$sPrefer%3$s - NTP should favor the use of this server more than all others.%1$s' .
365
	'%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' .
366
	'%2$sIs a Pool%3$s - this entry is a pool of NTP servers and not a single address. This is assumed for *.pool.ntp.org.',
367
	'<br />',
368
	'<b>',
369
	'</b>',
370
	'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
371
	'</a>'
372
	);
373

    
374
$section->addInput(new Form_Input(
375
	'ntpmaxpeers',
376
	'Max candidate pool peers',
377
	'number',
378
	$pconfig['ntpmaxpeers'],
379
	['min' => $min_candidate_peers, 'max' => $max_candidate_peers]
380
))->setHelp('Maximum number of candidate peers in the NTP pool. This value should be set low enough to provide sufficient alternate sources ' .
381
	    'while not contacting an excessively large number of peers. ' .
382
	    'Many servers inside public pools are provided by volunteers, ' .
383
	    'and a large candidate pool places unnecessary extra load ' .
384
	    'on the volunteer time servers for little to no added benefit. (Default: 5).');
385

    
386
$section->addInput(new Form_Input(
387
	'ntporphan',
388
	'Orphan Mode',
389
	'text',
390
	$pconfig['orphan'],
391
	['placeholder' => "12"]
392
))->setHelp('Orphan mode allows the system clock to be used when no other clocks are available. ' .
393
			'The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough ' .
394
			'to insure that any other servers available to clients are preferred over this server (default: 12).');
395

    
396
$section->addInput(new Form_Select(
397
	'ntpminpoll',
398
	'Minimum Poll Interval',
399
	$pconfig['ntpminpoll'],
400
	$ntp_poll_values
401
))->setHelp('Minimum poll interval for NTP messages. If set, must be less than or equal to Maximum Poll Interval.');
402

    
403
$section->addInput(new Form_Select(
404
	'ntpmaxpoll',
405
	'Maximum Poll Interval',
406
	$pconfig['ntpmaxpoll'],
407
	$ntp_poll_values
408
))->setHelp('Maximum poll interval for NTP messages. If set, must be greater than or equal to Minimum Poll Interval.');
409

    
410
$section->addInput(new Form_Checkbox(
411
	'statsgraph',
412
	'NTP Graphs',
413
	'Enable RRD graphs of NTP statistics (default: disabled).',
414
	$pconfig['statsgraph']
415
));
416

    
417
$section->addInput(new Form_Checkbox(
418
	'logpeer',
419
	'Logging',
420
	'Log peer messages (default: disabled).',
421
	$pconfig['logpeer']
422
));
423

    
424
$section->addInput(new Form_Checkbox(
425
	'logsys',
426
	null,
427
	'Log system messages (default: disabled).',
428
	$pconfig['logsys']
429
))->setHelp('These options enable additional messages from NTP to be written to the System Log %1$sStatus > System Logs > NTP%2$s',
430
			'<a href="status_logs.php?logfile=ntpd">', '</a>.');
431

    
432
// Statistics logging section
433
$btnadv = new Form_Button(
434
	'btnadvstats',
435
	'Display Advanced',
436
	null,
437
	'fa-cog'
438
);
439

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

    
442
$section->addInput(new Form_StaticText(
443
	'Statistics Logging',
444
	$btnadv
445
))->setHelp('Warning: These options will create persistent daily log files in /var/log/ntp.');
446

    
447
$section->addInput(new Form_Checkbox(
448
	'clockstats',
449
	null,
450
	'Log reference clock statistics (default: disabled).',
451
	$pconfig['clockstats']
452
));
453

    
454
$section->addInput(new Form_Checkbox(
455
	'loopstats',
456
	null,
457
	'Log clock discipline statistics (default: disabled).',
458
	$pconfig['loopstats']
459
));
460

    
461
$section->addInput(new Form_Checkbox(
462
	'peerstats',
463
	null,
464
	'Log NTP peer statistics (default: disabled).',
465
	$pconfig['peerstats']
466
));
467

    
468
// Leap seconds section
469
$btnadv = new Form_Button(
470
	'btnadvleap',
471
	'Display Advanced',
472
	null,
473
	'fa-cog'
474
);
475

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

    
478
$section->addInput(new Form_StaticText(
479
	'Leap seconds',
480
	$btnadv
481
))->setHelp(
482
	'Leap seconds may be added or subtracted at the end of June or December. Leap seconds are administered by the ' .
483
	'%1$sIERS%2$s, who publish them in their Bulletin C approximately 6 - 12 months in advance.  Normally this correction ' .
484
	'should only be needed if the server is a stratum 1 NTP server, but many NTP servers do not advertise an upcoming leap ' .
485
	'second when other NTP servers synchronise to them.%3$s%4$sIf the leap second is important to your network services, ' .
486
	'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 ' .
487
	'More information and files for downloading can be found on their %1$swebsite%2$s, and also on the %7$NIST%2$s and %8$sNTP%2$s websites.',
488
	'<a target="_blank" href="https://www.iers.org">',
489
	'</a>',
490
	'<br />',
491
	'<b>',
492
	'</b>',
493
	'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
494
	'<a target="_blank" href="https://www.nist.gov">',
495
	'<a target="_blank" href="https://www.ntp.org">'
496
);
497

    
498
$section->addInput(new Form_Textarea(
499
	'leaptext',
500
	null,
501
	base64_decode(chunk_split($pconfig['leapsec']))
502
))->setHelp('Enter Leap second configuration as text OR select a file to upload.');
503

    
504
$section->addInput(new Form_Input(
505
	'leapfile',
506
	null,
507
	'file'
508
))->addClass('btn-default');
509

    
510
$section->addInput(new Form_Select(
511
	'dnsresolv',
512
	'DNS Resolution',
513
	$pconfig['dnsresolv'],
514
	array(
515
		'auto' => 'Auto',
516
		'inet' => 'IPv4',
517
		'inet6' => 'IPv6',
518
	)
519
))->setHelp('Force NTP peers DNS resolution IP protocol. Do not affect pools.');
520

    
521
$section->addInput(new Form_Checkbox(
522
	'serverauth',
523
	'Enable NTP Server Authentication',
524
	'Enable NTPv3 authentication (RFC 1305)',
525
	$pconfig['serverauth']
526
))->setHelp('Authentication allows the NTP client to confirm it is communicating with the intended server, ' .
527
	    'which protects against man-in-the-middle attacks.');
528

    
529
$group = new Form_Group('Authentication key');
530
$group->addClass('ntpserverauth');
531

    
532
$group->add(new Form_IpAddress(
533
	'serverauthkey',
534
	'NTP Authentication key',
535
	base64_decode($pconfig['serverauthkey']),
536
	['placeholder' => 'NTP Authentication key']
537
))->setHelp(
538
	'Key format: %1$s MD5 - The key is 1 to 20 printable characters %1$s' .
539
	'SHA1 - The key is a hex-encoded ASCII string of 40 characters %1$s' .
540
	'SHA256 - The key is a hex-encoded ASCII string of 64 characters',
541
	'<br />'
542
);
543

    
544
$group->add(new Form_Select(
545
	'serverauthalgo',
546
	null,
547
	$pconfig['serverauthalgo'],
548
	$ntp_auth_halgos
549
))->setWidth(3)->setHelp('Digest algorithm');
550

    
551
$section->add($group);
552

    
553
$form->add($section);
554

    
555
print($form);
556

    
557
?>
558

    
559
<script type="text/javascript">
560
//<![CDATA[
561
	// If this variable is declared, any help text will not be deleted when rows are added
562
	// IOW the help text will appear on every row
563
	retainhelp = true;
564
</script>
565

    
566
<script type="text/javascript">
567
//<![CDATA[
568
events.push(function() {
569

    
570
	// Show advanced stats options ============================================
571
	var showadvstats = false;
572

    
573
	function show_advstats(ispageload) {
574
		var text;
575
		// On page load decide the initial state based on the data.
576
		if (ispageload) {
577
<?php
578
			if (!$pconfig['clockstats'] && !$pconfig['loopstats'] && !$pconfig['peerstats']) {
579
				$showadv = false;
580
			} else {
581
				$showadv = true;
582
			}
583
?>
584
			showadvstats = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
585
		} else {
586
			// It was a click, swap the state.
587
			showadvstats = !showadvstats;
588
		}
589

    
590
		hideCheckbox('clockstats', !showadvstats);
591
		hideCheckbox('loopstats', !showadvstats);
592
		hideCheckbox('peerstats', !showadvstats);
593

    
594
		if (showadvstats) {
595
			text = "<?=gettext('Hide Advanced');?>";
596
		} else {
597
			text = "<?=gettext('Display Advanced');?>";
598
		}
599
		$('#btnadvstats').html('<i class="fa fa-cog"></i> ' + text);
600
	}
601

    
602
	$('#btnadvstats').click(function(event) {
603
		show_advstats();
604
	});
605

    
606
	// Show advanced leap second options ======================================
607
	var showadvleap = false;
608

    
609
	function show_advleap(ispageload) {
610
		var text;
611
		// On page load decide the initial state based on the data.
612
		if (ispageload) {
613
<?php
614
			// Note: leapfile is not a field saved in the config, so no need to test for it here.
615
			// leapsec is the encoded text in the config, leaptext is not a pconfig[] key.
616
			if (empty($pconfig['leapsec'])) {
617
				$showadv = false;
618
			} else {
619
				$showadv = true;
620
			}
621
?>
622
			showadvleap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
623
		} else {
624
			// It was a click, swap the state.
625
			showadvleap = !showadvleap;
626
		}
627

    
628
		hideInput('leaptext', !showadvleap);
629
		hideInput('leapfile', !showadvleap);
630

    
631
		if (showadvleap) {
632
			text = "<?=gettext('Hide Advanced');?>";
633
		} else {
634
			text = "<?=gettext('Display Advanced');?>";
635
		}
636
		$('#btnadvleap').html('<i class="fa fa-cog"></i> ' + text);
637
	}
638

    
639
	function change_serverauth() {
640
		hideClass('ntpserverauth', !($('#serverauth').prop('checked')));
641
	}
642

    
643
	$('#btnadvleap').click(function(event) {
644
		show_advleap();
645
	});
646

    
647
	$('#serverauth').change(function () {
648
		change_serverauth();
649
	});
650

    
651
	// Set initial states
652
	show_advstats(true);
653
	show_advleap(true);
654
	change_serverauth();
655

    
656
	// Suppress "Delete row" button if there are fewer than two rows
657
	checkLastRow();
658
});
659
//]]>
660
</script>
661

    
662
<?php include("foot.inc");
(131-131/227)