Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #11 from calexandru2018/testing
Browse files Browse the repository at this point in the history
Merging the implementation of a message dialog
  • Loading branch information
calexandru2018 authored Mar 4, 2020
2 parents 8420a35 + 650d30b commit 8a26742
Show file tree
Hide file tree
Showing 8 changed files with 651 additions and 209 deletions.
52 changes: 45 additions & 7 deletions custom_pvpn_cli_ng/protonvpn_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,19 @@ def purge_configuration(gui_enabled=False):
time.sleep(0.5)

connection.disconnect(passed=True)

if os.path.isdir(CONFIG_DIR):
shutil.rmtree(CONFIG_DIR)
print("Configuration purged.")

print("Configuration purged.")
if gui_enabled:
return "All your configurations were purged. Re-initilize your profile."

def set_username_password(write=False, gui_enabled=False, user_data=False):
"""Set the ProtonVPN Username and Password."""


return_message = 'Something went wrong.'
print()
if gui_enabled == True:
if gui_enabled:
ovpn_username, ovpn_password1 = user_data
else:
ovpn_username = input("Enter your ProtonVPN OpenVPN username: ")
Expand Down Expand Up @@ -417,17 +420,22 @@ def set_username_password(write=False, gui_enabled=False, user_data=False):
os.chmod(PASSFILE, 0o600)

print("Username and Password has been updated!")
return_message = "Username and Password has been updated!"

if gui_enabled:
return return_message
return ovpn_username, ovpn_password1


def set_protonvpn_tier(write=False, gui_enabled=False, tier=False):
"""Set the users ProtonVPN Plan."""

result_message = "Some error occured updating ProtonVPN plan."

protonvpn_plans = {1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary"}

print()
if gui_enabled == True:
if gui_enabled:
user_tier = tier
else:
print("Please choose your ProtonVPN Plan")
Expand Down Expand Up @@ -459,15 +467,20 @@ def set_protonvpn_tier(write=False, gui_enabled=False, tier=False):
set_config_value("USER", "tier", str(user_tier))

print("ProtonVPN Plan has been updated!")
result_message = "ProtonVPN Plan has been updated!\n\nServer list has been refreshed."

if gui_enabled:
return result_message
return user_tier


def set_default_protocol(write=False, gui_enabled=False, protoc=False):
"""Set the users default protocol"""

result_message = "Some error occured in updating default OpenVPN protocol..."

print()
if gui_enabled == True:
if gui_enabled:
user_protocol = protoc
else:
print(
Expand Down Expand Up @@ -504,13 +517,19 @@ def set_default_protocol(write=False, gui_enabled=False, protoc=False):
if write:
set_config_value("USER", "default_protocol", user_protocol)
print("Default protocol has been updated.")
result_message = "Default OpenVPN protocol has been updated."

if gui_enabled:
return result_message

return user_protocol


def set_dns_protection(gui_enabled=False, dns_settings=False):
"""Enable or disable DNS Leak Protection and custom DNS"""

result_message = 'Some error occured during DNS configuration.'

if gui_enabled == True:
dns_leak_protection, custom_dns = dns_settings
else:
Expand Down Expand Up @@ -569,10 +588,17 @@ def set_dns_protection(gui_enabled=False, dns_settings=False):
set_config_value("USER", "custom_dns", custom_dns)
print("DNS Management updated.")

result_message = "DNS settings updated."

if gui_enabled:
return result_message

def set_killswitch(gui_enabled=True, user_choice=False):
"""Enable or disable the Kill Switch."""

# result_message = "Error occured during update of killswitch configurations."
result_message = ""

if gui_enabled == True:
killswitch = user_choice
else:
Expand Down Expand Up @@ -622,22 +648,28 @@ def set_killswitch(gui_enabled=True, user_choice=False):
"[!] Split Tunneling has been disabled."
)
time.sleep(1)
result_message = "Kill Switch can't be used with Split Tunneling.\nSplit Tunneling has been disabled."

set_config_value("USER", "killswitch", killswitch)
print()
print("Kill Switch configuration updated.")

result_message = result_message + "Kill Switch configuration updated."
if gui_enabled:
return result_message

def set_split_tunnel(gui_enabled=False, user_data=False):
"""Enable or disable split tunneling"""

result_message = ''

print()

if gui_enabled == True:
if len(user_data) == 0:
set_config_value("USER", "split_tunnel", 0)
if os.path.isfile(SPLIT_TUNNEL_FILE):
os.remove(SPLIT_TUNNEL_FILE)
result_message = "Split tunneling disabled.\n\n"
else:
if int(get_config_value("USER", "killswitch")):
set_config_value("USER", "killswitch", 0)
Expand All @@ -646,6 +678,7 @@ def set_split_tunnel(gui_enabled=False, user_data=False):
"[!] Split Tunneling can't be used with Kill Switch.\n" +
"[!] Kill Switch has been disabled.\n"
)
result_message = "Split Tunneling can't be used with Kill Switch.\nKill Switch has been disabled.\n\n"
time.sleep(1)

set_config_value("USER", "split_tunnel", 1)
Expand All @@ -661,6 +694,7 @@ def set_split_tunnel(gui_enabled=False, user_data=False):
# split tunneling should be disabled again
logger.debug("No split tunneling file existing.")
set_config_value("USER", "split_tunnel", 0)
result_message = result_message + "No split tunneling file, split tunneling will be disabled.\n\n"
else:
user_choice = input("Enable split tunneling? [y/N]: ")

Expand Down Expand Up @@ -713,4 +747,8 @@ def set_split_tunnel(gui_enabled=False, user_data=False):

print()
print("Split tunneling configuration updated.")
result_message = result_message + "Split tunneling configuration updated."
make_ovpn_template()

if gui_enabled:
return result_message
30 changes: 24 additions & 6 deletions custom_pvpn_cli_ng/protonvpn_cli/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def show_dialog(headline, choices, stop=False):
openvpn_connect(server_result, protocol_result)


def random_c(protocol=None):
def random_c(protocol=None, gui_enabled=False):
"""Connect to a random ProtonVPN Server."""

logger.debug("Starting random connect")
Expand All @@ -136,6 +136,8 @@ def random_c(protocol=None):

servername = random.choice(servers)["Name"]

if gui_enabled:
return openvpn_connect(servername, protocol, gui_enabled)
openvpn_connect(servername, protocol)


Expand Down Expand Up @@ -293,7 +295,7 @@ def direct(user_input, protocol=None):
openvpn_connect(servername, protocol)


def reconnect():
def reconnect(gui_enabled=False):
"""Reconnect to the last VPN Server."""

logger.debug("Starting reconnect")
Expand All @@ -307,16 +309,20 @@ def reconnect():
"[!] Couldn't find a previous connection\n"
"[!] Please connect normally first"
)
sys.exit(1)
if not gui_enabled:
sys.exit(1)
return "Couldn't find a previous connection.\nPlease connect normally first."

if gui_enabled:
return openvpn_connect(servername, protocol, gui_enabled)
openvpn_connect(servername, protocol)


def disconnect(passed=False):
def disconnect(passed=False, gui_enabled=False):
"""Disconnect VPN if a connection is present."""

logger.debug("Initiating disconnect")

return_message = 'Error occured with this message'
if is_connected():
if passed:
print("There is already a VPN connection running.")
Expand All @@ -341,21 +347,28 @@ def disconnect(passed=False):

if is_connected():
print("[!] Could not terminate OpenVPN process.")
sys.exit(1)
if not gui_enabled:
sys.exit(1)
return_message = "Could not terminate OpenVPN process."
else:
manage_dns("restore")
manage_ipv6("restore")
manage_killswitch("restore")
logger.debug("Disconnected")
if not passed:
print("Disconnected.")
return_message = "Disconnected from VPN server."
else:
if not passed:
print("No connection found.")
manage_dns("restore")
manage_ipv6("restore")
manage_killswitch("restore")
logger.debug("No connection found")
return_message = "No active connection was found."

if gui_enabled:
return return_message


def status(gui_enabled=False):
Expand Down Expand Up @@ -455,6 +468,8 @@ def openvpn_connect(servername, protocol, gui_enabled=False):
"Connecting to {0} via {1}".format(servername, protocol.upper())
)

return_message = ''

port = {"udp": 1194, "tcp": 443}

shutil.copyfile(TEMPLATE_FILE, OVPN_FILE)
Expand Down Expand Up @@ -524,6 +539,7 @@ def openvpn_connect(servername, protocol, gui_enabled=False):
disconnect(passed=True)
print("Connected!")
logger.debug("Connection successful")
return_message = "Connected to <b>{0}</b> via <b>{1}</b>".format(servername, protocol.upper())
break
# If Authentication failed
elif "AUTH_FAILED" in content:
Expand All @@ -535,6 +551,7 @@ def openvpn_connect(servername, protocol, gui_enabled=False):
logger.debug("Authentication failure")
if not gui_enabled == True:
sys.exit(1)
return_message = "Authentication failed.\nPlease make sure that your Username and Password is correct."
break
# Stop after 45s
elif time.time() - time_start >= 45:
Expand All @@ -556,6 +573,7 @@ def openvpn_connect(servername, protocol, gui_enabled=False):
config.write(f)

check_update()
return return_message


def manage_dns(mode, dns_server=False):
Expand Down
2 changes: 1 addition & 1 deletion protonvpn_linux_gui/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "1.3.0"
VERSION = "1.4.0"
GITHUB_URL_RELEASE = "https://github.com/calexandru2018/protonvpn-linux-gui/releases/latest"
PATH_AUTOCONNECT_SERVICE = "/etc/systemd/system/protonvpn-autoconnect.service"
TEMPLATE ="""
Expand Down
Loading

0 comments on commit 8a26742

Please sign in to comment.