Archived
Ajouter scripts/admin/steps/01-pfsense.sh
This commit is contained in:
1 parent
9367084e58
commit
9f5d990d5f
1 file changed
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# 01-pfsense.sh — Création VLAN + interface OPT + règles firewall sur pfSense
|
||||
# ==============================================================================
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_FW="${ADMIN_TOOLS}/fwdeploy/provision_pfsense_vlan_interactivev2.sh"
|
||||
PARENT_IF="vtnet1"
|
||||
WAN_IF="wan"
|
||||
|
||||
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; BLUE='\033[0;34m'; NC='\033[0m'
|
||||
info() { echo -e " ${BLUE}›${NC} $*"; }
|
||||
ok() { echo -e " ${GREEN}✔${NC} $*"; }
|
||||
warn() { echo -e " ${YELLOW}⚠${NC} $*"; }
|
||||
die() { echo -e " ${RED}✖${NC} $*" >&2; exit 1; }
|
||||
|
||||
[[ ! -x "${SCRIPT_FW}" ]] && die "Script pfSense non exécutable: ${SCRIPT_FW}"
|
||||
command -v expect &>/dev/null || die "expect non installé — dnf install -y expect"
|
||||
|
||||
info "Cible pfSense : ${VM_GW}:2266"
|
||||
info "VLAN tag : ${VLAN}"
|
||||
info "Description : ${VLAN_DESCR}"
|
||||
info "IP interface : ${VM_GW}/24"
|
||||
info "Parent IF : ${PARENT_IF}"
|
||||
info "WAN IF : ${WAN_IF}"
|
||||
|
||||
if [[ "${DRY_RUN}" == true ]]; then
|
||||
echo -e " ${YELLOW}[DRY-RUN]${NC} expect interactions avec ${SCRIPT_FW}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ─── Création VLAN + règles via expect ────────────────────────────────────────
|
||||
expect << EXPECT
|
||||
set timeout 60
|
||||
spawn ${SCRIPT_FW}
|
||||
|
||||
expect "Interface parente VLAN*:" { send "${PARENT_IF}\r" }
|
||||
expect "Tag VLAN*:" { send "${VLAN}\r" }
|
||||
expect "Description interface*:" { send "${VLAN_DESCR}\r" }
|
||||
expect "Adresse IP interface pfSense*:" { send "${VM_GW}\r" }
|
||||
expect "CIDR masque*:" { send "24\r" }
|
||||
expect "Interface WAN*:" { send "${WAN_IF}\r" }
|
||||
expect "Imposer un OPT*:" { send "n\r" }
|
||||
expect "Appliquer cette configuration*:" { send "y\r" }
|
||||
expect eof
|
||||
EXPECT
|
||||
|
||||
# ─── Reload complet pfSense (interfaces + règles + NAT) ──────────────────────
|
||||
# php /etc/rc.reload_all est la seule commande qui recharge tout correctement
|
||||
# après création d'une nouvelle interface — équivalent du bouton "Apply" UI
|
||||
info "Reload complet pfSense (rc.reload_all)..."
|
||||
ssh -p 2266 -o ConnectTimeout=15 -o StrictHostKeyChecking=yes \
|
||||
admin@10.11.0.1 \
|
||||
"php /etc/rc.reload_all 2>/dev/null && echo '[PF] reload_all OK'" \
|
||||
|| warn "rc.reload_all a retourné une erreur (non bloquant)"
|
||||
|
||||
sleep 3
|
||||
|
||||
# ─── Vérification règles actives ─────────────────────────────────────────────
|
||||
info "Vérification règles actives pour ${VLAN_DESCR}..."
|
||||
RULES_ACTIVE=$(ssh -p 2266 -o ConnectTimeout=10 -o StrictHostKeyChecking=yes \
|
||||
admin@10.11.0.1 \
|
||||
"pfctl -sr | grep -c '${VLAN_DESCR}'" 2>/dev/null || echo "0")
|
||||
|
||||
if [[ "${RULES_ACTIVE}" -gt 0 ]]; then
|
||||
ok "${RULES_ACTIVE} règles ${VLAN_DESCR} actives dans PF"
|
||||
else
|
||||
warn "Règles ${VLAN_DESCR} non confirmées dans PF — le trafic devrait quand même passer"
|
||||
fi
|
||||
|
||||
ok "VLAN ${VLAN} créé sur pfSense (${VM_GW}/24)"
|
||||
Reference in new issue
Block a user