Project

General

Profile

Download (5.51 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
69 aceaf18c Phil Davis
require_once("guiconfig.inc");
70 0461114f Seth Mos
71
exec("/usr/sbin/ndp -na", $rawdata);
72
73
$i = 0;
74
75
/* if list */
76
$ifdescrs = get_configured_interface_with_descr();
77
78
foreach ($ifdescrs as $key =>$interface) {
79
	$hwif[$config['interfaces'][$key]['if']] = $interface;
80
}
81
82 45d6ada5 Sjon Hortensius
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
83
[3] => Netif [4] => Expire [5] => S
84 0461114f Seth Mos
[6] => Flags ) */
85
$data = array();
86
array_shift($rawdata);
87
foreach ($rawdata as $line) {
88
	$elements = preg_split('/[ ]+/', $line);
89
90
	$ndpent = array();
91
	$ndpent['ipv6'] = trim($elements[0]);
92
	$ndpent['mac'] = trim($elements[1]);
93
	$ndpent['interface'] = trim($elements[2]);
94
	$data[] = $ndpent;
95
}
96
97
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
98 699737d9 Phil Davis
function _getHostName($mac, $ip) {
99 5f601060 Phil Davis
	if (is_ipaddr($ip)) {
100 30416166 jim-p
		list($ip, $scope) = explode("%", $ip);
101 5f601060 Phil Davis
		if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
102 0461114f Seth Mos
			return gethostbyaddr($ip);
103 5f601060 Phil Davis
		} else {
104 0461114f Seth Mos
			return "";
105 5f601060 Phil Davis
		}
106 0461114f Seth Mos
	}
107
}
108
109
// Resolve hostnames and replace Z_ with "".  The intention
110
// is to sort the list by hostnames, alpha and then the non
111
// resolvable addresses will appear last in the list.
112
foreach ($data as &$entry) {
113
	$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
114 5f601060 Phil Davis
	if (trim($dns)) {
115 0461114f Seth Mos
		$entry['dnsresolve'] = "$dns";
116 5f601060 Phil Davis
	} else {
117 0461114f Seth Mos
		$entry['dnsresolve'] = "Z_ ";
118 5f601060 Phil Davis
	}
119 0461114f Seth Mos
}
120 8ed2d200 NewEraCracker
unset($entry);
121 45d6ada5 Sjon Hortensius
122 0461114f Seth Mos
// Sort the data alpha first
123
$data = msort($data, "dnsresolve");
124
125 9cd01cd6 jim-p
// Load MAC-Manufacturer table
126
$mac_man = load_mac_manufacturer_table();
127
128 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
129 0461114f Seth Mos
include("head.inc");
130
?>
131
132 ac950976 Colin Fleming
<div class="panel panel-default">
133
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('NDP Table')?></h2></div>
134
	<div class="panel-body">
135
136 45d6ada5 Sjon Hortensius
<div class="table-responsive">
137 10fe1eb5 Stephen Beaver
	<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
138
		<thead>
139 45d6ada5 Sjon Hortensius
			<tr>
140
				<th><?= gettext("IPv6 address"); ?></th>
141
				<th><?= gettext("MAC address"); ?></th>
142
				<th><?= gettext("Hostname"); ?></th>
143
				<th><?= gettext("Interface"); ?></th>
144
			</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 0461114f Seth Mos
				</tr>
175 45d6ada5 Sjon Hortensius
			<?php endforeach; ?>
176
	</tbody>
177
	</table>
178
</div>
179
180 ac950976 Colin Fleming
	</div>
181
</div>
182
183 c10cb196 Stephen Beaver
<?php include("foot.inc");