1 |
0461114f
|
Seth Mos
|
<?php
|
2 |
|
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* diag_ndp.php
|
4 |
9da2cf1c
|
Stephen Beaver
|
*
|
5 |
c5d81585
|
Renato Botelho
|
* 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 |
fd9ebcd5
|
Stephen Beaver
|
*
|
10 |
c5d81585
|
Renato Botelho
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
11 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
12 |
|
|
* All rights reserved.
|
13 |
fd9ebcd5
|
Stephen Beaver
|
*
|
14 |
b12ea3fb
|
Renato Botelho
|
* 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 |
fd9ebcd5
|
Stephen Beaver
|
*
|
18 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
19 |
fd9ebcd5
|
Stephen Beaver
|
*
|
20 |
b12ea3fb
|
Renato Botelho
|
* 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 |
fd9ebcd5
|
Stephen Beaver
|
*/
|
26 |
0461114f
|
Seth Mos
|
|
27 |
|
|
##|+PRIV
|
28 |
|
|
##|*IDENT=page-diagnostics-ndptable
|
29 |
5230f468
|
jim-p
|
##|*NAME=Diagnostics: NDP Table
|
30 |
0461114f
|
Seth Mos
|
##|*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 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
38 |
0461114f
|
Seth Mos
|
|
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 |
45d6ada5
|
Sjon Hortensius
|
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
|
51 |
|
|
[3] => Netif [4] => Expire [5] => S
|
52 |
0461114f
|
Seth Mos
|
[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 |
699737d9
|
Phil Davis
|
function _getHostName($mac, $ip) {
|
67 |
5f601060
|
Phil Davis
|
if (is_ipaddr($ip)) {
|
68 |
30416166
|
jim-p
|
list($ip, $scope) = explode("%", $ip);
|
69 |
5f601060
|
Phil Davis
|
if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
|
70 |
0461114f
|
Seth Mos
|
return gethostbyaddr($ip);
|
71 |
5f601060
|
Phil Davis
|
} else {
|
72 |
0461114f
|
Seth Mos
|
return "";
|
73 |
5f601060
|
Phil Davis
|
}
|
74 |
0461114f
|
Seth Mos
|
}
|
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 |
5f601060
|
Phil Davis
|
if (trim($dns)) {
|
83 |
0461114f
|
Seth Mos
|
$entry['dnsresolve'] = "$dns";
|
84 |
5f601060
|
Phil Davis
|
} else {
|
85 |
0461114f
|
Seth Mos
|
$entry['dnsresolve'] = "Z_ ";
|
86 |
5f601060
|
Phil Davis
|
}
|
87 |
0461114f
|
Seth Mos
|
}
|
88 |
8ed2d200
|
NewEraCracker
|
unset($entry);
|
89 |
45d6ada5
|
Sjon Hortensius
|
|
90 |
0461114f
|
Seth Mos
|
// Sort the data alpha first
|
91 |
|
|
$data = msort($data, "dnsresolve");
|
92 |
|
|
|
93 |
9cd01cd6
|
jim-p
|
// Load MAC-Manufacturer table
|
94 |
|
|
$mac_man = load_mac_manufacturer_table();
|
95 |
|
|
|
96 |
699737d9
|
Phil Davis
|
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
|
97 |
0461114f
|
Seth Mos
|
include("head.inc");
|
98 |
|
|
?>
|
99 |
|
|
|
100 |
ac950976
|
Colin Fleming
|
<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 |
45d6ada5
|
Sjon Hortensius
|
<div class="table-responsive">
|
105 |
10fe1eb5
|
Stephen Beaver
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
|
106 |
|
|
<thead>
|
107 |
45d6ada5
|
Sjon Hortensius
|
<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 |
0461114f
|
Seth Mos
|
<tr>
|
117 |
45d6ada5
|
Sjon Hortensius
|
<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 |
fa172bc5
|
NewEraCracker
|
<?php if (isset($mac_man[$mac_hi])):?>
|
126 |
45d6ada5
|
Sjon Hortensius
|
(<?=$mac_man[$mac_hi]?>)
|
127 |
07a7b6db
|
NewEraCracker
|
<?php endif; ?>
|
128 |
45d6ada5
|
Sjon Hortensius
|
|
129 |
|
|
</td>
|
130 |
|
|
<td>
|
131 |
|
|
<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
|
132 |
|
|
</td>
|
133 |
|
|
<td>
|
134 |
|
|
<?php
|
135 |
947141fd
|
Phil Davis
|
if (isset($hwif[$entry['interface']])) {
|
136 |
45d6ada5
|
Sjon Hortensius
|
echo $hwif[$entry['interface']];
|
137 |
947141fd
|
Phil Davis
|
} else {
|
138 |
45d6ada5
|
Sjon Hortensius
|
echo $entry['interface'];
|
139 |
947141fd
|
Phil Davis
|
}
|
140 |
45d6ada5
|
Sjon Hortensius
|
?>
|
141 |
|
|
</td>
|
142 |
0461114f
|
Seth Mos
|
</tr>
|
143 |
45d6ada5
|
Sjon Hortensius
|
<?php endforeach; ?>
|
144 |
|
|
</tbody>
|
145 |
|
|
</table>
|
146 |
|
|
</div>
|
147 |
|
|
|
148 |
ac950976
|
Colin Fleming
|
</div>
|
149 |
|
|
</div>
|
150 |
|
|
|
151 |
c10cb196
|
Stephen Beaver
|
<?php include("foot.inc");
|