Пример #1
0
def profile(mail, with_used_quota=True, conn=None):
    """Get full user profile.

    @with_alias -- get per-user alias addresses.
    @with_forwardings -- get mail forwarding addresses
    """
    mail = str(mail).lower()

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

        qr = conn.select("mailbox",
                         vars={'mail': mail},
                         where="username=$mail",
                         limit=1)

        if qr:
            p = qr[0]
            p['stored_bytes'] = 0
            p['stored_messages'] = 0

            if with_used_quota:
                _used_quota = sql_lib_general.get_account_used_quota(
                    accounts=[mail], conn=conn)
                if mail in _used_quota:
                    p['stored_bytes'] = _used_quota[mail]['bytes']
                    p['stored_messages'] = _used_quota[mail]['messages']

            return (True, p)
        else:
            return (False, 'NO_SUCH_ACCOUNT')
    except Exception as e:
        return (False, repr(e))
Пример #2
0
    def GET(self, domain, cur_page=1, disabled_only=False):
        domain = str(domain).lower()
        cur_page = int(cur_page) or 1

        form = web.input(_unicode=False)
        order_name = form.get('order_name')
        order_by_desc = (form.get('order_by', 'asc').lower() == 'desc')

        records = []

        # Real-time used quota.
        used_quotas = {}

        all_first_chars = []
        first_char = None
        if 'starts_with' in form:
            first_char = form.get('starts_with')[:1].upper()
            if not iredutils.is_valid_account_first_char(first_char):
                first_char = None

        _wrap = SQLWrap()
        conn = _wrap.conn

        total = sql_lib_user.num_users_under_domains(
            conn=conn,
            domains=[domain],
            disabled_only=disabled_only,
            first_char=first_char)

        if total:
            _qr = sql_lib_general.get_first_char_of_all_accounts(
                domain=domain, account_type='user', conn=conn)
            if _qr[0]:
                all_first_chars = _qr[1]

            qr = sql_lib_user.get_paged_users(conn=conn,
                                              domain=domain,
                                              cur_page=cur_page,
                                              order_name=order_name,
                                              order_by_desc=order_by_desc,
                                              first_char=first_char,
                                              disabled_only=disabled_only)

            if qr[0]:
                records = qr[1]
            else:
                raise web.seeother('/api?msg=%s' % web.urlquote(qr[1]))

            # Get list of email addresses
            mails = []
            for r in records:
                mails += [str(r.get('username')).lower()]

            if mails:
                # Get real-time mailbox usage
                if settings.SHOW_USED_QUOTA:
                    try:
                        used_quotas = sql_lib_general.get_account_used_quota(
                            accounts=mails, conn=conn)
                    except Exception:
                        pass
        else:
            raise web.seeother('/api?msg=EMPTY_RESULTSET_FOR_SPECIFIED_DOMAIN')

        if session.get('is_global_admin_api'):
            days_to_keep_removed_mailbox = settings.DAYS_TO_KEEP_REMOVED_MAILBOX_FOR_GLOBAL_ADMIN

        return web.render('api/msg/msg.html',
                          content_type="application/json",
                          msg={
                              "cur_domain": domain,
                              "cur_page": cur_page,
                              "total": total,
                              "users": records,
                              "used_quotas": used_quotas,
                              "order_name": order_name,
                              "order_by_desc": order_by_desc,
                              "all_first_chars": all_first_chars,
                              "first_char": first_char,
                              "disabled_only": disabled_only,
                              "days_to_keep_removed_mailbox":
                              days_to_keep_removed_mailbox,
                              "msg": form.get('msg', None)
                          })
Пример #3
0
    def GET(self, mail):
        mail = str(mail).lower()
        domain = mail.split('@', 1)[-1]

        _wrap = SQLWrap()
        conn = _wrap.conn

        form = web.input()
        msg = form.get('msg', '')
        used_quota = {}

        qr = sql_lib_user.profile(mail=mail, conn=conn)
        if qr[0]:
            user_profile = qr[1]
        else:
            raise web.seeother('/api?msg={}'.format(web.urlquote(qr[1])))
        del qr

        # Get per-user settings
        user_settings = {}
        qr = sql_lib_general.get_user_settings(
            conn=conn, mail=mail, existing_settings=user_profile['settings'])
        if qr[0]:
            user_settings = qr[1]
        del qr

        # Get used quota.
        if settings.SHOW_USED_QUOTA:
            used_quota = sql_lib_general.get_account_used_quota(
                accounts=[mail], conn=conn)

        # Get per-domain disabled user profiles.
        qr = sql_lib_domain.simple_profile(conn=conn,
                                           domain=domain,
                                           columns=['settings'])

        if qr[0]:
            domain_profile = qr[1]
            domain_settings = sqlutils.account_settings_string_to_dict(
                domain_profile['settings'])

            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,
                              "mail":
                              mail,
                              "profile":
                              user_profile,
                              "timezones":
                              TIMEZONES,
                              "min_passwd_length":
                              min_passwd_length,
                              "max_passwd_length":
                              max_passwd_length,
                              "store_password_in_plain_text":
                              settings.STORE_PASSWORD_IN_PLAIN_TEXT,
                              "password_policies":
                              iredutils.get_password_policies(),
                              "user_settings":
                              user_settings,
                              "used_quota":
                              used_quota,
                              "languagemaps":
                              iredutils.get_language_maps(),
                              "msg":
                              msg,
                          })
Пример #4
0
    def GET(self, profile_type, mail):
        mail = str(mail).lower()
        domain = mail.split('@', 1)[-1]

        if not session.get('is_global_admin') and not session.get('is_admin'):
            mail = session.get("username")

        if session.get('is_admin'):
            #check if admin asking for details of correct domain
            admins_of_domain = sql_lib_domain.get_domain_admin_addresses(
                domain=domain)[1]
            if session.get(
                    'username'
            ) not in admins_of_domain and not session.get('is_global_admin'):
                raise web.seeother('/domains?msg=PERMISSION_DENIED')

        _wrap = SQLWrap()
        conn = _wrap.conn

        form = web.input()
        msg = form.get('msg', '')

        # profile_type == 'general'
        used_quota = {}

        qr = sql_lib_user.profile(mail=mail, conn=conn)

        if qr[0]:
            user_profile = qr[1]
        else:
            if not session.get('is_global_admin') and not session.get(
                    'is_admin'):
                raise web.seeother('/users/{}?msg={}'.format(
                    domain, web.urlquote(qr[1])))
            else:
                raise web.seeother("/dashboard?msg=SOMETHING_WENT_WRONG")
        del qr

        # Get per-user settings
        user_settings = {}
        qr = sql_lib_general.get_user_settings(
            conn=conn, mail=mail, existing_settings=user_profile['settings'])

        if qr[0]:
            user_settings = qr[1]
        del qr

        # Get used quota.
        if settings.SHOW_USED_QUOTA:
            used_quota = sql_lib_general.get_account_used_quota(
                accounts=[mail], conn=conn)

        # Get per-domain disabled user profiles.
        qr = sql_lib_general.get_domain_settings(conn=conn, domain=domain)

        if qr[0]:
            domain_settings = qr[1]
            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/profile.html',
            cur_domain=domain,
            mail=mail,
            profile_type=profile_type,
            profile=user_profile,
            timezones=TIMEZONES,
            min_passwd_length=min_passwd_length,
            max_passwd_length=max_passwd_length,
            store_password_in_plain_text=settings.STORE_PASSWORD_IN_PLAIN_TEXT,
            password_policies=iredutils.get_password_policies(),
            user_settings=user_settings,
            used_quota=used_quota,
            languagemaps=iredutils.get_language_maps(),
            msg=msg,
        )
Пример #5
0
    def GET(self, domain, cur_page=1, disabled_only=False):
        domain = str(domain).lower()
        cur_page = int(cur_page) or 1

        form = web.input(_unicode=False)
        order_name = form.get('order_name')
        order_by_desc = (form.get('order_by', 'asc').lower() == 'desc')

        #check if admin asking for details of correct domain
        admins_of_domain = sql_lib_domain.get_domain_admin_addresses(
            domain=domain)[1]
        if session.get('username') not in admins_of_domain and not session.get(
                'is_global_admin'):
            raise web.seeother(
                '/domains?msg=PERMISSION_DENIED_TRYING_TO_ACCESS_OUT_OF_BOUND_DOMAIN'
            )

        records = []

        # Real-time used quota.
        used_quotas = {}

        all_first_chars = []
        first_char = None
        if 'starts_with' in form:
            first_char = form.get('starts_with')[:1].upper()
            if not iredutils.is_valid_account_first_char(first_char):
                first_char = None

        _wrap = SQLWrap()
        conn = _wrap.conn

        total = sql_lib_user.num_users_under_domains(
            conn=conn,
            domains=[domain],
            disabled_only=disabled_only,
            first_char=first_char)

        if total:
            _qr = sql_lib_general.get_first_char_of_all_accounts(
                domain=domain, account_type='user', conn=conn)
            if _qr[0]:
                all_first_chars = _qr[1]

            qr = sql_lib_user.get_paged_users(conn=conn,
                                              domain=domain,
                                              cur_page=cur_page,
                                              order_name=order_name,
                                              order_by_desc=order_by_desc,
                                              first_char=first_char,
                                              disabled_only=disabled_only)

            if qr[0]:
                records = qr[1]
            else:
                raise web.seeother('/domains?msg=%s' % web.urlquote(qr[1]))

            # Get list of email addresses
            mails = []
            for r in records:
                mails += [str(r.get('username')).lower()]

            if mails:
                # Get real-time mailbox usage
                if settings.SHOW_USED_QUOTA:
                    try:
                        used_quotas = sql_lib_general.get_account_used_quota(
                            accounts=mails, conn=conn)
                    except Exception:
                        pass

        if session.get('is_global_admin'):
            days_to_keep_removed_mailbox = settings.DAYS_TO_KEEP_REMOVED_MAILBOX_FOR_GLOBAL_ADMIN
        else:
            days_to_keep_removed_mailbox = settings.DAYS_TO_KEEP_REMOVED_MAILBOX

        return web.render(
            'sql/user/list.html',
            cur_domain=domain,
            cur_page=cur_page,
            total=total,
            users=records,
            used_quotas=used_quotas,
            order_name=order_name,
            order_by_desc=order_by_desc,
            all_first_chars=all_first_chars,
            first_char=first_char,
            disabled_only=disabled_only,
            days_to_keep_removed_mailbox=days_to_keep_removed_mailbox,
            msg=form.get('msg', None))
Пример #6
0
    def GET(self, profile_type, mail):
        mail = str(mail).lower()
        domain = mail.split('@', 1)[-1]

        _wrap = SQLWrap()
        conn = _wrap.conn

        form = web.input()
        msg = form.get('msg', '')

        # profile_type == 'general'
        used_quota = {}

        qr = sql_lib_user.profile(mail=mail, conn=conn)
        if qr[0]:
            user_profile = qr[1]
        else:
            raise web.seeother('/users/{}?msg={}'.format(
                domain, web.urlquote(qr[1])))
        del qr

        # Get per-user settings
        user_settings = {}
        qr = sql_lib_general.get_user_settings(
            conn=conn, mail=mail, existing_settings=user_profile['settings'])
        if qr[0]:
            user_settings = qr[1]
        del qr

        # Get used quota.
        if settings.SHOW_USED_QUOTA:
            used_quota = sql_lib_general.get_account_used_quota(
                accounts=[mail], conn=conn)

        # Get per-domain disabled user profiles.
        qr = sql_lib_domain.simple_profile(conn=conn,
                                           domain=domain,
                                           columns=['settings'])

        if qr[0]:
            domain_profile = qr[1]
            domain_settings = sqlutils.account_settings_string_to_dict(
                domain_profile['settings'])

            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/profile.html',
            cur_domain=domain,
            mail=mail,
            profile_type=profile_type,
            profile=user_profile,
            timezones=TIMEZONES,
            min_passwd_length=min_passwd_length,
            max_passwd_length=max_passwd_length,
            store_password_in_plain_text=settings.STORE_PASSWORD_IN_PLAIN_TEXT,
            password_policies=iredutils.get_password_policies(),
            user_settings=user_settings,
            used_quota=used_quota,
            languagemaps=iredutils.get_language_maps(),
            msg=msg,
        )