1
|
<?php
|
2
|
/*
|
3
|
* diag_ndp.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2018 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
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
15
|
* you may not use this file except in compliance with the License.
|
16
|
* You may obtain a copy of the License at
|
17
|
*
|
18
|
* http://www.apache.org/licenses/LICENSE-2.0
|
19
|
*
|
20
|
* Unless required by applicable law or agreed to in writing, software
|
21
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
22
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
23
|
* See the License for the specific language governing permissions and
|
24
|
* limitations under the License.
|
25
|
*/
|
26
|
|
27
|
##|+PRIV
|
28
|
##|*IDENT=page-diagnostics-ndptable
|
29
|
##|*NAME=Diagnostics: NDP Table
|
30
|
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
|
31
|
##|*MATCH=diag_ndp.php*
|
32
|
##|-PRIV
|
33
|
|
34
|
@ini_set('zlib.output_compression', 0);
|
35
|
@ini_set('implicit_flush', 1);
|
36
|
define('NDP_BINARY_PATH', '/usr/sbin/ndp');
|
37
|
require_once("guiconfig.inc");
|
38
|
|
39
|
// Delete ndp entry.
|
40
|
if (isset($_POST['deleteentry'])) {
|
41
|
$ip = $_POST['deleteentry'];
|
42
|
if (is_ipaddrv6($ip)) {
|
43
|
$commandReturnValue = mwexec(NDP_BINARY_PATH . " -d " . escapeshellarg($ip), true);
|
44
|
$deleteSucceededFlag = ($commandReturnValue == 0);
|
45
|
} else {
|
46
|
$deleteSucceededFlag = false;
|
47
|
}
|
48
|
|
49
|
$deleteResultMessage = ($deleteSucceededFlag)
|
50
|
? sprintf(gettext("The NDP entry for %s has been deleted."), $ip)
|
51
|
: sprintf(gettext("%s is not a valid IPv6 address or could not be deleted."), $ip);
|
52
|
$deleteResultMessageType = ($deleteSucceededFlag)
|
53
|
? 'success'
|
54
|
: 'alert-warning';
|
55
|
}
|
56
|
|
57
|
exec(NDP_BINARY_PATH . " -na", $rawdata);
|
58
|
|
59
|
$i = 0;
|
60
|
|
61
|
/* if list */
|
62
|
$ifdescrs = get_configured_interface_with_descr();
|
63
|
|
64
|
foreach ($ifdescrs as $key =>$interface) {
|
65
|
$hwif[$config['interfaces'][$key]['if']] = $interface;
|
66
|
}
|
67
|
|
68
|
/*
|
69
|
* Key map for each element in $rawdata
|
70
|
* 0 => Neighbor IP
|
71
|
* 1 => Physical address (MAC)
|
72
|
* 2 => Interface
|
73
|
* 3 => Expiration
|
74
|
* 4 => State
|
75
|
* 5 => Flags
|
76
|
*/
|
77
|
$data = array();
|
78
|
array_shift($rawdata);
|
79
|
foreach ($rawdata as $line) {
|
80
|
$elements = preg_split('/[ ]+/', $line);
|
81
|
|
82
|
$ndpent = array();
|
83
|
$ndpent['ipv6'] = trim($elements[0]);
|
84
|
$ndpent['mac'] = trim($elements[1]);
|
85
|
$ndpent['interface'] = trim($elements[2]);
|
86
|
$ndpent['expiration'] = trim($elements[3]);
|
87
|
$data[] = $ndpent;
|
88
|
}
|
89
|
|
90
|
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
|
91
|
function _getHostName($mac, $ip) {
|
92
|
if (is_ipaddr($ip)) {
|
93
|
list($ip, $scope) = explode("%", $ip);
|
94
|
if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
|
95
|
return gethostbyaddr($ip);
|
96
|
} else {
|
97
|
return "";
|
98
|
}
|
99
|
}
|
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
|
$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
|
107
|
if (trim($dns)) {
|
108
|
$entry['dnsresolve'] = "$dns";
|
109
|
} else {
|
110
|
$entry['dnsresolve'] = "Z_ ";
|
111
|
}
|
112
|
}
|
113
|
unset($entry);
|
114
|
|
115
|
// Sort the data alpha first
|
116
|
$data = msort($data, "dnsresolve");
|
117
|
|
118
|
// Load MAC-Manufacturer table
|
119
|
$mac_man = load_mac_manufacturer_table();
|
120
|
|
121
|
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
|
122
|
include("head.inc");
|
123
|
|
124
|
// Show message if defined.
|
125
|
if (isset($deleteResultMessage, $deleteResultMessageType)) {
|
126
|
print_info_box(htmlentities($deleteResultMessage), $deleteResultMessageType);
|
127
|
}
|
128
|
?>
|
129
|
|
130
|
<div class="panel panel-default">
|
131
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('NDP Table')?></h2></div>
|
132
|
<div class="panel-body">
|
133
|
|
134
|
<div class="table-responsive">
|
135
|
<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
|
136
|
<thead>
|
137
|
<tr>
|
138
|
<th><?=gettext("IPv6 address")?></th>
|
139
|
<th><?=gettext("MAC address")?></th>
|
140
|
<th><?=gettext("Hostname")?></th>
|
141
|
<th><?=gettext("Interface")?></th>
|
142
|
<th><?=gettext("Expiration")?></th>
|
143
|
<th data-sortable="false"><?=gettext("Actions")?></th>
|
144
|
</tr>
|
145
|
</thead>
|
146
|
<tbody>
|
147
|
<?php foreach ($data as $entry): ?>
|
148
|
<tr>
|
149
|
<td><?=$entry['ipv6']?></td>
|
150
|
<td>
|
151
|
<?php
|
152
|
$mac=trim($entry['mac']);
|
153
|
$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
|
154
|
?>
|
155
|
<?=$mac?>
|
156
|
|
157
|
<?php if (isset($mac_man[$mac_hi])):?>
|
158
|
(<?=$mac_man[$mac_hi]?>)
|
159
|
<?php endif; ?>
|
160
|
|
161
|
</td>
|
162
|
<td>
|
163
|
<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
|
164
|
</td>
|
165
|
<td>
|
166
|
<?php
|
167
|
if (isset($hwif[$entry['interface']])) {
|
168
|
echo $hwif[$entry['interface']];
|
169
|
} else {
|
170
|
echo $entry['interface'];
|
171
|
}
|
172
|
?>
|
173
|
</td>
|
174
|
<td>
|
175
|
<?=$entry['expiration']?>
|
176
|
</td>
|
177
|
<td>
|
178
|
<a class="fa fa-trash" title="<?=gettext('Delete NDP entry')?>" href="diag_ndp.php?deleteentry=<?=$entry['ipv6']?>" usepost></a>
|
179
|
</td>
|
180
|
</tr>
|
181
|
<?php endforeach; ?>
|
182
|
</tbody>
|
183
|
</table>
|
184
|
</div>
|
185
|
|
186
|
</div>
|
187
|
</div>
|
188
|
|
189
|
<?php include("foot.inc");
|