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 #12 from calexandru2018/testing
Browse files Browse the repository at this point in the history
Several issue fixes and diagnosis tool added
  • Loading branch information
calexandru2018 authored Mar 6, 2020
2 parents 4e3cce9 + 1504ec3 commit d8e1b46
Show file tree
Hide file tree
Showing 8 changed files with 723 additions and 375 deletions.
5 changes: 3 additions & 2 deletions custom_pvpn_cli_ng/protonvpn_cli/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,9 @@ def openvpn_connect(servername, protocol, gui_enabled=False):
with open(CONFIG_FILE, "w+") as f:
config.write(f)

check_update()
return return_message
# check_update()
if gui_enabled:
return return_message


def manage_dns(mode, dns_server=False):
Expand Down
46 changes: 35 additions & 11 deletions custom_pvpn_cli_ng/protonvpn_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)


def call_api(endpoint, json_format=True, handle_errors=True):
def call_api(endpoint, json_format=True, handle_errors=True, gui_enabled=False):
"""Call to the ProtonVPN API."""

api_domain = "https://api.protonvpn.ch"
Expand All @@ -44,10 +44,11 @@ def call_api(endpoint, json_format=True, handle_errors=True):
response = requests.get(url, headers=headers)
except (requests.exceptions.ConnectionError,
requests.exceptions.ConnectTimeout):
print(
"[!] There was an error connecting to the ProtonVPN API.\n"
"[!] Please make sure your connection is working properly!"
)
if not gui_enabled:
print(
"[!] There was an error connecting to the ProtonVPN API.\n"
"[!] Please make sure your connection is working properly!"
)
logger.debug("Error connecting to ProtonVPN API")
return
# sys.exit(1)
Expand Down Expand Up @@ -98,9 +99,29 @@ def pull_server_data(force=False):
def get_servers():
"""Return a list of all servers for the users Tier."""

with open(SERVER_INFO_FILE, "r") as f:
logger.debug("Reading servers from file")
server_data = json.load(f)
server_data = {}
timer_start = time.time()

while True:
if time.time() - timer_start > 5:
break

with open(SERVER_INFO_FILE, "r") as f:
logger.debug("Reading servers from file")
try:
data = json.load(f)
if not data == None and not len(data) == 0:
server_data = data
break
except:
pull_server_data(force=True)
time.sleep(2)
pass

# time.sleep(2)

if len(server_data) == 0:
return False

servers = server_data["LogicalServers"]

Expand Down Expand Up @@ -139,15 +160,18 @@ def set_config_value(group, key, value):
config.write(f)


def get_ip_info(gui_enbled=False):
def get_ip_info(gui_enabled=False):
"""Return the current public IP Address"""
logger.debug("Getting IP Information")
ip_info = call_api("/vpn/location")
ip_info = call_api("/vpn/location", gui_enabled=gui_enabled)

if ip_info == None:
return False

ip = ip_info["IP"]
isp = ip_info["ISP"]

if gui_enbled == True:
if gui_enabled == True:
return ip, isp, ip_info["Country"]
return ip, isp

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.4.0"
VERSION = "1.5.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
70 changes: 63 additions & 7 deletions protonvpn_linux_gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
load_on_start,
load_configurations,
message_dialog,
check_for_updates
check_for_updates,
get_gui_processes
)

# Import functions that are called with threads
Expand All @@ -40,7 +41,8 @@
update_def_protocol,
update_killswitch,
update_split_tunneling,
purge_configurations
purge_configurations,
kill_duplicate_gui_process
)

from .constants import VERSION
Expand All @@ -63,7 +65,7 @@ def on_login_button_clicked(self, button):
"""Button/Event handler to intialize user account. Calls populate_server_list(server_list_object) to populate server list.
"""
login_window = self.interface.get_object("LoginWindow")
user_window = self.interface.get_object("Dashboard")
user_window = self.interface.get_object("DashboardWindow")

with concurrent.futures.ThreadPoolExecutor() as executor:
future = executor.submit(on_login, self.interface)
Expand Down Expand Up @@ -116,6 +118,7 @@ def connect_to_selected_server_button_clicked(self, button):

messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

# Get the server list object
Expand Down Expand Up @@ -147,6 +150,7 @@ def quick_connect_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Connecting to the fastest server...")
Expand All @@ -163,6 +167,7 @@ def last_connect_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

try:
Expand All @@ -188,6 +193,7 @@ def random_connect_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Connecting to a random server...")
Expand All @@ -204,6 +210,7 @@ def disconnect_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Disconnecting...")
Expand All @@ -221,6 +228,7 @@ def refresh_server_list_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Refreshing server list...")
Expand All @@ -238,10 +246,26 @@ def about_menu_button_clicked(self, button):
about_dialog = self.interface.get_object("AboutDialog")
about_dialog.set_version(VERSION)
about_dialog.show()


def diagnose_menu_button_clicked(self, button):
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label")
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Diagnosing...")
messagedialog_spinner.show()

thread = Thread(target=message_dialog, args=[self.interface, "diagnose", messagedialog_label, messagedialog_spinner, messagedialog_sub_label])
thread.daemon = True
thread.start()

messagedialog_window.show()

def check_for_updates_button_clicked(self, button):
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Checking...")
Expand Down Expand Up @@ -293,6 +317,7 @@ def update_user_pass_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Updating username and password...")
Expand Down Expand Up @@ -324,6 +349,7 @@ def update_dns_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Updating DNS configurations...")
Expand All @@ -340,6 +366,7 @@ def update_pvpn_plan_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Updating ProtonVPN Plan...")
Expand All @@ -357,6 +384,7 @@ def update_def_protocol_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Updating default OpenVPN Protocol...")
Expand Down Expand Up @@ -385,6 +413,7 @@ def update_killswitch_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Updating killswitch configurations...")
Expand All @@ -403,6 +432,7 @@ def update_split_tunneling_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Updating split tunneling configurations...")
Expand All @@ -420,6 +450,7 @@ def purge_configurations_button_clicked(self, button):
"""
messagedialog_window = self.interface.get_object("MessageDialog")
messagedialog_label = self.interface.get_object("message_dialog_label")
messagedialog_sub_label = self.interface.get_object("message_dialog_sub_label").hide()
messagedialog_spinner = self.interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Purging configurations configurations...")
Expand Down Expand Up @@ -461,14 +492,39 @@ def initialize_gui():

interface.connect_signals(Handler(interface))

if len(get_gui_processes()) > 1:
messagedialog_window = interface.get_object("MessageDialog")
messagedialog_label = interface.get_object("message_dialog_label")
messagedialog_spinner = interface.get_object("message_dialog_spinner")

messagedialog_label.set_markup("Another GUI process was found, attempting to end it...")
messagedialog_spinner.show()
messagedialog_window.show()

time.sleep(1)
# thread = Thread(target=kill_duplicate_gui_process, args=[interface, messagedialog_label, messagedialog_spinner])
# thread.daemon = True
# thread.start()

response = kill_duplicate_gui_process()

if not response['success']:
messagedialog_label.set_markup(response['message'])
messagedialog_spinner.hide()
time.sleep(3)
sys.exit(1)

messagedialog_label.set_markup(response['message'])
messagedialog_spinner.hide()

if not os.path.isfile(CONFIG_FILE):
window = interface.get_object("LoginWindow")
dashboard = interface.get_object("Dashboard")
dashboard = interface.get_object("DashboardWindow")
dashboard.connect("destroy", Gtk.main_quit)
else:
window = interface.get_object("Dashboard")
window = interface.get_object("DashboardWindow")
window.connect("destroy", Gtk.main_quit)
load_on_start(interface)
load_on_start(interface, fast_boot=True)

window.show()

Expand Down
Loading

0 comments on commit d8e1b46

Please sign in to comment.