From f419f0931de1f03a2c7c7adf2c725b3ec12e493e Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Mon, 23 Oct 2023 16:20:32 +0200 Subject: [PATCH] #12288 fixed filters in netflow explorer --- pandora_console/extras/mr/66.sql | 3 + .../operation/network/network_report.php | 96 +++++++++++++++++++ pandora_console/pandoradb.sql | 2 +- 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/pandora_console/extras/mr/66.sql b/pandora_console/extras/mr/66.sql index 60423984e0..83554679b7 100644 --- a/pandora_console/extras/mr/66.sql +++ b/pandora_console/extras/mr/66.sql @@ -362,4 +362,7 @@ WHERE NOT EXISTS (SELECT name, description FROM tmodule_inventory WHERE name = @ UPDATE `tevent_alert` ea INNER JOIN `tevent_rule` er ON ea.id = er.id_event_alert SET disabled=1 WHERE er.log_agent IS NOT NULL OR er.log_content IS NOT NULL OR er.log_source IS NOT NULL; +ALTER TABLE `tnetwork_explorer_filter` +MODIFY COLUMN `id` INT NOT NULL AUTO_INCREMENT; + COMMIT; diff --git a/pandora_console/operation/network/network_report.php b/pandora_console/operation/network/network_report.php index 4f5b91da5f..cbcf1328cc 100644 --- a/pandora_console/operation/network/network_report.php +++ b/pandora_console/operation/network/network_report.php @@ -135,11 +135,53 @@ if ($advanced_filter !== '') { $filter['advanced_filter'] = $advanced_filter; } +$filter_name = get_parameter('filter_name'); + $order_by = get_parameter('order_by', 'bytes'); if (!in_array($order_by, ['bytes', 'pkts', 'flows'])) { $order_by = 'bytes'; } + +$save = get_parameter('save_button', ''); +$update = get_parameter('update_button', ''); + +// Save user defined filter. +if ($save != '' && check_acl($config['id_user'], 0, 'AW')) { + // Save filter args. + $data['filter_name'] = $filter_name; + $data['top'] = $top; + $data['action'] = $action; + $data['advanced_filter'] = $advanced_filter; + + + $filter_id = db_process_sql_insert('tnetwork_explorer_filter', $data); + 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. + $data['top'] = $top; + $data['action'] = $action; + $data['advanced_filter'] = $advanced_filter; + + $result = db_process_sql_update( + 'tnetwork_explorer_filter', + $data, + ['id' => $filter_id] + ); + ui_print_result_message( + $result, + __('Filter updated successfully'), + __('Error updating filter') + ); +} + + // Build the table. $filterTable = new stdClass(); $filterTable->id = ''; @@ -176,6 +218,59 @@ $filterTable->data[0][1] = html_print_label_input_block( html_print_select_date_range('date', true) ); +$filterTable->data[1][0] = html_print_label_input_block( + __('Data to show'), + html_print_select( + network_get_report_actions(), + 'action', + $action, + '', + '', + 0, + true + ) +); + +$advanced_toggle = new stdClass(); +$advanced_toggle->class = 'filter-table-adv'; +$advanced_toggle->size = []; +$advanced_toggle->size[0] = '50%'; +$advanced_toggle->size[1] = '50%'; +$advanced_toggle->width = '100%'; +$user_groups = users_get_groups($config['id_user'], 'AR', $own_info['is_admin'], true); +$user_groups[0] = 0; +// Add all groups. +$sql = 'SELECT * FROM tnetwork_explorer_filter'; +$advanced_toggle->data[0][0] = html_print_label_input_block( + __('Load Filter'), + html_print_select_from_sql($sql, 'filter_id', $filter_id, '', __('Select a filter'), 0, true, false, true, false, 'width:100%;') +); +$advanced_toggle->data[0][1] = html_print_label_input_block( + __('Filter name'), + html_print_input_text('filter_name', $filter_name, false, 40, 45, true, false, false, '', 'w100p') +); +$advanced_toggle->colspan[1][0] = 2; +$advanced_toggle->data[1][0] = html_print_label_input_block( + __('Filter').ui_print_help_icon('pcap_filter', true), + html_print_textarea('advanced_filter', 4, 10, $advanced_filter, 'style="width:100%"', true) +); +$filterTable->colspan[2][0] = 3; +$filterTable->data[2][0] = html_print_label_input_block( + '', + ui_toggle( + html_print_table($advanced_toggle, true), + __('Advanced'), + '', + '', + true, + true, + '', + 'white-box-content', + 'box-flat white_table_graph' + ) +); + + $filterInputTable = '
'; $filterInputTable .= html_print_input_hidden('order_by', $order_by); $filterInputTable .= html_print_table($filterTable, true); @@ -493,6 +588,7 @@ $(document).ready(function(){ $('#action').val(data.action).trigger('change'); $('#top').val(data.top).trigger('change'); $('#textarea_advanced_filter').val(data.advanced_filter); + $('#text-filter_name').val(data.filter_name); $('select#filter_id').select2('close'); }, 'json'); }); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 141ab4344d..f23b44318e 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4472,7 +4472,7 @@ CREATE TABLE IF NOT EXISTS `tdiscovery_apps_tasks_macros` ( -- Table `tnetwork_explorer_filter` -- --------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tnetwork_explorer_filter` ( - `id` INT NOT NULL, + `id` INT NOT NULL auto_increment, `filter_name` VARCHAR(45) NULL, `top` VARCHAR(45) NULL, `action` VARCHAR(45) NULL,