Project

General

Profile

Feature #8794 » 8794.patch

workaround patch - Marcos M, 01/10/2024 07:51 PM

View differences:

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)*/) {
2557
			$ntpcfg .= " key {$ntp_keyid} ";
2558
		}
2555 2559
		$ntpcfg .= "\n";
2556 2560
	}
2557 2561
	unset($ts);
src/usr/local/www/services_ntpd.php
99 99
	if (isset($pconfig['serverauth'])) {
100 100
		if (empty($pconfig['serverauthkey'])) {
101 101
			$input_errors[] = gettext("The supplied value for NTP Authentication key can't be empty.");
102
		} elseif (empty($pconfig['serverauthkeyid'])) {
103
			$input_errors[] = gettext("The authentication Key ID can't be empty.");
104
		} elseif (!ctype_digit($pconfig['serverauthkeyid'])) {
105
			$input_errors[] = gettext("The authentication Key ID must be a positive integer.");
106
		} elseif ($pconfig['serverauthkeyid'] < 1 || $pconfig['serverauthkeyid'] > 65535) {
107
			$input_errors[] = gettext("The authentication Key ID must be between 1-65535.");
102 108
		} elseif (($pconfig['serverauthalgo'] == 'md5') && ((strlen($pconfig['serverauthkey']) > 20) ||
103 109
		    !ctype_print($pconfig['serverauthkey']))) {
104 110
			$input_errors[] = gettext("The supplied value for NTP Authentication key for MD5 digest must be from 1 to 20 printable characters.");
......
212 218
		if (!empty($_POST['serverauth'])) {
213 219
			config_set_path('ntpd/serverauth', $_POST['serverauth']);
214 220
			config_set_path('ntpd/serverauthkey', base64_encode(trim($_POST['serverauthkey'])));
221
			config_set_path('ntpd/serverauthkeyid', $_POST['serverauthkeyid']);
215 222
			config_set_path('ntpd/serverauthalgo', $_POST['serverauthalgo']);
216 223
		} elseif (isset($config['ntpd']['serverauth'])) {
217 224
			config_del_path('ntpd/serverauth');
218 225
			config_del_path('ntpd/serverauthkey');
226
			config_del_path('ntpd/serverauthkeyid');
219 227
			config_del_path('ntpd/serverauthalgo');
220 228
		}
221 229

  
......
540 548
$group = new Form_Group('Authentication key');
541 549
$group->addClass('ntpserverauth');
542 550

  
543
$group->add(new Form_IpAddress(
551
$group->add(new Form_Input(
552
	'serverauthkeyid',
553
	'Key ID',
554
	null,
555
	$pconfig['serverauthkeyid'],
556
	['type' => 'number', 'min' => 1, 'max' => 65535, 'step' => 1]
557
))->setWidth(2)->setHelp('ID associated with the authentication key');
558

  
559
$group->add(new Form_Input(
544 560
	'serverauthkey',
545 561
	'NTP Authentication key',
562
	'text',
546 563
	base64_decode($pconfig['serverauthkey']),
547 564
	['placeholder' => 'NTP Authentication key']
548 565
))->setHelp(
......
557 574
	null,
558 575
	$pconfig['serverauthalgo'],
559 576
	$ntp_auth_halgos
560
))->setWidth(3)->setHelp('Digest algorithm');
577
))->setWidth(2)->setHelp('Digest algorithm');
561 578

  
562 579
$section->add($group);
563 580

  
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">
(7-7/8)