$id]); if (empty($advanced_filter)) { $type = 0; } else { $type = 1; } echo $type; } // Get values of the current netflow filter. if ($get_filter_values) { $id = get_parameter('id'); $filter_values = db_get_row_filter('tnetflow_filter', ['id_sg' => $id]); // Decode HTML entities. $filter_values['advanced_filter'] = io_safe_output($filter_values['advanced_filter']); echo json_encode($filter_values); } return; } // Read filter configuration. $filter_id = (int) get_parameter('filter_id', 0); $filter['id_name'] = get_parameter('name', ''); $filter['id_group'] = (int) get_parameter('assign_group', 0); $filter['aggregate'] = get_parameter('aggregate', ''); $filter['ip_dst'] = get_parameter('ip_dst', ''); $filter['ip_src'] = get_parameter('ip_src', ''); $filter['dst_port'] = get_parameter('dst_port', ''); $filter['src_port'] = get_parameter('src_port', ''); $filter['advanced_filter'] = get_parameter('advanced_filter', ''); $filter['router_ip'] = get_parameter('router_ip'); // Read chart configuration. $chart_type = get_parameter('chart_type', 'netflow_area'); $max_aggregates = (int) get_parameter('max_aggregates', 10); $update_date = (int) get_parameter('update_date', 0); $connection_name = get_parameter('connection_name', ''); $interval_length = get_parameter('interval_length', NETFLOW_RES_MEDD); $address_resolution = (int) get_parameter('address_resolution', ($config['netflow_get_ip_hostname'] ?? '')); $filter_selected = (int) get_parameter('filter_selected', 0); // Read time values. $date = get_parameter_post('date', date(DATE_FORMAT, get_system_time())); $time = get_parameter_post('time', date(TIME_FORMAT, get_system_time())); $end_date = strtotime($date.' '.$time); $is_period = (bool) get_parameter('is_period', false); $period = (int) get_parameter('period', SECONDS_1DAY); $time_lower = get_parameter('time_lower', date(TIME_FORMAT, ($end_date - $period))); $date_lower = get_parameter('date_lower', date(DATE_FORMAT, ($end_date - $period))); $start_date = ($is_period) ? ($end_date - $period) : strtotime($date_lower.' '.$time_lower); if (!$is_period) { $period = ($end_date - $start_date); } else { $time_lower = date(TIME_FORMAT, $start_date); $date_lower = date(DATE_FORMAT, $start_date); } // Read buttons. $draw = get_parameter('draw_button', ''); $save = get_parameter('save_button', ''); $update = get_parameter('update_button', ''); // Header. ui_print_standard_header( __('Netflow live view'), 'images/op_netflow.png', false, '', false, [], [ [ 'link' => '', 'label' => __('Monitoring'), ], [ 'link' => '', 'label' => __('Network'), ], ] ); $is_windows = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); if ($is_windows === true) { ui_print_error_message(__('Not supported in Windows systems')); } else { netflow_print_check_version_error(); } // Save user defined filter. if ($save != '' && check_acl($config['id_user'], 0, 'AW')) { // Save filter args. $filter['filter_args'] = netflow_get_filter_arguments($filter, true); $filter_id = db_process_sql_insert('tnetflow_filter', $filter); if ($filter_id === false) { $filter_id = 0; ui_print_error_message(__('Error creating filter')); } else { ui_print_success_message(__('Filter created successfully')); } } else if ($update != '' && check_acl($config['id_user'], 0, 'AW')) { // Update current filter. // Do not update the filter name and group. $filter_copy = $filter; unset($filter_copy['id_name']); unset($filter_copy['id_group']); // Save filter args. $filter_copy['filter_args'] = netflow_get_filter_arguments($filter_copy, true); $result = db_process_sql_update( 'tnetflow_filter', $filter_copy, ['id_sg' => $filter_id] ); ui_print_result_message( $result, __('Filter updated successfully'), __('Error updating filter') ); } // The filter name will not be needed anymore. $filter['id_name'] = ''; $netflow_disable_custom_lvfilters = false; if (isset($config['netflow_disable_custom_lvfilters'])) { $netflow_disable_custom_lvfilters = $config['netflow_disable_custom_lvfilters']; } // Add nodes list. if (is_metaconsole() === true) { $list_servers = []; $servers = db_get_all_rows_sql( 'SELECT * FROM tmetaconsole_setup' ); if ($servers === false) { $servers = []; } 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(); } $nodeListInput = html_print_label_input_block( __('Connection'), html_print_select( $list_servers, 'connection_name', $connection_name, '', '', 0, true, false, false ) ); } else { $nodeListInput = ''; } $class_not_period = ($is_period === true) ? 'nf_hidden' : 'nf_display'; $class_period = ($is_period === true) ? 'nf_display' : 'nf_hidden'; $max_values = [ '2' => '2', '5' => '5', '10' => '10', '15' => '15', '20' => '20', '25' => '25', '50' => '50', $max_aggregates => $max_aggregates, ]; $aggregate_list = []; $aggregate_list = [ 'srcip' => __('Src Ip Address'), 'dstip' => __('Dst Ip Address'), 'srcport' => __('Src Port'), 'dstport' => __('Dst Port'), ]; $advanced_toggle = ''; $advanced_toggle .= ''; if ($netflow_disable_custom_lvfilters) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { $advanced_toggle .= ''; $advanced_toggle .= ''; } $advanced_toggle .= ''; $user_groups = users_get_groups($config['id_user'], 'AR', $own_info['is_admin'], true); $user_groups[0] = 0; // Add all groups. $sql = 'SELECT * FROM tnetflow_filter WHERE id_group IN ('.implode(',', array_keys($user_groups)).')'; $advanced_toggle .= "'; $advanced_toggle .= ''; $advanced_toggle .= ""; if ($netflow_disable_custom_lvfilters) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { $advanced_toggle .= "'; $advanced_toggle .= ''; } if ($netflow_disable_custom_lvfilters) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { $advanced_toggle .= "'; $advanced_toggle .= ''; } $advanced_toggle .= ''; $advanced_toggle .= ""; if ($netflow_disable_custom_lvfilters) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { $advanced_toggle .= "'; $advanced_toggle .= ''; } if ($netflow_disable_custom_lvfilters) { $advanced_toggle .= ''; $advanced_toggle .= ''; } else { $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 .= ''; $onclick = "if (!confirm('".__('Warning').'. '.__('IP address resolution can take a lot of time')."')) return false;"; $radio_buttons = __('Yes').'  '.html_print_radio_button_extended( 'address_resolution', 1, '', $address_resolution, false, $onclick, '', true ).'   '; $radio_buttons .= __('No').'  '.html_print_radio_button( 'address_resolution', 0, '', $address_resolution, true ); $advanced_toggle .= ''; $advanced_toggle .= ''; $advanced_toggle .= ''; $advanced_toggle .= ''; $advanced_toggle .= ''; $advanced_toggle .= '
'.__('Filter').''.__('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).''.__('Load filter').'".html_print_select_from_sql($sql, 'filter_id', $filter_id, '', __('Select a filter'), 0, true); $advanced_toggle .= html_print_input_hidden('filter_selected', $filter_selected, false); $advanced_toggle .= '
".__('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).'
'.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).'
'.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).'
'.html_print_input_text('src_port', $filter['src_port'], false, 40, 80, true).'
'.__('IP address resolution').''.ui_print_help_tip(__('Resolve the IP addresses to get their hostnames.'), true).''.$radio_buttons.''.__('Source ip').''.html_print_input_text('router_ip', $filter['router_ip'], false, 40, 80, true).'
'; // Read filter type. if (empty($filter['advanced_filter']) === false) { $filter_type = 1; } else { $filter_type = 0; } $filterTable = new stdClass(); $filterTable->id = ''; $filterTable->width = '100%'; $filterTable->class = 'filter-table-adv'; $filterTable->size = []; $filterTable->size[0] = '33%'; $filterTable->size[1] = '33%'; $filterTable->size[2] = '33%'; $filterTable->data = []; if (empty($nodeListInput) === false) { $filterTable->data[-1][] = $nodeListInput; } $filterTable->data[0][0] = html_print_label_input_block( __('Interval'), html_print_extended_select_for_time( 'period', $period, '', '', 0, false, true ), [ 'div_id' => 'period_container' ] ); $filterTable->data[0][0] .= html_print_label_input_block( __('Start date'), html_print_div( [ 'class' => '', 'content' => html_print_input_text( 'date_lower', $date_lower, false, 13, 10, true ).html_print_image( 'images/calendar_view_day.png', true, [ 'alt' => 'calendar', 'class' => 'main_menu_icon invert_filter', ] ).html_print_input_text( 'time_lower', $time_lower, false, 10, 8, true ), ], true ), [ 'div_id' => 'end_date_container' ] ); $filterTable->data[0][1] = html_print_label_input_block( __('End date'), html_print_div( [ 'class' => '', 'content' => html_print_input_text( 'date', $date, false, 13, 10, true ).html_print_image( 'images/calendar_view_day.png', true, ['alt' => 'calendar'] ).html_print_input_text( 'time', $time, false, 10, 8, true ), ], true ) ); $filterTable->data[0][2] = html_print_label_input_block( __('Resolution'), html_print_select( netflow_resolution_select_params(), 'interval_length', $interval_length, '', '', 0, true, false, false ).ui_print_input_placeholder( __('The interval will be divided in chunks the length of the resolution.'), true ) ); $filterTable->data[1][] = html_print_label_input_block( __('Defined period'), html_print_checkbox_switch( 'is_period', 1, ($is_period === true) ? 1 : 0, true, false, 'nf_view_click_period(event)' ) ); $filterTable->data[1][] = html_print_label_input_block( __('Type'), html_print_select( netflow_get_chart_types(), 'chart_type', $chart_type, '', '', 0, true ) ); $filterTable->data[1][] = html_print_label_input_block( __('Aggregated by'), html_print_select( $aggregate_list, 'aggregate', $filter['aggregate'], '', '', 0, true, false, true, '', false ) ); $filterTable->data[2][] = html_print_label_input_block( __('Max values'), html_print_div( [ 'class' => '', 'content' => html_print_select( $max_values, 'max_aggregates', $max_aggregates, '', '', 0, true ).html_print_anchor( [ 'id' => 'max_values', 'href' => '#', 'onClick' => 'edit_max_value()', 'content' => html_print_image( 'images/edit.svg', true, [ 'id' => 'pencil', 'class' => 'main_menu_icon invert_filter', ] ), ], true ), ], true ) ); $filterTable->colspan[3][0] = 3; $filterTable->data[3][0] = html_print_label_input_block( '', ui_toggle( $advanced_toggle, __('Advanced'), '', '', true, true, '', 'white-box-content', 'box-flat white_table_graph' ) ); $buttons = html_print_submit_button( __('Draw'), 'draw_button', false, [ 'icon' => 'cog', 'mode' => 'mini', ], true ); if (!$netflow_disable_custom_lvfilters) { if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { $buttons .= html_print_submit_button(__('Save as new filter'), 'save_button', false, ['icon' => 'load', 'onClick' => 'return defineFilterName();', 'mode' => 'mini secondary'], true); $buttons .= html_print_submit_button(__('Update current filter'), 'update_button', false, ['icon' => 'load', 'mode' => 'mini secondary'], true); } } $filterInputTable = '
'; $filterInputTable .= html_print_table($filterTable, true); $filterInputTable .= html_print_div( [ 'class' => 'action-buttons', 'content' => $buttons, ], true ); $filterInputTable .= '
'; ui_toggle( $filterInputTable, ''.__('Filter').'', __('Filter'), 'search', true, false, '', 'white-box-content no_border', 'box-flat white_table_graph fixed_filter_bar' ); if (empty($draw) === false) { // No filter selected. if ($netflow_disable_custom_lvfilters && $filter_selected == 0) { ui_print_error_message(__('No filter selected')); } else { // Hidden input for handle properly the text colors. html_print_input_hidden( 'selected_style_theme', $config['style'] ); $netflowContainerClass = ($chart_type === 'netflow_data' || $chart_type === 'netflow_summary' || $chart_type === 'netflow_top_N') ? '' : 'white_box'; // Draw the netflow chart. html_print_div( [ 'class' => $netflowContainerClass, 'content' => netflow_draw_item( $start_date, $end_date, $interval_length, $chart_type, $filter, $max_aggregates, $connection_name, 'HTML', $address_resolution ), ] ); } } else { ui_print_info_message(__('No data to show')); } ui_include_time_picker(); ?>