How to use the databases.models.Databases.objects.get 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 / IncBackups / restoreMeta.py View on Github external
## restoring databases

            logging.statusWriter(statusPath, "Restoring Databases!", 1)

            ## Create databases

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

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

                try:
                    dbExist = Databases.objects.get(dbName=dbName)
                    logging.statusWriter(statusPath, 'Database exists, changing Database password.. %s' % (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))
                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))
github usmannasir / cyberpanel / plogical / applicationInstaller.py View on Github external
statusFile.close()
            return 0


        except BaseException as msg:
            # remove the downloaded files

            homeDir = "/home/" + domainName + "/public_html"

            if not os.path.exists(homeDir):
                command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir
                ProcessUtilities.executioner(command, externalApp)

            try:
                mysqlUtilities.deleteDatabase(dbName, dbUser)
                db = Databases.objects.get(dbName=dbName)
                db.delete()
            except:
                pass

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines(str(msg) + " [404]")
            statusFile.close()
            return 0
github usmannasir / cyberpanel / plogical / mysqlUtilities.py View on Github external
    @staticmethod
    def fetchuser(userName):
        try:
            connection, cursor = mysqlUtilities.setupConnection()
            cursor.execute("use mysql")

            database = Databases.objects.get(dbUser=userName)
            databaseName = database.dbName
            databaseName = databaseName.replace('_', '\_')
            query = "select user from db where db = '%s'" % (databaseName)

            if connection == 0:
                return 0

            cursor.execute(query)
            rows = cursor.fetchall()
            counter = 0

            for row in rows:
                if row[0].find('_') > -1:
                    database.dbUser = row[0]
                    database.save()
                    try:
github usmannasir / cyberpanel / plogical / applicationInstaller.py View on Github external
statusFile.writelines("Successfully Installed. [200]")
            statusFile.close()
            return 0

        except BaseException as msg:
            # remove the downloaded files

            homeDir = "/home/" + domainName + "/public_html"

            if not os.path.exists(homeDir):
                command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + homeDir
                ProcessUtilities.executioner(command)

            try:
                mysqlUtilities.deleteDatabase(dbName, dbUser)
                db = Databases.objects.get(dbName=dbName)
                db.delete()
            except:
                pass

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines(str(msg) + " [404]")
            statusFile.close()
            logging.writeToFile(str(msg))
            return 0
github usmannasir / cyberpanel / databases / databaseManager.py View on Github external
def changePassword(self, userID = None, data = None):
        try:
            currentACL = ACLManager.loadedACL(userID)

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

            userName = data['dbUserName']
            dbPassword = data['dbPassword']

            db = Databases.objects.get(dbUser=userName)

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


            res = mysqlUtilities.changePassword(userName, dbPassword)

            if res == 0:
                data_ret = {'status': 0, 'changePasswordStatus': 0,'error_message': "Please see CyberPanel main log file."}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)

            data_ret = {'status': 1, 'changePasswordStatus': 1, 'error_message': "None"}
github usmannasir / cyberpanel / databases / databaseManager.py View on Github external
def submitDatabaseDeletion(self, userID = None, data = None):
        try:
            currentACL = ACLManager.loadedACL(userID)
            admin = Administrator.objects.get(pk=userID)
            if ACLManager.currentContextPermission(currentACL, 'deleteDatabase') == 0:
                return ACLManager.loadErrorJson('deleteStatus', 0)

            dbName = data['dbName']
            db = Databases.objects.get(dbName=dbName)

            if ACLManager.checkOwnership(db.website.domain, admin, currentACL) == 1:
                pass
            else:
                return ACLManager.loadErrorJson()

            result = mysqlUtilities.submitDBDeletion(dbName)

            if result[0] == 1:
                data_ret = {'status': 1, 'deleteStatus': 1, 'error_message': "None"}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
            else:
                data_ret = {'status': 0, 'deleteStatus': 0, 'error_message': result[1]}
                json_data = json.dumps(data_ret)
                return HttpResponse(json_data)
github usmannasir / cyberpanel / plogical / applicationInstaller.py View on Github external
statusFile.close()
            return 0


        except BaseException as msg:
            # remove the downloaded files

            homeDir = "/home/" + domainName + "/public_html"

            if not os.path.exists(homeDir):
                command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir
                ProcessUtilities.executioner(command, externalApp)

            try:
                mysqlUtilities.deleteDatabase(dbName, dbUser)
                db = Databases.objects.get(dbName=dbName)
                db.delete()
            except:
                pass

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines(str(msg) + " [404]")
            statusFile.close()
            return 0
github usmannasir / cyberpanel / plogical / applicationInstaller.py View on Github external
return 0


        except BaseException as msg:
            # remove the downloaded files
            FNULL = open(os.devnull, 'w')

            homeDir = "/home/" + domainName + "/public_html"

            if not os.path.exists(homeDir):
                command = "chown -R " + externalApp + ":" + externalApp + " " + homeDir
                ProcessUtilities.executioner(command, externalApp)

            try:
                mysqlUtilities.deleteDatabase(dbName, dbUser)
                db = Databases.objects.get(dbName=dbName)
                db.delete()
            except:
                pass

            statusFile = open(tempStatusPath, 'w')
            statusFile.writelines(str(msg) + " [404]")
            statusFile.close()
            return 0
github usmannasir / cyberpanel / plogical / mysqlUtilities.py View on Github external
    @staticmethod
    def submitDBDeletion(dbName):
        try:

            databaseToBeDeleted = Databases.objects.get(dbName=dbName)
            result = mysqlUtilities.deleteDatabase(dbName, databaseToBeDeleted.dbUser)

            if result == 1:
                databaseToBeDeleted.delete()
                return 1,'None'
            else:
                return 0,result

        except BaseException, msg:
            logging.CyberCPLogFileWriter.writeToFile(str(msg))
            return 0, str(msg)