SHARE
TWEET

vpnbook-get-configs

tolikpunkoff Aug 23rd, 2019 662 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. VPNBOOKPAGE="https://www.vpnbook.com/"
  4. WORKDIR="/tmp/vpnbook/"
  5. UNPDIR="/tmp/vpnbook/unpack/"
  6. HTMLFILE="vpnhtml.html"
  7.  
  8. OUTDIR="~/openvpn/vpnbook/"
  9. OUTMASK="*tcp80.ovpn"
  10.  
  11. ADD_COMMANDS[0]="#EXAMPLE OPTION script-security 2"
  12. ADD_COMMANDS[1]="#EXAMPLE OPTION up '~/openvpn/vpnbook/vb-routes up'"
  13. ADD_COMMANDS[2]="#EXAMPLE OPTION down '~/openvpn/vpnbook/vb-routes down'"
  14. ADD_COMMANDS[3]="#EXAMPLE OPTION auth-user-pass ~/openvpn/vpnbook/vpnbook.auth"
  15.  
  16. add_commands() #$1-output file
  17. {
  18.     CTR="${#ADD_COMMANDS[*]}"; I="0"
  19.     until [ "$CTR" -eq "$I" ]; do
  20.    
  21.     CMND_="${ADD_COMMANDS[I]}"
  22.     CMND_ST=`echo "$CMND_" |awk '{print $1}'`
  23.     CMND_C=`grep -c "$CMND_ST" "$1"`
  24.    
  25.     if [ "$CMND_C" -eq 0 ];then #not found, add
  26.         sed -i -e "1 s%^%$CMND_\n%" "$1"
  27.     else #found, replace
  28.         sed -i "s%^ *$CMND_ST.*%$CMND_%" "$1"
  29.     fi
  30.    
  31.     let "I+=1"
  32.     done
  33. }
  34.  
  35. echo "GET VPNBOOK CONFIGS v 0.1"
  36.  
  37. if [[ "$1" == "-h" ]]; then
  38.     echo "Use "`basename $0`" [options]"
  39.     echo "Options:"
  40.     echo "-c - Clean unpack directory after get configs"
  41.     echo "-h - This help"
  42.     echo "Please check values of variables at the"
  43.     echo "beginning of the script (e.g WORKDIR)"
  44.     echo "and add your VPN Config options to ADD_COMMANDS array"
  45.     exit
  46. fi
  47.  
  48. if [[ "$1" == "-c" ]]; then
  49.     echo "Cleaning  unpack directory..."
  50.     rm -rf "$UNPDIR"
  51. fi
  52.  
  53. rm "$WORKDIR$HTMLFILE"
  54.  
  55. mkdir -p "$WORKDIR"
  56. mkdir -p "$UNPDIR"
  57.  
  58. echo "Get vpnbook page..."
  59. wget -P $WORKDIR --default-page=$HTMLFILE --header="Content-type: text/html" $VPNBOOKPAGE
  60.  
  61. if [[ ! -f "$WORKDIR$HTMLFILE" ]];then
  62.     echo "Page not downloaded!"
  63.     exit
  64. fi
  65.  
  66. for ZIPURL in $(xidel -s --extract "//a/@href" "$WORKDIR$HTMLFILE" |grep ".zip"); do
  67.     ZIPNAME=`basename $ZIPURL`
  68.     echo "Download $ZIPNAME..."
  69.     wget -P $WORKDIR "$VPNBOOKPAGE/$ZIPURL" >/dev/null 2>/dev/null
  70.     if [ -f "$WORKDIR$ZIPNAME" ];then
  71.     echo "Unpacking $ZIPNAME..."
  72.     unzip -o "$WORKDIR$ZIPNAME" -d "$UNPDIR" >/dev/null 2>/dev/null
  73.     rm "$WORKDIR$ZIPNAME"
  74.     fi
  75. done
  76.  
  77. echo -n "Replacing Windows line ends"
  78. for FLE in $(find $UNPDIR -maxdepth 1 -iname "*.ovpn"); do
  79.     echo -n "."
  80.     sed -i 's/\r$//' "$FLE"
  81. done
  82. echo
  83.  
  84. echo -n "Add commands"
  85. for FLE in $(find $UNPDIR -maxdepth 1 -iname "*.ovpn"); do
  86.     echo -n "."
  87.     add_commands "$FLE"
  88. done
  89. echo
  90.  
  91.  
  92. #copyng to outdir
  93. if [ -n "$OUTDIR" ]; then
  94.     echo "Copy to outdir:"
  95.     for FLE in $(find $UNPDIR -maxdepth 1 -iname $OUTMASK); do
  96.     if [ -n "$FLE" ]; then
  97.         BN=`basename $FLE`
  98.         echo "$BN"
  99.         cp "$FLE" "$OUTDIR$BN"
  100.     fi
  101.     done
  102. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top