Skip to content
Snippets Groups Projects
Commit f0cb3b4b authored by Elian Loraux's avatar Elian Loraux
Browse files

Script de bascule réseau automatique

parent ffc34c1a
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
IPPubliqueTetrixChezOVH="109.190.180.230"
IPPubliqueAquilaChezOVH="5.135.140.89"
APIKEY="PUT YOUT PERSONAL TOKEN" # Jeton sur passbotl
stateFile="/opt/net-state"
currentIP=`curl api.ipify.org`
reverseSSHProxyPath="/opt/reverseSSHproxy.sh"
# check if file exist
if [[ -f "$stateFile" ]]; then
$state=`cat $stateFile`
# Check if current ip is different of normal ip
if [[ $IPPubliqueTetrixChezOVH == $currentIP ]]; then
if [[ $state != "normal" ]]; then
# Switch on normal mode
# ssh dockerweb@aquila.tetras-libre.fr 'cd reverse-ssh-proxy && docker-compose down'
pid=`ps aux | grep test.sh | grep -v grep | awk '{print $2}'`
kill $pid
change_dns $APIKEY $IPPubliqueTetrixChezOVH
echo "normal" > "$stateFile"
fi
else
if [[ $state = "normal" ]]; then
# Switch on back up mode
# ssh dockerweb@aquila.tetras-libre.fr 'cd reverse-ssh-proxy && docker-compose up'
bash $reverseSSHProxyPath &
change_dns $APIKEY $IPPubliqueAquilaChezOVH
echo "backup" > "$stateFile"
fi
fi
else
echo "normal" > "$stateFile"
fi
change_dns() {
APIKEY=$1
CURRENTIP=$2
curl -s -X PUT --header "Authorization: Bearer ${APIKEY}" \
--header "Content-Type: application/json" \
-d "{\"rrset_values\": [\"${CURRENTIP}\"], \"rrset_ttl\": "300"}" \
https://api.gandi.net/v5/livedns/domains/tetras-libre.fr/records/tetrixx/A
}
#!/bin/bash
HTTPS_PORT=8080
SSHPORT_INT=2223
SSHPORT=2222
PROXY_HOST=aquila.tetras-libre.fr
while true; do
/usr/bin/ssh -i /root/.ssh/id_rsa -N -R ${HTTPS_PORT}:localhost:443 -R ${SSHPORT_INT}:localhost:22 -o "ExitOnForwardFailure yes" -o "StrictHostKeyChecking no" -o "ServerAliveInterval 60" sshuser@${PROXY_HOST} -p ${SSHPORT}
echo "Ssh failed $?"
sleep 5
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment