def update_user_pass(interface, messagedialog_label, messagedialog_spinner):
    """Function that updates username and password.
    """
    username_field = interface.get_object("update_username_input")
    password_field = interface.get_object("update_password_input")

    username_text = username_field.get_text().strip()
    password_text = password_field.get_text().strip()

    if len(username_text) == 0 or len(password_text) == 0:
        messagedialog_label.set_markup("Both fields need to be filled!")
        messagedialog_spinner.hide()
        return

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

    set_config_value("USER", "username", username_text)

    with open(PASSFILE, "w") as f:
        f.write("{0}\n{1}".format(username_text, password_text))
        gui_logger.debug("Passfile updated")
        os.chmod(PASSFILE, 0o600)

        messagedialog_label.set_markup("Username and password updated!")
        password_field.set_text("")
        messagedialog_spinner.hide()
        messagedialog_label.set_markup("Username and password updated.")

    gui_logger.debug(">>> Ended tasks in \"set_username_password\" thread.")
示例#2
0
def update_pvpn_plan(interface, messagedialog_label, messagedialog_spinner, tier, tier_display):
    """Function that updates ProtonVPN plan.
    """
  
    protonvpn_plan = tier
    visionary_compare = 0

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

    visionary_compare = protonvpn_plan
    if protonvpn_plan == 4:
        protonvpn_plan = 3

    # Lower tier by one to match API allocation
    protonvpn_plan -= 1    

    set_config_value("USER", "tier", str(protonvpn_plan))

    messagedialog_label.set_markup("ProtonVPN Plan has been updated to <b>{}</b>!\nServers list will be refreshed.".format(tier_display))
    messagedialog_spinner.hide()

    gui_logger.debug(">>> Result: \"{0}\"".format("ProtonVPN Plan has been updated!"))

    time.sleep(1.5)

    load_on_start({"interface":interface, "gui_enabled": True})     
    populate_servers_dict = {
        "tree_object": interface.get_object("ServerTreeStore"),
        "servers": False
    }

    gobject.idle_add(populate_server_list, populate_servers_dict)

    gui_logger.debug(">>> Ended tasks in \"set_protonvpn_tier\" thread.")   
示例#3
0
    def set_dns(self, dns_value):
        try:
            set_config_value("USER", "dns_leak_protection", dns_value)
        except:
            gui_logger.debug("Could not update DNS Protection settings to: {}".format(dns_value))
            return False

        return True
示例#4
0
    def set_default_protocol(self, protocol):
        try:
            set_config_value("USER", "default_protocol", protocol)
        except:
            gui_logger.debug("Could not update default Protocol to: {}".format(protocol))
            return False

        return True
示例#5
0
def update_def_protocol(openvpn_protocol):
    """Function that updates default protocol.
    """
    gui_logger.debug(">>> Running \"set_default_protocol\".")

    set_config_value("USER", "default_protocol", openvpn_protocol)

    gui_logger.debug(">>> Ended tasks in \"set_default_protocol\" thread.")   
示例#6
0
    def set_killswitch(self, update_to):
        try:
            set_config_value("USER", "killswitch", update_to)
        except:
            gui_logger.debug("Could not update KillSwitch to: {}".format(update_to))
            return False

        return True
示例#7
0
def update_dns(dns_value):
    """Function that updates DNS settings.
    """
    
    set_config_value("USER", "dns_leak_protection", dns_value)
    # set_config_value("USER", "custom_dns", custom_dns)

    gui_logger.debug(">>> Result: \"{0}\"".format("DNS Management updated."))

    gui_logger.debug(">>> Ended tasks in \"dns_leak_switch_clicked\" thread.")
示例#8
0
def update_killswitch(update_to):
    """Function that updates killswitch configurations. 
    """
    set_config_value("USER", "killswitch", update_to)

    # Update killswitch label
    result = ">>> Kill Switch configuration updated to {}".format("enabled" if update_to == "1" else "disabled")

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

    gui_logger.debug(">>> Ended tasks in \"update_killswitch_switch_changed\" thread.")   
def update_def_protocol(interface, messagedialog_label, messagedialog_spinner,
                        openvpn_protocol):
    """Function that updates default protocol.
    """
    gui_logger.debug(">>> Running \"set_default_protocol\".")

    set_config_value("USER", "default_protocol", openvpn_protocol)

    messagedialog_label.set_markup("Protocol updated to <b>{}</b>!".format(
        openvpn_protocol.upper()))
    messagedialog_spinner.hide()

    gui_logger.debug(">>> Ended tasks in \"set_default_protocol\" thread.")
示例#10
0
    def set_user_pass(self, username, password):
        user_pass = "******".format(username, password)
        echo_to_passfile = "echo -e {} > {}".format(user_pass, PASSFILE)

        result_bool, display_message = self.root_command(["bash", "-c", echo_to_passfile])

        if not result_bool:
            gui_logger.debug("Could not update Passfile")
            return result_bool, display_message

        set_config_value("USER", "username", username)
        
        return result_bool, "Username and password <b>updated</b>!"
    def check_update(self):
        """Return the download URL if Update is available, False otherwise"""

        pvpncli_logger.logger.debug("Checking for new update")
        current_version = list(VERSION.split("."))
        current_version = [int(i) for i in current_version]
        pvpncli_logger.logger.debug(f"Current: {current_version}")

        latest_version = self.get_latest_version()
        if not latest_version:
            # Skip if get_latest_version() ran into errors
            return

        latest_version = latest_version.split(".")
        latest_version = [int(i) for i in latest_version]
        pvpncli_logger.logger.debug(f"Latest: {latest_version}")

        for idx, i in enumerate(latest_version):
            if i > current_version[idx]:
                pvpncli_logger.logger.debug("Update found")
                update_available = True
                break
            elif i < current_version[idx]:
                pvpncli_logger.logger.debug("No update")
                update_available = False
                break
        else:
            pvpncli_logger.logger.debug("No update")
            update_available = False

        pvpncli_utils.set_config_value("metadata", "last_update_check",
                                       int(time()))

        if update_available:
            latest_version = '.'.join([str(x) for x in latest_version])
            update_available_popup = PvpnPopup(
                title='Update Available!',
                label_text=(
                    f"protonvpn-cli-gui v{latest_version} is now available."),
                dt=5,
            )
            update_available_popup_label = PvpnPopupLabel(
                text=update_available_popup.label_text,
                text_size=(400, 400),
            )
            update_available_popup.add_widget(update_available_popup_label)
            Clock.schedule_once(
                update_available_popup.open,
                1,
            )
示例#12
0
    def generate_user_pass_file(self, username, password):
        user_pass = "******".format(username, password)
        echo_to_passfile = "echo -e {} > {}".format(user_pass, PASSFILE)

        sudo_type = "pkexec" if is_polkit_installed else "sudo"

        try:
            output = subprocess.check_output([sudo_type, "bash", "-c", echo_to_passfile], stderr=subprocess.STDOUT, timeout=30)
            set_config_value("USER", "username", username)
        except (subprocess.TimeoutExpired, subprocess.CalledProcessError) as e:
            gui_logger.debug(e)
            return False   

        gui_logger.debug("Passfile generated")
        return True
def update_killswitch(interface, messagedialog_label, messagedialog_spinner,
                      ks_value):
    """Function that updates killswitch configurations. 
    """
    set_config_value("USER", "killswitch", ks_value)

    # Update killswitch label
    result = "Kill Switch configuration updated to <b>{}</b>!".format(
        "enabled" if ks_value == "1" else "disabled")
    messagedialog_label.set_markup()
    messagedialog_spinner.hide()

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

    gui_logger.debug(
        ">>> Ended tasks in \"update_killswitch_switch_changed\" thread.")
def update_dns(interface, messagedialog_label, messagedialog_spinner,
               dns_value):
    """Function that updates DNS settings.
    """

    set_config_value("USER", "dns_leak_protection", dns_value)
    # set_config_value("USER", "custom_dns", custom_dns)

    messagedialog_label.set_markup(
        "DNS Management updated to <b>{0}</b>!".format(
            "enabled" if dns_value == "1" else "disabled"))
    messagedialog_spinner.hide()

    gui_logger.debug(">>> Result: \"{0}\"".format("DNS Management updated."))

    gui_logger.debug(">>> Ended tasks in \"dns_leak_switch_clicked\" thread.")
示例#15
0
    def set_pvpn_tier(self, protonvpn_plan):
        visionary_compare = 0

        visionary_compare = int(protonvpn_plan)
        if protonvpn_plan == 4:
            protonvpn_plan = 3

        # Lower tier by one to match API allocation
        protonvpn_plan -= 1    

        try:
            set_config_value("USER", "tier", str(protonvpn_plan))
        except:
            gui_logger.debug("Could not update ProtonVPN Plan to: {}".format(protonvpn_plan))
            return False

        return True
示例#16
0
def update_split_tunneling_status(update_to):
    if update_to == "1":
        result = "Split tunneling has been <b>enabled</b>!\n"
    else:
        if os.path.isfile(SPLIT_TUNNEL_FILE):
            os.remove(SPLIT_TUNNEL_FILE)
        result = "Split tunneling has been <b>disabled</b>!\n"

    if int(get_config_value("USER", "killswitch")):
        set_config_value("USER", "killswitch", 0)

        result = result + "Split Tunneling <b>can't</b> be used with Kill Switch, Kill Switch has been <b>disabled</b>!\n\n"
        time.sleep(1)

    set_config_value("USER", "split_tunnel", update_to)

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

    gui_logger.debug(">>> Ended tasks in \"set_split_tunnel\" thread.") 
示例#17
0
    def set_split_tunneling(self, update_to):
        if not update_to == "1":
            try:
                if os.path.isfile(SPLIT_TUNNEL_FILE):
                    os.remove(SPLIT_TUNNEL_FILE)
            except:
                return False

        try:
            if int(get_config_value("USER", "killswitch")):
                set_config_value("USER", "killswitch", 0)
        except:
            gui_logger.debug("Could not disable KillSwitch")
            return False

        try:
            set_config_value("USER", "split_tunnel", update_to)
        except:
            gui_logger.debug("Could not update split_tunnel to: {}".format(update_to))
            return False
示例#18
0
    def setup_user(self, user_data):
        ovpn_username = user_data['username']
        ovpn_password = user_data['password']
        user_tier = user_data['protonvpn_plan']
        user_protocol = user_data['openvpn_protocol']

        if not self.generate_user_pass_file(ovpn_username, ovpn_password):
            shutil.rmtree(CONFIG_DIR)
            return False

        gui_logger.debug("Passfile created")

        pull_server_data(force=True)

        if user_tier == 4:
            user_tier = 3
        user_tier -= 1

        set_config_value("USER", "username", ovpn_username)
        set_config_value("USER", "tier", user_tier)
        set_config_value("USER", "default_protocol", user_protocol)
        set_config_value("USER", "dns_leak_protection", 1)
        set_config_value("USER", "custom_dns", None)
        set_config_value("USER", "killswitch", 0)
        set_config_value("USER", "split_tunnel", 0)

        set_config_value("USER", "initialized", 1)

        return True
def update_split_tunneling(interface, messagedialog_label,
                           messagedialog_spinner):
    """Function that updates split tunneling configurations.
    """
    result = "Split tunneling configurations <b>updated</b>!\n"
    split_tunneling_buffer = interface.get_object(
        "split_tunneling_textview").get_buffer()

    # Get text takes a start_iter, end_iter and the buffer itself as last param
    split_tunneling_content = split_tunneling_buffer.get_text(
        split_tunneling_buffer.get_start_iter(),
        split_tunneling_buffer.get_end_iter(), split_tunneling_buffer)

    # Split IP/CIDR by either ";" and/or "\n"
    split_tunneling_content = re.split('[;\n]', split_tunneling_content)

    # Remove empty spaces
    split_tunneling_content = [
        content.strip() for content in split_tunneling_content
    ]

    # Remove empty list elements
    split_tunneling_content = list(filter(None, split_tunneling_content))

    for ip in split_tunneling_content:
        if not is_valid_ip(ip):
            messagedialog_spinner.hide()
            messagedialog_label.set_markup(
                "<b>{0}</b> is not valid!\nNone of the IP's were added, please try again with a different IP."
                .format(ip))
            gui_logger.debug("[!] Invalid IP \"{0}\".".format(ip))
            return

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

    if len(split_tunneling_content) == 0:
        set_config_value("USER", "split_tunnel", 0)
        if os.path.isfile(SPLIT_TUNNEL_FILE):
            os.remove(SPLIT_TUNNEL_FILE)
            result = "Split tunneling <b>disabled</b>!\n\n"

    if int(get_config_value("USER", "killswitch")):
        set_config_value("USER", "killswitch", 0)

        result = result + "Split Tunneling <b>can't</b> be used with Kill Switch.\nKill Switch has been <b>disabled</b>!\n\n"
        time.sleep(1)

    set_config_value("USER", "split_tunnel", 1)

    with open(SPLIT_TUNNEL_FILE, "w") as f:
        for ip in split_tunneling_content:
            f.write("\n{0}".format(ip))

    if os.path.isfile(SPLIT_TUNNEL_FILE):
        change_file_owner(SPLIT_TUNNEL_FILE)

        if len(split_tunneling_content) > 0:
            result = result + "The following servers were added:\n\n{}".format(
                [ip for ip in split_tunneling_content])
    else:
        # If no no config file exists,
        # split tunneling should be disabled again
        gui_logger.debug("No split tunneling file existing.")
        set_config_value("USER", "split_tunnel", 0)
        result = "No split tunneling file was found, split tunneling will be <b>disabled</b>!\n\n"

    messagedialog_label.set_markup(result)
    messagedialog_spinner.hide()

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

    gui_logger.debug(">>> Ended tasks in \"set_split_tunnel\" thread.")
def on_login(interface, username_field, password_field, messagedialog_label,
             user_window, login_window, messagedialog_window):
    """Function that initializes a user profile.
    """
    server_list_object = interface.get_object("ServerListStore")

    populate_servers_dict = {
        "list_object": server_list_object,
        "servers": False
    }

    user_data = prepare_initilizer(username_field, password_field, interface)

    config = configparser.ConfigParser()
    config["USER"] = {
        "username": "******",
        "tier": "None",
        "default_protocol": "None",
        "initialized": "0",
        "dns_leak_protection": "1",
        "custom_dns": "None",
        "check_update_interval": "3",
        "killswitch": "0",
        "split_tunnel": "0",
        "autoconnect": "0"
    }
    config["metadata"] = {
        "last_api_pull": "0",
        "last_update_check": str(int(time.time())),
    }
    with open(CONFIG_FILE, "w") as f:
        config.write(f)
    change_file_owner(CONFIG_FILE)
    gui_logger.debug("pvpn-cli.cfg initialized")

    change_file_owner(CONFIG_DIR)

    ovpn_username = user_data['username']
    ovpn_password = user_data['password']
    user_tier = user_data['protonvpn_plan']
    user_protocol = user_data['openvpn_protocol']

    pull_server_data(force=True)
    make_ovpn_template()

    if user_tier == 4:
        user_tier = 3
    user_tier -= 1

    set_config_value("USER", "username", ovpn_username)
    set_config_value("USER", "tier", user_tier)
    set_config_value("USER", "default_protocol", user_protocol)
    set_config_value("USER", "dns_leak_protection", 1)
    set_config_value("USER", "custom_dns", None)
    set_config_value("USER", "killswitch", 0)
    set_config_value("USER", "split_tunnel", 0)
    set_config_value("USER", "autoconnect", "0")

    with open(PASSFILE, "w") as f:
        f.write("{0}\n{1}".format(ovpn_username, ovpn_password))
        gui_logger.debug("Passfile created")
        os.chmod(PASSFILE, 0o600)

    gui_config = configparser.ConfigParser()
    gui_config["connections"] = {"display_secure_core": False}
    gui_config["general_tab"] = {
        "start_min": False,
        "start_on_boot": False,
        "show_notifications": False,
    }
    gui_config["tray_tab"] = {
        TRAY_CFG_DATA_TX: "0",
        TRAY_CFG_SERVENAME: "0",
        TRAY_CFG_TIME_CONN: "0",
        TRAY_CFG_SERVERLOAD: "0",
    }
    gui_config["conn_tab"] = {
        "autoconnect": "dis",
        "quick_connect": "dis",
    }

    with open(GUI_CONFIG_FILE, "w") as f:
        gui_config.write(f)
    change_file_owner(GUI_CONFIG_FILE)
    gui_logger.debug("pvpn-gui.cfg initialized")

    set_config_value("USER", "initialized", 1)

    load_on_start({
        "interface": interface,
        "gui_enabled": True,
        "messagedialog_label": messagedialog_label
    })