summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/cli
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-03-01 01:58:05 +0100
committerRuben Pollan <meskio@sindominio.net>2017-03-03 10:50:53 +0100
commitaf3866350e94c9238889a1c2485661466b1ec2dc (patch)
tree950511ec09ea238abb58de7ac28f2a5f19abec73 /src/leap/bitmask/cli
parent4003aaaa124b1ffa77d07f7e2ae5d16e2dddacf1 (diff)
[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
Diffstat (limited to 'src/leap/bitmask/cli')
-rw-r--r--src/leap/bitmask/cli/command.py4
-rw-r--r--src/leap/bitmask/cli/vpn.py67
2 files changed, 67 insertions, 4 deletions
diff --git a/src/leap/bitmask/cli/command.py b/src/leap/bitmask/cli/command.py
index a4757f8..068f19b 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 d80b7f3..6982515 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)