diff --git a/test/common.sh b/test/common.sh index dae174d..4414dcf 100644 --- a/test/common.sh +++ b/test/common.sh @@ -159,7 +159,14 @@ is_package_installed() { # Function to check if a service is running service() { - systemctl $1 $2 + systemctl $1 $2 || handle_error "test" log_message "SUCCESS" "Action : $1 for service : $2 successfully" +} + +# Fonction pour la gestion des erreurs +handle_error() { + log "${RED} - Erreur : $1 ${NOCOLOR}" + + exit 1 } \ No newline at end of file diff --git a/test/modules/ssh_hardening.sh b/test/modules/ssh_hardening.sh index adf8fd7..128e24d 100644 --- a/test/modules/ssh_hardening.sh +++ b/test/modules/ssh_hardening.sh @@ -98,16 +98,16 @@ EOF # Function to harden SSH configuration harden_ssh_config() { - local ssh_config="/etc/ssh/sshd_config" - local ssh_config_backup="$BACKUP_DIR/etc/ssh/sshd_config" + local SSH_CONFIG="/etc/ssh/sshd_config" + local SSH_CONFIG_BACKUP="$BACKUP_DIR/etc/ssh/sshd_config" # Backup current SSH configuration - backup_file "$ssh_config" + backup_file "$SSH_CONFIG" log_message "INFO" "Hardening SSH configuration" # Create a new SSH configuration with hardened settings - cat > "$ssh_config" << EOF + cat > "$SSH_CONFIG" << EOF # SSH Server Configuration # Hardened configuration from security script @@ -164,7 +164,7 @@ EOF else log_message "ERROR" "Failed to restart SSH service" # Revert to backup - cp "$ssh_config_backup" "$ssh_config" + cp "$SSH_CONFIG_BACKUP" "$SSH_CONFIG" service restart sshd log_message "WARNING" "Reverted to original SSH configuration"