Esempio n. 1
0
    def __init__(self, app, host='localhost', port=8000, enable_ssl=False, ssl_key=None, ssl_cert=None,
                 reload_on_change=False, use_debugger=True, evalex_whitelist=None, quiet=False):
        """
        Run an Indico server based on the Werkzeug server
        """

        if not SSL and enable_ssl:
            console.error('You need pyopenssl to use SSL')
            sys.exit(1)

        self.app = app
        self.host = host
        self.port = port
        self.ssl = enable_ssl
        self.ssl_key = ssl_key
        self.ssl_cert = ssl_cert
        self.reload_on_change = reload_on_change
        self.use_debugger = use_debugger
        self.evalex_whitelist = evalex_whitelist
        self.quiet = quiet

        logger = logging.getLogger('werkzeug')
        logger.setLevel(logging.DEBUG)
        logger.addHandler(logging.StreamHandler(sys.stderr))

        self._setup_ssl()
        self._server = None
Esempio n. 2
0
    def __init__(self, app, host='localhost', port=8000, enable_ssl=False, ssl_key=None, ssl_cert=None,
                 reload_on_change=False, use_debugger=True, evalex_whitelist=None, quiet=False):
        """
        Run an Indico server based on the Werkzeug server
        """

        if not SSL and enable_ssl:
            console.error('You need pyopenssl to use SSL')
            sys.exit(1)

        self.app = app
        self.host = host
        self.port = port
        self.ssl = enable_ssl
        self.ssl_key = ssl_key
        self.ssl_cert = ssl_cert
        self.reload_on_change = reload_on_change
        self.use_debugger = use_debugger
        self.evalex_whitelist = evalex_whitelist
        self.quiet = quiet

        logger = logging.getLogger('werkzeug')
        logger.setLevel(logging.DEBUG)
        logger.addHandler(logging.StreamHandler(sys.stderr))

        self._setup_ssl()
        self._server = None
Esempio n. 3
0
def user_create(grant_admin):
    """Creates new user"""
    update_session_options(db)
    user_type = 'user' if not grant_admin else 'admin'
    while True:
        email = prompt_email()
        if email is None:
            return
        email = email.lower()
        if not User.find(User.all_emails.contains(email), ~User.is_deleted, ~User.is_pending).count():
            break
        error('Email already exists')
    first_name = prompt("First name")
    last_name = prompt("Last name")
    affiliation = prompt("Affiliation", '')
    print()
    while True:
        username = prompt("Enter username").lower()
        if not Identity.find(provider='indico', identifier=username).count():
            break
        error('Username already exists')
    password = prompt_pass()
    if password is None:
        return

    identity = Identity(provider='indico', identifier=username, password=password)
    user = create_user(email, {'first_name': to_unicode(first_name), 'last_name': to_unicode(last_name),
                               'affiliation': to_unicode(affiliation)}, identity)
    user.is_admin = grant_admin
    print_user_info(user)

    if prompt_bool(cformat("%{yellow}Create the new {}?").format(user_type), default=True):
        db.session.add(user)
        db.session.commit()
        success("New {} created successfully with ID: {}".format(user_type, user.id))
Esempio n. 4
0
def user_revoke(user_id):
    """Revokes administration rights from a given user"""
    avatar = AvatarHolder().getById(user_id)
    if avatar is None:
        error("The user does not exists")
        return
    print_user_info(avatar)
    if not avatar.isAdmin():
        warning("This user does not have administration rights")
        return
    if prompt_bool(cformat("%{yellow}Revoke administration rights from this user?")):
        admin_list = HelperMaKaCInfo.getMaKaCInfoInstance().getAdminList()
        admin_list.revoke(avatar)
        success("Administration rights revoked successfully")
Esempio n. 5
0
def user_revoke(user_id):
    """Revokes administration rights from a given user"""
    user = User.get(user_id)
    if user is None:
        error("This user does not exist")
        return
    print_user_info(user)
    if not user.is_admin:
        warning("This user does not have administration rights")
        return
    if prompt_bool(cformat("%{yellow}Revoke administration rights from this user?")):
        user.is_admin = False
        transaction.commit()
        success("Administration rights revoked successfully")
Esempio n. 6
0
def user_grant(user_id):
    """Grants administration rights to a given user"""
    user = User.get(user_id)
    if user is None:
        error("This user does not exist")
        return
    print_user_info(user)
    if user.is_admin:
        warning("This user already has administration rights")
        return
    if prompt_bool(cformat("%{yellow}Grant administration rights to this user?")):
        user.is_admin = True
        transaction.commit()
        success("Administration rights granted successfully")
Esempio n. 7
0
def user_grant(user_id):
    """Grants administration rights to a given user"""
    avatar = AvatarHolder().getById(user_id)
    if avatar is None:
        error("The user does not exists")
        return
    print_user_info(avatar)
    if avatar.isAdmin():
        warning("This user already has administration rights")
        return
    if prompt_bool(cformat("%{yellow}Grant administration rights to this user?")):
        admin_list = HelperMaKaCInfo.getMaKaCInfoInstance().getAdminList()
        admin_list.grant(avatar)
        avatar.activateAccount()
        success("Administration rights granted successfully")
Esempio n. 8
0
    def __init__(self, host='localhost', port=8000, enable_ssl=False, ssl_key=None, ssl_cert=None,
                 reload_on_change=False, use_debugger=True):
        """
        Run an Indico WSGI ref server instance
        Very simple dispatching app
        """

        if not werkzeug:
            console.error('Please install werkzeug to use the builtin dev server')
            sys.exit(1)
        elif not SSL and enable_ssl:
            console.error('You need pyopenssl to use SSL')
            sys.exit(1)

        config = Config.getInstance()

        baseURL = config.getBaseURL()
        path = urlparse.urlparse(baseURL)[2].rstrip('/')

        def fake_app(environ, start_response):
            rpath = environ['PATH_INFO']
            m = re.match(r'^{0}(.*)$'.format(path), rpath)
            if m:
                environ['PATH_INFO'] = m.group(1)
                environ['SCRIPT_NAME'] = path
                for msg in application(environ, start_response):
                    yield msg
            else:
                start_response("404 NOT FOUND", [])
                yield 'Not found'

        self.app = fake_app
        self.host = host
        self.port = port
        self.ssl = enable_ssl
        self.ssl_key = ssl_key
        self.ssl_cert = ssl_cert
        self.reload_on_change = reload_on_change
        self.use_debugger = use_debugger

        logger = logging.getLogger('werkzeug')
        logger.setLevel(logging.DEBUG)
        logger.addHandler(logging.StreamHandler(sys.stderr))

        self._setup_ssl()
        self._server = None
Esempio n. 9
0
def user_create(grant_admin):
    """Creates new user"""
    avatar = Avatar()
    user_type = 'user' if not grant_admin else 'admin'

    print()
    name = prompt("First name")
    surname = prompt("Last name")
    organization = prompt("Affiliation")
    print()
    login = prompt("Enter username")
    email = prompt_email().encode('utf-8')
    if email is None:
        return
    password = prompt_pass().encode('utf-8')
    if password is None:
        return

    avatar.setName(name)
    avatar.setSurName(surname)
    avatar.setOrganisation(organization)
    avatar.setLang("en_GB")
    avatar.setEmail(email)
    print_user_info(avatar)

    if prompt_bool(cformat("%{yellow}Create the new {}?").format(user_type), default=True):
        from MaKaC.authentication import AuthenticatorMgr
        avatar.activateAccount()
        login_info = LoginInfo(login, password)
        auth_mgr = AuthenticatorMgr()
        try:
            user_id = auth_mgr.createIdentity(login_info, avatar, "Local")
            auth_mgr.add(user_id)
            AvatarHolder().add(avatar)
            if grant_admin:
                admin_list = HelperMaKaCInfo.getMaKaCInfoInstance().getAdminList()
                admin_list.grant(avatar)
            success("New {} created successfully with ID: {}".format(user_type, avatar.getId()))
        except UserError as e:
            error("Error: {}".format(str(e)))