Project

General

Profile

Download (6.32 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_arp.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2019 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-diagnostics-arptable
30
##|*NAME=Diagnostics: ARP Table
31
##|*DESCR=Allow access to the 'Diagnostics: ARP Table' page.
32
##|*MATCH=diag_arp.php*
33
##|-PRIV
34

    
35
@ini_set('zlib.output_compression', 0);
36
@ini_set('implicit_flush', 1);
37

    
38
require_once("guiconfig.inc");
39

    
40
// delete arp entry
41
if (isset($_POST['deleteentry'])) {
42
	$ip = $_POST['deleteentry'];
43
	if (is_ipaddrv4($ip)) {
44
		$ret = mwexec("arp -d " . $_POST['deleteentry'], true);
45
	} else {
46
		$ret = 1;
47
	}
48
	if ($ret) {
49
		$savemsg = sprintf(gettext("%s is not a valid IPv4 address or could not be deleted."), $ip);
50
		$savemsgtype = 'alert-warning';
51
	} else {
52
		$savemsg = sprintf(gettext("The ARP cache entry for %s has been deleted."), $ip);
53
		$savemsgtype = 'success';
54
	}
55
}
56

    
57
$leases = system_get_dhcpleases();
58

    
59
// Put this in an easy to use form
60
$dhcpmac = array();
61
$dhcpip = array();
62

    
63
foreach ($leases['lease'] as $value) {
64
	$dhcpmac[$value['mac']] = $value['hostname'];
65
	$dhcpip[$value['ip']] = $value['hostname'];
66
}
67

    
68
$arp_table = system_get_arp_table();
69

    
70
$i = 0;
71

    
72
/* if list */
73
$ifdescrs = get_configured_interface_with_descr();
74

    
75
foreach ($ifdescrs as $key => $interface) {
76
	$thisif = convert_friendly_interface_to_real_interface_name($key);
77
	if (!empty($thisif)) {
78
		$hwif[$thisif] = $interface;
79
	}
80
}
81

    
82
function _getHostName($mac, $ip) {
83
	global $dhcpmac, $dhcpip;
84

    
85
	if ($dhcpmac[$mac]) {
86
		return $dhcpmac[$mac];
87
	} else if ($dhcpip[$ip]) {
88
		return $dhcpip[$ip];
89
	} else {
90
		exec("host -W 1 " . escapeshellarg($ip), $output);
91
		if (preg_match('/.*pointer ([A-Za-z_0-9.-]+)\..*/', $output[0], $matches)) {
92
			if ($matches[1] <> $ip) {
93
				return $matches[1];
94
			}
95
		}
96
	}
97
	return "";
98
}
99

    
100
$pgtitle = array(gettext("Diagnostics"), gettext("ARP Table"));
101
include("head.inc");
102

    
103
// Handle save msg if defined
104
if ($savemsg) {
105
	print_info_box(htmlentities($savemsg), $savemsgtype);
106
}
107
?>
108

    
109
<!-- On modern hardware the table will load so fast you may never see this! -->
110
<div id="loading">
111
	<?= gettext(" Loading, please wait...")?>
112
</div>
113

    
114
<?php
115

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

    
121
ob_implicit_flush(1);
122

    
123
// Resolve hostnames and replace Z_ with "".  The intention
124
// is to sort the list by hostnames, alpha and then the non
125
// resolvable addresses will appear last in the list.
126
$dnsavailable=1;
127
$dns = trim(_getHostName("", "8.8.8.8"));
128
if ($dns == "") {
129
	$dns = trim(_getHostName("", "8.8.4.4"));
130
	if ($dns == "") {
131
		$dnsavailable = 0;
132
	}
133
}
134

    
135
foreach ($arp_table as &$entry) {
136
	if ($dnsavailable && !empty($entry['mac-address'])) {
137
		$dns = trim(_getHostName($entry['mac-address'],
138
		    $entry['ip-address']));
139
	} else {
140
		$dns="";
141
	}
142
	if (trim($dns)) {
143
		$entry['dnsresolve'] = "$dns";
144
	} else {
145
		$entry['dnsresolve'] = "Z_ ";
146
	}
147
}
148
unset($entry);
149

    
150
// Sort the data alpha first
151
$arp_table = msort($arp_table, "dnsresolve");
152

    
153
// Load MAC-Manufacturer table
154
$mac_man = load_mac_manufacturer_table();
155
?>
156
<div class="panel panel-default">
157
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('ARP Table')?></h2></div>
158
	<div class="panel-body">
159

    
160
<div class="table-responsive">
161
	<table class="sortable-theme-bootstrap table table-striped table-hover" data-sortable>
162
		<thead>
163
			<tr>
164
				<th><?= gettext("Interface")?></th>
165
				<th><?= gettext("IP address")?></th>
166
				<th><?= gettext("MAC address")?></th>
167
				<th><?= gettext("Hostname")?></th>
168
				<th><?= gettext("Status")?></th>
169
				<th><?= gettext("Link Type")?></th>
170
				<th data-sortable="false"><?=gettext("Actions")?></th>
171
			</tr>
172
		</thead>
173
		<tbody>
174

    
175
<?php
176
		foreach ($arp_table as $entry): ?>
177
			<tr>
178
				<td><?=$hwif[$entry['interface']]?></td>
179
				<td><?=$entry['ip-address']?></td>
180
<?php
181
				if (empty($entry['mac-address'])) {
182
					$mac = '(' . gettext("Incomplete") .')';
183
					print "<td>{$mac}</td>";
184
				} else {
185
					$mac = trim($entry['mac-address']);
186
					print "<td>{$mac}";
187
					$mac_hi = strtoupper($mac[0] . $mac[1] .
188
					    $mac[3] . $mac[4] . $mac[6] .
189
					    $mac[7]);
190

    
191
					if (isset($mac_man[$mac_hi])) {
192
						print '<small>('.
193
						    $mac_man[$mac_hi] .
194
						    ')</small>';
195
					}
196
				}
197

    
198
				$status = '';
199
				if (!empty($entry['expires'])) {
200
					$status = sprintf(gettext(
201
					    "Expires in %d seconds"),
202
					    $entry['expires']);
203
				} else if (!empty($entry['permanent'])) {
204
					$status = gettext("Permanent");
205
				}
206
?>
207
				</td>
208
				<td><?=trim(str_replace("Z_ ", "", $entry['dnsresolve']))?></td>
209
				<td><?=ucfirst($status)?></td>
210
				<td><?=$entry['type']?></td>
211
				<td>
212
					<a class="fa fa-trash" title="<?=gettext('Delete arp cache entry')?>"	href="diag_arp.php?deleteentry=<?=$entry['ip-address']?>" usepost></a>
213
				</td>
214
			</tr>
215
<?php
216
		endforeach
217
?>
218
		</tbody>
219
	</table>
220
</div>
221

    
222
	</div>
223
</div>
224

    
225
<script type="text/javascript">
226
//<![CDATA[
227
// Clear the "loading" div once the page has loaded"
228
events.push(function() {
229
	$('#loading').empty();
230
});
231
//]]>
232
</script>
233

    
234
<div class="infoblock blockopen">
235
<?php
236
print_info_box(sprintf(gettext('Local IPv6 peers use %1$sNDP%2$s instead of ARP.'), '<a href="diag_ndp.php">', '</a>') . '<br />' .
237
   '<br />' . gettext('Permanent ARP entries are shown for local interfaces or static ARP entries.') .
238
   '<br />' . gettext('Normal dynamic ARP entries show a countdown timer until they will expire and then be re-checked.') .
239
   '<br />' . gettext('Incomplete ARP entries indicate that the target host has not yet replied to an ARP request.'), 'info', false);
240
?>
241
</div>
242

    
243
<?php
244
include("foot.inc");
245
?>
(7-7/225)