def populate_autoconnect_list(self, autoconnect_liststore, return_list=False): """Function that populates autoconnect dropdown list. """ autoconnect_alternatives = self.settings_service.generate_autoconnect_list( ) other_choice_dict = { "dis": "Disabled", "fast": "Fastest", "rand": "Random", "p2p": "Peer2Peer", "sc": "Secure Core (Plus/Visionary)", "tor": "Tor (Plus/Visionary)" } return_values = collections.OrderedDict() for alt in autoconnect_alternatives: if alt in other_choice_dict: # if return_list: return_values[alt] = other_choice_dict[alt] # else: autoconnect_liststore.append( [alt, other_choice_dict[alt], alt]) else: for k, v in country_codes.items(): if alt.lower() == v.lower(): # if return_list: return_values[k] = v # else: autoconnect_liststore.append([k, v, k]) if return_list: return return_values
def get_flag_path(country): for k, v in country_codes.items(): if country == v: flag_path = SMALL_FLAGS_BASE_PATH + "{}.png".format(v) break else: flag_path = SMALL_FLAGS_BASE_PATH + "Unknown.png" return flag_path
def connect_to_country(self, user_selected_server): try: for k, v in country_codes.items(): if v == user_selected_server: selected_country = k break except: return False command = ["protonvpn", "connect", "--cc", selected_country] bool_value, result = self.root_command(command) return self.get_display_message(bool_value, result)
def connect_to_selected_server(*args): """Function that either connects by selected server or selected country. """ protocol = get_config_value("USER", "default_protocol") gui_logger.debug(">>> Running \"openvpn_connect\".") # Check if it should connect to country or server if "#" in args[0]["user_selected_server"]: result = subprocess.run([ "protonvpn", "connect", args[0]["user_selected_server"], "-p", protocol ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) gui_logger.debug( ">>> Log during connection to specific server: {}".format(result)) else: for k, v in country_codes.items(): if v == args[0]["user_selected_server"]: selected_country = k break result = subprocess.run( ["protonvpn", "connect", "--cc", selected_country, "-p", protocol], stdout=subprocess.PIPE, stderr=subprocess.PIPE) gui_logger.debug( ">>> Log during connection to country: {}".format(result)) server_protocol = get_server_protocol_from_cli(result) display_message = result.stdout.decode() if server_protocol: display_message = "You are connect to <b>{}</b> via <b>{}</b>!".format( server_protocol, protocol.upper()) args[0]["messagedialog_label"].set_markup(display_message) args[0]["messagedialog_spinner"].hide() update_labels_dict = { "interface": args[0]["interface"], "servers": False, "disconnecting": False, "conn_info": False } update_labels_status(update_labels_dict) gui_logger.debug(">>> Ended tasks in \"openvpn_connect\" thread.")
def populate_autoconnect_list(interface, return_list=False): """Function that populates autoconnect dropdown list. """ autoconnect_liststore = interface.get_object("AutoconnectListStore") countries = {} servers = get_servers() other_choice_dict = { "dis": "Disabled", "fast": "Fastest", "rand": "Random", "p2p": "Peer2Peer", "sc": "Secure Core (Plus/Visionary)", "tor": "Tor (Plus/Visionary)" } autoconnect_alternatives = ["dis", "fast", "rand", "p2p", "sc", "tor"] # return_values = collections.OrderedDict() return_values = collections.OrderedDict() for server in servers: country = get_country_name(server["ExitCountry"]) if country not in countries.keys(): countries[country] = [] countries[country].append(server["Name"]) for country in sorted(countries): autoconnect_alternatives.append(country) for alt in autoconnect_alternatives: if alt in other_choice_dict: # if return_list: return_values[alt] = other_choice_dict[alt] # else: autoconnect_liststore.append([alt, other_choice_dict[alt], alt]) else: for k, v in country_codes.items(): if alt.lower() == v.lower(): # if return_list: return_values[k] = v # else: autoconnect_liststore.append([k, v, k]) if return_list: return return_values
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)
def populate_server_list(populate_servers_dict): """Function that updates server list. """ only_secure_core = True if get_gui_config("connections", "display_secure_core") == "True" else False pull_server_data(force=True) features = {0: "Normal", 1: "Secure-Core", 2: "Tor", 4: "P2P"} server_tiers = {0: "Free", 1: "Basic", 2: "Plus/Visionary"} if not populate_servers_dict["servers"]: servers = get_servers() else: servers = populate_servers_dict["servers"] # Country with respective servers, ex: PT#02 countries = {} if servers: for server in servers: country = get_country_name(server["ExitCountry"]) if country not in countries.keys(): countries[country] = [] countries[country].append(server["Name"]) country_servers = {} # Order server list by country alphabetically countries = collections.OrderedDict(sorted(countries.items())) for country in countries: country_servers[country] = sorted(countries[country], key=lambda s: get_server_value(s, "Load", servers)) populate_servers_dict["tree_object"].clear() CURRDIR = os.path.dirname(os.path.abspath(__file__)) flags_base_path = CURRDIR+"/resources/img/flags/small/" features_base_path = CURRDIR+"/resources/img/utils/" # Create empty image empty_path = features_base_path+"normal.png" empty_pix = empty = GdkPixbuf.Pixbuf.new_from_file_at_size(empty_path, 15,15) # Create P2P image p2p_path = features_base_path+"p2p-arrows.png" p2p_pix = empty = GdkPixbuf.Pixbuf.new_from_file_at_size(p2p_path, 15,15) # Create TOR image tor_path = features_base_path+"tor-onion.png" tor_pix = empty = GdkPixbuf.Pixbuf.new_from_file_at_size(tor_path, 15,15) # Create Plus image plus_server_path = features_base_path+"plus-server.png" plus_pix = GdkPixbuf.Pixbuf.new_from_file_at_size(plus_server_path, 15,15) for country in country_servers: for k,v in country_codes.items(): if country == v: flag_path = flags_base_path+"{}.png".format(v) break else: flag_path = flags_base_path+"Unknown.png" # Get average load and highest feature avrg_load, country_feature = get_country_avrg_features(country, country_servers, servers, features) flag = GdkPixbuf.Pixbuf.new_from_file_at_size(flag_path, 15,15) # Check plus servers if country_feature == "normal" or country_feature == "p2p": plus_feature = empty_pix else: plus_feature = plus_pix # Check correct feature if country_feature == "normal" or country_feature == "secure-core": feature = empty_pix elif country_feature == "p2p": feature = p2p_pix elif country_feature == "tor": feature = tor_pix if country_feature == "secure-core" and only_secure_core: country_row = populate_servers_dict["tree_object"].append(None, [flag, country, plus_feature, feature, avrg_load]) elif not only_secure_core: country_row = populate_servers_dict["tree_object"].append(None, [flag, country, plus_feature, feature, avrg_load]) for servername in country_servers[country]: secure_core = False load = str(get_server_value(servername, "Load", servers)).rjust(3, " ") load = load + "%" tier = server_tiers[get_server_value(servername, "Tier", servers)] if not "Plus/Visionary".lower() == tier.lower(): plus_feature = empty_pix else: plus_feature = plus_pix server_feature = features[get_server_value(servername, 'Features', servers)].lower() if server_feature == "Normal".lower(): feature = empty_pix elif server_feature == "P2P".lower(): feature = p2p_pix elif server_feature == "Tor".lower(): feature = tor_pix else: # Should be secure core secure_core = True if secure_core and only_secure_core: populate_servers_dict["tree_object"].append(country_row, [empty_pix, servername, plus_feature, feature, load]) elif not secure_core and not only_secure_core: populate_servers_dict["tree_object"].append(country_row, [empty_pix, servername, plus_feature, feature, load])
def update_labels(interface, servers, is_connected, connected_server, disconnecting, conn_info=False): """Function that updates the labels. """ gui_logger.debug(">>> Running \"right_grid_update_labels\".") # Right grid 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") CURRDIR = os.path.dirname(os.path.abspath(__file__)) flags_base_path = CURRDIR+"/resources/img/flags/large/" # Get and set server load label try: load = get_server_value(connected_server, "Load", servers) except: load = False load = "{0}% Load".format(load) if load and is_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 country_cc = False for k,v in country_codes.items(): if k == country: if is_connected: try: flag_path = flags_base_path+"{}.jpg".format(k.lower()) background_large_flag.set_from_file(flag_path) except: pass country_cc = v protonvpn_sign_green.hide() country_server = country_cc if is_connected: country_server = country_server + " >> " + connected_server protonvpn_sign_green.show() # Get and set server name connected_server = connected_server if connected_server and is_connected else "" country_label.set_markup(country_server) ip_label.set_markup(ip) isp_label.set_markup(isp) # Get and set city label try: city = get_server_value(connected_server, "City", servers) except: city = False city = city if city else "" # Update sent and received data gobject.timeout_add_seconds(1, update_sent_received_data, {"received_label": data_received_label, "sent_label": data_sent_label}) # Left grid all_features = {0: "Normal", 1: "Secure-Core", 2: "Tor", 4: "P2P"} protocol = "No VPN Connection" # Check and set VPN status label. Get also protocol status if vpn is connected conn_disc_button = "Quick Connect" if is_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: 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_connected":is_connected, "label":time_connected_label}) # Check and set protocol label protocol_label.set_markup(protocol)