Ejemplo n.º 1
0
    def reStartLiteSpeed():
        try:

            if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
                command = "systemctl restart lsws"
            else:
                command = "/usr/local/lsws/bin/lswsctrl restart"

            ProcessUtilities.normalExecutioner(command)

        except OSError, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartLiteSpeed]")
            return 0
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def createEmailAccount(domain, userName, password):
        try:

            ## Check if already exists

            finalEmailUsername = userName + "@" + domain

            if EUsers.objects.filter(email=finalEmailUsername).exists():
                raise BaseException("This account already exists!")

            ## Check for email limits.

            ChildCheck = 0
            try:
                website = Websites.objects.get(domain=domain)
            except:
                website = ChildDomains.objects.get(domain=domain)
                ChildCheck = 1

            try:

                if not Domains.objects.filter(domain=domain).exists():
                    if ChildCheck == 0:
                        newEmailDomain = Domains(domainOwner=website,
                                                 domain=domain)
                    else:
                        newEmailDomain = Domains(childOwner=website,
                                                 domain=domain)

                    newEmailDomain.save()

                if not DomainLimits.objects.filter(
                        domain=newEmailDomain).exists():
                    domainLimits = DomainLimits(domain=newEmailDomain)
                    domainLimits.save()

                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."
                        )
                else:
                    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."
                        )

            except:

                emailDomain = Domains.objects.get(domain=domain)
                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."
                        )
                else:
                    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."
                        )

            ## After effects

            execPath = "/usr/local/CyberCP/bin/python2 /usr/local/CyberCP/plogical/mailUtilities.py"
            execPath = execPath + " AfterEffects --domain " + domain

            if getpass.getuser() == 'root':
                ## This is the case when cPanel Importer is running and token is not present in enviroment.
                ProcessUtilities.normalExecutioner(execPath)
            else:
                ProcessUtilities.executioner(execPath, 'lscpd')

            ## After effects ends

            emailDomain = Domains.objects.get(domain=domain)

            hash = hashlib.md5()
            hash.update(password)

            #emailAcct = EUsers(emailOwner=emailDomain, email=finalEmailUsername, password=hash.hexdigest())

            CentOSPath = '/etc/redhat-release'

            if os.path.exists(CentOSPath):
                password = bcrypt.hashpw(str(password), bcrypt.gensalt())
                password = '******' % (password)
                emailAcct = EUsers(emailOwner=emailDomain,
                                   email=finalEmailUsername,
                                   password=password)
                emailAcct.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (
                    domain, userName)
                emailAcct.save()
            else:
                password = bcrypt.hashpw(str(password), bcrypt.gensalt())
                password = '******' % (password)
                emailAcct = EUsers(emailOwner=emailDomain,
                                   email=finalEmailUsername,
                                   password=password)
                emailAcct.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (
                    domain, userName)
                emailAcct.save()

            emailLimits = EmailLimits(email=emailAcct)
            emailLimits.save()

            print "1,None"
            return 1, "None"

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [createEmailAccount]")
            print "0," + str(msg)
            return 0, str(msg)
Ejemplo n.º 4
0
    def configureSpamAssassin():
        try:

            if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                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()

            command = "groupadd spamd"
            ProcessUtilities.normalExecutioner(command)

            command = "useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd"
            ProcessUtilities.normalExecutioner(command)

            ##

            command = "chown spamd:spamd /var/log/spamassassin"
            ProcessUtilities.normalExecutioner(command)

            command = "systemctl enable spamassassin"
            ProcessUtilities.normalExecutioner(command)

            command = "systemctl start spamassassin"
            ProcessUtilities.normalExecutioner(command)

            ## 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'
            ProcessUtilities.normalExecutioner(command)

            print "1,None"
            return

        except OSError, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + " [configureSpamAssassin]")
            print "0," + str(msg)
            return
Ejemplo n.º 5
0
    def setupDKIM(virtualHostName):
        try:
            ## Generate DKIM Keys

            import tldextract

            #extractDomain = tldextract.extract(virtualHostName)
            #virtualHostName = extractDomain.domain + '.' + extractDomain.suffix

            if os.path.exists("/etc/opendkim/keys/" + virtualHostName):
                return 1, "None"

            path = '/etc/opendkim/keys/%s' % (virtualHostName)
            command = 'mkdir %s' % (path)
            ProcessUtilities.normalExecutioner(command)

            ## Generate keys

            command = "sudo opendkim-genkey -D /etc/opendkim/keys/%s -d %s -s default" % (
                virtualHostName, virtualHostName)
            ProcessUtilities.normalExecutioner(command)
            ## Fix permissions

            command = "chown -R root:opendkim /etc/opendkim/keys/" + virtualHostName
            ProcessUtilities.normalExecutioner(command)

            command = "chmod 640 /etc/opendkim/keys/" + virtualHostName + "/default.private"
            ProcessUtilities.normalExecutioner(command)

            command = "chmod 644 /etc/opendkim/keys/" + virtualHostName + "/default.txt"
            ProcessUtilities.normalExecutioner(command)

            ## Edit key file

            keyTable = "/etc/opendkim/KeyTable"
            configToWrite = "default._domainkey." + virtualHostName + " " + virtualHostName + ":default:/etc/opendkim/keys/" + virtualHostName + "/default.private\n"

            writeToFile = open(keyTable, 'a')
            writeToFile.write(configToWrite)
            writeToFile.close()

            ## Edit signing table

            signingTable = "/etc/opendkim/SigningTable"
            configToWrite = "*@" + virtualHostName + " default._domainkey." + virtualHostName + "\n"

            writeToFile = open(signingTable, 'a')
            writeToFile.write(configToWrite)
            writeToFile.close()

            ## Trusted hosts

            trustedHosts = "/etc/opendkim/TrustedHosts"
            configToWrite = virtualHostName + "\n"

            writeToFile = open(trustedHosts, 'a')
            writeToFile.write(configToWrite)
            writeToFile.close()

            ## Restart postfix and OpenDKIM

            command = "systemctl restart opendkim"
            subprocess.call(shlex.split(command))

            command = "systemctl restart postfix"
            subprocess.call(shlex.split(command))

            return 1, "None"

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [setupDKIM:275]")
            return 0, str(msg)