1
|
<?php
|
2
|
/*
|
3
|
* diag_ndp.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
|
9
|
* Copyright (c) 2011 Seth Mos <seth.mos@dds.nl>
|
10
|
* All rights reserved.
|
11
|
*
|
12
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
13
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
14
|
* All rights reserved.
|
15
|
*
|
16
|
* 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
|
*
|
20
|
* http://www.apache.org/licenses/LICENSE-2.0
|
21
|
*
|
22
|
* 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
|
*/
|
28
|
|
29
|
##|+PRIV
|
30
|
##|*IDENT=page-diagnostics-ndptable
|
31
|
##|*NAME=Diagnostics: NDP Table
|
32
|
##|*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
|
define('NDP_BINARY_PATH', '/usr/sbin/ndp');
|
39
|
require_once("guiconfig.inc");
|
40
|
|
41
|
// Delete ndp entry.
|
42
|
if (isset($_POST['deleteentry'])) {
|
43
|
$ip = $_POST['deleteentry'];
|
44
|
if (is_ipaddrv6($ip)) {
|
45
|
$commandReturnValue = mwexec(NDP_BINARY_PATH . " -d " . escapeshellarg($ip), true);
|
46
|
$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
|
} elseif (isset($_POST['clearndptable'])) {
|
58
|
$out = "";
|
59
|
$ret = exec("/usr/sbin/ndp -c", $out, $ndpTableRetVal);
|
60
|
if ($ndpTableRetVal == 0) {
|
61
|
$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
|
}
|
68
|
|
69
|
exec(NDP_BINARY_PATH . " -na", $rawdata);
|
70
|
|
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
|
/*
|
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
|
$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
|
$ndpent['expiration'] = trim($elements[3]);
|
99
|
$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
|
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
|
if (trim($dns)) {
|
115
|
$entry['dnsresolve'] = "$dns";
|
116
|
} else {
|
117
|
$entry['dnsresolve'] = "Z_ ";
|
118
|
}
|
119
|
}
|
120
|
unset($entry);
|
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
|
// Show message if defined.
|
132
|
if (isset($deleteResultMessage, $deleteResultMessageType)) {
|
133
|
print_info_box(htmlentities($deleteResultMessage), $deleteResultMessageType);
|
134
|
}
|
135
|
?>
|
136
|
|
137
|
<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
|
<i class="fa fa-plus-circle"></i>
|
144
|
</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
|
<?=gettext("Search term")?>
|
152
|
</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
|
<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
|
</select>
|
163
|
</div>
|
164
|
<div class="col-sm-3">
|
165
|
<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa 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 fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
|
167
|
</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
|
<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
|
<div class="table-responsive">
|
180
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
|
181
|
<thead>
|
182
|
<tr>
|
183
|
<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
|
</tr>
|
190
|
</thead>
|
191
|
<tbody>
|
192
|
<?php foreach ($data as $entry): ?>
|
193
|
<tr>
|
194
|
<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
|
<?php if (isset($mac_man[$mac_hi])):?>
|
203
|
(<?=$mac_man[$mac_hi]?>)
|
204
|
<?php endif; ?>
|
205
|
|
206
|
</td>
|
207
|
<td>
|
208
|
<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
|
209
|
</td>
|
210
|
<td>
|
211
|
<?php
|
212
|
if (isset($hwif[$entry['interface']])) {
|
213
|
echo $hwif[$entry['interface']];
|
214
|
} else {
|
215
|
echo $entry['interface'];
|
216
|
}
|
217
|
?>
|
218
|
</td>
|
219
|
<td>
|
220
|
<?=$entry['expiration']?>
|
221
|
</td>
|
222
|
<td>
|
223
|
<a class="fa fa-trash" title="<?=gettext('Delete NDP entry')?>" href="diag_ndp.php?deleteentry=<?=$entry['ipv6']?>" usepost></a>
|
224
|
</td>
|
225
|
</tr>
|
226
|
<?php endforeach; ?>
|
227
|
</tbody>
|
228
|
</table>
|
229
|
</div>
|
230
|
|
231
|
</div>
|
232
|
</div>
|
233
|
|
234
|
<nav class="action-buttons">
|
235
|
<button id="clearndp" class="btn btn-danger no-confirm">
|
236
|
<i class="fa fa-trash icon-embed-btn"></i>
|
237
|
<?=gettext("Clear NDP Table")?>
|
238
|
</button>
|
239
|
</nav>
|
240
|
|
241
|
<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
|
table.find('tr').each(function (i) {
|
287
|
$(this).show();
|
288
|
});
|
289
|
});
|
290
|
|
291
|
// Hitting the enter key will do the same as clicking the search button
|
292
|
$("#searchstr").on("keyup", function (event) {
|
293
|
if (event.keyCode == 13) {
|
294
|
$("#btnsearch").get(0).click();
|
295
|
}
|
296
|
});
|
297
|
|
298
|
$('#clearndp').click(function() {
|
299
|
if (confirm("Are you sure you wish to clear NDP table?")) {
|
300
|
postSubmit({clearndptable: 'true'}, 'diag_ndp.php');
|
301
|
}
|
302
|
});
|
303
|
|
304
|
});
|
305
|
//]]>
|
306
|
</script>
|
307
|
|
308
|
<?php include("foot.inc");
|