mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
bug fix: email configs reset
This commit is contained in:
@@ -1492,7 +1492,7 @@ class CloudManager:
|
||||
writeToFile.write('Starting..,0')
|
||||
writeToFile.close()
|
||||
|
||||
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/mailServer/mailserverManager.py"
|
||||
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||
execPath = execPath + ' ResetEmailConfigurations --tempStatusPath %s' % (tempStatusPath)
|
||||
|
||||
ProcessUtilities.popenExecutioner(execPath)
|
||||
|
||||
@@ -3,13 +3,10 @@
|
||||
import os.path
|
||||
import sys
|
||||
import django
|
||||
|
||||
from plogical.httpProc import httpProc
|
||||
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
django.setup()
|
||||
from django.shortcuts import render,redirect
|
||||
from django.http import HttpResponse
|
||||
try:
|
||||
from .models import Domains,EUsers
|
||||
@@ -62,7 +59,6 @@ class MailServerManager(multi.Thread):
|
||||
None, 'createEmail')
|
||||
return proc.render()
|
||||
|
||||
|
||||
def createEmailAccount(self):
|
||||
userID = self.request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import json
|
||||
import os,sys
|
||||
|
||||
from django.http import HttpResponse
|
||||
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
import django
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
@@ -17,6 +21,8 @@ import os
|
||||
import bcrypt
|
||||
import getpass
|
||||
import smtplib
|
||||
import threading as multi
|
||||
import socket
|
||||
|
||||
try:
|
||||
from mailServer.models import Domains, EUsers
|
||||
@@ -734,6 +740,883 @@ milter_default_action = accept
|
||||
str(msg) + " [checkIfMailScannerInstalled]")
|
||||
return 0
|
||||
|
||||
####### Imported below functions from mailserver/mailservermanager, need to refactor later
|
||||
|
||||
class MailServerManagerUtils(multi.Thread):
|
||||
|
||||
def __init__(self, request=None, function=None, extraArgs=None):
|
||||
multi.Thread.__init__(self)
|
||||
self.request = request
|
||||
self.function = function
|
||||
self.extraArgs = extraArgs
|
||||
|
||||
def checkIfMailServerSSLIssued(self):
|
||||
|
||||
postfixPath = '/etc/postfix/main.cf'
|
||||
|
||||
postFixData = ProcessUtilities.outputExecutioner('cat %s' % (postfixPath))
|
||||
|
||||
if postFixData.find('myhostname = server.example.com') > -1:
|
||||
return 0
|
||||
else:
|
||||
try:
|
||||
|
||||
postFixLines = ProcessUtilities.outputExecutioner('cat %s' % (postfixPath)).splitlines()
|
||||
|
||||
for items in postFixLines:
|
||||
if items.find('myhostname') > -1 and items[0] != '#':
|
||||
self.mailHostName = items.split('=')[1].strip(' ')
|
||||
self.MailSSL = 1
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile('%s. [checkIfMailServerSSLIssued:864]' % (str(msg)))
|
||||
|
||||
ipFile = "/etc/cyberpanel/machineIP"
|
||||
f = open(ipFile)
|
||||
ipData = f.read()
|
||||
ipAddress = ipData.split('\n', 1)[0]
|
||||
|
||||
command = 'openssl s_client -connect %s:465' % (ipAddress)
|
||||
result = ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
if result.find('18 (self signed certificate)') > -1:
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
def RunServerLevelEmailChecks(self):
|
||||
try:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Checking if MailServer SSL issued..,10')
|
||||
|
||||
reportFile = self.extraArgs['reportFile']
|
||||
|
||||
report = {}
|
||||
report['MailSSL'] = self.checkIfMailServerSSLIssued()
|
||||
|
||||
writeToFile = open(reportFile, 'w')
|
||||
writeToFile.write(json.dumps(report))
|
||||
writeToFile.close()
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
|
||||
|
||||
except BaseException as msg:
|
||||
final_dic = {'installOpenDKIM': 0, 'error_message': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def install_postfix_dovecot(self):
|
||||
try:
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
command = 'yum remove postfix -y'
|
||||
ProcessUtilities.executioner(command)
|
||||
elif ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
|
||||
command = 'apt-get -y remove postfix'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Re-installing postfix..,10')
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
|
||||
command = 'yum install --enablerepo=gf-plus -y postfix3 postfix3-ldap postfix3-mysql postfix3-pcre'
|
||||
elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
|
||||
command = 'dnf --nogpg install -y https://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'dnf install --enablerepo=gf-plus postfix3 postfix3-mysql -y'
|
||||
ProcessUtilities.executioner(command)
|
||||
else:
|
||||
command = 'apt-get install -y debconf-utils'
|
||||
ProcessUtilities.executioner(command)
|
||||
file_name = 'pf.unattend.text'
|
||||
pf = open(file_name, 'w')
|
||||
pf.write('postfix postfix/mailname string ' + str(socket.getfqdn() + '\n'))
|
||||
pf.write('postfix postfix/main_mailer_type string "Internet Site"\n')
|
||||
pf.close()
|
||||
command = 'debconf-set-selections ' + file_name
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'apt-get -y install postfix'
|
||||
# os.remove(file_name)
|
||||
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
import socket
|
||||
# We are going to leverage postconfig -e to edit the settings for hostname
|
||||
command = '"postconf -e "myhostname = %s"' % (str(socket.getfqdn()))
|
||||
ProcessUtilities.executioner(command)
|
||||
command = '"postconf -e "myhostname = %s"' % (str(socket.getfqdn()))
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
# We are explicitly going to use sed to set the hostname default from "myhostname = server.example.com"
|
||||
# to the fqdn from socket if the default is still found
|
||||
postfix_main = '/etc/postfix/main.cf'
|
||||
command = "sed -i 's|server.example.com|%s|g' %s" % (str(socket.getfqdn()), postfix_main)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Re-installing Dovecot..,15')
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
pass
|
||||
else:
|
||||
command = 'apt-get -y install dovecot-imapd dovecot-pop3d postfix-mysql'
|
||||
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
|
||||
command = 'yum --enablerepo=gf-plus -y install dovecot23 dovecot23-mysql'
|
||||
elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
||||
command = 'dnf install --enablerepo=gf-plus dovecot23 dovecot23-mysql -y'
|
||||
else:
|
||||
command = 'apt-get -y install dovecot-mysql'
|
||||
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
|
||||
|
||||
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'
|
||||
subprocess.call(command, shell=True)
|
||||
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'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
command = 'apt --fix-broken install -y'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
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
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Postfix/dovecot reinstalled.,40')
|
||||
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'%s [install_postfix_dovecot][404]' % (str(msg)), 10)
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def setup_email_Passwords(self, mysqlPassword):
|
||||
try:
|
||||
|
||||
mysql_virtual_domains = "/usr/local/CyberCP/install/email-configs-one/mysql-virtual_domains.cf"
|
||||
mysql_virtual_forwardings = "/usr/local/CyberCP/install/email-configs-one/mysql-virtual_forwardings.cf"
|
||||
mysql_virtual_mailboxes = "/usr/local/CyberCP/install/email-configs-one/mysql-virtual_mailboxes.cf"
|
||||
mysql_virtual_email2email = "/usr/local/CyberCP/install/email-configs-one/mysql-virtual_email2email.cf"
|
||||
dovecotmysql = "/usr/local/CyberCP/install/email-configs-one/dovecot-sql.conf.ext"
|
||||
|
||||
### update password:
|
||||
|
||||
data = open(dovecotmysql, "r").readlines()
|
||||
|
||||
writeDataToFile = open(dovecotmysql, "w")
|
||||
|
||||
dataWritten = "connect = host=localhost dbname=cyberpanel user=cyberpanel password=" + mysqlPassword + " port=3306\n"
|
||||
|
||||
for items in data:
|
||||
if items.find("connect") > -1:
|
||||
writeDataToFile.writelines(dataWritten)
|
||||
else:
|
||||
writeDataToFile.writelines(items)
|
||||
|
||||
# if self.distro == ubuntu:
|
||||
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
|
||||
|
||||
writeDataToFile.close()
|
||||
|
||||
### update password:
|
||||
|
||||
data = open(mysql_virtual_domains, "r").readlines()
|
||||
|
||||
writeDataToFile = open(mysql_virtual_domains, "w")
|
||||
|
||||
dataWritten = "password = " + mysqlPassword + "\n"
|
||||
|
||||
for items in data:
|
||||
if items.find("password") > -1:
|
||||
writeDataToFile.writelines(dataWritten)
|
||||
else:
|
||||
writeDataToFile.writelines(items)
|
||||
|
||||
# if self.distro == ubuntu:
|
||||
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
|
||||
|
||||
writeDataToFile.close()
|
||||
|
||||
### update password:
|
||||
|
||||
data = open(mysql_virtual_forwardings, "r").readlines()
|
||||
|
||||
writeDataToFile = open(mysql_virtual_forwardings, "w")
|
||||
|
||||
dataWritten = "password = " + mysqlPassword + "\n"
|
||||
|
||||
for items in data:
|
||||
if items.find("password") > -1:
|
||||
writeDataToFile.writelines(dataWritten)
|
||||
else:
|
||||
writeDataToFile.writelines(items)
|
||||
|
||||
# if self.distro == ubuntu:
|
||||
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
|
||||
|
||||
writeDataToFile.close()
|
||||
|
||||
### update password:
|
||||
|
||||
data = open(mysql_virtual_mailboxes, "r").readlines()
|
||||
|
||||
writeDataToFile = open(mysql_virtual_mailboxes, "w")
|
||||
|
||||
dataWritten = "password = " + mysqlPassword + "\n"
|
||||
|
||||
for items in data:
|
||||
if items.find("password") > -1:
|
||||
writeDataToFile.writelines(dataWritten)
|
||||
else:
|
||||
writeDataToFile.writelines(items)
|
||||
|
||||
# if self.distro == ubuntu:
|
||||
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
|
||||
|
||||
writeDataToFile.close()
|
||||
|
||||
### update password:
|
||||
|
||||
data = open(mysql_virtual_email2email, "r").readlines()
|
||||
|
||||
writeDataToFile = open(mysql_virtual_email2email, "w")
|
||||
|
||||
dataWritten = "password = " + mysqlPassword + "\n"
|
||||
|
||||
for items in data:
|
||||
if items.find("password") > -1:
|
||||
writeDataToFile.writelines(dataWritten)
|
||||
else:
|
||||
writeDataToFile.writelines(items)
|
||||
|
||||
# if self.distro == ubuntu:
|
||||
# os.fchmod(writeDataToFile.fileno(), stat.S_IRUSR | stat.S_IWUSR)
|
||||
|
||||
writeDataToFile.close()
|
||||
|
||||
if self.remotemysql == 'ON':
|
||||
command = "sed -i 's|host=localhost|host=%s|g' %s" % (self.mysqlhost, dovecotmysql)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "sed -i 's|port=3306|port=%s|g' %s" % (self.mysqlport, dovecotmysql)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = "sed -i 's|localhost|%s:%s|g' %s" % (self.mysqlhost, self.mysqlport, mysql_virtual_domains)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "sed -i 's|localhost|%s:%s|g' %s" % (
|
||||
self.mysqlhost, self.mysqlport, mysql_virtual_forwardings)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "sed -i 's|localhost|%s:%s|g' %s" % (
|
||||
self.mysqlhost, self.mysqlport, mysql_virtual_mailboxes)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "sed -i 's|localhost|%s:%s|g' %s" % (
|
||||
self.mysqlhost, self.mysqlport, mysql_virtual_email2email)
|
||||
ProcessUtilities.executioner(command)
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'%s [setup_email_Passwords][404]' % (str(msg)), 10)
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def centos_lib_dir_to_ubuntu(self, filename, old, new):
|
||||
try:
|
||||
fd = open(filename, 'r')
|
||||
lines = fd.readlines()
|
||||
fd.close()
|
||||
fd = open(filename, 'w')
|
||||
centos_prefix = old
|
||||
ubuntu_prefix = new
|
||||
for line in lines:
|
||||
index = line.find(centos_prefix)
|
||||
if index != -1:
|
||||
line = line[:index] + ubuntu_prefix + line[index + len(centos_prefix):]
|
||||
fd.write(line)
|
||||
fd.close()
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'%s [centos_lib_dir_to_ubuntu][404]' % (str(msg)), 10)
|
||||
|
||||
def setup_postfix_dovecot_config(self):
|
||||
try:
|
||||
|
||||
mysql_virtual_domains = "/etc/postfix/mysql-virtual_domains.cf"
|
||||
mysql_virtual_forwardings = "/etc/postfix/mysql-virtual_forwardings.cf"
|
||||
mysql_virtual_mailboxes = "/etc/postfix/mysql-virtual_mailboxes.cf"
|
||||
mysql_virtual_email2email = "/etc/postfix/mysql-virtual_email2email.cf"
|
||||
main = "/etc/postfix/main.cf"
|
||||
master = "/etc/postfix/master.cf"
|
||||
dovecot = "/etc/dovecot/dovecot.conf"
|
||||
dovecotmysql = "/etc/dovecot/dovecot-sql.conf.ext"
|
||||
|
||||
if os.path.exists(mysql_virtual_domains):
|
||||
os.remove(mysql_virtual_domains)
|
||||
|
||||
if os.path.exists(mysql_virtual_forwardings):
|
||||
os.remove(mysql_virtual_forwardings)
|
||||
|
||||
if os.path.exists(mysql_virtual_mailboxes):
|
||||
os.remove(mysql_virtual_mailboxes)
|
||||
|
||||
if os.path.exists(mysql_virtual_email2email):
|
||||
os.remove(mysql_virtual_email2email)
|
||||
|
||||
if os.path.exists(main):
|
||||
os.remove(main)
|
||||
|
||||
if os.path.exists(master):
|
||||
os.remove(master)
|
||||
|
||||
if os.path.exists(dovecot):
|
||||
os.remove(dovecot)
|
||||
|
||||
if os.path.exists(dovecotmysql):
|
||||
os.remove(dovecotmysql)
|
||||
|
||||
###############Getting SSL
|
||||
|
||||
command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/postfix/key.pem -out /etc/postfix/cert.pem'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /etc/dovecot/key.pem -out /etc/dovecot/cert.pem'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
# Cleanup config files for ubuntu
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
|
||||
self.centos_lib_dir_to_ubuntu("/usr/local/CyberCP/install/email-configs-one/master.cf", "/usr/libexec/",
|
||||
"/usr/lib/")
|
||||
self.centos_lib_dir_to_ubuntu("/usr/local/CyberCP/install/email-configs-one/main.cf",
|
||||
"/usr/libexec/postfix",
|
||||
"/usr/lib/postfix/sbin")
|
||||
|
||||
########### Copy config files
|
||||
import shutil
|
||||
|
||||
shutil.copy("/usr/local/CyberCP/install/email-configs-one/mysql-virtual_domains.cf",
|
||||
"/etc/postfix/mysql-virtual_domains.cf")
|
||||
shutil.copy("/usr/local/CyberCP/install/email-configs-one/mysql-virtual_forwardings.cf",
|
||||
"/etc/postfix/mysql-virtual_forwardings.cf")
|
||||
shutil.copy("/usr/local/CyberCP/install/email-configs-one/mysql-virtual_mailboxes.cf",
|
||||
"/etc/postfix/mysql-virtual_mailboxes.cf")
|
||||
shutil.copy("/usr/local/CyberCP/install/email-configs-one/mysql-virtual_email2email.cf",
|
||||
"/etc/postfix/mysql-virtual_email2email.cf")
|
||||
shutil.copy("/usr/local/CyberCP/install/email-configs-one/main.cf", main)
|
||||
shutil.copy("/usr/local/CyberCP/install/email-configs-one/master.cf", master)
|
||||
shutil.copy("/usr/local/CyberCP/install/email-configs-one/dovecot.conf", dovecot)
|
||||
shutil.copy("/usr/local/CyberCP/install/email-configs-one/dovecot-sql.conf.ext", dovecotmysql)
|
||||
|
||||
######################################## Permissions
|
||||
|
||||
command = 'chmod o= /etc/postfix/mysql-virtual_domains.cf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chmod o= /etc/postfix/mysql-virtual_forwardings.cf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chmod o= /etc/postfix/mysql-virtual_mailboxes.cf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chmod o= /etc/postfix/mysql-virtual_email2email.cf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chmod o= ' + main
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chmod o= ' + master
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
#######################################
|
||||
|
||||
command = 'chgrp postfix /etc/postfix/mysql-virtual_domains.cf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chgrp postfix /etc/postfix/mysql-virtual_forwardings.cf'
|
||||
ProcessUtilities.executioner(command)
|
||||
##
|
||||
|
||||
command = 'chgrp postfix /etc/postfix/mysql-virtual_mailboxes.cf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chgrp postfix /etc/postfix/mysql-virtual_email2email.cf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chgrp postfix ' + main
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chgrp postfix ' + master
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
######################################## users and groups
|
||||
|
||||
command = 'groupadd -g 5000 vmail'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'useradd -g vmail -u 5000 vmail -d /home/vmail -m'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
######################################## Further configurations
|
||||
|
||||
# hostname = socket.gethostname()
|
||||
|
||||
################################### Restart postix
|
||||
|
||||
command = 'systemctl enable postfix.service'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'systemctl start postfix.service'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
######################################## Permissions
|
||||
|
||||
command = 'chgrp dovecot /etc/dovecot/dovecot-sql.conf.ext'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'chmod o= /etc/dovecot/dovecot-sql.conf.ext'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
################################### Restart dovecot
|
||||
|
||||
command = 'systemctl enable dovecot.service'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'systemctl start dovecot.service'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = 'systemctl restart postfix.service'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
## changing permissions for main.cf
|
||||
|
||||
command = "chmod 755 " + main
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
|
||||
command = "mkdir -p /etc/pki/dovecot/private/"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "mkdir -p /etc/pki/dovecot/certs/"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "mkdir -p /etc/opendkim/keys/"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "sed -i 's/auth_mechanisms = plain/#auth_mechanisms = plain/g' /etc/dovecot/conf.d/10-auth.conf"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
## Ubuntu 18.10 ssl_dh for dovecot 2.3.2.1
|
||||
|
||||
if ProcessUtilities.ubuntu:
|
||||
dovecotConf = '/etc/dovecot/dovecot.conf'
|
||||
|
||||
data = open(dovecotConf, 'r').readlines()
|
||||
writeToFile = open(dovecotConf, 'w')
|
||||
for items in data:
|
||||
if items.find('ssl_key = <key.pem') > -1:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.writelines('ssl_dh = </usr/share/dovecot/dh.pem\n')
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.close()
|
||||
|
||||
command = "systemctl restart dovecot"
|
||||
ProcessUtilities.executioner(command)
|
||||
except BaseException as msg:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'%s [setup_postfix_dovecot_config][404]' % (
|
||||
str(msg)), 10)
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def fixCyberPanelPermissions(self):
|
||||
|
||||
###### fix Core CyberPanel permissions
|
||||
command = "find /usr/local/CyberCP -type d -exec chmod 0755 {} \;"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "find /usr/local/CyberCP -type f -exec chmod 0644 {} \;"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chmod -R 755 /usr/local/CyberCP/bin"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
## change owner
|
||||
|
||||
command = "chown -R root:root /usr/local/CyberCP"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
########### Fix LSCPD
|
||||
|
||||
command = "find /usr/local/lscp -type d -exec chmod 0755 {} \;"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "find /usr/local/lscp -type f -exec chmod 0644 {} \;"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chmod -R 755 /usr/local/lscp/bin"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chmod -R 755 /usr/local/lscp/fcgi-bin"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin/tmp"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
## change owner
|
||||
|
||||
command = "chown -R root:root /usr/local/lscp"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chmod 700 /usr/local/CyberCP/cli/cyberPanel.py"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chmod 700 /usr/local/CyberCP/plogical/upgradeCritical.py"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chmod 755 /usr/local/CyberCP/postfixSenderPolicy/client.py"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chmod 640 /usr/local/CyberCP/CyberCP/settings.py"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "chown root:cyberpanel /usr/local/CyberCP/CyberCP/settings.py"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
files = ['/etc/yum.repos.d/MariaDB.repo', '/etc/pdns/pdns.conf', '/etc/systemd/system/lscpd.service',
|
||||
'/etc/pure-ftpd/pure-ftpd.conf', '/etc/pure-ftpd/pureftpd-pgsql.conf',
|
||||
'/etc/pure-ftpd/pureftpd-mysql.conf', '/etc/pure-ftpd/pureftpd-ldap.conf',
|
||||
'/etc/dovecot/dovecot.conf', '/usr/local/lsws/conf/httpd_config.xml',
|
||||
'/usr/local/lsws/conf/modsec.conf', '/usr/local/lsws/conf/httpd.conf']
|
||||
|
||||
for items in files:
|
||||
command = 'chmod 644 %s' % (items)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
impFile = ['/etc/pure-ftpd/pure-ftpd.conf', '/etc/pure-ftpd/pureftpd-pgsql.conf',
|
||||
'/etc/pure-ftpd/pureftpd-mysql.conf', '/etc/pure-ftpd/pureftpd-ldap.conf',
|
||||
'/etc/dovecot/dovecot.conf', '/etc/pdns/pdns.conf', '/etc/pure-ftpd/db/mysql.conf',
|
||||
'/etc/powerdns/pdns.conf']
|
||||
|
||||
for items in impFile:
|
||||
command = 'chmod 600 %s' % (items)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'chmod 640 /etc/postfix/*.cf'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
command = 'chmod 644 /etc/postfix/main.cf'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
command = 'chmod 640 /etc/dovecot/*.conf'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
command = 'chmod 644 /etc/dovecot/dovecot.conf'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
command = 'chmod 640 /etc/dovecot/dovecot-sql.conf.ext'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
command = 'chmod 644 /etc/postfix/dynamicmaps.cf'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
fileM = ['/usr/local/lsws/FileManager/', '/usr/local/CyberCP/install/FileManager',
|
||||
'/usr/local/CyberCP/serverStatus/litespeed/FileManager', '/usr/local/lsws/Example/html/FileManager']
|
||||
|
||||
for items in fileM:
|
||||
try:
|
||||
import shutil
|
||||
shutil.rmtree(items)
|
||||
except:
|
||||
pass
|
||||
|
||||
command = 'chmod 755 /etc/pure-ftpd/'
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
command = 'chmod +x /usr/local/CyberCP/plogical/renew.py'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'chmod +x /usr/local/CyberCP/CLManager/CLPackages.py'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
clScripts = ['/usr/local/CyberCP/CLScript/panel_info.py', '/usr/local/CyberCP/CLScript/CloudLinuxPackages.py',
|
||||
'/usr/local/CyberCP/CLScript/CloudLinuxUsers.py',
|
||||
'/usr/local/CyberCP/CLScript/CloudLinuxDomains.py'
|
||||
, '/usr/local/CyberCP/CLScript/CloudLinuxResellers.py', '/usr/local/CyberCP/CLScript/CloudLinuxAdmins.py',
|
||||
'/usr/local/CyberCP/CLScript/CloudLinuxDB.py', '/usr/local/CyberCP/CLScript/UserInfo.py']
|
||||
|
||||
for items in clScripts:
|
||||
command = 'chmod +x %s' % (items)
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'chmod 600 /usr/local/CyberCP/plogical/adminPass.py'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'chmod 600 /etc/cagefs/exclude/cyberpanelexclude'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "find /usr/local/CyberCP/ -name '*.pyc' -delete"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.cent8:
|
||||
command = 'chown root:pdns /etc/pdns/pdns.conf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'chmod 640 /etc/pdns/pdns.conf'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = 'chmod 640 /usr/local/lscp/cyberpanel/logs/access.log'
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
###
|
||||
|
||||
def ResetEmailConfigurations(self):
|
||||
try:
|
||||
### Check if remote or local mysql
|
||||
|
||||
passFile = "/etc/cyberpanel/mysqlPassword"
|
||||
|
||||
try:
|
||||
jsonData = json.loads(ProcessUtilities.outputExecutioner('cat %s' % (passFile)))
|
||||
|
||||
self.mysqluser = jsonData['mysqluser']
|
||||
self.mysqlpassword = jsonData['mysqlpassword']
|
||||
self.mysqlport = jsonData['mysqlport']
|
||||
self.mysqlhost = jsonData['mysqlhost']
|
||||
self.remotemysql = 'ON'
|
||||
|
||||
if self.mysqlhost.find('rds.amazon') > -1:
|
||||
self.RDS = 1
|
||||
|
||||
## Also set localhost to this server
|
||||
|
||||
ipFile = "/etc/cyberpanel/machineIP"
|
||||
f = open(ipFile)
|
||||
ipData = f.read()
|
||||
ipAddressLocal = ipData.split('\n', 1)[0]
|
||||
|
||||
self.LOCALHOST = ipAddressLocal
|
||||
except BaseException as msg:
|
||||
self.remotemysql = 'OFF'
|
||||
|
||||
if os.path.exists(ProcessUtilities.debugPath):
|
||||
logging.CyberCPLogFileWriter.writeToFile('%s. [setupConnection:75]' % (str(msg)))
|
||||
|
||||
###
|
||||
|
||||
self.checkIfMailServerSSLIssued()
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Removing and re-installing postfix/dovecot..,5')
|
||||
|
||||
if self.install_postfix_dovecot() == 0:
|
||||
return 0
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Resetting configurations..,40')
|
||||
|
||||
import sys
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
from CyberCP import settings
|
||||
|
||||
if self.setup_email_Passwords(settings.DATABASES['default']['PASSWORD']) == 0:
|
||||
return 0
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Configurations reset..,70')
|
||||
|
||||
if self.setup_postfix_dovecot_config() == 0:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'setup_postfix_dovecot_config failed. [404].')
|
||||
return 0
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Restoreing OpenDKIM configurations..,70')
|
||||
|
||||
if self.configureOpenDKIM() == 0:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'configureOpenDKIM failed. [404].')
|
||||
return 0
|
||||
|
||||
if self.MailSSL:
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Setting up Mail Server SSL if any..,75')
|
||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||
virtualHostUtilities.issueSSLForMailServer(self.mailHostName,
|
||||
'/home/%s/public_html' % (self.mailHostName))
|
||||
|
||||
from websiteFunctions.models import ChildDomains
|
||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||
for websites in Websites.objects.all():
|
||||
try:
|
||||
child = ChildDomains.objects.get(domain='mail.%s' % (websites.domain))
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
||||
'Creating mail domain for %s..,80' % (websites.domain))
|
||||
virtualHostUtilities.setupAutoDiscover(1, '/dev/null', websites.domain, websites.admin)
|
||||
except:
|
||||
pass
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Fixing permissions..,90')
|
||||
|
||||
self.fixCyberPanelPermissions()
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Completed [200].')
|
||||
|
||||
except BaseException as msg:
|
||||
final_dic = {'installOpenDKIM': 0, 'error_message': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def configureOpenDKIM(self):
|
||||
try:
|
||||
|
||||
## Configure OpenDKIM specific settings
|
||||
|
||||
openDKIMConfigurePath = "/etc/opendkim.conf"
|
||||
|
||||
configData = """
|
||||
Mode sv
|
||||
Canonicalization relaxed/simple
|
||||
KeyTable refile:/etc/opendkim/KeyTable
|
||||
SigningTable refile:/etc/opendkim/SigningTable
|
||||
ExternalIgnoreList refile:/etc/opendkim/TrustedHosts
|
||||
InternalHosts refile:/etc/opendkim/TrustedHosts
|
||||
"""
|
||||
|
||||
writeToFile = open(openDKIMConfigurePath, 'a')
|
||||
writeToFile.write(configData)
|
||||
writeToFile.close()
|
||||
|
||||
## Configure postfix specific settings
|
||||
|
||||
postfixFilePath = "/etc/postfix/main.cf"
|
||||
|
||||
configData = """
|
||||
smtpd_milters = inet:127.0.0.1:8891
|
||||
non_smtpd_milters = $smtpd_milters
|
||||
milter_default_action = accept
|
||||
"""
|
||||
|
||||
writeToFile = open(postfixFilePath, 'a')
|
||||
writeToFile.write(configData)
|
||||
writeToFile.close()
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
|
||||
data = open(openDKIMConfigurePath, 'r').readlines()
|
||||
writeToFile = open(openDKIMConfigurePath, 'w')
|
||||
for items in data:
|
||||
if items.find('Socket') > -1 and items.find('local:') and items[0] != '#':
|
||||
writeToFile.writelines('Socket inet:8891@localhost\n')
|
||||
else:
|
||||
writeToFile.writelines(items)
|
||||
writeToFile.close()
|
||||
|
||||
#### Restarting Postfix and OpenDKIM
|
||||
|
||||
command = "systemctl start opendkim"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
command = "systemctl enable opendkim"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
##
|
||||
|
||||
command = "systemctl restart postfix"
|
||||
ProcessUtilities.executioner(command)
|
||||
|
||||
return 1
|
||||
|
||||
except BaseException as msg:
|
||||
return 0
|
||||
|
||||
def debugEmailForSite(self, websiteName):
|
||||
|
||||
ipFile = "/etc/cyberpanel/machineIP"
|
||||
f = open(ipFile)
|
||||
ipData = f.read()
|
||||
ipAddress = ipData.split('\n', 1)[0]
|
||||
|
||||
try:
|
||||
import socket
|
||||
siteIPAddr = socket.gethostbyname('mail.%s' % (websiteName))
|
||||
|
||||
if siteIPAddr != ipAddress:
|
||||
return 0, 'mail.%s does not point to %s.' % (websiteName, ipAddress)
|
||||
except:
|
||||
return 0, 'mail.%s does not point to %s.' % (websiteName, ipAddress)
|
||||
|
||||
command = 'openssl s_client -connect mail.%s:993' % (websiteName)
|
||||
result = ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
if result.find('18 (self signed certificate)') > -1:
|
||||
return 0, 'No valid SSL on port 993.'
|
||||
else:
|
||||
return 1, 'All checks are OK.'
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -744,6 +1627,7 @@ def main():
|
||||
parser.add_argument('--password', help='Email password!')
|
||||
parser.add_argument('--tempConfigPath', help='Temporary Configuration Path!')
|
||||
parser.add_argument('--install', help='Enable/Disable Policy Server!')
|
||||
parser.add_argument('--tempStatusPath', help='Path of temporary status file.')
|
||||
|
||||
|
||||
|
||||
@@ -767,6 +1651,10 @@ def main():
|
||||
mailUtilities.installMailScanner("install", "installMailScanner")
|
||||
elif args.function == 'AfterEffects':
|
||||
mailUtilities.AfterEffects(args.domain)
|
||||
elif args.function == "ResetEmailConfigurations":
|
||||
extraArgs = {'tempStatusPath': args.tempStatusPath}
|
||||
background = MailServerManagerUtils(None, 'ResetEmailConfigurations', extraArgs)
|
||||
background.ResetEmailConfigurations()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user