From 39bb03fd1085a5cde20668a01fa7a87b2fe2efa2 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sat, 12 Aug 2017 14:42:11 +0200 Subject: [PATCH] use configd to fetch states in diag_dump_states.php, for https://github.com/opnsense/core/pull/1771 --- src/www/diag_dump_states.php | 71 +++++++++++++++++------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/src/www/diag_dump_states.php b/src/www/diag_dump_states.php index ba5736bea..72269e29a 100644 --- a/src/www/diag_dump_states.php +++ b/src/www/diag_dump_states.php @@ -84,7 +84,12 @@ include("head.inc");
+ if (empty($_POST['filter'])) { + $filter = "''"; + } else { + $filter = escapeshellarg(htmlspecialchars($_POST['filter'])); + } + $states_info = json_decode(configd_run("filter list states {$filter} 10000"), true);?> @@ -95,7 +100,7 @@ include("head.inc"); - + @@ -126,59 +131,49 @@ include("head.inc"); = 10000) { - break; - } - - $line_split = preg_split("/\s+/", $line); - - $iface = array_shift($line_split); - $proto = array_shift($line_split); - $state = array_pop($line_split); - $info = htmlspecialchars(implode(" ", $line_split)); - - // We may want to make this optional, with a large state table, this could get to be expensive. - $iface = convert_real_interface_to_friendly_descr($iface); - - /* break up info and extract $srcip and $dstip */ - $ends = preg_split("/\?/", $info); - $parts = explode(":", $ends[0]); - $srcip = trim($parts[0]); - $parts = explode(":", $ends[count($ends) - 1]); - $dstip = trim($parts[0]); + $intfdescr = array(); + foreach (legacy_config_get_interfaces() as $intf) { + $intfdescr[$intf['if']] = $intf['descr']; + } + foreach ($states_info['details'] as $state): // states can be deleted by source / dest combination, all matching records use the same class. - $rowid = str_replace(array('.', ':'), '_', $srcip.$dstip); - ?> + $rowid = str_replace(array('.', ':'), '_', $state['src_addr'].$state['dst_addr']); + // (re)construct info + $direction = ($state['direction'] == 'out' ? '->' : '<-'); + $isipv4 = strpos($state['src_addr'], ':') === false; + $srcport = $isipv4 ? ":{$state['src_port']}" : "[{$state['src_port']}]"; + $dstport = $isipv4 ? ":{$state['dst_port']}" : "[{$state['dst_port']}]"; + $info = $state['src_addr'] . $srcport . " " . $direction . " "; + if (!empty($state['nat_addr'])) { + $natport = $isipv4 ? ":{$state['nat_port']}" : "[{$state['nat_port']}]"; + $info .=$state['nat_addr'] . $natport; + } + $info .= $state['dst_addr'] . $dstport; +?> - - + + - + + endforeach; + if ($states_info['total'] == 0): ?> + endif;?> - +
"/>
- +
: :