centralized execution ph5

This commit is contained in:
usmannasir
2019-04-01 15:19:54 +05:00
parent e12b412a42
commit 04e07905f2
8 changed files with 85 additions and 81 deletions

View File

@@ -253,7 +253,7 @@ class FirewallManager:
final_json = json.dumps(final_dic) final_json = json.dumps(final_dic)
return HttpResponse(final_json) return HttpResponse(final_json)
else: 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) final_json = json.dumps(final_dic)
return HttpResponse(final_json) return HttpResponse(final_json)
@@ -511,14 +511,13 @@ class FirewallManager:
else: else:
return ACLManager.loadErrorJson('installModSec', 0) return ACLManager.loadErrorJson('installModSec', 0)
writeToFile = open(modSec.installLogPath, "w")
writeToFile.close()
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py"
execPath = execPath + " installModSec" execPath = execPath + " installModSec"
ProcessUtilities.popenExecutioner(execPath) ProcessUtilities.popenExecutioner(execPath)
time.sleep(3)
final_json = json.dumps({'installModSec': 1, 'error_message': "None"}) final_json = json.dumps({'installModSec': 1, 'error_message': "None"})
return HttpResponse(final_json) return HttpResponse(final_json)
@@ -539,7 +538,7 @@ class FirewallManager:
execPath = execPath + " installModSecConfigs" execPath = execPath + " installModSecConfigs"
output = subprocess.check_output(shlex.split(execPath)) output = ProcessUtilities.outputExecutioner(execPath)
if output.find("1,None") > -1: if output.find("1,None") > -1:
pass pass
@@ -964,7 +963,7 @@ class FirewallManager:
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py"
execPath = execPath + " saveModSecRules" execPath = execPath + " saveModSecRules"
output = ProcessUtilities.outputExecutioner(execPath).split('\n') output = ProcessUtilities.outputExecutioner(execPath)
if output.find("1,None") > -1: if output.find("1,None") > -1:
data_ret = {'saveStatus': 1, 'error_message': "None"} data_ret = {'saveStatus': 1, 'error_message': "None"}
@@ -1295,8 +1294,8 @@ class FirewallManager:
csfInstalled = 1 csfInstalled = 1
try: try:
command = 'sudo csf -h' command = 'sudo csf -h'
res = ProcessUtilities.executioner(command) output = ProcessUtilities.outputExecutioner(command)
if res == 0: if output.find("command not found") > -1:
csfInstalled = 0 csfInstalled = 0
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
csfInstalled = 0 csfInstalled = 0
@@ -1316,6 +1315,7 @@ class FirewallManager:
execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py" execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py"
execPath = execPath + " installCSF" execPath = execPath + " installCSF"
ProcessUtilities.popenExecutioner(execPath) ProcessUtilities.popenExecutioner(execPath)
time.sleep(2) time.sleep(2)
@@ -1334,7 +1334,7 @@ class FirewallManager:
userID = self.request.session['userID'] userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
installStatus = unicode(open(CSF.installLogPath, "r").read()) installStatus = ProcessUtilities.outputExecutioner("sudo cat " + CSF.installLogPath)
if installStatus.find("[200]")>-1: if installStatus.find("[200]")>-1:

View File

@@ -42,7 +42,7 @@ urlpatterns = [
## CSF ## CSF
url(r'^csf$', views.csf, name='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'^installStatusCSF$', views.installStatusCSF, name='installStatusCSF'),
url(r'^removeCSF$', views.removeCSF, name='removeCSF'), url(r'^removeCSF$', views.removeCSF, name='removeCSF'),
url(r'^fetchCSFSettings$', views.fetchCSFSettings, name='fetchCSFSettings'), url(r'^fetchCSFSettings$', views.fetchCSFSettings, name='fetchCSFSettings'),

View File

@@ -362,18 +362,12 @@ class MailServerManager:
if ACLManager.currentContextPermission(currentACL, 'dkimManager') == 0: if ACLManager.currentContextPermission(currentACL, 'dkimManager') == 0:
return ACLManager.loadError() return ACLManager.loadError()
openDKIMInstalled = 0 openDKIMInstalled = 1
if mailUtilities.checkIfDKIMInstalled() == 1: websitesName = ACLManager.findAllSites(currentACL, userID)
openDKIMInstalled = 1
websitesName = ACLManager.findAllSites(currentACL, userID)
return render(self.request, 'mailServer/dkimManager.html',
{'websiteList': websitesName, 'openDKIMInstalled': openDKIMInstalled})
return render(self.request, 'mailServer/dkimManager.html', return render(self.request, 'mailServer/dkimManager.html',
{'openDKIMInstalled': openDKIMInstalled}) {'websiteList': websitesName, 'openDKIMInstalled': openDKIMInstalled})
except BaseException, msg: except BaseException, msg:
return HttpResponse(str(msg)) return HttpResponse(str(msg))

View File

@@ -158,9 +158,9 @@ class ApplicationInstaller(multi.Thread):
try: try:
command = 'sudo wp --info' 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() self.installWPCLI()
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
self.installWPCLI() self.installWPCLI()

View File

@@ -29,35 +29,35 @@ class CSF(multi.Thread):
except BaseException, msg: except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [CSF.run]') logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [CSF.run]')
def installCSF(self): @staticmethod
def installCSF():
try: try:
## ##
command = 'wget ' + CSF.csfURL logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Downloading CSF..\n', 1)
cmd = shlex.split(command)
with open(CSF.installLogPath, 'a') as f: command = 'wget ' + CSF.csfURL
subprocess.call(cmd, stdout=f) ProcessUtilities.normalExecutioner(command)
## ##
logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Extracting CSF..\n', 1)
command = 'tar -xzf csf.tgz' command = 'tar -xzf csf.tgz'
cmd = shlex.split(command) ProcessUtilities.normalExecutioner(command)
with open(CSF.installLogPath, 'a') as f:
res = subprocess.call(cmd, stdout=f)
## ##
logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Installing CSF..\n', 1)
os.chdir('csf') os.chdir('csf')
command = './install.sh' command = "chmod +x install.sh"
cmd = shlex.split(command) ProcessUtilities.normalExecutioner(command)
with open(CSF.installLogPath, 'a') as f: command = 'bash install.sh'
res = subprocess.call(cmd, stdout=f) ProcessUtilities.normalExecutioner(command)
os.chdir('/usr/local/CyberCP')
## Some initial configurations ## Some initial configurations
@@ -80,23 +80,23 @@ class CSF(multi.Thread):
## ##
command = 'csf -s' command = 'csf -s'
cmd = shlex.split(command) ProcessUtilities.normalExecutioner(command)
with open(CSF.installLogPath, 'a') as f: logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'CSF successfully Installed.[200]\n', 1)
subprocess.call(cmd, stdout=f)
try:
writeToFile = open(CSF.installLogPath, 'a') os.remove('csf.tgz')
writeToFile.writelines("CSF successfully Installed.[200]\n") os.removedirs('csf')
writeToFile.close() except:
pass
os.remove('csf.tgz')
os.removedirs('csf')
return 1 return 1
except BaseException, msg: except BaseException, msg:
os.remove('csf.tgz') try:
os.removedirs('csf') os.remove('csf.tgz')
os.removedirs('csf')
except:
pass
writeToFile = open(CSF.installLogPath, 'a') writeToFile = open(CSF.installLogPath, 'a')
writeToFile.writelines(str(msg) + " [404]") writeToFile.writelines(str(msg) + " [404]")
writeToFile.close() writeToFile.close()
@@ -294,8 +294,7 @@ def main():
args = parser.parse_args() args = parser.parse_args()
if args.function == "installCSF": if args.function == "installCSF":
controller = CSF(args.function, {}) CSF.installCSF()
controller.run()
elif args.function == 'removeCSF': elif args.function == 'removeCSF':
controller = CSF(args.function, {}) controller = CSF(args.function, {})
controller.run() controller.run()

View File

@@ -12,7 +12,7 @@ class ProcessUtilities(multi.Thread):
centos = 1 centos = 1
ubuntu = 0 ubuntu = 0
server_address = '/usr/local/lscpd/admin/comm.sock' server_address = '/usr/local/lscpd/admin/comm.sock'
token = "2dboNyhseD7ro8rRUsJGy9AlLxJtSjHI" token = "unset"
def __init__(self, function, extraArgs): def __init__(self, function, extraArgs):
multi.Thread.__init__(self) multi.Thread.__init__(self)
@@ -99,7 +99,7 @@ class ProcessUtilities(multi.Thread):
def killLiteSpeed(): def killLiteSpeed():
try: try:
command = 'sudo systemctl stop lsws' command = 'sudo systemctl stop lsws'
ProcessUtilities.executioner(command) ProcessUtilities.normalExecutioner(command)
except: except:
pass pass
@@ -108,7 +108,7 @@ class ProcessUtilities(multi.Thread):
for items in pids: for items in pids:
try: try:
command = 'sudo kill -9 ' + str(items) command = 'sudo kill -9 ' + str(items)
ProcessUtilities.executioner(command) ProcessUtilities.normalExecutioner(command)
except: except:
pass pass
@@ -155,15 +155,20 @@ class ProcessUtilities(multi.Thread):
@staticmethod @staticmethod
def sendCommand(command): def sendCommand(command):
try: try:
logging.writeToFile(command)
ret = ProcessUtilities.setupUDSConnection() ret = ProcessUtilities.setupUDSConnection()
if ret[0] == -1: if ret[0] == -1:
return ret[0] 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 = ret[0]
sock.sendall(token + command)
sock.sendall(ProcessUtilities.token + command)
data = "" data = ""
while (1): while (1):
@@ -178,14 +183,21 @@ class ProcessUtilities(multi.Thread):
logging.writeToFile(str(msg) + " [sendCommand]") logging.writeToFile(str(msg) + " [sendCommand]")
return "0" + str(msg) return "0" + str(msg)
@staticmethod @staticmethod
def executioner(command): def executioner(command):
try: try:
logging.writeToFile(command)
ret = ProcessUtilities.sendCommand(command) ret = ProcessUtilities.sendCommand(command)
return 1 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: except BaseException, msg:
logging.writeToFile(str(msg) + " [executioner]") logging.writeToFile(str(msg) + " [executioner]")
return 0 return 0
@@ -194,12 +206,11 @@ class ProcessUtilities(multi.Thread):
def outputExecutioner(command): def outputExecutioner(command):
try: try:
if type(command) == str or type(command) == unicode: if type(command) == str or type(command) == unicode:
logging.writeToFile(command) pass
else: else:
command = " ".join(command) command = " ".join(command)
logging.writeToFile(command)
return ProcessUtilities.sendCommand(command) return ProcessUtilities.sendCommand(command)[:-1]
except BaseException, msg: except BaseException, msg:
logging.writeToFile(str(msg) + "[outputExecutioner:188]") logging.writeToFile(str(msg) + "[outputExecutioner:188]")
@@ -207,10 +218,8 @@ class ProcessUtilities(multi.Thread):
try: try:
if type(self.extraArgs['command']) == str or type(self.extraArgs['command']) == unicode: if type(self.extraArgs['command']) == str or type(self.extraArgs['command']) == unicode:
command = self.extraArgs['command'] command = self.extraArgs['command']
logging.writeToFile(self.extraArgs['command'])
else: else:
command = " ".join(self.extraArgs['command']) command = " ".join(self.extraArgs['command'])
logging.writeToFile(command)
ProcessUtilities.sendCommand(command) ProcessUtilities.sendCommand(command)

View File

@@ -79,13 +79,9 @@ class virtualHostUtilities:
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'This domain exists as Alias. [404]') logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'This domain exists as Alias. [404]')
return 0, "This domain exists as Alias." return 0, "This domain exists as Alias."
if dkimCheck == 1: retValues = mailUtilities.setupDKIM(virtualHostName)
if mailUtilities.checkIfDKIMInstalled() == 0: if retValues[0] == 0:
raise BaseException("OpenDKIM is not installed, install OpenDKIM from DKIM Manager.") raise BaseException(retValues[1])
retValues = mailUtilities.setupDKIM(virtualHostName)
if retValues[0] == 0:
raise BaseException(retValues[1])
retValues = vhost.createDirectoryForVirtualHost(virtualHostName, administratorEmail, retValues = vhost.createDirectoryForVirtualHost(virtualHostName, administratorEmail,
virtualHostUser, phpVersion, openBasedir) virtualHostUser, phpVersion, openBasedir)
@@ -921,13 +917,9 @@ class virtualHostUtilities:
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'DKIM Setup..,30') logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'DKIM Setup..,30')
if dkimCheck == 1: retValues = mailUtilities.setupDKIM(virtualHostName)
if mailUtilities.checkIfDKIMInstalled() == 0: if retValues[0] == 0:
raise BaseException("OpenDKIM is not installed, install OpenDKIM from DKIM Manager.") raise BaseException(retValues[1])
retValues = mailUtilities.setupDKIM(virtualHostName)
if retValues[0] == 0:
raise BaseException(retValues[1])
FNULL = open(os.devnull, 'w') FNULL = open(os.devnull, 'w')

View File

@@ -37,6 +37,8 @@ class ServerStatusUtil:
def installLiteSpeed(licenseKey, statusFile): def installLiteSpeed(licenseKey, statusFile):
try: try:
logging.CyberCPLogFileWriter.writeToFile(os.environ.get('TERM'))
cwd = os.getcwd() cwd = os.getcwd()
try: try:
@@ -61,18 +63,18 @@ class ServerStatusUtil:
if ServerStatusUtil.executioner(command, statusFile) == 0: if ServerStatusUtil.executioner(command, statusFile) == 0:
return 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: if ServerStatusUtil.executioner(command, statusFile) == 0:
return 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.writelines(licenseKey)
writeSerial.close() writeSerial.close()
shutil.copy('/usr/local/CyberCP/serverStatus/litespeed/install.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', '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' command = 'chmod +x install.sh'
if ServerStatusUtil.executioner(command, statusFile) == 0: if ServerStatusUtil.executioner(command, statusFile) == 0:
@@ -98,6 +100,11 @@ class ServerStatusUtil:
except: except:
pass pass
try:
os.rmdir("/usr/local/CyberCP/lsws-5.3.5")
except:
pass
return 1 return 1
except BaseException, msg: except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg)) logging.CyberCPLogFileWriter.writeToFile(str(msg))
@@ -258,6 +265,9 @@ class ServerStatusUtil:
@staticmethod @staticmethod
def switchTOLSWS(licenseKey): def switchTOLSWS(licenseKey):
try: try:
os.environ['TERM'] = "xterm-256color"
statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w') statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')
FNULL = open(os.devnull, 'w') FNULL = open(os.devnull, 'w')