Skip to content

Commit

Permalink
Support for the client to declare itself
Browse files Browse the repository at this point in the history
* Introduces support for the client to declare itself as ProtonVPN Linux
  Community client.

Signed-off-by: Samuele Kaplun <[email protected]>
  • Loading branch information
kaplun committed Dec 3, 2020
1 parent dd0aab7 commit 81dfeec
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Table of Contents

- [v2.2.5](#v225)
- [v2.2.4](#v224)
- [v2.2.3](#v223)
- [v2.2.2](#v222)
Expand All @@ -13,6 +14,10 @@
- [v2.0.0](#v200)
- [v0.1.0](#v010)

## v2.2.5

- Enhancement: Introduces support for the client to declare itself

## v2.2.4

- Bug fix: Failing to connect when choosing a server via dialog menu
Expand Down
4 changes: 2 additions & 2 deletions protonvpn_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
)
# Constants
from .constants import (
CONFIG_DIR, CONFIG_FILE, PASSFILE, USER, VERSION, SPLIT_TUNNEL_FILE
CONFIG_DIR, CONFIG_FILE, PASSFILE, USER, VERSION, SPLIT_TUNNEL_FILE, CLIENT_SUFFIX
)


Expand Down Expand Up @@ -256,7 +256,7 @@ def init_config_file():
set_config_value("USER", "killswitch", 0)

with open(PASSFILE, "w") as f:
f.write("{0}\n{1}".format(ovpn_username, ovpn_password))
f.write("{0}+{1}\n{2}".format(ovpn_username, CLIENT_SUFFIX, ovpn_password))
logger.debug("Passfile created")
os.chmod(PASSFILE, 0o600)

Expand Down
6 changes: 4 additions & 2 deletions protonvpn_cli/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
set_config_value, get_ip_info, get_country_name,
get_fastest_server, check_update, get_default_nic,
get_transferred_data, create_openvpn_config,
is_ipv6_disabled
is_ipv6_disabled, patch_passfile
)
# Constants
from .constants import (
CONFIG_DIR, OVPN_FILE, PASSFILE, CONFIG_FILE
CONFIG_DIR, OVPN_FILE, PASSFILE, CONFIG_FILE, CLIENT_SUFFIX
)


Expand Down Expand Up @@ -459,6 +459,8 @@ def openvpn_connect(servername, protocol):

print("Connecting to {0} via {1}...".format(servername, protocol.upper()))

patch_passfile(PASSFILE)

with open(os.path.join(CONFIG_DIR, "ovpn.log"), "w+") as f:
subprocess.Popen(
[
Expand Down
3 changes: 2 additions & 1 deletion protonvpn_cli/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
SPLIT_TUNNEL_FILE = os.path.join(CONFIG_DIR, "split_tunnel.txt")
OVPN_FILE = os.path.join(CONFIG_DIR, "connect.ovpn")
PASSFILE = os.path.join(CONFIG_DIR, "pvpnpass")
VERSION = "2.2.4"
CLIENT_SUFFIX = "plc" # ProtonVPN Linux Community
VERSION = "2.2.5"
13 changes: 12 additions & 1 deletion protonvpn_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Constants
from .constants import (
USER, CONFIG_FILE, SERVER_INFO_FILE, SPLIT_TUNNEL_FILE,
VERSION, OVPN_FILE
VERSION, OVPN_FILE, CLIENT_SUFFIX
)


Expand Down Expand Up @@ -521,3 +521,14 @@ def convert_size(size_bytes):
rx_bytes = int(f.read())

return convert_size(tx_bytes), convert_size(rx_bytes)


def patch_passfile(passfile):
with open(passfile, "r") as f:
ovpn_username = f.readline()
ovpn_password = f.readline()
if CLIENT_SUFFIX not in ovpn_username.strip().split('+')[1:]:
# Let's append the CLIENT_SUFFIX
with open(passfile, "w") as f:
f.write("{0}+{1}\n{2}".format(ovpn_username.strip(), CLIENT_SUFFIX, ovpn_password))
os.chmod(passfile, 0o600)

0 comments on commit 81dfeec

Please sign in to comment.