@@ -378,21 +378,29 @@ def saveSSHConfigs(self, userID = None, data = None):
378
378
379
379
if output .find ("1,None" ) > - 1 :
380
380
381
- try :
382
- updateFW = FirewallRules .objects .get (name = "SSHCustom" )
383
- FirewallUtilities .deleteRule ("tcp" , updateFW .port , "0.0.0.0/0" )
384
- updateFW .port = sshPort
385
- updateFW .save ()
386
- FirewallUtilities .addRule ('tcp' , sshPort , "0.0.0.0/0" )
387
- except :
381
+ csfPath = '/etc/csf'
382
+
383
+ if os .path .exists (csfPath ):
384
+ dataIn = {'protocol' : 'TCP_IN' , 'ports' : sshPort }
385
+ self .modifyPorts (dataIn )
386
+ dataIn = {'protocol' : 'TCP_OUT' , 'ports' : sshPort }
387
+ self .modifyPorts (dataIn )
388
+ else :
388
389
try :
389
- newFireWallRule = FirewallRules (name = "SSHCustom" , port = sshPort , proto = "tcp" )
390
- newFireWallRule .save ()
390
+ updateFW = FirewallRules .objects .get (name = "SSHCustom" )
391
+ FirewallUtilities .deleteRule ("tcp" , updateFW .port , "0.0.0.0/0" )
392
+ updateFW .port = sshPort
393
+ updateFW .save ()
391
394
FirewallUtilities .addRule ('tcp' , sshPort , "0.0.0.0/0" )
392
- command = 'firewall-cmd --permanent --remove-service=ssh'
393
- ProcessUtilities .executioner (command )
394
- except BaseException , msg :
395
- logging .CyberCPLogFileWriter .writeToFile (str (msg ))
395
+ except :
396
+ try :
397
+ newFireWallRule = FirewallRules (name = "SSHCustom" , port = sshPort , proto = "tcp" )
398
+ newFireWallRule .save ()
399
+ FirewallUtilities .addRule ('tcp' , sshPort , "0.0.0.0/0" )
400
+ command = 'firewall-cmd --permanent --remove-service=ssh'
401
+ ProcessUtilities .executioner (command )
402
+ except BaseException , msg :
403
+ logging .CyberCPLogFileWriter .writeToFile (str (msg ))
396
404
397
405
final_dic = {'status' : 1 , 'saveStatus' : 1 }
398
406
final_json = json .dumps (final_dic )
@@ -1463,7 +1471,7 @@ def changeStatus(self):
1463
1471
final_json = json .dumps (final_dic )
1464
1472
return HttpResponse (final_json )
1465
1473
1466
- def modifyPorts (self ):
1474
+ def modifyPorts (self , data = None ):
1467
1475
try :
1468
1476
1469
1477
userID = self .request .session ['userID' ]
@@ -1474,8 +1482,6 @@ def modifyPorts(self):
1474
1482
else :
1475
1483
return ACLManager .loadErrorJson ()
1476
1484
1477
- data = json .loads (self .request .body )
1478
-
1479
1485
protocol = data ['protocol' ]
1480
1486
ports = data ['ports' ]
1481
1487
0 commit comments