Skip to content

Commit

Permalink
bug fix to csf
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Aug 3, 2019
1 parent 6e3310d commit 4d4b0c7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CyberCP/secMiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __call__(self, request):

if request.build_absolute_uri().find('docker') > -1 or request.build_absolute_uri().find('cloudAPI') > -1 or request.build_absolute_uri().find('filemanager') > -1 or request.build_absolute_uri().find('verifyLogin') > -1 or request.build_absolute_uri().find('submitUserCreation') > -1:
continue
if key == 'imageByPass' or key == 'passwordByPass' or key == 'cronCommand' or key == 'emailMessage' or key == 'configData' or key == 'rewriteRules' or key == 'modSecRules' or key == 'recordContentTXT' or key == 'SecAuditLogRelevantStatus' or key == 'fileContent':
if key == 'ports' or key == 'imageByPass' or key == 'passwordByPass' or key == 'cronCommand' or key == 'emailMessage' or key == 'configData' or key == 'rewriteRules' or key == 'modSecRules' or key == 'recordContentTXT' or key == 'SecAuditLogRelevantStatus' or key == 'fileContent':
continue
if value.find(';') > -1 or value.find('&&') > -1 or value.find('|') > -1 or value.find('...') > -1 \
or value.find("`") > -1 or value.find("$") > -1 or value.find("(") > -1 or value.find(")") > -1 \
Expand Down
14 changes: 10 additions & 4 deletions firewall/firewallManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
import plogical.CyberCPLogFileWriter as logging
from plogical.virtualHostUtilities import virtualHostUtilities
import subprocess
import shlex
from plogical.installUtilities import installUtilities
from django.shortcuts import HttpResponse, render
from random import randint
import time
from plogical.firewallUtilities import FirewallUtilities
from firewall.models import FirewallRules
import thread
from plogical.modSec import modSec
from plogical.csf import CSF
from plogical.processUtilities import ProcessUtilities
Expand Down Expand Up @@ -1482,8 +1479,17 @@ def modifyPorts(self):
protocol = data['protocol']
ports = data['ports']

portsPath = '/tmp/ports'

if os.path.exists(portsPath):
os.remove(portsPath)

writeToFile = open(portsPath, 'w')
writeToFile.write(ports)
writeToFile.close()

execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py"
execPath = execPath + " modifyPorts --protocol " + protocol + " --ports " + ports
execPath = execPath + " modifyPorts --protocol " + protocol + " --ports " + portsPath
output = ProcessUtilities.outputExecutioner(execPath)

if output.find("1,None") > -1:
Expand Down
10 changes: 9 additions & 1 deletion plogical/csf.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,14 @@ def changeStatus(controller, status):
print '0',str(msg)

@staticmethod
def modifyPorts(protocol, ports):
def modifyPorts(protocol, portsPath):
try:

data = open('/etc/csf/csf.conf', 'r').readlines()
writeToFile = open('/etc/csf/csf.conf', 'w')

ports = open(portsPath, 'r').read()

if protocol == 'TCP_IN':
for items in data:
if items.find('TCP_IN') > -1 and items.find('=') > -1 and (items[0] != '#'):
Expand Down Expand Up @@ -249,6 +252,11 @@ def modifyPorts(protocol, ports):
command = 'csf -r'
subprocess.call(shlex.split(command))

try:
os.remove(portsPath)
except:
pass

print '1,None'

except BaseException, msg:
Expand Down

0 comments on commit 4d4b0c7

Please sign in to comment.