Skip to content

Commit

Permalink
bug fix: Correctly store databases and users for cPanel Importer
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Sep 8, 2019
1 parent f7cb9bd commit 9652510
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
9 changes: 8 additions & 1 deletion filemanager/filemanager.py
Expand Up @@ -193,11 +193,18 @@ def copy(self):
if not self.data['newPath'].find(self.data['home']) > -1:
return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!')

if len(self.data['fileAndFolders']) == 1:
command = 'yes| cp -Rf %s %s' % (self.returnPathEnclosed(self.data['basePath']+ '/' + self.data['fileAndFolders'][0]), self.data['newPath'])
ProcessUtilities.executioner(command, website.externalApp)
self.changeOwner(self.data['newPath'])
json_data = json.dumps(finalData)
return HttpResponse(json_data)

command = 'mkdir ' + self.returnPathEnclosed(self.data['newPath'])
ProcessUtilities.executioner(command, website.externalApp)

for item in self.data['fileAndFolders']:
command = 'cp -R ' + self.returnPathEnclosed(self.data['basePath'] + '/' + item) + ' ' + self.returnPathEnclosed(self.data['newPath'] + '/' + item)
command = '%scp -Rf ' % ('yes |') + self.returnPathEnclosed(self.data['basePath'] + '/' + item) + ' ' + self.returnPathEnclosed(self.data['newPath'])
ProcessUtilities.executioner(command, website.externalApp)

self.changeOwner(self.data['newPath'])
Expand Down
2 changes: 1 addition & 1 deletion plogical/acl.py
Expand Up @@ -519,7 +519,7 @@ def checkOwnershipZone(domain, admin, currentACL):

if currentACL['admin'] == 1:
return 1
elif domain.admin.admin == admin:
elif domain.admin == admin:
return 1
elif domain.admin.owner == admin.pk:
return 1
Expand Down
23 changes: 21 additions & 2 deletions plogical/cPanelImporter.py
Expand Up @@ -628,7 +628,7 @@ def RestoreDatabases(self):
logging.statusWriter(self.logFile, message, 1)

try:
cursor.execute("CREATE DATABASE " + items.replace('.sql', ''))
cursor.execute("CREATE DATABASE `%s`" % (items.replace('.sql', '')))
except BaseException, msg:
message = 'Failed while restoring database %s from backup file %s, error message: %s' % (items.replace('.sql', ''), self.backupFile, str(msg))
logging.statusWriter(self.logFile, message, 1)
Expand All @@ -644,7 +644,26 @@ def RestoreDatabases(self):

website = Websites.objects.get(domain=self.mainDomain)

db = Databases(website=website, dbName=items.replace('.sql', ''), dbUser=items.replace('.sql', ''))
## 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', ''))
Expand Down

0 comments on commit 9652510

Please sign in to comment.