diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index c6b5f2b691..3b4a07e10b 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -2334,6 +2334,23 @@ 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 && 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. 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; + } +}