Project

General

Profile

Download (5.01 KB) Statistics
| Branch: | Tag: | Revision:
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 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2011 Seth Mos <seth.mos@dds.nl>
8
 * All rights reserved.
9 fd9ebcd5 Stephen Beaver
 *
10 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
11
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
 * All rights reserved.
13 fd9ebcd5 Stephen Beaver
 *
14 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 *
18 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
19 fd9ebcd5 Stephen Beaver
 *
20 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
26 0461114f Seth Mos
27
##|+PRIV
28
##|*IDENT=page-diagnostics-ndptable
29 5230f468 jim-p
##|*NAME=Diagnostics: NDP Table
30 0461114f Seth Mos
##|*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 13105d9c Sergio Carlos Morales Angeles
define('NDP_BINARY_PATH', '/usr/sbin/ndp');
37 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
38 0461114f Seth Mos
39 13105d9c Sergio Carlos Morales Angeles
// Delete ndp entry.
40
if (isset($_POST['deleteentry'])) {
41
	$ip = $_POST['deleteentry'];
42
	if (is_ipaddrv6($ip)) {
43 1d92faa3 Sergio Carlos Morales Angeles
		$commandReturnValue = mwexec(NDP_BINARY_PATH . " -d " . escapeshellarg($ip), true);
44 13105d9c Sergio Carlos Morales Angeles
		$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 0461114f Seth Mos
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 fec2c3b7 Sergio Carlos Morales Angeles
/*
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 0461114f Seth Mos
$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 fec2c3b7 Sergio Carlos Morales Angeles
	$ndpent['expiration'] = trim($elements[3]);
87 0461114f Seth Mos
	$data[] = $ndpent;
88
}
89
90
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
91 699737d9 Phil Davis
function _getHostName($mac, $ip) {
92 5f601060 Phil Davis
	if (is_ipaddr($ip)) {
93 30416166 jim-p
		list($ip, $scope) = explode("%", $ip);
94 5f601060 Phil Davis
		if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
95 0461114f Seth Mos
			return gethostbyaddr($ip);
96 5f601060 Phil Davis
		} else {
97 0461114f Seth Mos
			return "";
98 5f601060 Phil Davis
		}
99 0461114f Seth Mos
	}
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 5f601060 Phil Davis
	if (trim($dns)) {
108 0461114f Seth Mos
		$entry['dnsresolve'] = "$dns";
109 5f601060 Phil Davis
	} else {
110 0461114f Seth Mos
		$entry['dnsresolve'] = "Z_ ";
111 5f601060 Phil Davis
	}
112 0461114f Seth Mos
}
113 8ed2d200 NewEraCracker
unset($entry);
114 45d6ada5 Sjon Hortensius
115 0461114f Seth Mos
// Sort the data alpha first
116
$data = msort($data, "dnsresolve");
117
118 9cd01cd6 jim-p
// Load MAC-Manufacturer table
119
$mac_man = load_mac_manufacturer_table();
120
121 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
122 0461114f Seth Mos
include("head.inc");
123 13105d9c Sergio Carlos Morales Angeles
124
// Show message if defined.
125
if (isset($deleteResultMessage, $deleteResultMessageType)) {
126
	print_info_box(htmlentities($deleteResultMessage), $deleteResultMessageType);
127
}
128 0461114f Seth Mos
?>
129
130 ac950976 Colin Fleming
<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 45d6ada5 Sjon Hortensius
<div class="table-responsive">
135 10fe1eb5 Stephen Beaver
	<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
136
		<thead>
137 45d6ada5 Sjon Hortensius
			<tr>
138 fec2c3b7 Sergio Carlos Morales Angeles
				<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 13105d9c Sergio Carlos Morales Angeles
				<th data-sortable="false"><?=gettext("Actions")?></th>
144 45d6ada5 Sjon Hortensius
			</tr>
145
	</thead>
146
	<tbody>
147
			<?php foreach ($data as $entry): ?>
148 0461114f Seth Mos
				<tr>
149 45d6ada5 Sjon Hortensius
					<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 fa172bc5 NewEraCracker
						<?php if (isset($mac_man[$mac_hi])):?>
158 45d6ada5 Sjon Hortensius
							(<?=$mac_man[$mac_hi]?>)
159 07a7b6db NewEraCracker
						<?php endif; ?>
160 45d6ada5 Sjon Hortensius
161
					</td>
162
					<td>
163
						<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
164
					</td>
165
					<td>
166
						<?php
167 947141fd Phil Davis
						if (isset($hwif[$entry['interface']])) {
168 45d6ada5 Sjon Hortensius
							echo $hwif[$entry['interface']];
169 947141fd Phil Davis
						} else {
170 45d6ada5 Sjon Hortensius
							echo $entry['interface'];
171 947141fd Phil Davis
						}
172 45d6ada5 Sjon Hortensius
						?>
173
					</td>
174 fec2c3b7 Sergio Carlos Morales Angeles
					<td>
175
						<?=$entry['expiration']?>
176
					</td>
177 13105d9c Sergio Carlos Morales Angeles
					<td>
178
						<a class="fa fa-trash" title="<?=gettext('Delete NDP entry')?>"	href="diag_ndp.php?deleteentry=<?=$entry['ipv6']?>" usepost></a>
179
					</td>
180 0461114f Seth Mos
				</tr>
181 45d6ada5 Sjon Hortensius
			<?php endforeach; ?>
182
	</tbody>
183
	</table>
184
</div>
185
186 ac950976 Colin Fleming
	</div>
187
</div>
188
189 c10cb196 Stephen Beaver
<?php include("foot.inc");