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($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
		}
108
	}
109

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
250
	return($iflist);
251
}
252

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

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

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

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

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

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

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

    
293
$iflist = build_interface_list();
294

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
557
print($form);
558

    
559
?>
560

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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