本文整理汇总了Python中leap.bitmask.config.leapsettings.LeapSettings.get_selected_gateway方法的典型用法代码示例。如果您正苦于以下问题:Python LeapSettings.get_selected_gateway方法的具体用法?Python LeapSettings.get_selected_gateway怎么用?Python LeapSettings.get_selected_gateway使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类leap.bitmask.config.leapsettings.LeapSettings
的用法示例。
在下文中一共展示了LeapSettings.get_selected_gateway方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_gateways
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import get_selected_gateway [as 别名]
def get_gateways(kls, eipconfig, providerconfig):
"""
Return the selected gateways for a given provider, looking at the EIP
config file.
:param eipconfig: eip configuration object
:type eipconfig: EIPConfig
:param providerconfig: provider specific configuration
:type providerconfig: ProviderConfig
:rtype: list
"""
gateways = []
leap_settings = LeapSettings()
domain = providerconfig.get_domain()
gateway_conf = leap_settings.get_selected_gateway(domain)
gateway_selector = VPNGatewaySelector(eipconfig)
if gateway_conf == leap_settings.GATEWAY_AUTOMATIC:
gateways = gateway_selector.get_gateways()
else:
gateways = [gateway_conf]
if not gateways:
logger.error('No gateway was found!')
raise VPNLauncherException('No gateway was found!')
# this only works for selecting the first gateway, as we're
# currently doing.
ccodes = gateway_selector.get_gateways_country_code()
gateway_ccode = ccodes[gateways[0]]
flags.CURRENT_VPN_COUNTRY = gateway_ccode
logger.debug("Using gateways ips: {0}".format(', '.join(gateways)))
return gateways
示例2: PreferencesWindow
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import get_selected_gateway [as 别名]
#.........这里部分代码省略.........
:param domain: the domain name of the provider.
:type domain: str
:rtype: ProviderConfig or None if there is a problem loading the config
"""
provider_config = ProviderConfig()
provider_config_path = os.path.join(
"leap", "providers", domain, "provider.json")
if not provider_config.load(provider_config_path):
provider_config = None
return provider_config
def _save_selected_gateway(self, provider):
"""
SLOT
TRIGGERS:
self.ui.pbSaveGateway.clicked
Saves the new gateway setting to the configuration file.
:param provider: the provider config that we need to save.
:type provider: str
"""
gateway = self.ui.cbGateways.currentText()
if gateway == self.AUTOMATIC_GATEWAY_LABEL:
gateway = self._settings.GATEWAY_AUTOMATIC
else:
idx = self.ui.cbGateways.currentIndex()
gateway = self.ui.cbGateways.itemData(idx)
self._settings.set_selected_gateway(provider, gateway)
msg = self.tr(
"Gateway settings for provider '{0}' saved.".format(provider))
logger.debug(msg)
self._set_providers_gateway_status(msg, success=True)
def _populate_gateways(self, domain):
"""
SLOT
TRIGGERS:
self.ui.cbProvidersGateway.currentIndexChanged[unicode]
Loads the gateways that the provider provides into the UI for
the user to select.
:param domain: the domain of the provider to load gateways from.
:type domain: str
"""
# We hide the maybe-visible status label after a change
self.ui.lblProvidersGatewayStatus.setVisible(False)
if not domain:
return
try:
# disconnect prevoiusly connected save method
self.ui.pbSaveGateway.clicked.disconnect()
except RuntimeError:
pass # Signal was not connected
# set the proper connection for the 'save' button
save_gateway = partial(self._save_selected_gateway, domain)
self.ui.pbSaveGateway.clicked.connect(save_gateway)
eip_config = EIPConfig()
provider_config = self._get_provider_config(domain)
eip_config_path = os.path.join("leap", "providers",
domain, "eip-service.json")
api_version = provider_config.get_api_version()
eip_config.set_api_version(api_version)
eip_loaded = eip_config.load(eip_config_path)
if not eip_loaded or provider_config is None:
self._set_providers_gateway_status(
self.tr("There was a problem with configuration files."),
error=True)
return
gateways = VPNGatewaySelector(eip_config).get_gateways_list()
logger.debug(gateways)
self.ui.cbGateways.clear()
self.ui.cbGateways.addItem(self.AUTOMATIC_GATEWAY_LABEL)
# Add the available gateways and
# select the one stored in configuration file.
selected_gateway = self._settings.get_selected_gateway(domain)
index = 0
for idx, (gw_name, gw_ip) in enumerate(gateways):
gateway = "{0} ({1})".format(gw_name, gw_ip)
self.ui.cbGateways.addItem(gateway, gw_ip)
if gw_ip == selected_gateway:
index = idx + 1
self.ui.cbGateways.setCurrentIndex(index)
示例3: EIPPreferencesWindow
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import get_selected_gateway [as 别名]
#.........这里部分代码省略.........
"""
Add the client's configured providers to the providers combo boxes.
"""
self.ui.cbProvidersGateway.clear()
self.ui.cbProvidersEIP.clear()
providers = self._settings.get_configured_providers()
if not providers:
self.ui.gbAutomaticEIP.setEnabled(False)
self.ui.gbGatewaySelector.setEnabled(False)
return
for provider in providers:
self.ui.cbProvidersGateway.addItem(provider)
self.ui.cbProvidersEIP.addItem(provider)
def _save_selected_gateway(self, provider):
"""
SLOT
TRIGGERS:
self.ui.pbSaveGateway.clicked
Saves the new gateway setting to the configuration file.
:param provider: the provider config that we need to save.
:type provider: str
"""
gateway = self.ui.cbGateways.currentText()
if gateway == self.AUTOMATIC_GATEWAY_LABEL:
gateway = self._settings.GATEWAY_AUTOMATIC
else:
idx = self.ui.cbGateways.currentIndex()
gateway = self.ui.cbGateways.itemData(idx)
self._settings.set_selected_gateway(provider, gateway)
msg = self.tr(
"Gateway settings for provider '{0}' saved.").format(provider)
self._set_providers_gateway_status(msg, success=True)
def _populate_gateways(self, domain):
"""
SLOT
TRIGGERS:
self.ui.cbProvidersGateway.currentIndexChanged[unicode]
Loads the gateways that the provider provides into the UI for
the user to select.
:param domain: the domain of the provider to load gateways from.
:type domain: str
"""
# We hide the maybe-visible status label after a change
self.ui.lblProvidersGatewayStatus.setVisible(False)
if not domain:
return
try:
# disconnect previously connected save method
self.ui.pbSaveGateway.clicked.disconnect()
except RuntimeError:
pass # Signal was not connected
# set the proper connection for the 'save' button
save_gateway = partial(self._save_selected_gateway, domain)
self.ui.pbSaveGateway.clicked.connect(save_gateway)
eip_config = EIPConfig()
provider_config = ProviderConfig.get_provider_config(domain)
eip_config_path = os.path.join("leap", "providers",
domain, "eip-service.json")
api_version = provider_config.get_api_version()
eip_config.set_api_version(api_version)
eip_loaded = eip_config.load(eip_config_path)
if not eip_loaded or provider_config is None:
self._set_providers_gateway_status(
self.tr("There was a problem with configuration files."),
error=True)
return
gateways = VPNGatewaySelector(eip_config).get_gateways_list()
logger.debug(gateways)
self.ui.cbGateways.clear()
self.ui.cbGateways.addItem(self.AUTOMATIC_GATEWAY_LABEL)
# Add the available gateways and
# select the one stored in configuration file.
selected_gateway = self._settings.get_selected_gateway(domain)
index = 0
for idx, (gw_name, gw_ip) in enumerate(gateways):
gateway = "{0} ({1})".format(gw_name, gw_ip)
self.ui.cbGateways.addItem(gateway, gw_ip)
if gw_ip == selected_gateway:
index = idx + 1
self.ui.cbGateways.setCurrentIndex(index)
示例4: get_vpn_command
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import get_selected_gateway [as 别名]
def get_vpn_command(
self, eipconfig=None, providerconfig=None, socket_host=None, socket_port="9876", openvpn_verb=1
):
"""
Returns the platform dependant vpn launching command. It will
look for openvpn in the regular paths and algo in
path_prefix/apps/eip/ (in case standalone is set)
Might raise VPNException.
:param eipconfig: eip configuration object
:type eipconfig: EIPConfig
:param providerconfig: provider specific configuration
:type providerconfig: ProviderConfig
:param socket_host: either socket path (unix) or socket IP
:type socket_host: str
:param socket_port: either string "unix" if it's a unix
socket, or port otherwise
:type socket_port: str
:param openvpn_verb: the openvpn verbosity wanted
:type openvpn_verb: int
:return: A VPN command ready to be launched
:rtype: list
"""
leap_assert(eipconfig, "We need an eip config")
leap_assert_type(eipconfig, EIPConfig)
leap_assert(providerconfig, "We need a provider config")
leap_assert_type(providerconfig, ProviderConfig)
leap_assert(socket_host, "We need a socket host!")
leap_assert(socket_port, "We need a socket port!")
leap_assert(socket_port != "unix", "We cannot use unix sockets in windows!")
openvpn_possibilities = which(
self.OPENVPN_BIN, path_extension=os.path.join(providerconfig.get_path_prefix(), "..", "apps", "eip")
)
if len(openvpn_possibilities) == 0:
raise OpenVPNNotFoundException()
openvpn = first(openvpn_possibilities)
args = []
args += ["--setenv", "LEAPOPENVPN", "1"]
if openvpn_verb is not None:
args += ["--verb", "%d" % (openvpn_verb,)]
gateways = []
leap_settings = LeapSettings(ProviderConfig.standalone)
domain = providerconfig.get_domain()
gateway_conf = leap_settings.get_selected_gateway(domain)
if gateway_conf == leap_settings.GATEWAY_AUTOMATIC:
gateway_selector = VPNGatewaySelector(eipconfig)
gateways = gateway_selector.get_gateways()
else:
gateways = [gateway_conf]
if not gateways:
logger.error("No gateway was found!")
raise VPNLauncherException(self.tr("No gateway was found!"))
logger.debug("Using gateways ips: {0}".format(", ".join(gateways)))
for gw in gateways:
args += ["--remote", gw, "1194", "udp"]
args += [
"--client",
"--dev",
"tun",
##############################################################
# persist-tun makes ping-restart fail because it leaves a
# broken routing table
##############################################################
# '--persist-tun',
"--persist-key",
"--tls-client",
# We make it log to a file because we cannot attach to the
# openvpn process' stdout since it's a process with more
# privileges than we are
"--log-append",
"eip.log",
"--remote-cert-tls",
"server",
]
openvpn_configuration = eipconfig.get_openvpn_configuration()
for key, value in openvpn_configuration.items():
args += ["--%s" % (key,), value]
##############################################################
# The down-root plugin fails in some situations, so we don't
# drop privs for the time being
##############################################################
#.........这里部分代码省略.........
示例5: EIPPreferencesWindow
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import get_selected_gateway [as 别名]
#.........这里部分代码省略.........
"""
TRIGGERS:
self.ui.cbProvidersGateway.currentIndexChanged[unicode]
Loads the gateways that the provider provides into the UI for
the user to select.
:param domain: the domain index of the provider to load gateways from.
:type domain: int
"""
# We hide the maybe-visible status label after a change
self.ui.lblProvidersGatewayStatus.setVisible(False)
if domain_idx == -1:
return
domain = self.ui.cbProvidersGateway.itemData(domain_idx)
self._selected_domain = domain
self._backend.eip_get_gateways_list(domain=domain)
@QtCore.Slot(list)
def _update_gateways_list(self, gateways):
"""
TRIGGERS:
Signaler.eip_get_gateways_list
:param gateways: a list of gateways
:type gateways: list of unicode
Add the available gateways and select the one stored in configuration
file.
"""
self.ui.pbSaveGateway.setEnabled(True)
self.ui.cbGateways.setEnabled(True)
self.ui.cbGateways.clear()
self.ui.cbGateways.addItem(self.AUTOMATIC_GATEWAY_LABEL)
try:
# disconnect previously connected save method
self.ui.pbSaveGateway.clicked.disconnect()
except RuntimeError:
pass # Signal was not connected
# set the proper connection for the 'save' button
domain = self._selected_domain
save_gateway = partial(self._save_selected_gateway, domain)
self.ui.pbSaveGateway.clicked.connect(save_gateway)
selected_gateway = self._settings.get_selected_gateway(
self._selected_domain)
index = 0
for idx, (gw_name, gw_ip) in enumerate(gateways):
gateway = "{0} ({1})".format(gw_name, gw_ip)
self.ui.cbGateways.addItem(gateway, gw_ip)
if gw_ip == selected_gateway:
index = idx + 1
self.ui.cbGateways.setCurrentIndex(index)
@QtCore.Slot()
def _gateways_list_error(self):
"""
TRIGGERS:
Signaler.eip_get_gateways_list_error
An error has occurred retrieving the gateway list so we inform the
user.
"""
self._set_providers_gateway_status(
self.tr("There was a problem with configuration files."),
error=True)
self.ui.pbSaveGateway.setEnabled(False)
self.ui.cbGateways.setEnabled(False)
@QtCore.Slot()
def _gateways_list_uninitialized(self):
"""
TRIGGERS:
Signaler.eip_uninitialized_provider
The requested provider in not initialized yet, so we give the user an
error msg.
"""
self._set_providers_gateway_status(
self.tr("This is an uninitialized provider, please log in first."),
error=True)
self.ui.pbSaveGateway.setEnabled(False)
self.ui.cbGateways.setEnabled(False)
def _backend_connect(self):
sig = self._leap_signaler
sig.eip_get_gateways_list.connect(self._update_gateways_list)
sig.eip_get_gateways_list_error.connect(self._gateways_list_error)
sig.eip_uninitialized_provider.connect(
self._gateways_list_uninitialized)
sig.eip_get_initialized_providers.connect(
self._load_providers_in_combo)
示例6: EIPPreferencesWindow
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import get_selected_gateway [as 别名]
#.........这里部分代码省略.........
domain, QtCore.Qt.MatchStartsWith)
self.ui.cbProvidersGateway.setCurrentIndex(provider_index)
def _save_selected_gateway(self, provider):
"""
SLOT
TRIGGERS:
self.ui.pbSaveGateway.clicked
Saves the new gateway setting to the configuration file.
:param provider: the provider config that we need to save.
:type provider: str
"""
gateway = self.ui.cbGateways.currentText()
if gateway == self.AUTOMATIC_GATEWAY_LABEL:
gateway = self._settings.GATEWAY_AUTOMATIC
else:
idx = self.ui.cbGateways.currentIndex()
gateway = self.ui.cbGateways.itemData(idx)
self._settings.set_selected_gateway(provider, gateway)
msg = self.tr(
"Gateway settings for provider '{0}' saved.").format(provider)
self._set_providers_gateway_status(msg, success=True)
def _populate_gateways(self, domain_idx):
"""
SLOT
TRIGGERS:
self.ui.cbProvidersGateway.currentIndexChanged[unicode]
Loads the gateways that the provider provides into the UI for
the user to select.
:param domain: the domain index of the provider to load gateways from.
:type domain: int
"""
# We hide the maybe-visible status label after a change
self.ui.lblProvidersGatewayStatus.setVisible(False)
if domain_idx == -1:
return
domain = self.ui.cbProvidersGateway.itemData(domain_idx)
if not os.path.isfile(get_eipconfig_path(domain, relative=False)):
self._set_providers_gateway_status(
self.tr("This is an uninitialized provider, "
"please log in first."),
error=True)
self.ui.pbSaveGateway.setEnabled(False)
self.ui.cbGateways.setEnabled(False)
return
else:
self.ui.pbSaveGateway.setEnabled(True)
self.ui.cbGateways.setEnabled(True)
try:
# disconnect previously connected save method
self.ui.pbSaveGateway.clicked.disconnect()
except RuntimeError:
pass # Signal was not connected
# set the proper connection for the 'save' button
save_gateway = partial(self._save_selected_gateway, domain)
self.ui.pbSaveGateway.clicked.connect(save_gateway)
eip_config = 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(get_eipconfig_path(domain))
if not eip_loaded or provider_config is None:
self._set_providers_gateway_status(
self.tr("There was a problem with configuration files."),
error=True)
return
gateways = VPNGatewaySelector(eip_config).get_gateways_list()
logger.debug(gateways)
self.ui.cbGateways.clear()
self.ui.cbGateways.addItem(self.AUTOMATIC_GATEWAY_LABEL)
# Add the available gateways and
# select the one stored in configuration file.
selected_gateway = self._settings.get_selected_gateway(domain)
index = 0
for idx, (gw_name, gw_ip) in enumerate(gateways):
gateway = "{0} ({1})".format(gw_name, gw_ip)
self.ui.cbGateways.addItem(gateway, gw_ip)
if gw_ip == selected_gateway:
index = idx + 1
self.ui.cbGateways.setCurrentIndex(index)
示例7: get_vpn_command
# 需要导入模块: from leap.bitmask.config.leapsettings import LeapSettings [as 别名]
# 或者: from leap.bitmask.config.leapsettings.LeapSettings import get_selected_gateway [as 别名]
def get_vpn_command(kls, eipconfig, providerconfig,
socket_host, socket_port, openvpn_verb=1):
"""
Returns the platform dependant vpn launching command
Might raise:
OpenVPNNotFoundException,
VPNLauncherException.
:param eipconfig: eip configuration object
:type eipconfig: EIPConfig
:param providerconfig: provider specific configuration
:type providerconfig: ProviderConfig
:param socket_host: either socket path (unix) or socket IP
:type socket_host: str
:param socket_port: either string "unix" if it's a unix socket,
or port otherwise
:type socket_port: str
:param openvpn_verb: the openvpn verbosity wanted
:type openvpn_verb: int
:return: A VPN command ready to be launched.
:rtype: list
"""
leap_assert_type(eipconfig, EIPConfig)
leap_assert_type(providerconfig, ProviderConfig)
kwargs = {}
if flags.STANDALONE:
kwargs['path_extension'] = os.path.join(
get_path_prefix(), "..", "apps", "eip")
openvpn_possibilities = which(kls.OPENVPN_BIN, **kwargs)
if len(openvpn_possibilities) == 0:
raise OpenVPNNotFoundException()
openvpn = first(openvpn_possibilities)
args = []
args += [
'--setenv', "LEAPOPENVPN", "1",
'--nobind'
]
if openvpn_verb is not None:
args += ['--verb', '%d' % (openvpn_verb,)]
gateways = []
leap_settings = LeapSettings()
domain = providerconfig.get_domain()
gateway_conf = leap_settings.get_selected_gateway(domain)
if gateway_conf == leap_settings.GATEWAY_AUTOMATIC:
gateway_selector = VPNGatewaySelector(eipconfig)
gateways = gateway_selector.get_gateways()
else:
gateways = [gateway_conf]
if not gateways:
logger.error('No gateway was found!')
raise VPNLauncherException('No gateway was found!')
logger.debug("Using gateways ips: {0}".format(', '.join(gateways)))
for gw in gateways:
args += ['--remote', gw, '1194', 'udp']
args += [
'--client',
'--dev', 'tun',
##############################################################
# persist-tun makes ping-restart fail because it leaves a
# broken routing table
##############################################################
# '--persist-tun',
'--persist-key',
'--tls-client',
'--remote-cert-tls',
'server'
]
openvpn_configuration = eipconfig.get_openvpn_configuration()
for key, value in openvpn_configuration.items():
args += ['--%s' % (key,), value]
user = getpass.getuser()
##############################################################
# The down-root plugin fails in some situations, so we don't
# drop privs for the time being
##############################################################
# args += [
# '--user', user,
# '--group', grp.getgrgid(os.getgroups()[-1]).gr_name
# ]
if socket_port == "unix": # that's always the case for linux
args += [
'--management-client-user', user
]
#.........这里部分代码省略.........