Project

General

Profile

Download (5.62 KB) Statistics
| Branch: | Tag: | Revision:
1 0461114f Seth Mos
<?php
2
/*
3
	diag_ndp.php
4
*/
5 fd9ebcd5 Stephen Beaver
/* ====================================================================
6 0da0d43e Phil Davis
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 90719498 Phil Davis
 *	Copyright (c) 2011 Seth Mos <seth.mos@dds.nl>
8 9da2cf1c Stephen Beaver
 *
9 c9df279d Stephen Beaver
 *  Some or all of this file is based on the m0n0wall project which is
10 9da2cf1c Stephen Beaver
 *  Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
11 fd9ebcd5 Stephen Beaver
 *
12 0da0d43e Phil Davis
 *  Redistribution and use in source and binary forms, with or without modification,
13
 *  are permitted provided that the following conditions are met:
14 fd9ebcd5 Stephen Beaver
 *
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 0da0d43e Phil Davis
 *      distribution.
22 fd9ebcd5 Stephen Beaver
 *
23 0da0d43e Phil Davis
 *  3. All advertising materials mentioning features or use of this software
24 fd9ebcd5 Stephen Beaver
 *      must display the following acknowledgment:
25
 *      "This product includes software developed by the pfSense Project
26 0da0d43e Phil Davis
 *       for use in the pfSense software distribution. (http://www.pfsense.org/).
27 fd9ebcd5 Stephen Beaver
 *
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 0da0d43e Phil Davis
 *
43 fd9ebcd5 Stephen Beaver
 *  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 0461114f Seth Mos
60
##|+PRIV
61
##|*IDENT=page-diagnostics-ndptable
62 5230f468 jim-p
##|*NAME=Diagnostics: NDP Table
63 0461114f Seth Mos
##|*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("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 45d6ada5 Sjon Hortensius
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
84
[3] => Netif [4] => Expire [5] => S
85 0461114f Seth Mos
[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 699737d9 Phil Davis
function _getHostName($mac, $ip) {
100 5f601060 Phil Davis
	if (is_ipaddr($ip)) {
101 30416166 jim-p
		list($ip, $scope) = explode("%", $ip);
102 5f601060 Phil Davis
		if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
103 0461114f Seth Mos
			return gethostbyaddr($ip);
104 5f601060 Phil Davis
		} else {
105 0461114f Seth Mos
			return "";
106 5f601060 Phil Davis
		}
107 0461114f Seth Mos
	}
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 5f601060 Phil Davis
	if (trim($dns)) {
116 0461114f Seth Mos
		$entry['dnsresolve'] = "$dns";
117 5f601060 Phil Davis
	} else {
118 0461114f Seth Mos
		$entry['dnsresolve'] = "Z_ ";
119 5f601060 Phil Davis
	}
120 0461114f Seth Mos
}
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");