Line 0
Link Here
|
|
|
1 |
--- protonvpn-cli.sh.orig 2018-11-05 20:42:22 UTC |
2 |
+++ protonvpn-cli.sh |
3 |
@@ -17,63 +17,6 @@ if [[ ("$UID" != 0) && ("$1" != "ip") && ("$1" != "-ip |
4 |
exit 1 |
5 |
fi |
6 |
|
7 |
-function check_requirements() { |
8 |
- if [[ -z $(which openvpn) ]]; then |
9 |
- echo "[!] Error: openvpn is not installed. Install \`openvpn\` package to continue." |
10 |
- exit 1 |
11 |
- fi |
12 |
- |
13 |
- if [[ ! -z $(which python) ]]; then |
14 |
- python=$(which python) |
15 |
- elif [[ ! -z $(which python3) ]]; then |
16 |
- python=$(which python3) |
17 |
- elif [[ ! -z $(which python2) ]]; then |
18 |
- python=$(which python2) |
19 |
- fi |
20 |
- |
21 |
- if [[ -z "$python" ]]; then |
22 |
- echo "[!] Error: python is not installed. Install \`python\` package to continue." |
23 |
- exit 1 |
24 |
- fi |
25 |
- |
26 |
- if [[ -z $(which dialog) ]]; then |
27 |
- echo "[!] Error: dialog is not installed. Install \`dialog\` package to continue." |
28 |
- exit 1 |
29 |
- fi |
30 |
- if [[ -z $(which wget) ]]; then |
31 |
- echo "[!] Error: wget is not installed. Install \`wget\` package to continue." |
32 |
- exit 1 |
33 |
- fi |
34 |
- |
35 |
- if [[ -z $(which sysctl) && ( $(detect_platform_type) != "Mac" ) ]]; then |
36 |
- echo "[!] Error: sysctl is not installed. Install \`sysctl\` package to continue." |
37 |
- exit 1 |
38 |
- fi |
39 |
- |
40 |
- if [[ $(detect_platform_type) == "Linux" ]]; then |
41 |
- if [[ ( -z $(which iptables) ) || ( -z $(which iptables-save) ) || ( -z $(which iptables-restore) ) ]]; then |
42 |
- echo "[!] Error: iptables is not installed. Install \`iptables\` package to continue." |
43 |
- exit 1 |
44 |
- fi |
45 |
- fi |
46 |
- |
47 |
- sha512sum_func |
48 |
- if [[ -z "$sha512sum_tool" ]]; then |
49 |
- echo "[!] Error: sha512sum is not installed. Install \`sha512sum\` package to continue." |
50 |
- exit 1 |
51 |
- fi |
52 |
- |
53 |
- if [[ (! -x "/etc/openvpn/update-resolv-conf") && ( $(detect_platform_type) != "MacOS") ]]; then |
54 |
- echo "[!] Error: update-resolv-conf is not installed." |
55 |
- read -p "Would you like protonvpn-cli to install update-resolv-conf? (y/N): " "user_confirm" |
56 |
- if [[ "$user_confirm" == "y" || "$user_confirm" == "Y" ]]; then |
57 |
- install_update_resolv_conf |
58 |
- else |
59 |
- exit 1 |
60 |
- fi |
61 |
- fi |
62 |
-} |
63 |
- |
64 |
function get_home() { |
65 |
if [[ -z "$SUDO_USER" ]]; then |
66 |
CURRENT_USER="$(whoami)" |
67 |
@@ -100,25 +43,6 @@ function get_protonvpn_cli_home() { |
68 |
echo "$(get_home)/.protonvpn-cli" |
69 |
} |
70 |
|
71 |
-function install_update_resolv_conf() { |
72 |
- if [[ ("$UID" != 0) ]]; then |
73 |
- echo "[!] Error: Installation requires root access." |
74 |
- exit 1 |
75 |
- fi |
76 |
- echo "[*] Installing update-resolv-conf..." |
77 |
- mkdir -p "/etc/openvpn/" |
78 |
- file_sha512sum="81cf5ed20ec2a2f47f970bb0185fffb3e719181240f2ca3187dbee1f4d102ce63ab048ffee9daa6b68c96ac59d1d86ad4de2b1cfaf77f1b1f1918d143e96a588" |
79 |
- wget "https://raw.githubusercontent.com/ProtonVPN/scripts/master/update-resolv-conf.sh" -O "/etc/openvpn/update-resolv-conf" |
80 |
- if [[ ($? == 0) && ($($sha512sum_tool "/etc/openvpn/update-resolv-conf" | cut -d " " -f1) == "$file_sha512sum") ]]; then |
81 |
- chmod +x "/etc/openvpn/update-resolv-conf" |
82 |
- echo "[*] Done." |
83 |
- else |
84 |
- echo "[!] Error installing update-resolv-conf." |
85 |
- rm -f "/etc/openvpn/update-resolv-conf" 2> /dev/null |
86 |
- exit 1 |
87 |
- fi |
88 |
-} |
89 |
- |
90 |
function check_ip() { |
91 |
counter=0 |
92 |
ip="" |
93 |
@@ -222,15 +146,7 @@ function init_cli() { |
94 |
} |
95 |
|
96 |
function detect_platform_type() { |
97 |
- unameOut="$(uname -s)" |
98 |
- case "${unameOut}" in |
99 |
- Linux*) platform=Linux;; |
100 |
- Darwin*) platform=MacOS;; |
101 |
- CYGWIN*) platform=Linux;; |
102 |
- MINGW*) platform=Linux;; |
103 |
- *) platform=Linux |
104 |
- esac |
105 |
- echo "$platform" |
106 |
+ echo "FreeBSD" |
107 |
} |
108 |
|
109 |
function manage_ipv6() { |
110 |
@@ -501,7 +417,8 @@ function openvpn_connect() { |
111 |
--header 'Accept: application/vnd.protonmail.v1+json' \ |
112 |
-o /dev/null \ |
113 |
--timeout 10 --tries 1 -q -O "$openvpn_config" \ |
114 |
- "https://api.protonmail.ch/vpn/config?Platform=$(detect_platform_type)&LogicalID=$config_id&Protocol=$selected_protocol" |
115 |
+ "https://api.protonmail.ch/vpn/config?Platform=Linux&LogicalID=$config_id&Protocol=$selected_protocol" && \ |
116 |
+ sed -i '' s,/etc/openvpn/update-resolv-conf,%%LOCALBASE%%/etc/openvpn/update-resolv-conf, "$openvpn_config" |
117 |
|
118 |
echo "Connecting..." |
119 |
|
120 |
@@ -573,102 +490,6 @@ function openvpn_connect() { |
121 |
exit $status_exit |
122 |
} |
123 |
|
124 |
-function update_cli() { |
125 |
- check_if_internet_is_working_normally |
126 |
- |
127 |
- cli_path="/usr/local/bin/protonvpn-cli" |
128 |
- if [[ ! -f "$cli_path" ]]; then |
129 |
- echo "[!] Error: protonvpn-cli does not seem to be installed." |
130 |
- exit 1 |
131 |
- fi |
132 |
- echo "[#] Checking for update..." |
133 |
- current_local_hashsum=$($sha512sum_tool "$cli_path" | cut -d " " -f1) |
134 |
- remote_=$(wget --timeout 6 -o /dev/null -q -O - 'https://raw.githubusercontent.com/ProtonVPN/protonvpn-cli/master/protonvpn-cli.sh') |
135 |
- if [[ $? != 0 ]]; then |
136 |
- echo "[!] Error: There is an error updating protonvpn-cli." |
137 |
- exit 1 |
138 |
- fi |
139 |
- remote_hashsum=$(echo "$remote_" | $sha512sum_tool | cut -d ' ' -f1) |
140 |
- |
141 |
- if [[ "$current_local_hashsum" == "$remote_hashsum" ]]; then |
142 |
- echo "[*] protonvpn-cli is up-to-date!" |
143 |
- exit 0 |
144 |
- else |
145 |
- echo "[#] A new update is available." |
146 |
- echo "[#] Updating..." |
147 |
- wget -q --timeout 20 -O "$cli_path" 'https://raw.githubusercontent.com/ProtonVPN/protonvpn-cli/master/protonvpn-cli.sh' |
148 |
- if [[ $? == 0 ]]; then |
149 |
- echo "[#] protonvpn-cli has been updated successfully." |
150 |
- exit 0 |
151 |
- else |
152 |
- echo "[!] Error: There is an error updating protonvpn-cli." |
153 |
- exit 1 |
154 |
- fi |
155 |
- fi |
156 |
-} |
157 |
- |
158 |
-function install_cli() { |
159 |
- mkdir -p "/usr/bin/" "/usr/local/bin/" |
160 |
- cli="$(cd "$(dirname "$0")" && pwd -P)/$(basename "$0")" |
161 |
- errors_counter=0 |
162 |
- cp "$cli" "/usr/local/bin/protonvpn-cli" &> /dev/null |
163 |
- if [[ $? != 0 ]]; then errors_counter=$((errors_counter+1)); fi |
164 |
- |
165 |
- ln -s -f "/usr/local/bin/protonvpn-cli" "/usr/local/bin/pvpn" &> /dev/null |
166 |
- if [[ $? != 0 ]]; then errors_counter=$((errors_counter+1)); fi |
167 |
- |
168 |
- ln -s -f "/usr/local/bin/protonvpn-cli" "/usr/bin/protonvpn-cli" &> /dev/null |
169 |
- if [[ $? != 0 ]]; then errors_counter=$((errors_counter+1)); fi |
170 |
- |
171 |
- ln -s -f "/usr/local/bin/protonvpn-cli" "/usr/bin/pvpn" &> /dev/null |
172 |
- if [[ $? != 0 ]]; then errors_counter=$((errors_counter+1)); fi |
173 |
- |
174 |
- chown "$USER:$(id -gn $USER)" "/usr/local/bin/protonvpn-cli" "/usr/local/bin/pvpn" "/usr/bin/protonvpn-cli" "/usr/bin/pvpn" &> /dev/null |
175 |
- if [[ $? != 0 ]]; then errors_counter=$((errors_counter+1)); fi |
176 |
- |
177 |
- chmod 0755 "/usr/local/bin/protonvpn-cli" "/usr/local/bin/pvpn" "/usr/bin/protonvpn-cli" "/usr/bin/pvpn" &> /dev/null |
178 |
- if [[ $? != 0 ]]; then errors_counter=$((errors_counter+1)); fi |
179 |
- |
180 |
- if [[ ($errors_counter == 0) || ( ! -z $(which protonvpn-cli) ) ]]; then |
181 |
- echo "[*] Done." |
182 |
- exit 0 |
183 |
- else |
184 |
- echo "[!] Error: There was an error in installing protonvpn-cli." |
185 |
- exit 1 |
186 |
- fi |
187 |
-} |
188 |
- |
189 |
-function uninstall_cli() { |
190 |
- |
191 |
- if [[ $(is_openvpn_currently_running) == true ]]; then |
192 |
- echo "[!] OpenVPN is currently running." |
193 |
- echo "[!] Session will be disconnected." |
194 |
- openvpn_disconnect quiet dont_exit |
195 |
- if [[ $(is_openvpn_currently_running) == true ]]; then # Checking if OpenVPN is still active. |
196 |
- echo "[!] Error disconnecting OpenVPN." |
197 |
- echo "[!] Please disconnect manually and try the uninstallation again." |
198 |
- exit 1 |
199 |
- else |
200 |
- echo "[#] Disconnected." |
201 |
- fi |
202 |
- fi |
203 |
- |
204 |
- errors_counter=0 |
205 |
- rm -f "/usr/local/bin/protonvpn-cli" "/usr/local/bin/pvpn" "/usr/bin/protonvpn-cli" "/usr/bin/pvpn" &> /dev/null |
206 |
- if [[ $? != 0 ]]; then errors_counter=$((errors_counter+1)); fi |
207 |
- |
208 |
- rm -rf "$(get_protonvpn_cli_home)/" &> /dev/null |
209 |
- if [[ $? != 0 ]]; then errors_counter=$((errors_counter+1)); fi |
210 |
- |
211 |
- if [[ ($errors_counter == 0) || ( $(which protonvpn-cli) == "" ) ]]; then |
212 |
- echo "[*] Done." |
213 |
- exit 0 |
214 |
- else |
215 |
- echo "[!] Error: There was an error in uninstalling protonvpn-cli." |
216 |
- exit 1 |
217 |
- fi |
218 |
-} |
219 |
- |
220 |
function print_console_status() { |
221 |
current_ip="$(check_ip)" |
222 |
if [[ $(is_openvpn_currently_running) == true ]]; then |
223 |
@@ -1246,6 +1067,18 @@ function get_countries_server_list() { |
224 |
response_cache_path="$(get_protonvpn_cli_home)/.response_cache" |
225 |
tier=$(cat "$(get_protonvpn_cli_home)/protonvpn_tier") |
226 |
|
227 |
+ country_id=$1 |
228 |
+ if [[ $tier -eq 0 ]] |
229 |
+ then |
230 |
+ if [[ $1 -eq 1 ]] |
231 |
+ then |
232 |
+ country_id=6 |
233 |
+ elif [[ $1 -eq 2 ]] |
234 |
+ then |
235 |
+ country_id=7 |
236 |
+ fi |
237 |
+ fi |
238 |
+ |
239 |
output=`$python <<END |
240 |
import json |
241 |
response_cache = open("""$response_cache_path""", "r").read() |
242 |
@@ -1263,7 +1096,7 @@ for _ in output: |
243 |
countries.append(_['EntryCountry']) |
244 |
|
245 |
for i, country in enumerate(countries): |
246 |
- if str(i+1) == """$1""": |
247 |
+ if str(i+1) == """$country_id""": |
248 |
selected_country = country |
249 |
|
250 |
best_server = "" |
251 |
@@ -1536,9 +1369,6 @@ function help_message() { |
252 |
echo " --reconnect Reconnect to the current ProtonVPN server." |
253 |
echo " --ip Print the current public IP address." |
254 |
echo " --status Print connection status." |
255 |
- echo " --update Update protonvpn-cli." |
256 |
- echo " --install Install protonvpn-cli." |
257 |
- echo " --uninstall Uninstall protonvpn-cli." |
258 |
echo " -v, --version Display version." |
259 |
echo " -h, --help Show this help message." |
260 |
echo |
261 |
@@ -1546,7 +1376,6 @@ function help_message() { |
262 |
exit 0 |
263 |
} |
264 |
|
265 |
-check_requirements |
266 |
user_input="$1" |
267 |
case $user_input in |
268 |
""|"-h"|"--help"|"--h"|"-help"|"help") help_message |
269 |
@@ -1589,13 +1418,7 @@ case $user_input in |
270 |
;; |
271 |
"status"|"-status"|"--status") print_console_status |
272 |
;; |
273 |
- "update"|"-update"|"--update") update_cli |
274 |
- ;; |
275 |
"-init"|"--init") init_cli |
276 |
- ;; |
277 |
- "-install"|"--install") install_cli |
278 |
- ;; |
279 |
- "-uninstall"|"--uninstall") uninstall_cli |
280 |
;; |
281 |
*) |
282 |
echo "[!] Invalid input: $user_input" |