def delete(self, domains=[]): if not isinstance(domains, list): return (False, 'INVALID_DOMAIN_NAME') domains = [str(v).lower() for v in domains if iredutils.is_domain(v)] if not domains: return (True, ) msg = {} for domain in domains: dn = ldaputils.convert_keyword_to_dn(web.safestr(domain), accountType='domain') if dn[0] is False: return dn try: deltree.DelTree(self.conn, dn, ldap.SCOPE_SUBTREE) web.logger( msg="Delete domain: %s." % (domain), domain=domain, event='delete', ) except ldap.LDAPError, e: msg[domain] = str(e)
def deleteObjWithDN( self, domain, dn, account, accountType, ): self.domain = web.safestr(domain) if not iredutils.is_domain(self.domain): return (False, 'INVALID_DOMAIN_NAME') self.dn = escape_filter_chars(dn) # Used for logger. self.account = web.safestr(account) try: deltree.DelTree(self.conn, self.dn, ldap.SCOPE_SUBTREE) web.logger( msg="Delete %s: %s." % (str(accountType), self.account), domain=self.domain, event='delete', ) return (True, ) except Exception, e: return (False, ldaputils.getExceptionDesc(e))
def delete(self, mails): if mails is None or len(mails) == 0: return (False, 'NO_ACCOUNT_SELECTED') result = {} for mail in mails: self.mail = web.safestr(mail) dn = ldaputils.convKeywordToDN(self.mail, accountType='admin') try: deltree.DelTree(self.conn, dn, ldap.SCOPE_SUBTREE) web.logger( msg="Delete admin: %s." % (self.mail, ), event='delete', ) except ldap.LDAPError, e: result[self.mail] = str(e)
def delete(self, mails): if mails is None or len(mails) == 0: return (False, 'NO_ACCOUNT_SELECTED') result = {} for mail in mails: self.mail = web.safestr(mail) dn = ldaputils.convert_keyword_to_dn(self.mail, accountType='admin') if dn[0] is False: return dn try: deltree.DelTree(self.conn, dn, ldap.SCOPE_SUBTREE) web.logger( msg="Delete admin: %s." % (self.mail, ), event='delete', ) except ldap.NO_SUCH_OBJECT: # This is a mail user admin dn = ldaputils.convert_keyword_to_dn(self.mail, accountType='user') try: connutils = connUtils.Utils() # Delete enabledService=domainadmin connutils.addOrDelAttrValue(dn=dn, attr='enabledService', value='domainadmin', action='delete') # Delete domainGlobalAdmin=yes connutils.addOrDelAttrValue(dn=dn, attr='domainGlobalAdmin', value='yes', action='delete') web.logger(msg="Delete admin: %s." % (self.mail), event='delete') except Exception, e: result[self.mail] = str(e) except ldap.LDAPError, e: result[self.mail] = str(e)
def deleteSingleUser( self, mail, deleteFromGroups=True, ): self.mail = web.safestr(mail) if not iredutils.is_email(self.mail): return (False, 'INVALID_MAIL') # Get domain name of this account. self.domain = self.mail.split('@')[-1] # Get dn of mail user and domain. self.dnUser = ldaputils.convert_keyword_to_dn(self.mail, accountType='user') if self.dnUser[0] is False: return self.dnUser # Delete user object. try: # Delete single object. #self.conn.delete_s(self.dnUser) # Delete object and its subtree. deltree.DelTree(self.conn, self.dnUser, ldap.SCOPE_SUBTREE) if deleteFromGroups: self.deleteSingleUserFromGroups(self.mail) # Delete record from SQL database: real-time used quota. try: connUtils.deleteAccountFromUsedQuota([self.mail]) except Exception, e: pass # Log delete action. web.logger( msg="Delete user: %s." % (self.mail), domain=self.domain, event='delete', ) return (True, )
def deleteSingleUser(self, mail, deleteFromGroups=True, keep_mailbox_days=0): self.mail = web.safestr(mail) if not iredutils.is_email(self.mail): return (False, 'INVALID_MAIL') # Get domain name of this account. self.domain = self.mail.split('@')[-1] # Get dn of mail user and domain. self.dnUser = ldaputils.convert_keyword_to_dn(self.mail, accountType='user') if self.dnUser[0] is False: return self.dnUser # Log maildir path in SQL table. try: qr_profile = self.profile(domain=self.domain, mail=self.mail) if qr_profile[0]: user_profile = qr_profile[1][0][1] else: return qr_profile if 'homeDirectory' in user_profile: maildir = user_profile.get('homeDirectory', [''])[0] else: storageBaseDirectory = user_profile.get( 'storageBaseDirectory', [''])[0] mailMessageStore = user_profile.get('mailMessageStore', [''])[0] maildir = os.path.join(storageBaseDirectory, mailMessageStore) if keep_mailbox_days == 0: keep_mailbox_days = 36500 # Convert keep days to string _now_in_seconds = time.time() _days_in_seconds = _now_in_seconds + (keep_mailbox_days * 24 * 60 * 60) sql_keep_days = time.strftime( '%Y-%m-%d', time.strptime(time.ctime(_days_in_seconds))) web.admindb.insert('deleted_mailboxes', maildir=maildir, username=self.mail, domain=self.domain, admin=session.get('username'), delete_date=sql_keep_days) except: pass del maildir # Delete user object. try: # Delete object and its subtree. deltree.DelTree(self.conn, self.dnUser, ldap.SCOPE_SUBTREE) if deleteFromGroups: self.deleteSingleUserFromGroups(self.mail) # Delete record from SQL database: real-time used quota. try: connUtils.deleteAccountFromUsedQuota([self.mail]) except Exception, e: pass # Log delete action. web.logger(msg="Delete user: %s." % (self.mail), domain=self.domain, event='delete') return (True, )