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, $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
|
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}"]) && (($pconfig["servistype{$i}"] == 'pool') ||
|
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
|
unset($config['ntpd']['ispeer']);
|
125
|
$timeservers = '';
|
126
|
|
127
|
for ($i = 0; $i < NUMTIMESERVERS; $i++) {
|
128
|
$tserver = trim($_POST["server{$i}"]);
|
129
|
if (!empty($tserver)) {
|
130
|
$timeservers .= "{$tserver} ";
|
131
|
if (isset($_POST["servprefer{$i}"])) {
|
132
|
$config['ntpd']['prefer'] .= "{$tserver} ";
|
133
|
}
|
134
|
if (isset($_POST["servselect{$i}"])) {
|
135
|
$config['ntpd']['noselect'] .= "{$tserver} ";
|
136
|
}
|
137
|
if ($_POST["servistype{$i}"] == 'pool') {
|
138
|
$config['ntpd']['ispool'] .= "{$tserver} ";
|
139
|
} elseif ($_POST["servistype{$i}"] == 'peer') {
|
140
|
$config['ntpd']['ispeer'] .= "{$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
|
if ((substr_compare($timeservers[$counter], $auto_pool_suffix, strlen($timeservers[$counter]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0) || (isset($config['ntpd']['ispool']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['ispool'], $timeservers[$counter]))) {
|
336
|
$servertype = 'pool';
|
337
|
} elseif (isset($config['ntpd']['ispeer']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['ispeer'], $timeservers[$counter])) {
|
338
|
$servertype = 'peer';
|
339
|
} else {
|
340
|
$servertype = 'server';
|
341
|
}
|
342
|
|
343
|
$group->add(new Form_Select(
|
344
|
'servistype' . $counter,
|
345
|
null,
|
346
|
$servertype,
|
347
|
$ntp_server_types
|
348
|
))->sethelp('Type')->setWidth(2);
|
349
|
|
350
|
$group->add(new Form_Button(
|
351
|
'deleterow' . $counter,
|
352
|
'Delete',
|
353
|
null,
|
354
|
'fa-trash'
|
355
|
))->addClass('btn-warning');
|
356
|
|
357
|
$section->add($group);
|
358
|
}
|
359
|
|
360
|
$section->addInput(new Form_Button(
|
361
|
'addrow',
|
362
|
'Add',
|
363
|
null,
|
364
|
'fa-plus'
|
365
|
))->addClass('btn-success');
|
366
|
|
367
|
$section->addInput(new Form_StaticText(
|
368
|
null,
|
369
|
$btnaddrow
|
370
|
))->setHelp(
|
371
|
'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 ' .
|
372
|
'(%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 ' .
|
373
|
'are configured and they disagree, %2$sneither%3$s will be believed. Options:%1$s' .
|
374
|
'%2$sPrefer%3$s - NTP should favor the use of this server more than all others.%1$s' .
|
375
|
'%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' .
|
376
|
'%2$sType%3$s - Server, Peer or a Pool of NTP servers and not a single address. This is assumed for *.pool.ntp.org.',
|
377
|
'<br />',
|
378
|
'<b>',
|
379
|
'</b>',
|
380
|
'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
|
381
|
'</a>'
|
382
|
);
|
383
|
|
384
|
$section->addInput(new Form_Input(
|
385
|
'ntpmaxpeers',
|
386
|
'Max candidate pool peers',
|
387
|
'number',
|
388
|
$pconfig['ntpmaxpeers'],
|
389
|
['min' => $min_candidate_peers, 'max' => $max_candidate_peers]
|
390
|
))->setHelp('Maximum number of candidate peers in the NTP pool. This value should be set low enough to provide sufficient alternate sources ' .
|
391
|
'while not contacting an excessively large number of peers. ' .
|
392
|
'Many servers inside public pools are provided by volunteers, ' .
|
393
|
'and a large candidate pool places unnecessary extra load ' .
|
394
|
'on the volunteer time servers for little to no added benefit. (Default: 5).');
|
395
|
|
396
|
$section->addInput(new Form_Input(
|
397
|
'ntporphan',
|
398
|
'Orphan Mode',
|
399
|
'text',
|
400
|
$pconfig['orphan'],
|
401
|
['placeholder' => "12"]
|
402
|
))->setHelp('Orphan mode allows the system clock to be used when no other clocks are available. ' .
|
403
|
'The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough ' .
|
404
|
'to insure that any other servers available to clients are preferred over this server (default: 12).');
|
405
|
|
406
|
$section->addInput(new Form_Select(
|
407
|
'ntpminpoll',
|
408
|
'Minimum Poll Interval',
|
409
|
$pconfig['ntpminpoll'],
|
410
|
$ntp_poll_values
|
411
|
))->setHelp('Minimum poll interval for NTP messages. If set, must be less than or equal to Maximum Poll Interval.');
|
412
|
|
413
|
$section->addInput(new Form_Select(
|
414
|
'ntpmaxpoll',
|
415
|
'Maximum Poll Interval',
|
416
|
$pconfig['ntpmaxpoll'],
|
417
|
$ntp_poll_values
|
418
|
))->setHelp('Maximum poll interval for NTP messages. If set, must be greater than or equal to Minimum Poll Interval.');
|
419
|
|
420
|
$section->addInput(new Form_Checkbox(
|
421
|
'statsgraph',
|
422
|
'NTP Graphs',
|
423
|
'Enable RRD graphs of NTP statistics (default: disabled).',
|
424
|
$pconfig['statsgraph']
|
425
|
));
|
426
|
|
427
|
$section->addInput(new Form_Checkbox(
|
428
|
'logpeer',
|
429
|
'Logging',
|
430
|
'Log peer messages (default: disabled).',
|
431
|
$pconfig['logpeer']
|
432
|
));
|
433
|
|
434
|
$section->addInput(new Form_Checkbox(
|
435
|
'logsys',
|
436
|
null,
|
437
|
'Log system messages (default: disabled).',
|
438
|
$pconfig['logsys']
|
439
|
))->setHelp('These options enable additional messages from NTP to be written to the System Log %1$sStatus > System Logs > NTP%2$s',
|
440
|
'<a href="status_logs.php?logfile=ntpd">', '</a>.');
|
441
|
|
442
|
// Statistics logging section
|
443
|
$btnadv = new Form_Button(
|
444
|
'btnadvstats',
|
445
|
'Display Advanced',
|
446
|
null,
|
447
|
'fa-cog'
|
448
|
);
|
449
|
|
450
|
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
|
451
|
|
452
|
$section->addInput(new Form_StaticText(
|
453
|
'Statistics Logging',
|
454
|
$btnadv
|
455
|
))->setHelp('Warning: These options will create persistent daily log files in /var/log/ntp.');
|
456
|
|
457
|
$section->addInput(new Form_Checkbox(
|
458
|
'clockstats',
|
459
|
null,
|
460
|
'Log reference clock statistics (default: disabled).',
|
461
|
$pconfig['clockstats']
|
462
|
));
|
463
|
|
464
|
$section->addInput(new Form_Checkbox(
|
465
|
'loopstats',
|
466
|
null,
|
467
|
'Log clock discipline statistics (default: disabled).',
|
468
|
$pconfig['loopstats']
|
469
|
));
|
470
|
|
471
|
$section->addInput(new Form_Checkbox(
|
472
|
'peerstats',
|
473
|
null,
|
474
|
'Log NTP peer statistics (default: disabled).',
|
475
|
$pconfig['peerstats']
|
476
|
));
|
477
|
|
478
|
// Leap seconds section
|
479
|
$btnadv = new Form_Button(
|
480
|
'btnadvleap',
|
481
|
'Display Advanced',
|
482
|
null,
|
483
|
'fa-cog'
|
484
|
);
|
485
|
|
486
|
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
|
487
|
|
488
|
$section->addInput(new Form_StaticText(
|
489
|
'Leap seconds',
|
490
|
$btnadv
|
491
|
))->setHelp(
|
492
|
'Leap seconds may be added or subtracted at the end of June or December. Leap seconds are administered by the ' .
|
493
|
'%1$sIERS%2$s, who publish them in their Bulletin C approximately 6 - 12 months in advance. Normally this correction ' .
|
494
|
'should only be needed if the server is a stratum 1 NTP server, but many NTP servers do not advertise an upcoming leap ' .
|
495
|
'second when other NTP servers synchronise to them.%3$s%4$sIf the leap second is important to your network services, ' .
|
496
|
'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 ' .
|
497
|
'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.',
|
498
|
'<a target="_blank" href="https://www.iers.org">',
|
499
|
'</a>',
|
500
|
'<br />',
|
501
|
'<b>',
|
502
|
'</b>',
|
503
|
'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
|
504
|
'<a target="_blank" href="https://www.nist.gov">',
|
505
|
'<a target="_blank" href="https://www.ntp.org">'
|
506
|
);
|
507
|
|
508
|
$section->addInput(new Form_Textarea(
|
509
|
'leaptext',
|
510
|
null,
|
511
|
base64_decode(chunk_split($pconfig['leapsec']))
|
512
|
))->setHelp('Enter Leap second configuration as text OR select a file to upload.');
|
513
|
|
514
|
$section->addInput(new Form_Input(
|
515
|
'leapfile',
|
516
|
null,
|
517
|
'file'
|
518
|
))->addClass('btn-default');
|
519
|
|
520
|
$section->addInput(new Form_Select(
|
521
|
'dnsresolv',
|
522
|
'DNS Resolution',
|
523
|
$pconfig['dnsresolv'],
|
524
|
array(
|
525
|
'auto' => 'Auto',
|
526
|
'inet' => 'IPv4',
|
527
|
'inet6' => 'IPv6',
|
528
|
)
|
529
|
))->setHelp('Force NTP peers DNS resolution IP protocol. Do not affect pools.');
|
530
|
|
531
|
$section->addInput(new Form_Checkbox(
|
532
|
'serverauth',
|
533
|
'Enable NTP Server Authentication',
|
534
|
'Enable NTPv3 authentication (RFC 1305)',
|
535
|
$pconfig['serverauth']
|
536
|
))->setHelp('Authentication allows the NTP client to confirm it is communicating with the intended server, ' .
|
537
|
'which protects against man-in-the-middle attacks.');
|
538
|
|
539
|
$group = new Form_Group('Authentication key');
|
540
|
$group->addClass('ntpserverauth');
|
541
|
|
542
|
$group->add(new Form_IpAddress(
|
543
|
'serverauthkey',
|
544
|
'NTP Authentication key',
|
545
|
base64_decode($pconfig['serverauthkey']),
|
546
|
['placeholder' => 'NTP Authentication key']
|
547
|
))->setHelp(
|
548
|
'Key format: %1$s MD5 - The key is 1 to 20 printable characters %1$s' .
|
549
|
'SHA1 - The key is a hex-encoded ASCII string of 40 characters %1$s' .
|
550
|
'SHA256 - The key is a hex-encoded ASCII string of 64 characters',
|
551
|
'<br />'
|
552
|
);
|
553
|
|
554
|
$group->add(new Form_Select(
|
555
|
'serverauthalgo',
|
556
|
null,
|
557
|
$pconfig['serverauthalgo'],
|
558
|
$ntp_auth_halgos
|
559
|
))->setWidth(3)->setHelp('Digest algorithm');
|
560
|
|
561
|
$section->add($group);
|
562
|
|
563
|
$form->add($section);
|
564
|
|
565
|
print($form);
|
566
|
|
567
|
?>
|
568
|
|
569
|
<script type="text/javascript">
|
570
|
//<![CDATA[
|
571
|
// If this variable is declared, any help text will not be deleted when rows are added
|
572
|
// IOW the help text will appear on every row
|
573
|
retainhelp = true;
|
574
|
</script>
|
575
|
|
576
|
<script type="text/javascript">
|
577
|
//<![CDATA[
|
578
|
events.push(function() {
|
579
|
|
580
|
// Show advanced stats options ============================================
|
581
|
var showadvstats = false;
|
582
|
|
583
|
function show_advstats(ispageload) {
|
584
|
var text;
|
585
|
// On page load decide the initial state based on the data.
|
586
|
if (ispageload) {
|
587
|
<?php
|
588
|
if (!$pconfig['clockstats'] && !$pconfig['loopstats'] && !$pconfig['peerstats']) {
|
589
|
$showadv = false;
|
590
|
} else {
|
591
|
$showadv = true;
|
592
|
}
|
593
|
?>
|
594
|
showadvstats = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
|
595
|
} else {
|
596
|
// It was a click, swap the state.
|
597
|
showadvstats = !showadvstats;
|
598
|
}
|
599
|
|
600
|
hideCheckbox('clockstats', !showadvstats);
|
601
|
hideCheckbox('loopstats', !showadvstats);
|
602
|
hideCheckbox('peerstats', !showadvstats);
|
603
|
|
604
|
if (showadvstats) {
|
605
|
text = "<?=gettext('Hide Advanced');?>";
|
606
|
} else {
|
607
|
text = "<?=gettext('Display Advanced');?>";
|
608
|
}
|
609
|
$('#btnadvstats').html('<i class="fa fa-cog"></i> ' + text);
|
610
|
}
|
611
|
|
612
|
$('#btnadvstats').click(function(event) {
|
613
|
show_advstats();
|
614
|
});
|
615
|
|
616
|
// Show advanced leap second options ======================================
|
617
|
var showadvleap = false;
|
618
|
|
619
|
function show_advleap(ispageload) {
|
620
|
var text;
|
621
|
// On page load decide the initial state based on the data.
|
622
|
if (ispageload) {
|
623
|
<?php
|
624
|
// Note: leapfile is not a field saved in the config, so no need to test for it here.
|
625
|
// leapsec is the encoded text in the config, leaptext is not a pconfig[] key.
|
626
|
if (empty($pconfig['leapsec'])) {
|
627
|
$showadv = false;
|
628
|
} else {
|
629
|
$showadv = true;
|
630
|
}
|
631
|
?>
|
632
|
showadvleap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
|
633
|
} else {
|
634
|
// It was a click, swap the state.
|
635
|
showadvleap = !showadvleap;
|
636
|
}
|
637
|
|
638
|
hideInput('leaptext', !showadvleap);
|
639
|
hideInput('leapfile', !showadvleap);
|
640
|
|
641
|
if (showadvleap) {
|
642
|
text = "<?=gettext('Hide Advanced');?>";
|
643
|
} else {
|
644
|
text = "<?=gettext('Display Advanced');?>";
|
645
|
}
|
646
|
$('#btnadvleap').html('<i class="fa fa-cog"></i> ' + text);
|
647
|
}
|
648
|
|
649
|
function change_serverauth() {
|
650
|
hideClass('ntpserverauth', !($('#serverauth').prop('checked')));
|
651
|
}
|
652
|
|
653
|
$('#btnadvleap').click(function(event) {
|
654
|
show_advleap();
|
655
|
});
|
656
|
|
657
|
$('#serverauth').change(function () {
|
658
|
change_serverauth();
|
659
|
});
|
660
|
|
661
|
// Set initial states
|
662
|
show_advstats(true);
|
663
|
show_advleap(true);
|
664
|
change_serverauth();
|
665
|
|
666
|
// Suppress "Delete row" button if there are fewer than two rows
|
667
|
checkLastRow();
|
668
|
});
|
669
|
//]]>
|
670
|
</script>
|
671
|
|
672
|
<?php include("foot.inc");
|