1
|
<?php
|
2
|
/*
|
3
|
* diag_ndp.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
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
|
* Redistribution and use in source and binary forms, with or without
|
15
|
* modification, are permitted provided that the following conditions are met:
|
16
|
*
|
17
|
* 1. Redistributions of source code must retain the above copyright notice,
|
18
|
* this list of conditions and the following disclaimer.
|
19
|
*
|
20
|
* 2. Redistributions in binary form must reproduce the above copyright
|
21
|
* notice, this list of conditions and the following disclaimer in
|
22
|
* the documentation and/or other materials provided with the
|
23
|
* distribution.
|
24
|
*
|
25
|
* 3. All advertising materials mentioning features or use of this software
|
26
|
* must display the following acknowledgment:
|
27
|
* "This product includes software developed by the pfSense Project
|
28
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
29
|
*
|
30
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
31
|
* endorse or promote products derived from this software without
|
32
|
* prior written permission. For written permission, please contact
|
33
|
* coreteam@pfsense.org.
|
34
|
*
|
35
|
* 5. Products derived from this software may not be called "pfSense"
|
36
|
* nor may "pfSense" appear in their names without prior written
|
37
|
* permission of the Electric Sheep Fencing, LLC.
|
38
|
*
|
39
|
* 6. Redistributions of any form whatsoever must retain the following
|
40
|
* acknowledgment:
|
41
|
*
|
42
|
* "This product includes software developed by the pfSense Project
|
43
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
44
|
*
|
45
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
46
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
47
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
48
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
49
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
50
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
51
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
52
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
53
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
54
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
55
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
56
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
57
|
*/
|
58
|
|
59
|
##|+PRIV
|
60
|
##|*IDENT=page-diagnostics-ndptable
|
61
|
##|*NAME=Diagnostics: NDP Table
|
62
|
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
|
63
|
##|*MATCH=diag_ndp.php*
|
64
|
##|-PRIV
|
65
|
|
66
|
@ini_set('zlib.output_compression', 0);
|
67
|
@ini_set('implicit_flush', 1);
|
68
|
define('NDP_BINARY_PATH', '/usr/sbin/ndp');
|
69
|
require_once("guiconfig.inc");
|
70
|
|
71
|
// Delete ndp entry.
|
72
|
if (isset($_POST['deleteentry'])) {
|
73
|
$ip = $_POST['deleteentry'];
|
74
|
if (is_ipaddrv6($ip)) {
|
75
|
$commandReturnValue = mwexec(NDP_BINARY_PATH . " -d " . escapeshellarg($ip), true);
|
76
|
$deleteSucceededFlag = ($commandReturnValue == 0);
|
77
|
} else {
|
78
|
$deleteSucceededFlag = false;
|
79
|
}
|
80
|
|
81
|
$deleteResultMessage = ($deleteSucceededFlag)
|
82
|
? sprintf(gettext("The NDP entry for %s has been deleted."), $ip)
|
83
|
: sprintf(gettext("%s is not a valid IPv6 address or could not be deleted."), $ip);
|
84
|
$deleteResultMessageType = ($deleteSucceededFlag)
|
85
|
? 'success'
|
86
|
: 'alert-warning';
|
87
|
}
|
88
|
|
89
|
exec(NDP_BINARY_PATH . " -na", $rawdata);
|
90
|
|
91
|
$i = 0;
|
92
|
|
93
|
/* if list */
|
94
|
$ifdescrs = get_configured_interface_with_descr();
|
95
|
|
96
|
foreach ($ifdescrs as $key =>$interface) {
|
97
|
$hwif[$config['interfaces'][$key]['if']] = $interface;
|
98
|
}
|
99
|
|
100
|
/*
|
101
|
* Key map for each element in $rawdata
|
102
|
* 0 => Neighbor IP
|
103
|
* 1 => Physical address (MAC)
|
104
|
* 2 => Interface
|
105
|
* 3 => Expiration
|
106
|
* 4 => State
|
107
|
* 5 => Flags
|
108
|
*/
|
109
|
$data = array();
|
110
|
array_shift($rawdata);
|
111
|
foreach ($rawdata as $line) {
|
112
|
$elements = preg_split('/[ ]+/', $line);
|
113
|
|
114
|
$ndpent = array();
|
115
|
$ndpent['ipv6'] = trim($elements[0]);
|
116
|
$ndpent['mac'] = trim($elements[1]);
|
117
|
$ndpent['interface'] = trim($elements[2]);
|
118
|
$ndpent['expiration'] = trim($elements[3]);
|
119
|
$data[] = $ndpent;
|
120
|
}
|
121
|
|
122
|
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
|
123
|
function _getHostName($mac, $ip) {
|
124
|
if (is_ipaddr($ip)) {
|
125
|
list($ip, $scope) = explode("%", $ip);
|
126
|
if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
|
127
|
return gethostbyaddr($ip);
|
128
|
} else {
|
129
|
return "";
|
130
|
}
|
131
|
}
|
132
|
}
|
133
|
|
134
|
// Resolve hostnames and replace Z_ with "". The intention
|
135
|
// is to sort the list by hostnames, alpha and then the non
|
136
|
// resolvable addresses will appear last in the list.
|
137
|
foreach ($data as &$entry) {
|
138
|
$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
|
139
|
if (trim($dns)) {
|
140
|
$entry['dnsresolve'] = "$dns";
|
141
|
} else {
|
142
|
$entry['dnsresolve'] = "Z_ ";
|
143
|
}
|
144
|
}
|
145
|
unset($entry);
|
146
|
|
147
|
// Sort the data alpha first
|
148
|
$data = msort($data, "dnsresolve");
|
149
|
|
150
|
// Load MAC-Manufacturer table
|
151
|
$mac_man = load_mac_manufacturer_table();
|
152
|
|
153
|
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
|
154
|
include("head.inc");
|
155
|
|
156
|
// Show message if defined.
|
157
|
if (isset($deleteResultMessage, $deleteResultMessageType)) {
|
158
|
print_info_box(htmlentities($deleteResultMessage), $deleteResultMessageType);
|
159
|
}
|
160
|
?>
|
161
|
|
162
|
<div class="panel panel-default">
|
163
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('NDP Table')?></h2></div>
|
164
|
<div class="panel-body">
|
165
|
|
166
|
<div class="table-responsive">
|
167
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
|
168
|
<thead>
|
169
|
<tr>
|
170
|
<th><?=gettext("IPv6 address")?></th>
|
171
|
<th><?=gettext("MAC address")?></th>
|
172
|
<th><?=gettext("Hostname")?></th>
|
173
|
<th><?=gettext("Interface")?></th>
|
174
|
<th><?=gettext("Expiration")?></th>
|
175
|
<th data-sortable="false"><?=gettext("Actions")?></th>
|
176
|
</tr>
|
177
|
</thead>
|
178
|
<tbody>
|
179
|
<?php foreach ($data as $entry): ?>
|
180
|
<tr>
|
181
|
<td><?=$entry['ipv6']?></td>
|
182
|
<td>
|
183
|
<?php
|
184
|
$mac=trim($entry['mac']);
|
185
|
$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
|
186
|
?>
|
187
|
<?=$mac?>
|
188
|
|
189
|
<?php if (isset($mac_man[$mac_hi])):?>
|
190
|
(<?=$mac_man[$mac_hi]?>)
|
191
|
<?php endif; ?>
|
192
|
|
193
|
</td>
|
194
|
<td>
|
195
|
<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
|
196
|
</td>
|
197
|
<td>
|
198
|
<?php
|
199
|
if (isset($hwif[$entry['interface']])) {
|
200
|
echo $hwif[$entry['interface']];
|
201
|
} else {
|
202
|
echo $entry['interface'];
|
203
|
}
|
204
|
?>
|
205
|
</td>
|
206
|
<td>
|
207
|
<?=$entry['expiration']?>
|
208
|
</td>
|
209
|
<td>
|
210
|
<a class="fa fa-trash" title="<?=gettext('Delete NDP entry')?>" href="diag_ndp.php?deleteentry=<?=$entry['ipv6']?>" usepost></a>
|
211
|
</td>
|
212
|
</tr>
|
213
|
<?php endforeach; ?>
|
214
|
</tbody>
|
215
|
</table>
|
216
|
</div>
|
217
|
|
218
|
</div>
|
219
|
</div>
|
220
|
|
221
|
<?php include("foot.inc");
|