Netflow live view

This commit is contained in:
Jose Gonzalez 2023-03-13 13:25:42 +01:00
parent 590e7a3978
commit 5466cb5995
1 changed files with 396 additions and 275 deletions

View File

@ -101,7 +101,7 @@ $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']);
$address_resolution = (int) get_parameter('address_resolution', ($config['netflow_get_ip_hostname'] ?? ''));
$filter_selected = (int) get_parameter('filter_selected', 0);
// Read time values.
@ -127,13 +127,23 @@ $update = get_parameter('update_button', '');
if (is_metaconsole() === false) {
// Header.
ui_print_page_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';
@ -202,22 +212,9 @@ if (isset($config['netflow_disable_custom_lvfilters'])) {
$netflow_disable_custom_lvfilters = $config['netflow_disable_custom_lvfilters'];
}
$class = 'databox filters';
echo '<form method="post" action="'.$config['homeurl'].'index.php?sec=netf&sec2=operation/netflow/nf_live_view&pure='.$pure.'">';
echo "<table class='".$class."' width='100%'>";
if (is_metaconsole()) {
echo '<thead>
<tr>
<th align=center colspan=6>
'.__('Draw live filter').'
</th>
</tr>
</thead>';
// Add nodes list.
if (is_metaconsole() === true) {
$list_servers = [];
$servers = db_get_all_rows_sql(
'SELECT *
FROM tmetaconsole_setup'
@ -244,9 +241,9 @@ if (is_metaconsole()) {
metaconsole_restore_db();
}
echo '<tr>';
echo '<td><b>'.__('Connection').'</b></td>';
echo '<td>'.html_print_select(
$nodeListInput = html_print_label_input_block(
__('Connection'),
html_print_select(
$list_servers,
'connection_name',
$connection_name,
@ -256,76 +253,15 @@ if (is_metaconsole()) {
true,
false,
false
).'</td>';
echo '</tr>';
)
);
} else {
$nodeListInput = '';
}
echo '<tr>';
$class_not_period = ($is_period === true) ? 'nf_hidden' : 'nf_display';
$class_period = ($is_period === true) ? 'nf_display' : 'nf_hidden';
$class_not_period = ($is_period) ? 'nf_hidden' : 'nf_display';
$class_period = ($is_period) ? 'nf_display' : 'nf_hidden';
echo '<td>';
echo '<b class="'.$class_period.'">'.__('Interval').'</b>';
echo '<b class="'.$class_not_period.'">'.__('Start date').'</b>';
echo '</td>';
echo '<td>';
echo html_print_extended_select_for_time('period', $period, '', '', 0, false, true, false, true, $class_period);
echo html_print_input_text('date_lower', $date_lower, false, 13, 10, true, false, false, '', $class_not_period);
echo html_print_image(
'images/calendar_view_day.png',
true,
[
'alt' => 'calendar',
'class' => $class_not_period,
]
).html_print_input_text('time_lower', $time_lower, false, 10, 8, true, false, false, '', $class_not_period);
echo html_print_checkbox(
'is_period',
1,
($is_period === true) ? 1 : 0,
true,
false,
'nf_view_click_period(event)'
);
echo ui_print_help_tip(__('Select this checkbox to write interval instead a date.'), true);
echo '</td>';
echo '<td><b>'.__('End date').'</b></td>';
echo '<td>'.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);
echo '</td>';
echo '<td><b>'.__('Resolution').ui_print_help_tip(__('The interval will be divided in chunks the length of the resolution.'), true).'</b></td>';
echo '<td>'.html_print_select(
netflow_resolution_select_params(),
'interval_length',
$interval_length,
'',
'',
0,
true,
false,
false
).'</td>';
echo '</tr>';
echo '<tr>';
echo '<td><b>'.__('Type').'</b></td>';
echo '<td>'.html_print_select(
netflow_get_chart_types(),
'chart_type',
$chart_type,
'',
'',
0,
true
).'</td>';
echo '<td><b>'.__('Max. values').'</b></td>';
$max_values = [
'2' => '2',
'5' => '5',
@ -336,10 +272,7 @@ if (is_metaconsole()) {
'50' => '50',
$max_aggregates => $max_aggregates,
];
echo '<td>'.html_print_select($max_values, 'max_aggregates', $max_aggregates, '', '', 0, true).'<a id="max_values" href="#" onclick="javascript: edit_max_value();">'.html_print_image('images/edit.svg', true, ['id' => 'pencil', 'class' => 'main_menu_icon invert_filter']).'</a>';
echo '</td>';
echo '<td><b>'.__('Aggregate by').'</b></td>';
$aggregate_list = [];
$aggregate_list = [
'srcip' => __('Src Ip Address'),
@ -347,40 +280,8 @@ if (is_metaconsole()) {
'srcport' => __('Src Port'),
'dstport' => __('Dst Port'),
];
echo '<td>'.html_print_select($aggregate_list, 'aggregate', $filter['aggregate'], '', '', 0, true, false, true, '', false).'</td>';
echo '</tr>';
// Read filter type.
if ($filter['advanced_filter'] != '') {
$filter_type = 1;
} else {
$filter_type = 0;
}
echo "<tr class='filter_save' style='display: none;'>";
echo "<td colspan='6'>".ui_print_error_message('Define a name for the filter and click on Save as new filter again', '', true).'</td>';
echo '</tr>';
echo "<tr class='filter_save' style='display: none;'>";
echo '<td><span id="filter_name_color"><b>'.__('Name').'</b></span></td>';
echo "<td colspan='2'>".html_print_input_text(
'name',
$filter['id_name'],
false,
20,
80,
true
).'</td>';
$own_info = get_user_info($config['id_user']);
echo '<td><span id="filter_group_color"><b>'.__('Group').'</b></span></td>';
echo "<td colspan='2'>".html_print_select_groups($config['id_user'], 'AR', $own_info['is_admin'], 'assign_group', $filter['id_group'], '', '', -1, true, false, false).'</td>';
echo '</tr>';
$advanced_toggle = '<table style="width:100%">';
$advanced_toggle .= '<tr>';
if ($netflow_disable_custom_lvfilters) {
$advanced_toggle .= '<td></td>';
@ -390,8 +291,6 @@ if (is_metaconsole()) {
$advanced_toggle .= '<td colspan="2">'.__('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).'</td>';
}
$advanced_toggle .= '<td><b>'.__('Load filter').'</b></td>';
$user_groups = users_get_groups($config['id_user'], 'AR', $own_info['is_admin'], true);
$user_groups[0] = 0;
@ -482,34 +381,252 @@ if (is_metaconsole()) {
$advanced_toggle .= '</table>';
echo '<tr><td colspan="6">';
echo ui_toggle(
// Read filter type.
if (empty($filter['advanced_filter']) === false) {
$filter_type = 1;
} else {
$filter_type = 0;
}
$filterTable = new stdClass();
$filterTable->id = '';
$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 white_box_opened',
'no-border flex-row'
'',
'white-box-content',
'box-flat white_table_graph'
)
);
echo '</td></tr>';
echo '</table>';
echo "<table class='' width='100%' style='border: 0px; text-align:right;'><tr><td>";
echo html_print_submit_button(__('Draw'), 'draw_button', false, 'class="sub upd"', true);
$buttons = html_print_submit_button(
__('Draw'),
'draw_button',
false,
[
'icon' => 'cog',
'mode' => 'mini',
],
true
);
if (!$netflow_disable_custom_lvfilters) {
if (check_acl($config['id_user'], 0, 'AW')) {
html_print_submit_button(__('Save as new filter'), 'save_button', false, 'style="margin-left: 5px;" class="sub upd" onClick="return defineFilterName();"');
html_print_submit_button(__('Update current filter'), 'update_button', false, 'style="margin-left: 5px;" class="sub upd"');
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);
}
}
echo '</td></tr></table>';
$filterInputTable = '<form method="post" action="'.$config['homeurl'].'index.php?sec=netf&sec2=operation/netflow/nf_live_view&pure='.$pure.'">';
$filterInputTable .= html_print_table($filterTable, true);
$filterInputTable .= html_print_div(
[
'class' => 'action-buttons',
'content' => $buttons,
],
true
);
$filterInputTable .= '</form>';
echo '</form>';
ui_toggle(
$filterInputTable,
'<span class="subsection_header_title">'.__('Filter').'</span>',
__('Filter'),
'search',
true,
false,
'',
'white-box-content no_border',
'box-flat white_table_graph fixed_filter_bar'
);
if (empty($draw) === false) {
// Draw.
@ -525,7 +642,10 @@ if (is_metaconsole()) {
$config['style']
);
// Draw the netflow chart.
echo netflow_draw_item(
html_print_div(
[
'class' => 'white_box',
'content' => netflow_draw_item(
$start_date,
$end_date,
$interval_length,
@ -535,6 +655,8 @@ if (is_metaconsole()) {
$connection_name,
'HTML',
$address_resolution
),
]
);
}
}
@ -722,6 +844,8 @@ if (is_metaconsole()) {
});
$(document).ready( function() {
// Update visibility of controls.
nf_view_click_period();
// Hide update filter button
if ($("#filter_id").val() == 0) {
$("#submit-update_button").hide();
@ -758,13 +882,10 @@ if (is_metaconsole()) {
$.datepicker.regional["<?php echo get_user_language(); ?>"];
function nf_view_click_period(event) {
$(".nf_display").toggle();
$(".nf_hidden").toggle();
function nf_view_click_period() {
var is_period = document.getElementById('checkbox-is_period').checked;
document.getElementById('period_container').style.display = !is_period ? 'none' : 'flex';
document.getElementById('end_date_container').style.display = is_period ? 'none' : 'flex';
}
</script>
<style type="text/css">
.nf_hidden {
display: none;
}
</style>