diff options
| -rw-r--r-- | bonafide/src/leap/bonafide/bonafide_cli.py | 110 | ||||
| -rwxr-xr-x | bonafide/src/leap/bonafide/bonafide_cli2 | 120 | 
2 files changed, 0 insertions, 230 deletions
diff --git a/bonafide/src/leap/bonafide/bonafide_cli.py b/bonafide/src/leap/bonafide/bonafide_cli.py deleted file mode 100644 index 3f500e4..0000000 --- a/bonafide/src/leap/bonafide/bonafide_cli.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# bonafide_cli.py -# Copyright (C) 2015 LEAP -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program.  If not, see <http://www.gnu.org/licenses/>. -""" -Command Line interface for bonafide cli. -""" - -# XXX Warning! Work in progress------------------------------------------------ -# This is just a demo, real cli will work against a persistent bonafide daemon. -# XXX ------------------------------------------------------------------------- - -import argparse -import os -import sys -from getpass import getpass - -from colorama import init as color_init -from colorama import Fore - -from twisted.cred.credentials import UsernamePassword -from twisted.internet import reactor - -from leap.bonafide import provider -from leap.bonafide import session - -COMMANDS = ('signup', 'authenticate') - - -def _cbShutDown(ignored): -    reactor.stop() - - -def _authEb(failure): -    print(Fore.RED + "[error] " + Fore.YELLOW + -          failure.getErrorMessage() + Fore.RESET) - - -def _display_token(result, _session): -    if result == session.OK: -        print('[ok] token--> ' + Fore.GREEN + -              _session.token + Fore.RESET) -        print('[ok] uuid --> ' + Fore.GREEN + -              _session.uuid + Fore.RESET) - -def _display_registered(result, _session, _provider): -    ok, user = result -    if ok == session.OK: -        print('[ok] registered username--> ' + Fore.GREEN + -              '%s@%s' % (user, _provider)) - - -def run_command(command, _provider, username, password, skip_logout): -    api = provider.Api('https://api.%s:4430' % _provider) -    credentials = UsernamePassword(username, password) -    cdev_pem = os.path.expanduser( -        '~/.config/leap/providers/%s/keys/ca/cacert.pem' % _provider) -    _session = session.Session(credentials, api, cdev_pem) - -    if command == 'authenticate': -        d = _session.authenticate() -        d.addCallback(_display_token, _session) -    elif command == 'signup': -        d = _session.signup(username, password) -        d.addCallback(_display_registered, _session, _provider) -    else: -        print(Fore.YELLOW + "Command not implemented" + Fore.RESET) -        sys.exit() - -    d.addErrback(_authEb) -    if not skip_logout: -        d.addCallback(lambda _: _session.logout()) -    d.addBoth(_cbShutDown) -    reactor.run() - - -def main(): -    color_init() -    description = (Fore.YELLOW + 'Manage and configure a LEAP Account ' -                   'using the bonafide protocol.' + Fore.RESET) -    parser = argparse.ArgumentParser(description=description) -    parser.add_argument('command', type=str, choices=COMMANDS) -    parser.add_argument( -        '--skip-logout', action="store_true", -        help=("Skip logout. Use this if you want to re-use the token.")) -    parser.add_argument('--provider', dest='provider', required=True) -    parser.add_argument('--username', dest='username', required=True) - -    ns = parser.parse_args() -    password = getpass( -        Fore.BLUE + '%s@%s password:' % ( -            ns.username, ns.provider) + Fore.RESET) -    run_command(ns.command, ns.provider, ns.username, password, ns.skip_logout) - - -if __name__ == '__main__': -    main() diff --git a/bonafide/src/leap/bonafide/bonafide_cli2 b/bonafide/src/leap/bonafide/bonafide_cli2 deleted file mode 100755 index bf05a99..0000000 --- a/bonafide/src/leap/bonafide/bonafide_cli2 +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# bonafide_cli2.py -# Copyright (C) 2015 LEAP -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program.  If not, see <http://www.gnu.org/licenses/>. -""" -Bonafide command line interface: zmq client. -""" -import sys -import getpass -import argparse - -from colorama import init as color_init -from colorama import Fore -from twisted.internet import reactor -from txzmq import ZmqEndpoint, ZmqFactory, ZmqREQConnection -import zmq - -from leap.bonafide import config - -description = (Fore.YELLOW + 'Manage and configure a LEAP Account ' -               'using the bonafide protocol. This client connects to ' -               'a running Bonafide service.' + Fore.RESET) - -parser = argparse.ArgumentParser(description=description) -parser.add_argument("--stats", dest="do_stats", action="store_true", -                    help="print service stats") -parser.add_argument("--signup", action="store_true", dest="do_signup", -                    help="signup new user") -parser.add_argument("--auth", dest="do_auth", action="store_true", -                    help="authenticate the passed user") -parser.add_argument("--logout", dest="do_logout", action="store_true", -                    help="logout this user") -parser.add_argument("--username", dest="username", -                    help="user to operate with") -parser.add_argument("--shutdown", dest="do_shutdown", action="store_true", -                    help="shutdown the bonafide service.") - -# XXX DEBUG -------------------------------------------------------- -parser.add_argument("--debug", dest="do_debug", action="store_true", -                    help="debug command, can be anything") -# ------------------------------------------------------------------ -ns = parser.parse_args() - - -def get_zmq_connection(): -    zf = ZmqFactory() -    e = ZmqEndpoint('connect', config.ENDPOINT) -    return ZmqREQConnection(zf, e) - - -def error(msg): -    print Fore.RED + "[!] %s" % msg + Fore.RESET -    sys.exit(1) - -if len(sys.argv) < 2: -    error("Too few arguments. Try %s --help" % sys.argv[0]) - - -if (ns.do_signup or ns.do_auth or ns.do_logout) and not ns.username: -    error(Fore.RED + "Need to pass a username for signup/auth/logout" + -          Fore.RESET) - -if ns.username and '@' not in ns.username: -    error(Fore.RED + "Username must be in the form user@provider" + Fore.RESET) - - -def do_print(stuff): -    print Fore.GREEN + stuff[0] + Fore.RESET - - -def send_command(): - -    cb = do_print -    if ns.do_shutdown: -        data = ("shutdown",) - -    elif ns.do_stats: -        data = ("stats",) - -    elif ns.do_signup: -        passwd = getpass.getpass() -        data = ("signup", ns.username, passwd) - -    elif ns.do_auth: -        passwd = getpass.getpass() -        data = ("authenticate", ns.username, passwd) - -    elif ns.do_logout: -        passwd = getpass.getpass() -        data = ("logout", ns.username, passwd) - -    elif ns.do_debug: -        data = ("get_soledad",) - -    s = get_zmq_connection() -    try: -        d = s.sendMsg(*data) -    except zmq.error.Again: -        print Fore.RED + "[ERROR] Server is down" + Fore.RESET -    d.addCallback(cb) -    d.addCallback(lambda x: reactor.stop()) - - -if __name__ == "__main__": -    color_init() -    reactor.callWhenRunning(reactor.callLater, 0, send_command) -    reactor.run()  | 
