Project

General

Profile

Download (4.28 KB) Statistics
| Branch: | Tag: | Revision:
1 0461114f Seth Mos
<?php
2
/*
3
	diag_ndp.php
4 45d6ada5 Sjon Hortensius
	part of the pfSense project (https://www.pfsense.org)
5 0461114f Seth Mos
	Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
6
	Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>
7 29aef6c4 Jim Thompson
	All rights reserved.
8 0461114f Seth Mos
9
	originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2005 Paul Taylor (paultaylor@winndixie.com) and Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15
16
	1. Redistributions of source code must retain the above copyright notice,
17
	this list of conditions and the following disclaimer.
18
19
	2. Redistributions in binary form must reproduce the above copyright
20
	notice, this list of conditions and the following disclaimer in the
21
	documentation and/or other materials provided with the distribution.
22
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
35
/*
36
	pfSense_BUILDER_BINARIES:	/bin/cat		/usr/sbin/arp
37 45d6ada5 Sjon Hortensius
	pfSense_MODULE: arp
38 0461114f Seth Mos
*/
39
40
##|+PRIV
41
##|*IDENT=page-diagnostics-ndptable
42
##|*NAME=Diagnostics: NDP Table page
43
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
44
##|*MATCH=diag_ndp.php*
45
##|-PRIV
46
47
@ini_set('zlib.output_compression', 0);
48
@ini_set('implicit_flush', 1);
49
50
require("guiconfig.inc");
51
52
exec("/usr/sbin/ndp -na", $rawdata);
53
54
$i = 0;
55
56
/* if list */
57
$ifdescrs = get_configured_interface_with_descr();
58
59
foreach ($ifdescrs as $key =>$interface) {
60
	$hwif[$config['interfaces'][$key]['if']] = $interface;
61
}
62
63 45d6ada5 Sjon Hortensius
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
64
[3] => Netif [4] => Expire [5] => S
65 0461114f Seth Mos
[6] => Flags ) */
66
$data = array();
67
array_shift($rawdata);
68
foreach ($rawdata as $line) {
69
	$elements = preg_split('/[ ]+/', $line);
70
71
	$ndpent = array();
72
	$ndpent['ipv6'] = trim($elements[0]);
73
	$ndpent['mac'] = trim($elements[1]);
74
	$ndpent['interface'] = trim($elements[2]);
75
	$data[] = $ndpent;
76
}
77
78
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
79
function _getHostName($mac,$ip)
80 45d6ada5 Sjon Hortensius
{
81 0461114f Seth Mos
	if(is_ipaddr($ip)) {
82 30416166 jim-p
		list($ip, $scope) = explode("%", $ip);
83 45d6ada5 Sjon Hortensius
		if(gethostbyaddr($ip) != "" and gethostbyaddr($ip) != $ip)
84 0461114f Seth Mos
			return gethostbyaddr($ip);
85
		else
86
			return "";
87
	}
88
}
89
90
// Resolve hostnames and replace Z_ with "".  The intention
91
// is to sort the list by hostnames, alpha and then the non
92
// resolvable addresses will appear last in the list.
93
foreach ($data as &$entry) {
94
	$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
95
	if(trim($dns))
96
		$entry['dnsresolve'] = "$dns";
97
	else
98
		$entry['dnsresolve'] = "Z_ ";
99
}
100 45d6ada5 Sjon Hortensius
101 0461114f Seth Mos
// Sort the data alpha first
102
$data = msort($data, "dnsresolve");
103
104 9cd01cd6 jim-p
// Load MAC-Manufacturer table
105
$mac_man = load_mac_manufacturer_table();
106
107 0461114f Seth Mos
$pgtitle = array(gettext("Diagnostics"),gettext("NDP Table"));
108
include("head.inc");
109
?>
110
111 45d6ada5 Sjon Hortensius
<div class="table-responsive">
112
	<table class="table table-striped table-hover">
113
	<thead>
114
			<tr>
115
				<th><?= gettext("IPv6 address"); ?></th>
116
				<th><?= gettext("MAC address"); ?></th>
117
				<th><?= gettext("Hostname"); ?></th>
118
				<th><?= gettext("Interface"); ?></th>
119
			</tr>
120
	</thead>
121
	<tbody>
122
			<?php foreach ($data as $entry): ?>
123 0461114f Seth Mos
				<tr>
124 45d6ada5 Sjon Hortensius
					<td><?=$entry['ipv6']?></td>
125
					<td>
126
						<?php
127
						$mac=trim($entry['mac']);
128
						$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
129
						?>
130
						<?=$mac?>
131
132
						<? if(isset($mac_man[$mac_hi])):?>
133
							(<?=$mac_man[$mac_hi]?>)
134
						<?endif?>
135
136
					</td>
137
					<td>
138
						<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
139
					</td>
140
					<td>
141
						<?php
142
						if(isset($hwif[$entry['interface']]))
143
							echo $hwif[$entry['interface']];
144
						else
145
							echo $entry['interface'];
146
						?>
147
					</td>
148 0461114f Seth Mos
				</tr>
149 45d6ada5 Sjon Hortensius
			<?php endforeach; ?>
150
	</tbody>
151
	</table>
152
</div>
153
154
<?php include("foot.inc");