From f2a15061f0bcb2b8ecf2e1afb9b646c825c38930 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 7 Feb 2024 15:39:23 +0100 Subject: [PATCH 1/2] #12783 check if module is use by agent for safe mode before delete --- .../godmode/agentes/configurar_agente.php | 6 +++++ pandora_console/include/functions_modules.php | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index c2e3a2f4f6..a2372a66f0 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -2318,6 +2318,12 @@ if ($delete_module) { exit; } + // Check if module is used by agent for Safe mode. + $is_safe_mode_module = modules_check_safe_mode($id_borrar_modulo); + if ($is_safe_mode_module === true) { + db_process_sql_update('tagente', ['safe_mode_module' => '0'], ['id_agente' => $id_agente]); + } + // Before delete the main module, check and delete the childrens from the original module. module_check_childrens_and_delete($id_borrar_modulo); diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 2d3b5676ec..91f6ffc5d1 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -5074,3 +5074,28 @@ function modules_made_compatible($id_tipo_modulo) return true; } } + + +/** + * Check if module is used by agent for Safe mode. + * + * @param integer $id_module Id for module to check + * + * @return boolean + */ +function modules_check_safe_mode($id_module) +{ + $id_agent = modules_give_agent_id_from_module_id($id_module); + if ($id_agent === 0) { + // No exist agent with this id. + return false; + } + + $agent = agents_get_agent($id_agent); + + if (isset($agent['safe_mode_module']) === true && (int) $agent['safe_mode_module'] === (int) $id_module) { + return true; + } else { + return false; + } +} From 66f8e31824f7be90cd3ebe6570a361e9d89091f1 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Tue, 13 Feb 2024 16:55:46 +0100 Subject: [PATCH 2/2] #12783 enabled correct modules when safe mode module is active in agent --- .../godmode/agentes/configurar_agente.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index a2372a66f0..7e9f566e17 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -2320,8 +2320,19 @@ if ($delete_module) { // Check if module is used by agent for Safe mode. $is_safe_mode_module = modules_check_safe_mode($id_borrar_modulo); - if ($is_safe_mode_module === true) { + if ($is_safe_mode_module === true && isset($id_agente) === true) { db_process_sql_update('tagente', ['safe_mode_module' => '0'], ['id_agente' => $id_agente]); + db_process_sql_update( + 'tagente_modulo', + [ + 'disabled' => 0, + 'disabled_by_safe_mode' => 0, + ], + [ + 'id_agente' => $id_agente, + 'disabled_by_safe_mode' => 1, + ] + ); } // Before delete the main module, check and delete the childrens from the original module.