summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-03-27 11:47:47 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-04-03 15:41:18 +0200
commitd87aab6373338b67e0c24ed33942a615c4809d0d (patch)
tree635f706b08f657efffe48e24cc4d7dc6fc24641d
parentf4539da172c60533c98cc703f228591d59ca517d (diff)
[feat] store what was the last vpn provider used
To allow automatic connection to the VPN we are storing the last provider in a file. - Resolves: #8806
-rw-r--r--src/leap/bitmask/vpn/service.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py
index 0a26b28..f6c7359 100644
--- a/src/leap/bitmask/vpn/service.py
+++ b/src/leap/bitmask/vpn/service.py
@@ -35,6 +35,7 @@ from leap.common.files import check_and_fix_urw_only
class VPNService(HookableService):
name = 'vpn'
+ _last_vpn_path = os.path.join('leap', 'providers', 'last_vpn')
def __init__(self, basepath=None):
"""
@@ -68,6 +69,7 @@ class VPNService(HookableService):
self._vpn.start()
self._started = True
self._domain = domain
+ self._write_last(domain)
defer.returnValue({'result': 'started'})
def stop_vpn(self):
@@ -87,7 +89,12 @@ class VPNService(HookableService):
}
if self._vpn:
status = self._vpn.get_status()
+
+ if self._domain:
status['domain'] = self._domain
+ else:
+ status['domain'] = self._read_last()
+
return status
def do_check(self, domain):
@@ -152,3 +159,17 @@ class VPNService(HookableService):
self._vpn = VPNManager(provider, remotes, cert_path, key_path, ca_path,
extra_flags)
+
+ def _write_last(self, domain):
+ path = os.path.join(self._basepath, self._last_vpn_path)
+ with open(path, 'w') as f:
+ f.write(domain)
+
+ def _read_last(self):
+ path = os.path.join(self._basepath, self._last_vpn_path)
+ try:
+ with open(path, 'r') as f:
+ domain = f.read()
+ except IOError:
+ domain = None
+ return domain