Exemple #1
0
    def GET(self, domain):
        domain = str(domain).lower()

        form = web.input()

        # Get all managed domains.
        _wrap = SQLWrap()
        conn = _wrap.conn

        if session.get('is_global_admin'):
            qr = sql_lib_domain.get_all_domains(conn=conn, name_only=True)
        else:
            qr = sql_lib_admin.get_managed_domains(
                conn=conn,
                admin=session.get('username'),
                domain_name_only=True)

        if qr[0] is True:
            all_domains = qr[1]
        else:
            raise web.seeother('/api?msg=' + web.urlquote(qr[1]))

        # Get domain profile.
        qr_profile = sql_lib_domain.simple_profile(domain=domain, conn=conn)
        if qr_profile[0] is True:
            domain_profile = qr_profile[1]
            domain_settings = sqlutils.account_settings_string_to_dict(
                domain_profile['settings'])
        else:
            raise web.seeother('/api?msg=%s' % web.urlquote(qr_profile[1]))

        # Cet total number and allocated quota size of existing users under domain.
        num_users_under_domain = sql_lib_general.num_users_under_domain(
            domain=domain, conn=conn)

        min_passwd_length = domain_settings.get('min_passwd_length',
                                                settings.min_passwd_length)
        max_passwd_length = domain_settings.get('max_passwd_length',
                                                settings.max_passwd_length)

        return web.render(
            'api/msg/msg.html',
            content_type="application/json",
            msg={
                #"cur_domain":domain,
                #"allDomains":all_domains,
                #"profile":domain_profile,
                #"domain_settings":domain_settings,
                #"min_passwd_length":min_passwd_length,
                #"max_passwd_length":max_passwd_length,
                #"store_password_in_plain_text":settings.STORE_PASSWORD_IN_PLAIN_TEXT,
                #"num_existing_users":num_users_under_domain,
                #"languagemaps":iredutils.get_language_maps(),
                #"password_policies":iredutils.get_password_policies(),
                #"msg":form.get('msg')
                "msg": "Create User API's GET method!"
            })
Exemple #2
0
    def GET(self, domain):
        domain = str(domain).lower()

        form = web.input()

        # Get all managed domains.
        _wrap = SQLWrap()
        conn = _wrap.conn

        if session.get('is_global_admin'):
            qr = sql_lib_domain.get_all_domains(conn=conn, name_only=True)
        else:
            qr = sql_lib_admin.get_managed_domains(
                conn=conn,
                admin=session.get('username'),
                domain_name_only=True)

        if qr[0] is True:
            all_domains = qr[1]
        else:
            raise web.seeother('/domains?msg=' + web.urlquote(qr[1]))

        # Get domain profile.
        qr_profile = sql_lib_domain.simple_profile(domain=domain, conn=conn)

        if qr_profile[0] is True:
            domain_profile = qr_profile[1]
            domain_settings = sqlutils.account_settings_string_to_dict(
                domain_profile['settings'])
        else:
            raise web.seeother('/domains?msg=%s' % web.urlquote(qr_profile[1]))

        # Cet total number and allocated quota size of existing users under domain.
        num_users_under_domain = sql_lib_general.num_users_under_domain(
            domain=domain, conn=conn)

        min_passwd_length = domain_settings.get('min_passwd_length',
                                                settings.min_passwd_length)
        max_passwd_length = domain_settings.get('max_passwd_length',
                                                settings.max_passwd_length)

        return web.render(
            'sql/user/create.html',
            cur_domain=domain,
            allDomains=all_domains,
            profile=domain_profile,
            domain_settings=domain_settings,
            min_passwd_length=min_passwd_length,
            max_passwd_length=max_passwd_length,
            store_password_in_plain_text=settings.STORE_PASSWORD_IN_PLAIN_TEXT,
            num_existing_users=num_users_under_domain,
            languagemaps=iredutils.get_language_maps(),
            password_policies=iredutils.get_password_policies(),
            msg=form.get('msg'),
        )
Exemple #3
0
    def GET(self, account_type):
        _wrap = SQLWrap()
        conn = _wrap.conn

        qr = sql_lib_domain.get_all_domains(conn=conn, name_only=True)

        if qr[0] is True:
            all_domains = qr[1]

            # Go to first available domain.
            if all_domains:
                raise web.seeother('/create/{}/{}'.format(account_type, all_domains[0]))
            else:
                raise web.seeother('/domains?msg=NO_DOMAIN_AVAILABLE')
        else:
            raise web.seeother('/domains?msg=' + web.urlquote(qr[1]))
Exemple #4
0
    def GET(self):
        form = web.input()
        _wrap = SQLWrap()
        conn = _wrap.conn

        all_domains = sql_lib_domain.get_all_domains(conn=conn, name_only=True)
        if all_domains[0]:
            all_domains = all_domains[1]
        else:
            all_domains = []
        return web.render('sql/admin/create.html',
                          languagemaps=iredutils.get_language_maps(),
                          domains=all_domains,
                          default_language=settings.default_language,
                          min_passwd_length=settings.min_passwd_length,
                          max_passwd_length=settings.max_passwd_length,
                          password_policies=iredutils.get_password_policies(),
                          msg=form.get('msg'))
Exemple #5
0
    def GET(self, account_type):
        _wrap = SQLWrap()
        conn = _wrap.conn

        if session.get('is_global_admin'):
            qr = sql_lib_domain.get_all_domains(conn=conn, name_only=True)
        else:
            qr = sql_lib_admin.get_managed_domains(conn=conn,
                                                   admin=session.get('username'),
                                                   domain_name_only=True)

        if qr[0] is True:
            all_domains = qr[1]

            # Go to first available domain.
            if all_domains:
                raise web.seeother('/create/{}/{}'.format(account_type, all_domains[0]))
            else:
                raise web.seeother('/domains?msg=NO_DOMAIN_AVAILABLE')
        else:
            raise web.seeother('/domains?msg=' + web.urlquote(qr[1]))
Exemple #6
0
    def GET(self, profile_type, mail):
        mail = str(mail).lower()
        form = web.input()

        if not (session.get('is_global_admin')
                or session.get('username') == mail):
            # Don't allow to view/update others' profile.
            raise web.seeother(
                '/profile/admin/general/%s?msg=PERMISSION_DENIED' %
                session.get('username'))

        _wrap = SQLWrap()
        conn = _wrap.conn

        is_global_admin = sql_lib_general.is_global_admin(admin=mail,
                                                          conn=conn)
        result = sql_lib_admin.get_profile(mail=mail, conn=conn)

        if result[0] is True:
            profile = result[1]
            qr = sql_lib_general.get_admin_settings(admin=mail, conn=conn)
            if qr[0]:
                admin_settings = qr[1]
            else:
                return qr

            # Get all domains.
            all_domains = []

            qr_all_domains = sql_lib_domain.get_all_domains(conn=conn)
            if qr_all_domains[0] is True:
                all_domains = qr_all_domains[1]

            # Get managed domains.
            managed_domains = []

            qr = sql_lib_admin.get_managed_domains(conn=conn,
                                                   admin=mail,
                                                   domain_name_only=True,
                                                   listed_only=True)
            if qr[0] is True:
                managed_domains += qr[1]

            return web.render(
                'sql/admin/profile.html',
                mail=mail,
                profile_type=profile_type,
                is_global_admin=is_global_admin,
                profile=profile,
                admin_settings=admin_settings,
                languagemaps=iredutils.get_language_maps(),
                allDomains=all_domains,
                managedDomains=managed_domains,
                min_passwd_length=settings.min_passwd_length,
                max_passwd_length=settings.max_passwd_length,
                store_password_in_plain_text=settings.
                STORE_PASSWORD_IN_PLAIN_TEXT,
                password_policies=iredutils.get_password_policies(),
                msg=form.get('msg'),
            )
        else:
            # Return to user profile page if admin is a mail user.
            qr = sql_lib_user.simple_profile(conn=conn,
                                             mail=mail,
                                             columns=['username'])

            if qr[0]:
                raise web.seeother('/profile/user/general/' + mail)
            else:
                raise web.seeother('/admins?msg=' + web.urlquote(result[1]))
Exemple #7
0
def add_admin_from_form(form, conn=None):
    mail = web.safestr(form.get('mail')).strip().lower()

    if not iredutils.is_email(mail):
        return (False, 'INVALID_MAIL')

    # Get new password.
    newpw = web.safestr(form.get('newpw'))
    confirmpw = web.safestr(form.get('confirmpw'))

    qr = iredpwd.verify_new_password(newpw=newpw, confirmpw=confirmpw)
    if qr[0] is True:
        passwd = qr[1]
    else:
        return qr

    if not conn:
        _wrap = SQLWrap()
        conn = _wrap.conn

    # Check local domain
    domain = mail.split('@', 1)[-1]
    if not iredutils.is_domain(domain):
        return (False, 'INVALID_DOMAIN')

    if sql_lib_general.is_domain_exists(domain=domain, conn=conn):
        return (False, 'CAN_NOT_BE_LOCAL_DOMAIN')

    # Check admin exist.
    if is_admin_exists(conn=conn, admin=mail):
        return (False, 'ALREADY_EXISTS')

    # Name, language
    cn = form.get('cn', '')
    managed_domains = form.get('managed_domains', [])
    lang = form_utils.get_language(form)
    _status = form_utils.get_single_value(form=form,
                                          input_name='accountStatus',
                                          default_value='active')
    if _status == 'active':
        _status = 1
    else:
        _status = 0

    # GET ALL valid DOMAINS
    all_domains = sql_lib_domain.get_all_domains(conn=conn, name_only=True)
    if all_domains[0]:
        all_domains = all_domains[1]
    else:
        all_domains = []

    #Check form submitted DOMAINS for validity
    for i in managed_domains:
        if i not in all_domains:
            if i != "ALL":
                managed_domains = list(filter((i).__ne__, managed_domains))
    managed_domains = list(set(managed_domains))

    try:
        if len(managed_domains) > 0:
            conn.insert('admin',
                        username=mail,
                        name=cn,
                        password=iredpwd.generate_password_hash(passwd),
                        language=lang,
                        created=iredutils.get_gmttime(),
                        active=_status)

            for i in managed_domains:
                conn.insert('domain_admins',
                            username=mail,
                            domain=i,
                            created=iredutils.get_gmttime(),
                            active='1')

            log_activity(msg="Create admin: %s." % (mail), event='create')
            return (True, )
        else:
            return (False, "No Valid Domain Selected!")
    except Exception as e:
        log_traceback()
        return (False, repr(e))