Project

General

Profile

Download (7.78 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-2021 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
// delete arp entry
42
if (isset($_POST['deleteentry'])) {
43
	$ip = $_POST['deleteentry'];
44
	if (is_ipaddrv4($ip)) {
45
		$ret = mwexec("arp -d " . $_POST['deleteentry'], true);
46
	} else {
47
		$ret = 1;
48
	}
49
	if ($ret) {
50
		$savemsg = sprintf(gettext("%s is not a valid IPv4 address or could not be deleted."), $ip);
51
		$savemsgtype = 'alert-warning';
52
	} else {
53
		$savemsg = sprintf(gettext("The ARP cache entry for %s has been deleted."), $ip);
54
		$savemsgtype = 'success';
55
	}
56
} elseif (isset($_POST['cleararptable'])) {
57
	$out = "";
58
	$ret = exec("/usr/sbin/arp -d -a", $out, $arpTableRetVal);
59
	if ($arpTableRetVal == 0) { 
60
		$savemsg = gettext("ARP Table has been cleared.");
61
		$savemsgtype = 'success';
62
	} else {
63
		$savemsg = gettext("Unable to clear ARP Table.");
64
		$savemsgtype = 'alert-warning';
65
	}
66
}
67

    
68

    
69
$arp_table = prepare_ARP_table();
70

    
71
$pgtitle = array(gettext("Diagnostics"), gettext("ARP Table"));
72
include("head.inc");
73

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

    
118
<div class="panel panel-default">
119
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('ARP Table')?></h2></div>
120
	<div class="panel-body">
121

    
122
<div class="table-responsive">
123
	<table class="sortable-theme-bootstrap table table-striped table-hover" data-sortable>
124
		<thead>
125
			<tr>
126
				<th><?= gettext("Interface")?></th>
127
				<th><?= gettext("IP address")?></th>
128
				<th><?= gettext("MAC address")?></th>
129
				<th><?= gettext("Hostname")?></th>
130
				<th><?= gettext("Status")?></th>
131
				<th><?= gettext("Link Type")?></th>
132
				<th data-sortable="false"><?=gettext("Actions")?></th>
133
			</tr>
134
		</thead>
135
		<tbody>
136

    
137
<?php
138
		foreach ($arp_table as $entry): ?>
139
			<tr>
140
				<td><?=$entry['interface']?></td>
141
				<td><?=$entry['ip-address']?></td>
142
				<td><?=$entry['mac-address']?></td>
143
				<td><?=$entry['dnsresolve']?></td>
144
				<td><?=$entry['expires']?></td>
145
				<td><?=$entry['type']?></td>
146
				<td>
147
					<a class="fa fa-trash" title="<?=gettext('Delete arp cache entry')?>"	href="diag_arp.php?deleteentry=<?=$entry['ip-address']?>" usepost></a>
148
				</td>
149
			</tr>
150
<?php
151
		endforeach
152
?>
153
		</tbody>
154
	</table>
155
</div>
156

    
157
	</div>
158
</div>
159

    
160
<nav class="action-buttons">
161
	<button id="cleararp" class="btn btn-danger no-confirm">
162
		<i class="fa fa-trash icon-embed-btn"></i>
163
		<?=gettext("Clear ARP Table")?>
164
	</button>
165
</nav>
166

    
167
<script type="text/javascript">
168
//<![CDATA[
169
// Clear the "loading" div once the page has loaded"
170
events.push(function() {
171
	$('#loading').empty();
172

    
173
	// Make these controls plain buttons
174
	$("#btnsearch").prop('type', 'button');
175
	$("#btnclear").prop('type', 'button');
176

    
177
	// Search for a term in the entry name and/or dn
178
	$("#btnsearch").click(function() {
179
		var searchstr = $('#searchstr').val().toLowerCase();
180
		var table = $("table tbody");
181
		var where = $('#where').val();
182

    
183
		table.find('tr').each(function (i) {
184
			var $tds = $(this).find('td'),
185
				iface    = $tds.eq(0).text().trim().toLowerCase(),
186
				ipaddr   = $tds.eq(1).text().trim().toLowerCase();
187
				macaddr  = $tds.eq(2).text().trim().toLowerCase();
188
				hostname = $tds.eq(3).text().trim().toLowerCase();
189
				stat     = $tds.eq(4).text().trim().toLowerCase();
190
				linktype = $tds.eq(5).text().trim().toLowerCase();
191

    
192
			regexp = new RegExp(searchstr);
193
			if (searchstr.length > 0) {
194
				if (!(regexp.test(iface)    && ((where == 0) || (where == 6))) &&
195
				    !(regexp.test(ipaddr)   && ((where == 1) || (where == 6))) &&
196
				    !(regexp.test(macaddr)  && ((where == 2) || (where == 6))) &&
197
				    !(regexp.test(hostname) && ((where == 3) || (where == 6))) &&
198
				    !(regexp.test(stat)     && ((where == 4) || (where == 6))) &&
199
				    !(regexp.test(linktype) && ((where == 5) || (where == 6)))
200
				    ) {
201
					$(this).hide();
202
				} else {
203
					$(this).show();
204
				}
205
			} else {
206
				$(this).show();	// A blank search string shows all
207
			}
208
		});
209
	});
210

    
211
	// Clear the search term and unhide all rows (that were hidden during a previous search)
212
	$("#btnclear").click(function() {
213
		var table = $("table tbody");
214

    
215
		$('#searchstr').val("");
216

    
217
		table.find('tr').each(function (i) {
218
			$(this).show();
219
		});
220
	});
221

    
222
	// Hitting the enter key will do the same as clicking the search button
223
	$("#searchstr").on("keyup", function (event) {
224
		if (event.keyCode == 13) {
225
			$("#btnsearch").get(0).click();
226
		}
227
	});
228

    
229
	$('#cleararp').click(function() {
230
		if (confirm("Are you sure you wish to clear ARP table?")) {
231
			postSubmit({cleararptable: 'true'}, 'diag_arp.php');
232
		}
233
	});
234

    
235
});
236
//]]>
237
</script>
238

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

    
248
<?php
249
include("foot.inc");
250
?>
(7-7/229)