def main_loop(self, _): """Main loop that updates all labels. """ tray_icon = ALT_LOGO_PATH self.display_serverload = False display_data_rec = False display_server = False display_time_conn = False if is_connected(): tray_icon = LOGO_PATH settings = self.get_tray_settings() self.display_serverload = True if settings["display_serverload"] else False display_data_rec = True if settings["display_data_tx"] else False display_server = True if settings["display_server"] else False display_time_conn = True if settings["display_time_conn"] else False self.display_extra_info( display_serverload=self.display_serverload, display_data_rec=display_data_rec, display_server=display_server, display_time_conn=display_time_conn) self.ind.set_icon_full(tray_icon, 'protonvpn') return True
def main_loop(self, _): """Main loop that updates all labels. """ icon_path = "/resources/img/logo/protonvpn_logo_alt.png" self.display_serverload = False display_data_rec = False display_server = False display_time_conn = False if is_connected(): icon_path = "/resources/img/logo/protonvpn_logo.png" settings = self.get_tray_settings() self.display_serverload = True if settings["display_serverload"] else False display_data_rec = True if settings["display_data_tx"] else False display_server = True if settings["display_server"] else False display_time_conn = True if settings["display_time_conn"] else False self.display_extra_info( display_serverload=self.display_serverload, display_data_rec=display_data_rec, display_server=display_server, display_time_conn=display_time_conn) self.ind.set_icon_full(CURRDIR + icon_path, 'protonvpn') return True
def run(self): while self.applet.is_polling(): if is_connected(): self.applet.tray_icon.setIcon(QIcon('icons/16x16/protonvpn-connected.png')) self.applet.previous_status = Status.connected else: # notify on disconnection if self.applet.show_notifications() and self.applet.previous_status == Status.connected: CheckStatus(self).start() self.applet.tray_icon.setIcon(QIcon('icons/16x16/protonvpn-disconnected.png')) self.applet.previous_status = Status.disconnected self.sleep(1)
def main_conn_disc_button_label(self, button): """Button/Event handler to connect to the fastest server """ self.messagedialog_sub_label.hide() gui_logger.debug(">>> Starting \"main_conn_disc_button_label\" thread.") server_list = self.interface.get_object("TreeViewServerList").get_selection() (model, pathlist) = server_list.get_selected_rows() user_selected_server = False for path in pathlist : tree_iter = model.get_iter(path) # the second param of get_value() specifies the column number, starting at 0 user_selected_server = model.get_value(tree_iter, 1) server_list.unselect_all() target = quick_connect message = "Connecting to the fastest server..." if get_gui_config("conn_tab","quick_connect") != "dis": target = custom_quick_connect message = "Connecting to custom quick connect..." if is_connected() and not user_selected_server: target = disconnect message = "Disconnecting..." if user_selected_server: target = connect_to_selected_server message = "Connecting to <b>{}</b>".format(user_selected_server) self.messagedialog_label.set_markup(message) self.messagedialog_spinner.show() thread = Thread(target=target, args=[{ "interface":self.interface, "user_selected_server": user_selected_server, "messagedialog_label": self.messagedialog_label, "messagedialog_spinner": self.messagedialog_spinner}]) thread.daemon = True thread.start() self.messagedialog_window.show()
def get_diagnose_settings(self): # Check if there is internet connection # Depending on next questions, some actions might be suggested. has_internet = check_internet_conn(request_bool=True) # Check if killswitch is enabled # Advice to restore IP tables manually and restart netowrk manager. is_killswitch_enabled = True if get_config_value("USER", "killswitch") == 1 else False # Check if VPN is running # If there is a OpenVPN process running in the background, kill it. is_ovpnprocess_running = is_connected() # Check if custom DNS is enabled # If there is no VPN connection and also no internet, then it is a DNS issue. is_dns_protection_enabled = False if get_config_value("USER", "dns_leak_protection") == "0" or (not get_config_value("USER", "custom_dns") is None and get_config_value("USER", "dns_leak_protection") == "0") else True return has_internet, is_killswitch_enabled, is_ovpnprocess_running, is_dns_protection_enabled
def update_labels_status(update_labels_dict): """Function prepares data to update labels. """ gui_logger.debug(">>> Running \"update_labels_status\" getting servers, is_connected and connected_server.") if not update_labels_dict["servers"]: servers = get_servers() else: servers = update_labels_dict["servers"] protonvpn_conn_check = is_connected() is_vpn_connected = True if protonvpn_conn_check else False try: connected_server = get_config_value("metadata", "connected_server") except: connected_server = False update_labels(update_labels_dict["interface"], servers, is_vpn_connected, connected_server, update_labels_dict["disconnecting"], conn_info=update_labels_dict["conn_info"])
def main_conn_disc_button_label(self, button): """Button/Event handler to connect to either pre-selected quick connect, selected server/country or just fastest connect in the absence of previous params. """ gui_logger.debug( ">>> Starting \"main_conn_disc_button_label\" thread.") server_list = self.interface.get_object( "TreeViewServerList").get_selection() (model, pathlist) = server_list.get_selected_rows() user_selected_server = False for path in pathlist: tree_iter = model.get_iter(path) # the second param of get_value() specifies the column number, starting at 0 user_selected_server = model.get_value(tree_iter, 1) server_list.unselect_all() target = self.dashboard_presenter.quick_connect message = "Connecting to the fastest server..." if is_connected() and not user_selected_server: target = self.dashboard_presenter.on_disconnect message = "Disconnecting..." if user_selected_server: target = self.dashboard_presenter.on_connect_user_selected message = "Connecting to <b>{}</b>".format(user_selected_server) self.queue.put( dict(action="display_dialog", label=message, spinner=True, hide_close_button=True)) thread = Thread(target=target, kwargs=dict(connection_labels=self.connection_labels, user_selected_server=user_selected_server)) thread.daemon = True thread.start()
def message_dialog(interface, action, label_object, spinner_object, sub_label_object=False): """Multipurpose message dialog function. """ if action == "check_for_update": with concurrent.futures.ThreadPoolExecutor() as executor: future = executor.submit(check_for_updates) return_value = future.result() label_object.set_markup("<span>{0}</span>".format(return_value)) spinner_object.hide() elif action == "diagnose": reccomendation = '' end_openvpn_process_guide = """\n sudo pkill openvpn\n or\n sudo pkill -9 openvpn """ restore_ip_tables_guide = """\n sudo iptables -F sudo iptables -P INPUT ACCEPT sudo iptables -P OUTPUT ACCEPT sudo iptables -P FORWARD ACCEPT """ restart_netwman_guide = """\n sudo systemctl restart NetworkManager """ # Check if there is internet connection # Depending on next questions, some actions might be suggested. has_internet = check_internet_conn(request_bool=True) # Check if killswitch is enabled # Advice to restore IP tables manually and restart netowrk manager. is_killswitch_enabled = True if get_config_value( "USER", "killswitch") == 1 else False # Check if VPN is running # If there is a OpenVPN process running in the background, kill it. is_ovpnprocess_running = is_connected() # Check if custom DNS is enabled # If there is no VPN connection and also no internet, then it is a DNS issue. is_dns_protection_enabled = False if get_config_value( "USER", "dns_leak_protection") == "0" or ( not get_config_value("USER", "custom_dns") is None and get_config_value("USER", "dns_leak_protection") == "0") else True # Check if custom DNS is in use. # It might that the user has disabled the custom DNS settings but the file still resides there is_custom_resolv_conf = {"logical": False, "display": "Original"} with open("/etc/resolv.conf") as f: lines = f.readlines() # remove \n from all elements lines = map(lambda l: l.strip(), lines) # remove empty elements lines = list(filter(None, lines)) if len(lines) < 2: is_custom_resolv_conf["logical"] = None is_custom_resolv_conf["display"] = "Missing" else: for item in lines: if "protonvpn" in item.lower(): is_custom_resolv_conf["logical"] = True is_custom_resolv_conf["display"] = "Custom" try: is_splitunn_enabled = True if get_config_value( "USER", "split_tunnel") == "1" else False except (KeyError, IndexError): is_splitunn_enabled = False # Reccomendations based on known issues if not has_internet: if is_ovpnprocess_running: reccomendation = reccomendation + "\nYou have no internet connection and a VPN process is running.\n" reccomendation = reccomendation + "This might be due to a DNS misconfiguration or lack of internet connection. You can try to disconnecto from the VPN by clicking on \"Disconnect\" or following the instructions below.\n" reccomendation = reccomendation + "<b>Warning:</b> By doing this you are ending your VPN process, which might end exposing your traffic upon reconnecting, do at your own risk." + end_openvpn_process_guide elif not is_ovpnprocess_running: if is_killswitch_enabled: reccomendation = reccomendation + "\nYou Have killswitch enabled, which might be blocking your connection.\nTry to flush and then reconfigure your IP tables." reccomendation = reccomendation + "<b>Warning:</b> By doing this you are clearing all of your killswitch configurations. Do at your own risk." + restore_ip_tables_guide elif is_custom_resolv_conf["logical"]: reccomendation = reccomendation + "\nCustom DNS is still present in resolv.conf even though you are not connected to a server. This might be blocking your from establishing a non-encrypted connection.\n" reccomendation = reccomendation + "Try to restart your network manager to restore default configurations:" + restart_netwman_guide elif is_custom_resolv_conf["logical"] is None: reccomendation = reccomendation + "\nNo running VPN process was found, though DNS configurations are lacking in resolv.conf.\n" reccomendation = reccomendation + "This might be due to some error or corruption during DNS restoration or lack of internet connection.\n" reccomendation = reccomendation + "Try to restart your network manager to restore default configurations, if it still does not work, then you probably experiencing some internet connection issues." + restart_netwman_guide else: reccomendation = "\nYou have no internet connection.\nTry to connect to a different nework to resolve the issue." else: reccomendation = "<b>Unkown problem!</b>" else: reccomendation = "\nYour system seems to be ok. There are no reccomendations at the moment." result = """ Has internet:\t\t\t\t<b>{has_internet}</b> resolv.conf status:\t\t\t<b>{resolv_conf_status}</b> Killswitch enabled:\t\t\t<b>{is_ks_enabled}</b> VPN Process Running:\t\t<b>{is_vpnprocess_running}</b> DNS Protection Enabled:\t\t<b>{is_dns_enabled}</b> Split Tunneling Enabled:\t\t<b>{is_sp_enabled}</b> """.format( has_internet="Yes" if has_internet else "No", resolv_conf_status=is_custom_resolv_conf["display"], is_ks_enabled="Yes" if is_killswitch_enabled else "No", is_vpnprocess_running="Yes" if is_ovpnprocess_running else "No", is_dns_enabled="Yes" if is_dns_protection_enabled else "No", is_sp_enabled="Yes" if is_splitunn_enabled else "No") gui_logger.debug(result) label_object.set_markup(result) label_object.show() sub_label_object.set_markup( "<b><u>Reccomendation:</u></b>\n<span>{recc}</span>".format( recc=reccomendation)) sub_label_object.show() spinner_object.hide()
def update_labels_status(update_labels_dict): """Function prepares data to update labels. """ gui_logger.debug( ">>> Running \"update_labels_status\" getting servers, is_connected and connected_server." ) if not update_labels_dict["servers"]: servers = get_servers() else: servers = update_labels_dict["servers"] interface = update_labels_dict["interface"] disconnecting = update_labels_dict["disconnecting"] conn_info = update_labels_dict["conn_info"] is_vpn_connected = True if is_connected() else False country_cc = False load = False time_connected_label = interface.get_object("time_connected_label") protocol_label = interface.get_object("protocol_label") conn_disc_button_label = interface.get_object( "main_conn_disc_button_label") ip_label = interface.get_object("ip_label") server_load_label = interface.get_object("server_load_label") country_label = interface.get_object("country_label") isp_label = interface.get_object("isp_label") data_received_label = interface.get_object("data_received_label") data_sent_label = interface.get_object("data_sent_label") background_large_flag = interface.get_object("background_large_flag") protonvpn_sign_green = interface.get_object("protonvpn_sign_green") try: connected_server = get_config_value("metadata", "connected_server") except (KeyError, IndexError): connected_server = False # Get and set server load label try: load = get_server_value(connected_server, "Load", servers) except (KeyError, IndexError): gui_logger.debug("[!] Could not find server load information.") load = "{0}% Load".format(load) if load and is_vpn_connected else "" server_load_label.set_markup('<span>{0}</span>'.format(load)) # Get and set IP labels. Get also country and ISP if not conn_info: result = custom_get_ip_info() if result: ip, isp, country = result else: ip = "None" isp = "None" country = "None" else: ip, isp, country = conn_info for k, v in country_codes.items(): if k == country: if is_vpn_connected: flag_path = LARGE_FLAGS_BASE_PATH + "{}.jpg".format(k.lower()) background_large_flag.set_from_file(flag_path) country_cc = v protonvpn_sign_green.hide() country_server = country_cc if is_vpn_connected: try: country_server = country_server + " >> " + connected_server except TypeError: country_server = country_server + " >> " protonvpn_sign_green.show() ip_label.set_markup(ip) isp_label.set_markup(isp) # Get and set server name connected_server = connected_server if connected_server and is_vpn_connected else "" country_label.set_markup(country_server if country_server else "") # Update sent and received data gobject.timeout_add_seconds( 1, update_sent_received_data, { "is_vpn_connected": is_vpn_connected, "received_label": data_received_label, "sent_label": data_sent_label }) # Check and set VPN status label. Get also protocol status if vpn is connected protocol = "No VPN Connection" conn_disc_button = "Quick Connect" if is_vpn_connected and not disconnecting: try: connected_to_protocol = get_config_value("metadata", "connected_proto") protocol = '<span>OpenVPN >> {0}</span>'.format( connected_to_protocol.upper()) except (KeyError, IndexError): pass conn_disc_button = "Disconnect" conn_disc_button_label.set_markup(conn_disc_button) # Check and set DNS status label dns_enabled = get_config_value("USER", "dns_leak_protection") # Update time connected label gobject.timeout_add_seconds(1, update_connection_time, { "is_vpn_connected": is_vpn_connected, "label": time_connected_label }) # Check and set protocol label protocol_label.set_markup(protocol)