diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index b748b6065d..317c18bae2 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,16 @@ +2012-10-08 Ramon Novoa + + * include/functions_graph.php, + include/functions_html.php, + include/graphs/fgraph.php, + include/functions_ui.php, + include/functions_netflow.php, + operation/netflow/nf_live_view.php, + operation/netflow/nf_view.php, + godmode/netflow/nf_item_list.php, + godmode/netflow/nf_report_item.php: Small improvements and fixes. + Added support for PDF netflow reports (enterprise only). + 2012-10-07 Sancho Lerena * pandoradb.sql: Deleted index on utimestamp for tevento. This diff --git a/pandora_console/godmode/netflow/nf_item_list.php b/pandora_console/godmode/netflow/nf_item_list.php index 1f200cc165..421c18ab65 100644 --- a/pandora_console/godmode/netflow/nf_item_list.php +++ b/pandora_console/godmode/netflow/nf_item_list.php @@ -35,17 +35,17 @@ if (! check_acl ($config["id_user"], 0, "IW")) { $id = (int)get_parameter('id'); $buttons['report_list']['active'] = false; -$buttons['report_list'] = '' +$buttons['report_list'] = '' . html_print_image ("images/edit.png", true, array ("title" => __('Report list'))) . ''; $buttons['report_items']['active'] = true; -$buttons['report_items']['text'] = '' +$buttons['report_items']['text'] = '' . html_print_image ("images/god6.png", true, array ("title" => __('Report items'))) . ''; $buttons['edit_report']['active'] = false; -$buttons['edit_report']['text'] = '' +$buttons['edit_report']['text'] = '' . html_print_image ("images/config.png", true, array ("title" => __('Edit report'))) . ''; @@ -187,18 +187,18 @@ foreach ($reports_item as $item) { } else if (($item['id_rc'] == $first_item) && ($item['id_rc'] != $last_item)){ $data[0] = ' '; - $data[0] .= '' . html_print_image("images/down.png", true, array("title" => __('Move to down'))) . ''; + $data[0] .= '' . html_print_image("images/down.png", true, array("title" => __('Move to down'))) . ''; } else if (($item['id_rc'] == $last_item) && ($item['id_rc'] != $first_item)){ - $data[0] = '' . html_print_image("images/up.png", true, array("title" => __('Move to up'))) . ''; + $data[0] = '' . html_print_image("images/up.png", true, array("title" => __('Move to up'))) . ''; } else { - $data[0] = '' . html_print_image("images/up.png", true, array("title" => __('Move to up'))) . ''; - $data[0] .= '' . html_print_image("images/down.png", true, array("title" => __('Move to down'))) . ''; + $data[0] = '' . html_print_image("images/up.png", true, array("title" => __('Move to up'))) . ''; + $data[0] .= '' . html_print_image("images/down.png", true, array("title" => __('Move to down'))) . ''; } $name_filter = db_get_value('id_name', 'tnetflow_filter', 'id_sg', $item['id_filter']); - $data[1] = ''.$name_filter.''; + $data[1] = ''.$name_filter.''; $data[2] = $item['max']; @@ -221,7 +221,7 @@ foreach ($reports_item as $item) { } $data[4] = "" . + href='" . $config['homeurl'] . "index.php?sec=netf&sec2=" . $config['homedir'] . "/godmode/netflow/nf_item_list&delete=1&id_rc=".$item['id_rc']."&id=".$id."&offset=0'>" . html_print_image('images/cross.png', true, array('title' => __('Delete'))) . "" . html_print_checkbox_extended ('delete_multiple[]', $item['id_rc'], false, false, '', 'class="check_delete"', true); @@ -229,11 +229,7 @@ foreach ($reports_item as $item) { } if (isset($data)) { - if (! defined ('METACONSOLE')) { - echo '
'; - } else { - echo ''; - } + echo ''; html_print_input_hidden('multiple_delete', 1); html_print_table ($table); echo "
"; diff --git a/pandora_console/godmode/netflow/nf_report_item.php b/pandora_console/godmode/netflow/nf_report_item.php index c273b855e9..f425480478 100644 --- a/pandora_console/godmode/netflow/nf_report_item.php +++ b/pandora_console/godmode/netflow/nf_report_item.php @@ -157,7 +157,7 @@ foreach($groups_user as $key => $groups){ $sql = "SELECT * FROM tnetflow_filter WHERE id_group IN (".implode(',',$groups_id).")"; $table->data[0][0] = ''.__('Filter').''; -$table->data[0][1] = html_print_select_from_sql($sql, 'id_filter', $name_filter, '', '', 0, true); +$table->data[0][1] = html_print_select_from_sql($sql, 'id_filter', $id_filter, '', '', 0, true); $table->data[1][0] = ''.__('Max. values').''; $max_values = array ('2' => '2', @@ -189,4 +189,4 @@ else { } echo '
'; echo '
'; -?> \ No newline at end of file +?> diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index c0868840ba..da91f974e1 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2661,7 +2661,7 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events, * Print an area graph with netflow aggregated */ -function graph_netflow_aggregate_area ($data, $period, $width, $height, $only_image) { +function graph_netflow_aggregate_area ($data, $period, $width, $height, $unit = '', $ttl = 1, $only_image = false) { global $config; global $graphic_type; @@ -2726,7 +2726,7 @@ function graph_netflow_aggregate_area ($data, $period, $width, $height, $only_im return area_graph($flash_chart, $chart, $width, $height, $color, $legend, $long_index, "images/image_problem.opaque.png", "", $unit, $homeurl, $config['homedir'] . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size'], $unit); + $config['fontpath'], $config['font_size'], $unit, 2); } @@ -2734,7 +2734,7 @@ function graph_netflow_aggregate_area ($data, $period, $width, $height, $only_im /** * Print an area graph with netflow total */ -function graph_netflow_total_area ($data, $period, $width, $height, $only_image) { +function graph_netflow_total_area ($data, $period, $width, $height, $unit = '', $ttl = 1, $only_image = false) { global $config; global $graphic_type; @@ -2783,19 +2783,18 @@ function graph_netflow_total_area ($data, $period, $width, $height, $only_image) return area_graph($flash_chart, $chart, $width, $height, array (), array (), array (), ui_get_full_url("images/image_problem.opaque.png"), "", "", $homeurl, $water_mark, - $config['fontpath'], $config['font_size'], ""); + $config['fontpath'], $config['font_size'], $unit, $ttl); } /** * Print a pie graph with netflow aggregated */ -function graph_netflow_aggregate_pie ($data, $aggregate) { +function graph_netflow_aggregate_pie ($data, $aggregate, $ttl = 1, $only_image = false) { global $config; global $graphic_type; if (empty ($data)) { - echo fs_error_image (); - return; + return fs_error_image (); } $i = 0; @@ -2811,10 +2810,15 @@ function graph_netflow_aggregate_pie ($data, $aggregate) { } $i++; } - - return pie3d_graph($config['flash_charts'], $values, 320, 200, + + $flash_chart = $config['flash_charts']; + if ($only_image) { + $flash_chart = false; + } + + return pie3d_graph($flash_chart, $values, 320, 200, __('Other'), '', $config['homedir'] . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); + $config['fontpath'], $config['font_size'], $ttl); } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index ab5781a7ac..54cf5a559e 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -999,7 +999,7 @@ function html_print_table (&$table, $return = false) { $output .= 'tablealign; } else { - $output .= '
tablealign; + $output .= '
tablealign; } $output .= ' cellpadding="'.$table->cellpadding.'" cellspacing="'.$table->cellspacing.'"'; $output .= ' border="'.$table->border.'" class="'.$table->class.'" id="'.$tableid.'">'; diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index 1e77ca97c8..fc795cdeed 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -17,6 +17,8 @@ include_once($config['homedir'] . "/include/functions_users.php"); include_once($config['homedir'] . "/include/functions_io.php"); +require_once($config['homedir'] . '/enterprise/include/pdf_translator.php'); +enterprise_include_once ($config['homedir'] . "/include/functions_io.php"); // Date format for nfdump $nfdump_date_format = 'Y/m/d.H:i:s'; @@ -230,7 +232,7 @@ function netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit){ $x++; } - html_print_table($table); + return html_print_table ($table, true); } /** @@ -299,7 +301,7 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) { $i++; } - html_print_table($table); + return html_print_table($table, true); } /** @@ -331,7 +333,7 @@ function netflow_summary_table ($data) { $table->data[5][1] = format_numeric ($data['avgbpp']); - html_print_table($table); + return html_print_table ($table, true); } /** @@ -668,11 +670,12 @@ function netflow_get_filter_arguments ($filter) { * @param array values Array where netflow data will be placed. * @param string aggregate Aggregate field. * @param string unit Unit to show. + * @param string interval_length Interval length in seconds (num_intervals * interval_length = start_date - end_date). * * @return Timestamp of the last data read. * */ -function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate = '', $unit = '') { +function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate = '', $unit = '', $interval_length = 0) { global $config; // Last timestamp read @@ -685,9 +688,14 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate } // Calculate the number of intervals - $num_intervals = $config['graph_res'] * 50; - $period = $end_date - $start_date; - $interval_length = (int) ($period / $num_intervals); + if ($interval_length > 0) { + $num_intervals = $config['graph_res'] * 50; + $period = $end_date - $start_date; + $interval_length = (int) ($period / $num_intervals); + } else { + $period = $end_date - $start_date; + $num_intervals = (int) ($period / $interval_length); + } // Parse the summary and exit if ($aggregate == '' && $unit == '') { @@ -1002,8 +1010,9 @@ function netflow_get_valid_intervals () { * @param string unique_id A unique number that is used to generate a cache file. * @param string output Output format. Only HTML and XML are supported. * + * @return The netflow report in the appropriate format. */ -function netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggregates, $unique_id, $connection_name = '', $output = 'HTML') { +function netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggregates, $unique_id, $connection_name = '', $output = 'HTML', $only_image = false) { $aggregate = $filter['aggregate']; $unit = $filter['output']; $interval = $end_date - $start_date; @@ -1014,55 +1023,61 @@ function netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggrega $data = netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggregate, $max_aggregates, $unit, $connection_name); if ($aggregate != 'none') { if ($output == 'HTML') { - echo graph_netflow_aggregate_area($data, $interval, 660, 320, 0); + return graph_netflow_aggregate_area ($data, $interval, 660, 320, $unit); + } else if ($output == 'PDF') { + return graph_netflow_aggregate_area ($data, $interval, 660, 320, $unit, 2, true); } else if ($output == 'XML') { - netflow_aggregate_area_xml ($data); + return netflow_aggregate_area_xml ($data); } } else { if ($output == 'HTML') { - echo graph_netflow_total_area($data, $interval, 660, 320, 0); + return graph_netflow_total_area ($data, $interval, 660, 320, $unit); + } else if ($output == 'PDF') { + return graph_netflow_total_area ($data, $interval, 660, 320, $unit, 2, true); } else if ($output == 'XML') { - netflow_total_area_xml ($data); + return netflow_total_area_xml ($data); } } break; case '1': $data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name); if ($output == 'HTML') { - echo graph_netflow_aggregate_pie($data, $aggregate); + return graph_netflow_aggregate_pie ($data, $aggregate); + } else if ($output == 'PDF') { + return graph_netflow_aggregate_pie ($data, $aggregate, 2, true); } else if ($output == 'XML') { - netflow_aggregate_pie_xml ($data); + return netflow_aggregate_pie_xml ($data); } break; case '2': $data = netflow_get_data ($start_date, $end_date, $filter, $unique_id, $aggregate, $max_aggregates, $unit, $connection_name); - if ($output == 'HTML') { - echo netflow_data_table ($data, $start_date, $end_date, $aggregate); + if ($output == 'HTML' || $output == 'PDF') { + return netflow_data_table ($data, $start_date, $end_date, $aggregate); } else if ($output == 'XML') { // Same as netflow_aggregate_area_xml - netflow_aggregate_area_xml ($data); + return netflow_aggregate_area_xml ($data); } break; case '3': $data = netflow_get_stats ($start_date, $end_date, $filter, $aggregate, $max_aggregates, $unit, $connection_name); - if ($output == 'HTML') { - echo netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit); + if ($output == 'HTML' || $output == 'PDF') { + return netflow_stat_table ($data, $start_date, $end_date, $aggregate, $unit); } else if ($output == 'XML') { - netflow_stat_xml ($data); + return netflow_stat_xml ($data); } break; case '4': $data = netflow_get_summary ($start_date, $end_date, $filter, $unique_id, $connection_name); - if ($output == 'HTML') { - netflow_summary_table ($data); + if ($output == 'HTML' || $output == 'PDF') { + return netflow_summary_table ($data); } else if ($output == 'XML') { - netflow_summary_xml ($data); + return netflow_summary_xml ($data); } break; default: - if ($output == 'HTML') { - echo fs_error_image(); + if ($output == 'HTML' || $output == 'PDF') { + return fs_error_image(); } break; } @@ -1128,7 +1143,7 @@ function netflow_xml_report ($id, $start_date, $end_date) { // Build a unique id for the cache $unique_id = $report['id_report'] . '_' . $content['id_rc'] . '_' . ($end_date - $start_date); - netflow_draw_item ($start_date, $end_date, $content['show_graph'], $filter, $content['max'], $unique_id, $report['server_name'], 'XML'); + echo netflow_draw_item ($start_date, $end_date, $content['show_graph'], $filter, $content['max'], $unique_id, $report['server_name'], 'XML'); echo " \n"; } @@ -1176,14 +1191,16 @@ function netflow_aggregate_area_xml ($data) { function netflow_total_area_xml ($data) { // Print flow information - echo "\n"; + $xml = "\n"; foreach ($data as $timestamp => $flow) { - echo "\n"; - echo " " . $timestamp . "\n"; - echo " " . $flow['data'] . "\n"; - echo "\n"; + $xml .= "\n"; + $xml .= " " . $timestamp . "\n"; + $xml .= " " . $flow['data'] . "\n"; + $xml .= "\n"; } - echo "\n"; + $xml .= "\n"; + + return $xml; } /** @@ -1221,12 +1238,14 @@ function netflow_aggregate_pie_xml ($data) { function netflow_stat_xml ($data) { // Print stats - echo "\n"; + $xml .= "\n"; foreach ($data as $flow) { - echo "" . $flow['agg'] . "\n"; - echo "" . $flow['data'] . "\n"; + $xml .= "" . $flow['agg'] . "\n"; + $xml .= "" . $flow['data'] . "\n"; } - echo "\n"; + $xml .= "\n"; + + return $xml; } /** @@ -1238,14 +1257,16 @@ function netflow_stat_xml ($data) { function netflow_summary_xml ($data) { // Print summary - echo "\n"; - echo " " . $data['totalflows'] . "\n"; - echo " " . $data['totalbytes'] . "\n"; - echo " " . $data['totalbytes'] . "\n"; - echo " " . $data['avgbps'] . "\n"; - echo " " . $data['avgpps'] . "\n"; - echo " " . $data['avgpps'] . "\n"; - echo "\n"; + $xml = "\n"; + $xml .= " " . $data['totalflows'] . "\n"; + $xml .= " " . $data['totalbytes'] . "\n"; + $xml .= " " . $data['totalbytes'] . "\n"; + $xml .= " " . $data['avgbps'] . "\n"; + $xml .= " " . $data['avgpps'] . "\n"; + $xml .= " " . $data['avgpps'] . "\n"; + $xml .= "\n"; + + return $xml; } ?> diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 968cd51fd8..f232fc10ee 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -1845,10 +1845,11 @@ function ui_get_url_refresh ($params = false, $relative = true, $add_post = true * * @param mixed $url If provided, it will be added after the index.php, but it is false boolean value, put the homeurl in the url. * @param boolean $no_proxy To avoid the proxy checks, by default it is false. + * @param boolean $metaconsole_root Set the root to the metaconsole dir if the metaconsole is enabled, true by default. * * @return string A full URL in Pandora. */ -function ui_get_full_url ($url = '', $no_proxy = false, $add_name_php_file = false) { +function ui_get_full_url ($url = '', $no_proxy = false, $add_name_php_file = false, $metaconsole_root = true) { global $config; $port = null; // null means 'use the starndard port' @@ -1916,7 +1917,7 @@ function ui_get_full_url ($url = '', $no_proxy = false, $add_name_php_file = fal $url = $config['homeurl_static'] . '/'; } - if (defined('METACONSOLE')) { + if (defined('METACONSOLE') && $metaconsole_root) { $url .= 'enterprise/meta/'; } } @@ -1928,7 +1929,7 @@ function ui_get_full_url ($url = '', $no_proxy = false, $add_name_php_file = fal $fullurl .= $config['homeurl_static'] . '/'; } - if (defined('METACONSOLE')) { + if (defined('METACONSOLE') && $metaconsole_root) { $fullurl .= 'enterprise/meta/'; } } @@ -1943,7 +1944,7 @@ function ui_get_full_url ($url = '', $no_proxy = false, $add_name_php_file = fal else { $fullurl .= $config['homeurl_static'] . '/'; - if (defined('METACONSOLE')) { + if (defined('METACONSOLE') && $metaconsole_root) { $fullurl .= 'enterprise/meta/'; } } diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index b9454c6006..a68b19f0b4 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -268,8 +268,8 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $graph['font_size'] = $font_size; $id_graph = serialize_in_temp($graph, null, $ttl); - - return ""; + + return ""; } } @@ -304,7 +304,7 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, $id_graph = serialize_in_temp($graph, null, $ttl); - return ""; + return ""; } } diff --git a/pandora_console/operation/netflow/nf_live_view.php b/pandora_console/operation/netflow/nf_live_view.php index 96d0ae0faa..ccd5fffc7c 100644 --- a/pandora_console/operation/netflow/nf_live_view.php +++ b/pandora_console/operation/netflow/nf_live_view.php @@ -253,7 +253,7 @@ if ($draw != '') { $unique_id = 'live_view__' . ($end_date - $start_date); // Draw - netflow_draw_item ($start_date, $end_date, $chart_type, $filter, $max_aggregates, $unique_id, $connection_name); + echo netflow_draw_item ($start_date, $end_date, $chart_type, $filter, $max_aggregates, $unique_id, $connection_name); } ?> @@ -439,4 +439,4 @@ if ($draw != '') { } }); }); - \ No newline at end of file + diff --git a/pandora_console/operation/netflow/nf_view.php b/pandora_console/operation/netflow/nf_view.php index 1bf1dd7d38..a882026ecc 100644 --- a/pandora_console/operation/netflow/nf_view.php +++ b/pandora_console/operation/netflow/nf_view.php @@ -82,13 +82,20 @@ if (isset ($_GET["xml"])) { netflow_xml_report ($id, $start_date, $end_date); return; } +// Generate a PDF report +else if (isset ($_GET["pdf"])) { + enterprise_include_once ('include/functions_netflow_pdf.php'); + header ('Content-type: application/pdf', true); + netflow_pdf_report ($id, $start_date, $end_date); + return; +} -$buttons['report_list'] = '' - . html_print_image ("images/edit.png", true, array ("title" => __('Report list'))) - . ''; //Header if (! defined ('METACONSOLE')) { + $buttons['report_list'] = '' + . html_print_image ("images/edit.png", true, array ("title" => __('Report list'))) + . ''; ui_print_page_header (__('Netflow'), "images/networkmap/so_cisco_new.png", false, "", false, $buttons); } else { $nav_bar = array(array('link' => 'index.php?sec=main', 'text' => __('Main')), @@ -123,6 +130,11 @@ echo '" . html_print_image("images/database_lightning.png", true) . ''; } + if (defined ('METACONSOLE')) { + $table->data[2][1] .= '  " . html_print_image("images/pdf.png", true) . ''; + } else if (defined ('PANDORA_ENTERPRISE')) { + $table->data[2][1] .= '  " . html_print_image("images/pdf.png", true) . ''; + } html_print_table ($table); @@ -168,6 +180,6 @@ foreach ($report_contents as $content_report) { $unique_id = $report_id . '_' . $content_id . '_' . ($end_date - $start_date); // Draw - netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggregates, $unique_id, $connection_name); + echo netflow_draw_item ($start_date, $end_date, $type, $filter, $max_aggregates, $unique_id, $connection_name, 'HTML'); } -?> \ No newline at end of file +?>