예제 #1
0
def update_labels_status(update_labels_dict):
    """Updates labels status"""

    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

    left_grid_update_labels(update_labels_dict["interface"], servers,
                            is_vpn_connected, connected_server,
                            update_labels_dict["disconnecting"])
    right_grid_update_labels(update_labels_dict["interface"],
                             servers,
                             is_vpn_connected,
                             connected_server,
                             update_labels_dict["disconnecting"],
                             conn_info=update_labels_dict["conn_info"])
예제 #2
0
def connect_to_selected_server(interface, selected_server, messagedialog_label,
                               messagedialog_spinner):
    """Button/Event handler to connect to selected server
    """
    protocol = get_config_value("USER", "default_protocol")

    gui_logger.debug(">>> Running \"openvpn_connect\".")

    # openvpn needs to be changed
    result, servers = connection.openvpn_connect(selected_server,
                                                 protocol,
                                                 gui_enabled=True)

    update_labels_dict = {
        "interface": interface,
        "servers": servers if servers else False,
        "disconnecting": False,
        "conn_info": False
    }

    messagedialog_label.set_markup(result)
    messagedialog_spinner.hide()

    gui_logger.debug(">>> Result: \"{0}\"".format(result))

    update_labels_status(update_labels_dict)

    gui_logger.debug(">>> Ended tasks in \"openvpn_connect\" thread.")
예제 #3
0
def quick_connect(interface, messagedialog_label, messagedialog_spinner):
    """Button/Event handler to connect to the fastest server
    """

    protocol = get_config_value("USER", "default_protocol")

    gui_logger.debug(">>> Running \"fastest\".")

    result, servers = connection.fastest(protocol, gui_enabled=True)

    update_labels_dict = {
        "interface": interface,
        "servers": servers if servers else False,
        "disconnecting": False,
        "conn_info": False
    }

    messagedialog_label.set_markup(result)
    messagedialog_spinner.hide()

    gui_logger.debug(">>> Result: \"{0}\"".format(result))

    update_labels_status(update_labels_dict)

    gui_logger.debug(">>> Ended tasks in \"fastest\" thread.")
예제 #4
0
    def last_connect_button_clicked(self, button):
        """Button/Event handler to reconnect to previously connected server
        """
        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:
            servername = get_config_value("metadata", "connected_server")
            protocol = get_config_value("metadata", "connected_proto")
        except:
            messagedialog_label.set_markup(
                "You have not previously connected to any server, please do that connect to a server first before attempting to reconnect."
            )
            messagedialog_spinner.hide()
            messagedialog_window.show()
            gui_logger.debug(
                "[!] Attempted to connect to previously connected server without having made any previous connections."
            )
            return

        messagedialog_label.set_markup(
            "Connecting to to previously connected server <b>{0}</b> with <b>{1}</b>"
            .format(servername, protocol.upper()))
        messagedialog_spinner.show()

        gui_logger.debug(">>> Starting \"last_connect\" thread.")

        thread = Thread(
            target=last_connect,
            args=[self.interface, messagedialog_label, messagedialog_spinner])
        thread.daemon = True
        thread.start()

        messagedialog_window.show()
예제 #5
0
def enable_autoconnect():
    """Enables autoconnect
    """
    protonvpn_path = find_cli()
    command = " connect -f"
    if not protonvpn_path:
        return False

    # Fill template with CLI path and username
    with_cli_path = TEMPLATE.replace("PATH", (protonvpn_path + command))
    template = with_cli_path.replace("SUDO_USER",
                                     get_config_value("USER", "username"))

    if not generate_template(template):
        return False

    return enable_daemon()
예제 #6
0
def load_configurations(interface):
    """Set and populate user configurations before showing the configurations window
    """
    pref_dialog = interface.get_object("ConfigurationsWindow")

    username = get_config_value("USER", "username")
    dns_leak_protection = get_config_value("USER", "dns_leak_protection")
    custom_dns = get_config_value("USER", "custom_dns")
    tier = int(get_config_value("USER", "tier")) + 1
    default_protocol = get_config_value("USER", "default_protocol")
    killswitch = get_config_value("USER", "killswitch")

    # Populate username
    username_field = interface.get_object("update_username_input")
    username_field.set_text(username)

    # Set DNS combobox
    dns_combobox = interface.get_object("dns_preferens_combobox")
    dns_custom_input = interface.get_object("dns_custom_input")

    # DNS ComboBox
    # 0 - Leak Protection Enabled
    # 1 - Custom DNS
    # 2 - None

    if dns_leak_protection == '1':
        dns_combobox.set_active(0)
    elif dns_leak_protection != '1' and custom_dns.lower != "none":
        dns_combobox.set_active(1)
        dns_custom_input.set_property('sensitive', True)
    else:
        dns_combobox.set_active(2)

    dns_custom_input.set_text(custom_dns)

    # Set ProtonVPN Plan
    protonvpn_plans = {
        1: interface.get_object("member_free_update_checkbox"),
        2: interface.get_object("member_basic_update_checkbox"),
        3: interface.get_object("member_plus_update_checkbox"),
        4: interface.get_object("member_visionary_update_checkbox")
    }

    for tier_val, object in protonvpn_plans.items():
        if tier_val == tier:
            object.set_active(True)
            break

    # Set OpenVPN Protocol
    interface.get_object("protocol_tcp_update_checkbox").set_active(
        True) if default_protocol == "tcp" else interface.get_object(
            "protocol_udp_update_checkbox").set_active(True)

    # Set Kill Switch combobox
    killswitch_combobox = interface.get_object("killswitch_combobox")

    killswitch_combobox.set_active(int(killswitch))

    # Populate Split Tunelling
    split_tunneling = interface.get_object("split_tunneling_textview")

    # Check if killswtich is != 0, if it is then disable split tunneling funciton
    if killswitch != '0':
        split_tunneling.set_property('sensitive', False)
        interface.get_object("update_split_tunneling_button").set_property(
            'sensitive', False)

    split_tunneling_buffer = split_tunneling.get_buffer()
    content = ""
    try:
        with open(SPLIT_TUNNEL_FILE) as f:
            lines = f.readlines()

            for line in lines:
                content = content + line

            split_tunneling_buffer.set_text(content)

    except FileNotFoundError:
        split_tunneling_buffer.set_text(content)

    pref_dialog.show()
예제 #7
0
def left_grid_update_labels(interface, servers, is_connected, connected_server,
                            disconnecting):
    """Holds labels that are position within the left-side grid"""

    gui_logger.debug(">>> Running \"left_grid_update_labels\".")

    # Left grid
    vpn_status_label = interface.get_object("vpn_status_label")
    dns_status_label = interface.get_object("dns_status_label")
    time_connected_label = interface.get_object("time_connected_label")
    killswitch_label = interface.get_object("killswitch_label")
    protocol_label = interface.get_object("openvpn_protocol_label")
    server_features_label = interface.get_object("server_features_label")

    all_features = {0: "Normal", 1: "Secure-Core", 2: "Tor", 4: "P2P"}
    connection_time = False
    connected_to_protocol = False

    # Check and set VPN status label. Get also protocol status if vpn is connected
    if is_connected != True or disconnecting:
        vpn_status_label.set_markup('<span>Disconnected</span>')
    else:
        vpn_status_label.set_markup(
            '<span foreground="#4E9A06">Connected</span>')
        try:
            connected_time = get_config_value("metadata", "connected_time")
            connection_time = time.time() - int(connected_time)
            connection_time = str(
                datetime.timedelta(seconds=connection_time)).split(".")[0]
            connected_to_protocol = get_config_value("metadata",
                                                     "connected_proto")
        except KeyError:
            connection_time = False
            connected_to_protocol = False

    # Check and set DNS status label
    dns_enabled = get_config_value("USER", "dns_leak_protection")
    if int(dns_enabled) != 1:
        dns_status_label.set_markup('<span>Not Enabled</span>')
    else:
        dns_status_label.set_markup(
            '<span foreground="#4E9A06">Enabled</span>')

    # Set time connected label
    connection_time = connection_time if connection_time else ""
    time_connected_label.set_markup('<span>{0}</span>'.format(connection_time))

    # Check and set killswitch label
    connected_time = get_config_value("USER", "killswitch")
    killswitch_status = "Enabled" if connected_time == 0 else "Disabled"
    killswitch_label.set_markup('<span>{0}</span>'.format(killswitch_status))

    # Check and set protocol label
    connected_to_protocol = connected_to_protocol if connected_to_protocol else ""
    protocol_label.set_markup('<span>{0}</span>'.format(connected_to_protocol))

    # Check and set feature label
    try:
        feature = get_server_value(connected_server, "Features", servers)
    except:
        feature = False

    feature = all_features[
        feature] if not disconnecting and is_connected else ""
    server_features_label.set_markup('<span>{0}</span>'.format(feature))
예제 #8
0
def message_dialog(interface,
                   action,
                   label_object,
                   spinner_object,
                   sub_label_object=False):
    # time.sleep(1)
    # messagedialog_window = interface.get_object("MessageDialog")
    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()

        # 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") == 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))

            # False
            # print("None==False ", None==False)

            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:
            is_splitunn_enabled = False

        # Check if servers are cached
        # Maybe to-do

        # 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"] == True:
                    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"] == 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()