def main(args=None): parser = ArgumentParser(formatter_class=RawTextHelpFormatter) parser.add_argument('-c', '--create-user', dest='create_user', nargs='*', default=None, help=('Interface to add a new user. \n\n' 'supply arguments e.g.\n' '`python admin.py -c <email> <username> <passwd> <role> \'<full name>\'`\n' '\n or simply `python admin.py -c` for interactive creation.')) parser.add_argument('-m', '--modify-user', dest='modify_user', action='store_true', help='Interface to modify a user (role, email)') parser.add_argument('-d', '--delete-user', dest='delete_user', action='store_true', help='Interface to delete a user.') parser.add_argument('-i', '--invite') parser.add_argument('-l', '--list', action='store_true') parser.add_argument('-b', '--backlog') parser.add_argument('--check', help="check if username exists") parser.add_argument('-u', '--users', action="store_true", help="list all existing users") r = parser.parse_args(args=args) m = CLIUserManager() if r.backlog: do_invite_backlog(m, r.backlog) elif r.list: list_not_invited(m, r.invite_all) elif r.invite: do_invite(m, r.invite) elif r.create_user is not None: m.create_user(*r.create_user) elif r.modify_user: m.modify_user() elif r.delete_user: m.delete_user() elif r.check: m.check_user(r.check) elif r.users: m.list_users() else: print('All systems go! See --help for usage')
class WebrecorderRunner(StandaloneRunner): REDIS_PORT = 7679 def __init__(self, argres): self.root_dir = argres.root_dir self.redis_dir = os.path.join(self.root_dir, 'redis') self.user_manager = None self.browser_redis = None self.default_user = argres.default_user self.browser_id = base64.b32encode(os.urandom(15)).decode('utf-8') self.dat_share_port = argres.dat_share_port self.behaviors_tarfile = argres.behaviors_tarfile super(WebrecorderRunner, self).__init__(argres, rec_port=0) if not argres.no_browser: import webbrowser webbrowser.open_new(os.environ['APP_HOST'] + '/') def _runner_init(self): os.environ['WR_USER_CONFIG'] = 'pkg://webrecorder/config/standalone_recorder.yaml' os.environ['SECRET_KEY'] = base64.b32encode(os.urandom(75)).decode('utf-8') os.environ['RECORD_ROOT'] = os.path.join(self.root_dir, 'warcs', '') os.environ['STORAGE_ROOT'] = os.path.join(self.root_dir, 'storage', '') os.environ['REDIS_BROWSER_URL'] = 'redis://*****:*****@localhost'.format(self.default_user), username=self.default_user, passwd='LocalUser1', role='admin', name=self.default_user) # set max_size to available free space, if possible try: res = shutil.disk_usage(self.root_dir) max_size = res[2] user = self.user_manager.all_users[self.default_user] user.set_prop('max_size', max_size) except Exception as e: print(e) os.environ['AUTO_LOGIN_USER'] = self.default_user def close(self): for key in self.browser_redis.scan_iter('up:{0}:*'.format(self.browser_id)): print('Delete: ' + key) self.browser_redis.delete(key) super(WebrecorderRunner, self).close() @classmethod def add_args(cls, parser): parser.add_argument('-d', '--root-dir', default='./data/', help='Root Data Dir') parser.add_argument('-u', '--default-user', default=None, help='Create & Auto-Login as Default User') parser.add_argument('--dat-share-port', default=None, help='Dat Share API server port') parser.add_argument('--behaviors-tarfile', default=None, help='Behaviors Tarfile')