Projet

Général

Profil

Télécharger (5,12 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_ndp.php @ 3edbd787

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
	
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
		list($ip, $scope) = explode("%", $ip);
83
		if(gethostbyaddr($ip) <> "" and gethostbyaddr($ip) <> $ip)
84
			return gethostbyaddr($ip);
85
		else
86
			return "";
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
// Sort the data alpha first
102
$data = msort($data, "dnsresolve");
103

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

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

    
110
?>
111

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

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

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

    
121
<?php
122

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

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

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

    
172
<script type="text/javascript">
173
//<![CDATA[
174
	jQuery('#loading').html('');
175
//]]>
176
</script>
177
</body>
178
</html>
(36-36/254)