summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/services')
-rw-r--r--src/leap/bitmask/services/__init__.py10
-rw-r--r--src/leap/bitmask/services/eip/eipconfig.py2
-rw-r--r--src/leap/bitmask/services/eip/vpnlaunchers.py64
3 files changed, 52 insertions, 24 deletions
diff --git a/src/leap/bitmask/services/__init__.py b/src/leap/bitmask/services/__init__.py
index 924ca547..339f9cc6 100644
--- a/src/leap/bitmask/services/__init__.py
+++ b/src/leap/bitmask/services/__init__.py
@@ -26,6 +26,8 @@ DEPLOYED = ["openvpn", "mx"]
def get_service_display_name(service, standalone=False):
"""
Returns the name to display of the given service.
+ If there is no configured name for that service, then returns the same
+ parameter
:param service: the 'machine' service name
:type service: str
@@ -42,8 +44,10 @@ def get_service_display_name(service, standalone=False):
EIP_LABEL = _tr("Encrypted Internet")
MX_LABEL = _tr("Encrypted Mail")
- service_display = [EIP_LABEL, MX_LABEL]
- service_config = ["openvpn", "mx"]
+ service_display = {
+ "openvpn": EIP_LABEL,
+ "mx": MX_LABEL
+ }
# If we need to add a warning about eip needing
# administrative permissions to start. That can be either
@@ -52,7 +56,7 @@ def get_service_display_name(service, standalone=False):
if standalone or is_missing_policy_permissions():
EIP_LABEL += " " + _tr("(will need admin password to start)")
- return service_display[service_config.index(service)]
+ return service_display.get(service, service)
def get_supported(services):
diff --git a/src/leap/bitmask/services/eip/eipconfig.py b/src/leap/bitmask/services/eip/eipconfig.py
index 1f49f9cd..1cb7419e 100644
--- a/src/leap/bitmask/services/eip/eipconfig.py
+++ b/src/leap/bitmask/services/eip/eipconfig.py
@@ -141,7 +141,7 @@ class VPNGatewaySelector(object):
if time.daylight:
local_offset = time.altzone
- return local_offset / 3600
+ return -local_offset / 3600
class EIPConfig(BaseConfig):
diff --git a/src/leap/bitmask/services/eip/vpnlaunchers.py b/src/leap/bitmask/services/eip/vpnlaunchers.py
index 5921882b..49edc8eb 100644
--- a/src/leap/bitmask/services/eip/vpnlaunchers.py
+++ b/src/leap/bitmask/services/eip/vpnlaunchers.py
@@ -23,8 +23,8 @@ import logging
import getpass
import os
import platform
-import subprocess
import stat
+import subprocess
try:
import grp
except ImportError:
@@ -34,6 +34,7 @@ from abc import ABCMeta, abstractmethod
from functools import partial
from leap.bitmask.config.leapsettings import LeapSettings
+
from leap.bitmask.config.providerconfig import ProviderConfig
from leap.bitmask.services.eip.eipconfig import EIPConfig, VPNGatewaySelector
from leap.bitmask.util import first
@@ -218,19 +219,19 @@ def _is_auth_agent_running():
return any(is_running)
-def _try_to_launch_agent():
+def _try_to_launch_agent(standalone=False):
"""
Tries to launch a polkit daemon.
"""
- opts = [
- "/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1",
- # XXX add kde thing here
- ]
- for cmd in opts:
- try:
- subprocess.Popen([cmd], shell=True)
- except:
- pass
+ env = None
+ if standalone is True:
+ env = {
+ "PYTHONPATH": os.path.abspath('../../../../lib/')}
+ try:
+ subprocess.call(["python", "-m", "leap.bitmask.util.polkit_agent"],
+ shell=True, env=env)
+ except Exception as exc:
+ logger.exception(exc)
class LinuxVPNLauncher(VPNLauncher):
@@ -314,7 +315,7 @@ class LinuxVPNLauncher(VPNLauncher):
"""
if _is_pkexec_in_system():
if not _is_auth_agent_running():
- _try_to_launch_agent()
+ _try_to_launch_agent(ProviderConfig.standalone)
if _is_auth_agent_running():
pkexec_possibilities = which(kls.PKEXEC_BIN)
leap_assert(len(pkexec_possibilities) > 0,
@@ -430,7 +431,7 @@ class LinuxVPNLauncher(VPNLauncher):
logger.error('No gateway was found!')
raise VPNLauncherException(self.tr('No gateway was found!'))
- logger.debug("Using gateways ips: {}".format(', '.join(gateways)))
+ logger.debug("Using gateways ips: {0}".format(', '.join(gateways)))
for gw in gateways:
args += ['--remote', gw, '1194', 'udp']
@@ -678,11 +679,22 @@ class DarwinVPNLauncher(VPNLauncher):
if openvpn_verb is not None:
args += ['--verb', '%d' % (openvpn_verb,)]
- gateway_selector = VPNGatewaySelector(eipconfig)
- gateways = gateway_selector.get_gateways()
+ 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: {gw}".format(
- gw=', '.join(gateways)))
+ logger.debug("Using gateways ips: {0}".format(', '.join(gateways)))
for gw in gateways:
args += ['--remote', gw, '1194', 'udp']
@@ -850,10 +862,22 @@ class WindowsVPNLauncher(VPNLauncher):
if openvpn_verb is not None:
args += ['--verb', '%d' % (openvpn_verb,)]
- gateway_selector = VPNGatewaySelector(eipconfig)
- gateways = gateway_selector.get_gateways()
+ 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: {}".format(', '.join(gateways)))
+ logger.debug("Using gateways ips: {0}".format(', '.join(gateways)))
for gw in gateways:
args += ['--remote', gw, '1194', 'udp']