bug fix: restore email password

This commit is contained in:
Usman Nasir
2019-12-16 20:55:50 +05:00
2 changed files with 8 additions and 6 deletions

View File

@@ -695,7 +695,7 @@ class backupUtilities:
username = email.split("@")[0] username = email.split("@")[0]
password = emailAccount.find('password').text password = emailAccount.find('password').text
result = mailUtilities.createEmailAccount(masterDomain, username, password) result = mailUtilities.createEmailAccount(masterDomain, username, password, 'restore')
if result[0] == 0: if result[0] == 0:
raise BaseException(result[1]) raise BaseException(result[1])

View File

@@ -56,7 +56,7 @@ class mailUtilities:
ProcessUtilities.normalExecutioner(command) ProcessUtilities.normalExecutioner(command)
@staticmethod @staticmethod
def createEmailAccount(domain, userName, password): def createEmailAccount(domain, userName, password, restore = None):
try: try:
## Check if already exists ## Check if already exists
@@ -139,12 +139,14 @@ class mailUtilities:
CentOSPath = '/etc/redhat-release' CentOSPath = '/etc/redhat-release'
if os.path.exists(CentOSPath): if os.path.exists(CentOSPath):
if restore == None:
password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()) password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
password = '{CRYPT}%s' % (password.decode()) password = '{CRYPT}%s' % (password.decode())
emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password) emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)
emailAcct.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (domain, userName) emailAcct.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (domain, userName)
emailAcct.save() emailAcct.save()
else: else:
if restore == None:
password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()) password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
password = '{CRYPT}%s' % (password.decode()) password = '{CRYPT}%s' % (password.decode())
emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password) emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)