From f35abee2f7cc85a255cd4fef137e3cd4e548ea1f Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 27 Apr 2011 12:03:09 -0400 Subject: Whitespace cleanup, code cleanup, add choice to filter on ipv4/ipv6 and also accept a subnet to filter on via the host field. --- usr/local/www/diag_packet_capture.php | 169 ++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 78 deletions(-) (limited to 'usr/local/www') diff --git a/usr/local/www/diag_packet_capture.php b/usr/local/www/diag_packet_capture.php index 684011c..d95e52b 100644 --- a/usr/local/www/diag_packet_capture.php +++ b/usr/local/www/diag_packet_capture.php @@ -23,7 +23,7 @@ POSSIBILITY OF SUCH DAMAGE. */ -/* +/* pfSense_BUILDER_BINARIES: /bin/ps /usr/bin/grep /usr/sbin/tcpdump pfSense_MODULE: routing */ @@ -52,7 +52,8 @@ if ($_POST) { $packetlength = $_POST['snaplen']; $port = $_POST['port']; $detail = $_POST['detail']; - + $fam = $_POST['fam']; + conf_mount_rw(); if ($_POST['dnsquery']) { @@ -65,10 +66,10 @@ if ($_POST) { if ($_POST['startbtn'] != "" ) { $action = gettext("Start"); - - //delete previous packet capture if it exists - if (file_exists($fp.$fn)) - unlink ($fp.$fn); + + //delete previous packet capture if it exists + if (file_exists($fp.$fn)) + unlink ($fp.$fn); } elseif ($_POST['stopbtn']!= "") { $action = gettext("Stop"); @@ -88,7 +89,7 @@ if ($_POST) { //download file $fs = filesize($fp.$fn); header("Content-Type: application/octet-stream"); - header("Content-Disposition: attachment; filename=$fn"); + header("Content-Disposition: attachment; filename=$fn"); header("Content-Length: $fs"); readfile($fp.$fn); } @@ -100,22 +101,22 @@ include("head.inc"); ?> - - +
+
- +
- - - - + + + + + + + + - - - + + - - + - - + - - + - - + - - + - - + +
+
+ + +
-
+ +
+
- -
-
+
+ +
+

- + +

- + +
- + +
" . gettext("Enter 0 (zero) for no count limit.");?>
- +
+ >

:
  +    "; - else { - echo " "; - } + else { + echo " "; + } if (file_exists($fp.$fn) and $processisrunning != true) { echo ""; echo "  (" . gettext("The packet capture file was last updated:") . " " . date("F jS, Y g:i:s a.", filemtime($fp.$fn)) . ")"; } ?> -
@@ -219,36 +231,37 @@ include("fbegin.inc"); echo ""; if ($processisrunning == true) echo("" . gettext("Packet Capture is running.") . "
"); - - if ($do_tcpdump) { - - if ($port != "") { - $searchport = "and port ".$port; - if($host <> "") - $searchport = "and port ".$port; - else - $searchport = "port ".$port; - } else { - $searchport = ""; - } - - if ($host != "") { - $searchhost = "host " . $host; + + if ($do_tcpdump) { + $matches = array(); + + if (($fam == "ip6") || ($fam == "ip")) + $matches[] = $fam; + + if ($port != "") + $matches[] = "port ".$port; + + if ($host != "") { + if (is_ipaddr($host)) + $matches[] = "host " . $host; + elseif (is_subnet($host)) + $matches[] = "net " . $host; + } + + if ($count != "0" ) { + $searchcount = "-c " . $count; } else { - $searchhost = ""; - } - if ($count != "0" ) { - $searchcount = "-c " . $count; - } else { - $searchcount = ""; - } + $searchcount = ""; + } $selectedif = convert_friendly_interface_to_real_interface_name($selectedif); - + if ($action == gettext("Start")) { + $matchstr = implode($matches, " and "); echo("" . gettext("Packet Capture is running.") . "
"); - mwexec_bg ("/usr/sbin/tcpdump -i $selectedif $searchcount -s $packetlength -w $fp$fn $searchhost $searchport"); - } else { + mwexec_bg ("/usr/sbin/tcpdump -i $selectedif $searchcount -s $packetlength -w $fp$fn $matchstr"); + echo "/usr/sbin/tcpdump -i $selectedif $searchcount -s $packetlength -w $fp$fn $matchstr"; + } else { //action = stop echo("" . gettext("Packet Capture stopped.") . "

" . gettext("Packets Captured:") . "

"); ?> @@ -273,6 +286,6 @@ include("fbegin.inc");
- -- cgit v1.1