Esempio n. 1
0
    def enable_auto_connect(self, country_code: str, category: str = 'normal', protocol: str = 'tcp'):
        enabled = False
        selected_parameters = (country_code.lower(), category.lower(), protocol.lower())

        if selected_parameters in self.active_servers:
            connection_name = self.active_servers[selected_parameters]['name']
            connection_load = self.active_servers[selected_parameters]['load']
            connection_latency = self.active_servers[selected_parameters]['latency']

            if networkmanager.set_auto_connect(connection_name):
                self.logger.info("Auto-connect enabled for '%s' (Load: %i%%, Latency: %0.2fs).", connection_name, connection_load, connection_latency)

                # Temporarily remove the kill-switch if there was one
                kill_switch = networkmanager.remove_killswitch(log=False)

                networkmanager.disconnect_active_vpn(self.active_servers)

                if kill_switch:
                    networkmanager.set_killswitch(log=False)

                if networkmanager.enable_connection(connection_name):
                    enabled = True
        else:
            self.logger.error("Auto-connect not activated: No active server found matching [%s, %s, %s].", country_code, category, protocol)

        return enabled
Esempio n. 2
0
    def enable_auto_connect(self,
                            country_code: str,
                            category: str = 'normal',
                            protocol: str = 'tcp'):
        enabled = False
        selected_parameters = (country_code.upper(), category, protocol)

        if selected_parameters in self.active_servers:
            connection_name = self.active_servers[selected_parameters]['name']
            connection_load = self.active_servers[selected_parameters]['load']
            connection_latency = self.active_servers[selected_parameters][
                'latency']

            if networkmanager.set_auto_connect(connection_name):
                log.info(
                    f"Auto-connect enabled for '{connection_name}' "
                    f"(Load: {connection_load}%, Latency: {connection_latency:.2f})."
                )
                networkmanager.disconnect_active_vpn(self.active_servers)
                if networkmanager.enable_connection(connection_name):
                    enabled = True
        else:
            log.error(f"Auto-connect not activated: No active server found "
                      f"matching [{country_code}, {category}, {protocol}].")

        return enabled
Esempio n. 3
0
    def enable_auto_connect(self,
                            country_code,
                            category='normal',
                            protocol='tcp'):
        enabled = False
        selected_parameters = (country_code.upper(), category, protocol)

        if selected_parameters in self.active_servers:
            connection_name = self.active_servers[selected_parameters]['name']

            if networkmanager.set_auto_connect(connection_name):
                networkmanager.disconnect_active_vpn(self.active_servers)
                if networkmanager.enable_connection(connection_name):
                    enabled = True
        else:
            self.logger.error(
                "Auto-connect not activated: No active server found matching [%s, %s, %s].",
                country_code, category, protocol)

        return enabled