@@ -378,21 +378,29 @@ def saveSSHConfigs(self, userID = None, data = None):
378378
379379 if output .find ("1,None" ) > - 1 :
380380
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 :
388389 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 ()
391394 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 ))
396404
397405 final_dic = {'status' : 1 , 'saveStatus' : 1 }
398406 final_json = json .dumps (final_dic )
@@ -1463,7 +1471,7 @@ def changeStatus(self):
14631471 final_json = json .dumps (final_dic )
14641472 return HttpResponse (final_json )
14651473
1466- def modifyPorts (self ):
1474+ def modifyPorts (self , data = None ):
14671475 try :
14681476
14691477 userID = self .request .session ['userID' ]
@@ -1474,8 +1482,6 @@ def modifyPorts(self):
14741482 else :
14751483 return ACLManager .loadErrorJson ()
14761484
1477- data = json .loads (self .request .body )
1478-
14791485 protocol = data ['protocol' ]
14801486 ports = data ['ports' ]
14811487
0 commit comments