Project

General

Profile

Download (21.3 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(base64_decode($pconfig['serverauthkey'])) > 16)) {
102
			$input_errors[] = gettext("The supplied value for NTP Authentication key for MD5 digest must be from 1 to 16 printable characters.");
103
		} elseif (($pconfig['serverauthalgo'] == 'sha1') && ((strlen(base64_decode($pconfig['serverauthkey'])) != 40) ||
104
		    !ctype_xdigit($pconfig['serverauthkey']))) {
105
			$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA1 digest must be hex-encoded string of 40 characters.");
106
		}
107
	}
108

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

    
117
		if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport'])) {
118
			$config['ntpd']['gpsport'] = $_POST['gpsport'];
119
		} elseif (isset($config['ntpd']['gpsport'])) {
120
			unset($config['ntpd']['gpsport']);
121
		}
122

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

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

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

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

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

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

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

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

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

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

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

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

    
220
		write_config("Updated NTP Server Settings");
221

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

    
228
function build_interface_list() {
229
	global $pconfig;
230

    
231
	$iflist = array('options' => array(), 'selected' => array());
232

    
233
	$interfaces = get_configured_interface_with_descr();
234
	$interfaces['lo0'] = "Localhost";
235

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

    
242
		$iflist['options'][$iface] = $ifacename;
243

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

    
249
	return($iflist);
250
}
251

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

    
265
if ($input_errors) {
266
	print_input_errors($input_errors);
267
}
268

    
269
if ($changes_applied) {
270
	print_apply_result_box($retval);
271
}
272

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

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

    
283
$section = new Form_Section('NTP Server Configuration');
284

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

    
292
$iflist = build_interface_list();
293

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

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

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

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

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

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

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

    
349
	 $section->add($group);
350
}
351

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
556
print($form);
557

    
558
?>
559

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
663
<?php include("foot.inc");
(131-131/229)