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 |
402c98a2
|
Reid Linnemann
|
* Copyright (c) 2014-2023 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 |
6fe2387c
|
Viktor G
|
} elseif (isset($_POST['clearndptable'])) {
|
58 |
|
|
$out = "";
|
59 |
|
|
$ret = exec("/usr/sbin/ndp -c", $out, $ndpTableRetVal);
|
60 |
9bd56e9d
|
Christian McDonald
|
if ($ndpTableRetVal == 0) {
|
61 |
6fe2387c
|
Viktor G
|
$deleteResultMessage = gettext("NDP Table has been cleared.");
|
62 |
|
|
$deleteResultMessageType = 'success';
|
63 |
|
|
} else {
|
64 |
|
|
$deleteResultMessage = gettext("Unable to clear NDP Table.");
|
65 |
|
|
$deleteResultMessageType = 'alert-warning';
|
66 |
|
|
}
|
67 |
13105d9c
|
Sergio Carlos Morales Angeles
|
}
|
68 |
|
|
|
69 |
|
|
exec(NDP_BINARY_PATH . " -na", $rawdata);
|
70 |
0461114f
|
Seth Mos
|
|
71 |
|
|
$i = 0;
|
72 |
|
|
|
73 |
|
|
/* if list */
|
74 |
|
|
$ifdescrs = get_configured_interface_with_descr();
|
75 |
|
|
|
76 |
|
|
foreach ($ifdescrs as $key =>$interface) {
|
77 |
|
|
$hwif[$config['interfaces'][$key]['if']] = $interface;
|
78 |
|
|
}
|
79 |
|
|
|
80 |
fec2c3b7
|
Sergio Carlos Morales Angeles
|
/*
|
81 |
|
|
* Key map for each element in $rawdata
|
82 |
|
|
* 0 => Neighbor IP
|
83 |
|
|
* 1 => Physical address (MAC)
|
84 |
|
|
* 2 => Interface
|
85 |
|
|
* 3 => Expiration
|
86 |
|
|
* 4 => State
|
87 |
|
|
* 5 => Flags
|
88 |
|
|
*/
|
89 |
0461114f
|
Seth Mos
|
$data = array();
|
90 |
|
|
array_shift($rawdata);
|
91 |
|
|
foreach ($rawdata as $line) {
|
92 |
|
|
$elements = preg_split('/[ ]+/', $line);
|
93 |
|
|
|
94 |
|
|
$ndpent = array();
|
95 |
|
|
$ndpent['ipv6'] = trim($elements[0]);
|
96 |
|
|
$ndpent['mac'] = trim($elements[1]);
|
97 |
|
|
$ndpent['interface'] = trim($elements[2]);
|
98 |
fec2c3b7
|
Sergio Carlos Morales Angeles
|
$ndpent['expiration'] = trim($elements[3]);
|
99 |
0461114f
|
Seth Mos
|
$data[] = $ndpent;
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
// Resolve hostnames and replace Z_ with "". The intention
|
103 |
|
|
// is to sort the list by hostnames, alpha and then the non
|
104 |
|
|
// resolvable addresses will appear last in the list.
|
105 |
|
|
foreach ($data as &$entry) {
|
106 |
aa1936ee
|
Viktor G
|
if (is_null($dnsavailable)) {
|
107 |
|
|
$dnsavailable = check_dnsavailable('inet6');
|
108 |
|
|
}
|
109 |
|
|
if ($dnsavailable) {
|
110 |
|
|
$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
|
111 |
|
|
} else {
|
112 |
|
|
$dns = "";
|
113 |
|
|
}
|
114 |
5f601060
|
Phil Davis
|
if (trim($dns)) {
|
115 |
0461114f
|
Seth Mos
|
$entry['dnsresolve'] = "$dns";
|
116 |
5f601060
|
Phil Davis
|
} else {
|
117 |
0461114f
|
Seth Mos
|
$entry['dnsresolve'] = "Z_ ";
|
118 |
5f601060
|
Phil Davis
|
}
|
119 |
0461114f
|
Seth Mos
|
}
|
120 |
8ed2d200
|
NewEraCracker
|
unset($entry);
|
121 |
45d6ada5
|
Sjon Hortensius
|
|
122 |
0461114f
|
Seth Mos
|
// Sort the data alpha first
|
123 |
|
|
$data = msort($data, "dnsresolve");
|
124 |
|
|
|
125 |
9cd01cd6
|
jim-p
|
// Load MAC-Manufacturer table
|
126 |
|
|
$mac_man = load_mac_manufacturer_table();
|
127 |
|
|
|
128 |
699737d9
|
Phil Davis
|
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
|
129 |
0461114f
|
Seth Mos
|
include("head.inc");
|
130 |
13105d9c
|
Sergio Carlos Morales Angeles
|
|
131 |
|
|
// Show message if defined.
|
132 |
|
|
if (isset($deleteResultMessage, $deleteResultMessageType)) {
|
133 |
|
|
print_info_box(htmlentities($deleteResultMessage), $deleteResultMessageType);
|
134 |
|
|
}
|
135 |
0461114f
|
Seth Mos
|
?>
|
136 |
|
|
|
137 |
9297ad65
|
jim-p
|
<div class="panel panel-default" id="search-panel">
|
138 |
|
|
<div class="panel-heading">
|
139 |
|
|
<h2 class="panel-title">
|
140 |
|
|
<?=gettext('Search')?>
|
141 |
|
|
<span class="widget-heading-icon pull-right">
|
142 |
|
|
<a data-toggle="collapse" href="#search-panel_panel-body">
|
143 |
e0cb987c
|
Marcos Mendoza
|
<i class="fa-solid fa-plus-circle"></i>
|
144 |
9297ad65
|
jim-p
|
</a>
|
145 |
|
|
</span>
|
146 |
|
|
</h2>
|
147 |
|
|
</div>
|
148 |
|
|
<div id="search-panel_panel-body" class="panel-body collapse in">
|
149 |
|
|
<div class="form-group">
|
150 |
|
|
<label class="col-sm-2 control-label">
|
151 |
9bd56e9d
|
Christian McDonald
|
<?=gettext('Search Term')?>
|
152 |
9297ad65
|
jim-p
|
</label>
|
153 |
|
|
<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
|
154 |
|
|
<div class="col-sm-2">
|
155 |
|
|
<select id="where" class="form-control">
|
156 |
9bd56e9d
|
Christian McDonald
|
<option value="0"><?=gettext('IPv6 Address')?></option>
|
157 |
|
|
<option value="1"><?=gettext('MAC Address')?></option>
|
158 |
|
|
<option value="2"><?=gettext('Hostname')?></option>
|
159 |
|
|
<option value="3"><?=gettext('Interface')?></option>
|
160 |
|
|
<option value="4"><?=gettext('Expiration')?></option>
|
161 |
|
|
<option value="5" selected><?=gettext('All')?></option>
|
162 |
9297ad65
|
jim-p
|
</select>
|
163 |
|
|
</div>
|
164 |
|
|
<div class="col-sm-3">
|
165 |
e0cb987c
|
Marcos Mendoza
|
<a id="btnsearch" title="<?=gettext('Search')?>" class="btn btn-primary btn-sm"><i class="fa-solid fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
|
166 |
|
|
<a id="btnclear" title="<?=gettext('Clear')?>" class="btn btn-info btn-sm"><i class="fa-solid fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
|
167 |
9297ad65
|
jim-p
|
</div>
|
168 |
|
|
<div class="col-sm-10 col-sm-offset-2">
|
169 |
|
|
<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to filter entries.')?></span>
|
170 |
|
|
</div>
|
171 |
|
|
</div>
|
172 |
|
|
</div>
|
173 |
|
|
</div>
|
174 |
|
|
|
175 |
ac950976
|
Colin Fleming
|
<div class="panel panel-default">
|
176 |
|
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('NDP Table')?></h2></div>
|
177 |
|
|
<div class="panel-body">
|
178 |
|
|
|
179 |
45d6ada5
|
Sjon Hortensius
|
<div class="table-responsive">
|
180 |
10fe1eb5
|
Stephen Beaver
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
|
181 |
|
|
<thead>
|
182 |
45d6ada5
|
Sjon Hortensius
|
<tr>
|
183 |
9bd56e9d
|
Christian McDonald
|
<th><?=gettext('IPv6 Address')?></th>
|
184 |
|
|
<th><?=gettext('MAC Address')?></th>
|
185 |
|
|
<th><?=gettext('Hostname')?></th>
|
186 |
|
|
<th><?=gettext('Interface')?></th>
|
187 |
|
|
<th><?=gettext('Expiration')?></th>
|
188 |
|
|
<th data-sortable="false"><?=gettext('Actions')?></th>
|
189 |
45d6ada5
|
Sjon Hortensius
|
</tr>
|
190 |
|
|
</thead>
|
191 |
|
|
<tbody>
|
192 |
|
|
<?php foreach ($data as $entry): ?>
|
193 |
0461114f
|
Seth Mos
|
<tr>
|
194 |
45d6ada5
|
Sjon Hortensius
|
<td><?=$entry['ipv6']?></td>
|
195 |
|
|
<td>
|
196 |
|
|
<?php
|
197 |
|
|
$mac=trim($entry['mac']);
|
198 |
|
|
$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
|
199 |
|
|
?>
|
200 |
|
|
<?=$mac?>
|
201 |
|
|
|
202 |
fa172bc5
|
NewEraCracker
|
<?php if (isset($mac_man[$mac_hi])):?>
|
203 |
45d6ada5
|
Sjon Hortensius
|
(<?=$mac_man[$mac_hi]?>)
|
204 |
07a7b6db
|
NewEraCracker
|
<?php endif; ?>
|
205 |
45d6ada5
|
Sjon Hortensius
|
|
206 |
|
|
</td>
|
207 |
|
|
<td>
|
208 |
|
|
<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
|
209 |
|
|
</td>
|
210 |
|
|
<td>
|
211 |
|
|
<?php
|
212 |
947141fd
|
Phil Davis
|
if (isset($hwif[$entry['interface']])) {
|
213 |
45d6ada5
|
Sjon Hortensius
|
echo $hwif[$entry['interface']];
|
214 |
947141fd
|
Phil Davis
|
} else {
|
215 |
45d6ada5
|
Sjon Hortensius
|
echo $entry['interface'];
|
216 |
947141fd
|
Phil Davis
|
}
|
217 |
45d6ada5
|
Sjon Hortensius
|
?>
|
218 |
|
|
</td>
|
219 |
fec2c3b7
|
Sergio Carlos Morales Angeles
|
<td>
|
220 |
|
|
<?=$entry['expiration']?>
|
221 |
|
|
</td>
|
222 |
13105d9c
|
Sergio Carlos Morales Angeles
|
<td>
|
223 |
32be4696
|
Marcos Mendoza
|
<a class="fa-solid fa-trash-can" title="<?=gettext('Delete NDP entry')?>" href="diag_ndp.php?deleteentry=<?=$entry['ipv6']?>" usepost></a>
|
224 |
13105d9c
|
Sergio Carlos Morales Angeles
|
</td>
|
225 |
0461114f
|
Seth Mos
|
</tr>
|
226 |
45d6ada5
|
Sjon Hortensius
|
<?php endforeach; ?>
|
227 |
|
|
</tbody>
|
228 |
|
|
</table>
|
229 |
|
|
</div>
|
230 |
|
|
|
231 |
ac950976
|
Colin Fleming
|
</div>
|
232 |
|
|
</div>
|
233 |
|
|
|
234 |
6fe2387c
|
Viktor G
|
<nav class="action-buttons">
|
235 |
|
|
<button id="clearndp" class="btn btn-danger no-confirm">
|
236 |
32be4696
|
Marcos Mendoza
|
<i class="fa-solid fa-trash-can icon-embed-btn"></i>
|
237 |
6fe2387c
|
Viktor G
|
<?=gettext("Clear NDP Table")?>
|
238 |
|
|
</button>
|
239 |
|
|
</nav>
|
240 |
|
|
|
241 |
9297ad65
|
jim-p
|
<script type="text/javascript">
|
242 |
|
|
//<![CDATA[
|
243 |
|
|
events.push(function() {
|
244 |
|
|
// Make these controls plain buttons
|
245 |
|
|
$("#btnsearch").prop('type', 'button');
|
246 |
|
|
$("#btnclear").prop('type', 'button');
|
247 |
|
|
|
248 |
|
|
// Search for a term in the entry name and/or dn
|
249 |
|
|
$("#btnsearch").click(function() {
|
250 |
|
|
var searchstr = $('#searchstr').val().toLowerCase();
|
251 |
|
|
var table = $("table tbody");
|
252 |
|
|
var where = $('#where').val();
|
253 |
|
|
|
254 |
|
|
table.find('tr').each(function (i) {
|
255 |
|
|
var $tds = $(this).find('td'),
|
256 |
|
|
ipaddr = $tds.eq(0).text().trim().toLowerCase();
|
257 |
|
|
macaddr = $tds.eq(1).text().trim().toLowerCase();
|
258 |
|
|
hostname = $tds.eq(2).text().trim().toLowerCase();
|
259 |
|
|
iface = $tds.eq(3).text().trim().toLowerCase(),
|
260 |
|
|
stat = $tds.eq(4).text().trim().toLowerCase();
|
261 |
|
|
|
262 |
|
|
regexp = new RegExp(searchstr);
|
263 |
|
|
if (searchstr.length > 0) {
|
264 |
|
|
if (!(regexp.test(ipaddr) && ((where == 0) || (where == 5))) &&
|
265 |
|
|
!(regexp.test(macaddr) && ((where == 1) || (where == 5))) &&
|
266 |
|
|
!(regexp.test(hostname) && ((where == 2) || (where == 5))) &&
|
267 |
|
|
!(regexp.test(iface) && ((where == 3) || (where == 5))) &&
|
268 |
|
|
!(regexp.test(stat) && ((where == 4) || (where == 5)))
|
269 |
|
|
) {
|
270 |
|
|
$(this).hide();
|
271 |
|
|
} else {
|
272 |
|
|
$(this).show();
|
273 |
|
|
}
|
274 |
|
|
} else {
|
275 |
|
|
$(this).show(); // A blank search string shows all
|
276 |
|
|
}
|
277 |
|
|
});
|
278 |
|
|
});
|
279 |
|
|
|
280 |
|
|
// Clear the search term and unhide all rows (that were hidden during a previous search)
|
281 |
|
|
$("#btnclear").click(function() {
|
282 |
|
|
var table = $("table tbody");
|
283 |
|
|
|
284 |
|
|
$('#searchstr').val("");
|
285 |
|
|
|
286 |
9bd56e9d
|
Christian McDonald
|
$('#where option[value="5"]').prop('selected', true);
|
287 |
|
|
|
288 |
9297ad65
|
jim-p
|
table.find('tr').each(function (i) {
|
289 |
|
|
$(this).show();
|
290 |
|
|
});
|
291 |
|
|
});
|
292 |
|
|
|
293 |
|
|
// Hitting the enter key will do the same as clicking the search button
|
294 |
|
|
$("#searchstr").on("keyup", function (event) {
|
295 |
|
|
if (event.keyCode == 13) {
|
296 |
|
|
$("#btnsearch").get(0).click();
|
297 |
|
|
}
|
298 |
|
|
});
|
299 |
|
|
|
300 |
6fe2387c
|
Viktor G
|
$('#clearndp').click(function() {
|
301 |
9bd56e9d
|
Christian McDonald
|
if (confirm("<?=gettext('Are you sure you wish to clear NDP table?')?>")) {
|
302 |
6fe2387c
|
Viktor G
|
postSubmit({clearndptable: 'true'}, 'diag_ndp.php');
|
303 |
|
|
}
|
304 |
|
|
});
|
305 |
|
|
|
306 |
9297ad65
|
jim-p
|
});
|
307 |
|
|
//]]>
|
308 |
|
|
</script>
|
309 |
|
|
|
310 |
9bd56e9d
|
Christian McDonald
|
<?php
|
311 |
|
|
include('foot.inc');
|