vpngate-dialog.sh (2640B)
1#!/bin/bash 2 3CSV="/tmp/vpngate.csv" 4 5# $ sed 's/^#HostName,/HostName,/; 2q;d' /tmp/vpngate.csv | tr ',' '\n' | awk '{print NR " " $0}' | column -t -R1 6# 1 HostName 7# 2 IP 8# 3 Score 9# 4 Ping 10# 5 Speed 11# 6 CountryLong 12# 7 CountryShort 13# 8 NumVpnSessions 14# 9 Uptime 15# 10 TotalUsers 16# 11 TotalTraffic 17# 12 LogType 18# 13 Operator 19# 14 Message 20# 15 OpenVPN_ConfigData_Base64 21 22 23# check dependencies 24which dialog curl awk sort uniq awk grep column >/dev/null || exit 1 25 26# get vpngate.csv 27if [ ! -f $CSV ]; then 28 dialog --yesno "$CSV not found, download it?" 6 28 29 if [ $? = 0 ]; then 30 curl -o "$CSV" "https://www.vpngate.net/api/iphone/" 2>&1 | dialog --progressbox 20 85 31 else 32 clear 33 exit 0 34 fi 35fi 36 37# get server list 38SRV_LIST=$(sed -e ' 39 1,2d;$d 40 s/,Korea Republic of,/,South Korea,/ 41 s/,Russian Federation,/,Russia,/ 42 s/,Viet Nam,/,Vietnam,/ 43 ' $CSV 44) 45 46get_ovpn() { 47 # select country 48 local C=(ALL ALL) 49 while read -r line; do 50 country_short=${line%,*} 51 country_long=${line#*,} 52 C+=($country_short "$country_long") 53 done < <(echo "$SRV_LIST" | awk -F',' -vOFS=',' '{print toupper($7), $6}' | sort | uniq) 54 55 if [ -z "$country" ]; then 56 country=$(dialog --title "Select country" --menu "Choose server location" 20 40 17 "${C[@]}" 3>&2 2>&1 1>&3) 57 [ $? -ne 0 ] && { clear; exit 0; } 58 fi 59 [ "$country" != ALL ] && local SRV_LIST=$(echo "$SRV_LIST" | grep -i ",${country},") 60 61 # array of list of VPN Gate servers for dialog 62 local SRV_LIST_FORMATTED=$(echo "$SRV_LIST" \ 63 | awk -F',' -vOFS=',' '{print $3, $4, $5, $6}' \ 64 | awk -F',' -vOFS=',' '{ 65 tmp_score="echo "$1" | numfmt --to=si" 66 tmp_speed="echo "$3" | numfmt --to=iec-i --suffix=B/s --format=\"%.1f\"" 67 tmp_score | getline score 68 tmp_speed | getline speed 69 $1=score 70 $3=speed 71 print 72 }' 73 ) 74 75 let i=0 76 local W=("N" "Score Ping Speed Country") 77 while read -r line; do 78 let i=$i+1 79 W+=($i "$line") 80 done < <(echo "$SRV_LIST_FORMATTED" | column -s',' -t -R1,2,3) 81 82 # select server and save ovpn files 83 NUM=$(dialog \ 84 --title "List of VPN Gate servers ($country)" \ 85 --default-item "$NUM" \ 86 --menu "Choose to save ovpn file" 40 60 17 "${W[@]}" 3>&2 2>&1 1>&3) 87 if [ -z "$NUM" ]; then 88 clear 89 exit 0 90 else 91 if [ $NUM = "N" ]; then 92 unset country 93 else 94 local SRV_INFO=$(echo "$SRV_LIST" | sed -n "${NUM}p") 95 IFS=, read HostName IP Score Ping Speed CountryLong CountryShort Other <<<"$(echo $SRV_INFO)" 96 local OVPN="vpngate_${CountryShort,,}_${HostName}.ovpn" 97 dialog --yesno "Save file to \"${OVPN}\"?" 6 40 98 [ $? = 0 ] && echo "$SRV_INFO" | awk -F',' '{print $15}' | base64 -di >$OVPN 99 fi 100 fi 101} 102 103while true; do get_ovpn; done