1
|
<?php
|
2
|
/*
|
3
|
* services_ntpd.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
|
9
|
* Copyright (c) 2013 Dagorlad
|
10
|
* All rights reserved.
|
11
|
*
|
12
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
13
|
* you may not use this file except in compliance with the License.
|
14
|
* You may obtain a copy of the License at
|
15
|
*
|
16
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17
|
*
|
18
|
* Unless required by applicable law or agreed to in writing, software
|
19
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
20
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
21
|
* See the License for the specific language governing permissions and
|
22
|
* limitations under the License.
|
23
|
*/
|
24
|
|
25
|
##|+PRIV
|
26
|
##|*IDENT=page-services-ntpd
|
27
|
##|*NAME=Services: NTP Settings
|
28
|
##|*DESCR=Allow access to the 'Services: NTP Settings' page.
|
29
|
##|*MATCH=services_ntpd.php*
|
30
|
##|-PRIV
|
31
|
|
32
|
define('NUMTIMESERVERS', 10); // The maximum number of configurable time servers
|
33
|
require_once("guiconfig.inc");
|
34
|
require_once('rrd.inc');
|
35
|
require_once("shaper.inc");
|
36
|
|
37
|
global $ntp_poll_min_default, $ntp_poll_max_default, $ntp_server_types;
|
38
|
$ntp_poll_values = system_ntp_poll_values();
|
39
|
$auto_pool_suffix = "pool.ntp.org";
|
40
|
$max_candidate_peers = 25;
|
41
|
$min_candidate_peers = 4;
|
42
|
|
43
|
if (empty(config_get_path('ntpd/interface'))) {
|
44
|
$old_ifs = config_get_path('installedpackages/openntpd/config/0/interface');
|
45
|
if (!empty($old_ifs)) {
|
46
|
config_set_path('ntpd/interface', $old_ifs);
|
47
|
$pconfig['interface'] = explode(",", $old_ifs);
|
48
|
config_del_path('installedpackages/openntpd');
|
49
|
write_config(gettext("Upgraded settings from openntpd"));
|
50
|
} else {
|
51
|
$pconfig['interface'] = array();
|
52
|
}
|
53
|
} else {
|
54
|
$pconfig['interface'] = explode(",", config_get_path('ntpd/interface'));
|
55
|
}
|
56
|
|
57
|
if ($_POST) {
|
58
|
unset($input_errors);
|
59
|
$pconfig = $_POST;
|
60
|
|
61
|
if (!empty($_POST['ntpmaxpeers']) && (!is_numericint($_POST['ntpmaxpeers']) ||
|
62
|
($_POST['ntpmaxpeers'] < $min_candidate_peers) || ($_POST['ntpmaxpeers'] > $max_candidate_peers))) {
|
63
|
$input_errors[] = sprintf(gettext("Max candidate pool peers must be a number between %d and %d"), $min_candidate_peers, $max_candidate_peers);
|
64
|
}
|
65
|
|
66
|
if ((strlen($pconfig['ntporphan']) > 0) && (!is_numericint($pconfig['ntporphan']) || ($pconfig['ntporphan'] < 1) || ($pconfig['ntporphan'] > 15))) {
|
67
|
$input_errors[] = gettext("The supplied value for NTP Orphan Mode is invalid.");
|
68
|
}
|
69
|
|
70
|
if (!array_key_exists($pconfig['ntpminpoll'], $ntp_poll_values)) {
|
71
|
$input_errors[] = gettext("The supplied value for Minimum Poll Interval is invalid.");
|
72
|
}
|
73
|
|
74
|
if (!array_key_exists($pconfig['ntpmaxpoll'], $ntp_poll_values)) {
|
75
|
$input_errors[] = gettext("The supplied value for Maximum Poll Interval is invalid.");
|
76
|
}
|
77
|
|
78
|
for ($i = 0; $i < NUMTIMESERVERS; $i++) {
|
79
|
if (isset($pconfig["servselect{$i}"]) && (($pconfig["servistype{$i}"] == 'pool') ||
|
80
|
(substr_compare($pconfig["server{$i}"], $auto_pool_suffix, strlen($pconfig["server{$i}"]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0))) {
|
81
|
$input_errors[] = gettext("It is not possible to use 'No Select' for pools.");
|
82
|
}
|
83
|
if (!empty($pconfig["server{$i}"]) && !is_domain($pconfig["server{$i}"]) &&
|
84
|
!is_ipaddr($pconfig["server{$i}"])) {
|
85
|
$input_errors[] = gettext("NTP Time Server names must be valid domain names, IPv4 addresses, or IPv6 addresses");
|
86
|
}
|
87
|
if (isset($pconfig["servauth{$i}"]) && (($pconfig["servistype{$i}"] == 'pool') ||
|
88
|
(substr_compare($pconfig["server{$i}"], $auto_pool_suffix, strlen($pconfig["server{$i}"]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0))) {
|
89
|
$input_errors[] = gettext("It is not possible to use 'Authenticated' for pools.");
|
90
|
}
|
91
|
if (isset($pconfig["servauth{$i}"]) && empty($pconfig['serverauth'])) {
|
92
|
$input_errors[] = gettext("The NTP authentication key information must be set to use 'Authenticated' for a server or peer.");
|
93
|
}
|
94
|
}
|
95
|
|
96
|
if (is_numericint($pconfig['ntpminpoll']) &&
|
97
|
is_numericint($pconfig['ntpmaxpoll']) &&
|
98
|
($pconfig['ntpmaxpoll'] < $pconfig['ntpminpoll'])) {
|
99
|
$input_errors[] = gettext("The supplied value for Minimum Poll Interval is higher than NTP Maximum Poll Interval.");
|
100
|
}
|
101
|
|
102
|
if (isset($pconfig['serverauth'])) {
|
103
|
if (empty($pconfig['serverauthkey'])) {
|
104
|
$input_errors[] = gettext("The supplied value for NTP Authentication key can't be empty.");
|
105
|
} elseif (empty($pconfig['serverauthkeyid'])) {
|
106
|
$input_errors[] = gettext("The authentication Key ID can't be empty.");
|
107
|
} elseif (!ctype_digit($pconfig['serverauthkeyid'])) {
|
108
|
$input_errors[] = gettext("The authentication Key ID must be a positive integer.");
|
109
|
} elseif ($pconfig['serverauthkeyid'] < 1 || $pconfig['serverauthkeyid'] > 65535) {
|
110
|
$input_errors[] = gettext("The authentication Key ID must be between 1-65535.");
|
111
|
} elseif (($pconfig['serverauthalgo'] == 'md5') && ((strlen($pconfig['serverauthkey']) > 20) ||
|
112
|
!ctype_print($pconfig['serverauthkey']))) {
|
113
|
$input_errors[] = gettext("The supplied value for NTP Authentication key for MD5 digest must be from 1 to 20 printable characters.");
|
114
|
} elseif (($pconfig['serverauthalgo'] == 'sha1') && ((strlen($pconfig['serverauthkey']) != 40) ||
|
115
|
!ctype_xdigit($pconfig['serverauthkey']))) {
|
116
|
$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA1 digest must be hex-encoded string of 40 characters.");
|
117
|
} elseif (($pconfig['serverauthalgo'] == 'sha256') && ((strlen($pconfig['serverauthkey']) != 64) ||
|
118
|
!ctype_xdigit($pconfig['serverauthkey']))) {
|
119
|
$input_errors[] = gettext("The supplied value for NTP Authentication key for SHA256 digest must be hex-encoded string of 64 characters.");
|
120
|
}
|
121
|
}
|
122
|
|
123
|
if (!$input_errors) {
|
124
|
config_set_path('ntpd/enable', isset($_POST['enable']) ? 'enabled' : 'disabled');
|
125
|
if (is_array($_POST['interface'])) {
|
126
|
config_set_path('ntpd/interface', implode(",", $_POST['interface']));
|
127
|
} else {
|
128
|
config_del_path('ntpd/interface');
|
129
|
}
|
130
|
|
131
|
config_del_path('ntpd/prefer');
|
132
|
config_del_path('ntpd/noselect');
|
133
|
config_del_path('ntpd/ispool');
|
134
|
config_del_path('ntpd/ispeer');
|
135
|
config_del_path('ntpd/isauth');
|
136
|
$timeservers = '';
|
137
|
|
138
|
for ($i = 0; $i < NUMTIMESERVERS; $i++) {
|
139
|
$tserver = trim($_POST["server{$i}"]);
|
140
|
if (!empty($tserver)) {
|
141
|
$timeservers .= "{$tserver} ";
|
142
|
if (isset($_POST["servprefer{$i}"])) {
|
143
|
config_set_path('ntpd/prefer', (config_get_path('ntpd/prefer') . "{$tserver} "));
|
144
|
}
|
145
|
if (isset($_POST["servselect{$i}"])) {
|
146
|
config_set_path('ntpd/noselect', (config_get_path('ntpd/noselect') . "{$tserver} "));
|
147
|
}
|
148
|
if (isset($_POST["servauth{$i}"])) {
|
149
|
config_set_path('ntpd/isauth', (config_get_path('ntpd/isauth') . "{$tserver} "));
|
150
|
}
|
151
|
if ($_POST["servistype{$i}"] == 'pool') {
|
152
|
config_set_path('ntpd/ispool', (config_get_path('ntpd/ispool') . "{$tserver} "));
|
153
|
} elseif ($_POST["servistype{$i}"] == 'peer') {
|
154
|
config_set_path('ntpd/ispeer', (config_get_path('ntpd/ispeer') . "{$tserver} "));
|
155
|
}
|
156
|
}
|
157
|
}
|
158
|
if (trim($timeservers) == "") {
|
159
|
$timeservers = "pool.ntp.org";
|
160
|
}
|
161
|
config_set_path('system/timeservers', trim($timeservers));
|
162
|
|
163
|
if (!empty($pconfig['ntpmaxpeers'])) {
|
164
|
config_set_path('ntpd/ntpmaxpeers', $pconfig['ntpmaxpeers']);
|
165
|
} else {
|
166
|
config_del_path('ntpd/ntpmaxpeers');
|
167
|
}
|
168
|
config_set_path('ntpd/orphan', trim($pconfig['ntporphan']));
|
169
|
config_set_path('ntpd/ntpminpoll', $pconfig['ntpminpoll']);
|
170
|
config_set_path('ntpd/ntpmaxpoll', $pconfig['ntpmaxpoll']);
|
171
|
config_set_path('ntpd/dnsresolv', $pconfig['dnsresolv']);
|
172
|
|
173
|
if (!empty($_POST['logpeer'])) {
|
174
|
config_set_path('ntpd/logpeer', $_POST['logpeer']);
|
175
|
} elseif (config_path_enabled('ntpd', 'logpeer')) {
|
176
|
config_del_path('ntpd/logpeer');
|
177
|
}
|
178
|
|
179
|
if (!empty($_POST['logsys'])) {
|
180
|
config_set_path('ntpd/logsys', $_POST['logsys']);
|
181
|
} elseif (config_path_enabled('ntpd', 'logsys')) {
|
182
|
config_del_path('ntpd/logsys');
|
183
|
}
|
184
|
|
185
|
if (!empty($_POST['clockstats'])) {
|
186
|
config_set_path('ntpd/clockstats', $_POST['clockstats']);
|
187
|
} elseif (config_path_enabled('ntpd', 'clockstats')) {
|
188
|
config_del_path('ntpd/clockstats');
|
189
|
}
|
190
|
|
191
|
if (!empty($_POST['loopstats'])) {
|
192
|
config_set_path('ntpd/loopstats', $_POST['loopstats']);
|
193
|
} elseif (config_path_enabled('ntpd', 'loopstats')) {
|
194
|
config_del_path('ntpd/loopstats');
|
195
|
}
|
196
|
|
197
|
if (!empty($_POST['peerstats'])) {
|
198
|
config_set_path('ntpd/peerstats', $_POST['peerstats']);
|
199
|
} elseif (config_path_enabled('ntpd', 'peerstats')) {
|
200
|
config_del_path('ntpd/peerstats');
|
201
|
}
|
202
|
|
203
|
if ((empty($_POST['statsgraph'])) == (config_path_enabled('ntpd', 'statsgraph'))) {
|
204
|
$enable_rrd_graphing = true;
|
205
|
}
|
206
|
if (!empty($_POST['statsgraph'])) {
|
207
|
config_set_path('ntpd/statsgraph', $_POST['statsgraph']);
|
208
|
} elseif (config_path_enabled('ntpd', 'statsgraph')) {
|
209
|
config_del_path('ntpd/statsgraph');
|
210
|
}
|
211
|
if (isset($enable_rrd_graphing)) {
|
212
|
enable_rrd_graphing();
|
213
|
}
|
214
|
|
215
|
if (!empty($_POST['leaptext'])) {
|
216
|
config_set_path('ntpd/leapsec', base64_encode($_POST['leaptext']));
|
217
|
} elseif (config_path_enabled('ntpd', 'leapsec')) {
|
218
|
config_del_path('ntpd/leapsec');
|
219
|
}
|
220
|
|
221
|
if (is_uploaded_file($_FILES['leapfile']['tmp_name'])) {
|
222
|
config_set_path('ntpd/leapsec', base64_encode(file_get_contents($_FILES['leapfile']['tmp_name'])));
|
223
|
}
|
224
|
|
225
|
if (!empty($_POST['serverauth'])) {
|
226
|
config_set_path('ntpd/serverauth', $_POST['serverauth']);
|
227
|
config_set_path('ntpd/serverauthkey', base64_encode(trim($_POST['serverauthkey'])));
|
228
|
config_set_path('ntpd/serverauthkeyid', $_POST['serverauthkeyid']);
|
229
|
config_set_path('ntpd/serverauthalgo', $_POST['serverauthalgo']);
|
230
|
} elseif (config_path_enabled('ntpd', 'serverauth')) {
|
231
|
config_del_path('ntpd/serverauth');
|
232
|
config_del_path('ntpd/serverauthkey');
|
233
|
config_del_path('ntpd/serverauthkeyid');
|
234
|
config_del_path('ntpd/serverauthalgo');
|
235
|
}
|
236
|
|
237
|
write_config("Updated NTP Server Settings");
|
238
|
|
239
|
$changes_applied = true;
|
240
|
$retval = 0;
|
241
|
$retval |= system_ntp_configure();
|
242
|
}
|
243
|
}
|
244
|
|
245
|
function build_interface_list() {
|
246
|
global $pconfig;
|
247
|
|
248
|
$iflist = array('options' => array(), 'selected' => array());
|
249
|
|
250
|
$interfaces = get_configured_interface_with_descr();
|
251
|
$interfaces['lo0'] = "Localhost";
|
252
|
|
253
|
foreach ($interfaces as $iface => $ifacename) {
|
254
|
if (!is_ipaddr(get_interface_ip($iface)) &&
|
255
|
!is_ipaddrv6(get_interface_ipv6($iface))) {
|
256
|
continue;
|
257
|
}
|
258
|
|
259
|
$iflist['options'][$iface] = $ifacename;
|
260
|
|
261
|
if (in_array($iface, $pconfig['interface'])) {
|
262
|
array_push($iflist['selected'], $iface);
|
263
|
}
|
264
|
}
|
265
|
|
266
|
return($iflist);
|
267
|
}
|
268
|
|
269
|
$pconfig = config_get_path('ntpd', []);
|
270
|
$pconfig['enable'] = ($pconfig['enable'] != 'disabled') ? 'enabled' : 'disabled';
|
271
|
if (empty($pconfig['interface'])) {
|
272
|
$pconfig['interface'] = array();
|
273
|
} else {
|
274
|
$pconfig['interface'] = explode(",", $pconfig['interface']);
|
275
|
}
|
276
|
config_set_path('ntpd', $pconfig);
|
277
|
$pgtitle = array(gettext("Services"), gettext("NTP"), gettext("Settings"));
|
278
|
$pglinks = array("", "@self", "@self");
|
279
|
$shortcut_section = "ntp";
|
280
|
include("head.inc");
|
281
|
|
282
|
if ($input_errors) {
|
283
|
print_input_errors($input_errors);
|
284
|
}
|
285
|
|
286
|
if ($changes_applied) {
|
287
|
print_apply_result_box($retval);
|
288
|
}
|
289
|
|
290
|
$tab_array = array();
|
291
|
$tab_array[] = array(gettext("Settings"), true, "services_ntpd.php");
|
292
|
$tab_array[] = array(gettext("ACLs"), false, "services_ntpd_acls.php");
|
293
|
$tab_array[] = array(gettext("Serial GPS"), false, "services_ntpd_gps.php");
|
294
|
$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
|
295
|
display_top_tabs($tab_array);
|
296
|
|
297
|
$form = new Form;
|
298
|
$form->setMultipartEncoding(); // Allow file uploads
|
299
|
|
300
|
$section = new Form_Section('NTP Server Configuration');
|
301
|
|
302
|
$section->addInput(new Form_Checkbox(
|
303
|
'enable',
|
304
|
'Enable',
|
305
|
'Enable NTP Server',
|
306
|
($pconfig['enable'] == 'enabled')
|
307
|
))->setHelp('You may need to disable NTP if %1$s is running in a virtual machine and the host is responsible for the clock.', g_get('product_label'));
|
308
|
|
309
|
$iflist = build_interface_list();
|
310
|
|
311
|
$section->addInput(new Form_Select(
|
312
|
'interface',
|
313
|
'Interface',
|
314
|
$iflist['selected'],
|
315
|
$iflist['options'],
|
316
|
true
|
317
|
))->setHelp('Interfaces without an IP address will not be shown.%1$s' .
|
318
|
'Selecting no interfaces will listen on all interfaces with a wildcard.%1$s' .
|
319
|
'Selecting all interfaces will explicitly listen on only the interfaces/IPs specified.', '<br />');
|
320
|
|
321
|
$timeservers = explode(' ', config_get_path('system/timeservers'));
|
322
|
$maxrows = max(count($timeservers), 1);
|
323
|
for ($counter=0; $counter < $maxrows; $counter++) {
|
324
|
$group = new Form_Group($counter == 0 ? 'Time Servers':'');
|
325
|
$group->addClass('repeatable');
|
326
|
$group->setAttribute('max_repeats', NUMTIMESERVERS);
|
327
|
$group->setAttribute('max_repeats_alert', sprintf(gettext('%d is the maximum number of configured servers.'), NUMTIMESERVERS));
|
328
|
|
329
|
$group->add(new Form_Input(
|
330
|
'server' . $counter,
|
331
|
null,
|
332
|
'text',
|
333
|
$timeservers[$counter],
|
334
|
['placeholder' => 'Hostname']
|
335
|
))->setWidth(3);
|
336
|
|
337
|
$group->add(new Form_Checkbox(
|
338
|
'servprefer' . $counter,
|
339
|
null,
|
340
|
null,
|
341
|
config_path_enabled('ntpd', 'prefer') && isset($timeservers[$counter]) && substr_count(config_get_path('ntpd/prefer'), $timeservers[$counter])
|
342
|
))->sethelp('Prefer');
|
343
|
|
344
|
$group->add(new Form_Checkbox(
|
345
|
'servselect' . $counter,
|
346
|
null,
|
347
|
null,
|
348
|
config_path_enabled('ntpd', 'noselect') && isset($timeservers[$counter]) && substr_count(config_get_path('ntpd/noselect'), $timeservers[$counter])
|
349
|
))->sethelp('No Select');
|
350
|
|
351
|
$group->add(new Form_Checkbox(
|
352
|
'servauth' . $counter,
|
353
|
null,
|
354
|
null,
|
355
|
config_path_enabled('ntpd', 'isauth') && isset($timeservers[$counter]) && substr_count(config_get_path('ntpd/isauth', ''), $timeservers[$counter])
|
356
|
))->setHelp('Authenticated');
|
357
|
|
358
|
if ((substr_compare($timeservers[$counter], $auto_pool_suffix, strlen($timeservers[$counter]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0) ||
|
359
|
((config_get_path('ntpd/ispool') !== null) && isset($timeservers[$counter]) &&
|
360
|
substr_count(config_get_path('ntpd/ispool'), $timeservers[$counter]))) {
|
361
|
$servertype = 'pool';
|
362
|
} elseif ((config_get_path('ntpd/ispeer') !== null) && isset($timeservers[$counter]) && substr_count(config_get_path('ntpd/ispeer'), $timeservers[$counter])) {
|
363
|
$servertype = 'peer';
|
364
|
} else {
|
365
|
$servertype = 'server';
|
366
|
}
|
367
|
|
368
|
$group->add(new Form_Select(
|
369
|
'servistype' . $counter,
|
370
|
null,
|
371
|
$servertype,
|
372
|
$ntp_server_types
|
373
|
))->sethelp('Type')->setWidth(2);
|
374
|
|
375
|
$group->add(new Form_Button(
|
376
|
'deleterow' . $counter,
|
377
|
'Delete',
|
378
|
null,
|
379
|
'fa-solid fa-trash-can'
|
380
|
))->addClass('btn-warning');
|
381
|
|
382
|
$section->add($group);
|
383
|
}
|
384
|
|
385
|
$section->addInput(new Form_Button(
|
386
|
'addrow',
|
387
|
'Add',
|
388
|
null,
|
389
|
'fa-solid fa-plus'
|
390
|
))->addClass('btn-success');
|
391
|
|
392
|
$section->addInput(new Form_StaticText(
|
393
|
null,
|
394
|
$btnaddrow
|
395
|
))->setHelp(
|
396
|
'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 ' .
|
397
|
'(%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 ' .
|
398
|
'are configured and they disagree, %2$sneither%3$s will be believed. Options:%1$s' .
|
399
|
'%2$sPrefer%3$s - NTP should favor the use of this server more than all others.%1$s' .
|
400
|
'%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' .
|
401
|
'%2$sType%3$s - Server, Peer or a Pool of NTP servers and not a single address. This is assumed for *.pool.ntp.org.',
|
402
|
'<br />',
|
403
|
'<b>',
|
404
|
'</b>',
|
405
|
'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
|
406
|
'</a>'
|
407
|
);
|
408
|
|
409
|
$section->addInput(new Form_Input(
|
410
|
'ntpmaxpeers',
|
411
|
'Max candidate pool peers',
|
412
|
'number',
|
413
|
$pconfig['ntpmaxpeers'],
|
414
|
['min' => $min_candidate_peers, 'max' => $max_candidate_peers]
|
415
|
))->setHelp('Maximum number of candidate peers in the NTP pool. This value should be set low enough to provide sufficient alternate sources ' .
|
416
|
'while not contacting an excessively large number of peers. ' .
|
417
|
'Many servers inside public pools are provided by volunteers, ' .
|
418
|
'and a large candidate pool places unnecessary extra load ' .
|
419
|
'on the volunteer time servers for little to no added benefit. (Default: 5).');
|
420
|
|
421
|
$section->addInput(new Form_Input(
|
422
|
'ntporphan',
|
423
|
'Orphan Mode',
|
424
|
'text',
|
425
|
$pconfig['orphan'],
|
426
|
['placeholder' => "12"]
|
427
|
))->setHelp('Orphan mode allows the system clock to be used when no other clocks are available. ' .
|
428
|
'The number here specifies the stratum reported during orphan mode and should normally be set to a number high enough ' .
|
429
|
'to insure that any other servers available to clients are preferred over this server (default: 12).');
|
430
|
|
431
|
$section->addInput(new Form_Select(
|
432
|
'ntpminpoll',
|
433
|
'Minimum Poll Interval',
|
434
|
$pconfig['ntpminpoll'],
|
435
|
$ntp_poll_values
|
436
|
))->setHelp('Minimum poll interval for NTP messages. If set, must be less than or equal to Maximum Poll Interval.');
|
437
|
|
438
|
$section->addInput(new Form_Select(
|
439
|
'ntpmaxpoll',
|
440
|
'Maximum Poll Interval',
|
441
|
$pconfig['ntpmaxpoll'],
|
442
|
$ntp_poll_values
|
443
|
))->setHelp('Maximum poll interval for NTP messages. If set, must be greater than or equal to Minimum Poll Interval.');
|
444
|
|
445
|
$section->addInput(new Form_Checkbox(
|
446
|
'statsgraph',
|
447
|
'NTP Graphs',
|
448
|
'Enable RRD graphs of NTP statistics (default: disabled).',
|
449
|
$pconfig['statsgraph']
|
450
|
));
|
451
|
|
452
|
$section->addInput(new Form_Checkbox(
|
453
|
'logpeer',
|
454
|
'Logging',
|
455
|
'Log peer messages (default: disabled).',
|
456
|
$pconfig['logpeer']
|
457
|
));
|
458
|
|
459
|
$section->addInput(new Form_Checkbox(
|
460
|
'logsys',
|
461
|
null,
|
462
|
'Log system messages (default: disabled).',
|
463
|
$pconfig['logsys']
|
464
|
))->setHelp('These options enable additional messages from NTP to be written to the System Log %1$sStatus > System Logs > NTP%2$s',
|
465
|
'<a href="status_logs.php?logfile=ntpd">', '</a>.');
|
466
|
|
467
|
// Statistics logging section
|
468
|
$btnadv = new Form_Button(
|
469
|
'btnadvstats',
|
470
|
gettext('Display Advanced'),
|
471
|
null,
|
472
|
'fa-solid fa-cog'
|
473
|
);
|
474
|
|
475
|
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
|
476
|
|
477
|
$section->addInput(new Form_StaticText(
|
478
|
'Statistics Logging',
|
479
|
$btnadv
|
480
|
))->setHelp('Warning: These options will create persistent daily log files in /var/log/ntp.');
|
481
|
|
482
|
$section->addInput(new Form_Checkbox(
|
483
|
'clockstats',
|
484
|
null,
|
485
|
'Log reference clock statistics (default: disabled).',
|
486
|
$pconfig['clockstats']
|
487
|
));
|
488
|
|
489
|
$section->addInput(new Form_Checkbox(
|
490
|
'loopstats',
|
491
|
null,
|
492
|
'Log clock discipline statistics (default: disabled).',
|
493
|
$pconfig['loopstats']
|
494
|
));
|
495
|
|
496
|
$section->addInput(new Form_Checkbox(
|
497
|
'peerstats',
|
498
|
null,
|
499
|
'Log NTP peer statistics (default: disabled).',
|
500
|
$pconfig['peerstats']
|
501
|
));
|
502
|
|
503
|
// Leap seconds section
|
504
|
$btnadv = new Form_Button(
|
505
|
'btnadvleap',
|
506
|
gettext('Display Advanced'),
|
507
|
null,
|
508
|
'fa-solid fa-cog'
|
509
|
);
|
510
|
|
511
|
$btnadv->setAttribute('type','button')->addClass('btn-info btn-sm');
|
512
|
|
513
|
$section->addInput(new Form_StaticText(
|
514
|
'Leap seconds',
|
515
|
$btnadv
|
516
|
))->setHelp(
|
517
|
'Leap seconds may be added or subtracted at the end of June or December. Leap seconds are administered by the ' .
|
518
|
'%1$sIERS%2$s, who publish them in their Bulletin C approximately 6 - 12 months in advance. Normally this correction ' .
|
519
|
'should only be needed if the server is a stratum 1 NTP server, but many NTP servers do not advertise an upcoming leap ' .
|
520
|
'second when other NTP servers synchronise to them.%3$s%4$sIf the leap second is important to your network services, ' .
|
521
|
'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 ' .
|
522
|
'More information and files for downloading can be found on their %1$swebsite%2$s, and also on the %7$sNIST%2$s and %8$sNTP%2$s websites.',
|
523
|
'<a target="_blank" href="https://www.iers.org">',
|
524
|
'</a>',
|
525
|
'<br />',
|
526
|
'<b>',
|
527
|
'</b>',
|
528
|
'<a target="_blank" href="https://support.ntp.org/bin/view/Support/ConfiguringNTP">',
|
529
|
'<a target="_blank" href="https://www.nist.gov">',
|
530
|
'<a target="_blank" href="https://www.ntp.org">'
|
531
|
);
|
532
|
|
533
|
$section->addInput(new Form_Textarea(
|
534
|
'leaptext',
|
535
|
null,
|
536
|
base64_decode(chunk_split($pconfig['leapsec']))
|
537
|
))->setHelp('Enter Leap second configuration as text OR select a file to upload.');
|
538
|
|
539
|
$section->addInput(new Form_Input(
|
540
|
'leapfile',
|
541
|
null,
|
542
|
'file'
|
543
|
))->addClass('btn-default');
|
544
|
|
545
|
$section->addInput(new Form_Select(
|
546
|
'dnsresolv',
|
547
|
'DNS Resolution',
|
548
|
$pconfig['dnsresolv'],
|
549
|
array(
|
550
|
'auto' => 'Auto',
|
551
|
'inet' => 'IPv4',
|
552
|
'inet6' => 'IPv6',
|
553
|
)
|
554
|
))->setHelp('Force NTP peer DNS resolution IP protocol.');
|
555
|
|
556
|
$section->addInput(new Form_Checkbox(
|
557
|
'serverauth',
|
558
|
'Enable NTP Server Authentication',
|
559
|
'Enable NTPv3 authentication (RFC 1305)',
|
560
|
$pconfig['serverauth']
|
561
|
))->setHelp('Authentication allows the NTP client to confirm it is communicating with the intended server, ' .
|
562
|
'which protects against man-in-the-middle attacks.');
|
563
|
|
564
|
$group = new Form_Group('Authentication key');
|
565
|
$group->addClass('ntpserverauth');
|
566
|
|
567
|
$group->add(new Form_Input(
|
568
|
'serverauthkeyid',
|
569
|
'Key ID',
|
570
|
null,
|
571
|
$pconfig['serverauthkeyid'],
|
572
|
['placeholder' => 'Key ID', 'type' => 'number', 'min' => 1, 'max' => 65535, 'step' => 1]
|
573
|
))->setWidth(2)->setHelp('ID associated with the authentication key');
|
574
|
|
575
|
$group->add(new Form_Input(
|
576
|
'serverauthkey',
|
577
|
'NTP Authentication key',
|
578
|
'text',
|
579
|
base64_decode($pconfig['serverauthkey']),
|
580
|
['placeholder' => 'NTP Authentication key']
|
581
|
))->setHelp(
|
582
|
'Key format: %1$s MD5 - The key is 1 to 20 printable characters %1$s' .
|
583
|
'SHA1 - The key is a hex-encoded ASCII string of 40 characters %1$s' .
|
584
|
'SHA256 - The key is a hex-encoded ASCII string of 64 characters',
|
585
|
'<br />'
|
586
|
);
|
587
|
|
588
|
$group->add(new Form_Select(
|
589
|
'serverauthalgo',
|
590
|
null,
|
591
|
$pconfig['serverauthalgo'],
|
592
|
$ntp_auth_halgos
|
593
|
))->setWidth(2)->setHelp('Digest algorithm');
|
594
|
|
595
|
$section->add($group);
|
596
|
|
597
|
$form->add($section);
|
598
|
|
599
|
print($form);
|
600
|
|
601
|
?>
|
602
|
|
603
|
<script type="text/javascript">
|
604
|
//<![CDATA[
|
605
|
// If this variable is declared, any help text will not be deleted when rows are added
|
606
|
// IOW the help text will appear on every row
|
607
|
retainhelp = true;
|
608
|
</script>
|
609
|
|
610
|
<script type="text/javascript">
|
611
|
//<![CDATA[
|
612
|
events.push(function() {
|
613
|
|
614
|
// Show advanced stats options ============================================
|
615
|
var showadvstats = false;
|
616
|
|
617
|
function show_advstats(ispageload) {
|
618
|
var text;
|
619
|
// On page load decide the initial state based on the data.
|
620
|
if (ispageload) {
|
621
|
<?php
|
622
|
if (!$pconfig['clockstats'] && !$pconfig['loopstats'] && !$pconfig['peerstats']) {
|
623
|
$showadv = false;
|
624
|
} else {
|
625
|
$showadv = true;
|
626
|
}
|
627
|
?>
|
628
|
showadvstats = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
|
629
|
} else {
|
630
|
// It was a click, swap the state.
|
631
|
showadvstats = !showadvstats;
|
632
|
}
|
633
|
|
634
|
hideCheckbox('clockstats', !showadvstats);
|
635
|
hideCheckbox('loopstats', !showadvstats);
|
636
|
hideCheckbox('peerstats', !showadvstats);
|
637
|
|
638
|
if (showadvstats) {
|
639
|
text = "<?=gettext('Hide Advanced');?>";
|
640
|
} else {
|
641
|
text = "<?=gettext('Display Advanced');?>";
|
642
|
}
|
643
|
var children = $('#btnadvstats').children();
|
644
|
$('#btnadvstats').text(text).prepend(children);
|
645
|
}
|
646
|
|
647
|
$('#btnadvstats').click(function(event) {
|
648
|
show_advstats();
|
649
|
});
|
650
|
|
651
|
// Show advanced leap second options ======================================
|
652
|
var showadvleap = false;
|
653
|
|
654
|
function show_advleap(ispageload) {
|
655
|
var text;
|
656
|
// On page load decide the initial state based on the data.
|
657
|
if (ispageload) {
|
658
|
<?php
|
659
|
// Note: leapfile is not a field saved in the config, so no need to test for it here.
|
660
|
// leapsec is the encoded text in the config, leaptext is not a pconfig[] key.
|
661
|
if (empty($pconfig['leapsec'])) {
|
662
|
$showadv = false;
|
663
|
} else {
|
664
|
$showadv = true;
|
665
|
}
|
666
|
?>
|
667
|
showadvleap = <?php if ($showadv) {echo 'true';} else {echo 'false';} ?>;
|
668
|
} else {
|
669
|
// It was a click, swap the state.
|
670
|
showadvleap = !showadvleap;
|
671
|
}
|
672
|
|
673
|
hideInput('leaptext', !showadvleap);
|
674
|
hideInput('leapfile', !showadvleap);
|
675
|
|
676
|
if (showadvleap) {
|
677
|
text = "<?=gettext('Hide Advanced');?>";
|
678
|
} else {
|
679
|
text = "<?=gettext('Display Advanced');?>";
|
680
|
}
|
681
|
var children = $('#btnadvleap').children();
|
682
|
$('#btnadvleap').text(text).prepend(children);
|
683
|
}
|
684
|
|
685
|
function change_serverauth() {
|
686
|
hideClass('ntpserverauth', !($('#serverauth').prop('checked')));
|
687
|
}
|
688
|
|
689
|
$('#btnadvleap').click(function(event) {
|
690
|
show_advleap();
|
691
|
});
|
692
|
|
693
|
$('#serverauth').change(function () {
|
694
|
change_serverauth();
|
695
|
});
|
696
|
|
697
|
// Set initial states
|
698
|
show_advstats(true);
|
699
|
show_advleap(true);
|
700
|
change_serverauth();
|
701
|
|
702
|
// Suppress "Delete row" button if there are fewer than two rows
|
703
|
checkLastRow();
|
704
|
});
|
705
|
//]]>
|
706
|
</script>
|
707
|
|
708
|
<?php include("foot.inc");
|