further refoctor default render firewall

This commit is contained in:
Usman Nasir
2021-03-06 11:05:19 +05:00
parent c0bbf5fc2e
commit 3aeab72d91

View File

@@ -466,37 +466,26 @@ class FirewallManager:
return HttpResponse(final_json) return HttpResponse(final_json)
def loadModSecurityHome(self, request = None, userID = None): def loadModSecurityHome(self, request = None, userID = None):
try: if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
currentACL = ACLManager.loadedACL(userID) OLS = 1
confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
if currentACL['admin'] == 1: command = "sudo cat " + confPath
pass httpdConfig = ProcessUtilities.outputExecutioner(command).splitlines()
else:
return ACLManager.loadError()
if ProcessUtilities.decideServer() == ProcessUtilities.OLS: modSecInstalled = 0
OLS = 1
confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
command = "sudo cat " + confPath for items in httpdConfig:
httpdConfig = ProcessUtilities.outputExecutioner(command).splitlines() if items.find('module mod_security') > -1:
modSecInstalled = 1
break
else:
OLS = 0
modSecInstalled = 1
modSecInstalled = 0 proc = httpProc(request, 'firewall/modSecurity.html',
{'modSecInstalled': modSecInstalled, 'OLS': OLS}, 'admin')
for items in httpdConfig: return proc.render()
if items.find('module mod_security') > -1:
modSecInstalled = 1
break
else:
OLS = 0
modSecInstalled = 1
proc = httpProc(request, 'firewall/modSecurity.html',
{'modSecInstalled': modSecInstalled, 'OLS': OLS}, 'admin')
return proc.render()
except BaseException as msg:
return HttpResponse(str(msg))
def installModSec(self, userID = None, data = None): def installModSec(self, userID = None, data = None):
try: try:
@@ -852,35 +841,24 @@ class FirewallManager:
return HttpResponse(json_data) return HttpResponse(json_data)
def modSecRules(self, request = None, userID = None): def modSecRules(self, request = None, userID = None):
try: if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
currentACL = ACLManager.loadedACL(userID) command = "sudo cat " + confPath
httpdConfig = ProcessUtilities.outputExecutioner(command).split('\n')
if currentACL['admin'] == 1: modSecInstalled = 0
pass
else:
return ACLManager.loadError()
if ProcessUtilities.decideServer() == ProcessUtilities.OLS: for items in httpdConfig:
confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") if items.find('module mod_security') > -1:
modSecInstalled = 1
break
else:
modSecInstalled = 1
command = "sudo cat " + confPath proc = httpProc(request, 'firewall/modSecurityRules.html',
httpdConfig = ProcessUtilities.outputExecutioner(command).split('\n') {'modSecInstalled': modSecInstalled}, 'admin')
return proc.render()
modSecInstalled = 0
for items in httpdConfig:
if items.find('module mod_security') > -1:
modSecInstalled = 1
break
else:
modSecInstalled = 1
proc = httpProc(request, 'firewall/modSecurityRules.html',
{'modSecInstalled': modSecInstalled}, 'admin')
return proc.render()
except BaseException as msg:
return HttpResponse(str(msg))
def fetchModSecRules(self, userID = None, data = None): def fetchModSecRules(self, userID = None, data = None):
try: try:
@@ -977,37 +955,25 @@ class FirewallManager:
return HttpResponse(json_data) return HttpResponse(json_data)
def modSecRulesPacks(self, request = None, userID = None): def modSecRulesPacks(self, request = None, userID = None):
try: if ProcessUtilities.decideServer() == ProcessUtilities.OLS:
currentACL = ACLManager.loadedACL(userID) confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf")
if currentACL['admin'] == 1: command = "sudo cat " + confPath
pass httpdConfig = ProcessUtilities.outputExecutioner(command).split('\n')
else:
return ACLManager.loadError()
if ProcessUtilities.decideServer() == ProcessUtilities.OLS: modSecInstalled = 0
confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") for items in httpdConfig:
if items.find('module mod_security') > -1:
modSecInstalled = 1
break
else:
modSecInstalled = 1
command = "sudo cat " + confPath proc = httpProc(request, 'firewall/modSecurityRulesPacks.html',
httpdConfig = ProcessUtilities.outputExecutioner(command).split('\n') {'modSecInstalled': modSecInstalled}, 'admin')
return proc.render()
modSecInstalled = 0
for items in httpdConfig:
if items.find('module mod_security') > -1:
modSecInstalled = 1
break
else:
modSecInstalled = 1
proc = httpProc(request, 'firewall/modSecurityRulesPacks.html',
{'modSecInstalled': modSecInstalled}, 'admin')
return proc.render()
except BaseException as msg:
return HttpResponse(msg)
def getOWASPAndComodoStatus(self, userID = None, data = None): def getOWASPAndComodoStatus(self, userID = None, data = None):
try: try:
@@ -1284,30 +1250,18 @@ class FirewallManager:
return HttpResponse(json_data) return HttpResponse(json_data)
def csf(self): def csf(self):
csfInstalled = 1
try: try:
userID = self.request.session['userID'] command = 'csf -h'
currentACL = ACLManager.loadedACL(userID) output = ProcessUtilities.outputExecutioner(command)
if output.find("command not found") > -1:
if currentACL['admin'] == 1:
pass
else:
return ACLManager.loadError()
csfInstalled = 1
try:
command = 'csf -h'
output = ProcessUtilities.outputExecutioner(command)
if output.find("command not found") > -1:
csfInstalled = 0
except subprocess.CalledProcessError:
csfInstalled = 0 csfInstalled = 0
except subprocess.CalledProcessError:
csfInstalled = 0
proc = httpProc(self.request, 'firewall/csf.html', proc = httpProc(self.request, 'firewall/csf.html',
{'csfInstalled' : csfInstalled}, 'admin') {'csfInstalled': csfInstalled}, 'admin')
return proc.render() return proc.render()
except BaseException as msg:
return HttpResponse(str(msg))
def installCSF(self): def installCSF(self):
try: try:
@@ -1537,48 +1491,35 @@ class FirewallManager:
return HttpResponse(final_json) return HttpResponse(final_json)
def imunify(self): def imunify(self):
try: ipFile = "/etc/cyberpanel/machineIP"
userID = self.request.session['userID'] f = open(ipFile)
currentACL = ACLManager.loadedACL(userID) ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
if currentACL['admin'] == 1: fullAddress = '%s:%s' % (ipAddress, ProcessUtilities.fetchCurrentPort())
pass
else:
return ACLManager.loadError()
ipFile = "/etc/cyberpanel/machineIP" data = {}
f = open(ipFile) data['ipAddress'] = fullAddress
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
fullAddress = '%s:%s' % (ipAddress, ProcessUtilities.fetchCurrentPort()) data['CL'] = 1
data = {} if os.path.exists(FirewallManager.imunifyPath):
data['ipAddress'] = fullAddress data['imunify'] = 1
else:
data['imunify'] = 0
data['CL'] = 1 if data['CL'] == 0:
proc = httpProc(self.request, 'firewall/notAvailable.html',
if os.path.exists(FirewallManager.imunifyPath): data, 'admin')
data['imunify'] = 1 return proc.render()
else: elif data['imunify'] == 0:
data['imunify'] = 0 proc = httpProc(self.request, 'firewall/notAvailable.html',
data, 'admin')
if data['CL'] == 0: return proc.render()
proc = httpProc(self.request, 'firewall/notAvailable.html', else:
data, 'admin') proc = httpProc(self.request, 'firewall/imunify.html',
return proc.render() data, 'admin')
elif data['imunify'] == 0: return proc.render()
proc = httpProc(self.request, 'firewall/notAvailable.html',
data, 'admin')
return proc.render()
else:
proc = httpProc(self.request, 'firewall/imunify.html',
data, 'admin')
return proc.render()
except BaseException as msg:
return HttpResponse(str(msg))
def submitinstallImunify(self): def submitinstallImunify(self):
try: try:
@@ -1607,45 +1548,29 @@ class FirewallManager:
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1) logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
def imunifyAV(self): def imunifyAV(self):
try: ipFile = "/etc/cyberpanel/machineIP"
userID = self.request.session['userID'] f = open(ipFile)
currentACL = ACLManager.loadedACL(userID) ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
if currentACL['admin'] == 1: fullAddress = '%s:%s' % (ipAddress, ProcessUtilities.fetchCurrentPort())
pass
else:
return ACLManager.loadError()
ipFile = "/etc/cyberpanel/machineIP" data = {}
f = open(ipFile) data['ipAddress'] = fullAddress
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
fullAddress = '%s:%s' % (ipAddress, ProcessUtilities.fetchCurrentPort()) if os.path.exists(FirewallManager.imunifyAVPath):
data['imunify'] = 1
else:
data['imunify'] = 0
data = {} if data['imunify'] == 0:
data['ipAddress'] = fullAddress proc = httpProc(self.request, 'firewall/notAvailableAV.html',
data, 'admin')
return proc.render()
else:
if os.path.exists(FirewallManager.imunifyAVPath): proc = httpProc(self.request, 'firewall/imunifyAV.html',
data['imunify'] = 1 data, 'admin')
else: return proc.render()
data['imunify'] = 0
if data['imunify'] == 0:
proc = httpProc(self.request, 'firewall/notAvailableAV.html',
data, 'admin')
return proc.render()
else:
proc = httpProc(self.request, 'firewall/imunifyAV.html',
data, 'admin')
return proc.render()
except BaseException as msg:
return HttpResponse(str(msg))
def submitinstallImunifyAV(self): def submitinstallImunifyAV(self):
try: try: