def GET(self, cur_page=1): i = web.input() cur_page = int(cur_page) if cur_page == 0: cur_page == 1 adminLib = adminlib.Admin() result = adminLib.listAccounts(cur_page=cur_page) if result[0] is True: (total, records) = (result[1]['total'], result[1]['records']) # Get list of global admins. allGlobalAdmins = [] qr = adminLib.get_all_global_admins(mail_only=True) if qr[0]: allGlobalAdmins = qr[1] return web.render( 'pgsql/admin/list.html', cur_page=cur_page, total=total, admins=records, allGlobalAdmins=allGlobalAdmins, msg=i.get('msg', None), ) else: raise web.seeother('/domains?msg=%s' % web.urlquote(result[1]))
def POST(self): i = web.input(_unicode=False, mail=[]) self.mails = i.get('mail', []) self.action = i.get('action', None) msg = i.get('msg', None) adminLib = adminlib.Admin() if self.action == 'delete': result = adminLib.delete(mails=self.mails,) msg = 'DELETED' elif self.action == 'disable': result = adminLib.enableOrDisableAccount(accounts=self.mails, active=False,) msg = 'DISABLED' elif self.action == 'enable': result = adminLib.enableOrDisableAccount(accounts=self.mails, active=True,) msg = 'ENABLED' else: result = (False, 'INVALID_ACTION') if result[0] is True: raise web.seeother('/admins?msg=%s' % msg) else: raise web.seeother('/admins?msg=?' + web.urlquote(result[1]))
def POST(self, profile_type, mail): self.profile_type = web.safestr(profile_type) self.mail = web.safestr(mail) i = web.input(domainName=[], ) if session.get('domainGlobalAdmin' ) is not True and session.get('username') != self.mail: # Don't allow to view/update others' profile. raise web.seeother( '/profile/admin/general/%s?msg=PERMISSION_DENIED' % session.get('username')) adminLib = adminlib.Admin() result = adminLib.update( profile_type=self.profile_type, mail=self.mail, data=i, ) if result[0] is True: raise web.seeother('/profile/admin/%s/%s?msg=UPDATED' % (self.profile_type, self.mail)) else: raise web.seeother('/profile/admin/%s/%s?msg=%s' % ( self.profile_type, self.mail, web.urlquote(result[1]), ))
def POST(self): i = web.input() self.mail = web.safestr(i.get('mail')) adminLib = adminlib.Admin() result = adminLib.add(data=i) if result[0] is True: # Redirect to assign domains. raise web.seeother('/profile/admin/general/%s?msg=CREATED' % self.mail) else: raise web.seeother('/create/admin?msg=' + web.urlquote(result[1]))
def GET(self, profile_type, mail): i = web.input() self.mail = web.safestr(mail) self.profile_type = web.safestr(profile_type) if not iredutils.is_email(self.mail): raise web.seeother('/admins?msg=INVALID_MAIL') if session.get('domainGlobalAdmin' ) is not True and session.get('username') != self.mail: # Don't allow to view/update other admins' profile. raise web.seeother( '/profile/admin/general/%s?msg=PERMISSION_DENIED' % session.get('username')) adminLib = adminlib.Admin() result = adminLib.profile(mail=self.mail) if result[0] is True: domainGlobalAdmin, profile = result[1], result[2] # Get all domains. self.allDomains = [] domainLib = domainlib.Domain() resultOfAllDomains = domainLib.getAllDomains() if resultOfAllDomains[0] is True: self.allDomains = resultOfAllDomains[1] # Get managed domains. self.managedDomains = [] return web.render( 'pgsql/admin/profile.html', mail=self.mail, profile_type=self.profile_type, domainGlobalAdmin=domainGlobalAdmin, profile=profile, languagemaps=languages.get_language_maps(), allDomains=self.allDomains, min_passwd_length=settings.min_passwd_length, max_passwd_length=settings.max_passwd_length, msg=i.get('msg'), ) else: raise web.seeother('/admins?msg=' + web.urlquote(result[1]))
def GET(self, cur_page=1): i = web.input() cur_page = int(cur_page) if cur_page == 0: cur_page == 1 adminLib = adminlib.Admin() result = adminLib.listAccounts(cur_page=cur_page) if result[0] is True: (total, records) = (result[1]['total'], result[1]['records']) return web.render( 'pgsql/admin/list.html', cur_page=cur_page, total=total, admins=records, msg=i.get('msg', None), ) else: raise web.seeother('/domains?msg=%s' % web.urlquote(result[1]))
def add(self, domain, data): # Get domain name, username, cn. self.domain = web.safestr(data.get('domainName')).strip().lower() mail_local_part = web.safestr(data.get('username')).strip().lower() self.mail = mail_local_part + '@' + self.domain if not iredutils.is_domain(self.domain): return (False, 'INVALID_DOMAIN_NAME') if self.domain != domain: return (False, 'PERMISSION_DENIED') if not iredutils.is_email(self.mail): return (False, 'INVALID_MAIL') # Check account existing. connutils = connUtils.Utils() if connutils.is_email_exists(mail=self.mail): return (False, 'ALREADY_EXISTS') # Get domain profile. domainLib = domainlib.Domain() resultOfDomainProfile = domainLib.profile(domain=self.domain) if resultOfDomainProfile[0] is True: domainProfile = resultOfDomainProfile[1] else: return resultOfDomainProfile # Check account limit. adminLib = adminlib.Admin() numberOfExistAccounts = adminLib.getNumberOfManagedAccounts(accountType='user', domains=[self.domain]) if domainProfile.mailboxes == -1: return (False, 'NOT_ALLOWED') elif domainProfile.mailboxes > 0: if domainProfile.mailboxes <= numberOfExistAccounts: return (False, 'EXCEEDED_DOMAIN_ACCOUNT_LIMIT') # Check spare quota and number of spare account limit. # Get quota from <form> mailQuota = str(data.get('mailQuota')).strip() if mailQuota.isdigit(): mailQuota = int(mailQuota) else: mailQuota = 0 # Re-calculate mail quota if this domain has limited max quota. if domainProfile.maxquota > 0: # Get used quota. qr = domainLib.getAllocatedQuotaSize(domain=self.domain) if qr[0] is True: allocatedQuota = qr[1] else: return qr spareQuota = domainProfile.maxquota - allocatedQuota if spareQuota > 0: if spareQuota < mailQuota: mailQuota = spareQuota else: # No enough quota. return (False, 'EXCEEDED_DOMAIN_QUOTA_SIZE') # # Get password from <form>. # newpw = web.safestr(data.get('newpw', '')) confirmpw = web.safestr(data.get('confirmpw', '')) resultOfPW = iredutils.verify_new_password( newpw, confirmpw, min_passwd_length=settings.min_passwd_length, max_passwd_length=settings.max_passwd_length, ) if resultOfPW[0] is True: pwscheme = None if 'storePasswordInPlainText' in data and settings.STORE_PASSWORD_IN_PLAIN_TEXT: pwscheme = 'PLAIN' passwd = iredutils.generate_password_hash(resultOfPW[1], pwscheme=pwscheme) else: return resultOfPW # Get display name from <form> cn = data.get('cn', '') # Get storage base directory. tmpStorageBaseDirectory = settings.storage_base_directory.lower() splitedSBD = tmpStorageBaseDirectory.rstrip('/').split('/') storageNode = splitedSBD.pop() storageBaseDirectory = '/'.join(splitedSBD) try: # Store new user in SQL db. self.conn.insert( 'mailbox', domain=self.domain, username=self.mail, password=passwd, name=cn, maildir=iredutils.generate_maildir_path(self.mail), quota=mailQuota, storagebasedirectory=storageBaseDirectory, storagenode=storageNode, created=iredutils.get_gmttime(), active='1', local_part=mail_local_part, ) # Create an alias account: address=goto. self.conn.insert( 'alias', address=self.mail, goto=self.mail, domain=self.domain, created=iredutils.get_gmttime(), active='1', ) web.logger(msg="Create user: %s." % (self.mail), domain=self.domain, event='create',) return (True,) except Exception, e: return (False, str(e))