From 6d6abea43a8bfc21bbc495660704e1ef33d498eb Mon Sep 17 00:00:00 2001 From: jim-p Date: Fri, 5 Feb 2010 20:59:38 -0500 Subject: Use functions instead of repeated code, add a block for total by IP. Bump version. --- config/states-summary/diag_states_summary.php | 133 +++++++------------------- 1 file changed, 37 insertions(+), 96 deletions(-) (limited to 'config/states-summary/diag_states_summary.php') diff --git a/config/states-summary/diag_states_summary.php b/config/states-summary/diag_states_summary.php index adad9b6b..26697bb7 100644 --- a/config/states-summary/diag_states_summary.php +++ b/config/states-summary/diag_states_summary.php @@ -34,8 +34,20 @@ exec("/sbin/pfctl -s state", $states); $srcipinfo = array(); $dstipinfo = array(); +$allipinfo = array(); $pairipinfo = array(); +function addipinfo(&$iparr, $ip, $proto, $srcport, $dstport) { + $iparr[$ip]['seen']++; + $iparr[$ip]['protos'][$proto]['seen']++; + if (!empty($srcport)) { + $iparr[$ip]['protos'][$proto]['srcports'][$srcport]++; + } + if (!empty($dstport)) { + $iparr[$ip]['protos'][$proto]['dstports'][$dstport]++; + } +} + $row = 0; if(count($states) > 0) { foreach($states as $line) { @@ -64,32 +76,13 @@ if(count($states) > 0) { $dstip = trim($parts[0]); $dstport = trim($parts[1]); - $srcipinfo[$srcip]['seen']++; - $srcipinfo[$srcip]['protos'][$proto]['seen']++; - if (!empty($srcport)) { - $srcipinfo[$srcip]['protos'][$proto]['srcports'][$srcport]++; - } - if (!empty($dstport)) { - $srcipinfo[$srcip]['protos'][$proto]['dstports'][$dstport]++; - } + addipinfo($srcipinfo, $srcip, $proto, $srcport, $dstport); + addipinfo($dstipinfo, $dstip, $proto, $srcport, $dstport); + addipinfo($pairipinfo, "{$srcip} -> {$dstip}", $proto, $srcport, $dstport); - $dstipinfo[$dstip]['seen']++; - $dstipinfo[$dstip]['protos'][$proto]['seen']++; - if (!empty($srcport)) { - $dstipinfo[$dstip]['protos'][$proto]['srcports'][$srcport]++; - } - if (!empty($dstport)) { - $dstipinfo[$dstip]['protos'][$proto]['dstports'][$dstport]++; - } + addipinfo($allipinfo, $srcip, $proto, $srcport, $dstport); + addipinfo($allipinfo, $dstip, $proto, $srcport, $dstport); - $pairipinfo["{$srcip} -> {$dstip}"]['seen']++; - $pairipinfo["{$srcip} -> {$dstip}"]['protos'][$proto]['seen']++; - if (!empty($srcport)) { - $pairipinfo["{$srcip} -> {$dstip}"]['protos'][$proto]['srcports'][$srcport]++; - } - if (!empty($dstport)) { - $pairipinfo["{$srcip} -> {$dstip}"]['protos'][$proto]['dstports'][$dstport]++; - } } } @@ -97,14 +90,9 @@ function sort_by_ip($a, $b) { return sprintf("%u", ip2long($a)) < sprintf("%u", ip2long($b)) ? -1 : 1; } -$pgtitle = "Diagnostics: State Table Summary"; -require_once("guiconfig.inc"); -include("head.inc"); -include("fbegin.inc"); -?> -

+function print_summary_table($label, $iparr, $sort = TRUE) { ?> -

By Source IP

+

@@ -114,8 +102,9 @@ include("fbegin.inc"); - $ipinfo) { ?> + $ipinfo) { ?> @@ -138,69 +127,21 @@ include("fbegin.inc");
IPSrc Ports Dst Ports
+By Destination IP - - - - - - - - - - $ipinfo) { ?> - - - - - - - - - $protoinfo) { ?> - - - - - - - - - - -
IP# StatesProto# StatesSrc PortsDst Ports
    
  
+$pgtitle = "Diagnostics: State Table Summary"; +require_once("guiconfig.inc"); +include("head.inc"); +include("fbegin.inc"); +?> +

+ + -

By IP Pair

- - - - - - - - - - $ipinfo) { ?> - - - - - - - - - $protoinfo) { ?> - - - - - - - - - - -
IP# StatesProto# StatesSrc PortsDst Ports
    
  
-- cgit v1.2.3