Project

General

Profile

Download (4.99 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_ndp.php
4
	part of the pfSense project	(http://www.pfsense.org)
5
	Copyright (C) 2004-2010 Scott Ullrich <sullrich@gmail.com>
6
	Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>
7
	
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
{       
81
	if(is_ipaddr($ip)) {
82
		if(gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip)
83
			return gethostbyaddr($ip);
84
		else
85
			return "";
86
	}
87
}
88

    
89
// Resolve hostnames and replace Z_ with "".  The intention
90
// is to sort the list by hostnames, alpha and then the non
91
// resolvable addresses will appear last in the list.
92
foreach ($data as &$entry) {
93
	$dns = trim(_getHostName($entry['mac'], $entry['ipv6']));
94
	if(trim($dns))
95
		$entry['dnsresolve'] = "$dns";
96
	else
97
		$entry['dnsresolve'] = "Z_ ";
98
}
99
                
100
// Sort the data alpha first
101
$data = msort($data, "dnsresolve");
102

    
103
// Load MAC-Manufacturer table
104
$mac_man = load_mac_manufacturer_table();
105

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

    
109
?>
110

    
111
<body link="#000000" vlink="#000000" alink="#000000">
112

    
113
<?php include("fbegin.inc"); ?>
114

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

    
120
<?php
121

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

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

    
169
<?php include("fend.inc"); ?>
170

    
171
<script type="text/javascript">
172
	jQuery('#loading').html('');
173
</script>
(36-36/246)