Esempio n. 1
0
    def enableRuleFile(fileName, packName):
        try:

            if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
                confFile = os.path.join(virtualHostUtilities.Server_root,
                                        "conf/httpd_config.conf")
                confData = open(confFile).readlines()
                conf = open(confFile, 'w')

                for items in confData:
                    if items.find('modsec/' +
                                  packName) > -1 and items.find(fileName) > -1:
                        conf.write(items.lstrip('#'))
                    else:
                        conf.writelines(items)

                conf.close()
            else:
                path = '/usr/local/lsws/conf/comodo_litespeed/'
                completePath = path + fileName
                completePathBak = path + fileName + '.bak'

                command = 'mv ' + completePathBak + ' ' + completePath
                ProcessUtilities.executioner(command)

            installUtilities.reStartLiteSpeed()

            print "1,None"

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [enableRuleFile]")
            print "0," + str(msg)
Esempio n. 2
0
    def createDKIMRecords(domain):
        try:

            import tldextract

            extractDomain = tldextract.extract(domain)
            topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix

            zone = Domains.objects.get(name=topLevelDomain)

            path = "/etc/opendkim/keys/" + topLevelDomain + "/default.txt"
            command = "sudo cat " + path
            output = subprocess.check_output(shlex.split(command))
            leftIndex = output.index('(') + 2
            rightIndex = output.rindex(')') - 1

            record = Records(domainOwner=zone,
                             domain_id=zone.id,
                             name="default._domainkey." + topLevelDomain,
                             type="TXT",
                             content=output[leftIndex:rightIndex],
                             ttl=3600,
                             prio=0,
                             disabled=0,
                             auth=1)
            record.save()

            if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                command = 'sudo systemctl restart pdns'
                ProcessUtilities.executioner(command)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                "We had errors while creating DKIM record for: " + domain + ". Error message: " + str(msg))
Esempio n. 3
0
 def CronPrem(mode):
     if mode:
         cronParent = '/var/spool/cron'
         commandT = 'chmod 755 %s' % (cronParent)
         ProcessUtilities.executioner(commandT, 'root')
     else:
         cronParent = '/var/spool/cron'
         commandT = 'chmod 700 %s' % (cronParent)
         ProcessUtilities.executioner(commandT, 'root')
Esempio n. 4
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
Esempio n. 5
0
    def stopLiteSpeedSocket():
        try:

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

            return ProcessUtilities.executioner(command)

        except OSError, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartLiteSpeed]")
            return 0
Esempio n. 6
0
    def disableComodo():
        try:

            if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
                confFile = os.path.join(virtualHostUtilities.Server_root,
                                        "conf/httpd_config.conf")
                confData = open(confFile).readlines()
                conf = open(confFile, 'w')

                for items in confData:
                    if items.find('modsec/comodo') > -1:
                        continue
                    else:
                        conf.writelines(items)

                conf.close()
                installUtilities.reStartLiteSpeed()

                print "1,None"

            else:
                try:
                    shutil.rmtree('/usr/local/lsws/conf/comodo_litespeed')
                except BaseException, msg:
                    logging.CyberCPLogFileWriter.writeToFile(
                        str(msg) + ' [disableComodo]')

                installUtilities.reStartLiteSpeed()
                print "1,None"

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [disableComodo]")
            print "0," + str(msg)
Esempio n. 7
0
    def installModSec():
        try:

            mailUtilities.checkHome()

            if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
                command = 'sudo yum install ols-modsecurity -y'
            else:
                command = 'sudo DEBIAN_FRONTEND=noninteractive apt-get install ols-modsecurity -y'

            cmd = shlex.split(command)

            with open(modSec.installLogPath, 'w') as f:
                res = subprocess.call(cmd, stdout=f)

            if res == 1:
                writeToFile = open(modSec.installLogPath, 'a')
                writeToFile.writelines("Can not be installed.[404]\n")
                writeToFile.close()
                logging.CyberCPLogFileWriter.writeToFile("[Could not Install]")
                return 0
            else:
                writeToFile = open(modSec.installLogPath, 'a')
                writeToFile.writelines("ModSecurity Installed.[200]\n")
                writeToFile.close()

            return 1
        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "[installModSec]")
Esempio n. 8
0
    def installSpamAssassin(install, SpamAssassin):
        try:

            if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
                command = 'sudo yum install spamassassin -y'
            else:
                command = 'sudo apt-get install spamassassin spamc -y'

            cmd = shlex.split(command)

            with open(mailUtilities.spamassassinInstallLogPath, 'w') as f:
                res = subprocess.call(cmd, stdout=f)

            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
        except BaseException, msg:
            writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a')
            writeToFile.writelines("Can not be installed.[404]\n")
            writeToFile.close()
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "[installSpamAssassin]")
Esempio n. 9
0
    def unInstallPHPExtension(extension, extensions):
        try:

            mailUtilities.checkHome()

            if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
                command = 'sudo rpm --nodeps -e  ' + extension + ' -v'
            else:
                command = 'sudo apt-get remove -y  ' + extension

            cmd = shlex.split(command)

            try:

                with open(phpUtilities.installLogPath, 'w') as f:
                    subprocess.call(cmd, stdout=f)

                writeToFile = open(phpUtilities.installLogPath, 'a')
                writeToFile.writelines("PHP Extension Removed.\n")
                writeToFile.close()
                installUtilities.installUtilities.reStartLiteSpeed()
                return 1
            except:
                writeToFile = open(phpUtilities.installLogPath, 'a')
                writeToFile.writelines("Can not un-install Extension.\n")
                writeToFile.close()
                logging.CyberCPLogFileWriter.writeToFile("[Could not Install]")
                installUtilities.installUtilities.reStartLiteSpeed()
                return 0

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "[unInstallPHPExtension]")
Esempio n. 10
0
    def remCronbyLine(externalApp, line):
        try:
            line -= 1

            if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
                cronPath = "/var/spool/cron/" + externalApp
            else:
                cronPath = "/var/spool/cron/crontabs/" + externalApp

            data = open(cronPath, 'r').readlines()

            counter = 0

            writeToFile = open(cronPath, 'w')
            for items in data:
                if counter == line:
                    removedLine = items
                    continue
                else:
                    writeToFile.writelines(items)

                counter = counter + 1

            print "1," + removedLine
        except BaseException, msg:
            print "0," + str(msg)
Esempio n. 11
0
    def saveTuningDetails(maxConnections, maxSSLConnections, connectionTimeOut,
                          keepAliveTimeOut, cacheSizeInMemory,
                          gzipCompression):
        if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
            try:
                datas = open(
                    "/usr/local/lsws/conf/httpd_config.conf").readlines()
                writeDataToFile = open(
                    "/usr/local/lsws/conf/httpd_config.conf", "w")

                if gzipCompression == "Enable":
                    gzip = 1
                else:
                    gzip = 0

                for items in datas:
                    if items.find("maxConnections") > -1:
                        data = "  maxConnections          " + str(
                            maxConnections) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("maxSSLConnections") > -1:
                        data = "  maxSSLConnections       " + str(
                            maxSSLConnections) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("connTimeout") > -1:
                        data = "  connTimeout             " + str(
                            connectionTimeOut) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("keepAliveTimeout") > -1:
                        data = "  keepAliveTimeout        " + str(
                            keepAliveTimeOut) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("totalInMemCacheSize") > -1:
                        data = "  totalInMemCacheSize     " + str(
                            cacheSizeInMemory) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("enableGzipCompress") > -1:
                        data = "  enableGzipCompress      " + str(gzip) + "\n"
                        writeDataToFile.writelines(data)
                        continue
                    else:
                        writeDataToFile.writelines(items)

                writeDataToFile.close()

                print "1,None"
            except BaseException, msg:
                logging.CyberCPLogFileWriter.writeToFile(
                    str(msg) + " [saveTuningDetails]")
                print "0," + str(msg)
Esempio n. 12
0
    def saveModSecRules():
        try:
            rulesFile = open(modSec.tempRulesFile, 'r')
            data = rulesFile.read()
            rulesFile.close()

            if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
                rulesFilePath = os.path.join(virtualHostUtilities.Server_root,
                                             "conf/modsec/rules.conf")
            else:
                rulesFilePath = os.path.join(virtualHostUtilities.Server_root,
                                             "conf/rules.conf")

            rulesFile = open(rulesFilePath, 'w')
            rulesFile.write(data)
            rulesFile.close()

            installUtilities.reStartLiteSpeed()

            print "1,None"
            return

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [saveModSecRules]")
            print "0," + str(msg)
Esempio n. 13
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)
Esempio n. 14
0
    def fetchPHPDetails(virtualHost):
        if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
            try:
                path = installUtilities.Server_root_path + "/conf/vhosts/" + virtualHost + "/vhost.conf"

                command = "sudo cat " + path
                datas = ProcessUtilities.outputExecutioner(command).split("\n")

                dataToReturn = {}

                for items in datas:
                    if items.find("maxConns") > -1:
                        data = items.split()
                        dataToReturn['maxConns'] = data[1]

                    if items.find("initTimeout") > -1:
                        data = items.split()
                        dataToReturn['initTimeout'] = data[1]

                    if items.find("persistConn") > -1:
                        data = items.split()
                        dataToReturn['persistConn'] = data[1]

                    if items.find("memSoftLimit") > -1:
                        data = items.split()
                        dataToReturn['memSoftLimit'] = data[1]

                    if items.find("memHardLimit") > -1:
                        data = items.split()
                        dataToReturn['memHardLimit'] = data[1]

                    if items.find("procSoftLimit") > -1:
                        data = items.split()
                        dataToReturn['procSoftLimit'] = data[1]

                    if items.find("procHardLimit") > -1:
                        data = items.split()
                        dataToReturn['procHardLimit'] = data[1]

                return dataToReturn
            except BaseException, msg:
                logging.CyberCPLogFileWriter.writeToFile(
                    str(msg) + " [fetchPHPDetails]")
                return 0
Esempio n. 15
0
    def fetchTuningDetails():
        if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
            try:
                dataToReturn = {}
                command = "sudo cat /usr/local/lsws/conf/httpd_config.conf"
                datas = ProcessUtilities.outputExecutioner(command).split("\n")

                for items in datas:
                    if items.find("maxConnections") > -1:
                        data = items.split()
                        dataToReturn['maxConnections'] = data[1]

                    if items.find("maxSSLConnections") > -1:
                        data = items.split()
                        dataToReturn['maxSSLConnections'] = data[1]

                    if items.find("connTimeout") > -1:
                        data = items.split()
                        dataToReturn['connTimeout'] = data[1]

                    if items.find("maxConnections") > -1:
                        data = items.split()
                        dataToReturn['maxConnections'] = data[1]

                    if items.find("keepAliveTimeout") > -1:
                        data = items.split()
                        dataToReturn['keepAliveTimeout'] = data[1]

                    if items.find("totalInMemCacheSize") > -1:
                        data = items.split()
                        dataToReturn['totalInMemCacheSize'] = data[1]

                    if items.find("enableGzipCompress") > -1:
                        data = items.split()
                        dataToReturn['enableGzipCompress'] = data[1]

                return dataToReturn
            except BaseException, msg:
                logging.CyberCPLogFileWriter.writeToFile(
                    str(msg) + " [fetchTuningDetails]")
                return 0
Esempio n. 16
0
    def checkIfDKIMInstalled():
        try:

            path = "/etc/opendkim.conf"

            command = "sudo cat " + path
            return ProcessUtilities.executioner(command)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [checkIfDKIMInstalled]")
            return 0
Esempio n. 17
0
    def setupComodoRules():
        try:
            if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
                pathTOOWASPFolder = os.path.join(
                    virtualHostUtilities.Server_root, "conf/modsec/comodo")
                extractLocation = os.path.join(
                    virtualHostUtilities.Server_root, "conf/modsec")

                if os.path.exists(pathTOOWASPFolder):
                    shutil.rmtree(pathTOOWASPFolder)

                if os.path.exists('comodo.tar.gz'):
                    os.remove('comodo.tar.gz')

                command = "wget https://" + modSec.mirrorPath + "/modsec/comodo.tar.gz"
                result = subprocess.call(shlex.split(command))

                if result == 1:
                    return 0

                tar = tarfile.open('comodo.tar.gz')
                tar.extractall(extractLocation)
                tar.close()

                return 1
            else:
                if os.path.exists('/usr/local/lsws/conf/comodo_litespeed'):
                    shutil.rmtree('/usr/local/lsws/conf/comodo_litespeed')

                extractLocation = os.path.join(
                    virtualHostUtilities.Server_root, "conf")

                if os.path.exists('cpanel_litespeed_vendor'):
                    os.remove('cpanel_litespeed_vendor')

                command = "wget https://waf.comodo.com/api/cpanel_litespeed_vendor"
                result = subprocess.call(shlex.split(command))

                if result == 1:
                    return 0

                command = "unzip cpanel_litespeed_vendor -d " + extractLocation
                subprocess.call(shlex.split(command))

                return 1

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [setupComodoRules]")
            return 0
Esempio n. 18
0
    def checkHome():
        try:
            try:
                FNULL = open(os.devnull, 'w')

                if getpass.getuser() == 'root':
                    command = "sudo mkdir " + mailUtilities.cyberPanelHome
                    subprocess.call(shlex.split(command), stdout=FNULL)

                    command = "sudo chown -R cyberpanel:cyberpanel " + mailUtilities.cyberPanelHome
                    subprocess.call(shlex.split(command), stdout=FNULL)
                else:
                    command = "sudo mkdir " + mailUtilities.cyberPanelHome
                    ProcessUtilities.executioner(command)

                    command = "sudo chown -R cyberpanel:cyberpanel " + mailUtilities.cyberPanelHome
                    ProcessUtilities.executioner(command)
            except:
                FNULL = open(os.devnull, 'w')
                command = "sudo chown -R cyberpanel:cyberpanel " + mailUtilities.cyberPanelHome
                subprocess.call(shlex.split(command), stdout=FNULL)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [checkHome]")
Esempio n. 19
0
    def getWebsiteCron(externalApp):
        try:

            if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
                cronPath = "/var/spool/cron/" + externalApp
            else:
                cronPath = "/var/spool/cron/crontabs/" + externalApp

            try:
                f = open(cronPath, 'r').read()
                print f
            except BaseException, msg:
                print "0,CyberPanel," + str(msg)
                return 1

        except BaseException, msg:
            print "0,CyberPanel," + str(msg)
Esempio n. 20
0
    def checkIfSpamAssassinInstalled():
        try:

            path = "/etc/mail/spamassassin/local.cf"

            command = "sudo cat " + path
            output = ProcessUtilities.outputExecutioner(command)

            if output.find('No such') > -1:
                return 0
            else:
                return 1

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [checkIfSpamAssassinInstalled]")
            return 0
Esempio n. 21
0
    def saveCronChanges(externalApp, finalCron, line):
        try:

            if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
                cronPath = "/var/spool/cron/" + externalApp
            else:
                cronPath = "/var/spool/cron/crontabs/" + externalApp

            with open(cronPath, 'r') as file:
                data = file.readlines()

            data[line] = finalCron + '\n'

            with open(cronPath, 'w') as file:
                file.writelines(data)

            print "1,None"
        except BaseException, msg:
            print "0," + str(msg)
Esempio n. 22
0
    def reStartOpenLiteSpeed(restart,orestart):
        try:

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

            cmd = shlex.split(command)
            res = subprocess.call(cmd)

            if res == 1:
                print("###############################################")
                print("         Could not restart Litespeed serve     ")
                print("###############################################")
                sys.exit()
            else:
                print("###############################################")
                print("          Litespeed Re-Started                 ")
                print("###############################################")

        except OSError, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartOpenLiteSpeed]")
            return 0
Esempio n. 23
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)
Esempio n. 24
0
    def savePHPConfigBasic(phpVers, allow_url_fopen, display_errors,
                           file_uploads, allow_url_include, memory_limit,
                           max_execution_time, upload_max_filesize,
                           max_input_time, post_max_size):
        try:

            if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
                path = "/usr/local/lsws/ls" + phpVers + "/etc/php.ini"
            else:
                initial = phpVers[3]
                final = phpVers[4]

                completeName = str(initial) + '.' + str(final)
                path = "/usr/local/lsws/ls" + phpVers + "/etc/php/" + completeName + "/litespeed/php.ini"

            logging.CyberCPLogFileWriter.writeToFile(path)

            data = open(path, 'r').readlines()

            writeToFile = open(path, 'w')

            for items in data:
                if items.find("allow_url_fopen") > -1 and items.find("=") > -1:
                    writeToFile.writelines(allow_url_fopen + "\n")
                elif items.find("display_errors") > -1 and items.find(
                        "=") > -1:
                    writeToFile.writelines(display_errors + "\n")
                elif items.find("file_uploads") > -1 and items.find(
                        "=") > -1 and not items.find("max_file_uploads") > -1:
                    writeToFile.writelines(file_uploads + "\n")
                elif items.find("allow_url_include") > -1 and items.find(
                        "=") > -1:
                    writeToFile.writelines(allow_url_include + "\n")

                elif items.find("memory_limit") > -1 and items.find("=") > -1:
                    writeToFile.writelines("memory_limit = " + memory_limit +
                                           "\n")

                elif items.find("max_execution_time") > -1 and items.find(
                        "=") > -1:
                    writeToFile.writelines("max_execution_time = " +
                                           max_execution_time + "\n")

                elif items.find("upload_max_filesize") > -1 and items.find(
                        "=") > -1:
                    writeToFile.writelines("upload_max_filesize = " +
                                           upload_max_filesize + "\n")

                elif items.find("max_input_time") > -1 and items.find(
                        "=") > -1:
                    writeToFile.writelines("max_input_time = " +
                                           max_input_time + "\n")
                elif items.find("post_max_size") > -1 and items.find("=") > -1:
                    writeToFile.writelines("post_max_size = " + post_max_size +
                                           "\n")
                else:
                    writeToFile.writelines(items)

            writeToFile.close()

            installUtilities.installUtilities.reStartLiteSpeed()

            print "1,None"

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + " [savePHPConfigBasic]")
            print "0," + str(msg)
Esempio n. 25
0
                    if items.find("enableGzipCompress") > -1:
                        data = items.split()
                        dataToReturn['enableGzipCompress'] = data[1]

                return dataToReturn
            except BaseException, msg:
                logging.CyberCPLogFileWriter.writeToFile(
                    str(msg) + " [fetchTuningDetails]")
                return 0
        else:
            try:
                dataToReturn = {}

                command = "sudo cat /usr/local/lsws/conf/httpd_config.xml"
                datas = ProcessUtilities.outputExecutioner(command)
                comTree = ElementTree.fromstring(datas)
                tuningData = comTree.find('tuning')

                dataToReturn['maxConnections'] = tuningData.find(
                    'maxConnections').text
                dataToReturn['maxSSLConnections'] = tuningData.find(
                    'maxSSLConnections').text
                dataToReturn['connTimeout'] = tuningData.find(
                    'connTimeout').text
                dataToReturn['keepAliveTimeout'] = tuningData.find(
                    'keepAliveTimeout').text
                dataToReturn['totalInMemCacheSize'] = tuningData.find(
                    'totalInMemCacheSize').text
                dataToReturn['enableGzipCompress'] = tuningData.find(
                    'enableGzipCompress').text
Esempio n. 26
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)
Esempio n. 27
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
Esempio n. 28
0
    def dnsTemplate(domain, admin):
        try:

            ipFile = "/etc/cyberpanel/machineIP"
            f = open(ipFile)
            ipData = f.read()
            ipAddress = ipData.split('\n', 1)[0]

            import tldextract

            extractDomain = tldextract.extract(domain)
            topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
            subDomain = extractDomain.subdomain

            if len(subDomain) == 0:

                if Domains.objects.filter(name=topLevelDomain).count() == 0:
                    try:
                        pdns = PDNSStatus.objects.get(pk=1)
                        if pdns.type == 'MASTER':
                            zone = Domains(admin=admin, name=topLevelDomain, type="MASTER")
                            zone.save()

                            for items in SlaveServers.objects.all():
                                record = Records(domainOwner=zone,
                                                 domain_id=zone.id,
                                                 name=topLevelDomain,
                                                 type="NS",
                                                 content=items.slaveServer,
                                                 ttl=3600,
                                                 prio=0,
                                                 disabled=0,
                                                 auth=1)
                                record.save()

                        else:
                            zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
                    except:
                        zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")


                    zone.save()

                    if zone.type == 'NATIVE':

                        record = Records(domainOwner=zone,
                                         domain_id=zone.id,
                                         name=topLevelDomain,
                                         type="NS",
                                         content='hostmaster.%s' % (topLevelDomain),
                                         ttl=3600,
                                         prio=0,
                                         disabled=0,
                                         auth=1)
                        record.save()

                        if os.path.exists(DNS.defaultNameServersPath):
                            defaultNS = open(DNS.defaultNameServersPath, 'r').readlines()

                            for items in defaultNS:
                                record = Records(domainOwner=zone,
                                                 domain_id=zone.id,
                                                 name=topLevelDomain,
                                                 type="NS",
                                                 content=items,
                                                 ttl=3600,
                                                 prio=0,
                                                 disabled=0,
                                                 auth=1)
                                record.save()
                        else:
                            record = Records(domainOwner=zone,
                                             domain_id=zone.id,
                                             name=topLevelDomain,
                                             type="NS",
                                             content='ns1.%s' % (topLevelDomain),
                                             ttl=3600,
                                             prio=0,
                                             disabled=0,
                                             auth=1)
                            record.save()

                            record = Records(domainOwner=zone,
                                             domain_id=zone.id,
                                             name=topLevelDomain,
                                             type="NS",
                                             content='ns2.%s' % (topLevelDomain),
                                             ttl=3600,
                                             prio=0,
                                             disabled=0,
                                             auth=1)
                            record.save()

                    content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"

                    soaRecord = Records(domainOwner=zone,
                                        domain_id=zone.id,
                                        name=topLevelDomain,
                                        type="SOA",
                                        content=content,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1)
                    soaRecord.save()

                    ## Main A record.

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=topLevelDomain,
                                     type="A",
                                     content=ipAddress,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    # CNAME Records.

                    cNameValue = "www." + topLevelDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=cNameValue,
                                     type="CNAME",
                                     content=topLevelDomain,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    cNameValue = "ftp." + topLevelDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=cNameValue,
                                     type="CNAME",
                                     content=topLevelDomain,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    ## MX Record.

                    mxValue = "mail." + topLevelDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=topLevelDomain,
                                     type="MX",
                                     content=mxValue,
                                     ttl=3600,
                                     prio="10",
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=mxValue,
                                     type="A",
                                     content=ipAddress,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    ## TXT Records for mail

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=topLevelDomain,
                                     type="TXT",
                                     content="v=spf1 a mx ip4:" + ipAddress + " ~all",
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name="_dmarc." + topLevelDomain,
                                     type="TXT",
                                     content="v=DMARC1; p=none",
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name="_domainkey." + topLevelDomain,
                                     type="TXT",
                                     content="t=y; o=~;",
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()
            else:
                if Domains.objects.filter(name=topLevelDomain).count() == 0:
                    try:
                        pdns = PDNSStatus.objects.get(pk=1)
                        if pdns.type == 'MASTER':
                            zone = Domains(admin=admin, name=topLevelDomain, type="MASTER")
                        else:
                            zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")
                    except:
                        zone = Domains(admin=admin, name=topLevelDomain, type="NATIVE")

                    content = "ns1." + topLevelDomain + " hostmaster." + topLevelDomain + " 1 10800 3600 604800 3600"

                    soaRecord = Records(domainOwner=zone,
                                        domain_id=zone.id,
                                        name=topLevelDomain,
                                        type="SOA",
                                        content=content,
                                        ttl=3600,
                                        prio=0,
                                        disabled=0,
                                        auth=1)
                    soaRecord.save()

                    ## Main A record.

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=topLevelDomain,
                                     type="A",
                                     content=ipAddress,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    # CNAME Records.

                    cNameValue = "www." + topLevelDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=cNameValue,
                                     type="CNAME",
                                     content=topLevelDomain,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    cNameValue = "ftp." + topLevelDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=cNameValue,
                                     type="CNAME",
                                     content=topLevelDomain,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    ## MX Record.

                    mxValue = "mail." + topLevelDomain

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=topLevelDomain,
                                     type="MX",
                                     content=mxValue,
                                     ttl=3600,
                                     prio="10",
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=mxValue,
                                     type="A",
                                     content=ipAddress,
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    ## TXT Records for mail

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=topLevelDomain,
                                     type="TXT",
                                     content="v=spf1 a mx ip4:" + ipAddress + " ~all",
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name="_dmarc." + topLevelDomain,
                                     type="TXT",
                                     content="v=DMARC1; p=none",
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name="_domainkey." + topLevelDomain,
                                     type="TXT",
                                     content="t=y; o=~;",
                                     ttl=3600,
                                     prio=0,
                                     disabled=0,
                                     auth=1)
                    record.save()

                ## Creating sub-domain level record.

                zone = Domains.objects.get(name=topLevelDomain)

                actualSubDomain = subDomain + "." + topLevelDomain

                ## Main A record.

                DNS.createDNSRecord(zone, actualSubDomain, "A", ipAddress, 0, 3600)

                # CNAME Records.

                cNameValue = "www." + actualSubDomain

                DNS.createDNSRecord(zone, cNameValue, "CNAME", actualSubDomain, 0, 3600)

            if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                command = 'sudo systemctl restart pdns'
                ProcessUtilities.executioner(command)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                "We had errors while creating DNS records for: " + domain + ". Error message: " + str(msg))
Esempio n. 29
0
    def tunePHP(virtualHost, maxConns, initTimeout, persistConn, memSoftLimit,
                memHardLimit, procSoftLimit, procHardLimit):
        if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
            try:
                path = installUtilities.Server_root_path + "/conf/vhosts/" + virtualHost + "/vhost.conf"
                datas = open(path).readlines()

                writeDataToFile = open(path, "w")

                for items in datas:
                    if items.find("maxConns") > -1:
                        data = "  maxConns                " + str(
                            maxConns) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("initTimeout") > -1:
                        data = "  initTimeout             " + str(
                            initTimeout) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("memSoftLimit") > -1:
                        data = "  memSoftLimit            " + str(
                            memSoftLimit) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("memHardLimit") > -1:
                        data = "  memHardLimit            " + str(
                            memHardLimit) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("procSoftLimit") > -1:
                        data = "  procSoftLimit           " + str(
                            procSoftLimit) + "\n"
                        writeDataToFile.writelines(data)
                        continue

                    elif items.find("procHardLimit") > -1:
                        data = "  procHardLimit           " + str(
                            procHardLimit) + "\n"
                        writeDataToFile.writelines(data)
                        continue
                    elif items.find("persistConn") > -1:
                        if persistConn == "Enable":
                            persist = 1
                        else:
                            persist = 0

                        data = "  persistConn             " + str(
                            persist) + "\n"
                        writeDataToFile.writelines(data)
                        continue
                    else:
                        writeDataToFile.writelines(items)

                writeDataToFile.close()

                print "1,None"
            except BaseException, msg:
                logging.CyberCPLogFileWriter.writeToFile(
                    str(msg) + " [saveTuningDetails]")
                print "0," + str(msg)
Esempio n. 30
0
    def createDNSRecord(zone, name, type, value, priority, ttl):
        try:

            if zone.type == 'MASTER':
                getSOA = Records.objects.get(domainOwner=zone, type='SOA')
                soaContent = getSOA.content.split(' ')
                soaContent[2] = str(int(soaContent[2]) + 1)
                getSOA.content = " ".join(soaContent)
                getSOA.save()



            if type == 'NS':
                if Records.objects.filter(name=name, type=type, content=value).count() == 0:
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=name,
                                     type=type,
                                     content=value,
                                     ttl=ttl,
                                     prio=priority,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                        command = 'sudo systemctl restart pdns'
                        ProcessUtilities.executioner(command)

                return

            if type == 'TXT':
                if Records.objects.filter(name=name, type=type, content=value).count() == 0:
                    record = Records(domainOwner=zone,
                                     domain_id=zone.id,
                                     name=name,
                                     type=type,
                                     content=value,
                                     ttl=ttl,
                                     prio=priority,
                                     disabled=0,
                                     auth=1)
                    record.save()

                    if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                        command = 'sudo systemctl restart pdns'
                        ProcessUtilities.executioner(command)
                return

            if type == 'MX':
                record = Records(domainOwner=zone,
                                 domain_id=zone.id,
                                 name=name,
                                 type=type,
                                 content=value,
                                 ttl=ttl,
                                 prio=priority,
                                 disabled=0,
                                 auth=1)
                record.save()

                if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                    command = 'sudo systemctl restart pdns'
                    ProcessUtilities.executioner(command)
                return


            if Records.objects.filter(name=name, type=type).count() == 0:
                record = Records(domainOwner=zone,
                                 domain_id=zone.id,
                                 name=name,
                                 type=type,
                                 content=value,
                                 ttl=ttl,
                                 prio=priority,
                                 disabled=0,
                                 auth=1)
                record.save()
                if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                    command = 'sudo systemctl restart pdns'
                    ProcessUtilities.executioner(command)
        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDNSRecord]")