Project

General

Profile

Download (5.46 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_ndp.php
4
*/
5
/* ====================================================================
6
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved. 
7
 *	Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
8
 *	Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>
9
 *	Part of the pfSense project (https://www.pfsense.org)
10
 *
11
 *  Redistribution and use in source and binary forms, with or without modification, 
12
 *  are permitted provided that the following conditions are met: 
13
 *
14
 *  1. Redistributions of source code must retain the above copyright notice,
15
 *      this list of conditions and the following disclaimer.
16
 *
17
 *  2. Redistributions in binary form must reproduce the above copyright
18
 *      notice, this list of conditions and the following disclaimer in
19
 *      the documentation and/or other materials provided with the
20
 *      distribution. 
21
 *
22
 *  3. All advertising materials mentioning features or use of this software 
23
 *      must display the following acknowledgment:
24
 *      "This product includes software developed by the pfSense Project
25
 *       for use in the pfSense software distribution. (http://www.pfsense.org/). 
26
 *
27
 *  4. The names "pfSense" and "pfSense Project" must not be used to
28
 *       endorse or promote products derived from this software without
29
 *       prior written permission. For written permission, please contact
30
 *       coreteam@pfsense.org.
31
 *
32
 *  5. Products derived from this software may not be called "pfSense"
33
 *      nor may "pfSense" appear in their names without prior written
34
 *      permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *  6. Redistributions of any form whatsoever must retain the following
37
 *      acknowledgment:
38
 *
39
 *  "This product includes software developed by the pfSense Project
40
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
41
  *
42
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *  ====================================================================
56
 *
57
 */
58

    
59
/*
60
	pfSense_BUILDER_BINARIES:	/bin/cat		/usr/sbin/arp
61
	pfSense_MODULE: arp
62
*/
63

    
64
##|+PRIV
65
##|*IDENT=page-diagnostics-ndptable
66
##|*NAME=Diagnostics: NDP Table page
67
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
68
##|*MATCH=diag_ndp.php*
69
##|-PRIV
70

    
71
@ini_set('zlib.output_compression', 0);
72
@ini_set('implicit_flush', 1);
73

    
74
require("guiconfig.inc");
75

    
76
exec("/usr/sbin/ndp -na", $rawdata);
77

    
78
$i = 0;
79

    
80
/* if list */
81
$ifdescrs = get_configured_interface_with_descr();
82

    
83
foreach ($ifdescrs as $key =>$interface) {
84
	$hwif[$config['interfaces'][$key]['if']] = $interface;
85
}
86

    
87
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
88
[3] => Netif [4] => Expire [5] => S
89
[6] => Flags ) */
90
$data = array();
91
array_shift($rawdata);
92
foreach ($rawdata as $line) {
93
	$elements = preg_split('/[ ]+/', $line);
94

    
95
	$ndpent = array();
96
	$ndpent['ipv6'] = trim($elements[0]);
97
	$ndpent['mac'] = trim($elements[1]);
98
	$ndpent['interface'] = trim($elements[2]);
99
	$data[] = $ndpent;
100
}
101

    
102
/* FIXME: Not ipv6 compatible dns resolving. PHP needs fixing */
103
function _getHostName($mac, $ip) {
104
	if (is_ipaddr($ip)) {
105
		list($ip, $scope) = explode("%", $ip);
106
		if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
107
			return gethostbyaddr($ip);
108
		} else {
109
			return "";
110
		}
111
	}
112
}
113

    
114
// Resolve hostnames and replace Z_ with "".  The intention
115
// is to sort the list by hostnames, alpha and then the non
116
// resolvable addresses will appear last in the list.
117
foreach ($data as &$entry) {
118
	$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
119
	if (trim($dns)) {
120
		$entry['dnsresolve'] = "$dns";
121
	} else {
122
		$entry['dnsresolve'] = "Z_ ";
123
	}
124
}
125

    
126
// Sort the data alpha first
127
$data = msort($data, "dnsresolve");
128

    
129
// Load MAC-Manufacturer table
130
$mac_man = load_mac_manufacturer_table();
131

    
132
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
133
include("head.inc");
134
?>
135

    
136
<div class="table-responsive">
137
	<table class="table table-striped table-hover">
138
	<thead>
139
			<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
				<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
						<? if (isset($mac_man[$mac_hi])):?>
158
							(<?=$mac_man[$mac_hi]?>)
159
						<?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
					</td>
173
				</tr>
174
			<?php endforeach; ?>
175
	</tbody>
176
	</table>
177
</div>
178

    
179
<?php include("foot.inc");
(28-28/235)