forked from MattSurabian/proxpn-bash-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxpn
executable file
·208 lines (187 loc) · 7.1 KB
/
proxpn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env bash
# ProXPN OpenVPN Bash Client
# @see: https://github.com/MattSurabian/proxpn-bash-client/
#
# If you want to use ProXPN's service but don't want to or are unable
# to install their software, this script might be what you need.
# This script relies on an OpenVPN configuration file which can be
# extracted from ProXPNs software.
#
# Use of this script for any exit nodes other than BASIC requires a
# paid ProXPN account. The BASIC endpoint is rate limited, and a
# paid subscription is relatively cheap.
#
# Because this command runs a VPN for all your traffic you'll have to
# run it using sudo. If it is not run with sudo it will automatically use
# dry-run mode.
VERSION=3.0.0
echo -e "\nWelcome to the ProXPN OpenVPN Bash Client!"
OPENVPN=`which openvpn`
if $OPENVPN > /dev/null; then
echo -e "\nOpenVPN not found! It must be installed before proceeding\n"
exit 1
fi
# The recommendation is to write the ovpn file and other configuration
# information to ~/.config/proxpn/ since this script needs to be run as
# sudo in order to work we need to eval the home directory of the actual user
# without this check ~ would resolve to /root
CONF_BASE_PATH=$(eval echo ~$SUDO_USER)/.config/proxpn/
CONF_FILE=proxpn.ovpn
CONF_FILE_UDP=proxpn-udp.ovpn
# Ensure that the CONF_FILE exists
declare OPENVPN_CONF
if [ -e "$CONF_BASE_PATH$CONF_FILE" ]; then
OPENVPN_CONF=$CONF_BASE_PATH$CONF_FILE
# This udp derived config does not have to exist as it'll be created
# if needed
OPENVPN_CONF_UDP=$CONF_BASE_PATH$CONF_FILE_UDP
else
echo "ERROR: No OpenVPN configuration file found at $CONF_BASE_PATH$CONF_FILE!"
exit 1
fi
# By default the user will be prompted for their ProXPN username and password by
# OpenVPN. To avoid being prompted, an auth file containing two lines with the username
# on the first line and the password on the second line can be created. The
# recommendation is to call this file login.conf and store it in $CONF_BASE_PATH.
# If this file is not found, it will not be used and the user will be prompted
# for login credentials.
CREDS_FILE=login.conf
declare AUTH_CREDS
if [ -e "$CONF_BASE_PATH$CREDS_FILE" ]; then
AUTH_CREDS=$CONF_BASE_PATH$CREDS_FILE
else
echo "No credentials file found at $CONF_BASE_PATH$CREDS_FILE, you will be prompted by OpenVPN to login to ProXPN"
fi
# By default automatically connect to ProXPN when running this script
dryRun=false
dryRunExitCode=0
# Check for flags
while [[ $# > 0 ]]; do
key="$1"
case $key in
-v|-version|--version)
echo -e "Version: $VERSION\n"
exit
;;
-dry-run|--dry-run)
dryRun=true
dryRunExitCode=0
echo -e "-dry-run mode active, you will not be automatically connected."
;;
-r|-remote|--remote)
shift
remoteName=$1
;;
*)
echo -e "Unknown option: $key \nUsage: proxpn [-r|-remote|--remote REMOTE_NAME] [--dry-run|-dry-run]\n"
exit 1
;;
esac
shift # past argument or value
done
if [ $EUID != 0 -a $dryRun != true ]; then
echo "This script must be run as root in order to successfully apply network route configuration."
echo "Elevated permissions not detected, falling back to dry-run mode..."
dryRun=true
dryRunExitCode=1
fi
# Catch control-c signals to make sure we don't lose stty echo
# if we decide to prematurely quit the script.If stty echo is lost the user
# won't be able to see what they're typing into the terminal
# until reset or similar destructive command is issued. It will appear as
# if the shell is frozen or otherwise broken.
trap ctrl_c INT
function ctrl_c() {
stty echo
echo -e "\nProXPN OpenVPN Bash Client has been force quit. Goodbye.\n"
exit 1
}
# Both TCP and UDP configurations use port 443
PORT=443
# Hosts obtained from http://proxpn.com/updater/locations-v3.xml
# and http://proxpn.com/updater/locations-v2.xml
# Any of the following commented out nodes currently do not work with this script
declare -A EXIT_NODES
# EXIT_NODES[Dallas]=d1.proxpn.com
# EXIT_NODES[NYC]=ny1.proxpn.com
EXIT_NODES[Miami]=mfl1.proxpn.com
EXIT_NODES[Chicago]=chi1.proxpn.com
EXIT_NODES[Seattle]=se1.proxpn.com
EXIT_NODES[LA]=la1.proxpn.com
EXIT_NODES[Netherlands]=nl1.proxpn.com
# EXIT_NODES[Singapore]=sg1.proxpn.com
EXIT_NODES[London]=uk1.proxpn.com
EXIT_NODES[Prague]=cz1.proxpn.com
EXIT_NODES[Stockholm]=swe1.proxpn.com
EXIT_NODES[SanJose]=openvpn-cr.proxpn.com
# EXIT_NODES[Toronto]=tor1.proxpn.com
# EXIT_NODES[Montreal]=mtl1.proxpn.com
# EXIT_NODES[HongKong]=hk1.proxpn.com
# EXIT_NODES[Sydney]=au1.proxpn.com
# EXIT_NODES[Frankfurt]=de1.proxpn.com
# EXIT_NODES[NewDelhi]=ind1.proxpn.com
# EXIT_NODES[Tokyo]=jp1.proxpn.com
# EXIT_NODES[Bangkok]=th1.proxpn.com
# EXIT_NODES[Hafnarfjordur]=is1.proxpn.com
# EXIT_NODES[Zurich]=zch1.proxpn.com
# EXIT_NODES[Paris]=fr1.proxpn.com
# Tested/confirmed working UDP based exit nodes
# All IPs taken from locations-v3.xml
EXIT_NODES[Toronto]=162.253.128.67
EXIT_NODES[Bucharest]=89.46.102.14
#EXIT_NODES[Sydney]=108.61.184.22
EXIT_NODES[HongKong]=43.251.159.25
EXIT_NODES[Frankfurt]=50.7.88.172
EXIT_NODES[Frankfurt2]=37.123.112.69
EXIT_NODES[Paris]=151.236.21.12
EXIT_NODES[Singapore]=191.101.242.121
EXIT_NODES[Hafnarfjordur]=37.235.49.195
EXIT_NODES[Zurich]=178.209.52.135
EXIT_NODES[Netherlands2]=213.179.212.2
EXIT_NODES[Netherlands3]=213.179.208.146
# ProXPN basic account exit nodes actually send
# users to many geo locations so there's no reason
# to include the Dallas basic exit node too.
# If however, you prefer it: bd.proxpn.com
EXIT_NODES[BASIC]=bny1.proxpn.com
# If a remote wasn't set via flag then prompt the user to select
# an exit node to connect to.
if [ ! ${remoteName} ]; then
echo -e "\nWhich exit node would you like to use?"
PS3="Select an exit node (1-${#EXIT_NODES[@]}): "
select EXITNODE in ${!EXIT_NODES[@]};
do
remoteName=$EXITNODE
break
done
fi
# If the provided or selected exit node throw an error
if [ ${EXIT_NODES[$remoteName]} ]; then
remote=${EXIT_NODES[$remoteName]}
# This checks if we have an IP or a hostname with "proxpn" in it.
# If we have an IP address, use the UDP based configuration (and
# write it out if it doesn't exist yet)
hostname_count=$(echo $remote | grep -v grep | grep -c proxpn)
if [ $hostname_count -eq 0 ]; then
# If the udp configuration doesn't exist, copy the existing
# configuration, changing tcp to udp
if [ ! -f $OPENVPN_CONF_UDP ]; then
cat $OPENVPN_CONF | sed 's/proto tcp/proto udp/g' > $OPENVPN_CONF_UDP
fi
OPENVPN_CONF=$OPENVPN_CONF_UDP
fi
else
echo "ERROR: Sorry, the remote \"$remoteName\" you're trying to use is not known. Matching for the remote flag value is case sensitive."
exit 1
fi
# Store the command we're about to run in a variable and use the auth-nocache option
# to ensure OpenVPN doesn't attempt to cache auth information in memory
COMMAND="$OPENVPN --config $OPENVPN_CONF --remote $remote $PORT --auth-nocache --auth-user-pass $AUTH_CREDS"
# If we're in dry-run mode then print the command and exit
if [ $dryRun = true ]; then
echo -e "\nDry run complete!"
echo -e "Use following OpenVPN command to connect to ProXPN:\n$COMMAND\n"
exit $dryRunExitCode
fi
echo -e "\nRunning:\n$COMMAND\n"
$COMMAND