BarbossHack / RiseupVPN-OpenVPN

Bash script to generate OpenVPN config file for RiseupVPN
39 stars 10 forks source link

Fix for timeout issue with the generate.sh script #6

Closed x4740N closed 2 months ago

x4740N commented 2 months ago
#!/bin/bash

set -eu

# Verbose mode
if [ $# == 1 ] && [ "$1" == "-v" ]; then
    VERBOSE=1
    set -x
fi

OVPN_CONF=riseup-ovpn.conf

echo -e "\e[30mPlease wait, riseup API is slow...\e[0m"

# Download new VPN client certs (private and public keys)
# Orignal Timeout = 5
#key_cert=$(curl ${VERBOSE:+-v} -sS --fail --connect-timeout 10 --retry 5 https://api.black.riseup.net/3/cert)
#below command has timeout removed to solve timeout issue and silence removed to give visual feedback
key_cert=$(curl ${VERBOSE:+-v} --fail --retry 5 https://api.black.riseup.net/3/cert)

# Copy the sample openvpn conf
cp riseup-ovpn.sample.conf $OVPN_CONF
sed -i 's/^remote .*$//g' $OVPN_CONF
echo -e "\n<key>\n$key_cert\n</key>" >>$OVPN_CONF
echo -e "\n<cert>\n$key_cert\n</cert>" >>$OVPN_CONF

# Get the VPN IP list, and add them to openvpn conf
# Orignal Timeout = 5
#gateways=$(curl ${VERBOSE:+-v} -sS --fail --connect-timeout 10 --retry 5 https://api.black.riseup.net/3/config/eip-service.json | jq '.gateways')
#below command has timeout removed to solve timeout issue and silence removed to give visual feedback
gateways=$(curl ${VERBOSE:+-v} --fail --retry 5 https://api.black.riseup.net/3/config/eip-service.json | jq '.gateways')

for gateway_b64 in $(echo "$gateways" | jq -r '.[] | @base64'); do

    gateway=$(echo $gateway_b64 | base64 --decode)
    ip_address=$(echo $gateway | jq -r '.ip_address')
    host=$(echo $gateway | jq -r '.host')
    location=$(echo $gateway | jq -r '.location')
    ports=$(echo $gateway | jq -r '.capabilities.transport[] | select( .type | contains("openvpn")) | .ports[]')

    for port in $ports; do
        sed -i "/^remote-random$/i remote $ip_address $port # $host ($location)" $OVPN_CONF
    done
done

echo -e "\e[42m[+]\e[0m OpenVPN conf was created with success, you can now run:"
echo "sudo openvpn --config $OVPN_CONF"
BarbossHack commented 2 months ago

5 seconds for --connect-timeout is in fact already very huge, it's not the timeout of the whole request, it's only for the curl connection phase. The idea is to catch when riseup-vpn servers are down. But yeah I could raise it to 10s for people who have very very poor connection (or tunneling through many hopes).

For the silent option, if you run ./generate.sh -v it will enable verbose mode

BarbossHack commented 2 months ago

Fixed in https://github.com/BarbossHack/RiseupVPN-OpenVPN/commit/9ea6558f27998095eb79c6d68462a468e161f96c

x4740N commented 2 months ago

5 seconds for --connect-timeout is in fact already very huge, it's not the timeout of the whole request, it's only for the curl connection phase. The idea is to catch when riseup-vpn servers are down. But yeah I could raise it to 10s for people who have very very poor connection (or tunneling through many hopes).

For the silent option, if you run ./generate.sh -v it will enable verbose mode

Riseup's api is slower than a 5 second or 10 second timeout for me and testing so far with the timeout removed is consistently around 16 seconds from what curl reports if I'm remembering the time correctly

I don't have bad internet either, its just riseup's servers that take a bit longer

BarbossHack commented 2 months ago

Well, it's very weird, I've done a lot a tests since developing this script, and it always took less than 1-2 secs for the whole request :

image

In my tests, when it took longer, riseup servers were just down, it happened a few times in the past months

Are you using any other VPN or something else ? Or maybe it's your internet provider, or country...

Could you please run these 2 commands and post the outputs ?

time dig api.black.riseup.net
time curl https://api.black.riseup.net/3/cert >/dev/null