Project

General

Profile

Download (6.68 KB) Statistics
| Branch: | Tag: | Revision:
1 0461114f Seth Mos
<?php
2
/*
3 aaec5634 Renato Botelho
 * diag_ndp.php
4 9da2cf1c Stephen Beaver
 *
5 aaec5634 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 aaec5634 Renato Botelho
 * Copyright (c) 2011 Seth Mos <seth.mos@dds.nl>
8
 * All rights reserved.
9 fd9ebcd5 Stephen Beaver
 *
10 aaec5634 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 aaec5634 Renato Botelho
 * Redistribution and use in source and binary forms, with or without
15
 * modification, are permitted provided that the following conditions are met:
16 fd9ebcd5 Stephen Beaver
 *
17 aaec5634 Renato Botelho
 * 1. Redistributions of source code must retain the above copyright notice,
18
 *    this list of conditions and the following disclaimer.
19 fd9ebcd5 Stephen Beaver
 *
20 aaec5634 Renato Botelho
 * 2. Redistributions in binary form must reproduce the above copyright
21
 *    notice, this list of conditions and the following disclaimer in
22
 *    the documentation and/or other materials provided with the
23
 *    distribution.
24 fd9ebcd5 Stephen Beaver
 *
25 aaec5634 Renato Botelho
 * 3. All advertising materials mentioning features or use of this software
26
 *    must display the following acknowledgment:
27
 *    "This product includes software developed by the pfSense Project
28
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
29 fd9ebcd5 Stephen Beaver
 *
30 aaec5634 Renato Botelho
 * 4. The names "pfSense" and "pfSense Project" must not be used to
31
 *    endorse or promote products derived from this software without
32
 *    prior written permission. For written permission, please contact
33
 *    coreteam@pfsense.org.
34 fd9ebcd5 Stephen Beaver
 *
35 aaec5634 Renato Botelho
 * 5. Products derived from this software may not be called "pfSense"
36
 *    nor may "pfSense" appear in their names without prior written
37
 *    permission of the Electric Sheep Fencing, LLC.
38 fd9ebcd5 Stephen Beaver
 *
39 aaec5634 Renato Botelho
 * 6. Redistributions of any form whatsoever must retain the following
40
 *    acknowledgment:
41 0da0d43e Phil Davis
 *
42 aaec5634 Renato Botelho
 * "This product includes software developed by the pfSense Project
43
 * for use in the pfSense software distribution (http://www.pfsense.org/).
44 fd9ebcd5 Stephen Beaver
 *
45 aaec5634 Renato Botelho
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
46
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
49
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
54
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
56
 * OF THE POSSIBILITY OF SUCH DAMAGE.
57 fd9ebcd5 Stephen Beaver
 */
58 0461114f Seth Mos
59
##|+PRIV
60
##|*IDENT=page-diagnostics-ndptable
61 5230f468 jim-p
##|*NAME=Diagnostics: NDP Table
62 0461114f Seth Mos
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
63
##|*MATCH=diag_ndp.php*
64
##|-PRIV
65
66
@ini_set('zlib.output_compression', 0);
67
@ini_set('implicit_flush', 1);
68 c14573f7 Sergio Carlos Morales Angeles
define('NDP_BINARY_PATH', '/usr/sbin/ndp');
69 aceaf18c Phil Davis
require_once("guiconfig.inc");
70 0461114f Seth Mos
71 c14573f7 Sergio Carlos Morales Angeles
// Delete ndp entry.
72
if (isset($_POST['deleteentry'])) {
73
	$ip = $_POST['deleteentry'];
74
	if (is_ipaddrv6($ip)) {
75 7f8e4d5f Sergio Carlos Morales Angeles
		$commandReturnValue = mwexec(NDP_BINARY_PATH . " -d " . escapeshellarg($ip), true);
76 c14573f7 Sergio Carlos Morales Angeles
		$deleteSucceededFlag = ($commandReturnValue == 0);
77
	} else {
78
		$deleteSucceededFlag = false;
79
	}
80
81
	$deleteResultMessage = ($deleteSucceededFlag)
82
		? sprintf(gettext("The NDP entry for %s has been deleted."), $ip)
83
		: sprintf(gettext("%s is not a valid IPv6 address or could not be deleted."), $ip);
84
	$deleteResultMessageType = ($deleteSucceededFlag)
85
		? 'success'
86
		: 'alert-warning';
87
}
88
89
exec(NDP_BINARY_PATH . " -na", $rawdata);
90 0461114f Seth Mos
91
$i = 0;
92
93
/* if list */
94
$ifdescrs = get_configured_interface_with_descr();
95
96
foreach ($ifdescrs as $key =>$interface) {
97
	$hwif[$config['interfaces'][$key]['if']] = $interface;
98
}
99
100 4d473e17 Sergio Carlos Morales Angeles
/*
101
 * Key map for each element in $rawdata
102
 * 0 => Neighbor IP
103
 * 1 => Physical address (MAC)
104
 * 2 => Interface
105
 * 3 => Expiration
106
 * 4 => State
107
 * 5 => Flags
108
 */
109 0461114f Seth Mos
$data = array();
110
array_shift($rawdata);
111
foreach ($rawdata as $line) {
112
	$elements = preg_split('/[ ]+/', $line);
113
114
	$ndpent = array();
115
	$ndpent['ipv6'] = trim($elements[0]);
116
	$ndpent['mac'] = trim($elements[1]);
117
	$ndpent['interface'] = trim($elements[2]);
118 4d473e17 Sergio Carlos Morales Angeles
	$ndpent['expiration'] = trim($elements[3]);
119 0461114f Seth Mos
	$data[] = $ndpent;
120
}
121
122
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
123 699737d9 Phil Davis
function _getHostName($mac, $ip) {
124 5f601060 Phil Davis
	if (is_ipaddr($ip)) {
125 30416166 jim-p
		list($ip, $scope) = explode("%", $ip);
126 5f601060 Phil Davis
		if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
127 0461114f Seth Mos
			return gethostbyaddr($ip);
128 5f601060 Phil Davis
		} else {
129 0461114f Seth Mos
			return "";
130 5f601060 Phil Davis
		}
131 0461114f Seth Mos
	}
132
}
133
134
// Resolve hostnames and replace Z_ with "".  The intention
135
// is to sort the list by hostnames, alpha and then the non
136
// resolvable addresses will appear last in the list.
137
foreach ($data as &$entry) {
138
	$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
139 5f601060 Phil Davis
	if (trim($dns)) {
140 0461114f Seth Mos
		$entry['dnsresolve'] = "$dns";
141 5f601060 Phil Davis
	} else {
142 0461114f Seth Mos
		$entry['dnsresolve'] = "Z_ ";
143 5f601060 Phil Davis
	}
144 0461114f Seth Mos
}
145 8ed2d200 NewEraCracker
unset($entry);
146 45d6ada5 Sjon Hortensius
147 0461114f Seth Mos
// Sort the data alpha first
148
$data = msort($data, "dnsresolve");
149
150 9cd01cd6 jim-p
// Load MAC-Manufacturer table
151
$mac_man = load_mac_manufacturer_table();
152
153 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
154 0461114f Seth Mos
include("head.inc");
155 c14573f7 Sergio Carlos Morales Angeles
156
// Show message if defined.
157
if (isset($deleteResultMessage, $deleteResultMessageType)) {
158
	print_info_box(htmlentities($deleteResultMessage), $deleteResultMessageType);
159
}
160 0461114f Seth Mos
?>
161
162 ac950976 Colin Fleming
<div class="panel panel-default">
163
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('NDP Table')?></h2></div>
164
	<div class="panel-body">
165
166 45d6ada5 Sjon Hortensius
<div class="table-responsive">
167 10fe1eb5 Stephen Beaver
	<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
168
		<thead>
169 45d6ada5 Sjon Hortensius
			<tr>
170 4d473e17 Sergio Carlos Morales Angeles
				<th><?=gettext("IPv6 address")?></th>
171
				<th><?=gettext("MAC address")?></th>
172
				<th><?=gettext("Hostname")?></th>
173
				<th><?=gettext("Interface")?></th>
174
				<th><?=gettext("Expiration")?></th>
175 c14573f7 Sergio Carlos Morales Angeles
				<th data-sortable="false"><?=gettext("Actions")?></th>
176 45d6ada5 Sjon Hortensius
			</tr>
177
	</thead>
178
	<tbody>
179
			<?php foreach ($data as $entry): ?>
180 0461114f Seth Mos
				<tr>
181 45d6ada5 Sjon Hortensius
					<td><?=$entry['ipv6']?></td>
182
					<td>
183
						<?php
184
						$mac=trim($entry['mac']);
185
						$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
186
						?>
187
						<?=$mac?>
188
189 fa172bc5 NewEraCracker
						<?php if (isset($mac_man[$mac_hi])):?>
190 45d6ada5 Sjon Hortensius
							(<?=$mac_man[$mac_hi]?>)
191 07a7b6db NewEraCracker
						<?php endif; ?>
192 45d6ada5 Sjon Hortensius
193
					</td>
194
					<td>
195
						<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
196
					</td>
197
					<td>
198
						<?php
199 947141fd Phil Davis
						if (isset($hwif[$entry['interface']])) {
200 45d6ada5 Sjon Hortensius
							echo $hwif[$entry['interface']];
201 947141fd Phil Davis
						} else {
202 45d6ada5 Sjon Hortensius
							echo $entry['interface'];
203 947141fd Phil Davis
						}
204 45d6ada5 Sjon Hortensius
						?>
205
					</td>
206 4d473e17 Sergio Carlos Morales Angeles
					<td>
207
						<?=$entry['expiration']?>
208
					</td>
209 c14573f7 Sergio Carlos Morales Angeles
					<td>
210
						<a class="fa fa-trash" title="<?=gettext('Delete NDP entry')?>"	href="diag_ndp.php?deleteentry=<?=$entry['ipv6']?>" usepost></a>
211
					</td>
212 0461114f Seth Mos
				</tr>
213 45d6ada5 Sjon Hortensius
			<?php endforeach; ?>
214
	</tbody>
215
	</table>
216
</div>
217
218 ac950976 Colin Fleming
	</div>
219
</div>
220
221 c10cb196 Stephen Beaver
<?php include("foot.inc");