From cd13404d3c3208a8b4108b53159a30b91df1c6a1 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 25 Jan 2013 13:37:51 +0000 Subject: [PATCH] 2013-01-25 Miguel de Dios * operation/netflow/nf_live_view.php: fixed and cleaned the filter form. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7529 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 5 + .../operation/netflow/nf_live_view.php | 309 ++++++++++-------- 2 files changed, 180 insertions(+), 134 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 76a724665a..0fba379334 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2013-01-25 Miguel de Dios + + * operation/netflow/nf_live_view.php: fixed and cleaned the filter + form. + 2013-01-25 Junichi Satoh * include/help/ja/help_alert_macros.php: Changed description for diff --git a/pandora_console/operation/netflow/nf_live_view.php b/pandora_console/operation/netflow/nf_live_view.php index ec8f303e3a..514be4fd56 100644 --- a/pandora_console/operation/netflow/nf_live_view.php +++ b/pandora_console/operation/netflow/nf_live_view.php @@ -34,12 +34,12 @@ if (! check_acl ($config["id_user"], 0, "AR")) { $pure = get_parameter('pure', 0); // Ajax callbacks -if (is_ajax()){ +if (is_ajax()) { $get_filter_type = get_parameter('get_filter_type', 0); $get_filter_values = get_parameter('get_filter_values', 0); // Get filter of the current netflow filter - if ($get_filter_type){ + if ($get_filter_type) { $id = get_parameter('id'); $advanced_filter = db_get_value_filter('advanced_filter', 'tnetflow_filter', array('id_sg' => $id)); @@ -53,14 +53,15 @@ if (is_ajax()){ } // Get values of the current netflow filter - if ($get_filter_values){ + if ($get_filter_values) { $id = get_parameter('id'); $filter_values = db_get_row_filter ('tnetflow_filter', array('id_sg' => $id)); - + // Decode HTML entities $filter_values['advanced_filter'] = io_safe_output ($filter_values['advanced_filter']); + echo json_encode($filter_values); } @@ -106,14 +107,14 @@ if (! defined ('METACONSOLE')) { if (! is_executable ($config['netflow_nfdump'])) { ui_print_error_message(__('nfdump binary not found!')); } -} else { +} +else { $nav_bar = array(array('link' => 'index.php?sec=main', 'text' => __('Main')), - array('link' => 'index.php?sec=netf&sec2=operation/netflow/nf_live_view', 'text' => __('Netflow live view'))); - + array('link' => 'index.php?sec=netf&sec2=operation/netflow/nf_live_view', 'text' => __('Netflow live view'))); + ui_meta_print_page_header($nav_bar); ui_meta_print_header(__("Netflow live view")); - } // Save user defined filter @@ -150,121 +151,164 @@ else if ($update != '' && check_acl ($config["id_user"], 0, "AW")) { $filter['id_name'] = ''; echo '
'; - - // Chart options table - $table->width = '100%'; - $table->border = 0; - $table->class = "databox_color"; - $table->style[0] = 'vertical-align: top;'; - $table->data = array (); - $table->data[0][0] = ''.__('Date').''; - $table->data[0][1] = html_print_input_text ('date', $date, false, 12, 10, true); - $table->data[0][1] .= html_print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => "scwShow(scwID('text-date'),this);")); - $table->data[0][1] .= html_print_input_text ('time', $time, false, 10, 5, true); + if (defined ('METACONSOLE')) { + echo ""; + } + else { + echo "
"; + } + echo ""; - $table->data[0][2] = ''.__('Interval').''; - $table->data[0][3] = html_print_select (netflow_get_valid_intervals (), 'period', $period, '', '', 0, true, false, false); - $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); + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; $max_values = array ('2' => '2', '5' => '5', '10' => '10', '15' => '15', '20' => '20', '25' => '25', - '50' => '50' - ); - $table->data[0][8] = ''.__('Max. values').''; - $table->data[0][9] = html_print_select ($max_values, 'max_aggregates', $max_aggregates, '', '', 0, true); - + '50' => '50'); + echo ""; + if (defined ('METACONSOLE')) { - $table->data[0][10] = ''.__('Connection').''; - $table->data[0][11] = html_print_select (metaconsole_get_connection_names (), 'connection_name', $connection_name, '', '', 0, true, false, false); + $list_servers = array(); + + $servers = db_get_all_rows_sql ("SELECT * + FROM tmetaconsole_setup"); + if ($servers === false) + $servers = array(); + foreach ($servers as $server) { + // If connection was good then retrieve all data server + if (metaconsole_load_external_db ($server)) { + $connection = true; + } + else { + $connection = false; + } + + $row = db_get_row('tconfig', 'token', 'activate_netflow'); + + + if ($row['value']) { + $list_servers[$server['server_name']] = $server['server_name']; + } + + metaconsole_restore_db(); + } + + + + echo ""; + echo ""; } - html_print_table ($table); + echo ""; - // Filter options table - $i = 0; - $table->width = '100%'; - $table->border = 0; - $table->class = "databox_color"; - $table->style[0] = 'vertical-align: top;'; - $table->size[0] = '15%'; - $table->data = array (); + // Read filter type + if ($filter['advanced_filter'] != '') { + $filter_type = 1; + } + else { + $filter_type = 0; + } - $table->data[$i][0] = ui_print_error_message ('Define a name for the filter and click on Save as new filter again', '', true); - $table->colspan[$i][0] = 4; - $table->rowstyle[$i] = 'display: none'; - $i++; + echo ""; - $table->data[$i][0] = ''.__('Name').''; - $table->data[$i][1] = html_print_input_text ('name', $filter['id_name'], false, 20, 80, true); + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; $own_info = get_user_info ($config['id_user']); - $table->data[$i][2] = ''.__('Group').''; - $table->data[$i][3] = html_print_select_groups($config['id_user'], "IW", $own_info['is_admin'], 'assign_group', $filter['id_group'], '', '', -1, true, false, false); - $table->rowstyle[$i] = 'display: none'; - $i++; + echo ""; + echo ""; + echo ""; + echo ""; - if ($config['netflow_disable_custom_lvfilters'] == 0) { - // Read filter type - if ($filter['advanced_filter'] != '') { - $filter_type = 1; - } - else { - $filter_type = 0; - } - - $table->data[$i][0] = ''.__('Filter').''; - $table->data[$i][1] = __('Normal') . ' ' . html_print_radio_button_extended ('filter_type', 0, '', $filter_type, false, 'displayNormalFilter();', 'style="margin-right: 40px;"', true); - $table->data[$i][1] .= __('Advanced') . ' ' . html_print_radio_button_extended ('filter_type', 1, '', $filter_type, false, 'displayAdvancedFilter();', 'style="margin-right: 40px;"', true); - $table->data[$i][2] = ''.__('Load filter').''; - $user_groups = users_get_groups ($config['id_user'], "AR", $own_info['is_admin'], true); - $sql = "SELECT * FROM tnetflow_filter WHERE id_group IN (".implode(',', array_keys ($user_groups)).")"; - $table->data[$i][3] = html_print_select_from_sql ($sql, 'filter_id', $filter_id, '', __('none'), 0, true); - $i++; - - $table->data[$i][0] = __('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); - $table->data[$i][1] = html_print_input_text ('ip_dst', $filter['ip_dst'], false, 40, 80, true); - $table->data[$i][2] = __('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); - $table->data[$i][3] = html_print_input_text ('ip_src', $filter['ip_src'], false, 40, 80, true); - $i++; - - $table->data[$i][0] = __('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); - $table->data[$i][1] = html_print_input_text ('dst_port', $filter['dst_port'], false, 40, 80, true); - $table->data[$i][2] = __('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); - $table->data[$i][3] = html_print_input_text ('src_port', $filter['src_port'], false, 40, 80, true); - $i++; - - $table->data[$i][0] = ui_print_help_icon ('pcap_filter', true); - $table->data[$i][1] = html_print_textarea ('advanced_filter', 4, 40, $filter['advanced_filter'], "style='min-height: 0px;'", true); - $table->colspan[$i][1] = 3; - $i++; - } else { - $table->data[$i][0] = ''.__('Load filter').''; - $user_groups = users_get_groups ($config['id_user'], "AR", $own_info['is_admin'], true); - $sql = "SELECT * FROM tnetflow_filter WHERE id_group IN (".implode(',', array_keys ($user_groups)).")"; - $table->data[$i][1] = html_print_select_from_sql ($sql, 'filter_id', $filter_id, '', __('none'), 0, true); - $table->data[$i][2] = ''; - $table->data[$i][3] = ''; - $i++; - } - - $table->data[$i][0] = ''.__('Aggregate by').''. ui_print_help_icon ('aggregate_by', true); + echo ""; + echo ""; + + echo ""; + $user_groups = users_get_groups ($config['id_user'], "AR", $own_info['is_admin'], true); + $sql = "SELECT * FROM tnetflow_filter WHERE id_group IN (".implode(',', array_keys ($user_groups)).")"; + echo ""; + + echo ""; + + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; + echo ""; + + echo ""; $aggregate_list = array(); $aggregate_list = array ('none' => __('None'), 'proto' => __('Protocol'), 'srcip' =>__('Src Ip Address'), 'dstip' =>__('Dst Ip Address'), 'srcport' =>__('Src Port'), 'dstport' =>__('Dst Port') ); - $table->data[$i][1] = html_print_select ($aggregate_list, "aggregate", $filter['aggregate'], '', '', 0, true, false, true, '', false); + echo ""; - $table->data[$i][2] = ''.__('Output format').''; + echo ""; $show_output = array ('bytes' => __('Bytes'), 'bytespersecond' => __('Bytes per second'), 'kilobytes' => __('Kilobytes'), 'megabytes' => __('Megabytes'), 'kilobytespersecond' => __('Kilobytes per second'), 'megabytespersecond' => __('Megabytes per second')); - $table->data[$i][3] = html_print_select ($show_output, 'output', $filter['output'], '', '', 0, true, false, true, '', false); - $i++; - - html_print_table ($table); + echo ""; + + echo ""; + + echo "
" . + ''.__('Date').'' . + "" . + html_print_input_text ('date', $date, false, 10, 10, true) . + html_print_image ("images/calendar_view_day.png", true, + array("alt" => "calendar", + "onclick" => "scwShow(scwID('text-date'),this);")) . + html_print_input_text ('time', $time, false, 10, 5, true) . + "" . ''.__('Interval').'' . "" . html_print_select (netflow_get_valid_intervals (), 'period', $period, '', '', 0, true, false, false) . "" . ''.__('Resolution') . ui_print_help_tip (__("The interval will be divided in chunks the length of the resolution."), true) . '' . "" . html_print_select (netflow_get_valid_subintervals (), 'interval_length', $interval_length, '', '', 0, true, false, false) ."
" . ''.__('Type').'' . "" . html_print_select (netflow_get_chart_types (), 'chart_type', $chart_type,'','',0,true) . "" . ''.__('Max. values').'' . "" . html_print_select ($max_values, 'max_aggregates', $max_aggregates, '', '', 0, true) . "" . ''.__('Connection').'' . "" . html_print_select($list_servers, 'connection_name', $connection_name, '', '', 0, true, false, false) . "
" . ''.__('Filter').'' . "" . + __('Normal') . ' ' . html_print_radio_button_extended ('filter_type', 0, '', $filter_type, false, 'displayNormalFilter();', 'style="margin-right: 40px;"', true) . + __('Advanced') . ' ' . html_print_radio_button_extended ('filter_type', 1, '', $filter_type, false, 'displayAdvancedFilter();', 'style="margin-right: 40px;"', true) . + "" . ''.__('Load filter').'' . "" . html_print_select_from_sql ($sql, 'filter_id', $filter_id, '', __('none'), 0, 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, 30, 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) . "
" . html_print_input_text ('ip_src', $filter['ip_src'], false, 30, 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) . "
" . html_print_input_text ('dst_port', $filter['dst_port'], false, 30, 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) . "
" . html_print_input_text ('src_port', $filter['src_port'], false, 30, 80, true) . "
" . ''.__('Aggregate by').''. ui_print_help_icon ('aggregate_by', true, ui_get_full_url(false, false, false, false)) . "" . html_print_select ($aggregate_list, "aggregate", $filter['aggregate'], '', '', 0, true, false, true, '', false) . "" . ''.__('Output format').'' . "" . html_print_select ($show_output, 'output', $filter['output'], '', '', 0, true, false, true, '', false) . "
"; + + echo "
"; + + if (defined ('METACONSOLE')) { + echo "
"; + } html_print_submit_button (__('Draw'), 'draw_button', false, 'class="sub upd"'); if (check_acl ($config["id_user"], 0, "AW")) { @@ -272,9 +316,13 @@ echo '
"; + } echo'
'; -if ($draw != '') { +if ($draw != '') { // Get the command to call nfdump $command = netflow_get_command ($filter); @@ -288,37 +336,34 @@ if ($draw != '') { // Hide the normal filter and display the advanced filter function displayAdvancedFilter () { // Erase the normal filter - document.getElementById("text-ip_dst").value = ''; - document.getElementById("text-ip_src").value = ''; - document.getElementById("text-dst_port").value = ''; - document.getElementById("text-src_port").value = ''; + $("#text-ip_dst").value = ''; + $("#text-ip_src").value = ''; + $("#text-dst_port").value = ''; + $("#text-src_port").value = ''; // Hide the normal filter - document.getElementById("table2-3").style.display = 'none'; - document.getElementById("table2-4").style.display = 'none'; + $(".filter_normal").css('display', 'none'); // Show the advanced filter - document.getElementById("table2-5").style.display = ''; + $(".filter_advance").css('display', ''); }; // Hide the advanced filter and display the normal filter function displayNormalFilter () { // Erase the advanced filter - document.getElementById("textarea_advanced_filter").value = ''; + $("#textarea_advanced_filter").val(''); // Hide the advanced filter - document.getElementById("table2-5").style.display = 'none'; + $(".filter_advance").css('display', 'none'); // Show the normal filter - document.getElementById("table2-3").style.display = ''; - document.getElementById("table2-4").style.display = ''; + $(".filter_normal").css('display', ''); }; // Ask the user to define a name for the filter in order to save it function defineFilterName () { - if (document.getElementById("text-name").value == '') { - document.getElementById("table2-0").style.display = ''; - document.getElementById("table2-1").style.display = ''; + if ($("#text-name").val() == '') { + $(".filter_save").css('display', ''); return false; } @@ -334,24 +379,22 @@ if ($draw != '') { else { displayAdvancedFilter (); } - + $("#filter_id").change(function () { var filter_type; // Hide information and name/group row - $("#table2-0").css('display', 'none'); - $("#table2-1").css('display', 'none'); + $(".filter_save").css('display', 'none'); + $(".filter_save").css('display', 'none'); // Clean fields if ($("#filter_id").val() == 0) { //displayNormalFilter (); - $("#table2-3").css('display', ''); - $("#table2-4").css('display', ''); - $("#table2-5").css('display', 'none'); + $(".filter_normal").css('display', ''); + $(".filter_advance").css('display', 'none'); // Check right filter type $("#radiobtn0001").attr("checked", "checked"); - $("#radiobtn0002").attr("checked", ""); $("#text-ip_dst").val(''); $("#text-ip_src").val(''); @@ -372,7 +415,8 @@ if ($draw != '') { @@ -384,21 +428,17 @@ if ($draw != '') { filter_type = data; // Display the appropriate filter if (filter_type == 0) { - $("#table2-3").css('display', ''); - $("#table2-4").css('display', ''); - $("#table2-5").css('display', 'none'); + $(".filter_normal").css('display', ''); + $(".filter_advance").css('display', 'none'); // Check right filter type $("#radiobtn0001").attr("checked", "checked"); - $("#radiobtn0002").attr("checked", ""); } else { - $("#table2-3").css('display', 'none'); - $("#table2-4").css('display', 'none'); - $("#table2-5").css('display', ''); + $(".filter_normal").css('display', 'none'); + $(".filter_advance").css('display', ''); // Check right filter type - $("#radiobtn0001").attr("checked", ""); $("#radiobtn0002").attr("checked", "checked"); } }); @@ -410,7 +450,8 @@ if ($draw != '') {