summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-08-31 10:58:59 +0200
committerRuben Pollan <meskio@sindominio.net>2017-08-31 19:21:42 +0200
commit808f9d3542e21c819beb8fe72224f000ae2e019c (patch)
tree661e9e098103658a49d4e9170128c8592464249e /src/leap/bitmask/vpn
parentf721c5ef0cdd9952d014a1dc9e3a944afc0f7f45 (diff)
[feat] expose an API to set/get/list gateway preferences
- Related: #9010
Diffstat (limited to 'src/leap/bitmask/vpn')
-rw-r--r--src/leap/bitmask/vpn/service.py57
1 files changed, 37 insertions, 20 deletions
diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py
index 6588e1d..c410f7e 100644
--- a/src/leap/bitmask/vpn/service.py
+++ b/src/leap/bitmask/vpn/service.py
@@ -50,7 +50,7 @@ class VPNService(HookableService):
_last_vpn_path = os.path.join('leap', 'last_vpn')
log = Logger()
- def __init__(self, basepath=None):
+ def __init__(self, cfg, basepath=None):
"""
Initialize VPN service. This launches both the firewall and the vpn.
"""
@@ -59,12 +59,24 @@ class VPNService(HookableService):
self._tunnel = None
self._firewall = FirewallManager([])
self._domain = ''
+ self._cfg = cfg
if basepath is None:
self._basepath = get_path_prefix()
else:
self._basepath = basepath
+ try:
+ _cco = self._cfg.get('countries', "")
+ self._cco = json.loads(_cco)
+ except ValueError:
+ self._cco = []
+ try:
+ _loc = self._cfg.get('locations', "")
+ self._loc = json.loads(_loc)
+ except ValueError:
+ self._loc = []
+
if helpers.check() and self._firewall.is_up():
self._firewall.stop()
@@ -194,10 +206,29 @@ class VPNService(HookableService):
config = yield bonafide.do_provider_read(provider, 'eip')
except ValueError:
continue
- gateways = self._gateways(config)
+ gateways = GatewaySelector(
+ config.gateways, config.locations,
+ preferred={'cc': self._cco, 'loc': self._loc}
+ )
provider_dict[provider] = gateways.get_sorted_gateways()
defer.returnValue(provider_dict)
+ def do_set_locations(self, locations):
+ self._loc = locations
+ self._cfg.set('locations', json.dumps(locations))
+ return {'locations': 'ok'}
+
+ def do_get_locations(self):
+ return self._loc
+
+ def do_set_countries(self, countries):
+ self._cco = countries
+ self._cfg.set('countries', json.dumps(countries))
+ return {'countries': 'ok'}
+
+ def do_get_countries(self):
+ return self._cco
+
@defer.inlineCallbacks
def _setup(self, provider):
"""Set up ConfiguredTunnel for a specified provider.
@@ -208,7 +239,10 @@ class VPNService(HookableService):
bonafide = self.parent.getServiceNamed('bonafide')
config = yield bonafide.do_provider_read(provider, 'eip')
- sorted_gateways = self._gateways(config).select_gateways()
+ sorted_gateways = GatewaySelector(
+ config.gateways, config.locations,
+ preferred={'cc': self._cco, 'loc': self._loc}
+ ).select_gateways()
extra_flags = config.openvpn_configuration
@@ -231,23 +265,6 @@ class VPNService(HookableService):
provider, remotes, cert_path, key_path, ca_path, extra_flags)
self._firewall = FirewallManager(remotes)
- def _gateways(self, config):
- try:
- _cco = self.parent.get_config('vpn_prefs', 'countries', "")
- pref_cco = json.loads(_cco)
- except ValueError:
- pref_cco = []
- try:
- _loc = self.parent.get_config('vpn_prefs', 'locations', "")
- pref_loc = json.loads(_loc)
- except ValueError:
- pref_loc = []
-
- return GatewaySelector(
- config.gateways, config.locations,
- preferred={'cc': pref_cco, 'loc': pref_loc}
- )
-
def _cert_expires(self, provider):
path = os.path.join(
self._basepath, "leap", "providers", provider,