diff --git a/net-switch.sh b/net-switch.sh new file mode 100644 index 0000000000000000000000000000000000000000..2fad4419c6fd8ac9b80b9e184eae93bdd13bd52b --- /dev/null +++ b/net-switch.sh @@ -0,0 +1,54 @@ +#!/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 + +} diff --git a/reverseSSHproxy.sh b/reverseSSHproxy.sh new file mode 100644 index 0000000000000000000000000000000000000000..64d977d529360358b6e53d1d98bafb3ecc25c812 --- /dev/null +++ b/reverseSSHproxy.sh @@ -0,0 +1,10 @@ +#!/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