refactor: upgrade code for dovecot/postfix on ubuntu20

This commit is contained in:
Usman Nasir
2020-12-18 14:05:01 +05:00
parent 82eb1e4d2c
commit c57fccf1f0

View File

@@ -2061,87 +2061,6 @@ echo $oConfig->Save() ? 'Done' : 'Error';
command = 'systemctl restart postfix' command = 'systemctl restart postfix'
Upgrade.executioner(command, 0) Upgrade.executioner(command, 0)
else:
if Upgrade.installedOutput.find('dovecot-mysql/bionic,now 2:2.3.10-2') == -1:
command = 'curl https://repo.dovecot.org/DOVECOT-REPO-GPG | gpg --import'
subprocess.call(command, shell=True)
command = 'gpg --export ED409DA1 > /etc/apt/trusted.gpg.d/dovecot.gpg'
subprocess.call(command, shell=True)
debPath = '/etc/apt/sources.list.d/dovecot.list'
writeToFile = open(debPath, 'w')
writeToFile.write('deb https://repo.dovecot.org/ce-2.3-latest/ubuntu/bionic bionic main\n')
writeToFile.close()
try:
command = 'apt update -y'
Upgrade.executioner(command, 0)
except:
pass
try:
command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y'
subprocess.call(command, shell=True)
command = 'dpkg --configure -a'
Upgrade.executioner(command, 0)
command = 'apt --fix-broken install -y'
Upgrade.executioner(command, 0)
command = 'DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical sudo apt-get -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" --only-upgrade install dovecot-mysql -y'
subprocess.call(command, shell=True)
except:
pass
### Restore dovecot/postfix conf
command = 'cp -pR %s/dovecot/ /etc/' % (configbackups)
Upgrade.executioner(command, 0)
command = 'cp -pR %s/postfix/ /etc/' % (configbackups)
Upgrade.executioner(command, 0)
## Restored
## Remove Default Password Scheme
path = '/etc/dovecot/dovecot-sql.conf.ext'
data = open(path, 'r').readlines()
updatePasswords = 0
writeToFile = open(path, 'w')
for items in data:
if items.find('default_pass_scheme') > -1:
updatePasswords = 1
continue
else:
writeToFile.writelines(items)
writeToFile.close()
Upgrade.stdOut("Upgrading passwords...")
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
django.setup()
from mailServer.models import EUsers
for items in EUsers.objects.all():
if items.password.find('CRYPT') > -1:
continue
command = 'doveadm pw -p %s' % (items.password)
items.password = subprocess.check_output(shlex.split(command)).decode("utf-8").strip('\n')
items.save()
command = "systemctl restart dovecot"
Upgrade.executioner(command, 0)
dovecotConf = '/etc/dovecot/dovecot.conf' dovecotConf = '/etc/dovecot/dovecot.conf'
dovecotContent = open(dovecotConf, 'r').read() dovecotContent = open(dovecotConf, 'r').read()