How to use the databases.models.Databases 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
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()

            for items in data:
                if items.find("--") > -1 or items.find("'cyberpanel'@") > -1:
                    continue
                try:
github usmannasir / cyberpanel / plogical / applicationInstaller.py View on Github external
"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 as msg:
            logging.writeToFile(str(msg) + '[ApplicationInstallerdbCreation]')
github usmannasir / cyberpanel / IncBackups / restoreMeta.py View on Github external
except:
                    logging.statusWriter(statusPath, 'Database did not exist, creating new.. %s' % (dbName))
                    if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, "cyberpanel") == 0:
                        logging.statusWriter(statusPath, 'Failed the creation of database: %s' % (dbName))
                    else:
                        logging.statusWriter(statusPath, 'Database: %s successfully created.' % (dbName))

                    mysqlUtilities.mysqlUtilities.changePassword(dbUser, dbPassword, 1)
                    if mysqlUtilities.mysqlUtilities.changePassword(dbUser, dbPassword, 1) == 0:
                        logging.statusWriter(statusPath, 'Failed changing password for database: %s' % (dbName))
                    else:
                        logging.statusWriter(statusPath, 'Password successfully changed for database: %s.' % (dbName))


                    try:
                        newDB = Databases(website=website, dbName=dbName, dbUser=dbUser)
                        newDB.save()
                    except:
                        pass


            ## Databases restored

            try:
                os.remove(metaPath)
            except:
                pass

        except BaseException, msg:
            logging.writeToFile(str(msg) + " [startRestore]")
github usmannasir / cyberpanel / plogical / backupUtilities.py View on Github external
## Create Configurations ends here

            ## Create databases

            databases = backupMetaData.findall('Databases/database')
            website = Websites.objects.get(domain=domain)

            for database in databases:
                dbName = database.find('dbName').text
                dbUser = database.find('dbUser').text

                if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, "cyberpanel") == 0:
                    raise BaseException("Failed to create Databases!")

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

            ## Create dns zone

            dnsrecords = backupMetaData.findall('dnsrecords/dnsrecord')

            DNS.createDNSZone(domain, admin)

            zone = DNS.getZoneObject(domain)

            for dnsrecord in dnsrecords:

                recordType = dnsrecord.find('type').text
                value = dnsrecord.find('name').text
                content = dnsrecord.find('content').text
                prio = int(dnsrecord.find('priority').text)