From af3866350e94c9238889a1c2485661466b1ec2dc Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Wed, 1 Mar 2017 01:58:05 +0100 Subject: [bug] use username instead of provider in the vpn calls Without active user we need to use the username instead of the provider in the VPN API. - Resolves: #8783 --- src/leap/bitmask/cli/command.py | 4 +-- src/leap/bitmask/cli/vpn.py | 67 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 67 insertions(+), 4 deletions(-) (limited to 'src/leap/bitmask/cli') diff --git a/src/leap/bitmask/cli/command.py b/src/leap/bitmask/cli/command.py index a4757f80..068f19b5 100644 --- a/src/leap/bitmask/cli/command.py +++ b/src/leap/bitmask/cli/command.py @@ -42,9 +42,9 @@ def default_dict_printer(result): if not result: return for key, value in result.items(): - if value is None: + if value is not str: value = str(value) - if value in ('OFF', 'OFFLINE', 'ABORTED'): + if value in ('OFF', 'OFFLINE', 'ABORTED', 'False'): color = Fore.RED else: color = Fore.GREEN diff --git a/src/leap/bitmask/cli/vpn.py b/src/leap/bitmask/cli/vpn.py index d80b7f39..69825159 100644 --- a/src/leap/bitmask/cli/vpn.py +++ b/src/leap/bitmask/cli/vpn.py @@ -17,6 +17,9 @@ """ Bitmask Command Line interface: vpn module """ +import argparse +import sys + from leap.bitmask.cli import command @@ -40,6 +43,66 @@ SUBCOMMANDS: '''.format(name=command.appname) - commands = ['start', 'stop', 'status', 'check', - 'get_cert', 'install', 'uninstall', + commands = ['stop', 'status', 'install', 'uninstall', 'enable', 'disable'] + + def start(self, raw_args): + parser = argparse.ArgumentParser( + description='Bitmask VPN start', + prog='%s %s %s' % tuple(sys.argv[:3])) + parser.add_argument('provider', nargs='?', default=None, + help='provider to start the VPN') + subargs = parser.parse_args(raw_args) + + provider = None + if subargs.provider: + provider = subargs.provider + else: + uid = self.cfg.get('bonafide', 'active', default=None) + try: + _, provider = uid.split('@') + except ValueError: + raise ValueError("A provider is needed to start the VPN") + + self.data += ['start', provider] + + return self._send(command.default_dict_printer) + + def check(self, raw_args): + parser = argparse.ArgumentParser( + description='Bitmask VPN check', + prog='%s %s %s' % tuple(sys.argv[:3])) + parser.add_argument('provider', nargs='?', default=None, + help='provider to check the VPN') + subargs = parser.parse_args(raw_args) + + provider = None + if subargs.provider: + provider = subargs.provider + else: + uid = self.cfg.get('bonafide', 'active', default=None) + try: + _, provider = uid.split('@') + except ValueError: + raise ValueError("A provider is needed to start the VPN") + + self.data += ['check', provider] + + return self._send(command.default_dict_printer) + + def get_cert(self, raw_args): + parser = argparse.ArgumentParser( + description='Bitmask VPN cert fetcher', + prog='%s %s %s' % tuple(sys.argv[:3])) + parser.add_argument('uid', nargs='?', default=None, + help='uid to fetch the VPN cert') + subargs = parser.parse_args(raw_args) + + uid = None + if subargs.uid: + uid = subargs.uid + else: + uid = self.cfg.get('bonafide', 'active', default=None) + self.data += ['get_cert', uid] + + return self._send(command.default_dict_printer) -- cgit v1.2.3