From 6e8de73ca5b4b7187e26a9a5bb6ad9ebab719cf2 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Fri, 7 Dec 2012 14:03:00 +0000 Subject: [PATCH] 2012-12-07 Ramon Novoa * include/functions_graph.php, include/functions_reporting.php, include/functions_netflow.php, operation/netflow/nf_live_view.php: Aesthetic fixes. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7237 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 7 + pandora_console/include/functions_graph.php | 2 +- pandora_console/include/functions_netflow.php | 150 ++++++++++++++---- .../include/functions_reporting.php | 6 +- .../operation/netflow/nf_live_view.php | 9 +- 5 files changed, 134 insertions(+), 40 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2a42bfce6b..e3c3fc4280 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,10 @@ +2012-12-07 Ramon Novoa + + * include/functions_graph.php, + include/functions_reporting.php, + include/functions_netflow.php, + operation/netflow/nf_live_view.php: Aesthetic fixes. + 2012-12-07 Junichi Satoh * index.php: Fixed undefined function error in case of login diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index af209966ea..8bc3791682 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2794,7 +2794,7 @@ function graph_netflow_total_area ($data, $period, $width, $height, $unit = '', $water_mark = array('file' => $config['homedir'] . "/images/logo_vertical_water.png", 'url' => ui_get_full_url("/images/logo_vertical_water.png")); - return area_graph($flash_chart, $chart, $width, $height, array (), array (), + return area_graph($flash_chart, $chart, $width, $height, array (), false, array (), ui_get_full_url("images/image_problem.opaque.png"), "", "", $homeurl, $water_mark, $config['fontpath'], $config['font_size'], $unit, $ttl); diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index 445d3b8a42..281e6eab00 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -209,8 +209,6 @@ function netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit){ $end_date = date ($nfdump_date_format, $end_date); $values = array(); $table->width = '50%'; - $table->border = 1; - $table->cellpadding = 0; $table->cellspacing = 0; $table->class = 'databox'; $table->data = array(); @@ -218,20 +216,22 @@ function netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit){ $x = 0; $table->head = array (); - $table->head[0] = '' . __($aggregate) . ''; - $table->head[1] = '' . __($unit) . ''; - + $table->head[0] = '' . netflow_format_aggregate ($aggregate) . ''; + $table->head[1] = '' . netflow_format_unit ($unit) . ''; + $table->style[0] = 'border: 1px solid black; padding: 4px'; + $table->style[1] = 'border: 1px solid black; padding: 4px'; + while (isset ($data[$j])) { $agg = $data[$j]['agg']; if (!isset($values[$agg])){ $values[$agg] = $data[$j]['data']; $table->data[$x][0] = $agg; - $table->data[$x][1] = format_numeric ($data[$j]['data']); + $table->data[$x][1] = format_numeric ($data[$j]['data']) . ' ' . netflow_format_unit ($unit); } else { $values[$agg] += $data[$j]['data']; $table->data[$x][0] = $agg; - $table->data[$x][1] = format_numeric ($data[$j]['data']); + $table->data[$x][1] = format_numeric ($data[$j]['data']) . ' ' . netflow_format_unit ($unit); } $j++; $x++; @@ -250,7 +250,7 @@ function netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit){ * * @return The statistics table. */ -function netflow_data_table ($data, $start_date, $end_date, $aggregate) { +function netflow_data_table ($data, $start_date, $end_date, $aggregate, $unit) { global $nfdump_date_format; $period = $end_date - $start_date; @@ -277,25 +277,30 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) { $values = array(); $table->size = array ('50%'); $table->class = 'databox'; - $table->border = 1; - $table->cellpadding = 0; $table->cellspacing = 0; $table->data = array(); $table->head = array(); $table->head[0] = ''.__('Timestamp').''; - + $table->style[0] = 'border: 1px solid black;padding: 4px'; + $j = 0; $source_index = array (); $source_count = 0; - foreach ($data['sources'] as $source => $null) { - $table->align[$j+1] = "right"; - $table->head[$j+1] = $source; - $source_index[$j] = $source; - $source_count++; - $j++; + + if (isset ($data['sources'])) { + foreach ($data['sources'] as $source => $null) { + $table->style[$j+1] = 'border: 1px solid black;padding: 4px'; + $table->align[$j+1] = "right"; + $table->head[$j+1] = $source; + $source_index[$j] = $source; + $source_count++; + $j++; + } + } else { + $table->style[1] = 'border: 1px solid black;padding: 4px'; } - + // No aggregates if ($source_count == 0) { $table->head[1] = __('Data'); @@ -303,7 +308,7 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) { $i = 0; foreach ($data as $timestamp => $value) { $table->data[$i][0] = date ($time_format, $timestamp); - $table->data[$i][1] = format_numeric ($value['data']); + $table->data[$i][1] = format_numeric ($value['data']) . ' ' . netflow_format_unit ($unit); $i++; } } @@ -314,10 +319,10 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) { $table->data[$i][0] = date ($time_format, $timestamp); for ($j = 0; $j < $source_count; $j++) { if (isset ($values[$source_index[$j]])) { - $table->data[$i][$j+1] = format_numeric ($values[$source_index[$j]]); + $table->data[$i][$j+1] = format_numeric ($values[$source_index[$j]]) . ' ' . netflow_format_unit ($unit); } else { - $table->data[$i][$j+1] = 0; + $table->data[$i][$j+1] = 0 . ' ' . netflow_format_unit ($unit); } } $i++; @@ -339,12 +344,12 @@ function netflow_summary_table ($data) { $values = array(); $table->size = array ('50%'); - $table->border = 1; - $table->cellpadding = 0; $table->cellspacing = 0; $table->class = 'databox'; $table->data = array(); + $table->style[0] = 'border: 1px solid black;padding: 4px'; + $table->style[1] = 'border: 1px solid black;padding: 4px'; $table->data[0][0] = ''.__('Total flows').''; $table->data[0][1] = format_numeric ($data['totalflows']); $table->data[1][0] = ''.__('Total megabytes').''; @@ -358,7 +363,6 @@ function netflow_summary_table ($data) { $table->data[5][0] = ''.__('Average bytes per packet').''; $table->data[5][1] = format_numeric ($data['avgbpp']); - return html_print_table ($table, true); } @@ -436,17 +440,22 @@ function netflow_get_data ($start_date, $end_date, $interval_length, $filter, $u } // Load cache - $cache_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.cache'; - $last_timestamp = netflow_load_cache ($values, $cache_file, $start_date, $end_date, $interval_length, $aggregate); + if ($unique_id != '') { + $cache_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.cache'; + $last_timestamp = netflow_load_cache ($values, $cache_file, $start_date, $end_date, $interval_length, $aggregate); + } else { + $last_timestamp = $start_date; + } + if ($last_timestamp < $end_date) { $last_timestamp++; // Execute nfdump and save its output in a temporary file - $temp_file = $config['attachment_store'] . '/netflow_' . $unique_id . '.tmp'; + $temp_file = tempnam($config['attachment_store'], 'netflow_tmp_'); $command .= ' -t '.date($nfdump_date_format, $last_timestamp).'-'.date($nfdump_date_format, $end_date); exec("$command > $temp_file"); - + // Parse data file // We must parse from $start_date to avoid creating new intervals! netflow_parse_file ($start_date, $end_date, $interval_length, $temp_file, $values, $aggregate, $unit); @@ -455,7 +464,7 @@ function netflow_get_data ($start_date, $end_date, $interval_length, $filter, $u } // Save cache - if ($aggregate == 'none') { + if ($unique_id != '') { netflow_save_cache ($values, $cache_file); } @@ -1189,7 +1198,7 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi if ($interval_length != 0) { $html .= " " . _('Resolution') . ": $interval_length " . __('seconds'); } - $html .= netflow_data_table ($data, $start_date, $end_date, $aggregate); + $html .= netflow_data_table ($data, $start_date, $end_date, $aggregate, $unit); return $html; } else if ($output == 'XML') { $xml = "$unit\n"; @@ -1207,13 +1216,15 @@ function netflow_draw_item ($start_date, $end_date, $interval_length, $type, $fi break; } if ($output == 'HTML' || $output == 'PDF') { - return netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit); + $html = netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit); + return $html; } else if ($output == 'XML') { return netflow_stat_xml ($data); } break; case '4': case 'netflow_summary': + $data = netflow_get_summary ($start_date, $end_date, $filter, $unique_id, $connection_name); if (empty ($data)) { break; @@ -1293,7 +1304,7 @@ function netflow_xml_report ($id, $start_date, $end_date, $interval_length = 0) echo " \n"; // Build a unique id for the cache - $unique_id = $report['id_report'] . '_' . $content['id_rc'] . '_' . ($end_date - $start_date); + $unique_id = netflow_generate_unique_id ($content["type"], $filter, $start_date); echo netflow_draw_item ($start_date, $end_date, $interval_length, $content['show_graph'], $filter, $content['max'], $unique_id, $report['server_name'], 'XML'); @@ -1421,4 +1432,79 @@ function netflow_summary_xml ($data) { return $xml; } +/** + * Generate a unique id for the netflow cache. + * + * @param string Chart type. + * @param string Netflow filter. + * @param string Chart start date. + */ +function netflow_generate_unique_id ($type, $filter, $start_date) { + + switch ($type) { + case '0': + case 'netflow_area': + case '2': + case 'netflow_data': + $source = 'data'; + break; + case '1': + case 'netflow_pie': + case '3': + case 'netflow_statistics': + $source = 'stats'; + break; + case '4': + case 'netflow_summary': + $source = 'summary'; + break; + default: + return ''; + } + + return $source . '_' . $filter['id_sg'] . '_' . $start_date; +} + +/** + * Return a string describing the given unit. + * + * @param string Netflow unit. + */ +function netflow_format_unit ($unit) { + switch ($unit){ + case 'megabytes': + return __('MBytes'); + case 'megabytespersecond': + return __('MBytes/s'); + case 'kilobytes': + return __('kBytes'); + case 'kilobytespersecond': + return __('kBytes/s'); + default: + return ''; + } +} + +/** + * Return a string describing the given aggregate. + * + * @param string Netflow aggregate. + */ +function netflow_format_aggregate ($aggregate) { + switch ($aggregate){ + case 'dstport': + return __('Dst port'); + case 'dstip': + return __('Dst IP'); + case 'proto': + return __('Protocol'); + case 'srcip': + return __('Src IP'); + case 'srcport': + return __('Src port'); + default: + return ''; + } +} + ?> diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 319da7c9ff..4fcb244a60 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -4922,9 +4922,9 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $description = $filter['id_name']; } - // Build a unique id for the cache - $unique_id = $report_id . '_' . $content_id . '_' . ($end_date - $start_date); - + // Generate a unique id for the cache + $unique_id = netflow_generate_unique_id ($content["type"], $filter, $start_date); + $table->colspan[0][0] = 4; $table->data[0][0] = '

' . $description . '

'; $table->colspan[1][0] = 4; diff --git a/pandora_console/operation/netflow/nf_live_view.php b/pandora_console/operation/netflow/nf_live_view.php index a5b0c23ee6..022f64424b 100644 --- a/pandora_console/operation/netflow/nf_live_view.php +++ b/pandora_console/operation/netflow/nf_live_view.php @@ -85,7 +85,7 @@ $update_date = (int) get_parameter('update_date', 0); $date = get_parameter_post ('date', date ("Y/m/d", get_system_time ())); $time = get_parameter_post ('time', date ("H:i:s", get_system_time ())); $connection_name = get_parameter('connection_name', ''); -$interval_length = (int) get_parameter('interval_length', 0); +$interval_length = (int) get_parameter('interval_length', 300); // Read buttons $draw = get_parameter('draw_button', ''); @@ -159,7 +159,7 @@ echo '
'; + $table->data[0][4] = ''.__('Resolution') . ui_print_help_tip (__("The interval will be divided in chunks the length of the resolution."), true) . ''; $table->data[0][5] = html_print_select (netflow_get_valid_subintervals (), 'interval_length', $interval_length, '', '', 0, true, false, false); $table->data[0][6] = ''.__('Type').''; $table->data[0][7] = html_print_select (netflow_get_chart_types (), 'chart_type', $chart_type,'','',0,true); @@ -253,10 +253,11 @@ if ($draw != '') { // Get the command to call nfdump $command = netflow_get_command ($filter); - // Build a unique id for the cache - $unique_id = 'live_view__' . ($end_date - $start_date); + // Disable the netflow cache + $unique_id = ''; // Draw + echo "
"; echo netflow_draw_item ($start_date, $end_date, $interval_length, $chart_type, $filter, $max_aggregates, $unique_id, $connection_name); } ?>