Skip to content
Permalink
Browse files
bug fix: permissions on ubuntu
  • Loading branch information
usmannasir committed Apr 3, 2020
1 parent 4db2168 commit d0fd6316774443a8920d969df6e5895819bb8dde
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 21 deletions.
@@ -498,13 +498,18 @@ def fixPermissions(self, domainName):
website = Websites.objects.get(domain=domainName)
externalApp = website.externalApp

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

command = 'chown -R %s:%s /home/%s/public_html/*' % (externalApp, externalApp, domainName)
ProcessUtilities.popenExecutioner(command)

command = 'chown -R %s:%s /home/%s/public_html/.[^.]*' % (externalApp, externalApp, domainName)
ProcessUtilities.popenExecutioner(command)

command = "chown root:nobody /home/" + domainName + "/logs"
command = "chown root:%s /home/" % (groupName) + domainName + "/logs"
ProcessUtilities.popenExecutioner(command)

command = "find %s -type d -exec chmod 0755 {} \;" % ("/home/" + domainName + "/public_html")
@@ -513,7 +518,7 @@ def fixPermissions(self, domainName):
command = "find %s -type f -exec chmod 0644 {} \;" % ("/home/" + domainName + "/public_html")
ProcessUtilities.popenExecutioner(command)

command = 'chown %s:nobody /home/%s/public_html' % (externalApp, domainName)
command = 'chown %s:%s /home/%s/public_html' % (externalApp,groupName, domainName)
ProcessUtilities.executioner(command)

command = 'chmod 750 /home/%s/public_html' % (domainName)
@@ -351,8 +351,13 @@ def installWordPress(self):

##

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

if home != '0':
command = "chown " + externalApp + ":" + 'nobody' + " " + finalPath
command = "chown " + externalApp + ":" + groupName + " " + finalPath
ProcessUtilities.executioner(command, externalApp)

command = 'chmod 750 %s' % (self.permPath)
@@ -370,8 +375,13 @@ def installWordPress(self):

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

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

if not os.path.exists(homeDir):
command = "chown " + externalApp + ":" + 'nobody' + " " + homeDir
command = "chown " + externalApp + ":" + groupName + " " + homeDir
ProcessUtilities.executioner(command, externalApp)

try:
@@ -523,8 +533,13 @@ def installPrestaShop(self):

##

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

if home == '0':
command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
ProcessUtilities.executioner(command, externalApp)

command = "rm -f prestashop_1.7.4.2.zip"
@@ -544,8 +559,13 @@ def installPrestaShop(self):

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

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

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

try:
@@ -652,7 +672,12 @@ def setupGit(self):

##

command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
ProcessUtilities.executioner(command, externalApp)

vhost.addRewriteRules(domainName)
@@ -714,10 +739,15 @@ def gitPull(self):

##

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

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

command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
ProcessUtilities.executioner(command, externalApp)

return 0
@@ -756,7 +786,12 @@ def detachRepo(self):

##

command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
ProcessUtilities.executioner(command, website.externalApp)

gitPath = '/home/cyberpanel/' + domain + '.git'
@@ -906,7 +941,12 @@ def installJoomla(self):

shutil.rmtree(finalPath + "installation")

command = "chown -R " + virtualHostUser + ":" + 'nobody' + " " + finalPath
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

command = "chown -R " + virtualHostUser + ":" + groupName + " " + finalPath
ProcessUtilities.executioner(command)

vhost.addRewriteRules(domainName)
@@ -927,8 +967,13 @@ def installJoomla(self):

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

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

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

try:
@@ -1120,8 +1165,13 @@ def installMagento(self):

##

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

if home != '0':
command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
ProcessUtilities.executioner(command, externalApp)

installUtilities.reStartLiteSpeed()
@@ -1140,8 +1190,13 @@ def installMagento(self):

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

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

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

try:
@@ -849,7 +849,12 @@ def startRestore(backupName, dir):

installUtilities.reStartLiteSpeed()

command = "chown -R " + externalApp + ":nobody" " " + websiteHome
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

command = "chown -R " + externalApp + ":%s " % (groupName) + websiteHome
cmd = shlex.split(command)
subprocess.call(cmd)

@@ -717,7 +717,12 @@ def FixPermissions(self):
command = "sudo chown -R " + externalApp + ":" + externalApp + " /home/" + self.mainDomain
ProcessUtilities.normalExecutioner(command)

command = "sudo chown -R root:nobody /home/" + self.mainDomain + "/logs"
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

command = "sudo chown -R root:%s /home/" % (groupName) + self.mainDomain + "/logs"
ProcessUtilities.normalExecutioner(command)

command = "sudo find %s -type d -exec chmod 0755 {} \;" % ("/home/" + self.mainDomain + "/public_html")
@@ -91,7 +91,12 @@ def createDirectories(path, virtualHostUser, pathHTML, pathLogs, confPath, compl
try:
os.makedirs(pathHTML)

command = "chown " + virtualHostUser + ":nobody " + pathHTML
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

command = "chown " + virtualHostUser + ":%s " % (groupName) + pathHTML
cmd = shlex.split(command)
subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)

@@ -842,7 +847,13 @@ def createDirectoryForDomain(masterDomain, domain, phpVersion, path, administrat

try:
os.makedirs(path)
command = "chown " + virtualHostUser + ":nobody " + path

if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

command = "chown " + virtualHostUser + ":%s " % (groupName) + path
cmd = shlex.split(command)
subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)

@@ -299,10 +299,15 @@ def getAccessLogs(fileName, page, externalApp):
print("0, %s file is symlinked." % (fileName))
return 0

numberOfTotalLines = int(ProcessUtilities.outputExecutioner('wc -l %s' % (fileName), 'nobody').split(" ")[0])
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
groupName = 'nobody'
else:
groupName = 'nogroup'

numberOfTotalLines = int(ProcessUtilities.outputExecutioner('wc -l %s' % (fileName), groupName).split(" ")[0])

if numberOfTotalLines < 25:
data = ProcessUtilities.outputExecutioner('cat %s' % (fileName), 'nobody')
data = ProcessUtilities.outputExecutioner('cat %s' % (fileName), groupName)
else:
if page == 1:
end = numberOfTotalLines
@@ -311,15 +316,15 @@ def getAccessLogs(fileName, page, externalApp):
start = 1
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
command = "sed -n " + startingAndEnding + " " + fileName
data = ProcessUtilities.outputExecutioner(command, 'nobody')
data = ProcessUtilities.outputExecutioner(command, groupName)
else:
end = numberOfTotalLines - ((page - 1) * 25)
start = end - 24
if start <= 0:
start = 1
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
command = "sed -n " + startingAndEnding + " " + fileName
data = ProcessUtilities.outputExecutioner(command, 'nobody')
data = ProcessUtilities.outputExecutioner(command, groupName)
print(data)
return data
except BaseException as msg:

0 comments on commit d0fd631

Please sign in to comment.