Project

General

Profile

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

    
60
##|+PRIV
61
##|*IDENT=page-diagnostics-ndptable
62
##|*NAME=Diagnostics: NDP Table
63
##|*DESCR=Allow access to the 'Diagnostics: NDP Table' page.
64
##|*MATCH=diag_ndp.php*
65
##|-PRIV
66

    
67
@ini_set('zlib.output_compression', 0);
68
@ini_set('implicit_flush', 1);
69

    
70
require_once("guiconfig.inc");
71

    
72
exec("/usr/sbin/ndp -na", $rawdata);
73

    
74
$i = 0;
75

    
76
/* if list */
77
$ifdescrs = get_configured_interface_with_descr();
78

    
79
foreach ($ifdescrs as $key =>$interface) {
80
	$hwif[$config['interfaces'][$key]['if']] = $interface;
81
}
82

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

    
91
	$ndpent = array();
92
	$ndpent['ipv6'] = trim($elements[0]);
93
	$ndpent['mac'] = trim($elements[1]);
94
	$ndpent['interface'] = trim($elements[2]);
95
	$data[] = $ndpent;
96
}
97

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

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

    
123
// Sort the data alpha first
124
$data = msort($data, "dnsresolve");
125

    
126
// Load MAC-Manufacturer table
127
$mac_man = load_mac_manufacturer_table();
128

    
129
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
130
include("head.inc");
131
?>
132

    
133
<div class="panel panel-default">
134
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('NDP Table')?></h2></div>
135
	<div class="panel-body">
136

    
137
<div class="table-responsive">
138
	<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
139
		<thead>
140
			<tr>
141
				<th><?= gettext("IPv6 address"); ?></th>
142
				<th><?= gettext("MAC address"); ?></th>
143
				<th><?= gettext("Hostname"); ?></th>
144
				<th><?= gettext("Interface"); ?></th>
145
			</tr>
146
	</thead>
147
	<tbody>
148
			<?php foreach ($data as $entry): ?>
149
				<tr>
150
					<td><?=$entry['ipv6']?></td>
151
					<td>
152
						<?php
153
						$mac=trim($entry['mac']);
154
						$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
155
						?>
156
						<?=$mac?>
157

    
158
						<?php if (isset($mac_man[$mac_hi])):?>
159
							(<?=$mac_man[$mac_hi]?>)
160
						<?php endif; ?>
161

    
162
					</td>
163
					<td>
164
						<?=htmlspecialchars(str_replace("Z_ ", "", $entry['dnsresolve']))?>
165
					</td>
166
					<td>
167
						<?php
168
						if (isset($hwif[$entry['interface']])) {
169
							echo $hwif[$entry['interface']];
170
						} else {
171
							echo $entry['interface'];
172
						}
173
						?>
174
					</td>
175
				</tr>
176
			<?php endforeach; ?>
177
	</tbody>
178
	</table>
179
</div>
180

    
181
	</div>
182
</div>
183

    
184
<?php include("foot.inc");
(19-19/225)