2019-06-26 17:24:10 +02:00
#!/bin/sh
2019-06-29 13:42:44 +02:00
exitOnError( ) {
# $1 must be set to $?
status = $1
message = $2
[ " $message " != "" ] || message = "Undefined error"
if [ $status != 0 ] ; then
printf " [ERROR] $message , with status $status )\n "
exit $status
fi
}
2019-07-15 22:02:40 +02:00
printf "[INFO] Reading forwarded port\n"
2019-06-26 17:24:10 +02:00
client_id = ` head -n 100 /dev/urandom | sha256sum | tr -d " -" `
2019-07-16 20:44:12 +02:00
exitOnError $? "Unable to generate Client ID"
json = ` wget -qO- " http://209.222.18.222:2000/?client_id= $client_id " `
2019-06-26 17:24:10 +02:00
if [ " $json " = = "" ] ; then
2019-07-16 20:44:12 +02:00
printf " * Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding\n"
exit 1
2019-06-26 17:24:10 +02:00
fi
2019-07-15 22:02:40 +02:00
port = ` echo $json | jq .port`
port_file = "/forwarded_port"
echo " $port " > $port_file
printf " * Written forwarded port to $port_file \n "
2019-06-26 17:24:10 +02:00
ip = ` wget -qO- https://diagnostic.opendns.com/myip`
2019-06-29 13:42:44 +02:00
exitOnError $?
2019-07-16 20:44:12 +02:00
printf " * Forwarded port is $port on remote IP $ip \n "
2019-07-15 22:02:40 +02:00
printf " * Detecting target VPN interface..."
2019-06-29 13:42:44 +02:00
TARGET_PATH = "/openvpn/target"
vpn_device = $( cat $TARGET_PATH /config.ovpn | grep 'dev ' | cut -d" " -f 2) 0
exitOnError $?
printf " $vpn_device \n "
2019-07-15 22:02:40 +02:00
printf " * Accepting input traffic through $vpn_device to port $port ... "
iptables -A INPUT -i $vpn_device -p tcp --dport $port -j ACCEPT
iptables -A INPUT -i $vpn_device -p udp --dport $port -j ACCEPT
2019-06-29 13:42:44 +02:00
exitOnError $?
printf "DONE\n"