@@ -44,10 +44,11 @@ echo -e "\n---- OpenVPN Configuration ----"
4444
4545# Create a new configuration file to modify so the original is left untouched.
4646config_file_modified=${config_file_original} .modified
47- cp $config_file_original $config_file_modified
4847
4948# These configuration file changes are required by Alpine.
50- echo " Making required changes to the configuration file."
49+ echo " Creating $config_file_modified and making required changes to that file."
50+ cp $config_file_original $config_file_modified
51+
5152sed -i \
5253 -e ' /up /c up \/etc\/openvpn\/up.sh' \
5354 -e ' /down /c down \/etc\/openvpn\/down.sh' \
@@ -79,8 +80,7 @@ if [ $KILL_SWITCH = "on" ]; then
7980 echo " Creating VPN kill switch and local routes."
8081
8182 echo " Allowing established and related connections..."
82- iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
83- iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
83+ iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
8484
8585 echo " Allowing loopback connections..."
8686 iptables -A INPUT -i lo -j ACCEPT
@@ -110,7 +110,7 @@ if [ $KILL_SWITCH = "on" ]; then
110110 domain=$( echo " $line " | cut -d " " -f 1)
111111 port=$( echo " $line " | cut -d " " -f 2)
112112 proto=$( echo " $line " | cut -d " " -f 3 | cut -c1-3)
113- for ip in $( nslookup $domain localhost | tail -n +4 | grep -Eo ' \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} ' | sort | uniq ) ; do
113+ for ip in $( dig -4 +short $domain ) ; do
114114 echo " $domain (IP:$ip PORT:$port )"
115115 iptables -A OUTPUT -o eth0 -d $ip -p ${proto:- $remote_proto } --dport ${port:- $remote_port } -j ACCEPT
116116 done
@@ -142,8 +142,10 @@ else
142142fi
143143
144144if [ " $SHADOWSOCKS " = " on" ]; then
145+ # https://www.gnu.org/software/bash/manual/html_node/Command-Grouping.html
145146 {
146147 echo " [INFO] Running Shadowsocks"
148+ # Wait for VPN connection to be established
147149 while ! ping -c 1 1.1.1.1 > /dev/null 2>&1 ; do
148150 sleep 1
149151 done
@@ -159,11 +161,9 @@ if [ "$SHADOWSOCKS" = "on" ]; then
159161fi
160162
161163if [ " $TINYPROXY " = " on" ]; then
162- # start list of commands to run Tinyproxy
163164 # https://www.gnu.org/software/bash/manual/html_node/Command-Grouping.html
164165 {
165166 echo " [INFO] Running Tinyproxy"
166- # Wait for VPN connection to be established
167167 while ! ping -c 1 1.1.1.1 > /dev/null 2>&1 ; do
168168 sleep 1
169169 done
@@ -184,7 +184,7 @@ if [ "$TINYPROXY" = "on" ]; then
184184 fi
185185
186186 sleep 1
187- tinyproxy -c /data/tinyproxy.conf &
187+ tinyproxy -c /data/tinyproxy.conf
188188 } &
189189fi
190190
@@ -193,4 +193,4 @@ echo "[INFO] Running OpenVPN"
193193openvpn --verb $vpn_log_level --auth-nocache --cd /data/vpn --config $config_file_modified &
194194
195195openvpn_child=$!
196- wait $openvpn_child
196+ wait $openvpn_child
0 commit comments