tolikpunkoff

reconnect-openvpn 0.2

Aug 25th, 2019
261
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. CONFIGDIR="~/openvpn/configs"
  4.  
  5. create_list() #$1 - dir, $2 - file mask
  6. {
  7.     FOUNDLST=""
  8.     for FLE in $(find $1 -maxdepth 1 -iname $2|sort); do
  9.     if [ -n "$FLE" ]; then
  10.         FOUNDLST="$FOUNDLST"`basename $FLE`"\n"
  11.     fi
  12.     done
  13. }
  14.  
  15. ask_list() #$1 - list #$2 - header
  16. {
  17.     LIST_BUF=$1
  18.     LIST_BUF="$LIST_BUF""Exit "
  19.     LIST_BUF="$LIST_BUF""Down"
  20.     LIST_BUF=`echo -e "$LIST_BUF"|sed 's/\n/ /'`
  21.    
  22.     PS3=$2
  23.    
  24.     echo
  25.     select LIST_RET in $LIST_BUF; do
  26.     if [ -n "$LIST_RET" ];then
  27.         break
  28.     fi
  29.     done
  30.    
  31. }
  32.  
  33. ovpn_down()
  34. {
  35.     echo -n "Down connection..."
  36.     CTR=0
  37.     pkill openvpn
  38.     while [ "$CTR" -ne "1" ];do
  39.     echo -n "."
  40.     CTR=`ps ax|grep -c "openvpn"`
  41.     sleep 1
  42.     done
  43.     echo
  44. }
  45.  
  46. create_list $CONFIGDIR "*.ovpn"
  47. ask_list $FOUNDLST "Select config: "
  48. echo "Selected: $LIST_RET"
  49.  
  50. if [[ "$LIST_RET" == "Exit" ]]; then
  51.     echo "Exitting..."
  52.     exit 0
  53. fi
  54.  
  55. if [[ "$LIST_RET" == "Down" ]]; then
  56.     ovpn_down
  57.     exit 0
  58. fi
  59.  
  60. ovpn_down
  61. echo "Up connection..."
  62. openvpn --config "$CONFIGDIR/$LIST_RET" >/dev/tty3 &
  63. ~/scripts/waiter 10
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×