Beispiel #1
0
    def submitCageFSInstall():
        try:

            mailUtilities.checkHome()

            statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')

            logging.CyberCPLogFileWriter.statusWriter(
                ServerStatusUtil.lswsInstallStatusPath,
                "Starting Packages Installation..\n", 1)

            command = 'sudo yum install cagefs -y'
            ServerStatusUtil.executioner(command, statusFile)

            command = 'sudo /usr/sbin/cagefsctl --init'
            ServerStatusUtil.executioner(command, statusFile)

            command = 'sudo /usr/sbin/cagefsctl --update-etc'
            ServerStatusUtil.executioner(command, statusFile)

            command = 'sudo /usr/sbin/cagefsctl --force-update'
            ServerStatusUtil.executioner(command, statusFile)

            logging.CyberCPLogFileWriter.statusWriter(
                ServerStatusUtil.lswsInstallStatusPath,
                "Packages successfully installed.[200]\n", 1)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.statusWriter(
                ServerStatusUtil.lswsInstallStatusPath,
                str(msg) + ' [404].', 1)
Beispiel #2
0
def remoteTransfer(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 = {
                    "transferStatus": 0,
                    'error_message': "API Access Disabled."
                }
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

            ipAddress = data['ipAddress']
            accountsToTransfer = data['accountsToTransfer']

            if hashPassword.check_password(admin.password, password):
                dir = str(randint(1000, 9999))

                ##

                mailUtilities.checkHome()
                path = "/home/cyberpanel/accounts-" + str(randint(1000, 9999))
                writeToFile = open(path, 'w')

                for items in accountsToTransfer:
                    writeToFile.writelines(items + "\n")
                writeToFile.close()

                ## Accounts to transfer is a path to file, containing accounts.

                execPath = "/usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py"
                execPath = execPath + " remoteTransfer --ipAddress " + ipAddress + " --dir " + dir + " --accountsToTransfer " + path
                ProcessUtilities.popenExecutioner(execPath)

                return HttpResponse(
                    json.dumps({
                        "transferStatus": 1,
                        "dir": dir
                    }))

                ##
            else:
                data_ret = {
                    'transferStatus': 0,
                    'error_message': "Could not authorize access to API."
                }
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

    except BaseException, msg:
        data = {'transferStatus': 0, 'error_message': str(msg)}
        json_data = json.dumps(data)
        return HttpResponse(json_data)
Beispiel #3
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]')
Beispiel #4
0
    def createNameserver(self, request=None, userID=None):
        try:
            currentACL = ACLManager.loadedACL(userID)
            if ACLManager.currentContextPermission(currentACL,
                                                   'createNameServer') == 0:
                return ACLManager.loadError()

            mailUtilities.checkHome()

            if os.path.exists('/home/cyberpanel/powerdns'):
                return render(request, "dns/createNameServer.html",
                              {"status": 1})
            else:
                return render(request, "dns/createNameServer.html",
                              {"status": 0})

        except BaseException, msg:
            return HttpResponse(str(msg))
Beispiel #5
0
def installed(request):

    mailUtilities.checkHome()
    pluginPath = '/home/cyberpanel/plugins'
    pluginList = []

    if os.path.exists(pluginPath):
        for plugin in os.listdir(pluginPath):
            data = {}
            completePath = '/usr/local/CyberCP/' + plugin + '/meta.xml'
            pluginMetaData = ElementTree.parse(completePath)

            data['name'] = pluginMetaData.find('name').text
            data['type'] = pluginMetaData.find('type').text
            data['desc'] = pluginMetaData.find('description').text
            data['version'] = pluginMetaData.find('version').text

            pluginList.append(data)

    return render(request, 'pluginHolder/plugins.html',
                  {'plugins': pluginList})
Beispiel #6
0
    def submitContainerInstall():
        try:

            mailUtilities.checkHome()

            statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')

            logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
                                                      "Starting Packages Installation..\n", 1)

            command = 'sudo yum install -y libcgroup-tools'
            ServerStatusUtil.executioner(command, statusFile)

            command = 'sudo systemctl enable cgconfig'
            ServerStatusUtil.executioner(command, statusFile)

            command = 'sudo systemctl enable cgred'
            ServerStatusUtil.executioner(command, statusFile)

            logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
                                                      "Packages successfully installed.[200]\n", 1)

        except BaseException, msg:
            logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
Beispiel #7
0
def fetchStatus(request):
    try:
        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

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

                mailUtilities.checkHome()

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

                if service == 'powerdns':
                    data_ret = {}
                    data_ret['status'] = 1

                    try:
                        pdns = PDNSStatus.objects.get(pk=1)
                        data_ret['installCheck'] = pdns.serverStatus
                        #data_ret['slaveIPData'] = pdns.also_notify
                    except:
                        PDNSStatus(serverStatus=1).save()
                        data_ret['installCheck'] = 1
                        #data_ret['slaveIPData'] = ''

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

                elif service == 'postfix':
                    if os.path.exists('/home/cyberpanel/postfix'):
                        data_ret = {
                            'status': 1,
                            'error_message': 'None',
                            'installCheck': 1
                        }
                        json_data = json.dumps(data_ret)
                        return HttpResponse(json_data)
                    else:
                        data_ret = {
                            'status': 1,
                            'error_message': 'None',
                            'installCheck': 0
                        }
                        json_data = json.dumps(data_ret)
                        return HttpResponse(json_data)

                elif service == 'pureftpd':
                    if os.path.exists('/home/cyberpanel/pureftpd'):
                        data_ret = {
                            'status': 1,
                            'error_message': 'None',
                            'installCheck': 1
                        }
                        json_data = json.dumps(data_ret)
                        return HttpResponse(json_data)
                    else:
                        data_ret = {
                            'status': 1,
                            'error_message': 'None',
                            'installCheck': 0
                        }
                        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)

    except KeyError, msg:
        logging.CyberCPLogFileWriter.writeToFile(str(msg))
        data_ret = {'status': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
Beispiel #8
0
def saveStatus(request):
    try:
        userID = request.session['userID']
        currentACL = ACLManager.loadedACL(userID)

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

                data = json.loads(request.body)

                status = data['status']
                service = data['service']

                mailUtilities.checkHome()

                if service == 'powerdns':

                    if status == True:

                        pdns = PDNSStatus.objects.get(pk=1)
                        pdns.serverStatus = 1
                        pdns.type = data['dnsMode']

                        if data['dnsMode'] == 'SLAVE':
                            pdns.masterServer = data['slaveServerNS']
                            pdns.masterIP = data['masterServerIP']
                            pdns.save()
                        elif data['dnsMode'] == 'MASTER':
                            pdns.masterServer = 'NONE'
                            pdns.masterIP = 'NONE'
                            pdns.save()

                            for items in SlaveServers.objects.all():
                                items.delete()

                            slaveServer = SlaveServers(
                                slaveServer=data['slaveServer'],
                                slaveServerIP=data['slaveServerIP'])
                            slaveServer.save()

                            try:
                                slaveServer = SlaveServers(
                                    slaveServer=data['slaveServer2'],
                                    slaveServerIP=data['slaveServerIP2'])
                                slaveServer.save()
                            except:
                                pass

                            try:
                                slaveServer = SlaveServers(
                                    slaveServer=data['slaveServer3'],
                                    slaveServerIP=data['slaveServerIP3'])
                                slaveServer.save()
                            except:
                                pass
                        else:
                            pdns.save()

                        if data['dnsMode'] != 'Default':
                            data['type'] = data['dnsMode']

                            sm = ServiceManager(data)
                            sm.managePDNS()

                        command = 'sudo systemctl enable pdns'
                        ProcessUtilities.executioner(command)

                        command = 'sudo systemctl restart pdns'
                        ProcessUtilities.executioner(command)

                    else:

                        pdns = PDNSStatus.objects.get(pk=1)
                        pdns.serverStatus = 0
                        pdns.save()

                        command = 'sudo systemctl stop pdns'
                        ProcessUtilities.executioner(command)

                        command = 'sudo systemctl disable pdns'
                        ProcessUtilities.executioner(command)

                elif service == 'postfix':

                    servicePath = '/home/cyberpanel/postfix'
                    if status == True:
                        writeToFile = open(servicePath, 'w+')
                        writeToFile.close()
                        command = 'sudo systemctl start postfix'
                        ProcessUtilities.executioner(command)
                    else:
                        command = 'sudo systemctl stop postfix'
                        ProcessUtilities.executioner(command)

                        command = 'sudo systemctl disable postfix'
                        ProcessUtilities.executioner(command)

                        try:
                            os.remove(servicePath)
                        except:
                            pass

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

                    servicePath = '/home/cyberpanel/pureftpd'
                    if status == True:
                        writeToFile = open(servicePath, 'w+')
                        writeToFile.close()
                        command = 'sudo systemctl start ' + serviceName
                        ProcessUtilities.executioner(command)
                    else:
                        command = 'sudo systemctl stop ' + serviceName
                        ProcessUtilities.executioner(command)

                        command = 'sudo systemctl disable ' + serviceName
                        ProcessUtilities.executioner(command)

                        try:
                            os.remove(servicePath)
                        except:
                            pass

                data_ret = {'status': 1, 'error_message': "None"}
                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)

    except KeyError, msg:
        logging.CyberCPLogFileWriter.writeToFile(str(msg))
        data_ret = {'status': 0, 'error_message': str(msg)}
        json_data = json.dumps(data_ret)
        return HttpResponse(json_data)
    def setupGit(self):
        try:
            admin = self.extraArgs['admin']
            domainName = self.extraArgs['domainName']
            username = self.extraArgs['username']
            reponame = self.extraArgs['reponame']
            branch = self.extraArgs['branch']
            tempStatusPath = self.extraArgs['tempStatusPath']
            defaultProvider = self.extraArgs['defaultProvider']

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines('Checking if GIT installed..,0')
            statusFile.close()

            ### Check git

            try:
                command = 'sudo git --help'
                output = ProcessUtilities.outputExecutioner(command)

                if output.find('command not found') > -1:
                    statusFile = open(tempStatusPath, 'w')
                    statusFile.writelines('Installing GIT..,0')
                    statusFile.close()
                    self.installGit()
                    statusFile = open(tempStatusPath, 'w')
                    statusFile.writelines('GIT successfully installed,20')
                    statusFile.close()
            except subprocess.CalledProcessError:
                statusFile = open(tempStatusPath, 'w')
                statusFile.writelines('Installing GIT..,0')
                statusFile.close()
                self.installGit()
                statusFile = open(tempStatusPath, 'w')
                statusFile.writelines('GIT successfully installed.,20')
                statusFile.close()

            ## Open Status File

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines('Setting up directories..,20')
            statusFile.close()

            try:
                website = ChildDomains.objects.get(domain=domainName)
                externalApp = website.master.externalApp
                finalPath = website.path

            except:
                website = Websites.objects.get(domain=domainName)
                externalApp = website.externalApp
                finalPath = "/home/" + domainName + "/public_html/"

            ## Security Check

            if finalPath.find("..") > -1:
                statusFile = open(tempStatusPath, 'w')
                statusFile.writelines(
                    "Specified path must be inside virtual host home." +
                    " [404]")
                statusFile.close()
                return 0

            command = 'sudo mkdir -p ' + finalPath
            ProcessUtilities.executioner(command, externalApp)

            ## checking for directories/files

            if self.dataLossCheck(finalPath, tempStatusPath) == 0:
                return 0

            ####

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines('Cloning the repo..,40')
            statusFile.close()

            try:
                command = 'git clone --depth 1 --no-single-branch git@' + defaultProvider + '.com:' + username + '/' + reponame + '.git -b ' + branch + ' ' + finalPath
                ProcessUtilities.executioner(command, externalApp)
            except subprocess.CalledProcessError, msg:
                statusFile = open(tempStatusPath, 'w')
                statusFile.writelines(
                    'Failed to clone repository, make sure you deployed your key to repository. [404]'
                )
                statusFile.close()
                return 0

            ##

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

            vhost.addRewriteRules(domainName)
            installUtilities.reStartLiteSpeed()

            mailUtilities.checkHome()

            gitPath = '/home/cyberpanel/' + domainName + '.git'
            writeToFile = open(gitPath, 'w')
            writeToFile.write(username + ':' + reponame)
            writeToFile.close()

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines(
                "GIT Repository successfully attached. [200]")
            statusFile.close()
            return 0
Beispiel #10
0
    def submitRemoteBackups(self, userID = None, data = None):
        try:
            currentACL = ACLManager.loadedACL(userID)

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

            ipAddress = data['ipAddress']
            password = data['password']

            ## Ask for Remote version of CyberPanel

            try:
                finalData = json.dumps({'username': "******", "password": password})

                url = "https://" + ipAddress + ":8090/api/cyberPanelVersion"

                r = requests.post(url, data=finalData, verify=False)

                data = json.loads(r.text)

                if data['getVersion'] == 1:

                    if float(data['currentVersion']) >= 1.6 and data['build'] >= 0:
                        pass
                    else:
                        data_ret = {'status': 0,
                                    'error_message': "Your version does not match with version of remote server.",
                                    "dir": "Null"}
                        data_ret = json.dumps(data_ret)
                        return HttpResponse(data_ret)
                else:
                    data_ret = {'status': 0,
                                'error_message': "Not able to fetch version of remote server. Error Message: " +
                                                 data[
                                                     'error_message'], "dir": "Null"}
                    data_ret = json.dumps(data_ret)
                    return HttpResponse(data_ret)


            except BaseException, msg:
                data_ret = {'status': 0,
                            'error_message': "Not able to fetch version of remote server. Error Message: " + str(
                                msg),
                            "dir": "Null"}
                data_ret = json.dumps(data_ret)
                return HttpResponse(data_ret)

            ## Fetch public key of remote server!

            finalData = json.dumps({'username': "******", "password": password})

            url = "https://" + ipAddress + ":8090/api/fetchSSHkey"
            r = requests.post(url, data=finalData, verify=False)
            data = json.loads(r.text)

            if data['pubKeyStatus'] == 1:
                pubKey = data["pubKey"].strip("\n")
            else:
                final_json = json.dumps({'status': 0,
                                         'error_message': "I am sorry, I could not fetch key from remote server. Error Message: " +
                                                          data['error_message']
                                         })
                return HttpResponse(final_json)

            ## write key

            ## Writing key to a temporary location, to be read later by backup process.

            mailUtilities.checkHome()

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

            vhost = open(pathToKey, "w")
            vhost.write(pubKey)
            vhost.close()

            ##

            execPath = "/usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py"
            execPath = execPath + " writeAuthKey --pathToKey " + pathToKey
            output = ProcessUtilities.outputExecutioner(execPath)

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

            ##

            try:
                finalData = json.dumps({'username': "******", "password": password})

                url = "https://" + ipAddress + ":8090/api/fetchAccountsFromRemoteServer"

                r = requests.post(url, data=finalData, verify=False)

                data = json.loads(r.text)

                if data['fetchStatus'] == 1:
                    json_data = data['data']
                    data_ret = {'status': 1, 'error_message': "None",
                                "dir": "Null", 'data': json_data}
                    data_ret = json.dumps(data_ret)
                    return HttpResponse(data_ret)
                else:
                    data_ret = {'status': 0,
                                'error_message': "Not able to fetch accounts from remote server. Error Message: " +
                                                 data['error_message'], "dir": "Null"}
                    data_ret = json.dumps(data_ret)
                    return HttpResponse(data_ret)
            except BaseException, msg:
                data_ret = {'status': 0,
                            'error_message': "Not able to fetch accounts from remote server. Error Message: " + str(
                                msg), "dir": "Null"}
                data_ret = json.dumps(data_ret)
                return HttpResponse(data_ret)