From b57f27ccbe56a61ec8984e0de6f022b63b793546 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Thu, 27 Aug 2015 15:44:06 +0000 Subject: [PATCH] (legacy) refactor diag_system_pftop.php --- .../conf/actions.d/actions_filter.conf | 6 + src/www/diag_system_pftop.php | 282 ++++++++---------- 2 files changed, 129 insertions(+), 159 deletions(-) diff --git a/src/opnsense/service/conf/actions.d/actions_filter.conf b/src/opnsense/service/conf/actions.d/actions_filter.conf index e03d545c8..6962f6e1c 100644 --- a/src/opnsense/service/conf/actions.d/actions_filter.conf +++ b/src/opnsense/service/conf/actions.d/actions_filter.conf @@ -21,3 +21,9 @@ command:/usr/local/opnsense/scripts/filter/list_osfp.py parameters: type:script_output message:request osfp + +[diag.top] +command:/usr/local/sbin/pftop +parameters: -w 200 -b -o %s -v %s %s +type:script_output +message:request pftop statistics diff --git a/src/www/diag_system_pftop.php b/src/www/diag_system_pftop.php index 999d5ac01..84be1c190 100644 --- a/src/www/diag_system_pftop.php +++ b/src/www/diag_system_pftop.php @@ -28,178 +28,142 @@ require_once("guiconfig.inc"); -$pgtitle = gettext("Diagnostics: pfTop"); - $sorttypes = array('age', 'bytes', 'dest', 'dport', 'exp', 'none', 'peak', 'pkt', 'rate', 'size', 'sport', 'src'); $viewtypes = array('default', 'label', 'long', 'rules', 'size', 'speed', 'state', 'time'); -$viewall = array('label', 'rules'); -$numstates = array('50', '100', '200', '500', '1000', 'all'); +$numstates = array('50', '100', '200', '500', '1000', '99999999999'); -if($_REQUEST['getactivity']) { - if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) - && $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) - && $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) { - $viewtype = escapeshellarg($_REQUEST['viewtype']); - if (in_array($_REQUEST['viewtype'], $viewall)) { - $sorttype = ""; - $numstate = "-a"; - } else { - $sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']); - $numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states'])); - } - } else { - $sorttype = "bytes"; - $viewtype = "default"; - $numstate = "100"; - } +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // fetch only valid input data (items from above lists) + $viewtype = 'default'; + $numstate = '200'; + $sorttype ='bytes'; + if (isset($_POST['viewtype']) && in_array($_POST['viewtype'], $viewtypes)) { + $viewtype = $_POST['viewtype']; + } + if (isset($_POST['states']) && in_array($_POST['states'], $numstates)) { + $numstate = $_POST['states']; + } + if (isset($_POST['sorttype']) && in_array($_POST['sorttype'], $sorttypes)) { + $sorttype = $_POST['sorttype']; + } - $text = `pftop -b {$sorttype} -v {$viewtype} {$numstate}`; - echo $text; - exit; + // fetch pftop data + echo configd_run("filter diag top {$sorttype} {$viewtype} {$numstate}"); + exit; } +$pgtitle = gettext("Diagnostics: pfTop"); include("head.inc"); - -if($_REQUEST['sorttype'] && in_array($_REQUEST['sorttype'], $sorttypes) - && $_REQUEST['viewtype'] && in_array($_REQUEST['viewtype'], $viewtypes) - && $_REQUEST['states'] && in_array($_REQUEST['states'], $numstates)) { - $viewtype = escapeshellarg($_REQUEST['viewtype']); - if (in_array($_REQUEST['viewtype'], $viewall)) { - $sorttype = ""; - $numstate = "-a"; - } else { - $sorttype = "-o " . escapeshellarg($_REQUEST['sorttype']); - $numstate = ($_REQUEST['states'] == "all" ? "-a" : escapeshellarg($_REQUEST['states'])); - } -} else { - $sorttype = "bytes"; - $viewtype = "default"; - $numstate = "100"; -} - ?> - +$( document ).ready(function() { + /** + * fetch pftop data from backend + */ + function getpftopactivity() { + $.ajax( + '/diag_system_pftop.php', + { + type: 'post', + data: {'getactivity':'yes' + ,'sorttype':$('#sorttype').val() + ,'viewtype':$('#viewtype').val() + ,'states':$('#states').val() + }, + complete: function(transport) { + $('#pftopactivitydiv').html('
' + transport.responseText  + '<\/pre>');
+              setTimeout(getpftopactivity, 2500);
+          }
+        });
+    }
 
+    $("#viewtype").change(function() {
+      var selected = $("#viewtype option:selected").val();
+      switch(selected) {
+        case "rules":
+          $(".show_opt").addClass("hidden");
+          break;
+        default:
+          $(".show_opt").removeClass("hidden");
+      }
+    });
+
+    // toggle initial viewtype select
+    $("#viewtype").change();
+    // start initial fetch
+    getpftopactivity();
+});
+
 
 
-
-
- - - -
- -
- - - - - - - - - - - - - - - -
-
-
- -
- - - - "; - print_info_box($savemsg); - echo "
"; - } - if (isset($input_errors) && count($input_errors) > 0) - print_input_errors($input_errors); - ?> - -
- - -
- - - - +
+
+
+
+ + + + + + + + + + + + + + + +
+ + +
+ +
+
+
+ +
+
+
+
+
+
+
+ +
+
- - - - -