Esempio n. 1
0
    def setUpDataNode(self):
        try:

            userID = self.request.session['userID']
            currentACL = ACLManager.loadedACL(userID)
            proc = httpProc(self.request, None, None)

            if currentACL['admin'] == 0:
                return proc.ajax(0, 'Only administrators can create clusters.')

            composePath = '/home/cyberpanel/composePath'

            if not os.path.exists(composePath):
                os.mkdir(composePath)

            composeFile = composePath + '/docker-compose.yml'

            compose = open(composeFile, 'w')
            for items in self.data['composeData']:
                compose.writelines(items)
            compose.close()

            return proc.ajax(1, None)

        except BaseException, msg:
            logging.writeToFile(str(msg))
            proc = httpProc(self.request, None, None)
            return proc.ajax(0, str(msg))
Esempio n. 2
0
def restoreRemoteBackups(request):
    try:
        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

        if ACLManager.currentContextPermission(currentACL,
                                               'createBackup') == 0:
            return ACLManager.loadError()

        websitesName = ACLManager.findAllSites(currentACL, userID)

        destinations = []

        path = '/home/cyberpanel/sftp'

        if os.path.exists(path):
            for items in os.listdir(path):
                destinations.append('sftp:%s' % (items))

        path = '/home/cyberpanel/aws'
        if os.path.exists(path):
            for items in os.listdir(path):
                destinations.append('s3:s3.amazonaws.com/%s' % (items))

        return defRenderer(request, 'IncBackups/restoreRemoteBackups.html', {
            'websiteList': websitesName,
            'destinations': destinations
        })
    except BaseException, msg:
        logging.writeToFile(str(msg))
        return redirect(loadLoginPage)
Esempio n. 3
0
    def MainController(self):

        if self.ExtractBackup():
            pass
        else:
            return 0

        if self.CreateMainWebsite():
            pass
        else:
            return 0

        if self.CreateChildDomains():
            pass
        else:
            return 0

        if self.CreateDNSRecords():
            pass
        else:
            return 0

        if self.RestoreDatabases():
            pass
        else:
            return 0

        self.RestoreEmails()
        self.FixPermissions()

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

        return 1
Esempio n. 4
0
    def submitEditCluster(self):
        try:

            userID = self.request.session['userID']
            currentACL = ACLManager.loadedACL(userID)
            proc = httpProc(self.request, None, None)

            if currentACL['admin'] == 0:
                return proc.ajax(0, 'Only administrators can create clusters.')

            composePath = '/home/cyberpanel/composePath'
            composeFile = composePath + '/docker-compose.yml'

            data = open(composeFile, 'r').readlines()
            compose = open(composeFile, 'w')
            for items in data:
                if items.find('replicas') > -1:
                    compose.writelines('      replicas: ' +
                                       str(self.data['containers']) + '\n')
                elif items.find('memory') > -1:
                    compose.writelines('          memory: ' +
                                       self.data['containerRam'] + '\n')
                elif items.find('cpus:') > -1:
                    compose.writelines('          cpus: "' +
                                       self.data['containerCPU'] + '"\n')
                else:
                    compose.writelines(items)
            compose.close()

            return proc.ajax(1, None)

        except BaseException, msg:
            logging.writeToFile(str(msg))
            proc = httpProc(self.request, None, None)
            return proc.ajax(0, str(msg))
Esempio n. 5
0
    def backupDatabases(self):
        try:
            logging.statusWriter(self.statusPath, 'Backing up databases..', 1)

            databases = self.website.databases_set.all()

            for items in databases:
                if mysqlUtilities.mysqlUtilities.createDatabaseBackup(
                        items.dbName, '/home/cyberpanel') == 0:
                    return 0

                dbPath = '/home/cyberpanel/%s.sql' % (items.dbName)

                if self.backupDestinations == 'local':
                    self.localFunction(dbPath, 'database')
                elif self.backupDestinations[:4] == 'sftp':
                    self.sftpFunction(dbPath, 'database')
                else:
                    self.awsFunction('backup', dbPath, '', 'database')

                try:
                    os.remove('/home/cyberpanel/%s.sql' % (items.dbName))
                except BaseException, msg:
                    logging.statusWriter(
                        self.statusPath,
                        'Failed to delete database: %s. [IncJobs.backupDatabases.456]'
                        % str(msg), 1)
            return 1
Esempio n. 6
0
    def localFunction(self, backupPath, type, restore=None):
        if restore == None:
            command = 'restic -r %s backup %s --password-file %s --exclude %s' % (
                self.repoPath, backupPath, self.passwordFile, self.repoPath)
            result = ProcessUtilities.outputExecutioner(command)
            logging.statusWriter(self.statusPath, result, 1)
            snapShotid = result.split(' ')[-2]

            if type == 'database':
                newSnapshot = JobSnapshots(
                    job=self.jobid,
                    type='%s:%s' %
                    (type, backupPath.split('/')[-1].strip('.sql')),
                    snapshotid=snapShotid,
                    destination=self.backupDestinations)
            else:
                newSnapshot = JobSnapshots(job=self.jobid,
                                           type='%s:%s' % (type, backupPath),
                                           snapshotid=snapShotid,
                                           destination=self.backupDestinations)
            newSnapshot.save()
        else:
            repoLocation = '/home/%s/incbackup' % (self.website)
            command = 'restic -r %s restore %s --target / --password-file %s' % (
                repoLocation, self.jobid.snapshotid, self.passwordFile)
            result = ProcessUtilities.outputExecutioner(command)
            logging.statusWriter(self.statusPath, result, 1)
Esempio n. 7
0
    def gitPull(self):
        try:
            domain = self.extraArgs['domain']

            try:
                website = Websites.objects.get(domain=domain)
                finalPath = "/home/" + domain + "/public_html/"
                externalApp = website.externalApp
            except:
                childDomain = ChildDomains.objects.get(domain=domain)
                finalPath = childDomain.path
                externalApp = website.externalApp

            path = '/home/cyberpanel/' + domain + '.git'

            if not os.path.exists(path):
                logging.writeToFile('Git is not setup for this website.')
                return 0

            command = 'sudo git --git-dir=' + finalPath + '.git --work-tree=' + finalPath + '  pull'
            ProcessUtilities.executioner(command, externalApp)

            ##

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

            command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath
            ProcessUtilities.executioner(command, externalApp)

            return 0

        except BaseException, msg:
            logging.writeToFile(str(msg) + " [ApplicationInstaller.gitPull]")
            return 0
Esempio n. 8
0
    def changeBranch(self):
        try:
            domainName = self.extraArgs['domainName']
            githubBranch = self.extraArgs['githubBranch']
            admin = self.extraArgs['admin']

            try:
                website = Websites.objects.get(domain=domainName)
                finalPath = "/home/" + domainName + "/public_html/"
                externalApp = website.externalApp
            except:
                childDomain = ChildDomains.objects.get(domain=domainName)
                finalPath = childDomain.path
                externalApp = childDomain.master.externalApp

            try:
                command = 'sudo git --git-dir=' + finalPath + '/.git  checkout -b ' + githubBranch
                ProcessUtilities.executioner(command, externalApp)
            except:
                try:
                    command = 'sudo git --git-dir=' + finalPath + '/.git  checkout ' + githubBranch
                    ProcessUtilities.executioner(command, externalApp)
                except subprocess.CalledProcessError, msg:
                    logging.writeToFile('Failed to change branch: ' + str(msg))
                    return 0
            return 0
Esempio n. 9
0
    def dbCreation(self, tempStatusPath, website):
        try:
            dbName = randomPassword.generate_pass()
            dbUser = dbName
            dbPassword = randomPassword.generate_pass()

            ## DB Creation

            if Databases.objects.filter(
                    dbName=dbName).exists() or Databases.objects.filter(
                        dbUser=dbUser).exists():
                statusFile = open(tempStatusPath, 'w')
                statusFile.writelines(
                    "This database or user is already taken." + " [404]")
                statusFile.close()
                return 0

            result = mysqlUtilities.createDatabase(dbName, dbUser, dbPassword)

            if result == 1:
                pass
            else:
                statusFile = open(tempStatusPath, 'w')
                statusFile.writelines("Not able to create database." +
                                      " [404]")
                statusFile.close()
                return 0

            db = Databases(website=website, dbName=dbName, dbUser=dbUser)
            db.save()

            return dbName, dbUser, dbPassword

        except BaseException, msg:
            logging.writeToFile(str(msg) + '[ApplicationInstallerdbCreation]')
Esempio n. 10
0
    def reconstructWithMeta(self):
        try:

            if self.reconstruct == 'remote':
                if self.backupDestinations[:4] == 'sftp':
                    self.sftpFunction('none', 'none', 1)
                else:
                    self.awsFunction('restore', '', self.jobid)
            else:
                if self.jobid.destination == 'local':
                    self.localFunction('none', 'none', 1)
                elif self.jobid.destination[:4] == 'sftp':
                    self.sftpFunction('none', 'none', 1)
                else:
                    self.awsFunction('restore', '', self.jobid.snapshotid)

            metaPathNew = '/home/%s/meta.xml' % (self.website)
            execPath = "nice -n 10 /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/IncBackups/restoreMeta.py"
            execPath = execPath + " submitRestore --metaPath %s --statusFile %s" % (
                metaPathNew, self.statusPath)
            result = ProcessUtilities.outputExecutioner(execPath)
            logging.statusWriter(self.statusPath, result, 1)

            try:
                os.remove(metaPathNew)
            except:
                pass

        except BaseException, msg:
            logging.statusWriter(self.statusPath, "%s [46][5009]" % (str(msg)),
                                 1)
            return 0
Esempio n. 11
0
 def run(self):
     try:
         if self.function == 'setupNode':
             self.setupNode()
         elif self.function == 'addManager':
             self.setupNode()
     except BaseException, msg:
         logging.writeToFile(str(msg) + ' [HAManager.run]')
Esempio n. 12
0
 def run(self):
     try:
         if self.function == 'startCloning':
             self.startCloning()
         elif self.function == 'startSyncing':
             self.startSyncing()
     except BaseException, msg:
         logging.writeToFile(str(msg) + ' [StagingSetup.run]')
Esempio n. 13
0
 def __call__(self, request):
     if request.method == 'POST':
         if request.body.find(';') > -1 or request.body.find(
                 '&&') > -1 or request.body.find(
                     '|') > -1 or request.body.find('...') > -1:
             logging.writeToFile('Bad Input on.')
     response = self.get_response(request)
     return response
Esempio n. 14
0
    def handleCachePurgeRequest(command):
        try:
            mailUtilities.checkHome()
            writeToFile = open(cacheClient.cleaningPath, 'w')
            writeToFile.write(command)
            writeToFile.close()

        except BaseException, msg:
            logging.writeToFile(str(msg) + ' [cacheClient.handleCachePurgeRequest]')
Esempio n. 15
0
    def stop(self):

        path = policyCTRL.applicationPath
        if os.path.exists(path):
            pid = open(path, "r").readlines()[0]
            try:
                os.kill(int(pid), signal.SIGTERM)
            except BaseException, msg:
                logging.writeToFile(str(msg))
Esempio n. 16
0
    def run(self):
        try:
            if self.installApp == 'wordpress':
                self.installWordPress()
            elif self.installApp == 'joomla':
                self.installJoomla()

        except BaseException, msg:
            logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]')
Esempio n. 17
0
def localInitiate(request):
    try:
        data = json.loads(request.body)
        randomFile = data['randomFile']

        if os.path.exists(randomFile):
            wm = BackupManager()
            return wm.submitBackupCreation(1, json.loads(request.body))
    except BaseException, msg:
        logging.writeToFile(str(msg))
Esempio n. 18
0
    def purgeLimitDomain(command):
        try:
            domain = command[2]
            operationVal = int(command[3])

            if domain in cacheManager.domains:
                domainOBJ = cacheManager.domains[domain]
                domainOBJ.limitStatus = operationVal

        except BaseException, msg:
            logging.writeToFile(str(msg) + ' [cacheManager.purgeLimitDomain]')
Esempio n. 19
0
def runAWSBackups(request):
    try:

        data = json.loads(request.body)
        randomFile = data['randomFile']

        if os.path.exists(randomFile):
            s3 = S3Backups(request, None, 'runAWSBackups')
            s3.start()
    except BaseException, msg:
        logging.writeToFile(str(msg) + ' [API.runAWSBackups]')
Esempio n. 20
0
    def test_submitACLModifications(self):
        self.test_createACLFunc()
        data_ret = {'aclToModify': 'hello',
                    'adminStatus':1,
                    'createNewUser': 1,
                    'versionManagement': 1,
                    'listUsers': 1,
                    'resellerCenter': 1,
                    'deleteUser': 1,
                    'changeUserACL': 1,
                    'createWebsite': 1,
                    'modifyWebsite': 1,
                    'suspendWebsite': 1,
                    'deleteWebsite': 1,
                    'createPackage': 1,
                    'listPackages': 1,
                    'deletePackage': 1,
                    'modifyPackage': 1,
                    'createDatabase': 1,
                    'deleteDatabase': 1,
                    'listDatabases': 1,
                    'createNameServer': 1,
                    'createDNSZone': 1,
                    'deleteZone': 1,
                    'addDeleteRecords': 1,
                    'createEmail': 1,
                    'listEmails': 1,
                    'deleteEmail': 1,
                    'emailForwarding': 1,
                    'changeEmailPassword': 1,
                    'dkimManager': 1,
                    'createFTPAccount': 1,
                    'deleteFTPAccount': 1,
                    'listFTPAccounts': 1,
                    'createBackup': 1,
                    'restoreBackup': 1,
                    'addDeleteDestinations': 1,
                    'scheDuleBackups': 1,
                    'remoteBackups': 1,
                    'manageSSL': 1,
                    'hostnameSSL': 1,
                    'mailServerSSL': 0}
        json_data = json.dumps(data_ret)


        ## Modification
        response = self.client.post(self.submitACLModifications, json_data, content_type="application/json")
        logging.writeToFile(response.content)
        json_data = json.loads(response.content)

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

        self.assertEqual(ACL.objects.get(name='hello').mailServerSSL, 0)
        self.assertEqual(ACL.objects.get(name='hello').hostnameSSL, 1)
Esempio n. 21
0
    def updateDomainLimit(command):
        try:
            domain = command[2]
            newLimit = int(command[3])

            if domain in cacheManager.domains:
                domainOBJ = cacheManager.domains[domain]
                domainOBJ.monthlyLimits = newLimit

        except BaseException, msg:
            logging.writeToFile(str(msg) + ' [cacheManager.updateDomainLimit]')
Esempio n. 22
0
    def disableEnableLogs(self, emailAddress, operationValue):
        try:
            domainName = emailAddress.split('@')[1]

            if domainName in cacheManager.domains:
                domainOBJ = cacheManager.domains[domainName]
                if emailAddress in domainOBJ.emails:
                    emailOBJ = domainOBJ.emails[emailAddress]
                    emailOBJ.logStatus = operationValue

        except BaseException, msg:
            logging.writeToFile(str(msg) + ' [cacheManager.disableEnableLogs]')
Esempio n. 23
0
    def purgeLimit(command):
        try:
            email = command[2]
            operationVal = int(command[3])
            domain = email.split('@')[1]

            if domain in cacheManager.domains:
                domainOBJ = cacheManager.domains[domain]
                emailOBJ = domainOBJ.emails[email]
                emailOBJ.limitStatus = operationVal

        except BaseException, msg:
            logging.writeToFile(str(msg) + ' [cacheManager.purgeLimit]')
Esempio n. 24
0
def backupDestinations(request):
    try:
        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

        if ACLManager.currentContextPermission(currentACL,
                                               'addDeleteDestinations') == 0:
            return ACLManager.loadError()

        return defRenderer(request, 'IncBackups/incrementalDestinations.html',
                           {})
    except BaseException, msg:
        logging.writeToFile(str(msg))
        return redirect(loadLoginPage)
Esempio n. 25
0
    def wrap(request, *args, **kwargs):

        try:
            userID = request.session['userID']
        except KeyError:
            return redirect(loadLoginPage)

        currentACL = ACLManager.loadedACL(userID)

        if request.method == "POST":
            isPost = True
        else:
            isPost = False

        # check if docker is installed
        dockerInstallPath = '/usr/bin/docker'
        if not os.path.exists(dockerInstallPath):
            if isPost:
                data_ret = {
                    'status': 0,
                    'error_message': 'Docker not installed'
                }
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
            else:
                return render(request, 'dockerManager/install.html', {
                    'status': currentACL['admin'],
                    'conErr': 0
                })

        # Check if docker is running and we are able to connect

        try:
            client = docker.from_env()
            client.ping()
        except BaseException, msg:
            logging.writeToFile(str(msg))
            if isPost:
                data_ret = {
                    'status': 0,
                    'error_message':
                    'Docker daemon not running or not responsive'
                }
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
            else:
                return render(request, 'dockerManager/install.html', {
                    'status': currentACL['admin'],
                    'conErr': 1
                })
Esempio n. 26
0
def restorePoint(request):
    try:
        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)
        admin = Administrator.objects.get(pk=userID)

        data = json.loads(request.body)
        backupDomain = data['websiteToBeBacked']
        jobid = data['jobid']

        if ACLManager.checkOwnership(backupDomain, admin, currentACL) == 1:
            pass
        else:
            return ACLManager.loadErrorJson('metaStatus', 0)

        tempPath = "/home/cyberpanel/" + str(randint(1000, 9999))

        if data['reconstruct'] == 'remote':
            extraArgs = {}
            extraArgs['website'] = backupDomain
            extraArgs['jobid'] = jobid
            extraArgs['tempPath'] = tempPath
            extraArgs['reconstruct'] = data['reconstruct']
            extraArgs['backupDestinations'] = data['backupDestinations']
            extraArgs['password'] = data['password']
            extraArgs['path'] = data['path']
        else:
            extraArgs = {}
            extraArgs['website'] = backupDomain
            extraArgs['jobid'] = jobid
            extraArgs['tempPath'] = tempPath
            extraArgs['reconstruct'] = data['reconstruct']

        startJob = IncJobs('restorePoint', extraArgs)
        startJob.start()

        time.sleep(2)

        final_json = json.dumps({
            'status': 1,
            'error_message': "None",
            'tempPath': tempPath
        })
        return HttpResponse(final_json)

    except BaseException, msg:
        logging.writeToFile(str(msg))
        final_dic = {'status': 0, 'metaStatus': 0, 'error_message': str(msg)}
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)
Esempio n. 27
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))
Esempio n. 28
0
    def installWPCLI(self):
        try:
            command = 'sudo wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar'
            subprocess.call(shlex.split(command))

            command = 'sudo chmod +x wp-cli.phar'
            subprocess.call(shlex.split(command))

            command = 'sudo mv wp-cli.phar /usr/bin/wp'
            subprocess.call(shlex.split(command))

        except BaseException, msg:
            logging.writeToFile(
                str(msg) + ' [ApplicationInstaller.installWPCLI]')
Esempio n. 29
0
def submitBackupCreation(request):
    try:
        userID = request.session['userID']

        result = pluginManager.preSubmitBackupCreation(request)
        if result != 200:
            return result

        wm = BackupManager()
        coreResult =  wm.submitBackupCreation(userID, json.loads(request.body))

        return coreResult

    except BaseException, msg:
        logging.writeToFile(str(msg))
Esempio n. 30
0
    def installGit(self):
        try:
            if os.path.exists("/etc/lsb-release"):
                command = 'apt -y install git'
                ProcessUtilities.executioner(command)
            else:
                command = 'sudo yum -y install http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm'
                ProcessUtilities.executioner(command)

                command = 'sudo yum install git -y'
                ProcessUtilities.executioner(command)

        except BaseException, msg:
            logging.writeToFile(
                str(msg) + ' [ApplicationInstaller.installGit]')