add backward compatability to subprocess.run

This commit is contained in:
usmannasir 2024-10-14 15:28:59 +05:00
parent 092d8fd510
commit ff84c80f01
5 changed files with 136 additions and 31 deletions

View File

@ -162,7 +162,11 @@ class preFlightsChecks:
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
command = 'mount -o remount /'
mResult = subprocess.run(command, capture_output=True,universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True,universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
@ -197,7 +201,12 @@ class preFlightsChecks:
return 0
command = 'mount -o remount /'
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
@ -214,19 +223,31 @@ class preFlightsChecks:
####
command = "find /lib/modules/ -type f -name '*quota_v*.ko*'"
iResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
iResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
iResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
print(repr(iResult.stdout))
# Only if the first command works, run the rest
if iResult.returncode == 0:
command = "echo '{}' | sed -n 's|/lib/modules/\\([^/]*\\)/.*|\\1|p' | sort -u".format(iResult.stdout)
result = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
result = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
fResult = result.stdout.rstrip('\n')
print(repr(result.stdout.rstrip('\n')))
command = 'uname -r'
ffResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
ffResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
ffResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
ffResult = ffResult.stdout.rstrip('\n')
command = f"DEBIAN_FRONTEND=noninteractive apt-get install linux-modules-extra-{ffResult}"
@ -328,7 +349,10 @@ class preFlightsChecks:
def mountTemp(self):
try:
result = subprocess.run('systemd-detect-virt', capture_output=True, universal_newlines=True, shell=True)
try:
result = subprocess.run('systemd-detect-virt', capture_output=True, universal_newlines=True, shell=True)
except:
result = subprocess.run('systemd-detect-virt', stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
if result.stdout.find('openvz') > -1:
if self.distro == ubuntu:
@ -1775,7 +1799,10 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout';
# lscpdSelection = 'lscpd.aarch64'
try:
result = subprocess.run('uname -a', capture_output=True, universal_newlines=True, shell=True)
try:
result = subprocess.run('uname -a', capture_output=True, universal_newlines=True, shell=True)
except:
result = subprocess.run('uname -a', stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
if result.stdout.find('aarch64') == -1:
lscpdSelection = 'lscpd-0.3.1'

View File

@ -65,7 +65,10 @@ class InstallCyberPanel:
try:
command = 'uname -a'
result = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
result = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
if 'aarch64' in result.stdout:
return True

View File

@ -27,7 +27,10 @@ class rebuildQuotas:
if rData.find('xfs') > -1:
command = "mount | grep ' / '"
qResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
qResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
qResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
if qResult.stdout.find('usrquota') > -1:
print("Looks like Quotas are enabled in filesystem, moving on..")
@ -37,7 +40,12 @@ class rebuildQuotas:
exit(1)
else:
command = "mount | grep quota"
qResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
qResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
qResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if qResult.stdout.find('usrquota') > -1:
print("Looks like Quotas are enabled in filesystem, moving on..")
else:
@ -49,13 +57,22 @@ class rebuildQuotas:
for website in Websites.objects.all():
print(f"Rebuilding quotas for {website.domain}...")
command = 'chattr -R -i /home/%s/' % (website.domain)
subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
qResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
qResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if website.package.enforceDiskLimits:
spaceString = f'{website.package.diskSpace}M {website.package.diskSpace}M'
command = f'setquota -u {website.externalApp} {spaceString} 0 0 /'
print(command)
qResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
qResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
qResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
else:
print(f"Ignored {website.domain} because the selected package does not enforce disk limits.")
except:

View File

@ -585,8 +585,10 @@ context /.well-known/acme-challenge {
#output = subprocess.check_output(shlex.split(command)).decode("utf-8")
result = subprocess.run(command, capture_output=True, universal_newlines=True,
shell=True)
try:
result = subprocess.run(command, capture_output=True, universal_newlines=True,shell=True)
except:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
stdout = result.stdout
@ -605,8 +607,12 @@ context /.well-known/acme-challenge {
logging.CyberCPLogFileWriter.writeToFile(command, 0)
result = subprocess.run(command, capture_output=True, universal_newlines=True,
shell=True)
try:
result = subprocess.run(command, capture_output=True, universal_newlines=True,
shell=True)
except:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
stdout = result.stdout
stderr = result.stderr
@ -653,8 +659,12 @@ context /.well-known/acme-challenge {
logging.CyberCPLogFileWriter.writeToFile(command)
#output = subprocess.check_output(shlex.split(command)).decode("utf-8")
result = subprocess.run(command, capture_output=True, universal_newlines=True,
shell=True)
try:
result = subprocess.run(command, capture_output=True, universal_newlines=True,
shell=True)
except:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
stdout = result.stdout
stderr = result.stderr
@ -668,8 +678,12 @@ context /.well-known/acme-challenge {
+ '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \
+ ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w /usr/local/lsws/Example/html -k ec-256 --force --server letsencrypt'
result = subprocess.run(command, capture_output=True, universal_newlines=True,
shell=True)
try:
result = subprocess.run(command, capture_output=True, universal_newlines=True,
shell=True)
except:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
stdout = result.stdout
stderr = result.stderr

View File

@ -2291,7 +2291,10 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL
os.remove(lscpdPath)
try:
result = subprocess.run('uname -a', capture_output=True, universal_newlines=True, shell=True)
try:
result = subprocess.run('uname -a', capture_output=True, universal_newlines=True, shell=True)
except:
result = subprocess.run('uname -a', stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, shell=True)
if result.stdout.find('aarch64') == -1:
lscpdSelection = 'lscpd-0.3.1'
@ -3625,7 +3628,12 @@ pm.max_spare_servers = 3
command = 'mount -o remount /'
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
@ -3660,7 +3668,11 @@ pm.max_spare_servers = 3
return 0
command = 'mount -o remount /'
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
@ -3672,7 +3684,11 @@ pm.max_spare_servers = 3
return 0
command = 'quotacheck -ugm /'
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
@ -3686,19 +3702,31 @@ pm.max_spare_servers = 3
####
command = "find /lib/modules/ -type f -name '*quota_v*.ko*'"
iResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
iResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
iResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
print(repr(iResult.stdout))
# Only if the first command works, run the rest
if iResult.returncode == 0:
command = "echo '{}' | sed -n 's|/lib/modules/\\([^/]*\\)/.*|\\1|p' | sort -u".format(iResult.stdout)
result = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
result = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
fResult = result.stdout.rstrip('\n')
print(repr(result.stdout.rstrip('\n')))
command = 'uname -r'
ffResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
ffResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
ffResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
ffResult = ffResult.stdout.rstrip('\n')
command = f"apt-get install linux-modules-extra-{ffResult}"
@ -3707,7 +3735,11 @@ pm.max_spare_servers = 3
###
command = f'modprobe quota_v1 -S {ffResult}'
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
@ -3719,7 +3751,11 @@ pm.max_spare_servers = 3
return 0
command = f'modprobe quota_v2 -S {ffResult}'
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
@ -3731,7 +3767,11 @@ pm.max_spare_servers = 3
return 0
command = f'quotacheck -ugm /'
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
@ -3743,7 +3783,11 @@ pm.max_spare_servers = 3
return 0
command = f'quotaon -v /'
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
try:
mResult = subprocess.run(command, capture_output=True, universal_newlines=True, shell=True)
except:
mResult = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True)
if mResult.returncode != 0:
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'