How to use the databases.models.Databases.objects function in databases

To help you get started, we’ve selected a few databases examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github usmannasir / cyberpanel / plogical / cPanelImporter.py View on Github external
## Trying to figure out dbname

                    CommandsPath = '%s/mysql.sql' % (CompletPathToExtractedArchive)

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

                    for inItems in data:
                        if inItems.find('GRANT ALL PRIVILEGES') > -1 and inItems.find('localhost') > -1 and inItems.find('_test') == -1:
                            cDBName = inItems.split('`')[1].replace('\\', '')
                            logging.statusWriter(self.logFile, inItems, 1)
                            if cDBName == items.replace('.sql', ''):
                                cDBUser = inItems.split("'")[1]
                                message = 'Database user for %s is %s.' % (cDBName, cDBUser)
                                logging.statusWriter(self.logFile, message, 1)
                                if Databases.objects.filter(dbUser=cDBUser).count() > 0:
                                    continue
                                break


                    db = Databases(website=website, dbName=items.replace('.sql', ''), dbUser=cDBUser)
                    db.save()

                    message = 'MySQL dump successfully restored for %s.' % (items.replace('.sql', ''))
                    logging.statusWriter(self.logFile, message, 1)

            message = 'Creating Database users from backup file %s.' % (self.backupFile)
            logging.statusWriter(self.logFile, message, 1)

            CommandsPath = '%s/mysql.sql' % (CompletPathToExtractedArchive)

            data = open(CommandsPath, 'r').readlines()
github usmannasir / cyberpanel / plogical / website.py View on Github external
finalPath = ""

            admin = Administrator.objects.get(pk=userID)

            ## DB Creation

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines('Creating database..,10')
            statusFile.close()

            dbName = randomPassword.generate_pass()
            dbUser = dbName
            dbPassword = randomPassword.generate_pass()

            if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter(
                    dbUser=dbUser).exists():
                data_ret = {'status': 0, 'installStatus': 0,
                            'error_message': "0,This database or user is already taken."}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

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

            if result == 1:
                pass
            else:
                data_ret = {'status': 0, 'installStatus': 0,
                            'error_message': "0,Not able to create database."}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
github usmannasir / cyberpanel / websiteFunctions / website.py View on Github external
finalPath = ""

            admin = Administrator.objects.get(pk=userID)

            ## DB Creation

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines('Creating database..,10')
            statusFile.close()

            dbName = randomPassword.generate_pass()
            dbUser = dbName
            dbPassword = randomPassword.generate_pass()

            if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter(
                    dbUser=dbUser).exists():
                data_ret = {'status': 0, 'installStatus': 0,
                            'error_message': "0,This database or user is already taken."}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

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

            if result == 1:
                pass
            else:
                data_ret = {'status': 0, 'installStatus': 0,
                            'error_message': "0,Not able to create database."}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
github usmannasir / cyberpanel / plogical / mysqlUtilities.py View on Github external
def submitDBCreation(dbName, dbUsername, dbPassword, databaseWebsite):
        try:

            if len(dbName) > 16 or len(dbUsername) > 16:
                raise BaseException("Length of Database name or Database user should be 16 at max.")

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

            if website.package.dataBases == 0:
                pass
            elif website.package.dataBases > website.databases_set.all().count():
                pass
            else:
                raise BaseException("Maximum database limit reached for this website.")

            if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter(dbUser=dbUsername).exists():
                raise BaseException("This database or user is already taken.")

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

            if result == 1:
                pass
            else:
                raise BaseException(result)

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

            return 1,'None'

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg))
github usmannasir / cyberpanel / plogical / applicationInstaller.py View on Github external
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()
github usmannasir / cyberpanel / databases / databaseManager.py View on Github external
try:

            currentACL = ACLManager.loadedACL(userID)
            if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0:
                return ACLManager.loadErrorJson('fetchStatus', 0)

            databaseWebsite = data['databaseWebsite']

            admin = Administrator.objects.get(pk=userID)
            if ACLManager.checkOwnership(databaseWebsite, admin, currentACL) == 1:
                pass
            else:
                return ACLManager.loadErrorJson()

            website = Websites.objects.get(domain=databaseWebsite)
            databases = Databases.objects.filter(website=website)

            json_data = "["
            checker = 0

            for items in databases:
                dic = {'id': items.pk,
                       'dbName': items.dbName,
                       'dbUser': items.dbUser, }

                if checker == 0:
                    json_data = json_data + json.dumps(dic)
                    checker = 1
                else:
                    json_data = json_data + ',' + json.dumps(dic)

            json_data = json_data + ']'
github usmannasir / cyberpanel / plogical / vhost.py View on Github external
def deleteVirtualHostConfigurations(virtualHostName):
        if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
            try:

                ## Deleting master conf
                numberOfSites = str(Websites.objects.count() + ChildDomains.objects.count())
                vhost.deleteCoreConf(virtualHostName, numberOfSites)

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

                ## Cagefs

                command = '/usr/sbin/cagefsctl --disable %s' % (delWebsite.externalApp)
                ProcessUtilities.normalExecutioner(command)

                databases = Databases.objects.filter(website=delWebsite)

                childDomains = delWebsite.childdomains_set.all()

                ## Deleting child domains

                for items in childDomains:
                    numberOfSites = Websites.objects.count() + ChildDomains.objects.count()
                    vhost.deleteCoreConf(items.domain, numberOfSites)

                for items in databases:
                    mysqlUtilities.deleteDatabase(items.dbName, items.dbUser)

                delWebsite.delete()

                ## Deleting DNS Zone if there is any.