Last active
March 27, 2020 16:04
-
-
Save gbhgit/bd8d89f46a907e1317a575953c3d990d to your computer and use it in GitHub Desktop.
Automatic reconnects to the VPN server if lost connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
# + INSTALL: | |
# - install fortclient: sudo apt-get install <FortiClient installation deb file> | |
# - setup fortclient case x64: sudo /opt/forticlient-sslvpn/64bit/helper/setup | |
# - setup fortclient case x32: sudo /opt/forticlient-sslvpn/32bit/helper/setup | |
# - install: sudo apt-get install expect or sudo apt-get install ppp expect | |
# + USAGE: | |
# - Line 13: ADD IP AND PORT BY REPLACING 'IP:PORT', USE ':' BETWEEN IP AND PORT | |
# - Line 13: ADD VPN USER BY REPLACING 'USER' | |
# - Line 15: ADD PASSWORD BY REPLACING 'PASS' | |
spawn /opt/forticlient-sslvpn/64bit/forticlientsslvpn_cli --server IP:PORT --vpnuser USER | |
expect "Password for VPN:" | |
send "PASS\r" | |
expect "Would you like to connect to this server? (Y/N)" | |
send "Y\r" | |
interact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# + INSTALL: | |
# - install fortclient: sudo apt-get install <FortiClient installation deb file> | |
# - setup fortclient, case x64: sudo /opt/forticlient-sslvpn/64bit/helper/setup | |
# - setup fortclient, case x32: sudo /opt/forticlient-sslvpn/32bit/helper/setup | |
# - install expect packge: sudo apt-get install expect or sudo apt-get install ppp expect | |
address=IP # ADD IP BY REPLACING 'IP' TO CHECK IF VPN IS ONLINE | |
internet=1 | |
_mydir="`pwd`/vpn_credentials.sh" | |
while true; | |
do | |
echo -n $(date +"%a, %b %d, %r") "-- " | |
ping -c 1 ${address} > /tmp/ping.$ | |
if [[ $? -ne 0 ]]; then | |
if [[ ${internet} -eq 1 ]]; then | |
echo -n "Internet DOWN" | |
# re-start system | |
screen -X -S vpn quit | |
screen -dmS vpn bash -c "$_mydir" '; exec bash' | |
else | |
echo -n "... still down" | |
# re-start system | |
screen -X -S vpn quit | |
screen -dmS vpn bash -c "$_mydir" '; exec bash' | |
fi | |
internet=0 | |
else | |
if [[ ${internet} -eq 0 ]]; then | |
echo -n "... Internet back up" | |
fi | |
internet=1 | |
fi | |
cat /tmp/ping.$ | head -2 | tail -1 | |
sleep 180; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment