Skip to content

Commit

Permalink
use curly, small restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
binhex committed May 23, 2017
1 parent cd810af commit 8dc3bef
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MAINTAINER binhex
ADD build/root/*.sh /root/

# add bash script to run openvpn
ADD build/root/*.sh /root/
ADD run/root/*.sh /root/

# add bash script to run privoxy
ADD run/nobody/*.sh /home/nobody/
Expand Down
22 changes: 0 additions & 22 deletions run/root/checkvpnconn.sh

This file was deleted.

50 changes: 39 additions & 11 deletions run/root/getvpnextip.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,57 @@
#!/bin/bash

# ensure we have connectivity before attempting to detect external ip address
source /root/checkvpnconn.sh "google.com" "443"

# define name servers to connect to in order to get external ip address
pri_external_ip_ns="ns1.google.com"
sec_external_ip_ns="resolver1.opendns.com"
retry_count=30

# use dns query to get external ip address
external_ip="$(dig TXT +short o-o.myaddr.l.google.com @${pri_external_ip_ns} | tr -d '"')"
exit_code="${?}"
# remove previous run output file
rm -f /home/nobody/vpn_external_ip.txt

# if error then try secondary name server
if [[ "${exit_code}" != 0 ]]; then
while true; do

external_ip="$(dig +short myip.opendns.com @${sec_external_ip_ns})"
external_ip="$(dig TXT +short o-o.myaddr.l.google.com @${pri_external_ip_ns} | tr -d '"')"
exit_code="${?}"

# if error then try secondary name server
if [[ "${exit_code}" != 0 ]]; then

external_ip="0.0.0.0"
echo "[warn] Failed to get external IP from Google NS, trying OpenDNS..."

external_ip="$(dig +short myip.opendns.com @${sec_external_ip_ns})"
exit_code="${?}"

if [[ "${exit_code}" != 0 ]]; then

if [ "${retry_count}" -eq "0" ]; then

external_ip="0.0.0.0"

echo "[warn] Cannot determine external IP address, exausted retries setting to ${external_ip}"
break

else

retry_count=$((retry_count-1))
sleep 1s

fi

else

echo "[info] Successfully retrieved external IP address ${external_ip}"
break

fi

else

echo "[info] Successfully retrieved external IP address ${external_ip}"
break

fi

fi
done

# write external ip address to text file, this is then read by the downloader script
echo "${external_ip}" > /home/nobody/vpn_external_ip.txt
18 changes: 11 additions & 7 deletions run/root/getvpnport.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/bin/bash

# statically assigned url for pia api (taken from pia script)
pia_api_host="209.222.18.222"
pia_api_port="2000"
pia_api_url="http://${pia_api_host}:${pia_api_port}"

# remove previous run output file
rm -f /home/nobody/vpn_incoming_port.txt

# check we are provider pia (note this env var is passed through to up script via openvpn --sentenv option)
if [[ "${VPN_PROV}" == "pia" ]]; then

# ensure we have connectivity before attempting to assign incoming port from pia api
source /root/checkvpnconn.sh "google.com" "443"

# statically assigned url for pia api (taken from pia script)
pia_api_host="209.222.18.222"
pia_api_port="2000"
pia_api_url="http://${pia_api_host}:${pia_api_port}"
# remove temp file from previous run
rm -f /tmp/VPN_INCOMING_PORT

# create pia client id (randomly generated)
client_id=$(head -n 100 /dev/urandom | sha256sum | tr -d " -")
Expand All @@ -26,6 +29,7 @@ if [[ "${VPN_PROV}" == "pia" ]]; then
else

echo "[debug] Successfully assigned incoming port ${VPN_INCOMING_PORT}"

fi

# write port number to text file, this is then read by the downloader script
Expand Down
3 changes: 0 additions & 3 deletions build/root/start.sh → run/root/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ else
echo "[warn] Unable to chown/chmod /config/openvpn, assuming SMB mountpoint"
fi

# remove file from previous run of getvpnport.sh
rm -rf /home/nobody/vpn_incoming_port.txt

# setup ip tables and routing for application
source /root/iptable.sh

Expand Down

0 comments on commit 8dc3bef

Please sign in to comment.