#!/bin/bash

DOMAIN=$1
EXPIRED_IP="154.70.82.249"
MAIN_IP="154.70.82.246"
ZONE_FILE="/var/named/${DOMAIN}.db"

if [ -z "$DOMAIN" ]; then
    echo "Usage: $0 domaine.tg"
    exit 1
fi

if [ ! -f "$ZONE_FILE" ]; then
    echo "❌ Zone introuvable : $ZONE_FILE"
    exit 1
fi

# Remettre l'IP principale
sed -i "s/$EXPIRED_IP/$MAIN_IP/g" "$ZONE_FILE"

# Incrémenter le serial
SERIAL=$(date +%Y%m%d01)
sed -i "s/[0-9]\{10\}/$SERIAL/" "$ZONE_FILE"

# Recharger BIND
/scripts/restartsrv_named

echo "✅ $DOMAIN restauré → site de nouveau actif"
