diff --git a/doc/source/index.rst b/doc/source/index.rst index 0ffd864..c5c36b4 100755 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -63,7 +63,8 @@ Running SeedboxManager from crontab:: Starting Admin UI and REST API:: - dbadmin sqlite:////home/USER/.seedbox/torrent.db >> /home/USER/seedbox/etc/seedbox/admin.log 2>&1 + dbadmin passwd --password + dbadmin run sqlite:////home/USER/.seedbox/torrent.db >> /home/USER/seedbox/etc/seedbox/admin.log 2>&1 General Information diff --git a/requirements.txt b/requirements.txt index ef8d072..cab5e00 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,17 @@ -click +pbr +twine + futures oslo.config lockfile -pbr rarfile>=2.6 -sandman six>=1.4.1 sqlalchemy==0.9.8 sqlalchemy-migrate -stevedore>=0.10 -twine +stevedore>=1.3.0 xworkflows + +click +sandman +passlib + diff --git a/seedbox/db/admin.py b/seedbox/db/admin.py index d299e8f..ae05dcb 100755 --- a/seedbox/db/admin.py +++ b/seedbox/db/admin.py @@ -4,27 +4,56 @@ not available via sandmanctl """ import logging +import os import click -from sandman import app -from sandman.model import activate +from oslo.config import cfg +from passlib.hash import sha256_crypt +import sandman +from sandman import model +from seedbox import options from seedbox import version -def print_version(ctx, value): - """Print the current version of sandman and exit. +options.initialize([]) - :param ctx: application context - :param value: - """ - if not value: - return - click.echo('SeedboxManager v%s' % (version.version_string())) - ctx.exit() + +def load_passfile(): + pwfile = cfg.CONF.find_file('.admin_pass') + if not pwfile: + pwfile = os.path.join(cfg.CONF.config_dir, '.admin_pass') + return pwfile + + +@sandman.auth.verify_password +def verify_password(username, password): + pw = None + with open(load_passfile(), 'r') as fd: + pw = fd.read() + return sha256_crypt.verify(password, pw) + + +@sandman.app.before_request +@sandman.auth.login_required +def before_request(): + pass -@click.command() +@click.group() +def cli(): + pass + + +@cli.command('passwd') +@click.password_option() +def save_password(password): + """Set admin password for accessing admin UI""" + with open(load_passfile(), 'w') as fd: + fd.write(sha256_crypt.encrypt(password)) + + +@cli.command() @click.option('--generate-pks/--no-generate-pks', default=False, help='Have sandman generate primary keys for tables without one') @click.option('--show-pks/--no-show-pks', default=False, @@ -35,26 +64,21 @@ def print_version(ctx, value): help='Port of database server to connect to') @click.option('--debug', default=False, help='Enable debug output from webserver') -@click.option('--version', is_flag=True, - callback=print_version, expose_value=False, is_eager=True) +@click.version_option(version=version.version_string(), + message='SeedboxManager v%(version)s') @click.argument('URI', metavar='') def run(generate_pks, show_pks, host, port, debug, uri): - """Connect sandman to and start the API server/admin - - :param generate_pks: Have sandman generate primary keys for tables - without one - :param show_pks: Have sandman show primary key columns in the admin view - :param host: Hostname of database server to connect to - :param port: Port of database server to connect to - :param debug: Enable debug output from webserver - :param uri: database uri interface. + """Start the admin UI for managing data + + is the database connection uri + ex. sqlite:////path/to/file """ - app.config['SQLALCHEMY_DATABASE_URI'] = uri - app.config['SANDMAN_GENERATE_PKS'] = generate_pks - app.config['SANDMAN_SHOW_PKS'] = show_pks - app.config['SERVER_HOST'] = host - app.config['SERVER_PORT'] = port - activate(name='SeedboxManager Admin', browser=False) + sandman.app.config['SQLALCHEMY_DATABASE_URI'] = uri + sandman.app.config['SANDMAN_GENERATE_PKS'] = generate_pks + sandman.app.config['SANDMAN_SHOW_PKS'] = show_pks + sandman.app.config['SERVER_HOST'] = host + sandman.app.config['SERVER_PORT'] = port + model.activate(name='SeedboxManager Admin', browser=False) # set logging to dump output if in debug mode reqlogger = logging.getLogger('werkzeug') @@ -62,4 +86,4 @@ def run(generate_pks, show_pks, host, port, debug, uri): if debug: reqlogger.setLevel(logging.DEBUG) - app.run(host=host, port=int(port), debug=debug) + sandman.app.run(host=host, port=int(port), debug=debug) diff --git a/setup.cfg b/setup.cfg index e136acc..33d0a35 100755 --- a/setup.cfg +++ b/setup.cfg @@ -41,7 +41,7 @@ data_files = [entry_points] console_scripts = seedmgr = seedbox.cli:main - dbadmin = seedbox.db.admin:run + dbadmin = seedbox.db.admin:cli seedbox.tasks = filecopy = seedbox.tasks.filecopy:CopyFile