Skip to content

Commit d0fd631

Browse files
committed
bug fix: permissions on ubuntu
1 parent 4db2168 commit d0fd631

File tree

6 files changed

+107
-21
lines changed

6 files changed

+107
-21
lines changed

filemanager/filemanager.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,18 @@ def fixPermissions(self, domainName):
498498
website = Websites.objects.get(domain=domainName)
499499
externalApp = website.externalApp
500500

501+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
502+
groupName = 'nobody'
503+
else:
504+
groupName = 'nogroup'
505+
501506
command = 'chown -R %s:%s /home/%s/public_html/*' % (externalApp, externalApp, domainName)
502507
ProcessUtilities.popenExecutioner(command)
503508

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

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

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

516-
command = 'chown %s:nobody /home/%s/public_html' % (externalApp, domainName)
521+
command = 'chown %s:%s /home/%s/public_html' % (externalApp,groupName, domainName)
517522
ProcessUtilities.executioner(command)
518523

519524
command = 'chmod 750 /home/%s/public_html' % (domainName)

plogical/applicationInstaller.py

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,13 @@ def installWordPress(self):
351351

352352
##
353353

354+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
355+
groupName = 'nobody'
356+
else:
357+
groupName = 'nogroup'
358+
354359
if home != '0':
355-
command = "chown " + externalApp + ":" + 'nobody' + " " + finalPath
360+
command = "chown " + externalApp + ":" + groupName + " " + finalPath
356361
ProcessUtilities.executioner(command, externalApp)
357362

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

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

378+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
379+
groupName = 'nobody'
380+
else:
381+
groupName = 'nogroup'
382+
373383
if not os.path.exists(homeDir):
374-
command = "chown " + externalApp + ":" + 'nobody' + " " + homeDir
384+
command = "chown " + externalApp + ":" + groupName + " " + homeDir
375385
ProcessUtilities.executioner(command, externalApp)
376386

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

524534
##
525535

536+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
537+
groupName = 'nobody'
538+
else:
539+
groupName = 'nogroup'
540+
526541
if home == '0':
527-
command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
542+
command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
528543
ProcessUtilities.executioner(command, externalApp)
529544

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

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

562+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
563+
groupName = 'nobody'
564+
else:
565+
groupName = 'nogroup'
566+
547567
if not os.path.exists(homeDir):
548-
command = "chown -R " + externalApp + ":" + 'nobody' + " " + homeDir
568+
command = "chown -R " + externalApp + ":" + groupName + " " + homeDir
549569
ProcessUtilities.executioner(command, externalApp)
550570

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

653673
##
654674

655-
command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
675+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
676+
groupName = 'nobody'
677+
else:
678+
groupName = 'nogroup'
679+
680+
command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
656681
ProcessUtilities.executioner(command, externalApp)
657682

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

715740
##
716741

742+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
743+
groupName = 'nobody'
744+
else:
745+
groupName = 'nogroup'
746+
717747
website = Websites.objects.get(domain=domain)
718748
externalApp = website.externalApp
719749

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

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

757787
##
758788

759-
command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
789+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
790+
groupName = 'nobody'
791+
else:
792+
groupName = 'nogroup'
793+
794+
command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
760795
ProcessUtilities.executioner(command, website.externalApp)
761796

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

907942
shutil.rmtree(finalPath + "installation")
908943

909-
command = "chown -R " + virtualHostUser + ":" + 'nobody' + " " + finalPath
944+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
945+
groupName = 'nobody'
946+
else:
947+
groupName = 'nogroup'
948+
949+
command = "chown -R " + virtualHostUser + ":" + groupName + " " + finalPath
910950
ProcessUtilities.executioner(command)
911951

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

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

970+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
971+
groupName = 'nobody'
972+
else:
973+
groupName = 'nogroup'
974+
930975
if not os.path.exists(homeDir):
931-
command = "chown -R " + virtualHostUser + ":" + 'nobody' + " " + homeDir
976+
command = "chown -R " + virtualHostUser + ":" + groupName + " " + homeDir
932977
ProcessUtilities.executioner(command)
933978

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

11211166
##
11221167

1168+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
1169+
groupName = 'nobody'
1170+
else:
1171+
groupName = 'nogroup'
1172+
11231173
if home != '0':
1124-
command = "chown -R " + externalApp + ":" + 'nobody' + " " + finalPath
1174+
command = "chown -R " + externalApp + ":" + groupName + " " + finalPath
11251175
ProcessUtilities.executioner(command, externalApp)
11261176

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

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

1193+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
1194+
groupName = 'nobody'
1195+
else:
1196+
groupName = 'nogroup'
1197+
11431198
if not os.path.exists(homeDir):
1144-
command = "chown -R " + externalApp + ":" + 'nobody' + " " + homeDir
1199+
command = "chown -R " + externalApp + ":" + groupName + " " + homeDir
11451200
ProcessUtilities.executioner(command, externalApp)
11461201

11471202
try:

plogical/backupUtilities.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,12 @@ def startRestore(backupName, dir):
849849

850850
installUtilities.reStartLiteSpeed()
851851

852-
command = "chown -R " + externalApp + ":nobody" " " + websiteHome
852+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
853+
groupName = 'nobody'
854+
else:
855+
groupName = 'nogroup'
856+
857+
command = "chown -R " + externalApp + ":%s " % (groupName) + websiteHome
853858
cmd = shlex.split(command)
854859
subprocess.call(cmd)
855860

plogical/cPanelImporter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,12 @@ def FixPermissions(self):
717717
command = "sudo chown -R " + externalApp + ":" + externalApp + " /home/" + self.mainDomain
718718
ProcessUtilities.normalExecutioner(command)
719719

720-
command = "sudo chown -R root:nobody /home/" + self.mainDomain + "/logs"
720+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
721+
groupName = 'nobody'
722+
else:
723+
groupName = 'nogroup'
724+
725+
command = "sudo chown -R root:%s /home/" % (groupName) + self.mainDomain + "/logs"
721726
ProcessUtilities.normalExecutioner(command)
722727

723728
command = "sudo find %s -type d -exec chmod 0755 {} \;" % ("/home/" + self.mainDomain + "/public_html")

plogical/vhost.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ def createDirectories(path, virtualHostUser, pathHTML, pathLogs, confPath, compl
9191
try:
9292
os.makedirs(pathHTML)
9393

94-
command = "chown " + virtualHostUser + ":nobody " + pathHTML
94+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
95+
groupName = 'nobody'
96+
else:
97+
groupName = 'nogroup'
98+
99+
command = "chown " + virtualHostUser + ":%s " % (groupName) + pathHTML
95100
cmd = shlex.split(command)
96101
subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
97102

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

843848
try:
844849
os.makedirs(path)
845-
command = "chown " + virtualHostUser + ":nobody " + path
850+
851+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
852+
groupName = 'nobody'
853+
else:
854+
groupName = 'nogroup'
855+
856+
command = "chown " + virtualHostUser + ":%s " % (groupName) + path
846857
cmd = shlex.split(command)
847858
subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
848859

plogical/virtualHostUtilities.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,15 @@ def getAccessLogs(fileName, page, externalApp):
299299
print("0, %s file is symlinked." % (fileName))
300300
return 0
301301

302-
numberOfTotalLines = int(ProcessUtilities.outputExecutioner('wc -l %s' % (fileName), 'nobody').split(" ")[0])
302+
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
303+
groupName = 'nobody'
304+
else:
305+
groupName = 'nogroup'
306+
307+
numberOfTotalLines = int(ProcessUtilities.outputExecutioner('wc -l %s' % (fileName), groupName).split(" ")[0])
303308

304309
if numberOfTotalLines < 25:
305-
data = ProcessUtilities.outputExecutioner('cat %s' % (fileName), 'nobody')
310+
data = ProcessUtilities.outputExecutioner('cat %s' % (fileName), groupName)
306311
else:
307312
if page == 1:
308313
end = numberOfTotalLines
@@ -311,15 +316,15 @@ def getAccessLogs(fileName, page, externalApp):
311316
start = 1
312317
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
313318
command = "sed -n " + startingAndEnding + " " + fileName
314-
data = ProcessUtilities.outputExecutioner(command, 'nobody')
319+
data = ProcessUtilities.outputExecutioner(command, groupName)
315320
else:
316321
end = numberOfTotalLines - ((page - 1) * 25)
317322
start = end - 24
318323
if start <= 0:
319324
start = 1
320325
startingAndEnding = "'" + str(start) + "," + str(end) + "p'"
321326
command = "sed -n " + startingAndEnding + " " + fileName
322-
data = ProcessUtilities.outputExecutioner(command, 'nobody')
327+
data = ProcessUtilities.outputExecutioner(command, groupName)
323328
print(data)
324329
return data
325330
except BaseException as msg:

0 commit comments

Comments
 (0)