Advertisement
flabberghast

Untitled

Mar 24th, 2023 (edited)
1,089
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 1 0
  1. PIA_USER="pXXXXX"
  2. PIA_PASS="xxxxxx"
  3. PUB_KEY="xxxxxx="
  4. PRIV_KEY="xxxxxx="
  5. #select region from list
  6. #curl -s "https://serverlist.piaservers.net/vpninfo/servers/v6" | head -1 | jq -r '.regions[] | "Name: \(.name) ID: \(.id)"' | sort
  7. selectedRegion="swiss"
  8. VPN_IF="wg0_pia"
  9.  
  10. ifdown ${VPN_IF}
  11.  
  12. serverlist_url='https://serverlist.piaservers.net/vpninfo/servers/v6'
  13. # Get all region data
  14. all_region_data=$(curl -s "$serverlist_url" | head -1)
  15. regionData="$( echo "$all_region_data" |
  16. jq --arg REGION_ID "$selectedRegion" -r \
  17. '.regions[] | select(.id==$REGION_ID)')"
  18.  
  19. WG_SERVER_IP=$(echo "$regionData" | jq -r '.servers.wg[0].ip')
  20. WG_HOSTNAME=$(echo "$regionData" | jq -r '.servers.wg[0].cn')
  21.  
  22. echo $WG_SERVER_IP
  23. echo $WG_HOSTNAME
  24.  
  25. TOKEN_RES=`wget -O - --post-data="username=$PIA_USER&password=$PIA_PASS" https://www.privateinternetaccess.com/api/client/v2/token`
  26. TOKEN=`echo $TOKEN_RES | jq -r '.token'`
  27.  
  28. echo "$TOKEN"
  29. echo "${#TOKEN}"
  30.  
  31. if [ ${#TOKEN} != 128 ]; then
  32. echo "Couldn't get token"
  33. exit
  34. else
  35. echo "Got token"
  36. fi
  37.  
  38. wireguard_json=`curl -k -G --data-urlencode "pt=${TOKEN}" --data-urlencode "pubkey=$PUB_KEY" "https://${WG_SERVER_IP}:1337/addKey"`
  39.  
  40. echo $wireguard_json
  41.  
  42. dnsServer=$(echo "$wireguard_json" | jq -r '.dns_servers[0]')
  43. dnsSettingForVPN="DNS = $dnsServer"
  44.  
  45. VPN_ADDR=$(echo "$wireguard_json" | jq -r '.peer_ip')
  46. VPN_PORT=$(echo "$wireguard_json" | jq -r '.server_port')
  47. VPN_PUB=$(echo "$wireguard_json" | jq -r '.server_key')
  48.  
  49. uci set network.${VPN_IF}.addresses="${VPN_ADDR}"
  50. uci set network.@wireguard_wg0_pia[0].endpoint_host="${WG_SERVER_IP}"
  51. uci set network.@wireguard_wg0_pia[0].endpoint_port="${VPN_PORT}"
  52. uci set network.@wireguard_wg0_pia[0].public_key="${VPN_PUB}"
  53. uci commit
  54. ifdown ${VPN_IF}
  55. ifup ${VPN_IF}
  56.  
  57.  
  58.  
  59. echo "
  60. [Interface]
  61. Address = $(echo "$wireguard_json" | jq -r '.peer_ip')
  62. PrivateKey = $PRIV_KEY
  63. $dnsSettingForVPN
  64. [Peer]
  65. PersistentKeepalive = 25
  66. PublicKey = $(echo "$wireguard_json" | jq -r '.server_key')
  67. AllowedIPs = 0.0.0.0/0
  68. Endpoint = ${WG_SERVER_IP}:$(echo "$wireguard_json" | jq -r '.server_port')
  69. "
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement