Project

General

Profile

« Previous | Next » 

Revision 0461114f

Added by Seth Mos over 14 years ago

Add the IPv6 Neighbour list status page

View differences:

usr/local/www/diag_ndp.php
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
$pgtitle = array(gettext("Diagnostics"),gettext("NDP Table"));
104
include("head.inc");
105

  
106
?>
107

  
108
<body link="#000000" vlink="#000000" alink="#000000">
109

  
110
<?php include("fbegin.inc"); ?>
111

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

  
117
<?php
118

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

  
123
?>
124
<table width="100%" border="0" cellpadding="0" cellspacing="0">
125
	<tr>
126
		<td>
127
			<table class="tabcont sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
128
				<tr>
129
					<td class="listhdrr"><?= gettext("IPv6 address"); ?></td>
130
					<td class="listhdrr"><?= gettext("MAC address"); ?></td>
131
					<td class="listhdrr"><?= gettext("Hostname"); ?></td>
132
					<td class="listhdr"><?= gettext("Interface"); ?></td>
133
					<td class="list"></td>
134
				</tr>
135
				<?php foreach ($data as $entry): ?>
136
					<tr>
137
						<td class="listlr"><?=$entry['ipv6'];?></td>
138
						<td class="listr"><?=$entry['mac'];?></td>
139
						<td class="listr">
140
							<?php
141
							echo "&nbsp;". str_replace("Z_ ", "", $entry['dnsresolve']);
142
							?>
143
						</td>
144
						<td class="listr">
145
							<? 
146
							if(isset($hwif[$entry['interface']]))
147
								echo $hwif[$entry['interface']];
148
							else
149
								echo $entry['interface'];
150
							?>
151
						</td>
152
					</tr>
153
				<?php endforeach; ?>
154
			</table>
155
		</td>
156
	</tr>
157
</table>
158

  
159
<?php include("fend.inc"); ?>
160

  
161
<script type="text/javascript">
162
	$('loading').innerHTML = '';
163
</script>

Also available in: Unified diff