Project

General

Profile

Download (6.23 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-2019 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

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

    
33
@ini_set('zlib.output_compression', 0);
34
@ini_set('implicit_flush', 1);
35

    
36
require_once("guiconfig.inc");
37

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

    
55
$leases = system_get_dhcpleases();
56

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

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

    
66
$arp_table = system_get_arp_table();
67

    
68
$i = 0;
69

    
70
/* if list */
71
$ifdescrs = get_configured_interface_with_descr();
72

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

    
80
function _getHostName($mac, $ip) {
81
	global $dhcpmac, $dhcpip;
82

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

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

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

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

    
112
<?php
113

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

    
119
ob_implicit_flush(1);
120

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

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

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

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

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

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

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

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

    
220
	</div>
221
</div>
222

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

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

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