Feature #8794 » 8794.patch
src/etc/inc/system.inc | ||
---|---|---|
2327 | 2327 |
$driftfile = "/var/db/ntpd.drift"; |
2328 | 2328 |
$statsdir = "/var/log/ntp"; |
2329 | 2329 |
$gps_device = '/dev/gps0'; |
2330 |
$ntp_keyid = config_get_path('ntpd/serverauthkeyid') ?? '1'; |
|
2330 | 2331 | |
2331 | 2332 |
safe_mkdir($statsdir); |
2332 | 2333 | |
... | ... | |
2356 | 2357 | |
2357 | 2358 |
/* set NTP server authentication key */ |
2358 | 2359 |
if (config_get_path('ntpd/serverauth') == 'yes') { |
2359 |
$ntpkeyscfg = "1 " . strtoupper(config_get_path('ntpd/serverauthalgo')) . " " . base64_decode(config_get_path('ntpd/serverauthkey')) . "\n";
|
|
2360 |
$ntpkeyscfg = "{$ntp_keyid} " . strtoupper(config_get_path('ntpd/serverauthalgo')) . " " . base64_decode(config_get_path('ntpd/serverauthkey')) . "\n";
|
|
2360 | 2361 |
if (!@file_put_contents("{$g['varetc_path']}/ntp.keys", $ntpkeyscfg)) { |
2361 | 2362 |
log_error(sprintf(gettext("Could not open %s/ntp.keys for writing"), g_get('varetc_path'))); |
2362 | 2363 |
return; |
... | ... | |
2373 | 2374 |
if (config_get_path('ntpd/serverauth') == 'yes') { |
2374 | 2375 |
$ntpcfg .= "# Authentication settings \n"; |
2375 | 2376 |
$ntpcfg .= "keys /var/etc/ntp.keys \n"; |
2376 |
$ntpcfg .= "trustedkey 1 \n";
|
|
2377 |
$ntpcfg .= "requestkey 1 \n";
|
|
2378 |
$ntpcfg .= "controlkey 1 \n";
|
|
2377 |
$ntpcfg .= "trustedkey {$ntp_keyid} \n";
|
|
2378 |
$ntpcfg .= "requestkey {$ntp_keyid} \n";
|
|
2379 |
$ntpcfg .= "controlkey {$ntp_keyid} \n";
|
|
2379 | 2380 |
$ntpcfg .= "\n"; |
2380 | 2381 |
} |
2381 | 2382 | |
... | ... | |
2552 | 2553 |
if (substr_count(config_get_path('ntpd/noselect'), $ts)) { |
2553 | 2554 |
$ntpcfg .= ' noselect'; |
2554 | 2555 |
} |
2556 |
if (config_get_path('ntpd/serverauth') == 'yes' && !substr_count(config_get_path('ntpd/ispool'), $ts) && substr_count(config_get_path('ntpd/isauth'), $ts)) { |
|
2557 |
$ntpcfg .= " key {$ntp_keyid} "; |
|
2558 |
} |
|
2555 | 2559 |
$ntpcfg .= "\n"; |
2556 | 2560 |
} |
2557 | 2561 |
unset($ts); |
src/usr/local/www/services_ntpd.php | ||
---|---|---|
84 | 84 |
(substr_compare($pconfig["server{$i}"], $auto_pool_suffix, strlen($pconfig["server{$i}"]) - strlen($auto_pool_suffix), strlen($auto_pool_suffix)) === 0))) { |
85 | 85 |
$input_errors[] = gettext("It is not possible to use 'No Select' for pools."); |
86 | 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 |
} |
|
87 | 94 |
if (!empty($pconfig["server{$i}"]) && !is_domain($pconfig["server{$i}"]) && |
88 | 95 |
!is_ipaddr($pconfig["server{$i}"])) { |
89 | 96 |
$input_errors[] = gettext("NTP Time Server names must be valid domain names, IPv4 addresses, or IPv6 addresses"); |
... | ... | |
99 | 106 |
if (isset($pconfig['serverauth'])) { |
100 | 107 |
if (empty($pconfig['serverauthkey'])) { |
101 | 108 |
$input_errors[] = gettext("The supplied value for NTP Authentication key can't be empty."); |
109 |
} elseif (empty($pconfig['serverauthkeyid'])) { |
|
110 |
$input_errors[] = gettext("The authentication Key ID can't be empty."); |
|
111 |
} elseif (!ctype_digit($pconfig['serverauthkeyid'])) { |
|
112 |
$input_errors[] = gettext("The authentication Key ID must be a positive integer."); |
|
113 |
} elseif ($pconfig['serverauthkeyid'] < 1 || $pconfig['serverauthkeyid'] > 65535) { |
|
114 |
$input_errors[] = gettext("The authentication Key ID must be between 1-65535."); |
|
102 | 115 |
} elseif (($pconfig['serverauthalgo'] == 'md5') && ((strlen($pconfig['serverauthkey']) > 20) || |
103 | 116 |
!ctype_print($pconfig['serverauthkey']))) { |
104 | 117 |
$input_errors[] = gettext("The supplied value for NTP Authentication key for MD5 digest must be from 1 to 20 printable characters."); |
... | ... | |
123 | 136 |
config_del_path('ntpd/noselect'); |
124 | 137 |
config_del_path('ntpd/ispool'); |
125 | 138 |
config_del_path('ntpd/ispeer'); |
139 |
config_del_path('ntpd/isauth'); |
|
126 | 140 |
$timeservers = ''; |
127 | 141 | |
128 | 142 |
for ($i = 0; $i < NUMTIMESERVERS; $i++) { |
... | ... | |
135 | 149 |
if (isset($_POST["servselect{$i}"])) { |
136 | 150 |
$config['ntpd']['noselect'] .= "{$tserver} "; |
137 | 151 |
} |
152 |
if (isset($_POST["servauth{$i}"])) { |
|
153 |
$config['ntpd']['isauth'] .= "{$tserver} "; |
|
154 |
} |
|
138 | 155 |
if ($_POST["servistype{$i}"] == 'pool') { |
139 | 156 |
$config['ntpd']['ispool'] .= "{$tserver} "; |
140 | 157 |
} elseif ($_POST["servistype{$i}"] == 'peer') { |
... | ... | |
212 | 229 |
if (!empty($_POST['serverauth'])) { |
213 | 230 |
config_set_path('ntpd/serverauth', $_POST['serverauth']); |
214 | 231 |
config_set_path('ntpd/serverauthkey', base64_encode(trim($_POST['serverauthkey']))); |
232 |
config_set_path('ntpd/serverauthkeyid', $_POST['serverauthkeyid']); |
|
215 | 233 |
config_set_path('ntpd/serverauthalgo', $_POST['serverauthalgo']); |
216 | 234 |
} elseif (isset($config['ntpd']['serverauth'])) { |
217 | 235 |
config_del_path('ntpd/serverauth'); |
218 | 236 |
config_del_path('ntpd/serverauthkey'); |
237 |
config_del_path('ntpd/serverauthkeyid'); |
|
219 | 238 |
config_del_path('ntpd/serverauthalgo'); |
220 | 239 |
} |
221 | 240 | |
... | ... | |
319 | 338 |
['placeholder' => 'Hostname'] |
320 | 339 |
))->setWidth(3); |
321 | 340 | |
322 |
$group->add(new Form_Checkbox(
|
|
341 |
$group->add(new Form_Checkbox( |
|
323 | 342 |
'servprefer' . $counter, |
324 | 343 |
null, |
325 | 344 |
null, |
326 | 345 |
isset($config['ntpd']['prefer']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['prefer'], $timeservers[$counter]) |
327 | 346 |
))->sethelp('Prefer'); |
328 | 347 | |
329 |
$group->add(new Form_Checkbox(
|
|
348 |
$group->add(new Form_Checkbox( |
|
330 | 349 |
'servselect' . $counter, |
331 | 350 |
null, |
332 | 351 |
null, |
333 | 352 |
isset($config['ntpd']['noselect']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['noselect'], $timeservers[$counter]) |
334 | 353 |
))->sethelp('No Select'); |
335 | 354 | |
355 |
$group->add(new Form_Checkbox( |
|
356 |
'servauth' . $counter, |
|
357 |
null, |
|
358 |
null, |
|
359 |
isset($config['ntpd']['isauth']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['isauth'], $timeservers[$counter]) |
|
360 |
))->setHelp('Authenticated'); |
|
361 | ||
336 | 362 |
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]))) { |
337 | 363 |
$servertype = 'pool'; |
338 | 364 |
} elseif (isset($config['ntpd']['ispeer']) && isset($timeservers[$counter]) && substr_count($config['ntpd']['ispeer'], $timeservers[$counter])) { |
... | ... | |
540 | 566 |
$group = new Form_Group('Authentication key'); |
541 | 567 |
$group->addClass('ntpserverauth'); |
542 | 568 | |
543 |
$group->add(new Form_IpAddress( |
|
569 |
$group->add(new Form_Input( |
|
570 |
'serverauthkeyid', |
|
571 |
'Key ID', |
|
572 |
null, |
|
573 |
$pconfig['serverauthkeyid'], |
|
574 |
['placeholder' => 'Key ID', 'type' => 'number', 'min' => 1, 'max' => 65535, 'step' => 1] |
|
575 |
))->setWidth(2)->setHelp('ID associated with the authentication key'); |
|
576 | ||
577 |
$group->add(new Form_Input( |
|
544 | 578 |
'serverauthkey', |
545 | 579 |
'NTP Authentication key', |
580 |
'text', |
|
546 | 581 |
base64_decode($pconfig['serverauthkey']), |
547 | 582 |
['placeholder' => 'NTP Authentication key'] |
548 | 583 |
))->setHelp( |
... | ... | |
557 | 592 |
null, |
558 | 593 |
$pconfig['serverauthalgo'], |
559 | 594 |
$ntp_auth_halgos |
560 |
))->setWidth(3)->setHelp('Digest algorithm');
|
|
595 |
))->setWidth(2)->setHelp('Digest algorithm');
|
|
561 | 596 | |
562 | 597 |
$section->add($group); |
563 | 598 |
src/usr/local/www/status_ntpd.php | ||
---|---|---|
52 | 52 |
$inet_version = " -4"; |
53 | 53 |
} |
54 | 54 | |
55 |
exec('/usr/local/sbin/ntpq -pnw ' . $inet_version . ' | /usr/bin/tail +3 | /usr/bin/awk -v RS= \'{gsub(/\n[[:space:]][[:space:]]+/," ")}1\'', $ntpq_output); |
|
55 |
exec('/usr/local/sbin/ntpq -pnw' . $inet_version . ' | /usr/bin/tail +3 | /usr/bin/awk -v RS= \'{gsub(/\n[[:space:]][[:space:]]+/," ")}1\'', $ntpq_output); |
|
56 |
exec('/usr/local/sbin/ntpq -c associations' . $inet_version . ' | /usr/bin/tail +3 | /usr/bin/awk -v RS= \'{gsub(/\n[[:space:]][[:space:]]\n+/," ")}1\'', $ntpq_associations_output); |
|
56 | 57 | |
57 | 58 |
$ntpq_servers = array(); |
58 |
foreach ($ntpq_output as $line) { |
|
59 |
$ntpq_server_responses = array(); |
|
60 | ||
61 |
foreach ($ntpq_associations_output as $i => $line) { |
|
62 |
$associations_response = array(); |
|
63 |
$peerinfo = preg_split("/[\s\t]+/", $line); |
|
64 |
$server['ind'] = $peerinfo[1]; |
|
65 |
$associations_response['assid'] = $peerinfo[2]; |
|
66 |
$associations_response['status_word'] = $peerinfo[3]; |
|
67 |
$associations_response['conf'] = $peerinfo[4]; |
|
68 |
$associations_response['reach'] = $peerinfo[5]; |
|
69 |
$associations_response['auth'] = $peerinfo[6]; |
|
70 |
$associations_response['condition'] = $peerinfo[7]; |
|
71 |
$associations_response['last_event'] = $peerinfo[8]; |
|
72 |
$associations_response['cnt'] = $peerinfo[9]; |
|
73 |
$ntpq_server_responses[$i] = $associations_response; |
|
74 |
} |
|
75 | ||
76 |
foreach ($ntpq_output as $i => $line) { |
|
59 | 77 |
$server = array(); |
60 | 78 |
$status_char = substr($line, 0, 1); |
61 | 79 |
$line = substr($line, 1); |
... | ... | |
72 | 90 |
$server['offset'] = $peerinfo[8]; |
73 | 91 |
$server['jitter'] = $peerinfo[9]; |
74 | 92 | |
93 |
$server['ind'] = $ntpq_server_responses[$i]['ind']; |
|
94 |
$server['assid'] = $ntpq_server_responses[$i]['assid']; |
|
95 |
$server['status_word'] = $ntpq_server_responses[$i]['status_word']; |
|
96 |
$server['conf'] = $ntpq_server_responses[$i]['conf']; |
|
97 |
$server['auth'] = $ntpq_server_responses[$i]['auth']; |
|
98 |
$server['condition'] = $ntpq_server_responses[$i]['condition']; |
|
99 |
$server['last_event'] = $ntpq_server_responses[$i]['last_event']; |
|
100 |
$server['cnt'] = $ntpq_server_responses[$i]['cnt']; |
|
101 | ||
75 | 102 |
switch ($status_char) { |
76 | 103 |
case " ": |
77 | 104 |
if ($server['refid'] == ".POOL.") { |
... | ... | |
252 | 279 |
print("<td>" . $server['delay'] . "</td>\n"); |
253 | 280 |
print("<td>" . $server['offset'] . "</td>\n"); |
254 | 281 |
print("<td>" . $server['jitter'] . "</td>\n"); |
282 |
print("<td>" . $server['assid'] . "</td>\n"); |
|
283 |
print("<td>" . $server['status_word'] . "</td>\n"); |
|
284 |
print("<td>" . $server['auth'] . "</td>\n"); |
|
255 | 285 |
print("</tr>\n"); |
256 | 286 |
$i++; |
257 | 287 |
endforeach; |
... | ... | |
332 | 362 |
<th><?=gettext("Delay (ms)")?></th> |
333 | 363 |
<th><?=gettext("Offset (ms)")?></th> |
334 | 364 |
<th><?=gettext("Jitter (ms)")?></th> |
365 |
<th><?=gettext("AssocID")?></th> |
|
366 |
<th><?=gettext("Status Word")?></th> |
|
367 |
<th><?=gettext("Auth")?></th> |
|
335 | 368 |
</tr> |
336 | 369 |
</thead> |
337 | 370 |
<tbody id="ntpbody"> |
- « Previous
- 1
- …
- 6
- 7
- 8
- Next »