summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/cli
diff options
context:
space:
mode:
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)