def GET(self, cur_page=1, disabled_only=False): """List paged mail domains.""" form = web.input(_unicode=False) cur_page = int(cur_page) or 1 all_domain_profiles = [] domain_used_quota = {} 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 # Get first characters of all domains _qr = sql_lib_domain.get_first_char_of_all_domains(conn=conn) if _qr[0]: all_first_chars = _qr[1] total = sql_lib_admin.num_managed_domains(conn=conn, disabled_only=disabled_only, first_char=first_char) if total: qr = sql_lib_domain.get_paged_domains(cur_page=cur_page, first_char=first_char, disabled_only=disabled_only, conn=conn) if qr[0]: all_domain_profiles = qr[1] if settings.SHOW_USED_QUOTA: domains = [] for i in all_domain_profiles: domains.append(str(i.domain)) domain_used_quota = sql_lib_domain.get_domain_used_quota( conn=conn, domains=domains) 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/domain/list.html', cur_page=cur_page, total=total, all_domain_profiles=all_domain_profiles, 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))
def get_all_domains(attributes=None, search_filter=None, names_only=False, disabled_only=False, starts_with=None, conn=None): admin = session['username'] if not attributes: attributes = list(attrs.DOMAIN_SEARCH_ATTRS) if not search_filter: search_filter = '(&(objectClass=mailDomain)(domainAdmin=%s))' % (admin) if session.get('is_global_admin'): search_filter = '(objectClass=mailDomain)' if disabled_only is True: # use "is True" here to prevent client input invalid value in url. search_filter = '(&' + search_filter + '(accountStatus=disabled)' + ')' if starts_with: if iredutils.is_valid_account_first_char(starts_with): search_filter = '(&' + search_filter + ('(domainName=%s*)' % starts_with) + ')' if not conn: _wrap = LDAPWrap() conn = _wrap.conn try: qr = conn.search_s(settings.ldap_basedn, ldap.SCOPE_ONELEVEL, search_filter, attributes) if names_only: domain_names = [] for (_dn, _ldif) in qr: _ldif = iredutils.bytes2str(_ldif) domain_names += _ldif['domainName'] return (True, domain_names) else: return (True, iredutils.bytes2str(qr)) except Exception as e: return (False, repr(e))
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))
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) })
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))
def GET(self, domain, cur_page=1, disabled_only=False): domain = web.safestr(domain) cur_page = int(cur_page) form = web.input() order_name = form.get('order_name') order_by_desc = (form.get('order_by', 'asc').lower() == 'desc') first_char = None search_filter = None if 'starts_with' in form: first_char = form.get('starts_with')[:1].upper() if iredutils.is_valid_account_first_char(first_char): search_filter = '(&(objectClass=mailUser)(mail=%s*))' % first_char _wrap = LDAPWrap() conn = _wrap.conn qr = ldap_lib_user.list_accounts(domain=domain, search_filter=search_filter, disabled_only=disabled_only, conn=conn) if not qr[0]: raise web.seeother('/domains?msg=%s' % web.urlquote(qr[1])) all_users = qr[1] sl = ldap_lib_general.get_paged_account_list( account_profiles=all_users, current_page=cur_page, domain=domain, account_type='user', order_name=order_name, order_by_desc=order_by_desc, conn=conn) account_profiles = sl['account_profiles'] # Get real-time used quota. used_quotas = {} if settings.SHOW_USED_QUOTA: # Get email address list. accountEmailLists = [] for tmpuser in account_profiles: accountEmailLists += tmpuser[1].get('mail', []) if len(accountEmailLists) > 0: used_quotas = ldap_lib_general.get_account_used_quota( accountEmailLists) if cur_page > sl['pages']: cur_page = sl['pages'] 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 all_first_chars = ldap_lib_general.get_first_char_of_all_accounts( domain=domain, account_type='user', conn=conn) return web.render( 'ldap/user/list.html', cur_page=cur_page, total=sl['total'], users=account_profiles, cur_domain=domain, 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'))