mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 00:06:09 +01:00
major bug fix in old backups
This commit is contained in:
@@ -191,7 +191,7 @@ class backupUtilities:
|
|||||||
child.text = databaseUser[1]
|
child.text = databaseUser[1]
|
||||||
|
|
||||||
## Fetch user password
|
## Fetch user password
|
||||||
dbuser = DBUsers.objects.get(user=databaseUser[0])
|
dbuser = DBUsers.objects.get(user=databaseUser[0], host=databaseUser[1])
|
||||||
child = SubElement(databaseUserXML, 'password')
|
child = SubElement(databaseUserXML, 'password')
|
||||||
child.text = str(dbuser.password)
|
child.text = str(dbuser.password)
|
||||||
|
|
||||||
@@ -609,14 +609,16 @@ class backupUtilities:
|
|||||||
|
|
||||||
if VERSION == '2.1' and BUILD == '1':
|
if VERSION == '2.1' and BUILD == '1':
|
||||||
|
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Backup version 2.1.1 detected..')
|
||||||
|
|
||||||
databaseUsers = database.findall('databaseUsers')
|
databaseUsers = database.findall('databaseUsers')
|
||||||
|
|
||||||
for databaseUser in databaseUsers:
|
for databaseUser in databaseUsers:
|
||||||
|
|
||||||
dbUser = databaseUser.find('dbUser').text
|
dbUser = databaseUser.find('dbUser').text
|
||||||
|
|
||||||
if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, "cyberpanel") == 0:
|
if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, 'cyberpanel') == 0:
|
||||||
raise BaseException("Failed to create Databases!")
|
raise BaseException
|
||||||
|
|
||||||
newDB = Databases(website=website, dbName=dbName, dbUser=dbUser)
|
newDB = Databases(website=website, dbName=dbName, dbUser=dbUser)
|
||||||
newDB.save()
|
newDB.save()
|
||||||
@@ -626,7 +628,7 @@ class backupUtilities:
|
|||||||
dbUser = database.find('dbUser').text
|
dbUser = database.find('dbUser').text
|
||||||
|
|
||||||
if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, "cyberpanel") == 0:
|
if mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, "cyberpanel") == 0:
|
||||||
raise BaseException("Failed to create Databases!")
|
raise BaseException
|
||||||
|
|
||||||
newDB = Databases(website=website, dbName=dbName, dbUser=dbUser)
|
newDB = Databases(website=website, dbName=dbName, dbUser=dbUser)
|
||||||
newDB.save()
|
newDB.save()
|
||||||
@@ -803,6 +805,14 @@ class backupUtilities:
|
|||||||
if float(version) > 2.0 or float(build) > 0:
|
if float(version) > 2.0 or float(build) > 0:
|
||||||
if path.find('/home/%s/public_html' % masterDomain) == -1:
|
if path.find('/home/%s/public_html' % masterDomain) == -1:
|
||||||
#copy_tree('%s/%s-docroot' % (completPath, domain), path)
|
#copy_tree('%s/%s-docroot' % (completPath, domain), path)
|
||||||
|
|
||||||
|
## First remove if already exists
|
||||||
|
|
||||||
|
command = 'rm -rf %s' % (path)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
command = 'cp -R %s/%s-docroot %s' % (completPath, domain, path)
|
command = 'cp -R %s/%s-docroot %s' % (completPath, domain, path)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
@@ -865,6 +875,9 @@ class backupUtilities:
|
|||||||
dbName = database.find('dbName').text
|
dbName = database.find('dbName').text
|
||||||
|
|
||||||
if VERSION == '2.1' and BUILD == '1':
|
if VERSION == '2.1' and BUILD == '1':
|
||||||
|
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Backup version 2.1.1 detected..')
|
||||||
|
|
||||||
first = 1
|
first = 1
|
||||||
|
|
||||||
databaseUsers = database.findall('databaseUsers')
|
databaseUsers = database.findall('databaseUsers')
|
||||||
@@ -875,6 +888,12 @@ class backupUtilities:
|
|||||||
dbHost = databaseUser.find('dbHost').text
|
dbHost = databaseUser.find('dbHost').text
|
||||||
password = databaseUser.find('password').text
|
password = databaseUser.find('password').text
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Database user: %s' % (dbUser))
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Database host: %s' % (dbHost))
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Database password: %s' % (password))
|
||||||
|
|
||||||
if first:
|
if first:
|
||||||
first = 0
|
first = 0
|
||||||
if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(dbName, completPath, password, 1) == 0:
|
if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(dbName, completPath, password, 1) == 0:
|
||||||
@@ -882,6 +901,12 @@ class backupUtilities:
|
|||||||
|
|
||||||
mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, password, 0, dbHost)
|
mysqlUtilities.mysqlUtilities.createDatabase(dbName, dbUser, password, 0, dbHost)
|
||||||
|
|
||||||
|
mysqlUtilities.mysqlUtilities.changePassword(dbUser, password, 1, dbHost)
|
||||||
|
|
||||||
|
# UserInMySQLTable = DBUsers.objects.get(user=dbUser, host=dbHost)
|
||||||
|
# UserInMySQLTable.password = password
|
||||||
|
# UserInMySQLTable.save()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
password = database.find('password').text
|
password = database.find('password').text
|
||||||
if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(dbName, completPath, password) == 0:
|
if mysqlUtilities.mysqlUtilities.restoreDatabaseBackup(dbName, completPath, password) == 0:
|
||||||
@@ -901,6 +926,14 @@ class backupUtilities:
|
|||||||
else:
|
else:
|
||||||
if float(version) > 2.0 or float(build) > 0:
|
if float(version) > 2.0 or float(build) > 0:
|
||||||
#copy_tree('%s/public_html' % (completPath), websiteHome)
|
#copy_tree('%s/public_html' % (completPath), websiteHome)
|
||||||
|
|
||||||
|
## First remove if already exists
|
||||||
|
|
||||||
|
command = 'rm -rf %s' % (websiteHome)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
command = 'cp -R %s/public_html %s' % (completPath, websiteHome)
|
command = 'cp -R %s/public_html %s' % (completPath, websiteHome)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
@@ -931,6 +964,14 @@ class backupUtilities:
|
|||||||
|
|
||||||
if os.path.exists(emailsPath):
|
if os.path.exists(emailsPath):
|
||||||
#copy_tree(emailsPath, '/home/vmail/%s' % (masterDomain))
|
#copy_tree(emailsPath, '/home/vmail/%s' % (masterDomain))
|
||||||
|
|
||||||
|
## First remove if already exists
|
||||||
|
|
||||||
|
command = 'rm -rf /home/vmail/%s' % (masterDomain)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
command = 'cp -R %s /home/vmail/%s' % (emailsPath, masterDomain)
|
command = 'cp -R %s /home/vmail/%s' % (emailsPath, masterDomain)
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,13 @@ class mysqlUtilities:
|
|||||||
## Create db
|
## Create db
|
||||||
|
|
||||||
if dbcreate:
|
if dbcreate:
|
||||||
cursor.execute("CREATE DATABASE " + dbname)
|
|
||||||
|
query = "CREATE DATABASE %s" % (dbname)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(query)
|
||||||
|
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
## create user
|
## create user
|
||||||
|
|
||||||
@@ -155,7 +161,10 @@ class mysqlUtilities:
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
mysqlUtilities.deleteDatabase(dbname, dbuser)
|
if dbcreate:
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile('Deleting database because failed to create %s' % (dbname))
|
||||||
|
mysqlUtilities.deleteDatabase(dbname, dbuser)
|
||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[createDatabase]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[createDatabase]")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -831,18 +840,27 @@ password=%s
|
|||||||
return 0
|
return 0
|
||||||
cursor.execute("use mysql")
|
cursor.execute("use mysql")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if host != None:
|
if host != None:
|
||||||
mysqlUtilities.LOCALHOST = host
|
LOCALHOST = host
|
||||||
|
else:
|
||||||
|
LOCALHOST = mysqlUtilities.LOCALHOST
|
||||||
|
|
||||||
if encrypt == None:
|
if encrypt == None:
|
||||||
try:
|
try:
|
||||||
dbuser = DBUsers.objects.get(user=userName)
|
dbuser = DBUsers.objects.get(user=userName)
|
||||||
cursor.execute("SET PASSWORD FOR '" + userName + "'@'%s' = PASSWORD('" % (mysqlUtilities.LOCALHOST) + dbPassword + "')")
|
query = "SET PASSWORD FOR '" + userName + "'@'%s' = PASSWORD('" % (LOCALHOST) + dbPassword + "')"
|
||||||
except:
|
except:
|
||||||
userName = mysqlUtilities.fetchuser(userName)
|
userName = mysqlUtilities.fetchuser(userName)
|
||||||
cursor.execute("SET PASSWORD FOR '" + userName + "'@'%s' = PASSWORD('" % (mysqlUtilities.LOCALHOST) + dbPassword + "')")
|
query = "SET PASSWORD FOR '" + userName + "'@'%s' = PASSWORD('" % (LOCALHOST) + dbPassword + "')"
|
||||||
else:
|
else:
|
||||||
cursor.execute("SET PASSWORD FOR '" + userName + "'@'%s' = '" % (mysqlUtilities.LOCALHOST) + dbPassword + "'")
|
query = "SET PASSWORD FOR '" + userName + "'@'%s' = '" % (LOCALHOST) + dbPassword + "'"
|
||||||
|
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.CyberCPLogFileWriter.writeToFile(query)
|
||||||
|
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user