def _start_eip(self, restart=False): """ Start EIP :param restart: whether is is a restart. :type restart: bool """ provider_config = self._provider_config eip_config = eipconfig.EIPConfig() domain = provider_config.get_domain() loaded = eipconfig.load_eipconfig_if_needed(provider_config, eip_config, domain) if not self._can_start(domain): if self._signaler is not None: self._signaler.signal(self._signaler.eip_connection_aborted) return if not loaded: if self._signaler is not None: self._signaler.signal(self._signaler.eip_connection_aborted) logger.error("Tried to start EIP but cannot find any " "available provider!") return host, port = get_openvpn_management() self._vpn.start(eipconfig=eip_config, providerconfig=provider_config, socket_host=host, socket_port=port, restart=restart)
def _can_start(self, domain): """ Returns True if it has everything that is needed to run EIP, False otherwise :param domain: the domain for the provider to check :type domain: str """ if not LinuxPolicyChecker.is_up(): logger.error("No polkit agent running.") return False eip_config = eipconfig.EIPConfig() provider_config = ProviderConfig.get_provider_config(domain) api_version = provider_config.get_api_version() eip_config.set_api_version(api_version) eip_loaded = eip_config.load(eipconfig.get_eipconfig_path(domain)) launcher = get_vpn_launcher() ovpn_path = force_eval(launcher.OPENVPN_BIN_PATH) if not os.path.isfile(ovpn_path): logger.error("Cannot start OpenVPN, binary not found: %s" % (ovpn_path, )) return False # check for other problems if not eip_loaded or provider_config is None: logger.error("Cannot load provider and eip config, cannot " "autostart") return False client_cert_path = eip_config.\ get_client_cert_path(provider_config, about_to_download=True) if leap_certs.should_redownload(client_cert_path): logger.error("The client should redownload the certificate," " cannot autostart") return False if not os.path.isfile(client_cert_path): logger.error("Can't find the certificate, cannot autostart") return False return True
def get_gateway_country_code(self, domain): """ Signal the country code for the currently used gateway for the given provider. :param domain: the domain to get country code. :type domain: str Signals: eip_get_gateway_country_code -> str eip_no_gateway """ settings = Settings() eip_config = eipconfig.EIPConfig() provider_config = ProviderConfig.get_provider_config(domain) api_version = provider_config.get_api_version() eip_config.set_api_version(api_version) eip_config.load(eipconfig.get_eipconfig_path(domain)) gateway_selector = eipconfig.VPNGatewaySelector(eip_config) gateway_conf = settings.get_selected_gateway(domain) if gateway_conf == GATEWAY_AUTOMATIC: gateways = gateway_selector.get_gateways() else: gateways = [gateway_conf] if not gateways: self._signaler.signal(self._signaler.eip_no_gateway) return # this only works for selecting the first gateway, as we're # currently doing. ccodes = gateway_selector.get_gateways_country_code() gateway_ccode = '' # '' instead of None due to needed signal argument if ccodes is not None: gateway_ccode = ccodes[gateways[0]] self._signaler.signal(self._signaler.eip_get_gateway_country_code, gateway_ccode)
def get_gateways_list(self, domain): """ Signal a list of gateways for the given provider. :param domain: the domain to get the gateways. :type domain: str Signals: eip_get_gateways_list -> list of unicode eip_get_gateways_list_error eip_uninitialized_provider """ if not self._provider_is_initialized(domain): if self._signaler is not None: self._signaler.signal( self._signaler.eip_uninitialized_provider) return eip_config = eipconfig.EIPConfig() provider_config = ProviderConfig.get_provider_config(domain) api_version = provider_config.get_api_version() eip_config.set_api_version(api_version) eip_loaded = eip_config.load(eipconfig.get_eipconfig_path(domain)) # check for other problems if not eip_loaded or provider_config is None: if self._signaler is not None: self._signaler.signal( self._signaler.eip_get_gateways_list_error) return gateways = eipconfig.VPNGatewaySelector(eip_config).get_gateways_list() if self._signaler is not None: self._signaler.signal(self._signaler.eip_get_gateways_list, gateways)