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