diff --git a/ansible/install_fail2ban.sh b/ansible/install_fail2ban.sh index ffe871e01..4f1834eaf 100755 --- a/ansible/install_fail2ban.sh +++ b/ansible/install_fail2ban.sh @@ -10,8 +10,8 @@ fi IP_SERVER=$(zenity --entry --title "Configuration Serveur" --text "Entrez l'adresse IP du serveur :") SSH_USER=$(zenity --entry --title "Configuration Serveur" --text "Entrez l'utilisateur SSH :") SSH_PASS=$(zenity --password --title "Configuration Serveur" --text "Entrez le mot de passe SSH :") -SSH_PORT=$(zenity --entry --title "Configuration Serveur" --text "Entrez le port SSH (ex: 22) :" --entry-text "22") -MATTERMOST_WEBHOOK=$(zenity --entry --title "Mattermost" --text "Entrez l'URL du webhook Mattermost :") +SSH_PORT=$(zenity --entry --title "Configuration Serveur" --text "Entrez le port SSH (ex: 22) :" --entry-text "") +MATTERMOST_WEBHOOK=$(zenity --entry --title "Mattermost" --text "Entrez l'URL du webhook Mattermost :" --entry-text "https://mattermost.yeagerdan.com/hooks/c5nmzrf64fd33b1iqnm6zmt48o") # Vérifie si les variables sont vides if [[ -z "$IP_SERVER" || -z "$SSH_USER" || -z "$SSH_PASS" || -z "$SSH_PORT" || -z "$MATTERMOST_WEBHOOK" ]]; then @@ -19,14 +19,27 @@ if [[ -z "$IP_SERVER" || -z "$SSH_USER" || -z "$SSH_PASS" || -z "$SSH_PORT" || - exit 1 fi -# Crée le fichier d'inventaire dynamique -cat > inventory.ini < "$INVENTORY_FILE" < /dev/null; then + echo "Zenity non trouvé, installation..." + sudo apt update && sudo apt install -y zenity fi -# Extraire les valeurs -IP_SERVER=$(echo "$USER_INPUT" | cut -d',' -f1) -SSH_USER=$(echo "$USER_INPUT" | cut -d',' -f2) -SSH_PASS=$(echo "$USER_INPUT" | cut -d',' -f3) -SSH_PORT=$(echo "$USER_INPUT" | cut -d',' -f4) -MATTERMOST_WEBHOOK=$(echo "$USER_INPUT" | cut -d',' -f5) +# Demande les infos via Zenity +IP_SERVER=$(zenity --entry --title "Configuration Serveur" --text "Entrez l'adresse IP du serveur :") +SSH_USER=$(zenity --entry --title "Configuration Serveur" --text "Entrez l'utilisateur SSH :") +SSH_PASS=$(zenity --password --title "Configuration Serveur" --text "Entrez le mot de passe SSH :") +SSH_PORT=$(zenity --entry --title "Configuration Serveur" --text "Entrez le port SSH (ex: 22) :" --entry-text "") +MATTERMOST_WEBHOOK=$(zenity --entry --title "Mattermost" --text "Entrez l'URL du webhook Mattermost :" --entry-text "https://mattermost.yeagerdan.com/hooks/c5nmzrf64fd33b1iqnm6zmt48o") -# Vérifier que toutes les valeurs sont renseignées +# Vérifie si les variables sont vides if [[ -z "$IP_SERVER" || -z "$SSH_USER" || -z "$SSH_PASS" || -z "$SSH_PORT" || -z "$MATTERMOST_WEBHOOK" ]]; then - zenity --error --text="Toutes les informations doivent être remplies !" --width=300 + zenity --error --title "Erreur" --text "Toutes les informations sont requises !" exit 1 fi -# Générer un fichier d'inventaire dynamique +# Crée le fichier d'inventaire dynamique cat > inventory.ini <** après trop d'échecs SSH 🚨\"}" {{ mattermost_webhook }} + actionban = curl -X POST -H "Content-Type: application/json" --data "{\"text\": \"🚨 *$(hostname -s)* : **Fail2ban** a banni l'IP **** après trop d'échecs SSH 🚨\"}" "https://mattermost.yeagerdan.com/hooks/c5nmzrf64fd33b1iqnm6zmt48o" actionunban = notify: Restart Fail2ban