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 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
0284d79e
|
jim-p
|
* Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
|
9 |
c5d81585
|
Renato Botelho
|
* Copyright (c) 2011 Seth Mos <seth.mos@dds.nl>
|
10 |
|
|
* All rights reserved.
|
11 |
fd9ebcd5
|
Stephen Beaver
|
*
|
12 |
c5d81585
|
Renato Botelho
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
13 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
14 |
|
|
* All rights reserved.
|
15 |
fd9ebcd5
|
Stephen Beaver
|
*
|
16 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
17 |
|
|
* you may not use this file except in compliance with the License.
|
18 |
|
|
* You may obtain a copy of the License at
|
19 |
fd9ebcd5
|
Stephen Beaver
|
*
|
20 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
21 |
fd9ebcd5
|
Stephen Beaver
|
*
|
22 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
23 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
24 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
25 |
|
|
* See the License for the specific language governing permissions and
|
26 |
|
|
* limitations under the License.
|
27 |
fd9ebcd5
|
Stephen Beaver
|
*/
|
28 |
0461114f
|
Seth Mos
|
|
29 |
|
|
##|+PRIV
|
30 |
|
|
##|*IDENT=page-diagnostics-ndptable
|
31 |
5230f468
|
jim-p
|
##|*NAME=Diagnostics: NDP Table
|
32 |
0461114f
|
Seth Mos
|
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
|
33 |
|
|
##|*MATCH=diag_ndp.php*
|
34 |
|
|
##|-PRIV
|
35 |
|
|
|
36 |
|
|
@ini_set('zlib.output_compression', 0);
|
37 |
|
|
@ini_set('implicit_flush', 1);
|
38 |
13105d9c
|
Sergio Carlos Morales Angeles
|
define('NDP_BINARY_PATH', '/usr/sbin/ndp');
|
39 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
40 |
0461114f
|
Seth Mos
|
|
41 |
13105d9c
|
Sergio Carlos Morales Angeles
|
// Delete ndp entry.
|
42 |
|
|
if (isset($_POST['deleteentry'])) {
|
43 |
|
|
$ip = $_POST['deleteentry'];
|
44 |
|
|
if (is_ipaddrv6($ip)) {
|
45 |
1d92faa3
|
Sergio Carlos Morales Angeles
|
$commandReturnValue = mwexec(NDP_BINARY_PATH . " -d " . escapeshellarg($ip), true);
|
46 |
13105d9c
|
Sergio Carlos Morales Angeles
|
$deleteSucceededFlag = ($commandReturnValue == 0);
|
47 |
|
|
} else {
|
48 |
|
|
$deleteSucceededFlag = false;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
$deleteResultMessage = ($deleteSucceededFlag)
|
52 |
|
|
? sprintf(gettext("The NDP entry for %s has been deleted."), $ip)
|
53 |
|
|
: sprintf(gettext("%s is not a valid IPv6 address or could not be deleted."), $ip);
|
54 |
|
|
$deleteResultMessageType = ($deleteSucceededFlag)
|
55 |
|
|
? 'success'
|
56 |
|
|
: 'alert-warning';
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
exec(NDP_BINARY_PATH . " -na", $rawdata);
|
60 |
0461114f
|
Seth Mos
|
|
61 |
|
|
$i = 0;
|
62 |
|
|
|
63 |
|
|
/* if list */
|
64 |
|
|
$ifdescrs = get_configured_interface_with_descr();
|
65 |
|
|
|
66 |
|
|
foreach ($ifdescrs as $key =>$interface) {
|
67 |
|
|
$hwif[$config['interfaces'][$key]['if']] = $interface;
|
68 |
|
|
}
|
69 |
|
|
|
70 |
fec2c3b7
|
Sergio Carlos Morales Angeles
|
/*
|
71 |
|
|
* Key map for each element in $rawdata
|
72 |
|
|
* 0 => Neighbor IP
|
73 |
|
|
* 1 => Physical address (MAC)
|
74 |
|
|
* 2 => Interface
|
75 |
|
|
* 3 => Expiration
|
76 |
|
|
* 4 => State
|
77 |
|
|
* 5 => Flags
|
78 |
|
|
*/
|
79 |
0461114f
|
Seth Mos
|
$data = array();
|
80 |
|
|
array_shift($rawdata);
|
81 |
|
|
foreach ($rawdata as $line) {
|
82 |
|
|
$elements = preg_split('/[ ]+/', $line);
|
83 |
|
|
|
84 |
|
|
$ndpent = array();
|
85 |
|
|
$ndpent['ipv6'] = trim($elements[0]);
|
86 |
|
|
$ndpent['mac'] = trim($elements[1]);
|
87 |
|
|
$ndpent['interface'] = trim($elements[2]);
|
88 |
fec2c3b7
|
Sergio Carlos Morales Angeles
|
$ndpent['expiration'] = trim($elements[3]);
|
89 |
0461114f
|
Seth Mos
|
$data[] = $ndpent;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
|
93 |
699737d9
|
Phil Davis
|
function _getHostName($mac, $ip) {
|
94 |
5f601060
|
Phil Davis
|
if (is_ipaddr($ip)) {
|
95 |
30416166
|
jim-p
|
list($ip, $scope) = explode("%", $ip);
|
96 |
5f601060
|
Phil Davis
|
if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
|
97 |
0461114f
|
Seth Mos
|
return gethostbyaddr($ip);
|
98 |
5f601060
|
Phil Davis
|
} else {
|
99 |
0461114f
|
Seth Mos
|
return "";
|
100 |
5f601060
|
Phil Davis
|
}
|
101 |
0461114f
|
Seth Mos
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
// Resolve hostnames and replace Z_ with "". The intention
|
105 |
|
|
// is to sort the list by hostnames, alpha and then the non
|
106 |
|
|
// resolvable addresses will appear last in the list.
|
107 |
|
|
foreach ($data as &$entry) {
|
108 |
|
|
$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
|
109 |
5f601060
|
Phil Davis
|
if (trim($dns)) {
|
110 |
0461114f
|
Seth Mos
|
$entry['dnsresolve'] = "$dns";
|
111 |
5f601060
|
Phil Davis
|
} else {
|
112 |
0461114f
|
Seth Mos
|
$entry['dnsresolve'] = "Z_ ";
|
113 |
5f601060
|
Phil Davis
|
}
|
114 |
0461114f
|
Seth Mos
|
}
|
115 |
8ed2d200
|
NewEraCracker
|
unset($entry);
|
116 |
45d6ada5
|
Sjon Hortensius
|
|
117 |
0461114f
|
Seth Mos
|
// Sort the data alpha first
|
118 |
|
|
$data = msort($data, "dnsresolve");
|
119 |
|
|
|
120 |
9cd01cd6
|
jim-p
|
// Load MAC-Manufacturer table
|
121 |
|
|
$mac_man = load_mac_manufacturer_table();
|
122 |
|
|
|
123 |
699737d9
|
Phil Davis
|
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
|
124 |
0461114f
|
Seth Mos
|
include("head.inc");
|
125 |
13105d9c
|
Sergio Carlos Morales Angeles
|
|
126 |
|
|
// Show message if defined.
|
127 |
|
|
if (isset($deleteResultMessage, $deleteResultMessageType)) {
|
128 |
|
|
print_info_box(htmlentities($deleteResultMessage), $deleteResultMessageType);
|
129 |
|
|
}
|
130 |
0461114f
|
Seth Mos
|
?>
|
131 |
|
|
|
132 |
9297ad65
|
jim-p
|
<div class="panel panel-default" id="search-panel">
|
133 |
|
|
<div class="panel-heading">
|
134 |
|
|
<h2 class="panel-title">
|
135 |
|
|
<?=gettext('Search')?>
|
136 |
|
|
<span class="widget-heading-icon pull-right">
|
137 |
|
|
<a data-toggle="collapse" href="#search-panel_panel-body">
|
138 |
|
|
<i class="fa fa-plus-circle"></i>
|
139 |
|
|
</a>
|
140 |
|
|
</span>
|
141 |
|
|
</h2>
|
142 |
|
|
</div>
|
143 |
|
|
<div id="search-panel_panel-body" class="panel-body collapse in">
|
144 |
|
|
<div class="form-group">
|
145 |
|
|
<label class="col-sm-2 control-label">
|
146 |
|
|
<?=gettext("Search term")?>
|
147 |
|
|
</label>
|
148 |
|
|
<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
|
149 |
|
|
<div class="col-sm-2">
|
150 |
|
|
<select id="where" class="form-control">
|
151 |
|
|
<option value="0"><?=gettext("IPv6 Address")?></option>
|
152 |
|
|
<option value="1"><?=gettext("MAC Address")?></option>
|
153 |
|
|
<option value="2"><?=gettext("Hostname")?></option>
|
154 |
|
|
<option value="3"><?=gettext("Interface")?></option>
|
155 |
|
|
<option value="4"><?=gettext("Expiration")?></option>
|
156 |
|
|
<option value="5" selected><?=gettext("All")?></option>
|
157 |
|
|
</select>
|
158 |
|
|
</div>
|
159 |
|
|
<div class="col-sm-3">
|
160 |
|
|
<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
|
161 |
|
|
<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
|
162 |
|
|
</div>
|
163 |
|
|
<div class="col-sm-10 col-sm-offset-2">
|
164 |
|
|
<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to filter entries.')?></span>
|
165 |
|
|
</div>
|
166 |
|
|
</div>
|
167 |
|
|
</div>
|
168 |
|
|
</div>
|
169 |
|
|
|
170 |
ac950976
|
Colin Fleming
|
<div class="panel panel-default">
|
171 |
|
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('NDP Table')?></h2></div>
|
172 |
|
|
<div class="panel-body">
|
173 |
|
|
|
174 |
45d6ada5
|
Sjon Hortensius
|
<div class="table-responsive">
|
175 |
10fe1eb5
|
Stephen Beaver
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
|
176 |
|
|
<thead>
|
177 |
45d6ada5
|
Sjon Hortensius
|
<tr>
|
178 |
fec2c3b7
|
Sergio Carlos Morales Angeles
|
<th><?=gettext("IPv6 address")?></th>
|
179 |
|
|
<th><?=gettext("MAC address")?></th>
|
180 |
|
|
<th><?=gettext("Hostname")?></th>
|
181 |
|
|
<th><?=gettext("Interface")?></th>
|
182 |
|
|
<th><?=gettext("Expiration")?></th>
|
183 |
13105d9c
|
Sergio Carlos Morales Angeles
|
<th data-sortable="false"><?=gettext("Actions")?></th>
|
184 |
45d6ada5
|
Sjon Hortensius
|
</tr>
|
185 |
|
|
</thead>
|
186 |
|
|
<tbody>
|
187 |
|
|
<?php foreach ($data as $entry): ?>
|
188 |
0461114f
|
Seth Mos
|
<tr>
|
189 |
45d6ada5
|
Sjon Hortensius
|
<td><?=$entry['ipv6']?></td>
|
190 |
|
|
<td>
|
191 |
|
|
<?php
|
192 |
|
|
$mac=trim($entry['mac']);
|
193 |
|
|
$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
|
194 |
|
|
?>
|
195 |
|
|
<?=$mac?>
|
196 |
|
|
|
197 |
fa172bc5
|
NewEraCracker
|
<?php if (isset($mac_man[$mac_hi])):?>
|
198 |
45d6ada5
|
Sjon Hortensius
|
(<?=$mac_man[$mac_hi]?>)
|
199 |
07a7b6db
|
NewEraCracker
|
<?php endif; ?>
|
200 |
45d6ada5
|
Sjon Hortensius
|
|
201 |
|
|
</td>
|
202 |
|
|
<td>
|
203 |
|
|
<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
|
204 |
|
|
</td>
|
205 |
|
|
<td>
|
206 |
|
|
<?php
|
207 |
947141fd
|
Phil Davis
|
if (isset($hwif[$entry['interface']])) {
|
208 |
45d6ada5
|
Sjon Hortensius
|
echo $hwif[$entry['interface']];
|
209 |
947141fd
|
Phil Davis
|
} else {
|
210 |
45d6ada5
|
Sjon Hortensius
|
echo $entry['interface'];
|
211 |
947141fd
|
Phil Davis
|
}
|
212 |
45d6ada5
|
Sjon Hortensius
|
?>
|
213 |
|
|
</td>
|
214 |
fec2c3b7
|
Sergio Carlos Morales Angeles
|
<td>
|
215 |
|
|
<?=$entry['expiration']?>
|
216 |
|
|
</td>
|
217 |
13105d9c
|
Sergio Carlos Morales Angeles
|
<td>
|
218 |
|
|
<a class="fa fa-trash" title="<?=gettext('Delete NDP entry')?>" href="diag_ndp.php?deleteentry=<?=$entry['ipv6']?>" usepost></a>
|
219 |
|
|
</td>
|
220 |
0461114f
|
Seth Mos
|
</tr>
|
221 |
45d6ada5
|
Sjon Hortensius
|
<?php endforeach; ?>
|
222 |
|
|
</tbody>
|
223 |
|
|
</table>
|
224 |
|
|
</div>
|
225 |
|
|
|
226 |
ac950976
|
Colin Fleming
|
</div>
|
227 |
|
|
</div>
|
228 |
|
|
|
229 |
9297ad65
|
jim-p
|
<script type="text/javascript">
|
230 |
|
|
//<![CDATA[
|
231 |
|
|
events.push(function() {
|
232 |
|
|
// Make these controls plain buttons
|
233 |
|
|
$("#btnsearch").prop('type', 'button');
|
234 |
|
|
$("#btnclear").prop('type', 'button');
|
235 |
|
|
|
236 |
|
|
// Search for a term in the entry name and/or dn
|
237 |
|
|
$("#btnsearch").click(function() {
|
238 |
|
|
var searchstr = $('#searchstr').val().toLowerCase();
|
239 |
|
|
var table = $("table tbody");
|
240 |
|
|
var where = $('#where').val();
|
241 |
|
|
|
242 |
|
|
table.find('tr').each(function (i) {
|
243 |
|
|
var $tds = $(this).find('td'),
|
244 |
|
|
ipaddr = $tds.eq(0).text().trim().toLowerCase();
|
245 |
|
|
macaddr = $tds.eq(1).text().trim().toLowerCase();
|
246 |
|
|
hostname = $tds.eq(2).text().trim().toLowerCase();
|
247 |
|
|
iface = $tds.eq(3).text().trim().toLowerCase(),
|
248 |
|
|
stat = $tds.eq(4).text().trim().toLowerCase();
|
249 |
|
|
|
250 |
|
|
regexp = new RegExp(searchstr);
|
251 |
|
|
if (searchstr.length > 0) {
|
252 |
|
|
if (!(regexp.test(ipaddr) && ((where == 0) || (where == 5))) &&
|
253 |
|
|
!(regexp.test(macaddr) && ((where == 1) || (where == 5))) &&
|
254 |
|
|
!(regexp.test(hostname) && ((where == 2) || (where == 5))) &&
|
255 |
|
|
!(regexp.test(iface) && ((where == 3) || (where == 5))) &&
|
256 |
|
|
!(regexp.test(stat) && ((where == 4) || (where == 5)))
|
257 |
|
|
) {
|
258 |
|
|
$(this).hide();
|
259 |
|
|
} else {
|
260 |
|
|
$(this).show();
|
261 |
|
|
}
|
262 |
|
|
} else {
|
263 |
|
|
$(this).show(); // A blank search string shows all
|
264 |
|
|
}
|
265 |
|
|
});
|
266 |
|
|
});
|
267 |
|
|
|
268 |
|
|
// Clear the search term and unhide all rows (that were hidden during a previous search)
|
269 |
|
|
$("#btnclear").click(function() {
|
270 |
|
|
var table = $("table tbody");
|
271 |
|
|
|
272 |
|
|
$('#searchstr').val("");
|
273 |
|
|
|
274 |
|
|
table.find('tr').each(function (i) {
|
275 |
|
|
$(this).show();
|
276 |
|
|
});
|
277 |
|
|
});
|
278 |
|
|
|
279 |
|
|
// Hitting the enter key will do the same as clicking the search button
|
280 |
|
|
$("#searchstr").on("keyup", function (event) {
|
281 |
|
|
if (event.keyCode == 13) {
|
282 |
|
|
$("#btnsearch").get(0).click();
|
283 |
|
|
}
|
284 |
|
|
});
|
285 |
|
|
|
286 |
|
|
});
|
287 |
|
|
//]]>
|
288 |
|
|
</script>
|
289 |
|
|
|
290 |
c10cb196
|
Stephen Beaver
|
<?php include("foot.inc");
|