Esempio n. 1
0
    def GET(self, profile_type, domain):
        form = web.input()
        domain = web.safestr(domain).lower()

        _wrap = LDAPWrap()
        conn = _wrap.conn

        qr = ldap_lib_domain.get_profile(domain=domain, conn=conn)

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

        domain_profile = qr[1]['ldif']

        r = ldap_lib_domain.list_accounts(attributes=['domainName'], conn=conn)
        if r[0] is True:
            all_domains = r[1]
        else:
            return r

        domain_account_settings = ldaputils.get_account_setting_from_profile(
            domain_profile)

        (min_passwd_length,
         max_passwd_length) = ldap_lib_general.get_domain_password_lengths(
             domain=domain,
             account_settings=domain_account_settings,
             fallback_to_global_settings=False)

        # Get settings from db.
        _settings = iredutils.get_settings_from_db(
            params=['min_passwd_length', 'max_passwd_length'])
        global_min_passwd_length = _settings['min_passwd_length']
        global_max_passwd_length = _settings['max_passwd_length']

        return web.render(
            'ldap/domain/profile.html',
            cur_domain=domain,
            allDomains=all_domains,
            domain_account_settings=domain_account_settings,
            profile=domain_profile,
            profile_type=profile_type,
            global_min_passwd_length=global_min_passwd_length,
            global_max_passwd_length=global_max_passwd_length,
            min_passwd_length=min_passwd_length,
            max_passwd_length=max_passwd_length,
            timezones=TIMEZONES,
            default_mta_transport=settings.default_mta_transport,
            languagemaps=iredutils.get_language_maps(),
            msg=form.get('msg', None),
        )
Esempio n. 2
0
    def GET(self, account_type):
        qr = ldap_lib_domain.list_accounts(attributes=['domainName'], names_only=True, conn=None)
        if qr[0]:
            all_domains = qr[1]

            if all_domains:
                # Create new account under first domain, so that we
                # can get per-domain account settings, such as number of
                # account limit, password length control, etc.
                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]))
Esempio n. 3
0
    def GET(self, domain):
        domain = str(domain).lower()
        form = web.input()

        _wrap = LDAPWrap()
        conn = _wrap.conn

        _attrs = ['domainName', 'accountSetting', 'domainCurrentQuotaSize']
        result = ldap_lib_domain.list_accounts(attributes=_attrs, conn=conn)
        if result[0] is True:
            allDomains = result[1]

            # Get accountSetting of current domain.
            allAccountSettings = ldaputils.get_account_settings_from_qr(
                allDomains)
            domainAccountSetting = allAccountSettings.get(domain, {})

            defaultUserQuota = ldap_lib_domain.get_default_user_quota(
                domain=domain, domain_account_setting=domainAccountSetting)
        else:
            raise web.seeother('/domains?msg=' + web.urlquote(result[1]))

        # Get number of account limit.
        numberOfCurrentAccounts = ldap_lib_general.num_users_under_domain(
            domain=domain, conn=conn)

        (min_passwd_length,
         max_passwd_length) = ldap_lib_general.get_domain_password_lengths(
             domain=domain,
             account_settings=domainAccountSetting,
             fallback_to_global_settings=True,
         )

        return web.render(
            'ldap/user/create.html',
            cur_domain=domain,
            allDomains=allDomains,
            defaultUserQuota=defaultUserQuota,
            domainAccountSetting=domainAccountSetting,
            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(),
            numberOfCurrentAccounts=numberOfCurrentAccounts,
            languagemaps=iredutils.get_language_maps(),
            msg=form.get('msg'))
Esempio n. 4
0
    def GET(self, cur_page=1, disabled_only=False):
        form = web.input()
        cur_page = int(cur_page)

        if cur_page == 0:
            cur_page = 1

        first_char = None
        all_first_chars = []
        search_filter = 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 = LDAPWrap()
        conn = _wrap.conn

        qr = ldap_lib_domain.list_accounts(search_filter=search_filter,
                                           disabled_only=disabled_only,
                                           starts_with=first_char,
                                           conn=conn)
        if not qr[0]:
            return qr

        all_domains = qr[1]

        # Get value of accountSetting.
        all_account_settings = ldaputils.get_account_settings_from_qr(
            all_domains)

        # Get first characters of all domains
        _qr = ldap_lib_domain.get_first_char_of_all_domains(conn=conn)
        if _qr[0]:
            all_first_chars = _qr[1]

        sl = ldap_lib_general.get_paged_account_list(all_domains,
                                                     current_page=cur_page,
                                                     account_type='domain',
                                                     conn=conn)

        if cur_page > sl['pages']:
            cur_page = sl['pages']

        # Get used quota of each domain.
        domain_used_quota = {}
        _all_domain_names = []
        if settings.SHOW_USED_QUOTA:
            for (_dn, _ldif) in all_domains:
                _all_domain_names += _ldif.get('domainName', [])

            domain_used_quota = ldap_lib_general.get_domain_used_quota(
                domains=_all_domain_names)

        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(
            'ldap/domain/list.html',
            cur_page=cur_page,
            total=sl['total'],
            allDomains=sl['account_profiles'],
            allAccountSettings=all_account_settings,
            domain_used_quota=domain_used_quota,
            local_transports=settings.LOCAL_TRANSPORTS,
            first_char=first_char,
            all_first_chars=all_first_chars,
            disabled_only=disabled_only,
            days_to_keep_removed_mailbox=days_to_keep_removed_mailbox,
            msg=form.get('msg', None))
Esempio n. 5
0
    def GET(self, profile_type, mail):
        mail = web.safestr(mail).lower()
        profile_type = web.safestr(profile_type)

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

        _wrap = LDAPWrap()
        conn = _wrap.conn

        # Get admin profile.
        qr = ldap_lib_admin.get_profile(mail=mail, conn=conn)
        if qr[0]:
            admin_profile = qr[1]['ldif']
            account_settings = ldaputils.get_account_setting_from_profile(
                admin_profile)
            _qr = ldap_lib_general.get_admin_account_setting(
                mail=mail, profile=admin_profile, conn=conn)
            if _qr[0]:
                account_settings = _qr[1]
        else:
            raise web.seeother('/admins?msg=' + qr[1])

        form = web.input()

        if profile_type in ['general', 'password']:
            # Get all domains.
            qr_all_domains = ldap_lib_domain.list_accounts(
                attributes=['domainName', 'cn'], conn=conn)
            if qr_all_domains[0] is True:
                all_domains = qr_all_domains[1]
            else:
                return qr_all_domains

            # Get domains under control.
            qr_managed_domains = ldap_lib_admin.get_managed_domains(
                admin=mail,
                attributes=['domainName'],
                domain_name_only=True,
                conn=conn)

            if qr_managed_domains[0] is True:
                managed_domains = qr_managed_domains[1]
            else:
                return qr_managed_domains

            return web.render(
                'ldap/admin/profile.html',
                mail=mail,
                profile_type=profile_type,
                admin_profile=admin_profile,
                account_settings=account_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(),
                timezones=TIMEZONES,
                msg=form.get('msg', None),
            )