From d87aab6373338b67e0c24ed33942a615c4809d0d Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 27 Mar 2017 11:47:47 +0200 Subject: [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 --- src/leap/bitmask/vpn/service.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/leap/bitmask/vpn/service.py') diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py index 0a26b28c..f6c73592 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 -- cgit v1.2.3