-
Notifications
You must be signed in to change notification settings - Fork 18
/
proxpn
executable file
·221 lines (198 loc) · 7.28 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
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/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 udp FREE requires a
# paid ProXPN account. The FREE udp 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=4.0.3
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
# Ensure that the CONF_FILE exists
declare OPENVPN_CONF
if [ -e "$CONF_BASE_PATH$CONF_FILE" ]; then
OPENVPN_CONF=$CONF_BASE_PATH$CONF_FILE
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
;;
-p|-proto|--proto)
shift
proto=$1
;;
*)
echo -e "Unknown option: $key \nUsage: proxpn [-r|-remote|--remote REMOTE_NAME] [-p|-proto|--proto PROTOCOL] [--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
}
PORT=443
declare -A PROTOCOLS
PROTOCOLS[tcp]=tcp
PROTOCOLS[udp]=udp
# Setup Single Exit Node array populated based on protocol chosen
declare -A EXIT_NODES
# IPs obtained from http://proxpn.com/updater/locations-v3.xml
declare -A TCP_EXIT_NODES
declare -A UDP_EXIT_NODES
TCP_EXIT_NODES[NYC]=196.52.17.0
TCP_EXIT_NODES[Miami]=192.240.98.3
TCP_EXIT_NODES[Seattle]=50.7.74.99
TCP_EXIT_NODES[Chicago]=50.7.1.243
TCP_EXIT_NODES[Toronto]=162.253.128.69
TCP_EXIT_NODES[Netherlands]=213.179.213.2
TCP_EXIT_NODES[Stockholm]=94.185.84.34
TCP_EXIT_NODES[London]=78.157.207.131
TCP_EXIT_NODES[Sydney]=45.32.241.118
TCP_EXIT_NODES[Frankfurt]=50.7.89.131
TCP_EXIT_NODES[Frankfurt2]=37.123.112.35
TCP_EXIT_NODES[SanJose]=179.48.248.104
UDP_EXIT_NODES[FREE]=196.52.21.65
UDP_EXIT_NODES[NYC]=196.52.16.2
UDP_EXIT_NODES[NYC2]=196.52.17.68
UDP_EXIT_NODES[Miami]=196.52.22.2
UDP_EXIT_NODES[Miami2]=196.52.23.66
UDP_EXIT_NODES[Seattle]=196.52.18.2
UDP_EXIT_NODES[Seattle2]=196.52.19.241
UDP_EXIT_NODES[Chicago]=50.7.1.67
UDP_EXIT_NODES[Chicago2]=196.52.21.225
UDP_EXIT_NODES[Toronto]=162.253.128.67
UDP_EXIT_NODES[HongKong]=43.251.159.25
UDP_EXIT_NODES[HongKong2]=103.194.43.131
UDP_EXIT_NODES[HongKong3]=103.194.43.26
UDP_EXIT_NODES[LA]=188.172.214.196
UDP_EXIT_NODES[Netherlands]=213.179.212.2
UDP_EXIT_NODES[Netherlands2]=213.179.208.146
UDP_EXIT_NODES[Stockholm]=94.185.84.42
UDP_EXIT_NODES[London]=78.157.207.139
UDP_EXIT_NODES[Bucharest]=89.46.102.14
UDP_EXIT_NODES[Sydney]=45.32.191.165
UDP_EXIT_NODES[Frankfurt]=50.7.88.172
UDP_EXIT_NODES[Frankfurt2]=37.123.112.69
UDP_EXIT_NODES[Frankfurt3]=185.41.141.171
UDP_EXIT_NODES[Paris]=151.236.21.12
UDP_EXIT_NODES[Singapore]=191.101.242.121
UDP_EXIT_NODES[SanJose]=179.48.248.105
UDP_EXIT_NODES[Hafnarfjordur]=37.235.49.195
UDP_EXIT_NODES[Zurich]=178.209.52.135
if [ ! ${proto} ]; then
echo -e "\nWhat protocol would you like to connect with? \nGenerally, TCP is the best choice on networks prone to packet loss.\nBe advised if you don't have a paid account, you can only use the FREE UDP exit node."
PS3="Select a protocol to use for this connection (1-${#PROTOCOLS[@]}): "
select PROTOCOL in ${PROTOCOLS[@]};
do
proto=$PROTOCOL
break
done
fi
# If the provided or selected protocol is unknown throw an error
if [ ! ${PROTOCOLS[$proto]} ]; then
echo "ERROR: Sorry, the protocol \"$proto\" you're trying to use is not known. Matching is case sensitive and only tcp or udp are supported."
exit 1
elif [ $proto = 'tcp' ]; then
for i in ${!TCP_EXIT_NODES[@]}; do
EXIT_NODES[$i]="${TCP_EXIT_NODES[$i]}"
done
else
for i in ${!UDP_EXIT_NODES[@]}; do
EXIT_NODES[$i]="${UDP_EXIT_NODES[$i]}"
done
fi
# 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]}
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 $proto --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