Пример #1
0
    def rename(self):
        try:

            finalData = {}
            finalData['status'] = 1
            domainName = self.data['domainName']
            website = Websites.objects.get(domain=domainName)

            if self.data['newFileName'].find('..') > -1:
                return self.ajaxPre(
                    0,
                    'Not allowed to move in this path, please choose location inside home!'
                )

            command = 'mv ' + self.returnPathEnclosed(
                self.data['basePath'] + '/' +
                self.data['existingName']) + ' ' + self.returnPathEnclosed(
                    self.data['basePath'] + '/' + self.data['newFileName'])
            ProcessUtilities.executioner(command, website.externalApp)

            self.changeOwner(self.data['basePath'] + '/' +
                             self.data['newFileName'])

            json_data = json.dumps(finalData)
            return HttpResponse(json_data)

        except BaseException, msg:
            return self.ajaxPre(0, str(msg))
Пример #2
0
def killProcess(request):
    try:
        userID = request.session['userID']

        try:
            currentACL = ACLManager.loadedACL(userID)

            if currentACL['admin'] == 1:
                pass
            else:
                return ACLManager.loadErrorJson('status', 0)

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

            ProcessUtilities.executioner('sudo kill ' + pid)

            proc = httpProc(request, None)
            return proc.ajax(1, None)

        except BaseException, msg:
            final_dic = {'status': 0, 'erroMessage': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)
    except KeyError, msg:
        final_dic = {'status': 0, 'erroMessage': str(msg)}
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)
Пример #3
0
    def changePermissions(self):
        try:

            finalData = {}
            finalData['status'] = 1
            domainName = self.data['domainName']
            website = Websites.objects.get(domain=domainName)

            if self.data['recursive'] == 1:
                command = 'chmod -R ' + self.data[
                    'newPermissions'] + ' ' + self.returnPathEnclosed(
                        self.data['basePath'] + '/' +
                        self.data['permissionsPath'])
            else:
                command = 'chmod ' + self.data[
                    'newPermissions'] + ' ' + self.returnPathEnclosed(
                        self.data['basePath'] + '/' +
                        self.data['permissionsPath'])

            ProcessUtilities.executioner(command, website.externalApp)

            json_data = json.dumps(finalData)
            return HttpResponse(json_data)

        except BaseException, msg:
            return self.ajaxPre(0, str(msg))
Пример #4
0
    def deleteBackup(self, userID = None, data = None):
        try:
            backupID = data['backupID']
            backup = Backups.objects.get(id=backupID)

            domainName = backup.website.domain
            currentACL = ACLManager.loadedACL(userID)
            admin = Administrator.objects.get(pk=userID)
            if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
                pass
            else:
                return ACLManager.loadErrorJson()

            path = "/home/" + domainName + "/backup/" + backup.fileName + ".tar.gz"
            command = 'sudo rm -f ' + path
            ProcessUtilities.executioner(command)

            backup.delete()

            final_json = json.dumps({'status': 1, 'deleteStatus': 1, 'error_message': "None"})
            return HttpResponse(final_json)
        except BaseException, msg:
            final_dic = {'status': 0, 'deleteStatus': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)

            return HttpResponse(final_json)
Пример #5
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
Пример #6
0
    def initiateRepo(self):
        try:
            logging.statusWriter(self.statusPath,
                                 'Will first initiate backup repo..', 1)

            if self.backupDestinations == 'local':
                command = 'restic init --repo %s --password-file %s' % (
                    self.repoPath, self.passwordFile)
                ProcessUtilities.executioner(command, self.website.externalApp)

            elif self.backupDestinations[:4] == 'sftp':
                remotePath = '/home/backup/%s' % (self.website.domain)
                command = 'export PATH=${PATH}:/usr/bin && restic init --repo %s:%s --password-file %s' % (
                    self.backupDestinations, remotePath, self.passwordFile)
                ProcessUtilities.executioner(command)

            logging.statusWriter(
                self.statusPath, 'Repo %s initiated for %s.' %
                (self.backupDestinations, self.website.domain), 1)
            return 1
        except BaseException, msg:
            logging.statusWriter(
                self.statusPath,
                '%s. [IncJobs.initiateRepo.47][5009]' % str(msg), 1)
            return 0
Пример #7
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
Пример #8
0
    def addTrafficController(self):
        command = 'sudo tc qdisc add dev eth0 root handle 10: htb default 1000'
        #logging.CyberCPLogFileWriter.writeToFile(command)
        ProcessUtilities.executioner(command)

        try:
            command = 'sudo tc class del dev eth0 classid 10:' + str(self.data['classID'])
            # logging.CyberCPLogFileWriter.writeToFile(command)
            ProcessUtilities.executioner(command)
        except:
            pass

        command = 'sudo tc class add dev eth0 parent 10: classid 10:1000 htb rate 100mbit'
        #logging.CyberCPLogFileWriter.writeToFile(command)
        ProcessUtilities.executioner(command)

        command = 'sudo tc class add dev eth0 parent 10: classid 10:' + str(self.data['classID']) + ' htb rate ' + str(self.data['rateLimit'])
        #logging.CyberCPLogFileWriter.writeToFile(command)
        ProcessUtilities.executioner(command)

        #if str(self.data['classID']) == '1':
        #    command = 'sudo tc filter add dev eth0 parent 10: protocol ip prio 10 handle 1: cgroup'
        #else:
        #    command = 'sudo tc filter add dev eth0 parent 10:' + str(
        #        self.data['classID']) + ' protocol ip prio 10 handle 1: cgroup'

        command = 'sudo tc filter add dev eth0 parent 10: protocol ip prio 10 handle 1: cgroup'
        #logging.CyberCPLogFileWriter.writeToFile(command)
        ProcessUtilities.executioner(command)

        self.restartServices()
Пример #9
0
    def issueSelfSignedSSL(self, virtualHost):
        try:

            try:
                website = ChildDomains.objects.get(domain=virtualHost)
                adminEmail = website.master.adminEmail
            except:
                website = Websites.objects.get(domain=virtualHost)
                adminEmail = website.adminEmail

            pathToStoreSSL = "/etc/letsencrypt/live/" + virtualHost
            command = 'mkdir -p ' + pathToStoreSSL
            ProcessUtilities.executioner(command)

            pathToStoreSSLPrivKey = "/etc/letsencrypt/live/" + virtualHost + "/privkey.pem"
            pathToStoreSSLFullChain = "/etc/letsencrypt/live/" + virtualHost + "/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.executioner(command)

            sslUtilities.installSSLForDomain(virtualHost, adminEmail)
            ProcessUtilities.restartLitespeed()
            self.printStatus(1, 'None')

        except BaseException, msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            self.printStatus(0, str(msg))
Пример #10
0
    def deleteRule(proto, port, ipAddress):
        ruleFamily = 'rule family="ipv4"'
        sourceAddress = 'source address="' + ipAddress + '"'
        ruleProtocol = 'port protocol="' + proto + '"'
        rulePort = 'port="' + port + '"'

        command = "sudo firewall-cmd --permanent --zone=public --remove-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'"

        if ProcessUtilities.executioner(command) == 0:
            return 0

        ruleFamily = 'rule family="ipv6"'
        sourceAddress = ''

        command = "sudo firewall-cmd --permanent --zone=public --remove-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'"

        if ProcessUtilities.executioner(command) == 0:
            return 0

        command = 'sudo firewall-cmd --reload'

        if ProcessUtilities.executioner(command) == 0:
            return 0

        return 1
Пример #11
0
    def compress(self):
        try:

            finalData = {}
            finalData['status'] = 1
            domainName = self.data['domainName']
            website = Websites.objects.get(domain=domainName)

            if self.data['compressionType'] == 'zip':
                compressedFileName = self.returnPathEnclosed(
                    self.data['basePath'] + '/' +
                    self.data['compressedFileName'] + '.zip')
                command = 'zip -r ' + compressedFileName + ' '
            else:
                compressedFileName = self.returnPathEnclosed(
                    self.data['basePath'] + '/' +
                    self.data['compressedFileName'] + '.tar.gz')
                command = 'tar -czvf ' + compressedFileName + ' '

            for item in self.data['listOfFiles']:
                command = '%s%s ' % (command, self.returnPathEnclosed(item))

            finalCommand = 'cd %s && %s' % (self.data['basePath'], command)

            ProcessUtilities.executioner(finalCommand, website.externalApp)

            self.changeOwner(self.data['compressedFileName'])

            json_data = json.dumps(finalData)
            return HttpResponse(json_data)

        except BaseException, msg:
            return self.ajaxPre(0, str(msg))
Пример #12
0
    def checkIP(ipAddress):
        try:
            command = 'sudo csf -g ' + ipAddress
            ProcessUtilities.executioner(command)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[checkIP]")
Пример #13
0
def servicesAction(request):
    try:
        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

        if currentACL['admin'] == 1:
            pass
        else:
            return ACLManager.loadErrorJson('serviceAction', 0)

        try:
            if request.method == 'POST':
                data = json.loads(request.body)
                service = data['service']
                action = data['action']

                if action not in ["stop", "start", "restart"]:

                    final_dic = {
                        'serviceAction': 0,
                        "error_message": "Invalid Action"
                    }
                    final_json = json.dumps(final_dic)
                    return HttpResponse(final_json)
                else:
                    pass

                if service not in [
                        "lsws", "mysql", "pdns", "pure-ftpd", "docker"
                ]:
                    final_dic = {
                        'serviceAction': 0,
                        "error_message": "Invalid Service"
                    }
                    final_json = json.dumps(final_dic)
                    return HttpResponse(final_json)

                else:
                    if service == 'pure-ftpd':
                        if os.path.exists("/etc/lsb-release"):
                            service = 'pure-ftpd-mysql'
                        else:
                            service = 'pure-ftpd'

                    command = 'sudo systemctl %s %s' % (action, service)
                    ProcessUtilities.executioner(command)
                    final_dic = {'serviceAction': 1, "error_message": 0}
                    final_json = json.dumps(final_dic)
                    return HttpResponse(final_json)

        except BaseException, msg:
            final_dic = {'serviceAction': 0, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)
    except KeyError, msg:
        final_dic = {'serviceAction': 0, 'error_message': str(msg)}
        final_json = json.dumps(final_dic)
        return HttpResponse(final_json)
Пример #14
0
 def run(self):
     try:
         if self.function == 'submitInstallDocker':
             self.submitInstallDocker()
         elif self.function == 'restartGunicorn':
             command = 'sudo systemctl restart gunicorn.socket'
             ProcessUtilities.executioner(command)
     except BaseException, msg:
         logging.CyberCPLogFileWriter.writeToFile( str(msg) + ' [ContainerManager.run]')
Пример #15
0
    def ftpFunctions(path, externalApp):
        try:

            command = 'mkdir %s' % (path)
            ProcessUtilities.executioner(command, externalApp)

            return 1, 'None'

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(
                str(msg) + "  [ftpFunctions]")
            return 0, str(msg)
Пример #16
0
    def restartMySQL():
        try:
            command = 'sudo systemctl restart mysql'
            ProcessUtilities.executioner(command)

            return 1, None

        except BaseException, msg:
            command = 'sudo mv /etc/my.cnf.bak /etc/my.cnf'
            subprocess.call(shlex.split(command))
            logging.CyberCPLogFileWriter.writeToFile(str(msg))
            return 0, str(msg)
Пример #17
0
def saveSettings(request):
    try:

        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

        if currentACL['admin'] == 1:
            pass
        else:
            return ACLManager.loadErrorJson()

        data = json.loads(request.body)

        name = data['name']
        SPEED = data['SPEED']
        VMEM = data['VMEM']
        PMEM = data['PMEM']
        IO = data['IO']
        IOPS = data['IOPS']
        EP = data['EP']
        NPROC = data['NPROC']
        INODESsoft = data['INODESsoft']
        INODEShard = data['INODEShard']

        clPackage = CLPackages.objects.get(name=name)
        clPackage.speed = SPEED
        clPackage.vmem = VMEM
        clPackage.pmem = PMEM
        clPackage.io = IO
        clPackage.iops = IOPS
        clPackage.ep = EP
        clPackage.nproc = NPROC
        clPackage.inodessoft = INODESsoft
        clPackage.inodeshard = INODEShard
        clPackage.save()

        command = 'sudo lvectl package-set %s --speed=%s --pmem=%s --io=%s --nproc=%s --iops=%s --vmem=%s --ep=%s' % (
        name, SPEED, PMEM, IO, NPROC, IOPS, VMEM, EP)
        ProcessUtilities.executioner(command)

        command = 'sudo lvectl apply all'
        ProcessUtilities.popenExecutioner(command)

        data_ret = {'status': 1}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)


    except BaseException, msg:
        data_ret = {'status': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
Пример #18
0
def enableOrDisable(request):
    try:

        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

        if currentACL['admin'] == 1:
            pass
        else:
            return ACLManager.loadErrorJson()

        data = json.loads(request.body)

        if data['toggle'] == 1:
            cageFSPath = '/home/cyberpanel/cagefs'
            if os.path.exists(cageFSPath):
                os.remove(cageFSPath)
            else:
                writeToFile = open(cageFSPath, 'w')
                writeToFile.writelines('enable')
                writeToFile.close()

            data_ret = {'status': 1, 'error_message': 'None', 'success': 'Default status successfully changed changed.'}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)

        if data['all'] == 0:
            if data['mode'] == 1:
                website = Websites.objects.get(domain=data['domain'])
                command = '/usr/sbin/cagefsctl --enable %s' % (website.externalApp)
            else:
                website = Websites.objects.get(domain=data['domain'])
                command = '/usr/sbin/cagefsctl --disable %s' % (website.externalApp)

            ProcessUtilities.executioner(command)
            data_ret = {'status': 1, 'error_message': 'None', 'success': 'Changes successfully applied.'}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)
        else:
            c = CLManagerMain(request, None, 'enableOrDisable', data)
            c.start()

            data_ret = {'status': 1, 'error_message': 'None', 'success': 'Job started in background, refresh in few seconds to see the status.'}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)



    except BaseException, msg:
        data_ret = {'status': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
Пример #19
0
    def changeOwner(self, path):
        domainName = self.data['domainName']
        website = Websites.objects.get(domain=domainName)

        if path.find('..') > -1:
            return self.ajaxPre(
                0,
                'Not allowed to move in this path, please choose location inside home!'
            )

        command = "chown -R " + website.externalApp + ':' + website.externalApp + ' ' + self.returnPathEnclosed(
            path)
        ProcessUtilities.executioner(command, website.externalApp)
Пример #20
0
def submitCreatePackage(request):
    try:

        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

        if currentACL['admin'] == 1:
            pass
        else:
            return ACLManager.loadErrorJson()

        data = json.loads(request.body)

        selectedPackage = data['selectedPackage']

        package = Package.objects.get(packageName=selectedPackage)

        if package.clpackages_set.all().count() == 1:
            data_ret = {'status': 0, 'error_message': 'This package already have one associated CloudLinux Package.'}
            json_data = json.dumps(data_ret)
            return HttpResponse(json_data)

        name = data['name']
        SPEED = data['SPEED']
        VMEM = data['VMEM']
        PMEM = data['PMEM']
        IO = data['IO']
        IOPS = data['IOPS']
        EP = data['EP']
        NPROC = data['NPROC']
        INODESsoft = data['INODESsoft']
        INODEShard = data['INODEShard']

        clPackage = CLPackages(name=name, owner=package, speed=SPEED, vmem=VMEM, pmem=PMEM, io=IO, iops=IOPS, ep=EP, nproc=NPROC, inodessoft=INODESsoft, inodeshard=INODEShard)
        clPackage.save()

        command = 'sudo lvectl package-set %s --speed=%s --pmem=%s --io=%s --nproc=%s --iops=%s --vmem=%s --ep=%s' % (name, SPEED, PMEM, IO, NPROC, IOPS, VMEM, EP)
        ProcessUtilities.executioner(command)

        command = 'sudo lvectl apply all'
        ProcessUtilities.popenExecutioner(command)

        data_ret = {'status': 1}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)


    except BaseException, msg:
        data_ret = {'status': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
Пример #21
0
    def restoreStatus(self, data = None):
        try:
            backupFile = data['backupFile'].strip(".tar.gz")

            path = os.path.join("/home", "backup", data['backupFile'])

            if os.path.exists(path):
                path = os.path.join("/home", "backup", backupFile)
            elif os.path.exists(data['backupFile']):
                path = data['backupFile'].strip(".tar.gz")
            else:
                dir = data['dir']
                path = "/home/backup/transfer-" + str(dir) + "/" + backupFile

            if os.path.exists(path):
                try:
                    execPath = "sudo cat " + path + "/status"
                    status = ProcessUtilities.outputExecutioner(execPath)

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

                        command = "sudo rm -rf " + path
                        ProcessUtilities.executioner(command)

                        final_json = json.dumps(
                            {'restoreStatus': 1, 'error_message': "None", "status": status, 'abort': 1,
                             'running': 'Completed'})
                        return HttpResponse(final_json)
                    elif status.find("[5009]") > -1:
                        ## removing temporarily generated files while restoring
                        command = "sudo rm -rf " + path
                        ProcessUtilities.executioner(command)
                        final_json = json.dumps({'restoreStatus': 1, 'error_message': "None",
                                                 "status": status, 'abort': 1, 'alreadyRunning': 0,
                                                 'running': 'Error'})
                        return HttpResponse(final_json)
                    else:
                        final_json = json.dumps(
                            {'restoreStatus': 1, 'error_message': "None", "status": status, 'abort': 0,
                             'running': 'Running..'})
                        return HttpResponse(final_json)

                except BaseException, msg:
                    logging.CyberCPLogFileWriter.writeToFile(str(msg))
                    status = "Just Started"
                    final_json = json.dumps(
                        {'restoreStatus': 1, 'error_message': "None", "status": status, 'abort': 0,
                         'running': 'Running..'})
                    return HttpResponse(final_json)
            else:
Пример #22
0
 def enableOrDisable(self):
     try:
         websites = Websites.objects.all()
         if self.data['mode'] == 1:
             for items in websites:
                 command = '/usr/sbin/cagefsctl --enable %s' % (
                     items.externalApp)
                 ProcessUtilities.executioner(command)
         else:
             for items in websites:
                 command = '/usr/sbin/cagefsctl --disable %s' % (
                     items.externalApp)
                 ProcessUtilities.executioner(command)
     except BaseException, msg:
         logging.CyberCPLogFileWriter.writeToFile(str(msg))
Пример #23
0
def cancelRemoteTransfer(request):
    try:
        if request.method == "POST":
            data = json.loads(request.body)
            username = data['username']
            password = data['password']

            admin = Administrator.objects.get(userName=username)

            if admin.api == 0:
                data_ret = {
                    "cancelStatus": 0,
                    'error_message': "API Access Disabled."
                }
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

            dir = "/home/backup/transfer-" + str(data['dir'])

            if hashPassword.check_password(admin.password, password):

                path = dir + "/pid"

                command = "cat " + path
                pid = ProcessUtilities.outputExecutioner(command)

                command = "kill -KILL " + pid
                ProcessUtilities.executioner(command)

                command = "rm -rf " + dir
                ProcessUtilities.executioner(command)

                data = {'cancelStatus': 1, 'error_message': "None"}
                json_data = json.dumps(data)
                return HttpResponse(json_data)

            else:
                data_ret = {
                    'cancelStatus': 0,
                    'error_message': "Invalid Credentials"
                }
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

    except BaseException, msg:
        data = {'cancelStatus': 1, 'error_message': str(msg)}
        json_data = json.dumps(data)
        return HttpResponse(json_data)
Пример #24
0
    def getConnectionStatus(self, userID = None, data = None):
        try:
            currentACL = ACLManager.loadedACL(userID)

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

            ipAddress = data['IPAddress']

            execPath = "/usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py"
            execPath = execPath + " getConnectionStatus --ipAddress " + ipAddress

            output = ProcessUtilities.executioner(execPath)

            if output.find('1,') > -1:
                final_dic = {'connStatus': 1, 'error_message': "None"}
                final_json = json.dumps(final_dic)
                return HttpResponse(final_json)
            else:
                final_dic = {'connStatus': 0, 'error_message': output}
                final_json = json.dumps(final_dic)
                return HttpResponse(final_json)

        except BaseException, msg:
            final_dic = {'connStatus': 1, 'error_message': str(msg)}
            final_json = json.dumps(final_dic)
            return HttpResponse(final_json)
Пример #25
0
    def submitInstallDocker(self):
        try:
            currentACL = ACLManager.loadedACL(self.name)

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

            writeToFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')
            writeToFile.close()

            execPath = "/usr/local/CyberCP/bin/python2 /usr/local/CyberCP/dockerManager/dockerInstall.py"
            ProcessUtilities.executioner(execPath)

            time.sleep(2)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
Пример #26
0
    def localRestoreStatus(self, userID = None, data = None):
        try:
            currentACL = ACLManager.loadedACL(userID)

            if ACLManager.currentContextPermission(currentACL, 'remoteBackups') == 0:
                return ACLManager.loadErrorJson('remoteTransferStatus', 0)

            backupDir = data['backupDir']

            # admin = Administrator.objects.get(userName=username)
            backupLogPath = "/home/backup/transfer-" + backupDir + "/" + "backup_log"

            removalPath = "/home/backup/transfer-" + str(backupDir)

            time.sleep(3)

            if os.path.isfile(backupLogPath):
                command = "sudo cat " + backupLogPath
                status = ProcessUtilities.outputExecutioner(command)

                if status.find("completed[success]") > -1:
                    command = "rm -rf " + removalPath
                    ProcessUtilities.executioner(command)
                    data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 1}
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)
                elif status.find("[5010]") > -1:
                    command = "sudo rm -rf " + removalPath
                    ProcessUtilities.executioner(command)
                    data = {'remoteTransferStatus': 0, 'error_message': status,
                            "status": "None", "complete": 0}
                    json_data = json.dumps(data)
                    return HttpResponse(json_data)
                else:
                    data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 0}
                    json_data = json.dumps(data_ret)
                    return HttpResponse(json_data)
            else:
                data_ret = {'remoteTransferStatus': 0, 'error_message': "No such log found", "status": "None",
                            "complete": 0}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
        except BaseException, msg:
            data = {'remoteTransferStatus': 0, 'error_message': str(msg), "status": "None", "complete": 0}
            json_data = json.dumps(data)
            return HttpResponse(json_data)
Пример #27
0
    def cancelRemoteBackup(self, userID = None, data = None):
        try:

            currentACL = ACLManager.loadedACL(userID)

            if ACLManager.currentContextPermission(currentACL, 'remoteBackups') == 0:
                return ACLManager.loadErrorJson('cancelStatus', 0)

            ipAddress = data['ipAddress']
            password = data['password']
            dir = data['dir']
            username = "******"

            finalData = json.dumps({'dir': dir, "username": username, "password": password})
            r = requests.post("https://" + ipAddress + ":8090/api/cancelRemoteTransfer", data=finalData,
                              verify=False)

            data = json.loads(r.text)

            if data['cancelStatus'] == 1:
                pass
            else:
                logging.CyberCPLogFileWriter.writeToFile(
                    "Some error cancelling at remote server, see the log file for remote server.")

            path = "/home/backup/transfer-" + str(dir)
            pathpid = path + "/pid"

            command = "sudo cat " + pathpid
            pid = ProcessUtilities.outputExecutioner(command)

            command = "sudo kill -KILL " + pid
            ProcessUtilities.executioner(command)

            command = "sudo rm -rf " + path
            ProcessUtilities.executioner(command)

            data = {'cancelStatus': 1, 'error_message': "None"}
            json_data = json.dumps(data)
            return HttpResponse(json_data)

        except BaseException, msg:
            data = {'cancelStatus': 0, 'error_message': str(msg)}
            json_data = json.dumps(data)
            return HttpResponse(json_data)
Пример #28
0
    def fetchManagerTokens(self):
        try:

            proc = httpProc(self.request, None, None)

            userID = self.request.session['userID']
            currentACL = ACLManager.loadedACL(userID)

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

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

            command = 'sudo docker swarm init --advertise-addr ' + ipAddress
            ProcessUtilities.executioner(command)

            managerToken = ''
            workerToken = ''

            command = "sudo docker swarm join-token manager"
            output = subprocess.check_output(shlex.split(command)).splitlines()

            for items in output:
                if items.find('--token') > -1:
                    managerToken = items.split(' ')[-2]

            command = "sudo docker swarm join-token worker"
            output = subprocess.check_output(shlex.split(command)).splitlines()

            for items in output:
                if items.find('--token') > -1:
                    workerToken = items.split(' ')[-2]

            data = {}
            data['managerToken'] = managerToken
            data['workerToken'] = workerToken

            return proc.ajax(1, None, data)

        except BaseException, msg:
            proc = httpProc(self.request, None, None)
            return proc.ajax(0, None, str(msg))
Пример #29
0
    def createBackup(self):
        self.statusPath = self.extraArgs['tempPath']
        website = self.extraArgs['website']
        self.backupDestinations = self.extraArgs['backupDestinations']
        websiteData = self.extraArgs['websiteData']
        websiteEmails = self.extraArgs['websiteEmails']
        websiteSSLs = self.extraArgs['websiteSSLs']
        websiteDatabases = self.extraArgs['websiteDatabases']

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

        newJob = IncJob(website=self.website)
        newJob.save()

        self.jobid = newJob

        self.passwordFile = '/home/%s/%s' % (self.website.domain,
                                             self.website.domain)
        password = randomPassword.generate_pass()

        self.repoPath = '/home/%s/incbackup' % (self.website.domain)

        if not os.path.exists(self.passwordFile):
            command = 'echo "%s" > %s' % (password, self.passwordFile)
            ProcessUtilities.executioner(command, self.website.externalApp)

        if self.initiateRepo() == 0:
            return

        if self.prepareBackupMeta() == 0:
            return

        if websiteData:
            if self.backupData() == 0:
                return

        if websiteDatabases:
            if self.backupDatabases() == 0:
                return

        if websiteEmails:
            if self.emailBackup() == 0:
                return

        logging.statusWriter(self.statusPath, 'Completed', 1)
Пример #30
0
    def deleteFolderOrFile(self):
        try:
            finalData = {}
            finalData['status'] = 1

            domainName = self.data['domainName']
            website = Websites.objects.get(domain=domainName)

            for item in self.data['fileAndFolders']:
                command = 'rm -rf ' + self.returnPathEnclosed(
                    self.data['path'] + '/' + item)
                ProcessUtilities.executioner(command, website.externalApp)

            json_data = json.dumps(finalData)
            return HttpResponse(json_data)

        except BaseException, msg:
            return self.ajaxPre(0, str(msg))