Project

General

Profile

Download (8.55 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-2023 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
require_once('diag_arp.inc');
40

    
41
define('ARP_BIN', '/usr/sbin/arp');
42

    
43
/* delete ARP cache entry */
44
if (isset($_POST['deleteentry'])) {
45
	$ip = $_POST['deleteentry'];
46

    
47
	$rc = 0;
48
	$savemsg = sprintf(gettext('The ARP cache entry for %s as been deleted.'), $ip);
49
	$savemsgtype = 'success';
50

    
51
	if (is_ipaddrv4($ip)) {
52
		exec(implode(' ', [ARP_BIN, '-d', escapeshellarg($ip)]), $out, $rc);
53
		if ($rc !== 0) {
54
			$savemsg = sprintf(gettext('%s could not be deleted.'), $ip);
55
			$savemsgtype = 'alert-warning';
56
		}
57
	} else {
58
		$savemsg = sprintf(gettext('%s is not a valid IPv4 address.'), $ip);
59
		$savemsgtype = 'alert-warning';
60
	}
61
}
62

    
63
/* clear ARP table */
64
if (isset($_POST['cleararptable'])) {
65
	$rc = 0;
66
	$savemsg = gettext('ARP table has been cleared.');
67
	$savemsgtype = 'success';
68

    
69
	exec(implode(' ', [ARP_BIN, '-d', '-a']), $out, $rc);
70
	if ($rc !== 0) {
71
		$savemsg = gettext('Unable to clear ARP table.');
72
		$savemsgtype = 'alert-warning';
73
	}
74
}
75

    
76
$arp_table = prepare_ARP_table();
77

    
78
$pgtitle = [gettext('Diagnostics'), gettext('ARP Table')];
79
include('head.inc');
80

    
81
// Handle save msg if defined
82
if ($savemsg) {
83
	print_info_box(htmlentities($savemsg), $savemsgtype);
84
}
85
?>
86
<div class="panel panel-default" id="search-panel">
87
<div class="panel-heading">
88
	<h2 class="panel-title">
89
		<?=gettext('Search')?>
90
		<span class="widget-heading-icon pull-right">
91
			<a data-toggle="collapse" href="#search-panel_panel-body">
92
				<i class="fa-solid fa-plus-circle"></i>
93
			</a>
94
		</span>
95
	</h2>
96
</div>
97
<div id="search-panel_panel-body" class="panel-body collapse in">
98
	<div class="form-group">
99
		<label class="col-sm-2 control-label">
100
			<?=gettext('Search Term')?>
101
		</label>
102
		<div class="col-sm-5"><input class="form-control" name="searchstr" id="searchstr" type="text"/></div>
103
		<div class="col-sm-2">
104
			<select id="where" class="form-control">
105
				<option value="1" selected><?=gettext('All');?></option>
106
				<option value="2"><?=gettext('Interface')?></option>
107
				<option value="3"><?=gettext('IP Address')?></option>
108
				<option value="4"><?=gettext('MAC Address')?></option>
109
				<option value="5"><?=gettext('Hostname')?></option>
110
				<option value="6"><?=gettext('Status')?></option>
111
				<option value="7"><?=gettext('Link Type')?></option>
112
			</select>
113
		</div>
114
		<div class="col-sm-3">
115
			<a id="btnsearch" title="<?=gettext("Search")?>" class="btn btn-primary btn-sm"><i class="fa-solid fa-search icon-embed-btn"></i><?=gettext("Search")?></a>
116
			<a id="btnclear" title="<?=gettext("Clear")?>" class="btn btn-info btn-sm"><i class="fa-solid fa-undo icon-embed-btn"></i><?=gettext("Clear")?></a>
117
		</div>
118
		<div class="col-sm-10 col-sm-offset-2">
119
			<span class="help-block"><?=gettext('Enter a search string or *nix regular expression to filter entries.')?></span>
120
		</div>
121
	</div>
122
</div>
123
</div>
124

    
125
<div class="panel panel-default">
126
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('ARP Table')?></h2></div>
127
	<div class="panel-body">
128
		<div class="table-responsive">
129
			<table class="sortable-theme-bootstrap table table-striped table-hover" data-sortable>
130
				<thead>
131
					<tr>
132
						<th><?= gettext("Interface")?></th>
133
						<th><?= gettext("IP Address")?></th>
134
						<th><?= gettext("MAC Address")?></th>
135
						<th><?= gettext("Hostname")?></th>
136
						<th><?= gettext("Status")?></th>
137
						<th><?= gettext("Link Type")?></th>
138
						<th style="white-space:nowrap;" data-sortable="false"><?=gettext("Actions")?></th>
139
					</tr>
140
				</thead>
141
				<tbody>
142

    
143
<?php
144
	foreach ($arp_table as $entry): ?>
145
				<tr>
146
					<td><?=$entry['interface']?></td>
147
					<td><?=$entry['ip-address']?></td>
148
					<td><?=$entry['mac-address']?></td>
149
					<td><?=$entry['dnsresolve']?></td>
150
					<td><?=$entry['expires']?></td>
151
					<td><?=$entry['type']?></td>
152
					<td>
153
<?php if ($entry['assigned']): /* only useful for assigned interfaces */ ?>
154
						<a class="fa-solid fa-plus-square" title="<?=gettext('Add WOL mapping')?>" href="services_wol_edit.php?if=<?=htmlspecialchars($entry['if'])?>&amp;mac=<?=htmlspecialchars($entry['mac-address'])?>&amp;descr=<?=htmlspecialchars($entry['dnsresolve'])?>"></a>
155
						<a class="fa-solid fa-power-off" title="<?=gettext('Send WOL packet')?>" href="services_wol.php?if=<?=htmlspecialchars($entry['if'])?>&amp;mac=<?=htmlspecialchars($entry['mac-address'])?>" usepost></a>
156
<?php endif; ?>
157
						<a class="fa-solid fa-trash-can" title="<?=gettext('Delete ARP cache entry')?>" href="diag_arp.php?deleteentry=<?=$entry['ip-address']?>" usepost></a>
158
					</td>
159
				</tr>
160
<?php
161
	endforeach;
162
?>
163
				</tbody>
164
			</table>
165
		</div>
166
	</div>
167
</div>
168

    
169
<nav class="action-buttons">
170
	<button id="cleararp" class="btn btn-danger no-confirm">
171
		<i class="fa-solid fa-trash-can icon-embed-btn"></i>
172
		<?=gettext("Clear ARP Table")?>
173
	</button>
174
</nav>
175

    
176
<script type="text/javascript">
177
//<![CDATA[
178
// Clear the "loading" div once the page has loaded"
179
events.push(function() {
180
	$('#loading').empty();
181

    
182
	// Make these controls plain buttons
183
	$("#btnsearch").prop('type', 'button');
184
	$("#btnclear").prop('type', 'button');
185

    
186
	// Search for a term in the entry name and/or dn
187
	$("#btnsearch").click(function() {
188
		var searchstr = $('#searchstr').val().toLowerCase();
189
		var table = $("table tbody");
190
		var where = $('#where').val();
191

    
192
		table.find('tr').each(function (i) {
193
			var $tds = $(this).find('td'),
194
				iface    = $tds.eq(0).text().trim().toLowerCase(),
195
				ipaddr   = $tds.eq(1).text().trim().toLowerCase();
196
				macaddr  = $tds.eq(2).text().trim().toLowerCase();
197
				hostname = $tds.eq(3).text().trim().toLowerCase();
198
				stat     = $tds.eq(4).text().trim().toLowerCase();
199
				linktype = $tds.eq(5).text().trim().toLowerCase();
200

    
201
			regexp = new RegExp(searchstr);
202
			if (searchstr.length > 0) {
203
				if (!(regexp.test(iface)    && ((where == 2) || (where == 1))) &&
204
				    !(regexp.test(ipaddr)   && ((where == 3) || (where == 1))) &&
205
				    !(regexp.test(macaddr)  && ((where == 4) || (where == 1))) &&
206
				    !(regexp.test(hostname) && ((where == 5) || (where == 1))) &&
207
				    !(regexp.test(stat)     && ((where == 6) || (where == 1))) &&
208
				    !(regexp.test(linktype) && ((where == 7) || (where == 1)))
209
				    ) {
210
					$(this).hide();
211
				} else {
212
					$(this).show();
213
				}
214
			} else {
215
				$(this).show();	// A blank search string shows all
216
			}
217
		});
218
	});
219

    
220
	// Clear the search term and unhide all rows (that were hidden during a previous search)
221
	$("#btnclear").click(function() {
222
		var table = $("table tbody");
223

    
224
		$('#searchstr').val("");
225

    
226
		$('#where option[value="1"]').prop('selected', true);
227

    
228
		table.find('tr').each(function (i) {
229
			$(this).show();
230
		});
231
	});
232

    
233
	// Hitting the enter key will do the same as clicking the search button
234
	$("#searchstr").on("keyup", function (event) {
235
		if (event.keyCode == 13) {
236
			$("#btnsearch").get(0).click();
237
		}
238
	});
239

    
240
	$('#cleararp').click(function() {
241
		if (confirm("<?=gettext('Are you sure you wish to clear ARP table?')?>")) {
242
			postSubmit({cleararptable: 'true'}, 'diag_arp.php');
243
		}
244
	});
245

    
246
});
247
//]]>
248
</script>
249

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

    
259
<?php
260
include('foot.inc');
(7-7/228)