1 |
0461114f
|
Seth Mos
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
diag_ndp.php
|
4 |
|
|
*/
|
5 |
fd9ebcd5
|
Stephen Beaver
|
/* ====================================================================
|
6 |
|
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7 |
|
|
* Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
|
8 |
|
|
* Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>
|
9 |
|
|
* Part of the pfSense project (https://www.pfsense.org)
|
10 |
|
|
*
|
11 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
12 |
|
|
* are permitted provided that the following conditions are met:
|
13 |
|
|
*
|
14 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
* this list of conditions and the following disclaimer.
|
16 |
|
|
*
|
17 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
18 |
|
|
* notice, this list of conditions and the following disclaimer in
|
19 |
|
|
* the documentation and/or other materials provided with the
|
20 |
|
|
* distribution.
|
21 |
|
|
*
|
22 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
23 |
|
|
* must display the following acknowledgment:
|
24 |
|
|
* "This product includes software developed by the pfSense Project
|
25 |
|
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
26 |
|
|
*
|
27 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
28 |
|
|
* endorse or promote products derived from this software without
|
29 |
|
|
* prior written permission. For written permission, please contact
|
30 |
|
|
* coreteam@pfsense.org.
|
31 |
|
|
*
|
32 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
33 |
|
|
* nor may "pfSense" appear in their names without prior written
|
34 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
35 |
|
|
*
|
36 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
37 |
|
|
* acknowledgment:
|
38 |
|
|
*
|
39 |
|
|
* "This product includes software developed by the pfSense Project
|
40 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
41 |
|
|
*
|
42 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
43 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
45 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
46 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
50 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
53 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
54 |
|
|
*
|
55 |
|
|
* ====================================================================
|
56 |
|
|
*
|
57 |
|
|
*/
|
58 |
0461114f
|
Seth Mos
|
|
59 |
|
|
/*
|
60 |
|
|
pfSense_BUILDER_BINARIES: /bin/cat /usr/sbin/arp
|
61 |
45d6ada5
|
Sjon Hortensius
|
pfSense_MODULE: arp
|
62 |
0461114f
|
Seth Mos
|
*/
|
63 |
|
|
|
64 |
|
|
##|+PRIV
|
65 |
|
|
##|*IDENT=page-diagnostics-ndptable
|
66 |
|
|
##|*NAME=Diagnostics: NDP Table page
|
67 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
|
68 |
|
|
##|*MATCH=diag_ndp.php*
|
69 |
|
|
##|-PRIV
|
70 |
|
|
|
71 |
|
|
@ini_set('zlib.output_compression', 0);
|
72 |
|
|
@ini_set('implicit_flush', 1);
|
73 |
|
|
|
74 |
|
|
require("guiconfig.inc");
|
75 |
|
|
|
76 |
|
|
exec("/usr/sbin/ndp -na", $rawdata);
|
77 |
|
|
|
78 |
|
|
$i = 0;
|
79 |
|
|
|
80 |
|
|
/* if list */
|
81 |
|
|
$ifdescrs = get_configured_interface_with_descr();
|
82 |
|
|
|
83 |
|
|
foreach ($ifdescrs as $key =>$interface) {
|
84 |
|
|
$hwif[$config['interfaces'][$key]['if']] = $interface;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
45d6ada5
|
Sjon Hortensius
|
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
|
88 |
|
|
[3] => Netif [4] => Expire [5] => S
|
89 |
0461114f
|
Seth Mos
|
[6] => Flags ) */
|
90 |
|
|
$data = array();
|
91 |
|
|
array_shift($rawdata);
|
92 |
|
|
foreach ($rawdata as $line) {
|
93 |
|
|
$elements = preg_split('/[ ]+/', $line);
|
94 |
|
|
|
95 |
|
|
$ndpent = array();
|
96 |
|
|
$ndpent['ipv6'] = trim($elements[0]);
|
97 |
|
|
$ndpent['mac'] = trim($elements[1]);
|
98 |
|
|
$ndpent['interface'] = trim($elements[2]);
|
99 |
|
|
$data[] = $ndpent;
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
|
103 |
699737d9
|
Phil Davis
|
function _getHostName($mac, $ip) {
|
104 |
5f601060
|
Phil Davis
|
if (is_ipaddr($ip)) {
|
105 |
30416166
|
jim-p
|
list($ip, $scope) = explode("%", $ip);
|
106 |
5f601060
|
Phil Davis
|
if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
|
107 |
0461114f
|
Seth Mos
|
return gethostbyaddr($ip);
|
108 |
5f601060
|
Phil Davis
|
} else {
|
109 |
0461114f
|
Seth Mos
|
return "";
|
110 |
5f601060
|
Phil Davis
|
}
|
111 |
0461114f
|
Seth Mos
|
}
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
// Resolve hostnames and replace Z_ with "". The intention
|
115 |
|
|
// is to sort the list by hostnames, alpha and then the non
|
116 |
|
|
// resolvable addresses will appear last in the list.
|
117 |
|
|
foreach ($data as &$entry) {
|
118 |
|
|
$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
|
119 |
5f601060
|
Phil Davis
|
if (trim($dns)) {
|
120 |
0461114f
|
Seth Mos
|
$entry['dnsresolve'] = "$dns";
|
121 |
5f601060
|
Phil Davis
|
} else {
|
122 |
0461114f
|
Seth Mos
|
$entry['dnsresolve'] = "Z_ ";
|
123 |
5f601060
|
Phil Davis
|
}
|
124 |
0461114f
|
Seth Mos
|
}
|
125 |
45d6ada5
|
Sjon Hortensius
|
|
126 |
0461114f
|
Seth Mos
|
// Sort the data alpha first
|
127 |
|
|
$data = msort($data, "dnsresolve");
|
128 |
|
|
|
129 |
9cd01cd6
|
jim-p
|
// Load MAC-Manufacturer table
|
130 |
|
|
$mac_man = load_mac_manufacturer_table();
|
131 |
|
|
|
132 |
699737d9
|
Phil Davis
|
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
|
133 |
0461114f
|
Seth Mos
|
include("head.inc");
|
134 |
|
|
?>
|
135 |
|
|
|
136 |
45d6ada5
|
Sjon Hortensius
|
<div class="table-responsive">
|
137 |
|
|
<table class="table table-striped table-hover">
|
138 |
|
|
<thead>
|
139 |
|
|
<tr>
|
140 |
|
|
<th><?= gettext("IPv6 address"); ?></th>
|
141 |
|
|
<th><?= gettext("MAC address"); ?></th>
|
142 |
|
|
<th><?= gettext("Hostname"); ?></th>
|
143 |
|
|
<th><?= gettext("Interface"); ?></th>
|
144 |
|
|
</tr>
|
145 |
|
|
</thead>
|
146 |
|
|
<tbody>
|
147 |
|
|
<?php foreach ($data as $entry): ?>
|
148 |
0461114f
|
Seth Mos
|
<tr>
|
149 |
45d6ada5
|
Sjon Hortensius
|
<td><?=$entry['ipv6']?></td>
|
150 |
|
|
<td>
|
151 |
|
|
<?php
|
152 |
|
|
$mac=trim($entry['mac']);
|
153 |
|
|
$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
|
154 |
|
|
?>
|
155 |
|
|
<?=$mac?>
|
156 |
|
|
|
157 |
288a2a0f
|
Phil Davis
|
<? if (isset($mac_man[$mac_hi])):?>
|
158 |
45d6ada5
|
Sjon Hortensius
|
(<?=$mac_man[$mac_hi]?>)
|
159 |
|
|
<?endif?>
|
160 |
|
|
|
161 |
|
|
</td>
|
162 |
|
|
<td>
|
163 |
|
|
<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
|
164 |
|
|
</td>
|
165 |
|
|
<td>
|
166 |
|
|
<?php
|
167 |
288a2a0f
|
Phil Davis
|
if (isset($hwif[$entry['interface']]))
|
168 |
45d6ada5
|
Sjon Hortensius
|
echo $hwif[$entry['interface']];
|
169 |
|
|
else
|
170 |
|
|
echo $entry['interface'];
|
171 |
|
|
?>
|
172 |
|
|
</td>
|
173 |
0461114f
|
Seth Mos
|
</tr>
|
174 |
45d6ada5
|
Sjon Hortensius
|
<?php endforeach; ?>
|
175 |
|
|
</tbody>
|
176 |
|
|
</table>
|
177 |
|
|
</div>
|
178 |
|
|
|
179 |
|
|
<?php include("foot.inc");
|