Delay --up script execution until after TCP/UDP connection establishment with peer. Also add error handling with logging when PIA port response is empty, issue #220

This commit is contained in:
Kurs Developer 2017-04-02 21:31:17 +02:00
parent 9671707d1d
commit 0ba2a55cbb
2 changed files with 20 additions and 15 deletions

View File

@ -44,7 +44,7 @@ echo $TRANSMISSION_RPC_PASSWORD >> /config/transmission-credentials.txt
# Persist transmission settings for use by transmission-daemon
dockerize -template /etc/transmission/environment-variables.tmpl:/etc/transmission/environment-variables.sh /bin/true
TRANSMISSION_CONTROL_OPTS="--script-security 2 --up /etc/transmission/start.sh --down /etc/transmission/stop.sh"
TRANSMISSION_CONTROL_OPTS="--script-security 2 --up-delay --up /etc/transmission/start.sh --down /etc/transmission/stop.sh"
if [ -n "${LOCAL_NETWORK-}" ]; then
eval $(/sbin/ip r l m 0.0.0.0 | awk '{if($5!="tun0"){print "GW="$3"\nINT="$5; exit}}')

View File

@ -24,25 +24,30 @@ new_client_id() {
pia_client_id="$(cat $pia_client_id_file 2>/dev/null)"
if [ -z ${pia_client_id} ]; then
echo "Generating new client id for PIA"
pia_client_id=$(new_client_id)
echo "Generating new client id for PIA"
pia_client_id=$(new_client_id)
fi
# Get the port
port_assignment_url="http://209.222.18.222:2000/?client_id=$pia_client_id"
pia_response=$(curl -s -f $port_assignment_url)
pia_curl_exit_code=$?
if [ -z $pia_response ]; then
echo "Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding"
fi
# Check for curl error (curl will fail on HTTP errors with -f flag)
ret=$?
if [ $ret -ne 0 ]; then
echo "curl encountered an error looking up new port: $ret"
if [ $pia_curl_exit_code -ne 0 ]; then
echo "curl encountered an error looking up new port: $pia_curl_exit_code"
exit
fi
# Check for errors in PIA response
error=$(echo $pia_response | grep -oE "\"error\".*\"")
if [ ! -z "$error" ]; then
echo "PIA returned an error: $error"
exit
echo "PIA returned an error: $error"
exit
fi
# Get new port, check if empty
@ -61,9 +66,9 @@ echo "Got new port $new_port from PIA"
auth_enabled=$(grep 'rpc-authentication-required\"' $transmission_settings_file | grep -oE 'true|false')
if [ "true" = "$auth_enabled" ]
then
echo "transmission auth required"
myauth="--auth $transmission_username:$transmission_passwd"
else
echo "transmission auth required"
myauth="--auth $transmission_username:$transmission_passwd"
else
echo "transmission auth not required"
myauth=""
fi
@ -72,9 +77,9 @@ fi
transmission_peer_port=$(transmission-remote $myauth -si | grep Listenport | grep -oE '[0-9]+')
if [ "$new_port" != "$transmission_peer_port" ]
then
transmission-remote $myauth -p "$new_port"
echo "Checking port..."
sleep 10 && transmission-remote $myauth -pt
else
transmission-remote $myauth -p "$new_port"
echo "Checking port..."
sleep 10 && transmission-remote $myauth -pt
else
echo "No action needed, port hasn't changed"
fi