From 4f9e09b84a4083704c172c0dd3498295ef7995fc Mon Sep 17 00:00:00 2001 From: Pablo Aragon Date: Wed, 3 May 2023 17:01:21 +0200 Subject: [PATCH] 10815-Bulk operations do not edit modules created with policies --- .../godmode/massive/massive_edit_modules.php | 23 ++++++++++++++----- pandora_console/include/javascript/pandora.js | 8 ++++++- .../operation/agentes/ver_agente.php | 12 ++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 2f28c86357..c6e7870840 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -114,8 +114,10 @@ if ($update) { foreach ($agents_ as $id_agent) { $filter = [ - 'id_agente' => $id_agent, - 'delete_pending' => 0, + 'id_agente' => $id_agent, + 'delete_pending' => 0, + 'id_policy_module' => 0, + 'policy_linked' => 0, ]; if ($module_type != 0) { $filter['id_tipo_modulo'] = $module_type; @@ -141,8 +143,10 @@ if ($update) { foreach ($agents_ as $id_agent) { $filter = [ - 'id_agente' => $id_agent, - 'delete_pending' => 0, + 'id_agente' => $id_agent, + 'delete_pending' => 0, + 'id_policy_module' => 0, + 'policy_linked' => 0, ]; $module_name = db_get_all_rows_filter('tagente_modulo', $filter, 'nombre'); if ($module_name === false) { @@ -1262,6 +1266,8 @@ $table->data['edit1'][1] = ''; $preload ); + $table->data['exclude_policy_modules'][0] = html_print_input_hidden('exclude_policy_modules', 1); + echo ''; html_print_table($table); @@ -1399,7 +1405,8 @@ $(document).ready (function () { "truncate_module_names": 1, "get_distinct_name" : 1, "indexed" : 0, - "safe_name" : 1 + "safe_name" : 1, + "exclude_policy_modules" : 1 }; if (this.value != '0') @@ -2248,7 +2255,11 @@ function process_manage_edit($module_name, $agents_select=null, $module_status=' // Any module. $modules = db_get_all_rows_filter( 'tagente_modulo', - ['id_agente' => $agents_select], + [ + 'id_agente' => $agents_select, + 'id_policy_module' => 0, + 'policy_linked' => 0, + ], [ 'id_agente_modulo', 'id_tipo_modulo', diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index ea69d5f8d8..ffd7ed8fb5 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -232,6 +232,11 @@ function agent_changed_by_multiple_agents(event, id_agent, selected) { } } + var exclude_policy_modules = 0; + if ($("#hidden-exclude_policy_modules").val() === "1") { + exclude_policy_modules = 1; + } + jQuery.post( homedir + "/ajax.php", { @@ -248,7 +253,8 @@ function agent_changed_by_multiple_agents(event, id_agent, selected) { status_module: module_status, id_group: id_group, pendingdelete: - event.target != undefined ? event.target.dataset.pendingdelete : 0 // Get pendingdelete attribute from target + event.target != undefined ? event.target.dataset.pendingdelete : 0, // Get pendingdelete attribute from target + exclude_policy_modules }, function(data) { $("#module").empty(); diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 2e2ee2e37a..a12a85841e 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -483,6 +483,7 @@ if (is_ajax()) { $status_modulo = (int) get_parameter('status_module', -1); $id_group_selected = (int) get_parameter('id_group', 0); $metaconsole_server_name = null; + $exclude_policy_modules = (bool) get_parameter('exclude_policy_modules', false); if (!empty($id_server)) { $metaconsole_server_name = db_get_value( 'server_name', @@ -767,6 +768,10 @@ if (is_ajax()) { } } + if ($exclude_policy_modules === true) { + $sql .= ' AND t1.id_policy_module = 0 AND t1.policy_linked = 0'; + } + $sql .= ' ORDER BY nombre'; $nameModules = db_get_all_rows_sql($sql); if ($tags != null) { @@ -836,6 +841,8 @@ if (is_ajax()) { $truncate_module_names = (bool) get_parameter('truncate_module_names'); + $exclude_policy_modules = (bool) get_parameter('exclude_policy_modules', false); + // Filter. $filter = []; if ($disabled !== -1) { @@ -927,6 +934,11 @@ if (is_ajax()) { $filter['ttag_module.id_tag IN '] = '('.implode(',', $tags).')'; } + if ($exclude_policy_modules === true) { + $filter['id_policy_module'] = 0; + $filter['policy_linked'] = 0; + } + if (is_metaconsole() && !$force_local_modules) { if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { $connection = metaconsole_get_connection($server_name);