Exemple #1
0
    def ExtractBackup(self):
        try:

            message = 'Extracting main cPanel archive file: %s' % (
                self.backupFile)
            logging.statusWriter(self.logFile, message, 1)

            if not os.path.exists(cPanelImporter.mainBackupPath):
                os.mkdir(cPanelImporter.mainBackupPath)

            os.chdir(cPanelImporter.mainBackupPath)

            command = 'tar -xf %s --directory %s' % (
                self.backupFile, cPanelImporter.mainBackupPath)
            ProcessUtilities.normalExecutioner(command)

            message = '%s successfully extracted.' % (self.backupFile)
            logging.statusWriter(self.logFile, message, 1)

            return 1

        except BaseException, msg:
            message = 'Failed to extract backup for file %s, error message: %s. [ExtractBackup]' % (
                self.backupFile, str(msg))
            logging.statusWriter(self.logFile, message, 1)
            return 0
    def prepare():
        try:
            backupLogPath = "/usr/local/lscp/logs/local_backup_log." + time.strftime(
                "%m.%d.%Y_%H-%M-%S")

            writeToFile = open(backupLogPath, "a")

            backupSchedule.remoteBackupLogging(
                backupLogPath,
                "#################################################")
            backupSchedule.remoteBackupLogging(
                backupLogPath, "      Local Backup log for: " +
                time.strftime("%m.%d.%Y_%H-%M-%S"))
            backupSchedule.remoteBackupLogging(
                backupLogPath,
                "#################################################\n")

            backupSchedule.remoteBackupLogging(backupLogPath, "")
            backupSchedule.remoteBackupLogging(backupLogPath, "")

            for virtualHost in os.listdir("/home"):
                if match(
                        r'([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?',
                        virtualHost, M | I):
                    retValues = backupSchedule.createLocalBackup(
                        virtualHost, backupLogPath)

                    if os.path.exists(backupScheduleLocal.localBackupPath):
                        backupPath = retValues[1] + ".tar.gz"
                        localBackupPath = '%s/%s' % (open(
                            backupScheduleLocal.localBackupPath,
                            'r').read().rstrip('/'), time.strftime("%b-%d-%Y"))

                        command = 'mkdir -p %s' % (localBackupPath)
                        ProcessUtilities.normalExecutioner(command)

                        command = 'mv %s %s' % (backupPath, localBackupPath)
                        ProcessUtilities.normalExecutioner(command)

                backupSchedule.remoteBackupLogging(backupLogPath, "")
                backupSchedule.remoteBackupLogging(backupLogPath, "")

                backupSchedule.remoteBackupLogging(
                    backupLogPath,
                    "#################################################")

                backupSchedule.remoteBackupLogging(backupLogPath, "")
                backupSchedule.remoteBackupLogging(backupLogPath, "")

            backupSchedule.remoteBackupLogging(
                backupLogPath, "Local backup job completed.\n")

            writeToFile.close()

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + " [214:startBackup]")
Exemple #3
0
    def GenerateSelfSignedSSL(virtualHostName):
        if os.path.exists(ApacheVhost.sslBasePath):
            pass
        else:
            os.mkdir(ApacheVhost.sslBasePath)

        pathToStoreSSLPrivKey = ApacheVhost.sslBasePath + virtualHostName + ".privkey.pem"
        pathToStoreSSLFullChain = ApacheVhost.sslBasePath + virtualHostName + ".fullchain.pem"
        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 ' + pathToStoreSSLPrivKey + ' -out ' + pathToStoreSSLFullChain
        ProcessUtilities.normalExecutioner(command)
Exemple #4
0
    def DeleteApacheVhost(virtualHostName):
        try:
            finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf'

            if os.path.exists(finalConfPath):
                os.remove(finalConfPath)

            ApacheVhost.deletePHPPath(virtualHostName)

            command = "systemctl restart httpd"
            ProcessUtilities.normalExecutioner(command)

        except BaseException, msg:
            logging.writeToFile(str(msg))
    def saveSSHConfigs(type, sshPort, rootLogin):
        try:
            if type == "1":

                command = 'sudo semanage port -a -t ssh_port_t -p tcp ' + sshPort
                ProcessUtilities.normalExecutioner(command)

                FirewallUtilities.addRule('tcp', sshPort, "0.0.0.0/0")


                if rootLogin == "1":
                    rootLogin = "******"
                else:
                    rootLogin = "******"

                sshPort = "Port " + sshPort + "\n"

                pathToSSH = "/etc/ssh/sshd_config"

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

                writeToFile = open(pathToSSH, "w")

                for items in data:
                    if items.find("PermitRootLogin") > -1:
                        if items.find("Yes") > -1 or items.find("yes"):
                            writeToFile.writelines(rootLogin)
                            continue
                    elif items.find("Port") > -1:
                        writeToFile.writelines(sshPort)
                    else:
                        writeToFile.writelines(items)
                writeToFile.close()

                command = 'sudo systemctl restart sshd'
                ProcessUtilities.normalExecutioner(command)

                print "1,None"

        except BaseException, msg:
            print "0," + str(msg)
Exemple #6
0
    def test_issueSSL(self):
        ## Issue SSL

        data_ret = {'virtualHost': 'cyberpanel.xyz'}

        response = self.MakeRequest('manageSSL/issueSSL', data_ret)

        self.assertEqual(response['status'], 1)

        ## Verify SSL

        command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        path = '/home/%s/public_html/index.html' % ('cyberpanel.xyz')

        writeToFile = open(path, 'w')
        writeToFile.write('CyberPanel')
        writeToFile.close()

        exists = 0
        if self.MakeRequestRaw('https://cyberpanel.xyz').find('CyberPanel') > -1:
            exists = 1

        self.assertEqual(exists, 1)
Exemple #7
0
    def FixPermissions(self):
        externalApp = self.externalApp
        command = "sudo chown -R " + externalApp + ":" + externalApp + " /home/" + self.mainDomain
        ProcessUtilities.normalExecutioner(command)

        command = "sudo chown -R root:nobody /home/" + self.mainDomain + "/logs"
        ProcessUtilities.normalExecutioner(command)

        command = "sudo find %s -type d -exec chmod 0755 {} \;" % (
            "/home/" + self.mainDomain + "/public_html")
        ProcessUtilities.normalExecutioner(command)

        command = "sudo find %s -type f -exec chmod 0644 {} \;" % (
            "/home/" + self.mainDomain + "/public_html")
        ProcessUtilities.normalExecutioner(command)
Exemple #8
0
    def changePHP(phpVersion, vhFile):
        try:

            virtualHostName = vhFile.split('/')[6]

            finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf'

            if not os.path.exists(finalConfPath):
                return 0

            ApacheVhost.deletePHPPath(virtualHostName)

            website = Websites.objects.get(domain=virtualHostName)

            php = PHPManager.getPHPString(phpVersion)

            finalConfPath = ApacheVhost.DecidePHPPath(php, virtualHostName)

            confFile = open(finalConfPath, "w+")
            currentConf = vhostConfs.phpFpmPool
            currentConf = currentConf.replace('{www}', website.externalApp)
            currentConf = currentConf.replace('{Sock}', virtualHostName)
            currentConf = currentConf.replace('{externalApp}',
                                              website.externalApp)

            confFile.write(currentConf)

            command = "systemctl stop php%s-php-fpm" % (php)
            ProcessUtilities.normalExecutioner(command)

            command = "systemctl restart php%s-php-fpm" % (php)
            ProcessUtilities.normalExecutioner(command)

            return 1
        except BaseException, msg:
            logging.writeToFile(str(msg))
            return 1
Exemple #9
0
    def test_magentoInstall(self):

        command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        ## Suspend  check
        data_ret = {'domain': 'cyberpanel.xyz', 'home': '1','firstName': 'Usman', 'lastName': 'Nasir',
                    'passwordByPass': '******', 'sampleData': False, 'email': '*****@*****.**', 'username': '******'}

        response = self.MakeRequest('websites/magentoInstall', data_ret)
        logging.writeToFile('ps: ' + str(response))
        time.sleep(2)

        self.assertEqual(response['status'], 1)
        tempStatusPath = response['tempStatusPath']

        ## Wait for install to complete

        data_ret = {'statusFile': tempStatusPath, 'domainName': 'cyberpanel.xyz'}

        while True:
            response = self.MakeRequest('websites/installWordpressStatus', data_ret)
            time.sleep(1)
            if response['abort'] == 1:
                if response['installStatus'] == 1:
                    break
                else:
                    logging.writeToFile(response['error_message'])
                    break


        exists = 0

        if self.MakeRequestRaw('http://cyberpanel.xyz').find('Magento') > -1:
            exists = 1

        self.assertEqual(exists, 1)
Exemple #10
0
    def test_installJoomla(self):

        command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz')
        ProcessUtilities.normalExecutioner(command)

        ## Suspend  check
        data_ret = {'domain': 'cyberpanel.xyz', 'home': '1', 'sitename': 'Unit Test Joomla', 'username': '******',
                    'passwordByPass': '******', 'prefix': 'db_'}

        response = self.MakeRequest('websites/installJoomla', data_ret)
        time.sleep(2)

        self.assertEqual(response['status'], 1)
        tempStatusPath = response['tempStatusPath']

        ## Wait for install to complete

        data_ret = {'statusFile': tempStatusPath, 'domainName': 'cyberpanel.xyz'}

        while True:
            response = self.MakeRequest('websites/installWordpressStatus', data_ret)
            time.sleep(1)
            if response['abort'] == 1:
                if response['installStatus'] == 1:
                    break
                else:
                    logging.writeToFile(response['error_message'])
                    break


        exists = 0

        if self.MakeRequestRaw('http://cyberpanel.xyz').find('Unit Test Joomla') > -1:
            exists = 1

        self.assertEqual(exists, 1)
Exemple #11
0
    def installCSF():
        try:
            ##

            logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Downloading CSF..\n', 1)

            command = 'wget ' + CSF.csfURL
            ProcessUtilities.normalExecutioner(command)

            ##

            logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Extracting CSF..\n', 1)

            command = 'tar -xzf csf.tgz'
            ProcessUtilities.normalExecutioner(command)

            ##

            logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Installing CSF..\n', 1)

            os.chdir('csf')

            command = "chmod +x install.sh"
            ProcessUtilities.normalExecutioner(command)

            command = 'bash install.sh'
            ProcessUtilities.normalExecutioner(command)

            command = 'mv /etc/csf/ui/server.crt /etc/csf/ui/server.crt-bak'
            ProcessUtilities.normalExecutioner(command)

            command = 'mv /etc/csf/ui/server.key /etc/csf/ui/server.key-bak'
            ProcessUtilities.normalExecutioner(command)

            command = 'ln -s /usr/local/lscp/conf/cert.pem /etc/csf/ui/server.crt'
            ProcessUtilities.normalExecutioner(command)

            command = 'ln -s /usr/local/lscp/conf/key.pem /etc/csf/ui/server.key'
            ProcessUtilities.normalExecutioner(command)

            # install required packages for CSF perl and /usr/bin/host
            if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
                command = 'yum install bind-utils net-tools perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph ipset -y'
                ProcessUtilities.normalExecutioner(command)
            elif ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                command = 'apt-get install dnsutils libwww-perl liblwp-protocol-https-perl libgd-graph-perl net-tools ipset -y'
                ProcessUtilities.normalExecutioner(command)
                command = 'ln -s /bin/systemctl /usr/bin/systemctl'
                ProcessUtilities.normalExecutioner(command)
            else:

                logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath,
                                                          'CSF required packages successfully Installed.[200]\n', 1)

            # Some initial configurations

            data = open('/etc/csf/csf.conf', 'r').readlines()
            writeToConf = open('/etc/csf/csf.conf', 'w')

            for items in data:
                if items.find('TCP_IN') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines(
                        'TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,1025,8090,40110:40210"\n')
                elif items.find('TCP_OUT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines(
                        'TCP_OUT = "20,21,22,25,43,53,80,110,113,443,587,993,995,8090,40110:40210"\n')
                elif items.find('UDP_IN') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('UDP_IN = "20,21,53"\n')
                elif items.find('UDP_OUT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('UDP_OUT = "20,21,53,113,123"\n')
                elif items.find('TESTING =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('TESTING = "0"\n')
                # setting RESTRICT_SYSLOG to "3" for use with option RESTRICT_SYSLOG_GROUP
                elif items.find('RESTRICT_SYSLOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RESTRICT_SYSLOG = "3"\n')

                #  Send an email alert if an IP address is blocked by one of the [*] triggers: disabled
                elif items.find('LF_EMAIL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_EMAIL_ALERT = "0"\n')

                # Set LF_PERMBLOCK_ALERT to "0" to disable this feature
                elif items.find('LF_PERMBLOCK_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_PERMBLOCK_ALERT = "0"\n')

                #  Set LF_NETBLOCK_ALERT to "0" to disable this feature
                elif items.find('LF_NETBLOCK_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_NETBLOCK_ALERT = "0"\n')

                # Login Failure Blocking and Alerts
                # LF_TRIGGER_PERM = "1800" => the IP is blocked temporarily for 30 minutes
                elif items.find('LF_TRIGGER_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_TRIGGER_PERM = "1800"\n')

                #  Enable login failure detection of sshd connections: 10 failures triggers
                elif items.find('LF_SSHD =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_SSHD = "10"\n')

                #  LF_SSHD_PERM = "1800" => the IP is blocked temporarily for 30 minutes
                elif items.find('LF_SSHD_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_SSHD_PERM = "1800"\n')

                #  Enable login failure detection of ftp connections: 10 failures triggers
                elif items.find('LF_FTPD =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_FTPD = "10"\n')

                #  LF_FTPD_PERM = "1800" => the IP is blocked temporarily for 30 minutes
                elif items.find('LF_FTPD_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_FTPD_PERM = "1800"\n')

                #  Enable login failure detection of SMTP AUTH connections: 10 failures triggers
                elif items.find('LF_SMTPAUTH =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_SMTPAUTH = "10"\n')

                #  LF_SMTPAUTH_PERM = "1800" => the IP is blocked temporarily for 30 minutes
                elif items.find('LF_SMTPAUTH_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_SMTPAUTH_PERM = "1800"\n')

                #  Enable login failure detection of pop3 connections: 10 failures triggers
                elif items.find('LF_POP3D =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_POP3D = "10"\n')

                #  LF_POP3D_PERM = "1800" => the IP is blocked temporarily for 30 minutes
                elif items.find('LF_POP3D_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_POP3D_PERM = "1800"\n')

                #  Enable login failure detection of imap connections: 10 failures triggers
                elif items.find('LF_IMAPD =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_IMAPD = "10"\n')

                #  LF_IMAPD_PERM = "1800" => the IP is blocked temporarily for 30 minutes
                elif items.find('LF_IMAPD_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_IMAPD_PERM = "1800"\n')

                #  LF_HTACCESS_PERM = "1800" => the IP is blocked temporarily for 30 minutes
                elif items.find('LF_HTACCESS_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_HTACCESS_PERM = "1800"\n')

                #  Enable failure detection of repeated Apache mod_security rule triggers: 10 failures triggers
                elif items.find('LF_MODSEC =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_MODSEC = "10"\n')

                #  LF_MODSEC_PERM = "1800" => the IP is blocked temporarily for 30 minutes
                elif items.find('LF_MODSEC_PERM') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_MODSEC_PERM = "1800"\n')

                #  MODSEC_LOG location
                elif items.find('MODSEC_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('MODSEC_LOG = "/usr/local/lsws/logs/auditmodsec.log"\n')

                #  Send an email alert if anyone logs in successfully using SSH: Disabled
                elif items.find('LF_SSH_EMAIL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_SSH_EMAIL_ALERT = "0"\n')

                #  Send an email alert if anyone accesses webmin: Disabled not applicable
                elif items.find('LF_WEBMIN_EMAIL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_WEBMIN_EMAIL_ALERT = "0"\n')

                #  LF_QUEUE_ALERT disabled
                elif items.find('LF_QUEUE_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_QUEUE_ALERT = "0"\n')

                #  LF_QUEUE_INTERVAL disabled
                elif items.find('LF_QUEUE_INTERVAL = "0"') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_TRIGGER_PERM = "1800"\n')

                #  Relay Tracking. This allows you to track email that is relayed through the server. Disabled
                elif items.find('RT_RELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_RELAY_ALERT = "0"\n')

                #  RT_[relay type]_LIMIT: the limit/hour afterwhich an email alert will be sent
                elif items.find('RT_RELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_RELAY_LIMIT = "500"\n')

                #  RT_[relay type]_BLOCK: 0 = no block;1 = perm block;nn=temp block for nn secs
                elif items.find('RT_RELAY_BLOCK') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_RELAY_BLOCK = "0"\n')

                #   This option triggers for email authenticated by SMTP AUTH disabled
                elif items.find('RT_AUTHRELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_AUTHRELAY_ALERT = "0"\n')

                #  RT_AUTHRELAY_LIMIT set to 100
                elif items.find('RT_AUTHRELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_AUTHRELAY_LIMIT = "100"\n')

                #  RT_AUTHRELAY_LIMIT set to 0
                elif items.find('RT_AUTHRELAY_BLOCK') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_AUTHRELAY_BLOCK = "0"\n')

                #   This option triggers for email authenticated by POP before SMTP
                elif items.find('RT_POPRELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_POPRELAY_ALERT = "0"\n')

                #   This option triggers for email authenticated by POP before SMTP
                elif items.find('RT_POPRELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_POPRELAY_LIMIT = "100"\n')

                #  RT_POPRELAY_BLOCK disabled
                elif items.find('RT_POPRELAY_BLOCK') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_POPRELAY_BLOCK = "0"\n')

                #   This option triggers for email sent via /usr/sbin/sendmail or /usr/sbin/exim: Disabled
                elif items.find('RT_LOCALRELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_LOCALRELAY_ALERT = "0"\n')

                #   This option triggers for email sent via a local IP addresses
                elif items.find('RT_LOCALRELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_LOCALRELAY_LIMIT = "100"\n')

                #   This option triggers for email sent via a local IP addresses
                elif items.find('RT_LOCALHOSTRELAY_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_LOCALHOSTRELAY_ALERT = "0"\n')

                #   This option triggers for email sent via a local IP addresses disabled
                elif items.find('RT_LOCALHOSTRELAY_LIMIT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_LOCALHOSTRELAY_LIMIT = "100"\n')

                #  If an RT_* event is triggered, then if the following contains the path to a script
                elif items.find('RT_ACTION') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('RT_ACTION = ""\n')

                #   Send an email alert if an IP address is blocked due to connection tracking disabled
                elif items.find('CT_EMAIL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('CT_EMAIL_ALERT = "0"\n')

                #  User Process Tracking.  Set to 0 to disable this feature
                elif items.find('PT_USERPROC =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('PT_USERPROC = "0"\n')

                #  This User Process Tracking option sends an alert if any user process exceeds the virtual memory usage set (MB)
                elif items.find('PT_USERMEM =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('PT_USERMEM = "0"\n')

                #  This User Process Tracking option sends an alert if any user process exceeds the RSS memory usage set (MB) - RAM used, not virtual.
                elif items.find('PT_USERRSS =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('PT_USERRSS = "0"\n')

                #  If this option is set then processes detected by PT_USERMEM, PT_USERTIME or PT_USERPROC are killed. Disabled
                elif items.find('PT_USERTIME =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('PT_USERTIME = "0"\n')

                #  If you want to disable email alerts if PT_USERKILL is triggered, then set this option to 0. Disabled
                elif items.find('PT_USERKILL_ALERT') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('PT_USERKILL_ALERT = "0"\n')

                #  Check the PT_LOAD_AVG minute Load Average (can be set to 1 5 or 15 and defaults to 5 if set otherwise) on the server every PT_LOAD seconds. Disabled
                elif items.find('PT_LOAD =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('PT_LOAD = "0"\n')

                #  Enable LF_IPSET for CSF for more efficient ipables rules with ipset
                elif items.find('LF_IPSET =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('LF_IPSET = "1"\n')

                #  HTACCESS_LOG is ins main error.log
                elif items.find('HTACCESS_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('HTACCESS_LOG = "/usr/local/lsws/logs/error.log"\n')

                #  SYSLOG_CHECK Check whether syslog is running
                elif items.find('SYSLOG_CHECK =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                    writeToConf.writelines('SYSLOG_CHECK = "300"\n')

                #  CSF UI enable
                # elif items.find('UI = "0"') > -1 and items.find('=') > -1 and (items[0] != '#'):
                #    writeToConf.writelines('UI = "1"\n')
                # elif items.find('UI_ALLOW') > -1 and items.find('=') > -1 and (items[0] != '#'):
                #    writeToConf.writelines('UI_ALLOW = "0"\n')
                # elif items.find('UI_PORT =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                #    writeToConf.writelines('UI_PORT = "1025"\n')
                # elif items.find('UI_USER') > -1 and items.find('=') > -1 and (items[0] != '#'):
                #    writeToConf.writelines('UI_USER = "******"\n')
                # elif items.find('UI_PASS') > -1 and items.find('=') > -1 and (items[0] != '#'):
                #    writeToConf.writelines('UI_PASS = "******"\n')
                else:
                    writeToConf.writelines(items)

            writeToConf.close()

            ##

            # Some Ubuntu initial configurations
            if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
                data = open('/etc/csf/csf.conf', 'r').readlines()
                writeToConf = open('/etc/csf/csf.conf', 'w')

                for items in data:
                    if items.find('SSHD_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                        writeToConf.writelines('SSHD_LOG = "/var/log/auth.log"\n')
                    elif items.find('SU_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                        writeToConf.writelines('SU_LOG = "/var/log/auth.log"\n')
                    elif items.find('SMTPAUTH_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                        writeToConf.writelines('SMTPAUTH_LOG = "/var/log/mail.log"\n')
                    elif items.find('POP3D_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                        writeToConf.writelines('POP3D_LOG = "/var/log/mail.log"\n')
                    elif items.find('IMAPD_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                        writeToConf.writelines('IMAPD_LOG = "/var/log/mail.log"\n')
                    elif items.find('IPTABLES_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                        writeToConf.writelines('IPTABLES_LOG = "/var/log/kern.log"\n')
                    elif items.find('SYSLOG_LOG =') > -1 and items.find('=') > -1 and (items[0] != '#'):
                        writeToConf.writelines('SYSLOG_LOG = "/var/log/syslog"\n')
                    else:
                        writeToConf.writelines(items)
                writeToConf.close()

                ##

            command = 'csf -s'
            ProcessUtilities.normalExecutioner(command)

            command = 'sleep 5'
            ProcessUtilities.normalExecutioner(command)

            command = 'csf -ra'
            ProcessUtilities.normalExecutioner(command)

            logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'CSF successfully Installed.[200]\n', 1)

            try:
                os.remove('csf.tgz')
                os.removedirs('csf')
            except:
                pass

            return 1
        except BaseException, msg:
            try:
                os.remove('csf.tgz')
                os.removedirs('csf')
            except:
                pass
            writeToFile = open(CSF.installLogPath, 'a')
            writeToFile.writelines(str(msg) + " [404]")
            writeToFile.close()
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installCSF]")
Exemple #12
0
    def RestoreEmails(self):
        try:

            message = 'Restoring emails from archive file: %s' % (
                self.backupFile)
            logging.statusWriter(self.logFile, message, 1)

            CompletPathToExtractedArchive = cPanelImporter.mainBackupPath + self.fileName

            ### Find Mail Format
            UserData = '%s/homedir/mail' % (CompletPathToExtractedArchive)
            FormatPath = '%s/mailbox_format.cpanel' % (UserData)

            message = 'Detecting email format from %s.' % (self.backupFile)
            logging.statusWriter(self.logFile, message, 1)

            try:

                Format = open(FormatPath, 'r').read()

                if Format.find('mdbox') > -1:
                    self.mailFormat = cPanelImporter.MdBox
                    message = 'Mdbox format detected from %s.' % (
                        self.backupFile)
                    logging.statusWriter(self.logFile, message, 1)
                else:
                    self.mailFormat = cPanelImporter.MailDir
                    message = 'Maildir format detected from %s.' % (
                        self.backupFile)
                    logging.statusWriter(self.logFile, message, 1)
            except:
                self.mailFormat = cPanelImporter.MailDir

            ####

            for items in os.listdir(UserData):
                FinalMailDomainPath = '%s/%s' % (UserData, items)
                if os.path.isdir(FinalMailDomainPath):
                    if items[0] == '.':
                        continue
                    if items.find('.') > -1:
                        for it in os.listdir(FinalMailDomainPath):
                            try:
                                if self.checkIfExists(items) == 0:
                                    self.createDummyChild(items)

                                mailUtilities.createEmailAccount(
                                    items, it, 'cyberpanel')
                                finalEmailUsername = it + "@" + items
                                message = 'Starting restore for %s.' % (
                                    finalEmailUsername)
                                logging.statusWriter(self.logFile, message, 1)
                                eUser = EUsers.objects.get(
                                    email=finalEmailUsername)

                                if self.mailFormat == cPanelImporter.MailDir:
                                    eUser.mail = 'maildir:/home/vmail/%s/%s/Maildir' % (
                                        items, it)
                                    MailPath = '/home/vmail/%s/%s' % (items,
                                                                      it)

                                    command = 'mkdir -p %s' % (MailPath)
                                    ProcessUtilities.normalExecutioner(command)

                                    command = 'rm -rf %s/Maildir' % (MailPath)
                                    ProcessUtilities.normalExecutioner(command)

                                    MailPathInBackup = '%s/%s' % (
                                        FinalMailDomainPath, it)

                                    command = 'mv %s %s/Maildir' % (
                                        MailPathInBackup, MailPath)
                                    subprocess.call(command, shell=True)

                                else:
                                    eUser.mail = 'mdbox:/home/vmail/%s/%s/Mdbox' % (
                                        items, it)
                                    MailPath = '/home/vmail/%s/%s' % (items,
                                                                      it)

                                    command = 'mkdir -p %s' % (MailPath)
                                    ProcessUtilities.normalExecutioner(command)

                                    command = 'rm -rf %s/Mdbox' % (MailPath)
                                    ProcessUtilities.normalExecutioner(command)

                                    MailPathInBackup = '%s/%s' % (
                                        FinalMailDomainPath, it)

                                    command = 'mv %s %s/Mdbox' % (
                                        MailPathInBackup, MailPath)
                                    subprocess.call(command, shell=True)

                                ## Also update password

                                PasswordPath = '%s/homedir/etc/%s/shadow' % (
                                    CompletPathToExtractedArchive, items)
                                PasswordData = open(PasswordPath,
                                                    'r').readlines()

                                for i in PasswordData:
                                    if i.find(it) > -1:
                                        finalPassword = '******' % (
                                            '{CRYPT}', i.split(':')[1])
                                        eUser.password = finalPassword

                                eUser.save()

                                message = 'Restore completed for %s.' % (
                                    finalEmailUsername)
                                logging.statusWriter(self.logFile, message, 1)
                            except BaseException, msg:
                                message = 'Failed to restore emails from archive file %s, For domain: %s. error message: %s. [ExtractBackup]' % (
                                    self.backupFile, items, str(msg))
                                logging.statusWriter(self.logFile, message, 1)

            command = 'chown -R vmail:vmail /home/vmail'
            ProcessUtilities.normalExecutioner(command)

            message = 'Emails successfully restored'
            logging.statusWriter(self.logFile, message, 1)

            return 1
Exemple #13
0
    def CreateChildDomains(self):
        try:

            message = 'Creating child domains from archive file: %s' % (
                self.backupFile)
            logging.statusWriter(self.logFile, message, 1)

            CompletPathToExtractedArchive = cPanelImporter.mainBackupPath + self.fileName

            ### Find Possible Child Domains

            message = 'Finding Addon/Subdomains from backup file %s. Account main domain was %s.' % (
                self.backupFile, self.mainDomain)
            logging.statusWriter(self.logFile, message, 1)

            UserData = '%s/userdata/main' % (CompletPathToExtractedArchive)

            data = open(UserData, 'r').readlines()
            Domains = []
            addonStatus = 0
            subDomainsStatus = 0

            for items in data:
                if items.find('addon_domains') > -1:
                    addonStatus = 1
                    continue

                if addonStatus == 1:
                    if items.find('main_domain') > -1:
                        addonStatus = 0
                        continue
                    else:
                        cDomain = items.split(':')[0].replace(' ', '')
                        if len(cDomain) < 2:
                            continue
                        Domains.append(ChildDomains(cDomain, 1))
                        continue

                ##

                if items.find('sub_domains') > -1:
                    subDomainsStatus = 1
                    continue

                existCheck = 0
                if subDomainsStatus == 1:
                    cDomain = items.split(' ')[-1].replace('\n', '')
                    for items in Domains:
                        if cDomain.find(items.domain) > -1:
                            existCheck = 1
                    if existCheck == 0:
                        if len(cDomain) > 2:
                            Domains.append(ChildDomains(cDomain, 0))

            message = 'Following Addon/Subdomains found for backup file %s. Account main domain was %s.' % (
                self.backupFile, self.mainDomain)
            logging.statusWriter(self.logFile, message, 1)

            for items in Domains:
                print items.domain

            ## Starting Child-domains creation

            message = 'Starting Addon/Subdomains creation from backup file %s. Account main domain was %s.' % (
                self.backupFile, self.mainDomain)
            logging.statusWriter(self.logFile, message, 1)

            for items in Domains:

                try:

                    message = 'Creating %s.' % (items.domain)
                    logging.statusWriter(self.logFile, message, 1)

                    path = '/home/' + self.mainDomain + '/public_html/' + items.domain

                    ## Find PHP Version

                    if items.addon == 1:
                        DomainMeta = '%s/userdata/%s.%s' % (
                            CompletPathToExtractedArchive, items.domain,
                            self.mainDomain)
                    else:
                        DomainMeta = '%s/userdata/%s' % (
                            CompletPathToExtractedArchive, items.domain)

                    data = open(DomainMeta, 'r').readlines()
                    phpChecker = 1
                    for it in data:
                        if it.find('phpversion') > -1:
                            self.PHPVersion = it.split(' ')[-1].replace(
                                '\n', '')
                            self.PHPDecider()
                            phpChecker = 0
                            break

                    if phpChecker:
                        self.PHPDecider()

                    message = 'Calling core to create %s.' % (items.domain)
                    logging.statusWriter(self.logFile, message, 1)

                    result = virtualHostUtilities.createDomain(
                        self.mainDomain, items.domain, self.PHPVersion, path,
                        0, 0, 0, 'admin', 0)

                    if result[0] == 1:
                        message = 'Child domain %s created from archive file: %s' % (
                            items.domain, self.backupFile)
                        logging.statusWriter(self.logFile, message, 1)
                    else:
                        message = 'Failed to create Child domain %s from archive file: %s' % (
                            items.domain, self.backupFile)
                        logging.statusWriter(self.logFile, message, 1)

                    ## Setup SSL

                    message = 'Detecting SSL for %s.' % (items.domain)
                    logging.statusWriter(self.logFile, message, 1)

                    SSLPath = '%s/apache_tls/%s' % (
                        CompletPathToExtractedArchive, items.domain)

                    if os.path.exists(SSLPath):
                        message = 'SSL found for %s, setting up.' % (
                            items.domain)
                        logging.statusWriter(self.logFile, message, 1)
                        self.SetupSSL(SSLPath, items.domain)
                        message = 'SSL set up OK for %s.' % (items.domain)
                        logging.statusWriter(self.logFile, message, 1)
                    else:
                        SSLPath = '%s/apache_tls/%s.%s' % (
                            CompletPathToExtractedArchive, items.domain,
                            self.mainDomain)
                        if os.path.exists(SSLPath):
                            message = 'SSL found for %s, setting up.' % (
                                items.domain)
                            logging.statusWriter(self.logFile, message, 1)
                            self.SetupSSL(SSLPath, items.domain)
                            message = 'SSL set up OK for %s.' % (items.domain)
                            logging.statusWriter(self.logFile, message, 1)
                        else:
                            message = 'SSL not detected for %s, you can later issue SSL from Manage SSL in CyberPanel.' % (
                                items.domain)
                            logging.statusWriter(self.logFile, message, 1)

                    ## Creating Document root for childs

                    message = 'Restoring document root files for %s.' % (
                        items.domain)
                    logging.statusWriter(self.logFile, message, 1)

                    externalApp = "".join(
                        re.findall("[a-zA-Z]+", self.mainDomain))[:7]

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

                    for items in data:
                        if items.find('documentroot') > -1:
                            ChildDocRoot = items.split(' ')[-1].replace(
                                '\n', '')
                            break

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

                    movePath = '%s/homedir/public_html/%s' % (
                        CompletPathToExtractedArchive,
                        ChildDocRoot.replace(self.documentRoot, '', 1).replace(
                            '/', ''))

                    if os.path.exists(movePath):
                        shutil.move(movePath, path)
                    else:
                        movePath = '%s/homedir/%s' % (
                            CompletPathToExtractedArchive,
                            ChildDocRoot.split('/')[-1].replace(
                                self.documentRoot, '', 1).replace('/', ''))
                        if os.path.exists(movePath):
                            shutil.move(movePath, path)
                        else:
                            movePath = '%s/homedir/%s' % (
                                CompletPathToExtractedArchive, items.domain)
                            shutil.move(movePath, path)

                    command = 'chown -R %s:%s %s' % (externalApp, externalApp,
                                                     path)
                    ProcessUtilities.normalExecutioner(command)

                    message = 'Successfully created child domain.'
                    logging.statusWriter(self.logFile, message, 1)
                except BaseException, msg:
                    message = 'Failed to create child domain from backup file %s, error message: %s. Moving on..' % (
                        self.backupFile, str(msg))

            return 1
Exemple #14
0
    def CreateMainWebsite(self):
        try:

            message = 'Creating main account from archive file: %s' % (
                self.backupFile)
            logging.statusWriter(self.logFile, message, 1)

            CompletPathToExtractedArchive = cPanelImporter.mainBackupPath + self.fileName

            ### Find Domain Name
            UserData = '%s/userdata/main' % (CompletPathToExtractedArchive)

            data = open(UserData, 'r').readlines()
            DomainName = ''

            for items in data:
                if items.find('main_domain') > -1:
                    DomainName = items.split(' ')[-1].replace('\n', '')
                    self.mainDomain = DomainName
                    break

            message = 'Detected main domain for this file is: %s.' % (
                DomainName)
            logging.statusWriter(self.logFile, message, 1)

            ## Find PHP Version

            message = 'Finding PHP version for %s.' % (DomainName)
            logging.statusWriter(self.logFile, message, 1)

            DomainMeta = '%s/userdata/%s' % (CompletPathToExtractedArchive,
                                             DomainName)

            data = open(DomainMeta, 'r').readlines()
            phpChecker = 1

            for items in data:
                if items.find('phpversion') > -1:
                    self.PHPVersion = items.split(' ')[-1].replace('\n', '')
                    self.PHPDecider()
                    phpChecker = 0
                    break

            if phpChecker:
                self.PHPDecider()

            message = 'PHP version of %s is %s.' % (DomainName,
                                                    self.PHPVersion)
            logging.statusWriter(self.logFile, message, 1)

            ## Find Email

            message = 'Finding Server Admin email for %s.' % (DomainName)
            logging.statusWriter(self.logFile, message, 1)

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

            for items in data:
                if items.find('serveradmin') > -1:
                    self.email = items.split(' ')[-1].replace('\n', '')
                    break

            message = 'Server Admin email for %s is %s.' % (DomainName,
                                                            self.email)
            logging.statusWriter(self.logFile, message, 1)

            ## Create Site

            message = 'Calling core to create %s.' % (DomainName)
            logging.statusWriter(self.logFile, message, 1)

            self.externalApp = "".join(re.findall("[a-zA-Z]+", DomainName))[:7]

            try:
                counter = 0
                while True:
                    tWeb = Websites.objects.get(externalApp=self.externalApp)
                    self.externalApp = '%s%s' % (tWeb.externalApp,
                                                 str(counter))
                    counter = counter + 1
                    print self.externalApp
            except BaseException, msg:
                logging.statusWriter(self.logFile, str(msg), 1)
                time.sleep(2)

            result = virtualHostUtilities.createVirtualHost(
                DomainName, self.email, self.PHPVersion, self.externalApp, 0,
                0, 0, 'admin', 'Default', 0)

            if result[0] == 1:
                pass
            else:
                message = 'Failed to create main site %s from archive file: %s' % (
                    DomainName, self.backupFile)
                logging.statusWriter(self.logFile, message, 1)
                return 0

            message = 'Successfully created %s from core.' % (DomainName)
            logging.statusWriter(self.logFile, message, 1)

            ### Let see if there is SSL

            message = 'Detecting SSL for %s.' % (DomainName)
            logging.statusWriter(self.logFile, message, 1)

            SSLPath = '%s/apache_tls/%s' % (CompletPathToExtractedArchive,
                                            DomainName)

            if os.path.exists(SSLPath):
                message = 'SSL found for %s, setting up.' % (DomainName)
                logging.statusWriter(self.logFile, message, 1)
                self.SetupSSL(SSLPath, DomainName)
                message = 'SSL set up OK for %s.' % (DomainName)
                logging.statusWriter(self.logFile, message, 1)
            else:
                message = 'SSL not detected for %s, you can later issue SSL from Manage SSL in CyberPanel.' % (
                    DomainName)
                logging.statusWriter(self.logFile, message, 1)

            ## Document root

            message = 'Restoring document root files for %s.' % (DomainName)
            logging.statusWriter(self.logFile, message, 1)

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

            for items in data:
                if items.find('homedir') > -1:
                    self.homeDir = items.split(' ')[-1].replace('\n', '')
                    break

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

            for items in data:
                if items.find('documentroot') > -1:
                    self.documentRoot = items.split(' ')[-1].replace('\n', '')
                    break

            nowPath = '/home/%s/public_html' % (DomainName)
            if os.path.exists(nowPath):
                shutil.rmtree(nowPath)

            movePath = '%s/homedir/%s' % (CompletPathToExtractedArchive,
                                          self.documentRoot.replace(
                                              self.homeDir, '', 1).replace(
                                                  '/', ''))

            shutil.copytree(movePath, nowPath, symlinks=True)

            command = 'chown -R %s:%s %s' % (self.externalApp,
                                             self.externalApp, nowPath)
            ProcessUtilities.normalExecutioner(command)

            message = 'Main site %s created from archive file: %s' % (
                DomainName, self.backupFile)
            logging.statusWriter(self.logFile, message, 1)

            return 1
Exemple #15
0
    def deletePHPPath(virtualHostName):

        phpPath = ApacheVhost.DecidePHPPath('54', virtualHostName)
        if os.path.exists(phpPath):
            os.remove(phpPath)
            command = "systemctl restart php%s-php-fpm" % ('54')
            ProcessUtilities.normalExecutioner(command)

        phpPath = ApacheVhost.DecidePHPPath('55', virtualHostName)
        if os.path.exists(phpPath):
            os.remove(phpPath)
            command = "systemctl restart php%s-php-fpm" % ('55')
            ProcessUtilities.normalExecutioner(command)

        phpPath = ApacheVhost.DecidePHPPath('56', virtualHostName)
        if os.path.exists(phpPath):
            os.remove(phpPath)
            command = "systemctl restart php%s-php-fpm" % ('56')
            ProcessUtilities.normalExecutioner(command)

        phpPath = ApacheVhost.DecidePHPPath('70', virtualHostName)
        if os.path.exists(phpPath):
            os.remove(phpPath)
            command = "systemctl restart php%s-php-fpm" % ('70')
            ProcessUtilities.normalExecutioner(command)

        phpPath = ApacheVhost.DecidePHPPath('71', virtualHostName)
        if os.path.exists(phpPath):
            os.remove(phpPath)
            command = "systemctl restart php%s-php-fpm" % ('71')
            ProcessUtilities.normalExecutioner(command)

        phpPath = ApacheVhost.DecidePHPPath('72', virtualHostName)
        if os.path.exists(phpPath):
            os.remove(phpPath)
            command = "systemctl restart php%s-php-fpm" % ('72')
            ProcessUtilities.normalExecutioner(command)

        phpPath = ApacheVhost.DecidePHPPath('73', virtualHostName)
        if os.path.exists(phpPath):
            os.remove(phpPath)
            command = "systemctl restart php%s-php-fpm" % ('73')
            ProcessUtilities.normalExecutioner(command)
Exemple #16
0
    def perHostVirtualConf(administratorEmail, externalApp, virtualHostUser,
                           phpVersion, virtualHostName):
        try:

            ## Non-SSL Conf

            finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf'
            confFile = open(finalConfPath, "w+")

            php = PHPManager.getPHPString(phpVersion)

            currentConf = vhostConfs.apacheConf
            currentConf = currentConf.replace('{virtualHostName}',
                                              virtualHostName)
            currentConf = currentConf.replace('{administratorEmail}',
                                              administratorEmail)
            currentConf = currentConf.replace('{virtualHostUser}',
                                              virtualHostUser)
            currentConf = currentConf.replace('{php}', php)
            currentConf = currentConf.replace('{adminEmails}',
                                              administratorEmail)
            currentConf = currentConf.replace('{externalApp}', virtualHostUser)

            confFile.write(currentConf)
            confFile.close()

            ## SSL Conf

            finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf'
            confFile = open(finalConfPath, "a")

            php = PHPManager.getPHPString(phpVersion)

            currentConf = vhostConfs.apacheConfSSL
            currentConf = currentConf.replace('{virtualHostName}',
                                              virtualHostName)
            currentConf = currentConf.replace('{administratorEmail}',
                                              administratorEmail)
            currentConf = currentConf.replace('{virtualHostUser}',
                                              virtualHostUser)
            currentConf = currentConf.replace('{php}', php)
            currentConf = currentConf.replace('{adminEmails}',
                                              administratorEmail)
            currentConf = currentConf.replace('{externalApp}', virtualHostUser)

            confFile.write(currentConf)
            confFile.close()

            ##

            finalConfPath = ApacheVhost.DecidePHPPath(php, virtualHostName)

            confFile = open(finalConfPath, "w+")
            currentConf = vhostConfs.phpFpmPool
            currentConf = currentConf.replace('{www}', virtualHostUser)
            currentConf = currentConf.replace('{Sock}', virtualHostName)
            currentConf = currentConf.replace('{externalApp}', externalApp)

            confFile.write(currentConf)

            ApacheVhost.GenerateSelfSignedSSL(virtualHostName)

            command = "systemctl restart httpd"
            ProcessUtilities.normalExecutioner(command)

            return [1, 'None']
        except BaseException, msg:
            return [0, str(msg)]
Exemple #17
0
 def restartGunicorn():
     command = 'systemctl restart lscpd'
     ProcessUtilities.normalExecutioner(command)
Exemple #18
0
    def createLocalBackup(virtualHost, backupLogPath):
        try:

            backupSchedule.remoteBackupLogging(
                backupLogPath, "Starting local backup for: " + virtualHost)

            ###

            pathToFile = "/home/cyberpanel/" + str(randint(1000, 9999))
            file = open(pathToFile, "w+")
            file.close()

            finalData = json.dumps({
                'randomFile': pathToFile,
                'websiteToBeBacked': virtualHost
            })
            r = requests.post("https://localhost:8090/backup/localInitiate",
                              data=finalData,
                              verify=False)

            data = json.loads(r.text)
            tempStoragePath = data['tempStorage']

            backupSchedule.remoteBackupLogging(
                backupLogPath, "Waiting for backup to complete.. ")

            while (1):
                backupDomain = virtualHost
                status = os.path.join("/home", backupDomain, "backup/status")
                backupFileNamePath = os.path.join("/home", backupDomain,
                                                  "backup/backupFileName")
                pid = os.path.join("/home", backupDomain, "backup/pid")
                ## read file name

                try:
                    fileName = open(backupFileNamePath, 'r').read()
                except:
                    fileName = "Fetching.."

                ## file name read ends

                if os.path.exists(status):
                    status = open(status, 'r').read()
                    print status
                    time.sleep(2)

                    if status.find("Completed") > -1:

                        ### Removing Files

                        command = 'sudo rm -f ' + status
                        ProcessUtilities.normalExecutioner(command)

                        command = 'sudo rm -f ' + backupFileNamePath
                        ProcessUtilities.normalExecutioner(command)

                        command = 'sudo rm -f ' + pid
                        ProcessUtilities.normalExecutioner(command)

                        backupSchedule.remoteBackupLogging(
                            backupLogPath,
                            "Backup Completed for: " + virtualHost)
                        try:
                            os.remove(pathToFile)
                        except:
                            pass
                        return 1, tempStoragePath

                    elif status.find("[5009]") > -1:
                        ## removing status file, so that backup can re-run
                        try:
                            command = 'sudo rm -f ' + status
                            ProcessUtilities.normalExecutioner(command)

                            command = 'sudo rm -f ' + backupFileNamePath
                            ProcessUtilities.normalExecutioner(command)

                            command = 'sudo rm -f ' + pid
                            ProcessUtilities.normalExecutioner(command)

                            backupObs = Backups.objects.filter(
                                fileName=fileName)
                            for items in backupObs:
                                items.delete()

                        except:
                            pass

                        backupSchedule.remoteBackupLogging(
                            backupLogPath,
                            "An error occurred, Error message: " + status)
                        try:
                            os.remove(pathToFile)
                        except:
                            pass
                        return 0, tempStoragePath
        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + " [119:startBackup]")
            return 0, str(msg)