From fb129750d56dcdebe4466a39538f7c6c8ef836ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Mon, 28 Jun 2021 12:03:25 +0200 Subject: [PATCH] Fixed issues with views in Netflow live view --- pandora_console/include/functions_netflow.php | 105 ++++++++++-------- .../include/graphs/functions_flot.php | 3 +- .../operation/netflow/nf_live_view.php | 37 +++--- 3 files changed, 77 insertions(+), 68 deletions(-) diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index cd31986a2a..8007c19077 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -600,7 +600,7 @@ function netflow_get_stats( global $config, $nfdump_date_format; // Requesting remote data. - if (defined('METACONSOLE') && $connection_name != '') { + if (is_metaconsole() === true && empty($connection_name) === false) { $data = metaconsole_call_remote_api($connection_name, 'netflow_get_stats', "$start_date|$end_date|".base64_encode(json_encode($filter))."|$aggregate|$max|$absolute|".(int) $address_resolution); return json_decode($data, true); } @@ -612,7 +612,7 @@ function netflow_get_stats( // Execute nfdump. exec($command, $string); - if (! is_array($string)) { + if (is_array($string) === false) { return []; } @@ -1062,7 +1062,7 @@ function netflow_draw_item( ) { $aggregate = $filter['aggregate']; $interval = ($end_date - $start_date); - if (defined('METACONSOLE')) { + if (is_metaconsole() === true) { $width = 950; } else { $width = 850; @@ -1084,12 +1084,13 @@ function netflow_draw_item( $connection_name, $address_resolution ); - if (empty($data)) { + + if (empty($data) === true) { break; } - if ($output == 'HTML' || $output == 'PDF') { - $html .= graph_netflow_aggregate_area( + if ($output === 'HTML' || $output === 'PDF') { + return graph_netflow_aggregate_area( $data, $interval, $width, @@ -1098,9 +1099,8 @@ function netflow_draw_item( ($output === 'HTML'), $end_date ); - return $html; - } else if ($output == 'XML') { - $xml .= ''.$aggregate."\n"; + } else if ($output === 'XML') { + $xml = ''.$aggregate."\n"; $xml .= ''.$interval_length."\n"; $xml .= netflow_aggregate_area_xml($data); return $xml; @@ -1119,18 +1119,19 @@ function netflow_draw_item( $connection_name, $address_resolution ); - if (empty($data)) { + + if (empty($data) === true) { break; } - if ($output == 'HTML' || $output == 'PDF') { - $html .= "
"; + if ($output === 'HTML' || $output === 'PDF') { + $html = "
"; $html .= netflow_data_table($data, $start_date, $end_date, $aggregate); $html .= '
'; return $html; - } else if ($output == 'XML') { - $xml .= ''.$aggregate."\n"; + } else if ($output === 'XML') { + $xml = ''.$aggregate."\n"; $xml .= ''.$interval_length."\n"; // Same as netflow_aggregate_area_xml. $xml .= netflow_aggregate_area_xml($data); @@ -1159,7 +1160,8 @@ function netflow_draw_item( $connection_name, $address_resolution ); - if (empty($data_pie)) { + + if (empty($data_pie) === true) { break; } @@ -1222,51 +1224,56 @@ function netflow_draw_item( $connection_name, $address_resolution ); - switch ($aggregate) { - case 'srcip': - case 'srcport': - $address_type = 'source_address'; - $port_type = 'source_port'; - $type = __('Sent'); - break; - default: - case 'dstip': - case 'dstport': - $address_type = 'destination_address'; - $port_type = 'destination_port'; - $type = __('Received'); - break; - } + if (empty($data_stats) === false) { + switch ($aggregate) { + case 'srcip': + case 'srcport': + $address_type = 'source_address'; + $port_type = 'source_port'; + $type = __('Sent'); + break; - $data_graph = [ - 'name' => __('Host detailed traffic').': '.$type, - 'children' => [], - ]; - $id = -1; + default: + case 'dstip': + case 'dstport': + $address_type = 'destination_address'; + $port_type = 'destination_port'; + $type = __('Received'); + break; + } - foreach ($data_stats as $sdata) { - $data_graph['children'][] = [ - 'id' => $i++, - 'name' => $sdata['agg'], - 'children' => [ - [ - 'id' => $i++, - 'name' => $sdata['agg'], - 'value' => $sdata['data'], - 'tooltip_content' => network_format_bytes($sdata['data']), - ], - ], + $data_graph = [ + 'name' => __('Host detailed traffic').': '.$type, + 'children' => [], ]; + $id = -1; + + foreach ($data_stats as $sdata) { + $data_graph['children'][] = [ + 'id' => $id++, + 'name' => $sdata['agg'], + 'children' => [ + [ + 'id' => $id++, + 'name' => $sdata['agg'], + 'value' => $sdata['data'], + 'tooltip_content' => network_format_bytes($sdata['data']), + ], + ], + ]; + } + + return graph_netflow_host_traffic($data_graph, 'auto', 400); } - return graph_netflow_host_traffic($data_graph, 'auto', 400); + break; default: // Nothing to do. break; } - if ($output == 'HTML' || $output == 'PDF') { + if ($output === 'HTML' || $output === 'PDF') { return graph_nodata_image(300, 110, 'data'); } } diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index eabaa8c6b9..080c941049 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -763,7 +763,8 @@ function flot_slicesbar_graph( $height = ((int) $height + 15); $style = 'width:'.$width.'%;'; - $style .= 'height:'.$height.'px;'; + // Fixed height size. + $style .= 'height: 100%;'; $return = "
"; $return .= "
"; diff --git a/pandora_console/operation/netflow/nf_live_view.php b/pandora_console/operation/netflow/nf_live_view.php index a27686f8a7..dcc9e4065e 100644 --- a/pandora_console/operation/netflow/nf_live_view.php +++ b/pandora_console/operation/netflow/nf_live_view.php @@ -352,12 +352,12 @@ if (is_metaconsole()) { $filter_type = 0; } - echo ""; + echo ""; echo "".ui_print_error_message('Define a name for the filter and click on Save as new filter again', '', true).''; echo ''; - echo ""; + echo ""; echo ''.__('Name').''; echo "".html_print_input_text( @@ -373,7 +373,7 @@ if (is_metaconsole()) { echo "".html_print_select_groups($config['id_user'], 'AR', $own_info['is_admin'], 'assign_group', $filter['id_group'], '', '', -1, true, false, false).''; echo ''; - $advanced_toggle = ''; + $advanced_toggle = '
'; $advanced_toggle .= ''; if ($netflow_disable_custom_lvfilters) { @@ -381,7 +381,7 @@ if (is_metaconsole()) { $advanced_toggle .= ''; } else { $advanced_toggle .= ''; - $advanced_toggle .= ''; + $advanced_toggle .= ''; } @@ -403,7 +403,7 @@ if (is_metaconsole()) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { - $advanced_toggle .= "'; + $advanced_toggle .= "'; $advanced_toggle .= ''; } @@ -411,7 +411,7 @@ if (is_metaconsole()) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { - $advanced_toggle .= "'; + $advanced_toggle .= "'; $advanced_toggle .= ''; } @@ -422,7 +422,7 @@ if (is_metaconsole()) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { - $advanced_toggle .= "'; + $advanced_toggle .= "'; $advanced_toggle .= ''; } @@ -430,19 +430,19 @@ if (is_metaconsole()) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { - $advanced_toggle .= "'; + $advanced_toggle .= "'; $advanced_toggle .= ''; } $advanced_toggle .= ''; - $advanced_toggle .= ""; + $advanced_toggle .= ""; if ($netflow_disable_custom_lvfilters) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { $advanced_toggle .= ''; - $advanced_toggle .= "'; + $advanced_toggle .= "'; } $advanced_toggle .= ''; @@ -490,14 +490,14 @@ if (is_metaconsole()) { echo ''; echo '
'.__('Filter').''.__('Normal').' '.html_print_radio_button_extended('filter_type', 0, '', $filter_type, false, 'displayNormalFilter();', 'class="mrgn_right_40px"', true).__('Custom').' '.html_print_radio_button_extended('filter_type', 1, '', $filter_type, false, 'displayAdvancedFilter();', 'class="mrgn_right_40px"', true).''.__('Normal').' '.html_print_radio_button_extended('filter_type', 0, '', $filter_type, false, 'displayNormalFilter();', 'style="margin-right: 40px;"', true).__('Custom').' '.html_print_radio_button_extended('filter_type', 1, '', $filter_type, false, 'displayAdvancedFilter();', 'style="margin-right: 40px;"', true).'".__('Dst Ip').ui_print_help_tip(__('Destination IP. A comma separated list of destination ip. If we leave the field blank, will show all ip. Example filter by ip:
25.46.157.214,160.253.135.249'), true).'
".__('Dst Ip').ui_print_help_tip(__('Destination IP. A comma separated list of destination ip. If we leave the field blank, will show all ip. Example filter by ip:
25.46.157.214,160.253.135.249'), true).'
'.html_print_input_text('ip_dst', $filter['ip_dst'], false, 40, 80, true).'".__('Src Ip').ui_print_help_tip(__('Source IP. A comma separated list of source ip. If we leave the field blank, will show all ip. Example filter by ip:
25.46.157.214,160.253.135.249'), true).'
".__('Src Ip').ui_print_help_tip(__('Source IP. A comma separated list of source ip. If we leave the field blank, will show all ip. Example filter by ip:
25.46.157.214,160.253.135.249'), true).'
'.html_print_input_text('ip_src', $filter['ip_src'], false, 40, 80, true).'".__('Dst Port').ui_print_help_tip(__('Destination port. A comma separated list of destination ports. If we leave the field blank, will show all ports. Example filter by ports 80 and 22:
80,22'), true).'
".__('Dst Port').ui_print_help_tip(__('Destination port. A comma separated list of destination ports. If we leave the field blank, will show all ports. Example filter by ports 80 and 22:
80,22'), true).'
'.html_print_input_text('dst_port', $filter['dst_port'], false, 40, 80, true).'".__('Src Port').ui_print_help_tip(__('Source port. A comma separated list of source ports. If we leave the field blank, will show all ports. Example filter by ports 80 and 22:
80,22'), true).'
".__('Src Port').ui_print_help_tip(__('Source port. A comma separated list of source ports. If we leave the field blank, will show all ports. Example filter by ports 80 and 22:
80,22'), true).'
'.html_print_input_text('src_port', $filter['src_port'], false, 40, 80, true).'
'; - echo "
"; + echo "
"; echo html_print_submit_button(__('Draw'), 'draw_button', false, 'class="sub upd"', true); if (!$netflow_disable_custom_lvfilters) { if (check_acl($config['id_user'], 0, 'AW')) { - html_print_submit_button(__('Save as new filter'), 'save_button', false, ' class="sub upd mrgn_lft_5px" onClick="return defineFilterName();"'); - html_print_submit_button(__('Update current filter'), 'update_button', false, 'class="sub upd mrgn_lft_5px"'); + html_print_submit_button(__('Save as new filter'), 'save_button', false, 'style="margin-left: 5px;" class="sub upd" onClick="return defineFilterName();"'); + html_print_submit_button(__('Update current filter'), 'update_button', false, 'style="margin-left: 5px;" class="sub upd"'); } } @@ -670,11 +670,12 @@ if (is_metaconsole()) { // Check right filter type $("#radiobtn0002").attr("checked", "checked"); } - }); - + } // Get filter values from DB // Shows update filter button $("#submit-update_button").show();