Project

General

Profile

Download (5.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_ndp.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
7
 * Copyright (c) 2011 Seth Mos <seth.mos@dds.nl>
8
 * All rights reserved.
9
 *
10
 * originally based on m0n0wall (http://m0n0.ch/wall)
11
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
 * All rights reserved.
13
 *
14
 * Redistribution and use in source and binary forms, with or without
15
 * modification, are permitted provided that the following conditions are met:
16
 *
17
 * 1. Redistributions of source code must retain the above copyright notice,
18
 *    this list of conditions and the following disclaimer.
19
 *
20
 * 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
 *
25
 * 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
 *
30
 * 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
 *
35
 * 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
 *
39
 * 6. Redistributions of any form whatsoever must retain the following
40
 *    acknowledgment:
41
 *
42
 * "This product includes software developed by the pfSense Project
43
 * for use in the pfSense software distribution (http://www.pfsense.org/).
44
 *
45
 * 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
 */
58

    
59
##|+PRIV
60
##|*IDENT=page-diagnostics-ndptable
61
##|*NAME=Diagnostics: NDP Table
62
##|*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
require_once("guiconfig.inc");
70

    
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
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
83
[3] => Netif [4] => Expire [5] => S
84
[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
function _getHostName($mac, $ip) {
99
	if (is_ipaddr($ip)) {
100
		list($ip, $scope) = explode("%", $ip);
101
		if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
102
			return gethostbyaddr($ip);
103
		} else {
104
			return "";
105
		}
106
	}
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
	if (trim($dns)) {
115
		$entry['dnsresolve'] = "$dns";
116
	} else {
117
		$entry['dnsresolve'] = "Z_ ";
118
	}
119
}
120
unset($entry);
121

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

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

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

    
132
<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
<div class="table-responsive">
137
	<table class="table table-striped table-condensed table-hover sortable-theme-bootstrap" data-sortable>
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
						<?php if (isset($mac_man[$mac_hi])):?>
158
							(<?=$mac_man[$mac_hi]?>)
159
						<?php 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
						?>
173
					</td>
174
				</tr>
175
			<?php endforeach; ?>
176
	</tbody>
177
	</table>
178
</div>
179

    
180
	</div>
181
</div>
182

    
183
<?php include("foot.inc");
(18-18/227)