From 59c9f028af3e747dcaa6f7f42c9e7dbd0f0d1b10 Mon Sep 17 00:00:00 2001 From: Gauthier Delacroix Date: Tue, 16 Jul 2019 20:48:24 +0200 Subject: [PATCH] Fix/improve port forwarding handling --- portforward.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/portforward.sh b/portforward.sh index 821b41a0..b45a0a5d 100644 --- a/portforward.sh +++ b/portforward.sh @@ -24,15 +24,16 @@ port_file="/forwarded_port" echo "$port" > $port_file printf " * Written forwarded port to $port_file\n" ip=`wget -qO- https://diagnostic.opendns.com/myip` -exitOnError $? -printf " * Forwarded port is $port on remote IP $ip\n" +exitOnError $? "Unable to read remote VPN IP" +printf " * Forwarded port is $port on remote VPN IP $ip\n" printf " * Detecting target VPN interface..." TARGET_PATH="/openvpn/target" vpn_device=$(cat $TARGET_PATH/config.ovpn | grep 'dev ' | cut -d" " -f 2)0 -exitOnError $? +exitOnError $? "Unable to find VPN interface" printf "$vpn_device\n" printf " * Accepting input traffic through $vpn_device to port $port..." iptables -A INPUT -i $vpn_device -p tcp --dport $port -j ACCEPT +exitOnError $? "Unable to allow the forwarded port in TCP" iptables -A INPUT -i $vpn_device -p udp --dport $port -j ACCEPT -exitOnError $? +exitOnError $? "Unable to allow the forwarded port in UDP" printf "DONE\n"