Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #36 from peterisr/fix-reading-port-and-proto-from-…
Browse files Browse the repository at this point in the history
…conf

Fix iptables rules in case default OpenVPN port or proto is used.
  • Loading branch information
wfg authored Oct 29, 2021
2 parents f2a5eef + 8f5d3cd commit 5f62e9d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions data/scripts/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,18 @@ if [ "$KILL_SWITCH" = "on" ]; then
# strip any comments from line that could mess up cuts
clean_line=${line%% #*}
addr=$(echo "$clean_line" | cut -d " " -f 1)
port=$(echo "$clean_line" | cut -d " " -f 2)
proto=$(echo "$clean_line" | cut -d " " -f 3 | cut -c1-3)
port=$(echo "$clean_line" | cut -s -d " " -f 2)
proto=$(echo "$clean_line" | cut -s -d " " -f 3 | cut -c1-3)
port=${port:-${remote_port:-1194}}
proto=${proto:-${remote_proto:-udp}}

if is_ip "$addr"; then
echo " IP: $addr PORT: $port"
iptables -A OUTPUT -o eth0 -d "$addr" -p "${proto:-$remote_proto}" --dport "${port:-$remote_port}" -j ACCEPT
echo " IP: $addr PORT: $port PROTO: $proto"
iptables -A OUTPUT -o eth0 -d "$addr" -p "${proto}" --dport "${port}" -j ACCEPT
else
for ip in $(dig -4 +short "$addr"); do
echo " $addr (IP: $ip PORT: $port)"
iptables -A OUTPUT -o eth0 -d "$ip" -p "${proto:-$remote_proto}" --dport "${port:-$remote_port}" -j ACCEPT
echo " $addr (IP: $ip PORT: $port PROTO: $proto)"
iptables -A OUTPUT -o eth0 -d "$ip" -p "${proto}" --dport "${port}" -j ACCEPT
done
fi
done
Expand Down

0 comments on commit 5f62e9d

Please sign in to comment.