2021-04-24 03:42:05 +05:00
|
|
|
import json
|
2018-06-05 00:53:45 +05:00
|
|
|
import os,sys
|
2021-04-24 03:42:05 +05:00
|
|
|
|
|
|
|
|
from django.http import HttpResponse
|
|
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
sys.path.append('/usr/local/CyberCP')
|
|
|
|
|
import django
|
|
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
2019-07-18 14:08:00 +05:00
|
|
|
try:
|
|
|
|
|
django.setup()
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2017-12-09 22:30:10 +05:00
|
|
|
import os.path
|
|
|
|
|
import shutil
|
2019-12-15 13:30:40 +05:00
|
|
|
from plogical import CyberCPLogFileWriter as logging
|
2017-12-09 22:30:10 +05:00
|
|
|
import subprocess
|
|
|
|
|
import argparse
|
|
|
|
|
import shlex
|
2019-12-15 13:30:40 +05:00
|
|
|
from plogical.processUtilities import ProcessUtilities
|
2020-01-29 14:47:31 +05:00
|
|
|
import os
|
2019-07-16 23:23:16 +05:00
|
|
|
import bcrypt
|
2019-08-25 05:25:48 +05:00
|
|
|
import getpass
|
2019-11-02 19:29:02 +05:00
|
|
|
import smtplib
|
2021-04-24 03:42:05 +05:00
|
|
|
import threading as multi
|
2019-08-25 05:25:48 +05:00
|
|
|
|
2019-07-18 14:08:00 +05:00
|
|
|
try:
|
|
|
|
|
from mailServer.models import Domains, EUsers
|
|
|
|
|
from emailPremium.models import DomainLimits, EmailLimits
|
|
|
|
|
from websiteFunctions.models import Websites, ChildDomains
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2017-12-09 22:30:10 +05:00
|
|
|
|
|
|
|
|
class mailUtilities:
|
|
|
|
|
|
2018-05-08 21:25:37 +05:00
|
|
|
installLogPath = "/home/cyberpanel/openDKIMInstallLog"
|
2018-06-25 05:45:38 +05:00
|
|
|
spamassassinInstallLogPath = "/home/cyberpanel/spamassassinInstallLogPath"
|
2018-05-08 21:25:37 +05:00
|
|
|
cyberPanelHome = "/home/cyberpanel"
|
2020-05-28 21:29:48 +05:00
|
|
|
mailScannerInstallLogPath = "/home/cyberpanel/mailScannerInstallLogPath"
|
2018-05-03 01:22:28 +05:00
|
|
|
|
2019-11-02 19:29:02 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def SendEmail(sender, receivers, message):
|
|
|
|
|
try:
|
|
|
|
|
smtpObj = smtplib.SMTP('localhost')
|
|
|
|
|
smtpObj.sendmail(sender, receivers, message)
|
2019-12-10 15:09:10 +05:00
|
|
|
print("Successfully sent email")
|
|
|
|
|
except BaseException as msg:
|
2019-11-02 19:29:02 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
2019-07-16 23:23:16 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def AfterEffects(domain):
|
|
|
|
|
path = "/usr/local/CyberCP/install/rainloop/cyberpanel.net.ini"
|
|
|
|
|
|
|
|
|
|
if not os.path.exists("/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/"):
|
|
|
|
|
os.makedirs("/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/")
|
|
|
|
|
|
|
|
|
|
finalPath = "/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/" + domain + ".ini"
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(finalPath):
|
|
|
|
|
shutil.copy(path, finalPath)
|
|
|
|
|
|
|
|
|
|
command = 'chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data/'
|
|
|
|
|
ProcessUtilities.normalExecutioner(command)
|
|
|
|
|
|
2017-12-09 22:30:10 +05:00
|
|
|
@staticmethod
|
2019-12-16 20:53:03 +05:00
|
|
|
def createEmailAccount(domain, userName, password, restore = None):
|
2017-12-09 22:30:10 +05:00
|
|
|
try:
|
|
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
## Check if already exists
|
|
|
|
|
|
|
|
|
|
finalEmailUsername = userName + "@" + domain
|
|
|
|
|
|
|
|
|
|
if EUsers.objects.filter(email=finalEmailUsername).exists():
|
|
|
|
|
raise BaseException("This account already exists!")
|
|
|
|
|
|
|
|
|
|
## Check for email limits.
|
|
|
|
|
|
2019-06-08 21:41:43 +00:00
|
|
|
ChildCheck = 0
|
|
|
|
|
try:
|
|
|
|
|
website = Websites.objects.get(domain=domain)
|
|
|
|
|
except:
|
|
|
|
|
website = ChildDomains.objects.get(domain=domain)
|
|
|
|
|
ChildCheck = 1
|
2018-06-05 00:53:45 +05:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
2018-06-25 03:37:23 +05:00
|
|
|
if not Domains.objects.filter(domain=domain).exists():
|
2019-06-08 21:41:43 +00:00
|
|
|
if ChildCheck == 0:
|
|
|
|
|
newEmailDomain = Domains(domainOwner=website, domain=domain)
|
|
|
|
|
else:
|
|
|
|
|
newEmailDomain = Domains(childOwner=website, domain=domain)
|
|
|
|
|
|
2018-06-25 03:37:23 +05:00
|
|
|
newEmailDomain.save()
|
|
|
|
|
|
|
|
|
|
if not DomainLimits.objects.filter(domain=newEmailDomain).exists():
|
|
|
|
|
domainLimits = DomainLimits(domain=newEmailDomain)
|
|
|
|
|
domainLimits.save()
|
2018-06-05 00:53:45 +05:00
|
|
|
|
2019-06-08 21:41:43 +00:00
|
|
|
if ChildCheck == 0:
|
|
|
|
|
if website.package.emailAccounts == 0 or (
|
|
|
|
|
newEmailDomain.eusers_set.all().count() < website.package.emailAccounts):
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise BaseException("Exceeded maximum amount of email accounts allowed for the package.")
|
2018-06-05 00:53:45 +05:00
|
|
|
else:
|
2019-06-08 21:41:43 +00:00
|
|
|
if website.master.package.emailAccounts == 0 or (
|
|
|
|
|
newEmailDomain.eusers_set.all().count() < website.master.package.emailAccounts):
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise BaseException("Exceeded maximum amount of email accounts allowed for the package.")
|
2018-06-05 00:53:45 +05:00
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
|
|
emailDomain = Domains.objects.get(domain=domain)
|
2019-06-08 21:41:43 +00:00
|
|
|
if ChildCheck == 0:
|
|
|
|
|
if website.package.emailAccounts == 0 or (
|
|
|
|
|
emailDomain.eusers_set.all().count() < website.package.emailAccounts):
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise BaseException("Exceeded maximum amount of email accounts allowed for the package.")
|
2018-06-05 00:53:45 +05:00
|
|
|
else:
|
2019-06-08 21:41:43 +00:00
|
|
|
if website.master.package.emailAccounts == 0 or (
|
|
|
|
|
emailDomain.eusers_set.all().count() < website.master.package.emailAccounts):
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise BaseException("Exceeded maximum amount of email accounts allowed for the package.")
|
2018-06-05 00:53:45 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
## After effects
|
|
|
|
|
|
2019-12-10 23:04:24 +05:00
|
|
|
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/mailUtilities.py"
|
2019-07-16 23:23:16 +05:00
|
|
|
execPath = execPath + " AfterEffects --domain " + domain
|
2019-08-23 17:29:24 +05:00
|
|
|
|
2019-08-25 05:25:48 +05:00
|
|
|
if getpass.getuser() == 'root':
|
2019-08-23 17:29:24 +05:00
|
|
|
## This is the case when cPanel Importer is running and token is not present in enviroment.
|
|
|
|
|
ProcessUtilities.normalExecutioner(execPath)
|
|
|
|
|
else:
|
|
|
|
|
ProcessUtilities.executioner(execPath, 'lscpd')
|
2017-12-09 22:30:10 +05:00
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
## After effects ends
|
|
|
|
|
|
|
|
|
|
emailDomain = Domains.objects.get(domain=domain)
|
|
|
|
|
|
2019-06-08 21:41:43 +00:00
|
|
|
#emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=hash.hexdigest())
|
2019-07-03 13:15:26 +05:00
|
|
|
|
|
|
|
|
CentOSPath = '/etc/redhat-release'
|
|
|
|
|
|
|
|
|
|
if os.path.exists(CentOSPath):
|
2019-12-16 20:53:03 +05:00
|
|
|
if restore == None:
|
2019-12-16 20:55:50 +05:00
|
|
|
password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
|
|
|
|
|
password = '{CRYPT}%s' % (password.decode())
|
2019-07-03 13:15:26 +05:00
|
|
|
emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)
|
|
|
|
|
emailAcct.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (domain, userName)
|
|
|
|
|
emailAcct.save()
|
|
|
|
|
else:
|
2019-12-16 20:53:03 +05:00
|
|
|
if restore == None:
|
2019-12-16 20:55:50 +05:00
|
|
|
password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
|
|
|
|
|
password = '{CRYPT}%s' % (password.decode())
|
2019-07-03 13:15:26 +05:00
|
|
|
emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=password)
|
|
|
|
|
emailAcct.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (domain, userName)
|
|
|
|
|
emailAcct.save()
|
2018-06-05 00:53:45 +05:00
|
|
|
|
2018-06-25 03:37:23 +05:00
|
|
|
emailLimits = EmailLimits(email=emailAcct)
|
|
|
|
|
emailLimits.save()
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
print("1,None")
|
2018-06-05 00:53:45 +05:00
|
|
|
return 1,"None"
|
2017-12-09 22:30:10 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2017-12-09 22:30:10 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
|
|
|
|
str(msg) + " [createEmailAccount]")
|
2019-12-10 15:09:10 +05:00
|
|
|
print("0," + str(msg))
|
2018-06-05 00:53:45 +05:00
|
|
|
return 0, str(msg)
|
2017-12-09 22:30:10 +05:00
|
|
|
|
2018-06-05 00:53:45 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def deleteEmailAccount(email):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
email = EUsers(email=email)
|
|
|
|
|
email.delete()
|
|
|
|
|
|
|
|
|
|
return 1, 'None'
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-06-05 00:53:45 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
|
|
|
|
str(msg) + " [deleteEmailAccount]")
|
|
|
|
|
return 0, str(msg)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def getEmailAccounts(virtualHostName):
|
|
|
|
|
try:
|
|
|
|
|
emailDomain = Domains.objects.get(domain=virtualHostName)
|
|
|
|
|
return emailDomain.eusers_set.all()
|
|
|
|
|
except:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
2019-10-06 18:41:09 +05:00
|
|
|
def changeEmailPassword(email, newPassword, encrypt = None):
|
2018-06-05 00:53:45 +05:00
|
|
|
try:
|
2019-10-06 18:41:09 +05:00
|
|
|
if encrypt == None:
|
|
|
|
|
CentOSPath = '/etc/redhat-release'
|
|
|
|
|
changePass = EUsers.objects.get(email=email)
|
|
|
|
|
if os.path.exists(CentOSPath):
|
2019-12-16 15:48:45 +05:00
|
|
|
password = bcrypt.hashpw(newPassword.encode('utf-8'), bcrypt.gensalt())
|
|
|
|
|
password = '{CRYPT}%s' % (password.decode())
|
2019-10-06 18:41:09 +05:00
|
|
|
changePass.password = password
|
|
|
|
|
else:
|
|
|
|
|
changePass.password = newPassword
|
|
|
|
|
changePass.save()
|
2019-07-03 13:15:26 +05:00
|
|
|
else:
|
2019-10-06 18:41:09 +05:00
|
|
|
changePass = EUsers.objects.get(email=email)
|
2019-07-03 13:15:26 +05:00
|
|
|
changePass.password = newPassword
|
2019-10-06 18:41:09 +05:00
|
|
|
changePass.save()
|
2018-06-05 00:53:45 +05:00
|
|
|
return 0,'None'
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-06-05 00:53:45 +05:00
|
|
|
return 0, str(msg)
|
2017-12-09 22:30:10 +05:00
|
|
|
|
2018-05-01 00:49:47 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def setupDKIM(virtualHostName):
|
|
|
|
|
try:
|
|
|
|
|
## Generate DKIM Keys
|
|
|
|
|
|
2021-04-28 01:04:29 +05:00
|
|
|
command = 'chown cyberpanel:cyberpanel -R /usr/local/CyberCP/lib/python3.6/site-packages/tldextract/.suffix_cache'
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
2021-09-07 19:38:30 +05:00
|
|
|
command = 'chown cyberpanel:cyberpanel /usr/local/CyberCP/lib/python3.8/site-packages/tldextract/.suffix_cache/publicsuffix.org-tlds/'
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
2018-06-11 21:04:55 +05:00
|
|
|
import tldextract
|
|
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
actualDomain = virtualHostName
|
|
|
|
|
extractDomain = tldextract.extract(virtualHostName)
|
|
|
|
|
virtualHostName = extractDomain.domain + '.' + extractDomain.suffix
|
2018-06-11 21:04:55 +05:00
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
if not os.path.exists("/etc/opendkim/keys/" + virtualHostName + "/default.txt"):
|
2021-04-02 12:45:42 +05:00
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
path = '/etc/opendkim/keys/%s' % (virtualHostName)
|
|
|
|
|
command = 'mkdir %s' % (path)
|
|
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-05-01 00:49:47 +05:00
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
## Generate keys
|
2018-05-01 00:49:47 +05:00
|
|
|
|
2020-05-24 10:29:22 +01:00
|
|
|
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
2020-05-19 13:29:39 +05:00
|
|
|
command = "/usr/sbin/opendkim-genkey -D /etc/opendkim/keys/%s -d %s -s default" % (virtualHostName, virtualHostName)
|
|
|
|
|
else:
|
|
|
|
|
command = "opendkim-genkey -D /etc/opendkim/keys/%s -d %s -s default" % (
|
|
|
|
|
virtualHostName, virtualHostName)
|
2021-04-02 12:45:42 +05:00
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2021-04-02 12:45:42 +05:00
|
|
|
|
|
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
## Fix permissions
|
2018-05-01 00:49:47 +05:00
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
command = "chown -R root:opendkim /etc/opendkim/keys/" + virtualHostName
|
|
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-05-01 00:49:47 +05:00
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
command = "chmod 640 /etc/opendkim/keys/" + virtualHostName + "/default.private"
|
|
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-05-01 00:49:47 +05:00
|
|
|
|
2020-05-19 13:29:39 +05:00
|
|
|
command = "chmod 644 /etc/opendkim/keys/" + virtualHostName + "/default.txt"
|
|
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-05-01 00:49:47 +05:00
|
|
|
|
|
|
|
|
## Edit key file
|
|
|
|
|
|
|
|
|
|
keyTable = "/etc/opendkim/KeyTable"
|
2020-05-19 13:29:39 +05:00
|
|
|
configToWrite = "default._domainkey." + actualDomain + " " + actualDomain + ":default:/etc/opendkim/keys/" + virtualHostName + "/default.private\n"
|
2018-05-01 00:49:47 +05:00
|
|
|
|
|
|
|
|
writeToFile = open(keyTable, 'a')
|
|
|
|
|
writeToFile.write(configToWrite)
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
## Edit signing table
|
|
|
|
|
|
|
|
|
|
signingTable = "/etc/opendkim/SigningTable"
|
2020-05-19 13:29:39 +05:00
|
|
|
configToWrite = "*@" + actualDomain + " default._domainkey." + actualDomain + "\n"
|
2018-05-01 00:49:47 +05:00
|
|
|
|
|
|
|
|
writeToFile = open(signingTable, 'a')
|
|
|
|
|
writeToFile.write(configToWrite)
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
## Trusted hosts
|
|
|
|
|
|
|
|
|
|
trustedHosts = "/etc/opendkim/TrustedHosts"
|
2020-05-19 13:29:39 +05:00
|
|
|
configToWrite = actualDomain + "\n"
|
2018-05-01 00:49:47 +05:00
|
|
|
|
|
|
|
|
writeToFile = open(trustedHosts, 'a')
|
|
|
|
|
writeToFile.write(configToWrite)
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
2021-04-02 12:45:42 +05:00
|
|
|
## Restart Postfix and OpenDKIM
|
2018-05-01 00:49:47 +05:00
|
|
|
|
|
|
|
|
command = "systemctl restart opendkim"
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-05-01 00:49:47 +05:00
|
|
|
|
|
|
|
|
command = "systemctl restart postfix"
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-05-01 00:49:47 +05:00
|
|
|
|
|
|
|
|
return 1, "None"
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-05-01 00:49:47 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
2019-10-20 23:33:19 +05:00
|
|
|
str(msg) + " [setupDKIM:275]")
|
2018-05-01 00:49:47 +05:00
|
|
|
return 0, str(msg)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def checkIfDKIMInstalled():
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
path = "/etc/opendkim.conf"
|
|
|
|
|
|
2018-05-08 21:25:37 +05:00
|
|
|
command = "sudo cat " + path
|
2019-03-31 02:47:35 +05:00
|
|
|
return ProcessUtilities.executioner(command)
|
2018-05-01 00:49:47 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-05-01 00:49:47 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
|
|
|
|
str(msg) + " [checkIfDKIMInstalled]")
|
|
|
|
|
return 0
|
|
|
|
|
|
2018-05-03 01:22:28 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def generateKeys(domain):
|
|
|
|
|
try:
|
|
|
|
|
result = mailUtilities.setupDKIM(domain)
|
|
|
|
|
if result[0] == 0:
|
|
|
|
|
raise BaseException(result[1])
|
|
|
|
|
else:
|
2019-12-10 15:09:10 +05:00
|
|
|
print("1,None")
|
2018-05-03 01:22:28 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-05-03 01:22:28 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
|
|
|
|
str(msg) + " [generateKeys]")
|
2019-12-10 15:09:10 +05:00
|
|
|
print("0," + str(msg))
|
2018-05-03 01:22:28 +05:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def configureOpenDKIM():
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
#### Restarting Postfix and OpenDKIM
|
|
|
|
|
|
|
|
|
|
command = "systemctl start opendkim"
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-05-03 01:22:28 +05:00
|
|
|
|
|
|
|
|
command = "systemctl enable opendkim"
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-05-03 01:22:28 +05:00
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
command = "systemctl start postfix"
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-05-03 01:22:28 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
print("1,None")
|
2018-05-03 01:22:28 +05:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except OSError as msg:
|
2018-05-03 01:22:28 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [configureOpenDKIM]")
|
2019-12-10 15:09:10 +05:00
|
|
|
print("0," + str(msg))
|
2018-05-03 01:22:28 +05:00
|
|
|
return
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-05-03 01:22:28 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [configureOpenDKIM]")
|
2019-12-10 15:09:10 +05:00
|
|
|
print("0," + str(msg))
|
2018-05-03 01:22:28 +05:00
|
|
|
return
|
|
|
|
|
|
2018-05-08 21:25:37 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def checkHome():
|
|
|
|
|
try:
|
|
|
|
|
try:
|
2018-11-26 02:32:30 +05:00
|
|
|
FNULL = open(os.devnull, 'w')
|
|
|
|
|
|
2019-06-08 21:41:43 +00:00
|
|
|
if getpass.getuser() == 'root':
|
2020-01-29 14:47:31 +05:00
|
|
|
if not os.path.exists(mailUtilities.cyberPanelHome):
|
|
|
|
|
command = "mkdir " + mailUtilities.cyberPanelHome
|
|
|
|
|
subprocess.call(shlex.split(command), stdout=FNULL)
|
2018-05-08 21:25:37 +05:00
|
|
|
|
2020-01-29 14:48:43 +05:00
|
|
|
command = "sudo chown -R cyberpanel:cyberpanel " + mailUtilities.cyberPanelHome
|
|
|
|
|
subprocess.call(shlex.split(command), stdout=FNULL)
|
2019-06-08 21:41:43 +00:00
|
|
|
else:
|
2020-01-29 14:47:31 +05:00
|
|
|
if not os.path.exists(mailUtilities.cyberPanelHome):
|
|
|
|
|
command = "mkdir " + mailUtilities.cyberPanelHome
|
|
|
|
|
ProcessUtilities.executioner(command)
|
2019-06-08 21:41:43 +00:00
|
|
|
|
2020-01-29 14:48:43 +05:00
|
|
|
command = "chown -R cyberpanel:cyberpanel " + mailUtilities.cyberPanelHome
|
|
|
|
|
ProcessUtilities.executioner(command)
|
2018-05-08 21:25:37 +05:00
|
|
|
except:
|
2019-02-03 13:37:14 +05:00
|
|
|
FNULL = open(os.devnull, 'w')
|
2020-01-29 14:47:31 +05:00
|
|
|
command = "chown -R cyberpanel:cyberpanel " + mailUtilities.cyberPanelHome
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command), stdout=FNULL)
|
2018-05-08 21:25:37 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-05-08 21:25:37 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [checkHome]")
|
|
|
|
|
|
2018-05-03 01:22:28 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def installOpenDKIM(install, openDKIMINstall):
|
|
|
|
|
try:
|
|
|
|
|
|
2018-05-08 21:25:37 +05:00
|
|
|
mailUtilities.checkHome()
|
|
|
|
|
|
2018-05-03 01:22:28 +05:00
|
|
|
command = 'sudo yum install opendkim -y'
|
|
|
|
|
|
|
|
|
|
cmd = shlex.split(command)
|
|
|
|
|
|
|
|
|
|
with open(mailUtilities.installLogPath, 'w') as f:
|
2019-03-26 16:19:03 +05:00
|
|
|
res = subprocess.call(cmd, stdout=f)
|
2018-05-03 01:22:28 +05:00
|
|
|
|
|
|
|
|
if res == 1:
|
|
|
|
|
writeToFile = open(mailUtilities.installLogPath, 'a')
|
|
|
|
|
writeToFile.writelines("Can not be installed.[404]\n")
|
|
|
|
|
writeToFile.close()
|
2018-05-08 21:25:37 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile("[Could not Install OpenDKIM.]")
|
2018-05-03 01:22:28 +05:00
|
|
|
return 0
|
|
|
|
|
else:
|
|
|
|
|
writeToFile = open(mailUtilities.installLogPath, 'a')
|
|
|
|
|
writeToFile.writelines("OpenDKIM Installed.[200]\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
return 1
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-05-08 21:25:37 +05:00
|
|
|
writeToFile = open(mailUtilities.installLogPath, 'a')
|
|
|
|
|
writeToFile.writelines("Can not be installed.[404]\n")
|
|
|
|
|
writeToFile.close()
|
2018-05-03 01:22:28 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installOpenDKIM]")
|
|
|
|
|
|
2018-05-24 23:37:10 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def restartServices():
|
|
|
|
|
try:
|
|
|
|
|
command = 'systemctl restart postfix'
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-05-24 23:37:10 +05:00
|
|
|
|
|
|
|
|
command = 'systemctl restart dovecot'
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-05-24 23:37:10 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [restartServices]")
|
|
|
|
|
|
2018-06-25 05:45:38 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def installSpamAssassin(install, SpamAssassin):
|
|
|
|
|
try:
|
|
|
|
|
|
2020-05-28 16:19:30 +05:00
|
|
|
if os.path.exists(mailUtilities.spamassassinInstallLogPath):
|
|
|
|
|
os.remove(mailUtilities.spamassassinInstallLogPath)
|
|
|
|
|
|
2020-05-24 10:29:22 +01:00
|
|
|
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
2018-11-12 18:39:04 +05:00
|
|
|
command = 'sudo yum install spamassassin -y'
|
|
|
|
|
else:
|
|
|
|
|
command = 'sudo apt-get install spamassassin spamc -y'
|
2018-06-25 05:45:38 +05:00
|
|
|
|
|
|
|
|
cmd = shlex.split(command)
|
|
|
|
|
|
|
|
|
|
with open(mailUtilities.spamassassinInstallLogPath, 'w') as f:
|
2019-03-26 16:19:03 +05:00
|
|
|
res = subprocess.call(cmd, stdout=f)
|
2018-06-25 05:45:38 +05:00
|
|
|
|
|
|
|
|
if res == 1:
|
|
|
|
|
writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a')
|
|
|
|
|
writeToFile.writelines("Can not be installed.[404]\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile("[Could not Install SpamAssassin.]")
|
|
|
|
|
return 0
|
|
|
|
|
else:
|
|
|
|
|
writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a')
|
|
|
|
|
writeToFile.writelines("SpamAssassin Installed.[200]\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
return 1
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-06-25 05:45:38 +05:00
|
|
|
writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a')
|
|
|
|
|
writeToFile.writelines("Can not be installed.[404]\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installSpamAssassin]")
|
|
|
|
|
|
2020-05-28 16:19:30 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def installMailScanner(install, SpamAssassin):
|
|
|
|
|
try:
|
|
|
|
|
|
2020-05-28 21:29:48 +05:00
|
|
|
if os.path.exists(mailUtilities.mailScannerInstallLogPath):
|
|
|
|
|
os.remove(mailUtilities.mailScannerInstallLogPath)
|
2020-05-28 16:19:30 +05:00
|
|
|
|
|
|
|
|
if mailUtilities.checkIfSpamAssassinInstalled():
|
|
|
|
|
|
|
|
|
|
command = 'chmod +x /usr/local/CyberCP/CPScripts/mailscannerinstaller.sh'
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
command = '/usr/local/CyberCP/CPScripts/mailscannerinstaller.sh'
|
|
|
|
|
|
|
|
|
|
cmd = shlex.split(command)
|
|
|
|
|
|
2020-05-28 21:29:48 +05:00
|
|
|
with open(mailUtilities.mailScannerInstallLogPath, 'w') as f:
|
2020-05-29 10:49:31 +05:00
|
|
|
res = subprocess.call(cmd, stdout=f, shell=True)
|
2020-05-28 16:19:30 +05:00
|
|
|
|
|
|
|
|
if res == 1:
|
2020-05-28 21:29:48 +05:00
|
|
|
writeToFile = open(mailUtilities.mailScannerInstallLogPath, 'a')
|
2020-05-28 16:19:30 +05:00
|
|
|
writeToFile.writelines("Can not be installed.[404]\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile("[Could not Install MailScanner.]")
|
|
|
|
|
return 0
|
|
|
|
|
else:
|
2020-05-28 21:29:48 +05:00
|
|
|
writeToFile = open(mailUtilities.mailScannerInstallLogPath, 'a')
|
2020-05-28 16:19:30 +05:00
|
|
|
writeToFile.writelines("MailScanner Installed.[200]\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
2020-05-28 21:29:48 +05:00
|
|
|
writeToFile = open(mailUtilities.mailScannerInstallLogPath, 'a')
|
2020-05-28 16:19:30 +05:00
|
|
|
writeToFile.writelines("Please install SpamAssassin from CyberPanel before installing MailScanner.[404]\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except BaseException as msg:
|
2020-05-28 21:29:48 +05:00
|
|
|
writeToFile = open(mailUtilities.mailScannerInstallLogPath, 'a')
|
2020-05-28 16:19:30 +05:00
|
|
|
writeToFile.writelines("Can not be installed.[404]\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installSpamAssassin]")
|
|
|
|
|
|
2018-06-25 05:45:38 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def checkIfSpamAssassinInstalled():
|
|
|
|
|
try:
|
|
|
|
|
|
2020-02-27 17:38:53 +05:00
|
|
|
path = "/etc/postfix/master.cf"
|
2018-06-25 05:45:38 +05:00
|
|
|
|
2020-02-27 17:38:53 +05:00
|
|
|
command = "cat " + path
|
2019-04-15 15:54:23 +05:00
|
|
|
output = ProcessUtilities.outputExecutioner(command)
|
2018-06-25 05:45:38 +05:00
|
|
|
|
2020-02-27 17:38:53 +05:00
|
|
|
if output.find('content_filter=spamassassin') > -1:
|
2018-06-25 05:45:38 +05:00
|
|
|
return 1
|
2020-02-27 17:38:53 +05:00
|
|
|
else:
|
|
|
|
|
return 0
|
2018-06-25 05:45:38 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-06-25 05:45:38 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
|
|
|
|
str(msg) + " [checkIfSpamAssassinInstalled]")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def configureSpamAssassin():
|
|
|
|
|
try:
|
|
|
|
|
|
2020-05-15 01:07:04 +05:00
|
|
|
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
|
2019-01-12 17:52:45 +05:00
|
|
|
confFile = "/etc/mail/spamassassin/local.cf"
|
|
|
|
|
confData = open(confFile).readlines()
|
|
|
|
|
|
|
|
|
|
conf = open(confFile, 'w')
|
|
|
|
|
|
|
|
|
|
for items in confData:
|
|
|
|
|
if items.find('report_safe') > -1 or items.find('rewrite_header') > -1 or items.find('required_score') > -1 or items.find('required_hits') > -1:
|
|
|
|
|
conf.write(items.strip('#').strip(' '))
|
|
|
|
|
else:
|
|
|
|
|
conf.write(items)
|
|
|
|
|
|
|
|
|
|
conf.close()
|
|
|
|
|
|
|
|
|
|
|
2018-06-25 05:45:38 +05:00
|
|
|
command = "groupadd spamd"
|
2019-08-31 13:13:59 +05:00
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-06-25 05:45:38 +05:00
|
|
|
|
|
|
|
|
command = "useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd"
|
2019-08-31 13:13:59 +05:00
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-06-25 05:45:38 +05:00
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
command = "chown spamd:spamd /var/log/spamassassin"
|
2019-08-31 13:13:59 +05:00
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-06-25 05:45:38 +05:00
|
|
|
|
|
|
|
|
command = "systemctl enable spamassassin"
|
2019-08-31 13:13:59 +05:00
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-06-25 05:45:38 +05:00
|
|
|
|
|
|
|
|
command = "systemctl start spamassassin"
|
2019-08-31 13:13:59 +05:00
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-06-25 05:45:38 +05:00
|
|
|
|
|
|
|
|
## Configuration to postfix
|
|
|
|
|
|
|
|
|
|
postfixConf = '/etc/postfix/master.cf'
|
|
|
|
|
data = open(postfixConf, 'r').readlines()
|
|
|
|
|
|
|
|
|
|
writeToFile = open(postfixConf, 'w')
|
|
|
|
|
checker = 1
|
|
|
|
|
|
|
|
|
|
for items in data:
|
|
|
|
|
if items.find('smtp') > - 1 and items.find('inet') > - 1 and items.find('smtpd') > - 1 and checker == 1:
|
|
|
|
|
writeToFile.writelines(items.strip('\n') + ' -o content_filter=spamassassin\n')
|
|
|
|
|
checker = 0
|
|
|
|
|
else:
|
|
|
|
|
writeToFile.writelines(items)
|
|
|
|
|
|
|
|
|
|
writeToFile.writelines('spamassassin unix - n n - - pipe flags=R user=spamd argv=/usr/bin/spamc -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}')
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
command = 'systemctl restart postfix'
|
2019-08-31 13:13:59 +05:00
|
|
|
ProcessUtilities.normalExecutioner(command)
|
2018-06-25 05:45:38 +05:00
|
|
|
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
print("1,None")
|
2018-06-25 05:45:38 +05:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except OSError as msg:
|
2018-06-25 05:45:38 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [configureSpamAssassin]")
|
2019-12-10 15:09:10 +05:00
|
|
|
print("0," + str(msg))
|
2018-06-25 05:45:38 +05:00
|
|
|
return
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-06-25 05:45:38 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [configureSpamAssassin]")
|
2019-12-10 15:09:10 +05:00
|
|
|
print("0," + str(msg))
|
2018-06-25 05:45:38 +05:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def saveSpamAssassinConfigs(tempConfigPath):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
data = open(tempConfigPath).readlines()
|
|
|
|
|
os.remove(tempConfigPath)
|
|
|
|
|
|
|
|
|
|
confFile = "/etc/mail/spamassassin/local.cf"
|
|
|
|
|
confData = open(confFile).readlines()
|
|
|
|
|
|
|
|
|
|
conf = open(confFile, 'w')
|
|
|
|
|
|
|
|
|
|
rsCheck = 0
|
|
|
|
|
|
|
|
|
|
for items in confData:
|
|
|
|
|
|
|
|
|
|
if items.find('report_safe ') > -1:
|
|
|
|
|
conf.writelines(data[0])
|
|
|
|
|
continue
|
|
|
|
|
elif items.find('required_hits ') > -1:
|
|
|
|
|
conf.writelines(data[1])
|
|
|
|
|
continue
|
|
|
|
|
elif items.find('rewrite_header ') > -1:
|
|
|
|
|
conf.writelines(data[2])
|
|
|
|
|
continue
|
|
|
|
|
elif items.find('required_score ') > -1:
|
|
|
|
|
conf.writelines(data[3])
|
|
|
|
|
rsCheck = 1
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if rsCheck == 0:
|
|
|
|
|
conf.writelines(data[3])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conf.close()
|
|
|
|
|
|
|
|
|
|
command = 'systemctl restart spamassassin'
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-06-25 05:45:38 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
print("1,None")
|
2018-06-25 05:45:38 +05:00
|
|
|
return
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-06-25 05:45:38 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
|
|
|
|
str(msg) + " [saveSpamAssassinConfigs]")
|
2019-12-10 15:09:10 +05:00
|
|
|
print("0," + str(msg))
|
2018-06-25 05:45:38 +05:00
|
|
|
|
2018-06-27 00:16:50 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def savePolicyServerStatus(install):
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
postfixPath = '/etc/postfix/main.cf'
|
|
|
|
|
|
|
|
|
|
if install == '1':
|
|
|
|
|
if not os.path.exists('/etc/systemd/system/cpecs.service'):
|
|
|
|
|
shutil.copy("/usr/local/CyberCP/postfixSenderPolicy/cpecs.service", "/etc/systemd/system/cpecs.service")
|
|
|
|
|
|
2018-10-12 18:18:10 +05:00
|
|
|
command = 'systemctl enable cpecs'
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-10-12 18:18:10 +05:00
|
|
|
|
2018-06-27 00:16:50 +05:00
|
|
|
command = 'systemctl start cpecs'
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-06-27 00:16:50 +05:00
|
|
|
|
|
|
|
|
writeToFile = open(postfixPath, 'a')
|
2018-07-13 04:26:40 +05:00
|
|
|
writeToFile.writelines('smtpd_data_restrictions = check_policy_service unix:/var/log/policyServerSocket\n')
|
2018-10-13 18:31:47 +05:00
|
|
|
writeToFile.writelines('smtpd_policy_service_default_action = DUNNO\n')
|
2018-06-27 00:16:50 +05:00
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
command = 'systemctl restart postfix'
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-06-27 00:16:50 +05:00
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
data = open(postfixPath, 'r').readlines()
|
|
|
|
|
writeToFile = open(postfixPath, 'w')
|
|
|
|
|
|
|
|
|
|
for items in data:
|
2018-07-13 04:26:40 +05:00
|
|
|
if items.find('check_policy_service unix:/var/log/policyServerSocket') > -1:
|
2018-06-27 00:16:50 +05:00
|
|
|
continue
|
2018-10-13 18:31:47 +05:00
|
|
|
elif items.find('smtpd_policy_service_default_action = DUNNO') > -1:
|
|
|
|
|
continue
|
2018-06-27 00:16:50 +05:00
|
|
|
else:
|
|
|
|
|
writeToFile.writelines(items)
|
|
|
|
|
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
command = 'systemctl stop cpecs'
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-06-27 00:16:50 +05:00
|
|
|
|
|
|
|
|
command = 'systemctl restart postfix'
|
2019-03-26 16:19:03 +05:00
|
|
|
subprocess.call(shlex.split(command))
|
2018-06-27 00:16:50 +05:00
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
print("1,None")
|
2018-06-27 00:16:50 +05:00
|
|
|
return
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except BaseException as msg:
|
2018-06-27 00:16:50 +05:00
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
|
|
|
|
str(msg) + " [savePolicyServerStatus]")
|
2019-12-10 15:09:10 +05:00
|
|
|
print("0," + str(msg))
|
2018-06-27 00:16:50 +05:00
|
|
|
|
2020-05-28 13:30:25 +05:00
|
|
|
@staticmethod
|
|
|
|
|
def checkIfMailScannerInstalled():
|
|
|
|
|
try:
|
|
|
|
|
|
2020-05-28 16:19:30 +05:00
|
|
|
path = "/usr/local/CyberCP/public/mailwatch"
|
2020-05-28 13:30:25 +05:00
|
|
|
|
|
|
|
|
if os .path.exists(path):
|
|
|
|
|
return 1
|
|
|
|
|
else:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
except BaseException as msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(
|
|
|
|
|
str(msg) + " [checkIfMailScannerInstalled]")
|
|
|
|
|
return 0
|
|
|
|
|
|
2021-04-24 03:42:05 +05:00
|
|
|
####### 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
|
2021-04-24 23:17:32 +05:00
|
|
|
self.MailSSL = 0
|
2021-04-24 03:42:05 +05:00
|
|
|
|
|
|
|
|
def checkIfMailServerSSLIssued(self):
|
|
|
|
|
|
|
|
|
|
postfixPath = '/etc/postfix/main.cf'
|
|
|
|
|
|
|
|
|
|
postFixData = ProcessUtilities.outputExecutioner('cat %s' % (postfixPath))
|
|
|
|
|
|
|
|
|
|
if postFixData.find('myhostname = server.example.com') > -1:
|
2021-04-24 04:57:15 +05:00
|
|
|
self.MailSSL = 0
|
2021-04-24 03:42:05 +05:00
|
|
|
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:
|
2021-04-24 04:57:15 +05:00
|
|
|
self.MailSSL = 0
|
2021-04-24 03:42:05 +05:00
|
|
|
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)
|
|
|
|
|
|
2021-06-15 14:55:48 +05:00
|
|
|
### On Ubuntu 18 find if old dovecot and remove
|
|
|
|
|
|
|
|
|
|
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
command = 'apt-get purge dovecot* -y'
|
|
|
|
|
os.system(command)
|
|
|
|
|
|
|
|
|
|
command = 'apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 18A348AEED409DA1'
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
|
|
|
|
writeToFile = open('/etc/apt/sources.list.d/dovecot.list', 'a')
|
|
|
|
|
writeToFile.writelines('deb [arch=amd64] https://repo.dovecot.org/ce-2.3-latest/ubuntu/bionic bionic main\n')
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
command = 'apt update'
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
2021-04-24 03:42:05 +05:00
|
|
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Re-installing postfix..,10')
|
|
|
|
|
|
|
|
|
|
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
|
2021-04-24 22:39:55 +05:00
|
|
|
|
|
|
|
|
command = 'yum --nogpg install https://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm -y'
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
2021-04-24 03:42:05 +05:00
|
|
|
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:
|
2021-06-15 14:55:48 +05:00
|
|
|
|
|
|
|
|
|
2021-04-24 04:57:15 +05:00
|
|
|
import socket
|
2021-04-24 03:42:05 +05:00
|
|
|
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)
|
|
|
|
|
|
2021-04-24 21:42:04 +05:00
|
|
|
command = 'apt-get -y install postfix postfix-mysql'
|
2021-04-24 03:42:05 +05:00
|
|
|
# os.remove(file_name)
|
|
|
|
|
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
|
|
|
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Re-installing Dovecot..,15')
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
|
|
|
|
|
command = 'yum --enablerepo=gf-plus -y install dovecot23 dovecot23-mysql'
|
2021-06-15 14:55:48 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
2021-04-24 03:42:05 +05:00
|
|
|
elif ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
|
|
|
|
|
command = 'dnf install --enablerepo=gf-plus dovecot23 dovecot23-mysql -y'
|
2021-06-15 14:55:48 +05:00
|
|
|
ProcessUtilities.executioner(command)
|
2021-04-24 03:42:05 +05:00
|
|
|
else:
|
2021-06-15 14:55:48 +05:00
|
|
|
command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install dovecot-mysql dovecot-imapd dovecot-pop3d'
|
|
|
|
|
os.system(command)
|
2021-04-24 03:42:05 +05:00
|
|
|
|
|
|
|
|
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)
|
2021-06-14 10:34:19 +05:00
|
|
|
|
|
|
|
|
## For ubuntu 20
|
|
|
|
|
|
|
|
|
|
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
|
|
|
|
|
|
|
|
|
|
command = "sed -i 's|daemon_directory = /usr/libexec/postfix|daemon_directory = /usr/lib/postfix/sbin|g' /etc/postfix/main.cf"
|
|
|
|
|
ProcessUtilities.executioner(command)
|
|
|
|
|
|
|
|
|
|
|
2021-04-24 03:42:05 +05:00
|
|
|
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'],
|
2021-04-24 04:57:15 +05:00
|
|
|
'Restoring OpenDKIM configurations..,70')
|
2021-04-24 03:42:05 +05:00
|
|
|
|
|
|
|
|
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:
|
2021-04-24 04:57:15 +05:00
|
|
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
|
|
|
|
'Failed. Error %s [404].' % str(msg))
|
2021-04-24 03:42:05 +05:00
|
|
|
|
|
|
|
|
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:
|
2021-04-24 04:57:15 +05:00
|
|
|
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
|
|
|
|
|
'configureOpenDKIM failed. Error %s [404].' % str(msg))
|
2021-04-24 03:42:05 +05:00
|
|
|
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.'
|
|
|
|
|
|
|
|
|
|
|
2017-12-09 22:30:10 +05:00
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
|
|
|
|
parser.add_argument('function', help='Specific a function to call!')
|
|
|
|
|
parser.add_argument('--domain', help='Domain name!')
|
2018-06-05 00:53:45 +05:00
|
|
|
parser.add_argument('--userName', help='Email Username!')
|
|
|
|
|
parser.add_argument('--password', help='Email password!')
|
2018-06-25 05:45:38 +05:00
|
|
|
parser.add_argument('--tempConfigPath', help='Temporary Configuration Path!')
|
2018-06-27 00:16:50 +05:00
|
|
|
parser.add_argument('--install', help='Enable/Disable Policy Server!')
|
2021-04-24 03:42:05 +05:00
|
|
|
parser.add_argument('--tempStatusPath', help='Path of temporary status file.')
|
2018-06-05 00:53:45 +05:00
|
|
|
|
2017-12-09 22:30:10 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
if args.function == "createEmailAccount":
|
2018-06-05 00:53:45 +05:00
|
|
|
mailUtilities.createEmailAccount(args.domain, args.userName, args.password)
|
2018-05-03 01:22:28 +05:00
|
|
|
elif args.function == "generateKeys":
|
|
|
|
|
mailUtilities.generateKeys(args.domain)
|
|
|
|
|
elif args.function == "configureOpenDKIM":
|
|
|
|
|
mailUtilities.configureOpenDKIM()
|
2018-06-25 05:45:38 +05:00
|
|
|
elif args.function == "configureSpamAssassin":
|
|
|
|
|
mailUtilities.configureSpamAssassin()
|
|
|
|
|
elif args.function == "saveSpamAssassinConfigs":
|
|
|
|
|
mailUtilities.saveSpamAssassinConfigs(args.tempConfigPath)
|
2018-06-27 00:16:50 +05:00
|
|
|
elif args.function == 'savePolicyServerStatus':
|
|
|
|
|
mailUtilities.savePolicyServerStatus(args.install)
|
2019-04-15 15:54:23 +05:00
|
|
|
elif args.function == 'installSpamAssassin':
|
|
|
|
|
mailUtilities.installSpamAssassin("install", "SpamAssassin")
|
2020-05-28 16:19:30 +05:00
|
|
|
elif args.function == 'installMailScanner':
|
|
|
|
|
mailUtilities.installMailScanner("install", "installMailScanner")
|
2019-07-16 23:23:16 +05:00
|
|
|
elif args.function == 'AfterEffects':
|
|
|
|
|
mailUtilities.AfterEffects(args.domain)
|
2021-04-24 03:42:05 +05:00
|
|
|
elif args.function == "ResetEmailConfigurations":
|
|
|
|
|
extraArgs = {'tempStatusPath': args.tempStatusPath}
|
|
|
|
|
background = MailServerManagerUtils(None, 'ResetEmailConfigurations', extraArgs)
|
|
|
|
|
background.ResetEmailConfigurations()
|
2017-12-09 22:30:10 +05:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-04-24 03:42:05 +05:00
|
|
|
main()
|