summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/cli
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/cli')
-rwxr-xr-xsrc/leap/bitmask/cli/bitmask_cli.py16
-rw-r--r--src/leap/bitmask/cli/command.py4
-rw-r--r--src/leap/bitmask/cli/keys.py24
-rw-r--r--src/leap/bitmask/cli/mail.py9
-rw-r--r--src/leap/bitmask/cli/user.py33
5 files changed, 63 insertions, 23 deletions
diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py
index dfd1fbc..782a52e 100755
--- a/src/leap/bitmask/cli/bitmask_cli.py
+++ b/src/leap/bitmask/cli/bitmask_cli.py
@@ -25,6 +25,7 @@ import signal
from colorama import Fore
from twisted.internet import reactor, defer
+from leap.bitmask.config import Configuration
from leap.bitmask.cli.eip import Eip
from leap.bitmask.cli.keys import Keys
from leap.bitmask.cli.mail import Mail
@@ -62,27 +63,27 @@ GENERAL COMMANDS:
"about each command.")
def user(self, raw_args):
- user = User()
+ user = User(self.cfg)
return user.execute(raw_args)
def mail(self, raw_args):
- mail = Mail()
+ mail = Mail(self.cfg)
return mail.execute(raw_args)
def eip(self, raw_args):
- eip = Eip()
+ eip = Eip(self.cfg)
return eip.execute(raw_args)
def keys(self, raw_args):
- keys = Keys()
+ keys = Keys(self.cfg)
return keys.execute(raw_args)
def ui(self, raw_args):
- webui = WebUI()
+ webui = WebUI(self.cfg)
return webui.execute(raw_args)
def logs(self, raw_args):
- logs = Logs()
+ logs = Logs(self.cfg)
return logs.execute(raw_args)
# Single commands
@@ -129,7 +130,8 @@ GENERAL COMMANDS:
@defer.inlineCallbacks
def execute():
- cli = BitmaskCLI()
+ cfg = Configuration("bitmaskctl.cfg")
+ cli = BitmaskCLI(cfg)
cli.data = ['core', 'version']
args = ['--verbose'] if '--verbose' in sys.argv else None
yield cli._send(
diff --git a/src/leap/bitmask/cli/command.py b/src/leap/bitmask/cli/command.py
index 16f483a..95b0fe8 100644
--- a/src/leap/bitmask/cli/command.py
+++ b/src/leap/bitmask/cli/command.py
@@ -57,7 +57,9 @@ class Command(object):
"about each command.")
commands = []
- def __init__(self):
+ def __init__(self, cfg):
+ self.cfg = cfg
+
color_init()
zf = ZmqFactory()
e = ZmqEndpoint(ZmqEndpointType.connect, ENDPOINT)
diff --git a/src/leap/bitmask/cli/keys.py b/src/leap/bitmask/cli/keys.py
index 65747cb..b11d280 100644
--- a/src/leap/bitmask/cli/keys.py
+++ b/src/leap/bitmask/cli/keys.py
@@ -50,7 +50,11 @@ SUBCOMMANDS:
help='Use private keys (by default uses public)')
subargs = parser.parse_args(raw_args)
- self.data += ['list', subargs.uid]
+ userid = subargs.userid
+ if not userid:
+ userid = self.cfg.get('bonafide', 'active', default='')
+
+ self.data += ['list', userid]
if subargs.private:
self.data += ['private']
else:
@@ -69,7 +73,11 @@ SUBCOMMANDS:
parser.add_argument('address', nargs=1,
help='email address of the key')
subargs = parser.parse_args(raw_args)
- self.data += ['export', subargs.uid, subargs.address[0]]
+
+ userid = subargs.userid
+ if not userid:
+ userid = self.cfg.get('bonafide', 'active', default='')
+ self.data += ['export', userid, subargs.address[0]]
return self._send(self._print_key)
@@ -88,9 +96,13 @@ SUBCOMMANDS:
help='email address of the key')
subargs = parser.parse_args(raw_args)
+ userid = subargs.userid
+ if not userid:
+ userid = self.cfg.get('bonafide', 'active')
+
with open(subargs.file[0], 'r') as keyfile:
rawkey = keyfile.read()
- self.data += ['insert', subargs.uid, subargs.address[0],
+ self.data += ['insert', userid, subargs.address[0],
subargs.validation, rawkey]
return self._send(self._print_key)
@@ -106,8 +118,12 @@ SUBCOMMANDS:
parser.add_argument('address', nargs=1,
help='email address of the key')
subargs = parser.parse_args(raw_args)
- self.data += ['delete', subargs.uid, subargs.address[0]]
+ userid = subargs.userid
+ if not userid:
+ userid = self.cfg.get('bonafide', 'active')
+
+ self.data += ['delete', userid, subargs.address[0]]
return self._send()
def _print_key_list(self, keys):
diff --git a/src/leap/bitmask/cli/mail.py b/src/leap/bitmask/cli/mail.py
index 7fd574b..025804e 100644
--- a/src/leap/bitmask/cli/mail.py
+++ b/src/leap/bitmask/cli/mail.py
@@ -51,8 +51,15 @@ SUBCOMMANDS:
subargs = parser.parse_args(raw_args)
self.data.append('status')
+
+ uid = None
if subargs.uid:
- self.data.append(subargs.uid)
+ uid = subargs.uid
+ else:
+ uid = self.cfg.get('bonafide', 'active', default=None)
+ if uid:
+ self.data.append(uid)
+
return self._send(self._print_status)
def _print_status(self, status, depth=0):
diff --git a/src/leap/bitmask/cli/user.py b/src/leap/bitmask/cli/user.py
index b802d86..a5cad1b 100644
--- a/src/leap/bitmask/cli/user.py
+++ b/src/leap/bitmask/cli/user.py
@@ -23,6 +23,7 @@ import sys
from copy import copy
from colorama import Fore
+from twisted.internet import defer
from leap.bitmask.cli import command
@@ -44,10 +45,8 @@ SUBCOMMANDS:
'''.format(name=command.appname)
- commands = ['active']
-
- def __init__(self):
- super(User, self).__init__()
+ def __init__(self, cfg):
+ super(User, self).__init__(cfg)
self.data.append('user')
def create(self, raw_args):
@@ -75,7 +74,7 @@ SUBCOMMANDS:
args.pop(index + 1)
args.pop(index)
- username = self.username(args)
+ username = self._username(args, needed=True)
if not passwd:
passwd = self._getpass_twice()
self.data += ['create', username, passwd,
@@ -89,15 +88,20 @@ SUBCOMMANDS:
passwd = raw_args.pop(index + 1)
raw_args.pop(index)
- username = self.username(raw_args)
+ username = self._username(raw_args, needed=True)
if not passwd:
passwd = getpass.getpass()
self.data += ['authenticate', username, passwd, 'true']
+ self.cfg.set('bonafide', 'active', username)
return self._send(printer=command.default_dict_printer)
def logout(self, raw_args):
- username = self.username(raw_args)
+ username = self._username(raw_args)
self.data += ['logout', username]
+
+ active = self.cfg.get('bonafide', 'active', default=None)
+ if active == username:
+ self.cfg.set('bonafide', 'active', "")
return self._send(printer=command.default_dict_printer)
def list(self, raw_args):
@@ -105,13 +109,19 @@ SUBCOMMANDS:
return self._send(printer=self._print_user_list)
def update(self, raw_args):
- username = self.username(raw_args)
+ username = self._username(raw_args)
current_passwd = getpass.getpass('Current password: ')
new_passwd = self._getpass_twice('New password: ')
self.data += ['update', username, current_passwd, new_passwd]
return self._send(printer=command.default_dict_printer)
- def username(self, raw_args):
+ def active(self, raw_args):
+ username = self.cfg.get('bonafide', 'active', default='<none>')
+ print(Fore.RESET + 'active'.ljust(10) + Fore.GREEN + username +
+ Fore.RESET)
+ return defer.succeed(None)
+
+ def _username(self, raw_args, needed=False):
args = tuple([command.appname] + sys.argv[1:3])
parser = argparse.ArgumentParser(
description='Bitmask user',
@@ -121,7 +131,10 @@ SUBCOMMANDS:
username = subargs.username
if not username:
- self._error("Missing username ID but needed for this command")
+ if needed:
+ self._error("Missing username ID but needed for this command")
+ else:
+ return self.cfg.get('bonafide', 'active')
if '@' not in username:
self._error("Username ID must be in the form <user@example.org>")