From d0fd6316774443a8920d969df6e5895819bb8dde Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 3 Apr 2020 11:28:27 +0500 Subject: [PATCH] bug fix: permissions on ubuntu --- filemanager/filemanager.py | 9 +++- plogical/applicationInstaller.py | 77 +++++++++++++++++++++++++++----- plogical/backupUtilities.py | 7 ++- plogical/cPanelImporter.py | 7 ++- plogical/vhost.py | 15 ++++++- plogical/virtualHostUtilities.py | 13 ++++-- 6 files changed, 107 insertions(+), 21 deletions(-) diff --git a/filemanager/filemanager.py b/filemanager/filemanager.py index 1417e28e6..fd4d2fbb8 100755 --- a/filemanager/filemanager.py +++ b/filemanager/filemanager.py @@ -498,13 +498,18 @@ class FileManager: 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 @@ class FileManager: 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) diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 649be3665..a48eb85b8 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -351,8 +351,13 @@ class ApplicationInstaller(multi.Thread): ## + 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 @@ class ApplicationInstaller(multi.Thread): 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 @@ class ApplicationInstaller(multi.Thread): ## + 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 @@ class ApplicationInstaller(multi.Thread): 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 @@ class ApplicationInstaller(multi.Thread): ## - 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 @@ class ApplicationInstaller(multi.Thread): ## + 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 @@ class ApplicationInstaller(multi.Thread): ## - 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 @@ class ApplicationInstaller(multi.Thread): 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 @@ class ApplicationInstaller(multi.Thread): 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 @@ class ApplicationInstaller(multi.Thread): ## + 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 @@ class ApplicationInstaller(multi.Thread): 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: diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index c8a82bd52..6ee5b2583 100755 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -849,7 +849,12 @@ class backupUtilities: 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) diff --git a/plogical/cPanelImporter.py b/plogical/cPanelImporter.py index c8402b576..7c2352971 100644 --- a/plogical/cPanelImporter.py +++ b/plogical/cPanelImporter.py @@ -717,7 +717,12 @@ class cPanelImporter: 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") diff --git a/plogical/vhost.py b/plogical/vhost.py index c8c7d8766..a1d0457b1 100755 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -91,7 +91,12 @@ class vhost: 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 @@ class vhost: 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) diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 654df45bc..7bbfcb306 100755 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -299,10 +299,15 @@ class virtualHostUtilities: 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,7 +316,7 @@ class virtualHostUtilities: 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 @@ -319,7 +324,7 @@ class virtualHostUtilities: 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: