#1 Le 17/04/2013, à 17:08
- ljere
[Résolu] démon vpn de reconnection auto fonctionne trop
bonjour, j'utilise pour mon serveur un vpn j'ai donc fureté un peu partout pour que lorsqu'il tombe il puisse être relancer automatiquement j'ai donc récupérer et modifier deux scripts dont un sert de démon pour contrôler la connexion
donc au démarrage j'ai
sh -c '~/script/script-vpn' &
sleep 60
sh -c '~/script/demon-vpn' &
...
script-vpn
#!/bin/bash
# FREEDOM-IP AUTO CONNECT SCRIPT
# ANALYSE INTERFACE RÉSEAU ACTIVE
echo
echo ----- ANALYSE INTERFACE RÉSEAU
NET_STAT=$(nmcli con status | egrep eth0)
echo
echo $NET_STAT est la connexion active
# VÉRIFICATION D'ÉTABLISSEMENT COMPLET DE LA CONNECTIVITÉ INTERNET
echo
echo ----- VÉRIFICATION INTERNET...
CURRENT_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
PING=$(ping -c 3 vpn2.freedom-ip.com | grep % | cut -d ' ' -f4)
echo
echo Adresse IP actuelle: $CURRENT_IP
echo
echo $PING sur 3 paquets reçus depuis vpn2.freedom-ip.com
if [ -z $PING ]; then
echo
echo Pas de connexion Internet fonctionnelle
notify-send 'Freedom-IP:' 'Pas de connexion Internet fonctionnelle' -i dialog-error
exit
fi
# OCCUPATION DES SERVEURS
echo
echo ----- OCCUPATION DES SERVEURS
wget --no-check-certificate -O /tmp/fip_occupation https://freedom-ip.com/statistiques.php
SERV_LOAD=$(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sed -e '/FR1/d')
echo
echo $SERV_LOAD
SERV_MAX_LOAD=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sed -e '/FR1/d' | sort -n | tail -n1) | cut -d ' ' -f2 | cut -d '
' -f1)
echo
echo $SERV_MAX_LOAD est le plus occupé, sélection pour connexion
notify-send 'Freedom-IP:' "Séléction du serveur le plus occupé: $SERV_MAX_LOAD" -i dialog-information
SERV_MAX_LOAD_2=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n2) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_3=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n3) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_4=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n4) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_5=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n5) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_6=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n6) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_7=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n7) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_8=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n8) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_9=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n9) | cut -d ' ' -f2 | cut -d '
' -f1)
# VÉRIFICATION D'UNE CONNEXION AU VPN DÉJÀ EXISTANTE
echo
echo ----- VERIFICATION
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\ -f 1)
if [ -n "${VPN_STAT}" ]; then
echo
echo Déjà connecté à $VPN_STAT - Redémarrage avec $SERV_MAX_LOAD
notify-send 'Freedom-IP:' "Déjà connecté à $VPN_STAT, Reconnexion" -i dialog-warning
echo
echo ----- DÉCONNEXION DE $VPN_STAT
nmcli con down id "${VPN_STAT}"
echo
echo OK
echo
echo ----- RECONNEXION À $SERV_MAX_LOAD'_freedomip'
echo
RCON=$(nmcli con up id $SERV_MAX_LOAD'_freedomip' | grep "Connexion activée")
echo $RCON
if [ "$RCON" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD" -i dialog-information ; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2" -i dialog-error
sleep 20
RCON_2=$(nmcli con up id $SERV_MAX_LOAD_2'_freedomip' | grep "Connexion activée")
echo $CON_2
if [ "$CON_2" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_2" -i dialog-information ; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3" -i dialog-error
sleep 20
CON_3=$(nmcli con up id $SERV_MAX_LOAD_3'_freedomip' | grep "Connexion activée")
echo $CON_3
if [ "$CON_3" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_3" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4" -i dialog-error
sleep 20
CON_4=$(nmcli con up id $SERV_MAX_LOAD_4'_freedomip' | grep "Connexion activée")
echo $CON_4
if [ "$CON_4" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_4" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5" -i dialog-error
sleep 20
CON_5=$(nmcli con up id $SERV_MAX_LOAD_5'_freedomip' | grep "Connexion activée")
echo $CON_5
if [ "$CON_5" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_5" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6" -i dialog-error
sleep 20
CON_6=$(nmcli con up id $SERV_MAX_LOAD_6'_freedomip' | grep "Connexion activée")
echo $CON_6
if [ "$CON_6" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_6" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_6, essaie $SERV_MAX_LOAD_7
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_6, essaie $SERV_MAX_LOAD_7" -i dialog-error
sleep 20
CON_7=$(nmcli con up id $SERV_MAX_LOAD_7'_freedomip' | grep "Connexion activée")
echo $CON_7
if [ "$CON_7" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_7" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_7, essaie $SERV_MAX_LOAD_8
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_7, essaie $SERV_MAX_LOAD_8" -i dialog-error
sleep 20
CON_8=$(nmcli con up id $SERV_MAX_LOAD_8'_freedomip' | grep "Connexion activée")
echo $CON_8
if [ "$CON_8" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_8" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_8, essaie $SERV_MAX_LOAD_9
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_8, essaie $SERV_MAX_LOAD_9" -i dialog-error
sleep 20
CON_9=$(nmcli con up id $SERV_MAX_LOAD_9'_freedomip' | grep "Connexion activée")
echo $CON_9
if [ "$CON_9" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_9" -i dialog-information; else
echo Impossible de se connecter à $SERV_MAX_LOAD_9
echo
echo Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !
notify-send 'Freedom-IP:' "Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !" -i dialog-warning
fi
fi
fi
fi
fi
fi
fi
fi
fi
NEW_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
echo $NEW_IP > /tmp/monip
echo Ancienne IP: $CURRENT_IP
echo Nouvelle IP: $NEW_IP
echo
echo ----- FIN DE SCRIPT
exit; else
echo
echo Pas de connexion VPN active
notify-send 'Freedom-IP:' "Établissement de la connexion sécurisée..." -i dialog-warning
fi
# CONNECTION AU VPN SI INTERNET CONNECTÉ
if [ $PING -eq 3 ]; then
echo
echo ----- CONNEXION À $SERV_MAX_LOAD
echo
CON=$(nmcli con up id $SERV_MAX_LOAD'_freedomip' | grep "Connexion activée")
echo $CON
if [ "$CON" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD" -i dialog-information ; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2" -i dialog-error
sleep 20
CON_2=$(nmcli con up id $SERV_MAX_LOAD_2'_freedomip' | grep "Connexion activée")
echo $CON_2
if [ "$CON_2" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_2" -i dialog-information ; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3" -i dialog-error
sleep 20
CON_3=$(nmcli con up id $SERV_MAX_LOAD_3'_freedomip' | grep "Connexion activée")
echo $CON_3
if [ "$CON_3" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_3" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4" -i dialog-error
sleep 20
CON_4=$(nmcli con up id $SERV_MAX_LOAD_4'_freedomip' | grep "Connexion activée")
echo $CON_4
if [ "$CON_4" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_4" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5" -i dialog-error
sleep 20
CON_5=$(nmcli con up id $SERV_MAX_LOAD_5'_freedomip' | grep "Connexion activée")
echo $CON_5
if [ "$CON_5" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_5" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6" -i dialog-error
sleep 20
CON_6=$(nmcli con up id $SERV_MAX_LOAD_6'_freedomip' | grep "Connexion activée")
echo $CON_6
if [ "$CON_6" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_6" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_6, essaie $SERV_MAX_LOAD_7
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_6, essaie $SERV_MAX_LOAD_7" -i dialog-error
sleep 20
CON_7=$(nmcli con up id $SERV_MAX_LOAD_7'_freedomip' | grep "Connexion activée")
echo $CON_7
if [ "$CON_7" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_7" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_7, essaie $SERV_MAX_LOAD_8
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_7, essaie $SERV_MAX_LOAD_8" -i dialog-error
sleep 20
CON_8=$(nmcli con up id $SERV_MAX_LOAD_8'_freedomip' | grep "Connexion activée")
echo $CON_8
if [ "$CON_8" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_8" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_8, essaie $SERV_MAX_LOAD_9
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_8, essaie $SERV_MAX_LOAD_9" -i dialog-error
sleep 20
CON_9=$(nmcli con up id $SERV_MAX_LOAD_9'_freedomip' | grep "Connexion activée")
echo $CON_9
if [ "$CON_9" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_9" -i dialog-information; else
echo Impossible de se connecter à $SERV_MAX_LOAD_9
echo
echo Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !
notify-send 'Freedom-IP:' "Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !" -i dialog-warning
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
NEW_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
echo $NEW_IP > /tmp/monip
echo Ancienne IP: $CURRENT_IP
echo Nouvelle IP: $NEW_IP
echo
echo ----- FIN DE SCRIPT
exit
demon-vpn
#! /bin/bash
# Script permettant la reconnection du vpn automatiquement si l'IP de connexion a changé ou si le vpn tombe
while true
do
sleep 5
monip=`dig +short myip.opendns.com @resolver1.opendns.com`
maderniereip=`cat /tmp/monip`
if test "$monip" = "$maderniereip";
then
# L'adresse IP n'a pas changé, tout va bien :)
echo $monip > /tmp/monip
else
# L'adresse IP a changé, on lance une reconnexion du vpn
echo $monip > /tmp/monip
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\ -f 1)
nmcli con down id "${VPN_STAT}"
sleep 20
nmcli con down id connexion filaire 1
sleep 20
nmcli con up id connexion filaire 1
sleep 30
sh -c '~/script/script-vpn' &
fi
done
donc au lancement tout va bien, mais si la connexion est perdu le démon se lance bien relance le script mais même lorsqu'il raccroche un autre vpn et que le fichier /tmp/monip correspond il décroche lui même la connexion, la boucle devient incontrôlable je ne comprend pas ou est mon erreur
Dernière modification par ljere (Le 21/04/2013, à 15:03)
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#2 Le 17/04/2013, à 17:21
- Didier-T
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
bonjour,
a ce que je vois dans ton script-vpn, a chaque lancement le script te redonne un ip sécurisé, donc si tu note ta nouvelle ip avant de lacer le script, sa tourne en rond.
du coups je tenterais ceci.
demon-vpn
#! /bin/bash
# Script permettant la reconnection du vpn automatiquement si l'IP de connexion a changé ou si le vpn tombe
while true
do
sleep 5
monip=`dig +short myip.opendns.com @resolver1.opendns.com`
maderniereip=`cat /tmp/monip`
if test "$monip" != "$maderniereip";
then
# L'adresse IP a changé, on lance une reconnexion du vpn
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\ -f 1)
nmcli con down id "${VPN_STAT}"
sleep 20
nmcli con down id connexion filaire 1
sleep 20
nmcli con up id connexion filaire 1
sleep 30
sh -c '~/script/script-vpn'
fi
done
ton ip est déjà renseigné dans /tmp/monip par le script script-vpn
Hors ligne
#3 Le 17/04/2013, à 17:37
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
je vais tester ton idée mais par contre serait il possible d’empêcher /tmp/monip d'avoir mon adresse ip sans vpn
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#4 Le 17/04/2013, à 17:43
- Didier-T
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
avec ceci, sa doit pouvoir le faire,
#!/bin/bash
# FREEDOM-IP AUTO CONNECT SCRIPT
echo "" > /tmp/monip
# ANALYSE INTERFACE RÉSEAU ACTIVE
echo
echo ----- ANALYSE INTERFACE RÉSEAU
NET_STAT=$(nmcli con status | egrep eth0)
echo
echo $NET_STAT est la connexion active
# VÉRIFICATION D'ÉTABLISSEMENT COMPLET DE LA CONNECTIVITÉ INTERNET
echo
echo ----- VÉRIFICATION INTERNET...
CURRENT_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
PING=$(ping -c 3 vpn2.freedom-ip.com | grep % | cut -d ' ' -f4)
echo
echo Adresse IP actuelle: $CURRENT_IP
echo
echo $PING sur 3 paquets reçus depuis vpn2.freedom-ip.com
if [ -z $PING ]; then
echo
echo Pas de connexion Internet fonctionnelle
notify-send 'Freedom-IP:' 'Pas de connexion Internet fonctionnelle' -i dialog-error
exit
fi
# OCCUPATION DES SERVEURS
echo
echo ----- OCCUPATION DES SERVEURS
wget --no-check-certificate -O /tmp/fip_occupation https://freedom-ip.com/statistiques.php
SERV_LOAD=$(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sed -e '/FR1/d')
echo
echo $SERV_LOAD
SERV_MAX_LOAD=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sed -e '/FR1/d' | sort -n | tail -n1) | cut -d ' ' -f2 | cut -d '
' -f1)
echo
echo $SERV_MAX_LOAD est le plus occupé, sélection pour connexion
notify-send 'Freedom-IP:' "Séléction du serveur le plus occupé: $SERV_MAX_LOAD" -i dialog-information
SERV_MAX_LOAD_2=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n2) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_3=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n3) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_4=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n4) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_5=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n5) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_6=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n6) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_7=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n7) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_8=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n8) | cut -d ' ' -f2 | cut -d '
' -f1)
SERV_MAX_LOAD_9=$(awk '{ for (i=1; i<=NF; i++) { if (i%5==1) { nb=$i } if (i%5==0) { print nb" "$i } } }' < <(grep personnes /tmp/fip_occupation | cut -d '<' -f2 | cut -d '"' -f2 | sort -n | tail -n9) | cut -d ' ' -f2 | cut -d '
' -f1)
# VÉRIFICATION D'UNE CONNEXION AU VPN DÉJÀ EXISTANTE
echo
echo ----- VERIFICATION
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\ -f 1)
if [ -n "${VPN_STAT}" ]; then
echo
echo Déjà connecté à $VPN_STAT - Redémarrage avec $SERV_MAX_LOAD
notify-send 'Freedom-IP:' "Déjà connecté à $VPN_STAT, Reconnexion" -i dialog-warning
echo
echo ----- DÉCONNEXION DE $VPN_STAT
nmcli con down id "${VPN_STAT}"
echo
echo OK
echo
echo ----- RECONNEXION À $SERV_MAX_LOAD'_freedomip'
echo
RCON=$(nmcli con up id $SERV_MAX_LOAD'_freedomip' | grep "Connexion activée")
echo $RCON
if [ "$RCON" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD" -i dialog-information ; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2" -i dialog-error
sleep 20
RCON_2=$(nmcli con up id $SERV_MAX_LOAD_2'_freedomip' | grep "Connexion activée")
echo $CON_2
if [ "$CON_2" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_2" -i dialog-information ; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3" -i dialog-error
sleep 20
CON_3=$(nmcli con up id $SERV_MAX_LOAD_3'_freedomip' | grep "Connexion activée")
echo $CON_3
if [ "$CON_3" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_3" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4" -i dialog-error
sleep 20
CON_4=$(nmcli con up id $SERV_MAX_LOAD_4'_freedomip' | grep "Connexion activée")
echo $CON_4
if [ "$CON_4" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_4" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5" -i dialog-error
sleep 20
CON_5=$(nmcli con up id $SERV_MAX_LOAD_5'_freedomip' | grep "Connexion activée")
echo $CON_5
if [ "$CON_5" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_5" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6" -i dialog-error
sleep 20
CON_6=$(nmcli con up id $SERV_MAX_LOAD_6'_freedomip' | grep "Connexion activée")
echo $CON_6
if [ "$CON_6" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_6" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_6, essaie $SERV_MAX_LOAD_7
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_6, essaie $SERV_MAX_LOAD_7" -i dialog-error
sleep 20
CON_7=$(nmcli con up id $SERV_MAX_LOAD_7'_freedomip' | grep "Connexion activée")
echo $CON_7
if [ "$CON_7" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_7" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_7, essaie $SERV_MAX_LOAD_8
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_7, essaie $SERV_MAX_LOAD_8" -i dialog-error
sleep 20
CON_8=$(nmcli con up id $SERV_MAX_LOAD_8'_freedomip' | grep "Connexion activée")
echo $CON_8
if [ "$CON_8" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_8" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_8, essaie $SERV_MAX_LOAD_9
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_8, essaie $SERV_MAX_LOAD_9" -i dialog-error
sleep 20
CON_9=$(nmcli con up id $SERV_MAX_LOAD_9'_freedomip' | grep "Connexion activée")
echo $CON_9
if [ "$CON_9" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_9" -i dialog-information; else
echo Impossible de se connecter à $SERV_MAX_LOAD_9
echo
echo Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !
notify-send 'Freedom-IP:' "Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !" -i dialog-warning
fi
fi
fi
fi
fi
fi
fi
fi
fi
NEW_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
echo $NEW_IP > /tmp/monip
echo Ancienne IP: $CURRENT_IP
echo Nouvelle IP: $NEW_IP
echo
echo ----- FIN DE SCRIPT
exit; else
echo
echo Pas de connexion VPN active
notify-send 'Freedom-IP:' "Établissement de la connexion sécurisée..." -i dialog-warning
fi
# CONNECTION AU VPN SI INTERNET CONNECTÉ
if [ $PING -eq 3 ]; then
echo
echo ----- CONNEXION À $SERV_MAX_LOAD
echo
CON=$(nmcli con up id $SERV_MAX_LOAD'_freedomip' | grep "Connexion activée")
echo $CON
if [ "$CON" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD" -i dialog-information ; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD, essaie $SERV_MAX_LOAD_2" -i dialog-error
sleep 20
CON_2=$(nmcli con up id $SERV_MAX_LOAD_2'_freedomip' | grep "Connexion activée")
echo $CON_2
if [ "$CON_2" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_2" -i dialog-information ; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_2, essaie $SERV_MAX_LOAD_3" -i dialog-error
sleep 20
CON_3=$(nmcli con up id $SERV_MAX_LOAD_3'_freedomip' | grep "Connexion activée")
echo $CON_3
if [ "$CON_3" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_3" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_3, essaie $SERV_MAX_LOAD_4" -i dialog-error
sleep 20
CON_4=$(nmcli con up id $SERV_MAX_LOAD_4'_freedomip' | grep "Connexion activée")
echo $CON_4
if [ "$CON_4" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_4" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_4, essaie $SERV_MAX_LOAD_5" -i dialog-error
sleep 20
CON_5=$(nmcli con up id $SERV_MAX_LOAD_5'_freedomip' | grep "Connexion activée")
echo $CON_5
if [ "$CON_5" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_5" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_5, essaie $SERV_MAX_LOAD_6" -i dialog-error
sleep 20
CON_6=$(nmcli con up id $SERV_MAX_LOAD_6'_freedomip' | grep "Connexion activée")
echo $CON_6
if [ "$CON_6" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_6" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_6, essaie $SERV_MAX_LOAD_7
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_6, essaie $SERV_MAX_LOAD_7" -i dialog-error
sleep 20
CON_7=$(nmcli con up id $SERV_MAX_LOAD_7'_freedomip' | grep "Connexion activée")
echo $CON_7
if [ "$CON_7" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_7" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_7, essaie $SERV_MAX_LOAD_8
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_7, essaie $SERV_MAX_LOAD_8" -i dialog-error
sleep 20
CON_8=$(nmcli con up id $SERV_MAX_LOAD_8'_freedomip' | grep "Connexion activée")
echo $CON_8
if [ "$CON_8" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_8" -i dialog-information; else
echo
echo Impossible de se connecter à $SERV_MAX_LOAD_8, essaie $SERV_MAX_LOAD_9
notify-send 'Freedom-IP:' "Impossible de se connecter à $SERV_MAX_LOAD_8, essaie $SERV_MAX_LOAD_9" -i dialog-error
sleep 20
CON_9=$(nmcli con up id $SERV_MAX_LOAD_9'_freedomip' | grep "Connexion activée")
echo $CON_9
if [ "$CON_9" = "Connexion activée" ]; then
sleep 15
notify-send 'Freedom-IP:' "Connexion sécurisée établie au server $SERV_MAX_LOAD_9" -i dialog-information; else
echo Impossible de se connecter à $SERV_MAX_LOAD_9
echo
echo Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !
notify-send 'Freedom-IP:' "Connexion à tous les serveurs impossible, Vérifiez vos paramètres de connexion !" -i dialog-warning
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
NEW_IP=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
if "$NEW_IP" != "$CURRENT_IP";
then
echo $NEW_IP > /tmp/monip
fi
echo Ancienne IP: $CURRENT_IP
echo Nouvelle IP: $NEW_IP
echo
echo ----- FIN DE SCRIPT
exit
donc au debut du script je supprime l'adresse ip contenue dans /tmp/monip, et je la renseigne uniquement si le changement d'ip à bien eut lieu.
Hors ligne
#5 Le 17/04/2013, à 18:33
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
merci didier tout à l'air fonctionnel
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#6 Le 19/04/2013, à 20:20
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
pour finir non la partie qui contrôle que je ne suis pas en ip réelle fait tourner en boucle empêchant l'accroche du vpn
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#7 Le 20/04/2013, à 09:54
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
je pense avoir trouvé une solution simple par contre je ne suis pas sur de la syntaxe du ou
#! /bin/bash
# Script permettant la reconnection du vpn automatiquement si l'IP de connexion a changé ou si le vpn tombe
while true
do
sleep 5
ipnonprotege=`0.0.0.0`
monip=`dig +short myip.opendns.com @resolver1.opendns.com`
maderniereip=`cat /tmp/monip`
if test "$monip" != "$maderniereip" || "$ipnonprotege" = "$maderniereip";
then
# L'adresse IP a changé, on lance une reconnexion du vpn
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\ -f 1)
nmcli con down id "${VPN_STAT}"
sleep 20
nmcli con down id connexion filaire 1
sleep 20
nmcli con up id connexion filaire 1
sleep 30
sh -c '~/script/script-vpn'
fi
done
j'ai modifié
if test ["$monip" != "$maderniereip" || "$ipnonprotege" = "$maderniereip"];
en
if test "$monip" != "$maderniereip" || "$ipnonprotege" = "$maderniereip";
car sinon ça décrochait la connection
Dernière modification par ljere (Le 20/04/2013, à 10:51)
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#8 Le 12/05/2013, à 13:35
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
je l'ai encore amélioré ajout d'un ping + log
#! /bin/bash
# Script permettant la reconnection du vpn automatiquement si l'IP de connexion a changé ou si le vpn tombe
while true
do
sleep 5
log=/tmp/demon-log
ipnonprotege="**.**.**.**"
monip=`dig +short myip.opendns.com @resolver1.opendns.com`
maderniereip=`cat /tmp/monip`
PING=$(ping -c 2 freedom-ip.com | grep % | cut -d ' ' -f4)
if [[ "$monip" != "$maderniereip" || "$ipnonprotege" = "$maderniereip" || -z $PING ]];
then
(
echo Pas de connexion Internet fonctionnelle
notify-send 'Freedom-IP:' 'Pas de connexion Internet fonctionnelle' -i dialog-error
# L'adresse IP a changé, on lance une reconnexion du vpn
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\ -f 1)
nmcli con down id "${VPN_STAT}"
sleep 20
nmcli con down id connexion filaire 1
sleep 20
nmcli con up id connexion filaire 1
sleep 30
sh -c '~/script/script-vpn'
) 2>&1 | tee -a $log
fi
done
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#9 Le 24/04/2014, à 14:12
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
Salut Ijere,
Très intéressant, mais j'avoue avoir du mal à appréhender certains points qui sont obscurs à mes yeux (reconnexion de multiples serveurs notamment), vu mes maigres connaissances dans les domaines réseau et script.
Si j'ai bien compris :
- Lancement du parefeu au démarrage qui bloque tous les port si le VPN n’accroche pas ou tombe, donc en cas de connexion "en clair".
- Connexion VPN automatique au boot. (démon VPN)
- Tu peux te reconnecter alternativement à 8 autres serveurs si premier vient à tomber. (script de reconnexion automatique)
En fouinant un peu, je suis tombé sur ce fil : (plus facile à comprendre pour ma part)
https://freedom-ip.com/forum/viewtopic.php?id=3823
En ce qui me concerne, les points 1, 2 et 4 sont déjà réalisés. (network-manager en openvpn, parefeu au boot et bind9 pour les DNS)
Bien que Network-manager fasse des siennes sous 14.04 LTS 64bits (enregistrement du mot de passe et import d'une configuration enregistrée impossible), actuellement je suis contrains de me connecter en console.
La connexion automatique au démarrage serait un confort apprécié, de même que la reconnexion sur d'autres serveurs en cas de pépin, là ça serait le top !
Tes scripts fonctionnent-ils malgré le bug de network-manager évoqué ci-dessus ?
Je pense que ceux-ci seraient modifiables pour un autre prestataire que freedom-ip, en l’occurrence vpntunnel.
Dans l'affirmative, quelles paramètres seraient à modifier ?
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#10 Le 24/04/2014, à 14:45
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
Si j'ai bien compris :
- Lancement du parefeu au démarrage qui bloque tous les port si le VPN n’accroche pas ou tombe, donc en cas de connexion "en clair".
- Connexion VPN automatique au boot. (démon VPN)
- Tu peux te reconnecter alternativement à 8 autres serveurs si premier vient à tomber. (script de reconnexion automatique)
oui c'est bien ça tu as tout résumé
En fouinant un peu, je suis tombé sur ce fil : (plus facile à comprendre pour ma part)
https://freedom-ip.com/forum/viewtopic.php?id=3823En ce qui me concerne, les points 1, 2 et 4 sont déjà réalisés. (network-manager en openvpn, parefeu au boot et bind9 pour les DNS)
Bien que Network-manager fasse des siennes sous 14.04 LTS 64bits (enregistrement du mot de passe et import d'une configuration enregistrée impossible), actuellement je suis contrains de me connecter en console.
La connexion automatique au démarrage serait un confort apprécié, de même que la reconnexion sur d'autres serveurs en cas de pépin, là ça serait le top !Tes scripts fonctionnent-ils malgré le bug de network-manager évoqué ci-dessus ?
Je pense que ceux-ci seraient modifiables pour un autre prestataire que freedom-ip, en l’occurrence vpntunnel.
Dans l'affirmative, quelles paramètres seraient à modifier ?
normalement si tu fais
sudo openvpn --config vpntunnel.ovpn
est ce que ça se connecte à ton serveur biensur vpntunnel.ovpn est à adapter au nom réel de ta connexion vpn
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#11 Le 24/04/2014, à 15:14
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
Pour me connecter je dois réaliser ces commandes:
cd /etc/openvpn
sudo openvpn SE-openvpn.conf
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#12 Le 24/04/2014, à 15:50
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
donc tu as juste besoin du démon voilà mon dernier code fonctionnel c'est une primeur
nécessite curl pour fonctionner
#! /bin/bash
# Script permettant la reconnection du vpn automatiquement si l'IP de connexion a changé ou si le vpn tombe
echo "script lancé au démarrage 30 secondes d'attente pour que les autres services démarre"
sleep 30
echo "**.**.**.**" > /tmp/monip
echo "mon ip est enregistré"
while true
do
sleep 5
log=/tmp/demon-log
ipnonprotege="**.**.**.**"
monip=`curl curlmyip.com`
maderniereip=`cat /tmp/monip`
PING=$(ping -c 2 google.fr | grep % | cut -d ' ' -f4)
echo "ma collecte d'info suivante est faite"
echo "mon ip: " $monip ", ma dernière ip: " $maderniereip", mon ip non protégé: "$ipnonprotege", mon ping: "$PING
if [[ "$monip" != "$maderniereip" || "$ipnonprotege" == "$maderniereip" || -z $PING ]];
then
(
echo Pas de Protection Internet fonctionnelle
notify-send 'ERREUR :' 'Pas de Protection Internet fonctionnelle' -i dialog-error
# L'adresse IP a changé, on lance une reconnexion du vpn
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\ -f 1)
nmcli con down id "${VPN_STAT}"
echo $VPN_STAT
sleep 5
nmcli con down id "Connexion filaire 1"
sleep 5
nmcli con up id "Connexion filaire 1"
sleep 5
sh -c 'cd /etc/openvpn && openvpn SE-openvpn.conf'
) 2>&1 | tee -a $log
fi
echo `date`
echo "je suis sorti du script je vais recontrôler la connexion dans 10mn"
sleep 600
echo `date`
echo "je relance la boucle"
done
pour echo "**.**.**.**" et ipnonprotege="**.**.**.**" tu dois biensur remplacer par ton ip.
pour le sleep de 600 tu peux l'augmenter là ça relance le contrôle toute les 10minutes
pour le lancer au démarrage j'utilise le cron de root
sudo crontab -e
@reboot /le/chemin/ou/tu/as/mis/le/script
Dernière modification par ljere (Le 24/04/2014, à 15:54)
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#13 Le 24/04/2014, à 16:08
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
Merci, je vais essayer ça et je te tiens informé du résultat.
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#14 Le 24/04/2014, à 17:12
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
J'ai suivi tes instructions, installé curl, indiqué mon IP et enregisté le script. Mais après reboot il ne se passe rien.
Peut-être le
sudo crontab -e
???
C'est la première fois que je m'en sers, il m'a demandé de choisir un éditeur. J'ai choisi 2 "nano", c'est peut être "easiest" mais plutôt déroutant...
Après toutes les lignes commentées #, j'y ai inscris :
@reboot /home/marc/Demon VPN/Demon vpn
Puis crtl+x afin de fermer nano, puis j'ai fermé le terminal (message de fermeture ?) et enfin j'ai rebouté.
En relisant le script, je m’aperçois qu'il y a"freedomip":
VPN_STAT=$(nmcli con status | grep freedomip | cut -d\ -f 1)
Dernière modification par Ansuz (Le 24/04/2014, à 17:20)
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#15 Le 24/04/2014, à 17:21
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
alors si ton script est Demon tu dois juste mettre
@reboot /home/marc/Demon
le script démarre ensuite au bout de 30 sec donc pas immédiat
sinon pour les premiers essais tu peux le lancer directement dans ton terminal en root
./home/marc/Demon
question bête je sais mais as tu bien rendu ton script exécutable
chmod + x /home/marc/Demon
tu remplaces freedom-ip par openvpn
Dernière modification par ljere (Le 24/04/2014, à 17:23)
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#16 Le 24/04/2014, à 17:51
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
Désolé, j'ai besoin d'aide...
Bon j'ai remplacé freedom-ip par openvpn et enregistré.
Ensuite, pour suivre tes commandes, j'ai déplacé le script que j'ai renommé Demon dans /home/marc/Demon
Mais j'arrive pas à le rendre exécutable, ni lancer directement le script en root pour tester.
De plus, j'arrive plus à accéder avec sudo crontab -e (le chemin du fichier n'est plus bon) > à l'ouverture = vide ?
Moi et les lignes de commandes...
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#17 Le 24/04/2014, à 18:49
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
donne moi le retour de
ls -l /home/marc/Demon
pour passer en root
sudo su
puis
/home/marc/Demon
donne aussi le retour de
sudo crontab -l
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#18 Le 24/04/2014, à 18:55
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
~$ ls -l /home/marc/Demon
ls: impossible d'accéder à /home/marc/Demon: Aucun fichier ou dossier de ce type
~$ sudo crontab -l
[sudo] password for marc:
no crontab for root
pourtant il existe bien ce fichier dans mon /home
Dans la fenêtre "propriétés de Demon" emplacement : /home/marc
J'ai coché "autoriser l'exécution du fichier comme un programme". J'ai lancé le script en terminal (double clic), il se lance après 30 secondes, semble fonctionner mais n'accroche pas à la fin.
Dernière modification par Ansuz (Le 24/04/2014, à 19:09)
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#19 Le 24/04/2014, à 20:11
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
ben oui si tu le lances en double clic tu le lances en simple utilisateur donc normal que ça ne fonctionne pas
donne moi le retour de
ls -l
tout simplement
on continuera de main si ça ne te dérange pas je suis plus là
sinon réessaye de refaire le sudo crontab -e
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#20 Le 24/04/2014, à 20:17
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
-rwxrwxr-x 1 marc marc 1500 avril 24 17:34 Demon
Ok, ça marche. On continuera ça plus tard, encore merci pour ton aide et ta patience...
Dernière modification par Ansuz (Le 24/04/2014, à 20:20)
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#21 Le 25/04/2014, à 07:54
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
c'est parfait ça il reste donc juste
sudo crontab -e
@reboot /home/marc/Demon
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#22 Le 25/04/2014, à 10:18
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
Le boulet est de retour...
Donc, ça c'est bon ?
-rwxrwxr-x 1 marc marc 1500 avril 24 17:34 Demon
Le propriétaire ne devrait-il pas être root ?
Si je lance le script par double clic :
script lancé au démarrage 30 secondes d'attente pour que les autres services démarrent
mon ip est enregistré
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15 100 15 0 0 21 0 --:--:-- --:--:-- --:--:-- 21
ma collecte d'info suivante est faite
mon ip: XXX , ma dernière ip: XXX, mon ip non protégé: XXX, mon ping: 2
Pas de Protection Internet fonctionnelle
Erreur : connexion inconnue : .Fri Apr 25 09:48:15 2014 OpenVPN 2.3.2 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [eurephia] [MH] [IPv6] built on Feb 4 2014
Enter Auth Username:XXX
Enter Auth Password:
Fri Apr 25 09:48:28 2014 Socket Buffers: R=[212992->131072] S=[212992->131072]
Fri Apr 25 09:48:28 2014 UDPv4 link local: [undef]
Fri Apr 25 09:48:28 2014 UDPv4 link remote: [AF_INET]178.73.212.241:1196
Fri Apr 25 09:49:28 2014 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
Fri Apr 25 09:49:28 2014 TLS Error: TLS handshake failed
Fri Apr 25 09:49:28 2014 SIGUSR1[soft,tls-error] received, process restarting
Fri Apr 25 09:49:28 2014 Restart pause, 2 second(s)
Fri Apr 25 09:49:30 2014 Socket Buffers: R=[212992->131072] S=[212992->131072]
Fri Apr 25 09:49:30 2014 UDPv4 link local: [undef]
Fri Apr 25 09:49:30 2014 UDPv4 link remote: [AF_INET]178.73.212.242:1198
Fri Apr 25 09:50:30 2014 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
Fri Apr 25 09:50:30 2014 TLS Error: TLS handshake failed
Fri Apr 25 09:50:30 2014 SIGUSR1[soft,tls-error] received, process restarting
Fri Apr 25 09:50:30 2014 Restart pause, 2 second(s)
Fri Apr 25 09:50:32 2014 Socket Buffers: R=[212992->131072] S=[212992->131072]
Fri Apr 25 09:50:32 2014 UDPv4 link local: [undef]
Fri Apr 25 09:50:32 2014 UDPv4 link remote: [AF_INET]178.73.212.243:1200
Fri Apr 25 09:51:32 2014 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
Fri Apr 25 09:51:32 2014 TLS Error: TLS handshake failed
Fri Apr 25 09:51:32 2014 SIGUSR1[soft,tls-error] received, process restarting
Fri Apr 25 09:51:32 2014 Restart pause, 2 second(s)
Fri Apr 25 09:51:34 2014 Socket Buffers: R=[212992->131072] S=[212992->131072]
Fri Apr 25 09:51:34 2014 UDPv4 link local: [undef]
Fri Apr 25 09:51:34 2014 UDPv4 link remote: [AF_INET]178.73.212.244:7004
Fri Apr 25 09:51:35 2014 TLS: Initial packet from [AF_INET]178.73.212.244:7004, sid=014462f0 58a5b44b
Fri Apr 25 09:51:35 2014 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
Fri Apr 25 09:51:35 2014 VERIFY OK: depth=1, C=SE, ST=Stockholm, L=Stockholm, O=Vpntunnel.se, OU=changeme, CN=changeme, name=changeme, emailAddress=info@vpntunnel.se
Fri Apr 25 09:51:35 2014 VERIFY OK: nsCertType=SERVER
Fri Apr 25 09:51:35 2014 VERIFY OK: depth=0, C=SE, ST=Stockholm, L=Stockholm, O=vpntunnel.se, OU=changeme, CN=server, name=changeme, emailAddress=info@vpntunnel.se
Fri Apr 25 09:51:35 2014 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Fri Apr 25 09:51:35 2014 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Apr 25 09:51:35 2014 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Fri Apr 25 09:51:35 2014 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri Apr 25 09:51:35 2014 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 2048 bit RSA
Fri Apr 25 09:51:35 2014 [server] Peer Connection Initiated with [AF_INET]178.73.212.244:7004
Fri Apr 25 09:51:38 2014 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1)
Fri Apr 25 09:51:38 2014 PUSH: Received control message: 'PUSH_REPLY,dhcp-option DNS 80.67.0.2,dhcp-option DNS 91.213.246.2,redirect-gateway def1,route-gateway 5.254.140.97,topology subnet,ping 10,ping-restart 160,ifconfig 5.254.140.107 255.255.255.224'
Fri Apr 25 09:51:38 2014 OPTIONS IMPORT: timers and/or timeouts modified
Fri Apr 25 09:51:38 2014 OPTIONS IMPORT: --ifconfig/up options modified
Fri Apr 25 09:51:38 2014 OPTIONS IMPORT: route options modified
Fri Apr 25 09:51:38 2014 OPTIONS IMPORT: route-related options modified
Fri Apr 25 09:51:38 2014 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Fri Apr 25 09:51:38 2014 ROUTE_GATEWAY 192.168.0.254/255.255.255.0 IFACE=eth0 HWADDR=00:1a:92:20:58:21
Fri Apr 25 09:51:38 2014 ERROR: Cannot ioctl TUNSETIFF tun: Operation not permitted (errno=1)
Fri Apr 25 09:51:38 2014 Exiting due to fatal error
vendredi 25 avril 2014, 09:51:38 (UTC+0200)
je suis sorti du script je vais recontrôler la connexion dans 10mn
Ensuite, le sudo crontab -e, une fois le terminal ouvert : (nano)
Fichier : /tmp/crontab.YyeBFH/crontab
comment on s'en sert ?
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#23 Le 25/04/2014, à 15:56
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
bon je vai t'expliquer point par point
sudo crontab -e
là tu vas en bas et tu ajoutes à la fin
@reboot /home/marc/Demon
pour enregistrer c'est la touche "ctrl" + la lettre "o" comme oscar
puis "entrée" pour valider
et on ferme avec "ctrl" + "x"
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne
#24 Le 25/04/2014, à 16:25
- Ansuz
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
J'ai suivi tes instructions, j'ai simplement renommé le fichier pour le retrouver.
J'ai rebooter, mais rien ne se passe.
sudo crontab -l
no crontab for root
crontab -l
no crontab for marc
Dernière modification par Ansuz (Le 25/04/2014, à 16:30)
"Mieux vaut ne rien savoir que beaucoup savoir à moitié !" Friedrich Nietzsche
Hors ligne
#25 Le 25/04/2014, à 18:18
- ljere
Re : [Résolu] démon vpn de reconnection auto fonctionne trop
est ce que quand tu fais le
sudo crontab -e
tu as le message new crontab enregistré qui s'affiche?
ancien PC Toshiba satellite_c670d-11 / Linux Mint 21 Vanessa
Nouveau PC ASUS TUF GAMING A17 GPU RTX 4070 CPU AMD Ryzen 9 7940HS w/ Radeon 780M Graphics / Linux Mint 21.2 Victoria / Kernel: 6.4.8-1-liquorix / Desktop: Cinnamon
Hors ligne