mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 08:16:11 +01:00
bug fix: add custom ssh port to csf
This commit is contained in:
@@ -378,6 +378,14 @@ class FirewallManager:
|
|||||||
|
|
||||||
if output.find("1,None") > -1:
|
if output.find("1,None") > -1:
|
||||||
|
|
||||||
|
csfPath = '/etc/csf'
|
||||||
|
|
||||||
|
if os.path.exists(csfPath):
|
||||||
|
dataIn = {'protocol': 'TCP_IN', 'ports': sshPort}
|
||||||
|
self.modifyPorts(dataIn)
|
||||||
|
dataIn = {'protocol': 'TCP_OUT', 'ports': sshPort}
|
||||||
|
self.modifyPorts(dataIn)
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
updateFW = FirewallRules.objects.get(name="SSHCustom")
|
updateFW = FirewallRules.objects.get(name="SSHCustom")
|
||||||
FirewallUtilities.deleteRule("tcp", updateFW.port, "0.0.0.0/0")
|
FirewallUtilities.deleteRule("tcp", updateFW.port, "0.0.0.0/0")
|
||||||
@@ -1463,7 +1471,7 @@ class FirewallManager:
|
|||||||
final_json = json.dumps(final_dic)
|
final_json = json.dumps(final_dic)
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
def modifyPorts(self):
|
def modifyPorts(self, data = None):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
userID = self.request.session['userID']
|
userID = self.request.session['userID']
|
||||||
@@ -1474,8 +1482,6 @@ class FirewallManager:
|
|||||||
else:
|
else:
|
||||||
return ACLManager.loadErrorJson()
|
return ACLManager.loadErrorJson()
|
||||||
|
|
||||||
data = json.loads(self.request.body)
|
|
||||||
|
|
||||||
protocol = data['protocol']
|
protocol = data['protocol']
|
||||||
ports = data['ports']
|
ports = data['ports']
|
||||||
|
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ def saveSSHConfigs(request):
|
|||||||
if result != 200:
|
if result != 200:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
fm = FirewallManager()
|
fm = FirewallManager(request)
|
||||||
coreResult = fm.saveSSHConfigs(userID, json.loads(request.body))
|
coreResult = fm.saveSSHConfigs(userID, json.loads(request.body))
|
||||||
|
|
||||||
result = pluginManager.postSaveSSHConfigs(request, coreResult)
|
result = pluginManager.postSaveSSHConfigs(request, coreResult)
|
||||||
@@ -520,7 +520,7 @@ def modifyPorts(request):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
fm = FirewallManager(request)
|
fm = FirewallManager(request)
|
||||||
coreResult = fm.modifyPorts()
|
coreResult = fm.modifyPorts(json.loads(request.body))
|
||||||
|
|
||||||
result = pluginManager.postModifyPorts(request, coreResult)
|
result = pluginManager.postModifyPorts(request, coreResult)
|
||||||
if result != 200:
|
if result != 200:
|
||||||
|
|||||||
@@ -486,14 +486,22 @@ class CSF(multi.Thread):
|
|||||||
if protocol == 'TCP_IN':
|
if protocol == 'TCP_IN':
|
||||||
for items in data:
|
for items in data:
|
||||||
if items.find('TCP_IN') > -1 and items.find('=') > -1 and (items[0] != '#'):
|
if items.find('TCP_IN') > -1 and items.find('=') > -1 and (items[0] != '#'):
|
||||||
|
if ports.find(',') > -1:
|
||||||
writeToFile.writelines('TCP_IN = "' + ports + '"\n')
|
writeToFile.writelines('TCP_IN = "' + ports + '"\n')
|
||||||
|
else:
|
||||||
|
content = '%s,%s\n' % (items, ports)
|
||||||
|
writeToFile.writelines(content)
|
||||||
else:
|
else:
|
||||||
writeToFile.writelines(items)
|
writeToFile.writelines(items)
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
elif protocol == 'TCP_OUT':
|
elif protocol == 'TCP_OUT':
|
||||||
for items in data:
|
for items in data:
|
||||||
if items.find('TCP_OUT') > -1 and items.find('=') > -1 and (items[0] != '#'):
|
if items.find('TCP_OUT') > -1 and items.find('=') > -1 and (items[0] != '#'):
|
||||||
|
if ports.find(',') > -1:
|
||||||
writeToFile.writelines('TCP_OUT = "' + ports + '"\n')
|
writeToFile.writelines('TCP_OUT = "' + ports + '"\n')
|
||||||
|
else:
|
||||||
|
content = '%s,%s\n' % (items, ports)
|
||||||
|
writeToFile.writelines(content)
|
||||||
else:
|
else:
|
||||||
writeToFile.writelines(items)
|
writeToFile.writelines(items)
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user