From f8e1f00db8b7bdc1b8035b1ac1feae0486819db3 Mon Sep 17 00:00:00 2001 From: Yolan Maldonado Date: Mon, 13 Apr 2020 22:27:13 +0200 Subject: [PATCH 1/4] added a "go back to menu entry" to all the submenu where it made sense to add it. Now you can configure all the app without relaunching it. --- protonvpn_cli/cli.py | 63 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/protonvpn_cli/cli.py b/protonvpn_cli/cli.py index 53a40d1..fa73c8f 100644 --- a/protonvpn_cli/cli.py +++ b/protonvpn_cli/cli.py @@ -317,6 +317,7 @@ def configure_cli(): "5) Kill Switch\n" "6) Split Tunneling\n" "7) Purge Configuration\n" + "8) Exit\n" ) user_choice = input( @@ -326,27 +327,20 @@ def configure_cli(): user_choice = user_choice.lower().strip() if user_choice == "1": set_username_password(write=True) - break elif user_choice == "2": set_protonvpn_tier(write=True) - break elif user_choice == "3": set_default_protocol(write=True) - break elif user_choice == "4": set_dns_protection() - break elif user_choice == "5": set_killswitch() - break elif user_choice == "6": set_split_tunnel() - break # Make sure this is always the last option elif user_choice == "7": purge_configuration() - break - elif user_choice == "": + elif user_choice == "8" or user_choice == "": print("Quitting configuration.") sys.exit(0) else: @@ -379,7 +373,10 @@ def set_username_password(write=False): """Set the ProtonVPN Username and Password.""" print() - ovpn_username = input("Enter your ProtonVPN OpenVPN username: ") + ovpn_username = input("Enter your ProtonVPN OpenVPN username or 'menu' to go back to menu: ") + + if ovpn_username == "menu": + configure_cli() # Ask for the password and confirmation until both are the same while True: @@ -412,13 +409,13 @@ def set_username_password(write=False): def set_protonvpn_tier(write=False): """Set the users ProtonVPN Plan.""" - protonvpn_plans = {1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary"} + protonvpn_plans_selection = {1: "Free", 2: "Basic", 3: "Plus or Visionary", 4: "Go back to menu"} print() print("Please choose your ProtonVPN Plan") - for plan in protonvpn_plans: - print("{0}) {1}".format(plan, protonvpn_plans[plan])) + for plan in protonvpn_plans_selection: + print("{0}) {1}".format(plan, protonvpn_plans_selection[plan])) while True: print() @@ -427,16 +424,15 @@ def set_protonvpn_tier(write=False): try: user_tier = int(user_tier) # Check if the choice exists in the dictionary - protonvpn_plans[user_tier] + protonvpn_plans_selection[user_tier] + if user_tier == 4: + configure_cli() break except (KeyError, ValueError): print() print("[!] Invalid choice. Please enter the number of your plan.") if write: - # Set Visionary to plus as it has the same access - if user_tier == 4: - user_tier = 3 # Lower tier by one to match API allocation user_tier -= 1 @@ -453,17 +449,17 @@ def set_default_protocol(write=False): print() print( - "Choose the default OpenVPN protocol.\n" + "Choose the default OpenVPN protocol or go back to menu.\n" "OpenVPN can act on two different protocols: UDP and TCP.\n" "UDP is preferred for speed but might be blocked in some networks.\n" "TCP is not as fast but a lot harder to block.\n" "Input your preferred protocol. (Default: UDP)\n" ) - protonvpn_protocols = {1: "UDP", 2: "TCP"} + protonvpn_protocols_choice = {1: "UDP", 2: "TCP", 3: "Go back to menu"} - for protocol in protonvpn_protocols: - print("{0}) {1}".format(protocol, protonvpn_protocols[protocol])) + for protocol in protonvpn_protocols_choice: + print("{0}) {1}".format(protocol, protonvpn_protocols_choice[protocol])) while True: print() @@ -472,15 +468,17 @@ def set_default_protocol(write=False): try: if user_protocol_choice == "": user_protocol_choice = 1 + elif user_protocol_choice == "3": + configure_cli() user_protocol_choice = int(user_protocol_choice) # Check if the choice exists in the dictionary - user_protocol = protonvpn_protocols[user_protocol_choice].lower() + user_protocol = protonvpn_protocols_choice[user_protocol_choice].lower() break except (KeyError, ValueError): print() print( "[!] Invalid choice. " - "Please enter the number of your preferred protocol." + "Please enter the number of your preferred protocol or exit to menu (3)." ) if write: @@ -502,11 +500,11 @@ def set_dns_protection(): "\n" "1) Enable DNS Leak Protection (recommended)\n" "2) Configure Custom DNS Servers\n" - "3) Disable DNS Management" + "3) Disable DNS Management\n" + "4) Go back to menu\n" ) - print() user_choice = input( - "Please enter your choice or leave empty to quit: " + "Please enter your choice or leave empty to go back to menu: " ) user_choice = user_choice.lower().strip() if user_choice == "1": @@ -535,9 +533,8 @@ def set_dns_protection(): dns_leak_protection = 0 custom_dns = None break - elif user_choice == "": - print("Quitting configuration.") - sys.exit(0) + elif user_choice == "4" or user_choice == "": + configure_cli() else: print( "[!] Invalid choice. Please enter the number of your choice.\n" @@ -562,11 +559,12 @@ def set_killswitch(): "\n" "1) Enable Kill Switch (Block access to/from LAN)\n" "2) Enable Kill Switch (Allow access to/from LAN)\n" - "3) Disable Kill Switch" + "3) Disable Kill Switch\n" + "4) Go back to menu" ) print() user_choice = input( - "Please enter your choice or leave empty to quit: " + "Please enter your choice or leave empty to go back to menu: " ) user_choice = user_choice.lower().strip() if user_choice == "1": @@ -578,9 +576,8 @@ def set_killswitch(): elif user_choice == "3": killswitch = 0 break - elif user_choice == "": - print("Quitting configuration.") - sys.exit(0) + elif user_choice == "4" or user_choice == "": + configure_cli() else: print( "[!] Invalid choice. Please enter the number of your choice.\n" From d7c71ea390a35d0d3e8147d0e81321a93ab132d2 Mon Sep 17 00:00:00 2001 From: Yolan Maldonado Date: Tue, 14 Apr 2020 10:41:10 +0200 Subject: [PATCH 2/4] Reset visionary as single option --- protonvpn_cli/cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/protonvpn_cli/cli.py b/protonvpn_cli/cli.py index fa73c8f..81c5f96 100644 --- a/protonvpn_cli/cli.py +++ b/protonvpn_cli/cli.py @@ -409,7 +409,7 @@ def set_username_password(write=False): def set_protonvpn_tier(write=False): """Set the users ProtonVPN Plan.""" - protonvpn_plans_selection = {1: "Free", 2: "Basic", 3: "Plus or Visionary", 4: "Go back to menu"} + protonvpn_plans_selection = {1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary", 5: "Go back to menu"} print() print("Please choose your ProtonVPN Plan") @@ -434,6 +434,10 @@ def set_protonvpn_tier(write=False): if write: + # Set Visionary to plus as it has the same access + if user_tier == 4: + user_tier = 3 + # Lower tier by one to match API allocation user_tier -= 1 From 700a9e449e5686bbc31f80f5db99d0818ad61828 Mon Sep 17 00:00:00 2001 From: Yolan Maldonado Date: Thu, 16 Apr 2020 11:28:22 +0200 Subject: [PATCH 3/4] Fixed init bugs. --- protonvpn_cli/cli.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/protonvpn_cli/cli.py b/protonvpn_cli/cli.py index 81c5f96..8bcc42b 100644 --- a/protonvpn_cli/cli.py +++ b/protonvpn_cli/cli.py @@ -212,13 +212,13 @@ def init_config_file(): print(textwrap.fill(line, width=term_width)) # Set ProtonVPN Username and Password - ovpn_username, ovpn_password = set_username_password(write=False) + ovpn_username, ovpn_password = set_username_password(write=False, init=True) # Set the ProtonVPN Plan - user_tier = set_protonvpn_tier(write=False) + user_tier = set_protonvpn_tier(write=False, init=True) # Set default Protocol - user_protocol = set_default_protocol(write=False) + user_protocol = set_default_protocol(write=False, init=True) protonvpn_plans = {1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary"} @@ -369,13 +369,19 @@ def purge_configuration(): print("Configuration purged.") -def set_username_password(write=False): +def set_username_password(write=False, init=False): """Set the ProtonVPN Username and Password.""" print() - ovpn_username = input("Enter your ProtonVPN OpenVPN username or 'menu' to go back to menu: ") + input_message_ovpn_username = "Enter your ProtonVPN OpenVPN username" + if init: + input_message_ovpn_username += ": " + if not init: + input_message_ovpn_username += " or 'menu' to go back to menu: " - if ovpn_username == "menu": + ovpn_username = input(input_message_ovpn_username) + + if not init and ovpn_username == "menu": configure_cli() # Ask for the password and confirmation until both are the same @@ -406,10 +412,13 @@ def set_username_password(write=False): return ovpn_username, ovpn_password1 -def set_protonvpn_tier(write=False): +def set_protonvpn_tier(write=False, init=False): """Set the users ProtonVPN Plan.""" - protonvpn_plans_selection = {1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary", 5: "Go back to menu"} + protonvpn_plans_selection = {1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary"} + + if not init: + protonvpn_plans_selection[5] = "Go back to menu" print() print("Please choose your ProtonVPN Plan") @@ -425,7 +434,7 @@ def set_protonvpn_tier(write=False): user_tier = int(user_tier) # Check if the choice exists in the dictionary protonvpn_plans_selection[user_tier] - if user_tier == 4: + if not init and user_tier == 5: configure_cli() break except (KeyError, ValueError): @@ -448,19 +457,22 @@ def set_protonvpn_tier(write=False): return user_tier -def set_default_protocol(write=False): +def set_default_protocol(write=False, init=False): """Set the users default protocol""" print() print( - "Choose the default OpenVPN protocol or go back to menu.\n" + "Choose the default OpenVPN protocol.\n" "OpenVPN can act on two different protocols: UDP and TCP.\n" "UDP is preferred for speed but might be blocked in some networks.\n" "TCP is not as fast but a lot harder to block.\n" "Input your preferred protocol. (Default: UDP)\n" ) - protonvpn_protocols_choice = {1: "UDP", 2: "TCP", 3: "Go back to menu"} + protonvpn_protocols_choice = {1: "UDP", 2: "TCP"} + + if not init : + protonvpn_protocols_choice[3] = "Go back to menu" for protocol in protonvpn_protocols_choice: print("{0}) {1}".format(protocol, protonvpn_protocols_choice[protocol])) @@ -472,7 +484,7 @@ def set_default_protocol(write=False): try: if user_protocol_choice == "": user_protocol_choice = 1 - elif user_protocol_choice == "3": + elif user_protocol_choice == "3" and not init: configure_cli() user_protocol_choice = int(user_protocol_choice) # Check if the choice exists in the dictionary @@ -482,7 +494,7 @@ def set_default_protocol(write=False): print() print( "[!] Invalid choice. " - "Please enter the number of your preferred protocol or exit to menu (3)." + "Please enter the number of your preferred protocol." ) if write: From c247786a967c1341f47054fd9361da30e8c0aefd Mon Sep 17 00:00:00 2001 From: Rafficer Date: Sat, 18 Apr 2020 23:31:12 +0200 Subject: [PATCH 4/4] various fixes --- protonvpn_cli/cli.py | 77 +++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/protonvpn_cli/cli.py b/protonvpn_cli/cli.py index 8bcc42b..578bdc0 100644 --- a/protonvpn_cli/cli.py +++ b/protonvpn_cli/cli.py @@ -212,13 +212,13 @@ def init_config_file(): print(textwrap.fill(line, width=term_width)) # Set ProtonVPN Username and Password - ovpn_username, ovpn_password = set_username_password(write=False, init=True) + ovpn_username, ovpn_password = set_username_password(init=True) # Set the ProtonVPN Plan - user_tier = set_protonvpn_tier(write=False, init=True) + user_tier = set_protonvpn_tier(init=True) # Set default Protocol - user_protocol = set_default_protocol(write=False, init=True) + user_protocol = set_default_protocol(init=True) protonvpn_plans = {1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary"} @@ -326,20 +326,35 @@ def configure_cli(): user_choice = user_choice.lower().strip() if user_choice == "1": - set_username_password(write=True) + try: + set_username_password() + time.sleep(1) + except KeyboardInterrupt: + print() elif user_choice == "2": - set_protonvpn_tier(write=True) + set_protonvpn_tier() + time.sleep(1) + print() elif user_choice == "3": - set_default_protocol(write=True) + set_default_protocol() + time.sleep(1) + print() elif user_choice == "4": set_dns_protection() + time.sleep(1) + print() elif user_choice == "5": set_killswitch() + time.sleep(1) + print() elif user_choice == "6": set_split_tunnel() - # Make sure this is always the last option + time.sleep(1) + print() elif user_choice == "7": purge_configuration() + break + # Make sure this is always the last option elif user_choice == "8" or user_choice == "": print("Quitting configuration.") sys.exit(0) @@ -369,20 +384,11 @@ def purge_configuration(): print("Configuration purged.") -def set_username_password(write=False, init=False): +def set_username_password(init=False): """Set the ProtonVPN Username and Password.""" print() - input_message_ovpn_username = "Enter your ProtonVPN OpenVPN username" - if init: - input_message_ovpn_username += ": " - if not init: - input_message_ovpn_username += " or 'menu' to go back to menu: " - - ovpn_username = input(input_message_ovpn_username) - - if not init and ovpn_username == "menu": - configure_cli() + ovpn_username = input("Enter your ProtonVPN OpenVPN username: ") # Ask for the password and confirmation until both are the same while True: @@ -399,7 +405,7 @@ def set_username_password(write=False, init=False): else: break - if write: + if not init: set_config_value("USER", "username", ovpn_username) with open(PASSFILE, "w") as f: @@ -412,10 +418,12 @@ def set_username_password(write=False, init=False): return ovpn_username, ovpn_password1 -def set_protonvpn_tier(write=False, init=False): +def set_protonvpn_tier(init=False): """Set the users ProtonVPN Plan.""" - protonvpn_plans_selection = {1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary"} + protonvpn_plans_selection = { + 1: "Free", 2: "Basic", 3: "Plus", 4: "Visionary" + } if not init: protonvpn_plans_selection[5] = "Go back to menu" @@ -435,14 +443,13 @@ def set_protonvpn_tier(write=False, init=False): # Check if the choice exists in the dictionary protonvpn_plans_selection[user_tier] if not init and user_tier == 5: - configure_cli() + return break except (KeyError, ValueError): print() print("[!] Invalid choice. Please enter the number of your plan.") - if write: - + if not init: # Set Visionary to plus as it has the same access if user_tier == 4: user_tier = 3 @@ -457,7 +464,7 @@ def set_protonvpn_tier(write=False, init=False): return user_tier -def set_default_protocol(write=False, init=False): +def set_default_protocol(init=False): """Set the users default protocol""" print() @@ -471,11 +478,13 @@ def set_default_protocol(write=False, init=False): protonvpn_protocols_choice = {1: "UDP", 2: "TCP"} - if not init : + if not init: protonvpn_protocols_choice[3] = "Go back to menu" for protocol in protonvpn_protocols_choice: - print("{0}) {1}".format(protocol, protonvpn_protocols_choice[protocol])) + print("{0}) {1}".format( + protocol, protonvpn_protocols_choice[protocol]) + ) while True: print() @@ -485,10 +494,10 @@ def set_default_protocol(write=False, init=False): if user_protocol_choice == "": user_protocol_choice = 1 elif user_protocol_choice == "3" and not init: - configure_cli() + return user_protocol_choice = int(user_protocol_choice) # Check if the choice exists in the dictionary - user_protocol = protonvpn_protocols_choice[user_protocol_choice].lower() + user_protocol = protonvpn_protocols_choice[user_protocol_choice].lower() # noqa break except (KeyError, ValueError): print() @@ -497,7 +506,7 @@ def set_default_protocol(write=False, init=False): "Please enter the number of your preferred protocol." ) - if write: + if not init: set_config_value("USER", "default_protocol", user_protocol) print("Default protocol has been updated.") @@ -520,7 +529,7 @@ def set_dns_protection(): "4) Go back to menu\n" ) user_choice = input( - "Please enter your choice or leave empty to go back to menu: " + "Please enter your choice: " ) user_choice = user_choice.lower().strip() if user_choice == "1": @@ -550,7 +559,7 @@ def set_dns_protection(): custom_dns = None break elif user_choice == "4" or user_choice == "": - configure_cli() + return else: print( "[!] Invalid choice. Please enter the number of your choice.\n" @@ -580,7 +589,7 @@ def set_killswitch(): ) print() user_choice = input( - "Please enter your choice or leave empty to go back to menu: " + "Please enter your choice: " ) user_choice = user_choice.lower().strip() if user_choice == "1": @@ -593,7 +602,7 @@ def set_killswitch(): killswitch = 0 break elif user_choice == "4" or user_choice == "": - configure_cli() + return else: print( "[!] Invalid choice. Please enter the number of your choice.\n"