Advertisement
tolikpunkoff

reconnect-openvpn v 0.1

Aug 25th, 2019
1,579
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. CONFIGDIR="~/openvpn/configs"
  4.  
  5. CONFIGFILES[0]="riseup-nl.ovpn"
  6. CONFIGFILES[1]="riseup-ca.ovpn"
  7. CONFIGFILES[2]="riseup-us.ovpn"
  8. CONFIGFILES[3]="vpnbook-ca1-tcp80.ovpn"
  9. CONFIGFILES[4]="vpnbook-de233-tcp80.ovpn"
  10. CONFIGFILES[5]="vpnbook-euro1-tcp80.ovpn"
  11. CONFIGFILES[6]="vpnbook-euro2-tcp80.ovpn"
  12. CONFIGFILES[7]="vpnbook-us1-tcp80.ovpn"
  13. CONFIGFILES[8]="vpnbook-us2-tcp80.ovpn"
  14. CTR="${#CONFIGFILES[*]}"; I="0"
  15. SELFILE=""
  16. ERRINP="0"
  17.  
  18. ovpn_down()
  19. {
  20.     echo -n "Down connection..."
  21.     CTR=0
  22.     pkill openvpn
  23.     while [ "$CTR" -ne "1" ];do
  24.     echo -n "."
  25.     CTR=`ps ax|grep -c "openvpn"`
  26.     sleep 1
  27.     done
  28.     echo
  29. }
  30.  
  31. echo "Select config:"
  32. until [ "$CTR" -eq "$I" ]; do
  33.     echo "$I:" "${CONFIGFILES[I]}"
  34.     let "I+=1"
  35. done
  36. echo "d - down connection"
  37. echo "q - exit"
  38.  
  39. while [ "$KEYINPUT" != "q" ]; do
  40.     ERRINP="0"
  41.     read KEYINPUT
  42.     if [ "$KEYINPUT" = "q" ];then exit;fi
  43.     if [ "$KEYINPUT" = "d" ];then
  44.     ovpn_down
  45.     exit
  46.     fi
  47.    
  48.     if (echo "$KEYINPUT" | grep -E -q "^?[0-9]+$"); then
  49.     if [ "$KEYINPUT" -lt "0" ];then
  50.         echo "Wrong number :("
  51.         ERRINP="1"
  52.     fi
  53.     if [ "$KEYINPUT" -gt "$CTR" ];then
  54.         echo "Wrong number :("
  55.         ERRINP="1"
  56.     fi
  57.  
  58.     else
  59.     echo "Not Number"
  60.     ERRINP="1"
  61.     fi
  62.    
  63.     if [ "$ERRINP" -eq "0" ]; then
  64.     SELFILE="$CONFIGDIR/${CONFIGFILES[$KEYINPUT]}"
  65.     echo "Selected: $SELFILE"
  66.     break
  67.     fi
  68. done
  69.  
  70. ovpn_down
  71.  
  72. echo "Up connection..."
  73. openvpn --config $SELFILE >/dev/tty3 &
  74. waiter 10
Advertisement
RAW Paste Data Copied
Advertisement