Project

General

Profile

Download (5.18 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_ndp.php
4
	part of the pfSense project	(https://www.pfsense.org)
5
	Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
6
	Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>
7
	All rights reserved.
8

    
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
	pfSense_MODULE:	arp
38
*/
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
/* Array ( [0] => Neighbor [1] => Linklayer [2] => Address
64
[3] => Netif [4] => Expire [5] => S
65
[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
	if (is_ipaddr($ip)) {
81
		list($ip, $scope) = explode("%", $ip);
82
		if (gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip) {
83
			return gethostbyaddr($ip);
84
		} else {
85
			return "";
86
		}
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
}
101

    
102
// Sort the data alpha first
103
$data = msort($data, "dnsresolve");
104

    
105
// Load MAC-Manufacturer table
106
$mac_man = load_mac_manufacturer_table();
107

    
108
$pgtitle = array(gettext("Diagnostics"), gettext("NDP Table"));
109
include("head.inc");
110

    
111
?>
112

    
113
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
114

    
115
<?php include("fbegin.inc"); ?>
116

    
117
<div id="loading">
118
	<img src="/themes/<?=$g['theme'];?>/images/misc/loader.gif" alt="loader" /><?= gettext("Loading, please wait..."); ?>
119
	<p>&nbsp;</p>
120
</div>
121

    
122
<?php
123

    
124
// Flush buffers out to client so that they see Loading, please wait....
125
for ($i = 0; $i < ob_get_level(); $i++) {
126
	ob_end_flush();
127
}
128
ob_implicit_flush(1);
129

    
130
?>
131
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="diag ndp">
132
	<tr>
133
		<td>
134
			<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0" summary="tabcont">
135
				<tr>
136
					<td class="listhdrr"><?= gettext("IPv6 address"); ?></td>
137
					<td class="listhdrr"><?= gettext("MAC address"); ?></td>
138
					<td class="listhdrr"><?= gettext("Hostname"); ?></td>
139
					<td class="listhdr"><?= gettext("Interface"); ?></td>
140
					<td class="list"></td>
141
				</tr>
142
				<?php foreach ($data as $entry): ?>
143
					<tr>
144
						<td class="listlr"><?=$entry['ipv6'];?></td>
145
						<td class="listr">
146
							<?php
147
							$mac=trim($entry['mac']);
148
							$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
149
							print $mac;
150
							if (isset($mac_man[$mac_hi])) {
151
								print "<br /><font size=\"-2\"><i>{$mac_man[$mac_hi]}</i></font>";
152
							}
153
							?>
154
						</td>
155
						<td class="listr">
156
							<?php
157
							echo "&nbsp;". str_replace("Z_ ", "", $entry['dnsresolve']);
158
							?>
159
						</td>
160
						<td class="listr">
161
							<?php
162
							if (isset($hwif[$entry['interface']])) {
163
								echo $hwif[$entry['interface']];
164
							} else {
165
								echo $entry['interface'];
166
							}
167
							?>
168
						</td>
169
					</tr>
170
				<?php endforeach; ?>
171
			</table>
172
		</td>
173
	</tr>
174
</table>
175

    
176
<?php include("fend.inc"); ?>
177

    
178
<script type="text/javascript">
179
//<![CDATA[
180
	jQuery('#loading').html('');
181
//]]>
182
</script>
183
</body>
184
</html>
(38-38/252)