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-2020 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
|
}
|
58
|
|
59
|
exec(NDP_BINARY_PATH . " -na", $rawdata);
|
60
|
|
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
|
/*
|
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
|
$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
|
$ndpent['expiration'] = trim($elements[3]);
|
89
|
$data[] = $ndpent;
|
90
|
}
|
91
|
|
92
|
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
|
93
|
function _getHostName($mac, $ip) {
|
94
|
if (is_ipaddr($ip)) {
|
95
|
list($ip, $scope) = explode("%", $ip);
|
96
|
if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
|
97
|
return gethostbyaddr($ip);
|
98
|
} else {
|
99
|
return "";
|
100
|
}
|
101
|
}
|
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
|
if (trim($dns)) {
|
110
|
$entry['dnsresolve'] = "$dns";
|
111
|
} else {
|
112
|
$entry['dnsresolve'] = "Z_ ";
|
113
|
}
|
114
|
}
|
115
|
unset($entry);
|
116
|
|
117
|
// Sort the data alpha first
|
118
|
$data = msort($data, "dnsresolve");
|
119
|
|
120
|
// Load MAC-Manufacturer table
|
121
|
$mac_man = load_mac_manufacturer_table();
|
122
|
|
123
|
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
|
124
|
include("head.inc");
|
125
|
|
126
|
// Show message if defined.
|
127
|
if (isset($deleteResultMessage, $deleteResultMessageType)) {
|
128
|
print_info_box(htmlentities($deleteResultMessage), $deleteResultMessageType);
|
129
|
}
|
130
|
?>
|
131
|
|
132
|
<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
|
<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
|
<div class="table-responsive">
|
175
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
|
176
|
<thead>
|
177
|
<tr>
|
178
|
<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
|
<th data-sortable="false"><?=gettext("Actions")?></th>
|
184
|
</tr>
|
185
|
</thead>
|
186
|
<tbody>
|
187
|
<?php foreach ($data as $entry): ?>
|
188
|
<tr>
|
189
|
<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
|
<?php if (isset($mac_man[$mac_hi])):?>
|
198
|
(<?=$mac_man[$mac_hi]?>)
|
199
|
<?php endif; ?>
|
200
|
|
201
|
</td>
|
202
|
<td>
|
203
|
<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
|
204
|
</td>
|
205
|
<td>
|
206
|
<?php
|
207
|
if (isset($hwif[$entry['interface']])) {
|
208
|
echo $hwif[$entry['interface']];
|
209
|
} else {
|
210
|
echo $entry['interface'];
|
211
|
}
|
212
|
?>
|
213
|
</td>
|
214
|
<td>
|
215
|
<?=$entry['expiration']?>
|
216
|
</td>
|
217
|
<td>
|
218
|
<a class="fa fa-trash" title="<?=gettext('Delete NDP entry')?>" href="diag_ndp.php?deleteentry=<?=$entry['ipv6']?>" usepost></a>
|
219
|
</td>
|
220
|
</tr>
|
221
|
<?php endforeach; ?>
|
222
|
</tbody>
|
223
|
</table>
|
224
|
</div>
|
225
|
|
226
|
</div>
|
227
|
</div>
|
228
|
|
229
|
<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
|
<?php include("foot.inc");
|