Merge branch 'ent-12288-varios-bugs-en-netflow' into 'develop'

Ent 12288 Varios bugs en netflow

See merge request artica/pandorafms!6580
This commit is contained in:
Matias Didier 2023-10-24 13:23:38 +00:00
commit 79fc169e4e
7 changed files with 214 additions and 14 deletions

View File

@ -365,4 +365,7 @@ ALTER TABLE tagente_modulo ADD COLUMN `last_compact` TIMESTAMP NOT NULL DEFAULT
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;

View File

@ -5409,7 +5409,7 @@ function html_print_link_with_params($text, $params=[], $type='text', $style='',
$formStyle = ' style="'.$formStyle.'"';
}
$html = '<form method="POST"'.$formStyle.'>';
$html = '<form method="POST"'.$formStyle.' class="link-with-params">';
switch ($type) {
case 'image':
$html .= html_print_input_image($text, $text, $text, $style, true);

View File

@ -1292,6 +1292,11 @@ p.center {
margin: 0 5px;
}
.loading-text {
font-size: 19px;
text-align: center;
}
/* Legacy spinner */
#loading {
position: fixed;

View File

@ -87,7 +87,7 @@ if (is_ajax() === true) {
$filter_id = (int) get_parameter('filter_id', 0);
$filter['id_name'] = get_parameter('new_filter_name', '');
$filter['id_group'] = (int) get_parameter('assign_group', 0);
$filter['aggregate'] = get_parameter('aggregate', '');
$filter['aggregate'] = get_parameter('aggregate', 'dstip');
$filter['ip_dst'] = get_parameter('ip_dst', '');
$filter['ip_src'] = get_parameter('ip_src', '');
$filter['dst_port'] = get_parameter('dst_port', '');
@ -169,7 +169,8 @@ if ($custom_date === '1') {
$date_from = strtotime($date_init);
$date_to = strtotime($date_end);
// Read buttons.
$draw = get_parameter('draw_button', '');
// Change default value for not autoload default filter when load view.
$draw = get_parameter('draw_button', 1);
$save = get_parameter('save_button', '');
$update = get_parameter('update_button', '');
@ -663,6 +664,7 @@ if (empty($draw) === false) {
// Draw the netflow chart.
html_print_div(
[
'id' => 'container_netflow',
'class' => $netflowContainerClass,
'content' => netflow_draw_item(
$date_from,
@ -677,6 +679,22 @@ if (empty($draw) === false) {
),
]
);
$spinner = html_print_div(
[
'content' => '<span></span>',
'class' => 'spinner-fixed inherit',
'style' => 'position: initial;',
],
true
);
html_print_div(
[
'id' => 'spinner',
'content' => '<p class="loading-text">'.__('Loading netflow data, please wait...').'</p>'.$spinner,
'class' => 'invisible',
'style' => 'position: initial;',
]
);
}
} else {
ui_print_info_message(__('No data to show'));
@ -934,6 +952,11 @@ ui_include_time_picker();
$('#filter_group_color').css('color', '#000000');
}
});
$("#button-draw_button").on('click', function(){
$("#container_netflow").remove();
$("#spinner").removeClass("invisible");
});
});
$("#text-time, #text-time_lower").timepicker({

View File

@ -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 = '<form method="POST">';
$filterInputTable .= html_print_input_hidden('order_by', $order_by);
$filterInputTable .= html_print_table($filterTable, true);
@ -262,12 +357,16 @@ $data = netflow_get_top_summary(
// Get the params to return the builder.
$hidden_main_link = [
'time_greater' => $time_greater,
'date_greater' => $date_greater,
'time_lower' => $time_lower,
'date_lower' => $date_lower,
'top' => $top,
'action' => $action,
'custom_date' => get_parameter('custom_date', '0'),
'date' => get_parameter('date', SECONDS_1DAY),
'date_init' => get_parameter('date_init'),
'time_init' => get_parameter('time_init'),
'date_end' => get_parameter('date_end'),
'time_end' => get_parameter('time_end'),
'date_text' => get_parameter('date_text'),
'date_units' => get_parameter('date_units'),
'top' => $top,
'action' => $action,
];
unset($table);
@ -449,6 +548,7 @@ if (empty($data)) {
// Print results.
html_print_div(
[
'id' => 'content-netflow',
'style' => 'max-width: -webkit-fill-available; display: flex',
'class' => '',
'content' => $resultsTable.$pieGraph,
@ -456,11 +556,25 @@ if (empty($data)) {
);
}
$spinner = html_print_div(
[
'content' => '<span></span>',
'class' => 'spinner-fixed inherit',
'style' => 'position: initial;',
],
true
);
html_print_div(
[
'id' => 'spinner',
'content' => '<p class="loading-text">'.__('Loading netflow data, please wait...').'</p>'.$spinner,
'class' => 'invisible',
'style' => 'position: initial;',
]
);
?>
<script>
$(document).ready(function(){
nf_view_click_period();
$('#filter_id').change(function(){
jQuery.post (
"ajax.php",
@ -473,9 +587,42 @@ $(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');
});
$('#button-update').on('click', function(){
if ($('.info_box_information').length > 0) {
$('.info_box_information').remove();
}
if ($('#content-netflow').length > 0) {
$('#content-netflow').remove();
}
if ($('#spinner').length > 0) {
$('#spinner').removeClass("invisible");
}
if ($('.link-with-params').length > 0) {
$('.link-with-params').remove();
}
});
$('.link-with-params').on('submit', function(e){
setTimeout(() => {
if ($('.info_box_information').length > 0) {
$('.info_box_information').remove();
}
if ($('#content-netflow').length > 0) {
$('#content-netflow').remove();
}
if ($('#spinner').length > 0) {
$('#spinner').removeClass("invisible");
}
if ($('.link-with-params').length > 0) {
$('.link-with-params').remove();
}
}, 100); // Prevent fields from being deleted before being sent.
})
});
// Configure jQuery timepickers.

View File

@ -336,7 +336,7 @@ ui_toggle(
$has_data = false;
if ((bool) get_parameter('update_netflow') === true) {
if ((bool) get_parameter('update_netflow', 1) === true) {
$map_data = netflow_build_map_data(
$date_from,
$date_to,
@ -354,6 +354,23 @@ if ($has_data === true) {
ui_print_info_message(__('No data to show'));
}
$spinner = html_print_div(
[
'content' => '<span></span>',
'class' => 'spinner-fixed inherit',
'style' => 'position: initial;',
],
true
);
html_print_div(
[
'id' => 'spinner',
'content' => '<p class="loading-text">'.__('Loading netflow data, please wait...').'</p>'.$spinner,
'class' => 'invisible',
'style' => 'position: initial;',
]
);
?>
<style>
.networkconsole {
@ -363,7 +380,6 @@ if ($has_data === true) {
<script>
$(document).ready(function(){
nf_view_click_period();
$('#filter_id').change(function(){
jQuery.post (
@ -380,6 +396,12 @@ $(document).ready(function(){
$('select#filter_id').select2('close');
}, 'json');
});
$('#button-update_netflow').on('click', function(){
$('.info_box_information').remove();
$('.networkconsole').remove();
$('#spinner').removeClass("invisible");
});
});
// Configure jQuery timepickers.

View File

@ -4473,7 +4473,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,