Project

General

Profile

Download (17.3 KB) Statistics
| Branch: | Tag: | Revision:
1 ab6a5cfc Scott Ullrich
<?php
2
/*
3 ce77a9c4 Phil Davis
    diag_packet_capture.php
4
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
5 29aef6c4 Jim Thompson
	All rights reserved
6
7 ab6a5cfc Scott Ullrich
	Redistribution and use in source and binary forms, with or without
8
	modification, are permitted provided that the following conditions are met:
9
10
	1. Redistributions of source code must retain the above copyright notice,
11
	this list of conditions and the following disclaimer.
12
13
	2. Redistributions in binary form must reproduce the above copyright
14
	notice, this list of conditions and the following disclaimer in the
15
	documentation and/or other materials provided with the distribution.
16
17
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
	POSSIBILITY OF SUCH DAMAGE.
27
*/
28
29 f35abee2 jim-p
/*
30 13d193c2 Scott Ullrich
	pfSense_BUILDER_BINARIES:	/bin/ps	/usr/bin/grep	/usr/sbin/tcpdump
31
	pfSense_MODULE:	routing
32
*/
33
34 6b07c15a Matthew Grooms
##|+PRIV
35
##|*IDENT=page-diagnostics-packetcapture
36
##|*NAME=Diagnostics: Packet Capture page
37
##|*DESCR=Allow access to the 'Diagnostics: Packet Capture' page.
38
##|*MATCH=diag_packet_capture.php*
39
##|-PRIV
40
41 7c9a30c8 jim-p
$allowautocomplete = true;
42
43 017e4ad3 jim-p
function fixup_host_logic($value) {
44
	return str_replace(array(" ", ",", "+", "|", "!"), array("", "and ", "and ", "or ", "not "), $value);
45
}
46
function strip_host_logic($value) {
47
	return str_replace(array(" ", ",", "+", "|", "!"), array("", "", "", "", ""), $value);
48
}
49
function get_host_boolean($value, $host) {
50
	$value = str_replace(array("!", $host), array("", ""), $value);
51
	$andor = "";
52
	switch (trim($value)) {
53
		case "|":
54
			$andor = "or ";
55
			break;
56
		case ",":
57
		case "+":
58
			$andor = "and ";
59
			break;
60
	}
61
	return $andor;
62
}
63
function has_not($value) {
64
	return strpos($value, '!') !== false;
65
}
66 715d2895 jim-p
function fixup_not($value) {
67
	return str_replace("!", "not ", $value);
68
}
69
function strip_not($value) {
70 017e4ad3 jim-p
	return ltrim(trim($value), '!');
71
}
72
73
function fixup_host($value, $position) {
74
	$host = strip_host_logic($value);
75
	$not = has_not($value) ? "not " : "";
76
	$andor = ($position > 0) ? get_host_boolean($value, $host) : "";
77
	if (is_ipaddr($host))
78
		return "{$andor}host {$not}" . $host;
79
	elseif (is_subnet($host))
80
		return "{$andor}net {$not}" . $host;
81
	else
82
		return "";
83 715d2895 jim-p
}
84
85 f257c139 jim-p
if ($_POST['downloadbtn'] == gettext("Download Capture"))
86
	$nocsrf = true;
87
88 1c550bed Renato Botelho
$pgtitle = array(gettext("Diagnostics"), gettext("Packet Capture"));
89 d7cd7129 Scott Ullrich
require_once("guiconfig.inc");
90
require_once("pfsense-utils.inc");
91 ab6a5cfc Scott Ullrich
92 4e7d1665 Scott Ullrich
$fp = "/root/";
93 ab6a5cfc Scott Ullrich
$fn = "packetcapture.cap";
94 68ed7d9d Chris Buechler
$snaplen = 0;//default packet length
95 ab6a5cfc Scott Ullrich
$count = 100;//default number of packets to capture
96
97 fd8774c0 jim-p
$fams = array('ip', 'ip6');
98 715d2895 jim-p
$protos = array('icmp', 'icmp6', 'tcp', 'udp', 'arp', 'carp', 'esp',
99
		'!icmp', '!icmp6', '!tcp', '!udp', '!arp', '!carp', '!esp');
100 fd8774c0 jim-p
101 391cd070 Darren Embry
$input_errors = array();
102
103 f7b6c87a Darren Embry
$interfaces = get_configured_interface_with_descr();
104
if (isset($config['ipsec']['enable']))
105
	$interfaces['ipsec'] = "IPsec";
106
foreach (array('server', 'client') as $mode) {
107
	if (is_array($config['openvpn']["openvpn-{$mode}"])) {
108
		foreach ($config['openvpn']["openvpn-{$mode}"] as $id => $setting) {
109
			if (!isset($setting['disable'])) {
110
				$interfaces['ovpn' . substr($mode, 0, 1) . $setting['vpnid']] = gettext("OpenVPN") . " ".$mode.": ".htmlspecialchars($setting['description']);
111
			}
112
		}
113
	}
114
}
115
116 ab6a5cfc Scott Ullrich
if ($_POST) {
117
	$host = $_POST['host'];
118
	$selectedif = $_POST['interface'];
119
	$count = $_POST['count'];
120 391cd070 Darren Embry
	$snaplen = $_POST['snaplen'];
121 ab6a5cfc Scott Ullrich
	$port = $_POST['port'];
122
	$detail = $_POST['detail'];
123 f35abee2 jim-p
	$fam = $_POST['fam'];
124 fd8774c0 jim-p
	$proto = $_POST['proto'];
125 f35abee2 jim-p
126 20e7e444 jim-p
	if (!array_key_exists($selectedif, $interfaces)) {
127 622caf8f Darren Embry
		$input_errors[] = gettext("Invalid interface.");
128
	}
129
	if ($fam !== "" && $fam !== "ip" && $fam !== "ip6") {
130
		$input_errors[] = gettext("Invalid address family.");
131
	}
132 715d2895 jim-p
	if ($proto !== "" && !in_array(strip_not($proto), $protos)) {
133 622caf8f Darren Embry
		$input_errors[] = gettext("Invalid protocol.");
134
	}
135
	
136 391cd070 Darren Embry
	if ($host != "") {
137 017e4ad3 jim-p
		$host_string = str_replace(array(" ", "|", ","), array("", "#|", "#+"), $host);
138
		if (strpos($host_string, '#') === false) {
139
			$hosts = array($host);
140
		} else {
141
			$hosts = explode('#', $host_string);
142
		}
143
		foreach ($hosts as $h) {
144
			if (!is_subnet(strip_host_logic($h)) && !is_ipaddr(strip_host_logic($h))) {
145
				$input_errors[] = sprintf(gettext("A valid IP address or CIDR block must be specified. [%s]"), $h);
146
			}
147 391cd070 Darren Embry
		}
148
	}
149
	if ($port != "") {
150 715d2895 jim-p
		if (!is_port(strip_not($port))) {
151 391cd070 Darren Embry
			$input_errors[] = gettext("Invalid value specified for port.");
152
		}
153
	}
154
	if ($snaplen == "") {
155
		$snaplen = 0;
156 b39ca83c Scott Ullrich
	} else {
157 391cd070 Darren Embry
		if (!is_numeric($snaplen) || $snaplen < 0) {
158
			$input_errors[] = gettext("Invalid value specified for packet length.");
159
		}
160
	}
161
	if ($count == "") {
162
		$count = 0;
163
	} else {
164
		if (!is_numeric($count) || $count < 0) {
165
			$input_errors[] = gettext("Invalid value specified for packet count.");
166
		}
167 ab6a5cfc Scott Ullrich
	}
168
169 391cd070 Darren Embry
	if (!count($input_errors)) {
170
		$do_tcpdump = true;
171 f35abee2 jim-p
172 391cd070 Darren Embry
		conf_mount_rw();
173 ab6a5cfc Scott Ullrich
174 8d64d6b5 N0YB
		if ($_POST['promiscuous']) {
175
			//if promiscuous mode is checked
176
			$disablepromiscuous = "";
177
		} else {
178
			//if promiscuous mode is unchecked
179
			$disablepromiscuous = "-p";
180
		}
181
182 391cd070 Darren Embry
		if ($_POST['dnsquery']) {
183
			//if dns lookup is checked
184
			$disabledns = "";
185
		} else {
186
			//if dns lookup is unchecked
187
			$disabledns = "-n";
188
		}
189 d5c2fde5 Scott Ullrich
190 391cd070 Darren Embry
		if ($_POST['startbtn'] != "" ) {
191
			$action = gettext("Start");
192 d5c2fde5 Scott Ullrich
193 391cd070 Darren Embry
			//delete previous packet capture if it exists
194
			if (file_exists($fp.$fn))
195
				unlink ($fp.$fn);
196
197
		} elseif ($_POST['stopbtn']!= "") {
198
			$action = gettext("Stop");
199
			$processes_running = trim(shell_exec("/bin/ps axw -O pid= | /usr/bin/grep tcpdump | /usr/bin/grep {$fn} | /usr/bin/egrep -v '(pflog|grep)'"));
200
201
			//explode processes into an array, (delimiter is new line)
202
			$processes_running_array = explode("\n", $processes_running);
203
204
			//kill each of the packetcapture processes
205
			foreach ($processes_running_array as $process) {
206
				$process_id_pos = strpos($process, ' ');
207
				$process_id = substr($process, 0, $process_id_pos);
208
				exec("kill $process_id");
209
			}
210 d5c2fde5 Scott Ullrich
211 391cd070 Darren Embry
		} elseif ($_POST['downloadbtn']!= "") {
212
			//download file
213
			$fs = filesize($fp.$fn);
214
			header("Content-Type: application/octet-stream");
215
			header("Content-Disposition: attachment; filename=$fn");
216
			header("Content-Length: $fs");
217
			readfile($fp.$fn);
218
			exit;
219
		}
220 ab6a5cfc Scott Ullrich
	}
221 b39ca83c Scott Ullrich
} else {
222 ab6a5cfc Scott Ullrich
	$do_tcpdump = false;
223
}
224 f7b6c87a Darren Embry
225 ab6a5cfc Scott Ullrich
include("head.inc"); ?>
226 b39ca83c Scott Ullrich
227 ab6a5cfc Scott Ullrich
<body link="#000000" vlink="#0000CC" alink="#0000CC">
228 b39ca83c Scott Ullrich
229
<?php
230 f35abee2 jim-p
include("fbegin.inc");
231 b39ca83c Scott Ullrich
?>
232 ab6a5cfc Scott Ullrich
233 391cd070 Darren Embry
<?php if ($input_errors) print_input_errors($input_errors); ?>
234
235 e19669c5 Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="diag packet capture">
236 89fae3e7 jim-p
	<tr><td>
237
	<form action="diag_packet_capture.php" method="post" name="iform" id="iform">
238 e19669c5 Colin Fleming
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="table">
239 f35abee2 jim-p
		<tr>
240 8d64d6b5 N0YB
			<td colspan="3" valign="top" class="listtopic"><?=gettext("Packet capture");?></td>
241 89fae3e7 jim-p
		</tr>
242
		<tr>
243
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
244 8d64d6b5 N0YB
			<td width="32%" class="vtable">
245 89fae3e7 jim-p
			<select name="interface">
246 391cd070 Darren Embry
			<?php
247
			?>
248
			<?php foreach ($interfaces as $iface => $ifacename): ?>
249 e19669c5 Colin Fleming
				<option value="<?=$iface;?>" <?php if ($selectedif == $iface) echo "selected=\"selected\""; ?>>
250 391cd070 Darren Embry
				<?php echo $ifacename;?>
251
				</option>
252
			<?php endforeach; ?>
253 89fae3e7 jim-p
			</select>
254 8cd558b6 ayvis
			<br /><?=gettext("Select the interface on which to capture traffic.");?>
255 89fae3e7 jim-p
			</td>
256 b2f73235 jim-p
		</tr>
257
		<tr>
258
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Promiscuous");?></td>
259 8d64d6b5 N0YB
			<td width="51%" class="vtable">
260 e19669c5 Colin Fleming
			<input name="promiscuous" type="checkbox"<?php if($_POST['promiscuous']) echo " checked=\"checked\""; ?> />
261 8cd558b6 ayvis
			<br /><?=gettext("If checked, the");?> <a target="_blank" href="http://www.freebsd.org/cgi/man.cgi?query=tcpdump&amp;apropos=0&amp;sektion=0&amp;manpath=FreeBSD+8.3-stable&amp;arch=default&amp;format=html"><?= gettext("packet capture")?></a> <?= gettext("will be performed using promiscuous mode.");?>
262
			<br /><b><?=gettext("Note");?>: </b><?=gettext("Some network adapters do not support or work well in promiscuous mode.");?>
263 8d64d6b5 N0YB
			</td>
264 89fae3e7 jim-p
		</tr>
265
		<tr>
266
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Address Family");?></td>
267 8d64d6b5 N0YB
			<td colspan="2" width="83%" class="vtable">
268 89fae3e7 jim-p
			<select name="fam">
269
				<option value="">Any</option>
270 e19669c5 Colin Fleming
				<option value="ip" <?php if ($fam == "ip") echo "selected=\"selected\""; ?>>IPv4 Only</option>
271
				<option value="ip6" <?php if ($fam == "ip6") echo "selected=\"selected\""; ?>>IPv6 Only</option>
272 89fae3e7 jim-p
			</select>
273 8cd558b6 ayvis
			<br /><?=gettext("Select the type of traffic to be captured, either Any, IPv4 only or IPv6 only.");?>
274 89fae3e7 jim-p
			</td>
275
		</tr>
276 fd8774c0 jim-p
		<tr>
277
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
278 8d64d6b5 N0YB
			<td colspan="2" width="83%" class="vtable">
279 fd8774c0 jim-p
			<select name="proto">
280
				<option value="">Any</option>
281 e19669c5 Colin Fleming
				<option value="icmp" <?php if ($proto == "icmp") echo "selected=\"selected\""; ?>>ICMP</option>
282 715d2895 jim-p
				<option value="!icmp" <?php if ($proto == "!icmp") echo "selected=\"selected\""; ?>>Exclude ICMP</option>
283 e19669c5 Colin Fleming
				<option value="icmp6" <?php if ($proto == "icmp6") echo "selected=\"selected\""; ?>>ICMPv6</option>
284 715d2895 jim-p
				<option value="!icmp6" <?php if ($proto == "!icmp6") echo "selected=\"selected\""; ?>>Exclude ICMPv6</option>
285 e19669c5 Colin Fleming
				<option value="tcp" <?php if ($proto == "tcp") echo "selected=\"selected\""; ?>>TCP</option>
286 715d2895 jim-p
				<option value="!tcp" <?php if ($proto == "!tcp") echo "selected=\"selected\""; ?>>Exclude TCP</option>
287 e19669c5 Colin Fleming
				<option value="udp" <?php if ($proto == "udp") echo "selected=\"selected\""; ?>>UDP</option>
288 715d2895 jim-p
				<option value="!udp" <?php if ($proto == "!udp") echo "selected=\"selected\""; ?>>Exclude UDP</option>
289 e19669c5 Colin Fleming
				<option value="arp" <?php if ($proto == "arp") echo "selected=\"selected\""; ?>>ARP</option>
290 715d2895 jim-p
				<option value="!arp" <?php if ($proto == "!arp") echo "selected=\"selected\""; ?>>Exclude ARP</option>
291 e19669c5 Colin Fleming
				<option value="carp" <?php if ($proto == "carp") echo "selected=\"selected\""; ?>>CARP (VRRP)</option>
292 715d2895 jim-p
				<option value="!carp" <?php if ($proto == "!carp") echo "selected=\"selected\""; ?>>Exclude CARP (VRRP)</option>
293 e19669c5 Colin Fleming
				<option value="esp" <?php if ($proto == "esp") echo "selected=\"selected\""; ?>>ESP</option>
294 fd8774c0 jim-p
			</select>
295 8cd558b6 ayvis
			<br /><?=gettext("Select the protocol to capture, or Any.");?>
296 fd8774c0 jim-p
			</td>
297
		</tr>
298 89fae3e7 jim-p
		<tr>
299
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Host Address");?></td>
300 8d64d6b5 N0YB
			<td colspan="2" width="83%" class="vtable">
301 e19669c5 Colin Fleming
			<input name="host" class="formfld host" id="host" size="20" value="<?=htmlspecialchars($host);?>" />
302 8cd558b6 ayvis
			<br /><?=gettext("This value is either the Source or Destination IP address or subnet in CIDR notation. The packet capture will look for this address in either field.");?>
303 77a4e6d7 jim-p
			<br /><?=gettext("Matching can be negated by preceding the value with \"!\". Multiple IP addresses or CIDR subnets may be specified. Comma (\",\") separated values perform a boolean \"and\". Separating with a pipe (\"|\") performs a boolean \"or\".");?>
304 8cd558b6 ayvis
			<br /><?=gettext("If you leave this field blank, all packets on the specified interface will be captured.");?>
305 89fae3e7 jim-p
			</td>
306
		</tr>
307
		<tr>
308
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Port");?></td>
309 8d64d6b5 N0YB
			<td colspan="2" width="83%" class="vtable">
310 e19669c5 Colin Fleming
			<input name="port" class="formfld unknown" id="port" size="5" value="<?=$port;?>" />
311 8cd558b6 ayvis
			<br /><?=gettext("The port can be either the source or destination port. The packet capture will look for this port in either field.");?>
312
			<br /><?=gettext("Leave blank if you do not want to filter by port.");?>
313 89fae3e7 jim-p
			</td>
314
		</tr>
315
		<tr>
316
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Packet Length");?></td>
317 8d64d6b5 N0YB
			<td colspan="2" width="83%" class="vtable">
318 e19669c5 Colin Fleming
			<input name="snaplen" class="formfld unknown" id="snaplen" size="5" value="<?=$snaplen;?>" />
319 8cd558b6 ayvis
			<br /><?=gettext("The Packet length is the number of bytes of each packet that will be captured. Default value is 0, which will capture the entire frame regardless of its size.");?>
320 89fae3e7 jim-p
			</td>
321
		</tr>
322
		<tr>
323
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Count");?></td>
324 8d64d6b5 N0YB
			<td colspan="2" width="83%" class="vtable">
325 e19669c5 Colin Fleming
			<input name="count" class="formfld unknown" id="count" size="5" value="<?=$count;?>" />
326 8cd558b6 ayvis
			<br /><?=gettext("This is the number of packets the packet capture will grab. Default value is 100.") . "<br />" . gettext("Enter 0 (zero) for no count limit.");?>
327 8d64d6b5 N0YB
			</td>
328 89fae3e7 jim-p
		</tr>
329
		<tr>
330
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Level of Detail");?></td>
331 8d64d6b5 N0YB
			<td colspan="2" width="83%" class="vtable">
332 e19669c5 Colin Fleming
			<select name="detail" class="formselect" id="detail" size="1">
333
				<option value="normal" <?php if ($detail == "normal") echo "selected=\"selected\""; ?>><?=gettext("Normal");?></option>
334
				<option value="medium" <?php if ($detail == "medium") echo "selected=\"selected\""; ?>><?=gettext("Medium");?></option>
335
				<option value="high"   <?php if ($detail == "high")   echo "selected=\"selected\""; ?>><?=gettext("High");?></option>
336
				<option value="full"   <?php if ($detail == "full")   echo "selected=\"selected\""; ?>><?=gettext("Full");?></option>
337 89fae3e7 jim-p
			</select>
338 8cd558b6 ayvis
			<br /><?=gettext("This is the level of detail that will be displayed after hitting 'Stop' when the packets have been captured.") .  "<br /><b>" .
339 89fae3e7 jim-p
					gettext("Note:") . "</b> " .
340
					gettext("This option does not affect the level of detail when downloading the packet capture.");?>
341 8d64d6b5 N0YB
			</td>
342 89fae3e7 jim-p
		</tr>
343
		<tr>
344
			<td width="17%" valign="top" class="vncellreq"><?=gettext("Reverse DNS Lookup");?></td>
345 8d64d6b5 N0YB
			<td colspan="2" width="83%" class="vtable">
346 e19669c5 Colin Fleming
			<input name="dnsquery" type="checkbox" <?php if($_POST['dnsquery']) echo " checked=\"checked\""; ?> />
347 8cd558b6 ayvis
			<br /><?=gettext("This check box will cause the packet capture to perform a reverse DNS lookup associated with all IP addresses.");?>
348
			<br /><b><?=gettext("Note");?>: </b><?=gettext("This option can cause delays for large packet captures.");?>
349 89fae3e7 jim-p
			</td>
350
		</tr>
351
		<tr>
352
			<td width="17%" valign="top">&nbsp;</td>
353 8d64d6b5 N0YB
			<td colspan="2" width="83%">
354 b39ca83c Scott Ullrich
<?php
355 d5c2fde5 Scott Ullrich
356 89fae3e7 jim-p
			/* check to see if packet capture tcpdump is already running */
357
			$processcheck = (trim(shell_exec("/bin/ps axw -O pid= | /usr/bin/grep tcpdump | /usr/bin/grep {$fn} | /usr/bin/egrep -v '(pflog|grep)'")));
358
359
			if ($processcheck != "")
360
				$processisrunning = true;
361
			else
362
				$processisrunning = false;
363
364
			if (($action == gettext("Stop") or $action == "") and $processisrunning != true)
365 e19669c5 Colin Fleming
				echo "<input type=\"submit\" name=\"startbtn\" value=\"" . gettext("Start") . "\" />&nbsp;";
366 89fae3e7 jim-p
			else {
367 e19669c5 Colin Fleming
				echo "<input type=\"submit\" name=\"stopbtn\" value=\"" . gettext("Stop") . "\" />&nbsp;";
368 89fae3e7 jim-p
			}
369
			if (file_exists($fp.$fn) and $processisrunning != true) {
370 e19669c5 Colin Fleming
				echo "<input type=\"submit\" name=\"viewbtn\" value=\"" . gettext("View Capture") . "\" />&nbsp;";
371
				echo "<input type=\"submit\" name=\"downloadbtn\" value=\"" . gettext("Download Capture") . "\" />";
372 8cd558b6 ayvis
				echo "<br />" . gettext("The packet capture file was last updated:") . " " . date("F jS, Y g:i:s a.", filemtime($fp.$fn));
373 89fae3e7 jim-p
			}
374 b39ca83c Scott Ullrich
?>
375 89fae3e7 jim-p
			</td>
376
		</tr>
377 77877238 jim-p
	</table>
378
	</form>
379 e19669c5 Colin Fleming
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="results">
380 89fae3e7 jim-p
		<tr>
381
		<td valign="top" colspan="2">
382 b39ca83c Scott Ullrich
<?php
383 e19669c5 Colin Fleming
		echo "<font face=\"terminal\" size=\"2\">";
384 89fae3e7 jim-p
		if ($processisrunning == true)
385 8cd558b6 ayvis
			echo("<strong>" . gettext("Packet Capture is running.") . "</strong><br />");
386 89fae3e7 jim-p
387
		if ($do_tcpdump) {
388
			$matches = array();
389
390 fd8774c0 jim-p
			if (in_array($fam, $fams))
391 89fae3e7 jim-p
				$matches[] = $fam;
392
393 43d735de jim-p
			if (in_array($proto, $protos)) {
394 715d2895 jim-p
				$matches[] = fixup_not($proto);
395 43d735de jim-p
			}
396 fd8774c0 jim-p
397 89fae3e7 jim-p
			if ($port != "")
398 715d2895 jim-p
				$matches[] = "port ".fixup_not($port);
399 89fae3e7 jim-p
400
			if ($host != "") {
401 017e4ad3 jim-p
				$hostmatch = "";
402
				$hostcount = 0;
403
				foreach ($hosts as $h) {
404
					$h = fixup_host($h, $hostcount++);
405
					if (!empty($h))
406
						$hostmatch .= " " . $h;
407
				}
408
				if (!empty($hostmatch))
409
					$matches[] = "({$hostmatch})";
410 89fae3e7 jim-p
			}
411
412
			if ($count != "0" ) {
413
				$searchcount = "-c " . $count;
414
			} else {
415
				$searchcount = "";
416
			}
417
418
			$selectedif = convert_friendly_interface_to_real_interface_name($selectedif);
419
420
			if ($action == gettext("Start")) {
421
				$matchstr = implode($matches, " and ");
422 8cd558b6 ayvis
				echo("<strong>" . gettext("Packet Capture is running.") . "</strong><br />");
423 017e4ad3 jim-p
				$cmd = "/usr/sbin/tcpdump -i {$selectedif} {$disablepromiscuous} {$searchcount} -s {$snaplen} -w {$fp}{$fn} " . escapeshellarg($matchstr);
424
				// Debug
425
				//echo $cmd;
426
				mwexec_bg ($cmd);
427 89fae3e7 jim-p
			} else {
428
				//action = stop
429 8cd558b6 ayvis
				echo("<strong>" . gettext("Packet Capture stopped.") . "<br /><br />" . gettext("Packets Captured:") . "</strong><br />");
430 b39ca83c Scott Ullrich
?>
431 e19669c5 Colin Fleming
				<script type="text/javascript">
432
				//<![CDATA[
433
				window.onload=function(){
434
					document.getElementById("packetsCaptured").wrap='off';
435
				}
436
				//]]>
437
				</script>
438
				<textarea id="packetsCaptured" style="width:98%" name="code" rows="15" cols="66" readonly="readonly">
439 b39ca83c Scott Ullrich
<?php
440 622caf8f Darren Embry
				$detail_args = "";
441
				switch ($detail) {
442
				case "full":
443
					$detail_args = "-vv -e";
444
					break;
445
				case "high":
446
					$detail_args = "-vv";
447
					break;
448
				case "medium":
449
					$detail_args = "-v";
450
					break;
451
				case "normal":
452
				default:
453
					$detail_args = "-q";
454
					break;
455
				}
456 715d2895 jim-p
				system("/usr/sbin/tcpdump {$disabledns} {$detail_args} -r {$fp}{$fn}");
457 b39ca83c Scott Ullrich
458 89fae3e7 jim-p
				conf_mount_ro();
459 b39ca83c Scott Ullrich
?>
460 89fae3e7 jim-p
				</textarea>
461 b39ca83c Scott Ullrich
<?php
462 89fae3e7 jim-p
			}
463
		}
464 b39ca83c Scott Ullrich
?>
465 e19669c5 Colin Fleming
		&nbsp;</font>
466 89fae3e7 jim-p
		</td>
467
		</tr>
468
	</table>
469
	</td></tr>
470 b39ca83c Scott Ullrich
</table>
471 4e7d1665 Scott Ullrich
472 f35abee2 jim-p
<?php
473
include("fend.inc");
474 4e7d1665 Scott Ullrich
?>
475 e19669c5 Colin Fleming
</body>
476
</html>