diff options
author | jim-p <jim@pingle.org> | 2010-02-05 16:39:35 -0500 |
---|---|---|
committer | jim-p <jim@pingle.org> | 2010-02-05 16:40:31 -0500 |
commit | 63284430301636fb0887faffd41cc09e02ce0144 (patch) | |
tree | 40bf84f77277501111ddffebb82a0689d6a8b6cb /usr/local/www/diag_states_summary.php | |
parent | 691fbf14b966d584a4af9ee2195a0eeb002e1855 (diff) | |
download | pfsense-63284430301636fb0887faffd41cc09e02ce0144.zip pfsense-63284430301636fb0887faffd41cc09e02ce0144.tar.gz |
Simplify with some functions, and add a "total per IP" table.
Diffstat (limited to 'usr/local/www/diag_states_summary.php')
-rw-r--r-- | usr/local/www/diag_states_summary.php | 129 |
1 files changed, 34 insertions, 95 deletions
diff --git a/usr/local/www/diag_states_summary.php b/usr/local/www/diag_states_summary.php index d626d85..fddf0ba 100644 --- a/usr/local/www/diag_states_summary.php +++ b/usr/local/www/diag_states_summary.php @@ -46,8 +46,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) { @@ -76,32 +88,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]++; - } } } @@ -109,12 +102,9 @@ function sort_by_ip($a, $b) { return sprintf("%u", ip2long($a)) < sprintf("%u", ip2long($b)) ? -1 : 1; } -$pgtitle = array("Diagnostics", "State Table Summary"); -require_once("guiconfig.inc"); -include("head.inc"); -include("fbegin.inc"); -?> -<h3>By Source IP</h3> +function print_summary_table($label, $iparr, $sort = TRUE) { ?> + +<h3><?php echo $label; ?></h3> <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="listhdrr">IP</td> @@ -124,8 +114,9 @@ include("fbegin.inc"); <td class="listhdrr">Src Ports</td> <td class="listhdrr">Dst Ports</td> </tr> -<?php uksort($srcipinfo, "sort_by_ip"); - foreach($srcipinfo as $ip => $ipinfo) { ?> +<?php if ($sort) + uksort($iparr, "sort_by_ip"); + foreach($iparr as $ip => $ipinfo) { ?> <tr> <td class='vncell'><?php echo $ip; ?></td> <td class='vncell'><?php echo $ipinfo['seen']; ?></td> @@ -148,71 +139,19 @@ include("fbegin.inc"); </table> +<? +} -<h3>By Destination IP</h3> -<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0"> - <tr> - <td class="listhdrr">IP</td> - <td class="listhdrr"># States</td> - <td class="listhdrr">Proto</td> - <td class="listhdrr"># States</td> - <td class="listhdrr">Src Ports</td> - <td class="listhdrr">Dst Ports</td> - </tr> -<?php uksort($dstipinfo, "sort_by_ip"); - foreach($dstipinfo as $ip => $ipinfo) { ?> - <tr> - <td class='vncell'><?php echo $ip; ?></td> - <td class='vncell'><?php echo $ipinfo['seen']; ?></td> - <td class='vncell'> </td> - <td class='vncell'> </td> - <td class='vncell'> </td> - <td class='vncell'> </td> - </tr> - <?php foreach($ipinfo['protos'] as $proto => $protoinfo) { ?> - <tr> - <td class='list'> </td> - <td class='list'> </td> - <td class='listlr'><?php echo $proto; ?></td> - <td class='listr' align="center"><?php echo $protoinfo['seen']; ?></td> - <td class='listr' align="center"><?php echo count($protoinfo['srcports']); ?></td> - <td class='listr' align="center"><?php echo count($protoinfo['dstports']); ?></td> - </tr> - <?php } ?> -<?php } ?> -</table> +$pgtitle = array("Diagnostics", "State Table Summary"); +require_once("guiconfig.inc"); +include("head.inc"); +include("fbegin.inc"); -<h3>By IP Pair</h3> -<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0"> - <tr> - <td class="listhdrr">IP</td> - <td class="listhdrr"># States</td> - <td class="listhdrr">Proto</td> - <td class="listhdrr"># States</td> - <td class="listhdrr">Src Ports</td> - <td class="listhdrr">Dst Ports</td> - </tr> -<?php foreach($pairipinfo as $ip => $ipinfo) { ?> - <tr> - <td class='vncell'><?php echo $ip; ?></td> - <td class='vncell'><?php echo $ipinfo['seen']; ?></td> - <td class='vncell'> </td> - <td class='vncell'> </td> - <td class='vncell'> </td> - <td class='vncell'> </td> - </tr> - <?php foreach($ipinfo['protos'] as $proto => $protoinfo) { ?> - <tr> - <td class='list'> </td> - <td class='list'> </td> - <td class='listlr'><?php echo $proto; ?></td> - <td class='listr' align="center"><?php echo $protoinfo['seen']; ?></td> - <td class='listr' align="center"><?php echo count($protoinfo['srcports']); ?></td> - <td class='listr' align="center"><?php echo count($protoinfo['dstports']); ?></td> - </tr> - <?php } ?> -<?php } ?> -</table> +print_summary_table("By Source IP", $srcipinfo); +print_summary_table("By Destination IP", $dstipinfo); +print_summary_table("Total per IP", $allipinfo); +print_summary_table("By IP Pair", $pairipinfo, FALSE); +?> <?php include("fend.inc"); ?> |