several fixes

This commit is contained in:
alejandro.campos@artica.es 2023-02-28 17:06:31 +01:00
parent 2a9494b48d
commit a1f172e713
4 changed files with 289 additions and 45 deletions

View File

@ -38,6 +38,7 @@ $save_filter_modal = get_parameter('save_filter_modal', 0);
$get_agent_filters = get_parameter('get_agent_filters', 0);
$save_agent_filter = get_parameter('save_agent_filter', 0);
$update_agent_filter = get_parameter('update_agent_filter', 0);
$delete_agent_filter = get_parameter('delete_agent_filter', 0);
if (https_is_running()) {
header('Content-type: application/json');
@ -365,6 +366,7 @@ if ($save_agent_filter) {
$values['policies'] = json_encode(get_parameter('policies'));
$values['search_custom'] = get_parameter('search_custom');
$values['ag_custom_fields'] = get_parameter('ag_custom_fields');
$values['id_group_filter'] = get_parameter('id_group_filter');
$exists = (bool) db_get_value_filter(
'id_filter',
@ -411,8 +413,40 @@ if ($update_agent_filter) {
}
}
if ($delete_agent_filter) {
$id = get_parameter('id');
$user_groups = users_get_groups(
$config['id_user'],
'AW',
users_can_manage_group_all('AW'),
true
);
$sql = 'DELETE
FROM tagent_filter
WHERE id_filter = '.$id.' AND id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$agent_filters = db_process_sql($sql);
if ($agent_filters === false) {
echo 'error';
} else {
echo 'ok';
}
}
if ($get_agent_filters) {
$sql = 'SELECT id_filter, id_name FROM tagent_filter';
$user_groups = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all('AR'),
true
);
$sql = 'SELECT id_filter, id_name
FROM tagent_filter
WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$agent_filters = db_get_all_rows_sql($sql);
@ -431,7 +465,7 @@ if ((int) $load_filter_modal === 1) {
$user_groups = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all(),
users_can_manage_group_all('AR'),
true
);
@ -439,11 +473,11 @@ if ((int) $load_filter_modal === 1) {
FROM tagent_filter
WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$event_filters = db_get_all_rows_sql($sql);
$agent_filters = db_get_all_rows_sql($sql);
$filters = [];
foreach ($event_filters as $event_filter) {
$filters[$event_filter['id_filter']] = $event_filter['id_name'];
foreach ($agent_filters as $agent_filter) {
$filters[$agent_filter['id_filter']] = $agent_filter['id_name'];
}
echo '<div id="load-filter-select" class="load-filter-modal">';
@ -560,7 +594,7 @@ if ($save_filter_modal) {
'',
false,
true
).__('Update filter').'';
).__('Update/delete filter').'';
$table->data[] = $data;
$table->rowclass[] = '';
@ -578,8 +612,8 @@ if ($save_filter_modal) {
$user_groups_array = users_get_groups_for_select(
$config['id_user'],
'EW',
users_can_manage_group_all(),
'AW',
users_can_manage_group_all('AW'),
true
);
@ -607,9 +641,19 @@ if ($save_filter_modal) {
$data = [];
$table->rowid[3] = 'update_filter_row1';
$data[0] = __('Overwrite filter').$jump;
$data[0] = __('Filter').$jump;
$user_groups = users_get_groups(
$config['id_user'],
'AW',
users_can_manage_group_all('AW'),
true
);
$sql = 'SELECT id_filter, id_name
FROM tagent_filter
WHERE id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$sql = 'SELECT id_filter, id_name FROM tagent_filter';
$agent_filters = db_get_all_rows_sql($sql);
$_filters_update = [];
@ -629,21 +673,30 @@ if ($save_filter_modal) {
0,
true
);
$data[1] = html_print_submit_button(
__('Update filter'),
'update_filter',
false,
'class="sub upd" onclick="save_update_filter();"',
true
);
$table->data[] = $data;
$table->rowclass[] = '';
html_print_table($table);
echo '<div>';
echo '<div id="update_delete_row"><br>';
echo html_print_submit_button(
__('Save filter'),
__('Update filter'),
'update_filter',
false,
'class="sub upd" onclick="save_update_filter();"',
true
);
echo html_print_submit_button(
__('Delete filter'),
'delete_filter',
false,
'class="sub delete float-right" onclick="save_delete_filter();"',
true
);
echo '</div>';
echo '<div><br>';
echo html_print_submit_button(
__('Save current filter'),
'save_filter',
false,
'class="sub upd float-right" onclick="save_new_filter();"',
@ -662,6 +715,7 @@ function show_save_filter() {
$('#save_filter_row1').show();
$('#save_filter_row2').show();
$('#update_filter_row1').hide();
$('#update_delete_row').hide();
// Filter save mode selector
$("[name='filter_mode']").click(function() {
if ($(this).val() == 'new') {
@ -669,12 +723,14 @@ function show_save_filter() {
$('#save_filter_row2').show();
$('#submit-save_filter').show();
$('#update_filter_row1').hide();
$('#update_delete_row').hide();
}
else {
$('#save_filter_row1').hide();
$('#save_filter_row2').hide();
$('#update_filter_row1').show();
$('#submit-save_filter').hide();
$('#update_delete_row').show();
}
});
$("#save-filter-select").dialog({
@ -726,7 +782,9 @@ function save_new_filter() {
"policies" : $("#policies").val(),
"search_custom" : $("#text-search_custom").val(),
"ag_custom_fields": JSON.stringify(ag_custom_fields),
"id_group_filter": $("#id_group_filter_dialog").val(),
},
function (data) {
$("#info_box").hide();
if (data == 'error') {
@ -759,6 +817,27 @@ function save_new_filter() {
}).show();
}
// First remove all options of filters select.
$('#filter_id').find('option').remove().end();
// Add 'none' option.
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('None')."'"; ?> ).attr ("value", 0));
// Reload filters select.
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"get_agent_filters" : 1
},
function (data) {
jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val);
$('#filter_id').append($('<option></option>').html (s).attr("value", i));
});
},
"json"
);
// Close dialog.
$("#save-filter-select").dialog('close');
}
@ -793,10 +872,10 @@ function save_update_filter() {
"group_id" : $("#group_id").val(),
"recursion" : $("#checkbox-recursion").is(':checked'),
"status" : $("#status").val(),
"search" : $("#search").val(),
"search" : $("#text-search").val(),
"id_os" : $("#os").val(),
"policies" : $("#policies").val(),
"search_custom" : $("#search_custom").val(),
"search_custom" : $("#text-search_custom").val(),
"ag_custom_fields": JSON.stringify(ag_custom_fields),
},
function (data) {
@ -821,11 +900,13 @@ function save_update_filter() {
}
});
// First remove all options of filters select
// First remove all options of filters select.
$('#filter_id').find('option').remove().end();
// Add 'none' option the first
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('none')."'"; ?> ).attr ("value", 0));
// Reload filters select
// Add 'none' option.
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('None')."'"; ?> ).attr ("value", 0));
// Reload filters select.
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
@ -853,7 +934,69 @@ function save_update_filter() {
$('#filter_loaded_span').html($('#filter_loaded_text').html() + ': ' + name_filter_update);
return false;
}
function save_delete_filter() {
var id_filter_update = $("#overwrite_filter").val();
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"delete_agent_filter" : 1,
"id" : $("#overwrite_filter").val(),
},
function (data) {
$(".info_box").hide();
if (data == 'ok') {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "success_update_filter") {
return true;
}
else
return false;
}).show();
}
else {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "error_create_filter") {
return true;
}
else
return false;
}).show();
}
});
// First remove all options of filters select.
$('#filter_id').find('option').remove().end();
// Add 'none' option.
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('None')."'"; ?> ).attr ("value", 0));
// Reload filters select.
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/agent",
"get_agent_filters" : 1
},
function (data) {
jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val);
if (i == id_filter_update) {
$('#filter_id').append ($('<option selected="selected"></option>').html (s).attr ("value", i));
}
else {
$('#filter_id').append ($('<option></option>').html (s).attr ("value", i));
}
});
},
"json"
);
// Close dialog
$('.ui-dialog-titlebar-close').trigger('click');
return false;
}
$(document).ready(function() {
show_save_filter();

View File

@ -73,6 +73,7 @@ if (check_login()) {
$get_monitor_filters = get_parameter('get_monitor_filters', 0);
$save_monitor_filter = get_parameter('save_monitor_filter', 0);
$update_monitor_filter = get_parameter('update_monitor_filter', 0);
$delete_monitor_filter = get_parameter('delete_monitor_filter', 0);
if ($get_agent_modules_json_by_name === true) {
$agent_name = get_parameter('agent_name');
@ -1740,6 +1741,29 @@ if (check_login()) {
}
}
if ($delete_monitor_filter) {
$id = get_parameter('id');
$user_groups = users_get_groups(
$config['id_user'],
'AW',
users_can_manage_group_all('AW'),
true
);
$sql = 'DELETE
FROM tmonitor_filter
WHERE id_filter = '.$id.' AND id_group_filter IN ('.implode(',', array_keys($user_groups)).')';
$monitor_filters = db_process_sql($sql);
if ($monitor_filters === false) {
echo 'error';
} else {
echo 'ok';
}
}
if ($get_monitor_filters) {
$sql = 'SELECT id_filter, id_name FROM tmonitor_filter';
@ -1760,7 +1784,7 @@ if (check_login()) {
$user_groups = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all(),
users_can_manage_group_all('AR'),
true
);
@ -1886,7 +1910,7 @@ if (check_login()) {
'',
false,
true
).__('Update filter').'';
).__('Update/delete filter').'';
$table->data[] = $data;
$table->rowclass[] = '';
@ -1904,7 +1928,7 @@ if (check_login()) {
$user_groups_array = users_get_groups_for_select(
$config['id_user'],
'AW',
users_can_manage_group_all(),
users_can_manage_group_all('AW'),
true
);
@ -1954,21 +1978,30 @@ if (check_login()) {
0,
true
);
$data[1] = html_print_submit_button(
__('Update filter'),
'update_filter',
false,
'class="sub upd" onclick="save_update_filter();"',
true
);
$table->data[] = $data;
$table->rowclass[] = '';
html_print_table($table);
echo '<div>';
echo '<div id="update_delete_row"><br>';
echo html_print_submit_button(
__('Save filter'),
__('Update filter'),
'update_filter',
false,
'class="sub upd" onclick="save_update_filter();"',
true
);
echo html_print_submit_button(
__('Delete filter'),
'delete_filter',
false,
'class="sub delete float-right" onclick="save_delete_filter();"',
true
);
echo '</div>';
echo '<div><br>';
echo html_print_submit_button(
__('Save current filter'),
'save_filter',
false,
'class="sub upd float-right" onclick="save_new_filter();"',
@ -1986,6 +2019,7 @@ if (check_login()) {
$('#save_filter_row1').show();
$('#save_filter_row2').show();
$('#update_filter_row1').hide();
$('#update_delete_row').hide();
// Filter save mode selector
$("[name='filter_mode']").click(function() {
if ($(this).val() == 'new') {
@ -1993,12 +2027,14 @@ if (check_login()) {
$('#save_filter_row2').show();
$('#submit-save_filter').show();
$('#update_filter_row1').hide();
$('#update_delete_row').hide();
}
else {
$('#save_filter_row1').hide();
$('#save_filter_row2').hide();
$('#update_filter_row1').show();
$('#submit-save_filter').hide();
$('#update_delete_row').show();
}
});
$("#save-filter-select").dialog({
@ -2189,6 +2225,69 @@ if (check_login()) {
$('#filter_loaded_span').html($('#filter_loaded_text').html() + ': ' + name_filter_update);
return false;
}
function save_delete_filter() {
var id_filter_update = $("#overwrite_filter").val();
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/module",
"delete_monitor_filter" : 1,
"id" : $("#overwrite_filter").val(),
},
function (data) {
$(".info_box").hide();
if (data == 'ok') {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "success_update_filter") {
return true;
}
else
return false;
}).show();
}
else {
$(".info_box").filter(function(i, item) {
if ($(item).data('type_info_box') == "error_create_filter") {
return true;
}
else
return false;
}).show();
}
});
// First remove all options of filters select.
$('#filter_id').find('option').remove().end();
// Add 'none' option.
$('#filter_id').append ($('<option></option>').html ( <?php echo "'".__('None')."'"; ?> ).attr ("value", 0));
// Reload filters select.
jQuery.post ("<?php echo ui_get_full_url('ajax.php', false, false, false); ?>",
{
"page" : "include/ajax/module",
"get_monitor_filters" : 1
},
function (data) {
jQuery.each (data, function (i, val) {
s = js_html_entity_decode(val);
if (i == id_filter_update) {
$('#filter_id').append ($('<option selected="selected"></option>').html (s).attr ("value", i));
}
else {
$('#filter_id').append ($('<option></option>').html (s).attr ("value", i));
}
});
},
"json"
);
// Close dialog
$('.ui-dialog-titlebar-close').trigger('click');
return false;
}
$(document).ready(function() {
show_save_filter();

View File

@ -319,11 +319,11 @@ $table->data[0][0] .= '<div class="flex flex-row-vcenter w290px"><div class="w20
$groups = users_get_groups(false, $access);
$table->data[0][0] .= html_print_select_groups(false, $access, true, 'group_id', $group_id, 'this.form.submit()', '', '', true, false, true, '', false);
$table->data[0][0] .= html_print_select_groups(false, $access, true, 'group_id', $group_id, '', '', '', true, false, true, '', false);
//$table->data[0][1] .= '&nbsp;&nbsp;';
$table->data[0][0] .= __('Recursion').'&nbsp;'.'&nbsp;'.'&nbsp;';
$table->data[0][0] .= '<br>'.__('Recursion').'&nbsp;'.'&nbsp;'.'&nbsp;';
$table->data[0][0] .= html_print_input(
[
'type' => 'checkbox',
@ -348,7 +348,7 @@ $fields[AGENT_STATUS_NOT_NORMAL] = __('Not normal');
$fields[AGENT_STATUS_NOT_INIT] = __('Not init');
$table->data[0][1] = __('Status').'&nbsp;'.'&nbsp;'.'&nbsp;';
$table->data[0][1] .= html_print_select($fields, 'status', $status, 'this.form.submit()', __('All'), AGENT_STATUS_ALL, true, false, true, '', false, 'width: 90px;');
$table->data[0][1] .= html_print_select($fields, 'status', $status, '', __('All'), AGENT_STATUS_ALL, true, false, true, '', false, 'width: 90px;');
$table->data[0][2] = __('Search').'&nbsp;'.'&nbsp;'.'&nbsp;';
$table->data[0][2] .= html_print_input_text('search', $search, '', 15, 255, true);
@ -364,7 +364,7 @@ foreach ($pre_fields as $key => $value) {
$fields[$value['id_os']] = $value['name'];
}
$table->data[1][0] .= html_print_select($fields, 'os', $os, 'this.form.submit()', 'All', 0, true);
$table->data[1][0] .= html_print_select($fields, 'os', $os, '', 'All', 0, true);
$table->data[1][1] = __('Policies').'&nbsp;';
@ -446,7 +446,7 @@ $table->data[4][0] = html_print_button(
$table->cellstyle[4][0] .= 'padding-top: 0px;';
$table->data[4][0] .= html_print_button(
__('Save filter'),
__('Manage filter'),
'save-filter',
false,
'',

View File

@ -227,7 +227,7 @@ if ($load_filter_id > 0) {
$user_groups_fl = users_get_groups(
$config['id_user'],
'AR',
users_can_manage_group_all(),
users_can_manage_group_all('AR'),
true
);
@ -287,6 +287,8 @@ if ($loaded_filter['id_filter'] > 0) {
}
}
$all_groups = [];
// Agent group selector.
if (!$is_metaconsole) {
if ($ag_group > 0 && check_acl($config['id_user'], $ag_group, 'AR')) {
@ -937,7 +939,7 @@ $table->data[4][0] = html_print_button(
$table->cellstyle[4][0] .= 'padding-top: 0px;';
$table->data[4][0] .= html_print_button(
__('Save filter'),
__('Manage filter'),
'save-filter',
false,
'',