From 46bc6e545a17e77202aaf01ec0cd8d5a46567525 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Tue, 25 Aug 2015 08:08:24 -0300 Subject: Move main pfSense content to src/ --- src/usr/local/www/diag_states_summary.php | 206 ++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 src/usr/local/www/diag_states_summary.php (limited to 'src/usr/local/www/diag_states_summary.php') diff --git a/src/usr/local/www/diag_states_summary.php b/src/usr/local/www/diag_states_summary.php new file mode 100644 index 0000000..7aa91d6 --- /dev/null +++ b/src/usr/local/www/diag_states_summary.php @@ -0,0 +1,206 @@ + 0) { + foreach ($states as $line) { + $line_split = preg_split("/\s+/", $line); + $iface = array_shift($line_split); + $proto = array_shift($line_split); + $state = array_pop($line_split); + $info = implode(" ", $line_split); + + /* Handle NAT cases + Replaces an external IP + NAT by the internal IP */ + if (strpos($info, ') ->') !== FALSE) { + /* Outbound NAT */ + $info = preg_replace('/(\S+) \((\S+)\)/U', "$2", $info); + } elseif (strpos($info, ') <-') !== FALSE) { + /* Inbound NAT/Port Forward */ + $info = preg_replace('/(\S+) \((\S+)\)/U', "$1", $info); + } + + /* break up info and extract $srcip and $dstip */ + $ends = preg_split("/\?/", $info); + + if (strpos($info, '->') === FALSE) { + $srcinfo = $ends[count($ends) - 1]; + $dstinfo = $ends[0]; + } else { + $srcinfo = $ends[0]; + $dstinfo = $ends[count($ends) - 1]; + } + + /* Handle IPv6 */ + $parts = explode(":", $srcinfo); + $partcount = count($parts); + if ($partcount <= 2) { + $srcip = trim($parts[0]); + $srcport = trim($parts[1]); + } else { + preg_match("/([0-9a-f:]+)(\[([0-9]+)\])?/i", $srcinfo, $matches); + $srcip = $matches[1]; + $srcport = trim($matches[3]); + } + + $parts = explode(":", $dstinfo); + $partcount = count($parts); + if ($partcount <= 2) { + $dstip = trim($parts[0]); + $dstport = trim($parts[1]); + } else { + preg_match("/([0-9a-f:]+)(\[([0-9]+)\])?/i", $dstinfo, $matches); + $dstip = $matches[1]; + $dstport = trim($matches[3]); + } + + addipinfo($srcipinfo, $srcip, $proto, $srcport, $dstport); + addipinfo($dstipinfo, $dstip, $proto, $srcport, $dstport); + addipinfo($pairipinfo, "{$srcip} -> {$dstip}", $proto, $srcport, $dstport); + + addipinfo($allipinfo, $srcip, $proto, $srcport, $dstport); + addipinfo($allipinfo, $dstip, $proto, $srcport, $dstport); + + } +} + +function sort_by_ip($a, $b) { + return ip2ulong($a) < ip2ulong($b) ? -1 : 1; +} + +function build_port_info($portarr, $proto) { + if (!$portarr) { + return ''; + } + $ports = array(); + asort($portarr); + foreach (array_reverse($portarr, TRUE) as $port => $count) { + $str = ""; + $service = getservbyport($port, strtolower($proto)); + $port = "{$proto}/{$port}"; + if ($service) { + $port = "{$port} ({$service})"; + } + $ports[] = "{$port}: {$count}"; + } + return implode($ports, ', '); +} + +function print_summary_table($label, $iparr, $sort = TRUE) { ?> + +

+ + + + + + + + + + $ipinfo) { ?> + + + + + + + + + $protoinfo) { ?> + + + + + + + + + + + +
# #
    
  
+ +"; +include("fbegin.inc"); + + +print_summary_table(gettext("By Source IP"), $srcipinfo); +print_summary_table(gettext("By Destination IP"), $dstipinfo); +print_summary_table(gettext("Total per IP"), $allipinfo); +print_summary_table(gettext("By IP Pair"), $pairipinfo, FALSE); +?> + + + + -- cgit v1.1