Project

General

Profile

Download (3.83 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_ndp.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * Copyright (c) 2011 Seth Mos <seth.mos@dds.nl>
8
 * All rights reserved.
9
 *
10
 * originally based on m0n0wall (http://m0n0.ch/wall)
11
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
 * All rights reserved.
13
 *
14
 * Licensed under the Apache License, Version 2.0 (the "License");
15
 * you may not use this file except in compliance with the License.
16
 * You may obtain a copy of the License at
17
 *
18
 * http://www.apache.org/licenses/LICENSE-2.0
19
 *
20
 * Unless required by applicable law or agreed to in writing, software
21
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * See the License for the specific language governing permissions and
24
 * limitations under the License.
25
 */
26

    
27
##|+PRIV
28
##|*IDENT=page-diagnostics-ndptable
29
##|*NAME=Diagnostics: NDP Table
30
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
31
##|*MATCH=diag_ndp.php*
32
##|-PRIV
33

    
34
@ini_set('zlib.output_compression', 0);
35
@ini_set('implicit_flush', 1);
36

    
37
require_once("guiconfig.inc");
38

    
39
exec("/usr/sbin/ndp -na", $rawdata);
40

    
41
$i = 0;
42

    
43
/* if list */
44
$ifdescrs = get_configured_interface_with_descr();
45

    
46
foreach ($ifdescrs as $key =>$interface) {
47
	$hwif[$config['interfaces'][$key]['if']] = $interface;
48
}
49

    
50
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
51
[3] => Netif [4] => Expire [5] => S
52
[6] => Flags ) */
53
$data = array();
54
array_shift($rawdata);
55
foreach ($rawdata as $line) {
56
	$elements = preg_split('/[ ]+/', $line);
57

    
58
	$ndpent = array();
59
	$ndpent['ipv6'] = trim($elements[0]);
60
	$ndpent['mac'] = trim($elements[1]);
61
	$ndpent['interface'] = trim($elements[2]);
62
	$data[] = $ndpent;
63
}
64

    
65
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
66
function _getHostName($mac, $ip) {
67
	if (is_ipaddr($ip)) {
68
		list($ip, $scope) = explode("%", $ip);
69
		if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
70
			return gethostbyaddr($ip);
71
		} else {
72
			return "";
73
		}
74
	}
75
}
76

    
77
// Resolve hostnames and replace Z_ with "".  The intention
78
// is to sort the list by hostnames, alpha and then the non
79
// resolvable addresses will appear last in the list.
80
foreach ($data as &$entry) {
81
	$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
82
	if (trim($dns)) {
83
		$entry['dnsresolve'] = "$dns";
84
	} else {
85
		$entry['dnsresolve'] = "Z_ ";
86
	}
87
}
88
unset($entry);
89

    
90
// Sort the data alpha first
91
$data = msort($data, "dnsresolve");
92

    
93
// Load MAC-Manufacturer table
94
$mac_man = load_mac_manufacturer_table();
95

    
96
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
97
include("head.inc");
98
?>
99

    
100
<div class="panel panel-default">
101
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('NDP Table')?></h2></div>
102
	<div class="panel-body">
103

    
104
<div class="table-responsive">
105
	<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
106
		<thead>
107
			<tr>
108
				<th><?= gettext("IPv6 address"); ?></th>
109
				<th><?= gettext("MAC address"); ?></th>
110
				<th><?= gettext("Hostname"); ?></th>
111
				<th><?= gettext("Interface"); ?></th>
112
			</tr>
113
	</thead>
114
	<tbody>
115
			<?php foreach ($data as $entry): ?>
116
				<tr>
117
					<td><?=$entry['ipv6']?></td>
118
					<td>
119
						<?php
120
						$mac=trim($entry['mac']);
121
						$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
122
						?>
123
						<?=$mac?>
124

    
125
						<?php if (isset($mac_man[$mac_hi])):?>
126
							(<?=$mac_man[$mac_hi]?>)
127
						<?php endif; ?>
128

    
129
					</td>
130
					<td>
131
						<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
132
					</td>
133
					<td>
134
						<?php
135
						if (isset($hwif[$entry['interface']])) {
136
							echo $hwif[$entry['interface']];
137
						} else {
138
							echo $entry['interface'];
139
						}
140
						?>
141
					</td>
142
				</tr>
143
			<?php endforeach; ?>
144
	</tbody>
145
	</table>
146
</div>
147

    
148
	</div>
149
</div>
150

    
151
<?php include("foot.inc");
(18-18/227)