From 1008527985c9ca392d62beca66b7a49be840330c Mon Sep 17 00:00:00 2001 From: luckman212 Date: Tue, 10 Oct 2017 03:17:17 -0400 Subject: [PATCH] Add filtering to pfTop page --- src/usr/local/www/diag_pftop.php | 39 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/usr/local/www/diag_pftop.php b/src/usr/local/www/diag_pftop.php index ea8d685702..6384a24121 100644 --- a/src/usr/local/www/diag_pftop.php +++ b/src/usr/local/www/diag_pftop.php @@ -29,6 +29,7 @@ require_once("guiconfig.inc"); $pgtitle = array(gettext("Diagnostics"), gettext("pfTop")); +$pftop = "/usr/local/sbin/pftop"; $sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'pkt', 'sport', 'src'); $viewtypes = array('default', 'label', 'long', 'queue', 'rules', 'size', 'speed', 'state', 'time'); @@ -52,9 +53,17 @@ if ($_REQUEST['getactivity']) { $viewtype = "default"; $numstate = "100"; } - - $text = `pftop -b {$sorttype} -w 135 -v {$viewtype} {$numstate}`; - echo trim($text); + if ($_REQUEST['filter'] != "") { + $filter = "-f " . escapeshellarg($_REQUEST['filter']); + } else { + $filter = ""; + } + $text = shell_exec("$pftop {$filter} -b {$sorttype} -w 135 -v {$viewtype} {$numstate}"); + if (empty($text)) { + echo "Invalid filter, check syntax"; + } else { + echo trim($text); + } exit; } @@ -76,6 +85,11 @@ if ($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) && $viewtype = "default"; $numstate = "100"; } +if ($_REQUEST['filter'] != "") { + $filter = "-f " . escapeshellarg($_REQUEST['filter']); +} else { + $filter = ""; +} if ($input_errors) { print_input_errors($input_errors); @@ -108,6 +122,23 @@ $section->addInput(new Form_Select( $validViews )); +$section->addInput(new Form_Input( + 'filter', + 'Filter expression', + 'text', + $_REQUEST['filter'], + ['placeholder' => 'e.g. tcp, ip6 or dst net 208.123.73.0/24'] +))->setHelp('click for filter help%1$s' . + '[proto <ip|ip6|ah|carp|esp|icmp|ipv6-icmp|pfsync|tcp|udp>]
' . + '[src|dst|gw] [host|net|port] <host/network/port>
' . + '[in|out]

' . + 'These are the most common selectors. Some expressions can be combined using "and" / "or". ' . + 'See %2$s for more detailed expression syntax.%3$s', + '
', + 'pftop(8)', + '

' +); + $section->addInput(new Form_Select( 'sorttype', 'Sort by', @@ -125,7 +156,7 @@ $section->addInput(new Form_Select( ) )); -$validStates = array(50, 100, 200, 500, 100, 'all'); +$validStates = array(50, 100, 200, 500, 1000, 'all'); $section->addInput(new Form_Select( 'states', 'Maximum # of States',