From a1f172e713a86c9d074c0bbe80122ed70ee08528 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Tue, 28 Feb 2023 17:06:31 +0100 Subject: [PATCH] several fixes --- pandora_console/include/ajax/agent.php | 195 +++++++++++++++--- pandora_console/include/ajax/module.php | 123 +++++++++-- .../operation/agentes/estado_agente.php | 10 +- .../operation/agentes/status_monitor.php | 6 +- 4 files changed, 289 insertions(+), 45 deletions(-) diff --git a/pandora_console/include/ajax/agent.php b/pandora_console/include/ajax/agent.php index 5ba3f90799..f0884dea7f 100644 --- a/pandora_console/include/ajax/agent.php +++ b/pandora_console/include/ajax/agent.php @@ -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 '
'; @@ -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 '
'; + echo '

'; 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 '
'; + echo '

'; + 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 ($('').html ( ).attr ("value", 0)); + + // Reload filters select. + jQuery.post ("", + { + "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($('').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 ($('').html ( ).attr ("value", 0)); - // Reload filters select + + // Add 'none' option. + $('#filter_id').append ($('').html ( ).attr ("value", 0)); + + // Reload filters select. jQuery.post ("", { "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 ("", + { + "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 ($('').html ( ).attr ("value", 0)); + + // Reload filters select. + jQuery.post ("", + { + "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 ($('').html (s).attr ("value", i)); + } + else { + $('#filter_id').append ($('').html (s).attr ("value", i)); + } + }); + }, + "json" + ); + + // Close dialog + $('.ui-dialog-titlebar-close').trigger('click'); + + return false; +} $(document).ready(function() { show_save_filter(); diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 3857c5d6b2..ec87996805 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -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 '
'; + echo '

'; 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 '
'; + echo '

'; + 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 ("", + { + "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 ($('').html ( ).attr ("value", 0)); + + // Reload filters select. + jQuery.post ("", + { + "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 ($('').html (s).attr ("value", i)); + } + else { + $('#filter_id').append ($('').html (s).attr ("value", i)); + } + }); + }, + "json" + ); + + // Close dialog + $('.ui-dialog-titlebar-close').trigger('click'); + + return false; + } $(document).ready(function() { show_save_filter(); diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index 5314c36df7..8e49877037 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -319,11 +319,11 @@ $table->data[0][0] .= '