Project

General

Profile

Feature #8794 » status_ntpd.php.auth.patch

Adds output of 'ntpq -c associations' to /usr/local/www/status_ntpd.php - LamaZ ., 03/03/2023 03:00 PM

View differences:

/usr/local/www/status_ntpd.php 2023-02-25 07:37:38.947966000 -0500
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();
59
	$ntpq_server_responses = array();
60
	$i = 0;
61
	foreach ($ntpq_associations_output as $line) {
62
		$associations_response = array();
63
                $peerinfo = preg_split("/[\s\t]+/", $line);
64
		
65
		$server['ind'] = $peerinfo[1];
66
                $associations_response['assid'] = $peerinfo[2];
67
                $associations_response['status_word'] = $peerinfo[3];
68
                $associations_response['conf'] = $peerinfo[4];
69
		$associations_response['reach'] = $peerinfo[5];
70
                $associations_response['auth'] = $peerinfo[6];
71
		$associations_response['condition'] = $peerinfo[7];
72
                $associations_response['last_event'] = $peerinfo[8];
73
                $associations_response['cnt'] = $peerinfo[9];
74

  
75

  
76
		$ntpq_server_responses[$i] = $associations_response;
77
		$i = $i +1;
78
	}
79
	
80
	$i = 0;
81

  
58 82
	foreach ($ntpq_output as $line) {
59 83
		$server = array();
60 84
		$status_char = substr($line, 0, 1);
......
72 96
		$server['offset'] = $peerinfo[8];
73 97
		$server['jitter'] = $peerinfo[9];
74 98

  
99
                $server['ind'] = $ntpq_server_responses[$i]['ind'];
100
                $server['assid'] = $ntpq_server_responses[$i]['assid'];
101
                $server['status_word'] = $ntpq_server_responses[$i]['status_word'];
102
                $server['conf'] = $ntpq_server_responses[$i]['conf'];
103
                $server['auth'] = $ntpq_server_responses[$i]['auth'];
104
                $server['condition'] = $ntpq_server_responses[$i]['condition'];
105
                $server['last_event'] = $ntpq_server_responses[$i]['last_event'];
106
                $server['cnt'] = $ntpq_server_responses[$i]['cnt'];
107

  
108
 
75 109
		switch ($status_char) {
76 110
			case " ":
77 111
				if ($server['refid'] == ".POOL.") {
......
104 138
		}
105 139

  
106 140
		$ntpq_servers[] = $server;
141
		$i = $i + 1;
107 142
	}
108 143

  
109 144
	exec("/usr/local/sbin/ntpq -c clockvar $inet_version", $ntpq_clockvar_output);
......
206 241
}
207 242

  
208 243
function print_status() {
209
	global $ntpq_servers, $allow_query;
244
	global $ntpq_servers, $allow_query, $ntpq_server_responses;
210 245

  
211 246
	if (config_get_path('ntpd/enable') == 'disabled'):
212 247
		print("<tr>\n");
......
242 277
			print("<td>" . $server['delay'] . "</td>\n");
243 278
			print("<td>" . $server['offset'] . "</td>\n");
244 279
			print("<td>" . $server['jitter'] . "</td>\n");
280
                        print("<td>" . $server['assid'] . "</td>\n");
281
                        print("<td>" . $server['status_word'] . "</td>\n");
282
                        print("<td>" . $server['auth'] . "</td>\n");
245 283
			print("</tr>\n");
246 284
			$i++;
247 285
		endforeach;
......
322 360
					<th><?=gettext("Delay (ms)")?></th>
323 361
					<th><?=gettext("Offset (ms)")?></th>
324 362
					<th><?=gettext("Jitter (ms)")?></th>
363
                                        <th><?=gettext("AssocID")?></th>
364
                                        <th><?=gettext("Status Word")?></th>
365
                                        <th><?=gettext("Auth")?></th>
325 366
				</tr>
326 367
			</thead>
327 368
			<tbody id="ntpbody">
(2-2/8)