mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
centralized execution ph5
This commit is contained in:
@@ -253,7 +253,7 @@ class FirewallManager:
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
else:
|
||||
final_dic = {'status': 1, 'error_message': "none", 'firewallStatus': 0}
|
||||
final_dic = {'status': 1, 'error_message': "none", 'firewallStatus': 1}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
@@ -511,14 +511,13 @@ class FirewallManager:
|
||||
else:
|
||||
return ACLManager.loadErrorJson('installModSec', 0)
|
||||
|
||||
writeToFile = open(modSec.installLogPath, "w")
|
||||
writeToFile.close()
|
||||
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py"
|
||||
execPath = execPath + " installModSec"
|
||||
|
||||
ProcessUtilities.popenExecutioner(execPath)
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
final_json = json.dumps({'installModSec': 1, 'error_message': "None"})
|
||||
return HttpResponse(final_json)
|
||||
|
||||
@@ -539,7 +538,7 @@ class FirewallManager:
|
||||
|
||||
execPath = execPath + " installModSecConfigs"
|
||||
|
||||
output = subprocess.check_output(shlex.split(execPath))
|
||||
output = ProcessUtilities.outputExecutioner(execPath)
|
||||
|
||||
if output.find("1,None") > -1:
|
||||
pass
|
||||
@@ -964,7 +963,7 @@ class FirewallManager:
|
||||
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py"
|
||||
execPath = execPath + " saveModSecRules"
|
||||
output = ProcessUtilities.outputExecutioner(execPath).split('\n')
|
||||
output = ProcessUtilities.outputExecutioner(execPath)
|
||||
|
||||
if output.find("1,None") > -1:
|
||||
data_ret = {'saveStatus': 1, 'error_message': "None"}
|
||||
@@ -1295,8 +1294,8 @@ class FirewallManager:
|
||||
csfInstalled = 1
|
||||
try:
|
||||
command = 'sudo csf -h'
|
||||
res = ProcessUtilities.executioner(command)
|
||||
if res == 0:
|
||||
output = ProcessUtilities.outputExecutioner(command)
|
||||
if output.find("command not found") > -1:
|
||||
csfInstalled = 0
|
||||
except subprocess.CalledProcessError:
|
||||
csfInstalled = 0
|
||||
@@ -1316,6 +1315,7 @@ class FirewallManager:
|
||||
|
||||
execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py"
|
||||
execPath = execPath + " installCSF"
|
||||
|
||||
ProcessUtilities.popenExecutioner(execPath)
|
||||
|
||||
time.sleep(2)
|
||||
@@ -1334,7 +1334,7 @@ class FirewallManager:
|
||||
userID = self.request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
installStatus = unicode(open(CSF.installLogPath, "r").read())
|
||||
installStatus = ProcessUtilities.outputExecutioner("sudo cat " + CSF.installLogPath)
|
||||
|
||||
if installStatus.find("[200]")>-1:
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ urlpatterns = [
|
||||
## CSF
|
||||
|
||||
url(r'^csf$', views.csf, name='csf'),
|
||||
url(r'^installCSF$', views.installCSF, name='installModSec'),
|
||||
url(r'^installCSF$', views.installCSF, name='installCSF'),
|
||||
url(r'^installStatusCSF$', views.installStatusCSF, name='installStatusCSF'),
|
||||
url(r'^removeCSF$', views.removeCSF, name='removeCSF'),
|
||||
url(r'^fetchCSFSettings$', views.fetchCSFSettings, name='fetchCSFSettings'),
|
||||
|
||||
@@ -362,9 +362,6 @@ class MailServerManager:
|
||||
if ACLManager.currentContextPermission(currentACL, 'dkimManager') == 0:
|
||||
return ACLManager.loadError()
|
||||
|
||||
openDKIMInstalled = 0
|
||||
|
||||
if mailUtilities.checkIfDKIMInstalled() == 1:
|
||||
openDKIMInstalled = 1
|
||||
|
||||
websitesName = ACLManager.findAllSites(currentACL, userID)
|
||||
@@ -372,9 +369,6 @@ class MailServerManager:
|
||||
return render(self.request, 'mailServer/dkimManager.html',
|
||||
{'websiteList': websitesName, 'openDKIMInstalled': openDKIMInstalled})
|
||||
|
||||
return render(self.request, 'mailServer/dkimManager.html',
|
||||
{'openDKIMInstalled': openDKIMInstalled})
|
||||
|
||||
except BaseException, msg:
|
||||
return HttpResponse(str(msg))
|
||||
|
||||
|
||||
@@ -158,9 +158,9 @@ class ApplicationInstaller(multi.Thread):
|
||||
|
||||
try:
|
||||
command = 'sudo wp --info'
|
||||
res = ProcessUtilities.executioner(command)
|
||||
outout = ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
if res == 0:
|
||||
if not outout.find('WP-CLI root dir:') > -1:
|
||||
self.installWPCLI()
|
||||
except subprocess.CalledProcessError:
|
||||
self.installWPCLI()
|
||||
|
||||
@@ -29,35 +29,35 @@ class CSF(multi.Thread):
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [CSF.run]')
|
||||
|
||||
def installCSF(self):
|
||||
@staticmethod
|
||||
def installCSF():
|
||||
try:
|
||||
##
|
||||
|
||||
command = 'wget ' + CSF.csfURL
|
||||
cmd = shlex.split(command)
|
||||
logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Downloading CSF..\n', 1)
|
||||
|
||||
with open(CSF.installLogPath, 'a') as f:
|
||||
subprocess.call(cmd, stdout=f)
|
||||
command = 'wget ' + CSF.csfURL
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
##
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Extracting CSF..\n', 1)
|
||||
|
||||
command = 'tar -xzf csf.tgz'
|
||||
cmd = shlex.split(command)
|
||||
|
||||
with open(CSF.installLogPath, 'a') as f:
|
||||
res = subprocess.call(cmd, stdout=f)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
##
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Installing CSF..\n', 1)
|
||||
|
||||
os.chdir('csf')
|
||||
|
||||
command = './install.sh'
|
||||
cmd = shlex.split(command)
|
||||
command = "chmod +x install.sh"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
with open(CSF.installLogPath, 'a') as f:
|
||||
res = subprocess.call(cmd, stdout=f)
|
||||
command = 'bash install.sh'
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
os.chdir('/usr/local/CyberCP')
|
||||
|
||||
## Some initial configurations
|
||||
|
||||
@@ -80,23 +80,23 @@ class CSF(multi.Thread):
|
||||
##
|
||||
|
||||
command = 'csf -s'
|
||||
cmd = shlex.split(command)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
with open(CSF.installLogPath, 'a') as f:
|
||||
subprocess.call(cmd, stdout=f)
|
||||
|
||||
|
||||
writeToFile = open(CSF.installLogPath, 'a')
|
||||
writeToFile.writelines("CSF successfully Installed.[200]\n")
|
||||
writeToFile.close()
|
||||
logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'CSF successfully Installed.[200]\n', 1)
|
||||
|
||||
try:
|
||||
os.remove('csf.tgz')
|
||||
os.removedirs('csf')
|
||||
except:
|
||||
pass
|
||||
|
||||
return 1
|
||||
except BaseException, msg:
|
||||
try:
|
||||
os.remove('csf.tgz')
|
||||
os.removedirs('csf')
|
||||
except:
|
||||
pass
|
||||
writeToFile = open(CSF.installLogPath, 'a')
|
||||
writeToFile.writelines(str(msg) + " [404]")
|
||||
writeToFile.close()
|
||||
@@ -294,8 +294,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.function == "installCSF":
|
||||
controller = CSF(args.function, {})
|
||||
controller.run()
|
||||
CSF.installCSF()
|
||||
elif args.function == 'removeCSF':
|
||||
controller = CSF(args.function, {})
|
||||
controller.run()
|
||||
|
||||
@@ -12,7 +12,7 @@ class ProcessUtilities(multi.Thread):
|
||||
centos = 1
|
||||
ubuntu = 0
|
||||
server_address = '/usr/local/lscpd/admin/comm.sock'
|
||||
token = "2dboNyhseD7ro8rRUsJGy9AlLxJtSjHI"
|
||||
token = "unset"
|
||||
|
||||
def __init__(self, function, extraArgs):
|
||||
multi.Thread.__init__(self)
|
||||
@@ -99,7 +99,7 @@ class ProcessUtilities(multi.Thread):
|
||||
def killLiteSpeed():
|
||||
try:
|
||||
command = 'sudo systemctl stop lsws'
|
||||
ProcessUtilities.executioner(command)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -108,7 +108,7 @@ class ProcessUtilities(multi.Thread):
|
||||
for items in pids:
|
||||
try:
|
||||
command = 'sudo kill -9 ' + str(items)
|
||||
ProcessUtilities.executioner(command)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -155,15 +155,20 @@ class ProcessUtilities(multi.Thread):
|
||||
@staticmethod
|
||||
def sendCommand(command):
|
||||
try:
|
||||
logging.writeToFile(command)
|
||||
|
||||
ret = ProcessUtilities.setupUDSConnection()
|
||||
|
||||
if ret[0] == -1:
|
||||
return ret[0]
|
||||
|
||||
token = os.environ.get('TOKEN')
|
||||
if ProcessUtilities.token == "unset":
|
||||
ProcessUtilities.token = os.environ.get('TOKEN')
|
||||
del os.environ['TOKEN']
|
||||
|
||||
sock = ret[0]
|
||||
sock.sendall(token + command)
|
||||
|
||||
sock.sendall(ProcessUtilities.token + command)
|
||||
data = ""
|
||||
|
||||
while (1):
|
||||
@@ -178,14 +183,21 @@ class ProcessUtilities(multi.Thread):
|
||||
logging.writeToFile(str(msg) + " [sendCommand]")
|
||||
return "0" + str(msg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def executioner(command):
|
||||
try:
|
||||
logging.writeToFile(command)
|
||||
ret = ProcessUtilities.sendCommand(command)
|
||||
|
||||
exitCode = ret[len(ret) -1]
|
||||
exitCode = int(exitCode.encode('hex'), 16)
|
||||
|
||||
if exitCode == 0:
|
||||
#logging.writeToFile("Command: " + command + ", resturn code: " + str(exitCode) + ".")
|
||||
return 1
|
||||
else:
|
||||
#logging.writeToFile("Command: " + command + ", resturn code: " + str(exitCode) + ".")
|
||||
return 0
|
||||
|
||||
except BaseException, msg:
|
||||
logging.writeToFile(str(msg) + " [executioner]")
|
||||
return 0
|
||||
@@ -194,12 +206,11 @@ class ProcessUtilities(multi.Thread):
|
||||
def outputExecutioner(command):
|
||||
try:
|
||||
if type(command) == str or type(command) == unicode:
|
||||
logging.writeToFile(command)
|
||||
pass
|
||||
else:
|
||||
command = " ".join(command)
|
||||
logging.writeToFile(command)
|
||||
|
||||
return ProcessUtilities.sendCommand(command)
|
||||
return ProcessUtilities.sendCommand(command)[:-1]
|
||||
except BaseException, msg:
|
||||
logging.writeToFile(str(msg) + "[outputExecutioner:188]")
|
||||
|
||||
@@ -207,10 +218,8 @@ class ProcessUtilities(multi.Thread):
|
||||
try:
|
||||
if type(self.extraArgs['command']) == str or type(self.extraArgs['command']) == unicode:
|
||||
command = self.extraArgs['command']
|
||||
logging.writeToFile(self.extraArgs['command'])
|
||||
else:
|
||||
command = " ".join(self.extraArgs['command'])
|
||||
logging.writeToFile(command)
|
||||
|
||||
ProcessUtilities.sendCommand(command)
|
||||
|
||||
|
||||
@@ -79,10 +79,6 @@ class virtualHostUtilities:
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'This domain exists as Alias. [404]')
|
||||
return 0, "This domain exists as Alias."
|
||||
|
||||
if dkimCheck == 1:
|
||||
if mailUtilities.checkIfDKIMInstalled() == 0:
|
||||
raise BaseException("OpenDKIM is not installed, install OpenDKIM from DKIM Manager.")
|
||||
|
||||
retValues = mailUtilities.setupDKIM(virtualHostName)
|
||||
if retValues[0] == 0:
|
||||
raise BaseException(retValues[1])
|
||||
@@ -921,10 +917,6 @@ class virtualHostUtilities:
|
||||
|
||||
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'DKIM Setup..,30')
|
||||
|
||||
if dkimCheck == 1:
|
||||
if mailUtilities.checkIfDKIMInstalled() == 0:
|
||||
raise BaseException("OpenDKIM is not installed, install OpenDKIM from DKIM Manager.")
|
||||
|
||||
retValues = mailUtilities.setupDKIM(virtualHostName)
|
||||
if retValues[0] == 0:
|
||||
raise BaseException(retValues[1])
|
||||
|
||||
@@ -37,6 +37,8 @@ class ServerStatusUtil:
|
||||
def installLiteSpeed(licenseKey, statusFile):
|
||||
try:
|
||||
|
||||
logging.CyberCPLogFileWriter.writeToFile(os.environ.get('TERM'))
|
||||
|
||||
cwd = os.getcwd()
|
||||
try:
|
||||
|
||||
@@ -61,18 +63,18 @@ class ServerStatusUtil:
|
||||
if ServerStatusUtil.executioner(command, statusFile) == 0:
|
||||
return 0
|
||||
|
||||
command = 'tar zxf lsws-5.3.5-ent-x86_64-linux.tar.gz'
|
||||
command = 'tar zxf lsws-5.3.5-ent-x86_64-linux.tar.gz -C /usr/local/CyberCP'
|
||||
if ServerStatusUtil.executioner(command, statusFile) == 0:
|
||||
return 0
|
||||
|
||||
writeSerial = open('lsws-5.3.5/serial.no', 'w')
|
||||
writeSerial = open('/usr/local/CyberCP/lsws-5.3.5/serial.no', 'w')
|
||||
writeSerial.writelines(licenseKey)
|
||||
writeSerial.close()
|
||||
|
||||
shutil.copy('/usr/local/CyberCP/serverStatus/litespeed/install.sh', 'lsws-5.3.5/')
|
||||
shutil.copy('/usr/local/CyberCP/serverStatus/litespeed/functions.sh', 'lsws-5.3.5/')
|
||||
shutil.copy('/usr/local/CyberCP/serverStatus/litespeed/install.sh', '/usr/local/CyberCP/lsws-5.3.5/')
|
||||
shutil.copy('/usr/local/CyberCP/serverStatus/litespeed/functions.sh', '/usr/local/CyberCP/lsws-5.3.5/')
|
||||
|
||||
os.chdir('lsws-5.3.5')
|
||||
os.chdir('/usr/local/CyberCP/lsws-5.3.5/')
|
||||
|
||||
command = 'chmod +x install.sh'
|
||||
if ServerStatusUtil.executioner(command, statusFile) == 0:
|
||||
@@ -98,6 +100,11 @@ class ServerStatusUtil:
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
os.rmdir("/usr/local/CyberCP/lsws-5.3.5")
|
||||
except:
|
||||
pass
|
||||
|
||||
return 1
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
@@ -258,6 +265,9 @@ class ServerStatusUtil:
|
||||
@staticmethod
|
||||
def switchTOLSWS(licenseKey):
|
||||
try:
|
||||
|
||||
os.environ['TERM'] = "xterm-256color"
|
||||
|
||||
statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')
|
||||
FNULL = open(os.devnull, 'w')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user