Skip to content

Commit

Permalink
centralized execution ph5
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Apr 1, 2019
1 parent e12b412 commit 04e0790
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 81 deletions.
18 changes: 9 additions & 9 deletions firewall/firewallManager.py
Expand Up @@ -253,7 +253,7 @@ def firewallStatus(self, userID = None, data = None):
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)

Expand Down Expand Up @@ -511,14 +511,13 @@ def installModSec(self, userID = None, data = None):
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)

Expand All @@ -539,7 +538,7 @@ def installStatusModSec(self, userID = None, data = None):

execPath = execPath + " installModSecConfigs"

output = subprocess.check_output(shlex.split(execPath))
output = ProcessUtilities.outputExecutioner(execPath)

if output.find("1,None") > -1:
pass
Expand Down Expand Up @@ -964,7 +963,7 @@ def saveModSecRules(self, userID = None, data = None):

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"}
Expand Down Expand Up @@ -1295,8 +1294,8 @@ def csf(self):
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
Expand All @@ -1316,6 +1315,7 @@ def installCSF(self):

execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py"
execPath = execPath + " installCSF"

ProcessUtilities.popenExecutioner(execPath)

time.sleep(2)
Expand All @@ -1334,7 +1334,7 @@ def installStatusCSF(self):
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:

Expand Down
2 changes: 1 addition & 1 deletion firewall/urls.py
Expand Up @@ -42,7 +42,7 @@
## 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'),
Expand Down
12 changes: 3 additions & 9 deletions mailServer/mailserverManager.py
Expand Up @@ -362,18 +362,12 @@ def dkimManager(self):
if ACLManager.currentContextPermission(currentACL, 'dkimManager') == 0:
return ACLManager.loadError()

openDKIMInstalled = 0
openDKIMInstalled = 1

if mailUtilities.checkIfDKIMInstalled() == 1:
openDKIMInstalled = 1

websitesName = ACLManager.findAllSites(currentACL, userID)

return render(self.request, 'mailServer/dkimManager.html',
{'websiteList': websitesName, 'openDKIMInstalled': openDKIMInstalled})
websitesName = ACLManager.findAllSites(currentACL, userID)

return render(self.request, 'mailServer/dkimManager.html',
{'openDKIMInstalled': openDKIMInstalled})
{'websiteList': websitesName, 'openDKIMInstalled': openDKIMInstalled})

except BaseException, msg:
return HttpResponse(str(msg))
Expand Down
4 changes: 2 additions & 2 deletions plogical/applicationInstaller.py
Expand Up @@ -158,9 +158,9 @@ def installWordPress(self):

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()
Expand Down
55 changes: 27 additions & 28 deletions plogical/csf.py
Expand Up @@ -29,35 +29,35 @@ def run(self):
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)

##

command = 'tar -xzf csf.tgz'
cmd = shlex.split(command)
logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'Extracting CSF..\n', 1)

with open(CSF.installLogPath, 'a') as f:
res = subprocess.call(cmd, stdout=f)
command = 'tar -xzf csf.tgz'
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

Expand All @@ -80,23 +80,23 @@ def installCSF(self):
##

command = 'csf -s'
cmd = shlex.split(command)

with open(CSF.installLogPath, 'a') as f:
subprocess.call(cmd, stdout=f)
ProcessUtilities.normalExecutioner(command)

logging.CyberCPLogFileWriter.statusWriter(CSF.installLogPath, 'CSF successfully Installed.[200]\n', 1)

writeToFile = open(CSF.installLogPath, 'a')
writeToFile.writelines("CSF successfully Installed.[200]\n")
writeToFile.close()

os.remove('csf.tgz')
os.removedirs('csf')
try:
os.remove('csf.tgz')
os.removedirs('csf')
except:
pass

return 1
except BaseException, msg:
os.remove('csf.tgz')
os.removedirs('csf')
try:
os.remove('csf.tgz')
os.removedirs('csf')
except:
pass
writeToFile = open(CSF.installLogPath, 'a')
writeToFile.writelines(str(msg) + " [404]")
writeToFile.close()
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 22 additions & 13 deletions plogical/processUtilities.py
Expand Up @@ -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)
Expand Down Expand Up @@ -99,7 +99,7 @@ def normalExecutioner(command):
def killLiteSpeed():
try:
command = 'sudo systemctl stop lsws'
ProcessUtilities.executioner(command)
ProcessUtilities.normalExecutioner(command)
except:
pass

Expand All @@ -108,7 +108,7 @@ def killLiteSpeed():
for items in pids:
try:
command = 'sudo kill -9 ' + str(items)
ProcessUtilities.executioner(command)
ProcessUtilities.normalExecutioner(command)
except:
pass

Expand Down Expand Up @@ -155,15 +155,20 @@ def setupUDSConnection():
@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):
Expand All @@ -178,14 +183,21 @@ def sendCommand(command):
logging.writeToFile(str(msg) + " [sendCommand]")
return "0" + str(msg)


@staticmethod
def executioner(command):
try:
logging.writeToFile(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:
logging.writeToFile(str(msg) + " [executioner]")
return 0
Expand All @@ -194,23 +206,20 @@ def executioner(command):
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]")

def customPoen(self):
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)

Expand Down
20 changes: 6 additions & 14 deletions plogical/virtualHostUtilities.py
Expand Up @@ -79,13 +79,9 @@ def createVirtualHost(virtualHostName, administratorEmail, phpVersion, virtualHo
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])
retValues = mailUtilities.setupDKIM(virtualHostName)
if retValues[0] == 0:
raise BaseException(retValues[1])

retValues = vhost.createDirectoryForVirtualHost(virtualHostName, administratorEmail,
virtualHostUser, phpVersion, openBasedir)
Expand Down Expand Up @@ -921,13 +917,9 @@ def createDomain(masterDomain, virtualHostName, phpVersion, path, ssl, dkimCheck

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])
retValues = mailUtilities.setupDKIM(virtualHostName)
if retValues[0] == 0:
raise BaseException(retValues[1])

FNULL = open(os.devnull, 'w')

Expand Down

0 comments on commit 04e0790

Please sign in to comment.