From 6591aae635effad45061ea5a62a65cf38ea01241 Mon Sep 17 00:00:00 2001 From: rperper Date: Wed, 14 Nov 2018 13:45:03 -0500 Subject: [PATCH] Committed all files --- plogical/firewallUtilities.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/plogical/firewallUtilities.py b/plogical/firewallUtilities.py index e9be73541..0ecc88159 100644 --- a/plogical/firewallUtilities.py +++ b/plogical/firewallUtilities.py @@ -14,15 +14,12 @@ class FirewallUtilities: @staticmethod def addRule(proto,port,ipAddress): try: - if ipAddress != '': - ruleFamily = 'rule family="ipv4"' - sourceAddress = 'source address="' + ipAddress + '"' - ruleProtocol = 'port protocol="' + proto + '"' - rulePort = 'port="' + port + '"' + ruleFamily = 'rule family="ipv4"' + sourceAddress = 'source address="' + ipAddress + '"' + ruleProtocol = 'port protocol="' + proto + '"' + rulePort = 'port="' + port + '"' - command = "sudo firewall-cmd --permanent --zone=public --add-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'" - else: - command = "sudo firewall-cmd --permanent --zone=public --add-port=" + port + '/' + proto + command = "sudo firewall-cmd --permanent --zone=public --add-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'" cmd = shlex.split(command) @@ -46,15 +43,12 @@ class FirewallUtilities: @staticmethod def deleteRule(proto, port, ipAddress): try: - if ipAddress != '': - ruleFamily = 'rule family="ipv4"' - sourceAddress = 'source address="' + ipAddress + '"' - ruleProtocol = 'port protocol="' + proto + '"' - rulePort = 'port="' + port + '"' + ruleFamily = 'rule family="ipv4"' + sourceAddress = 'source address="' + ipAddress + '"' + ruleProtocol = 'port protocol="' + proto + '"' + rulePort = 'port="' + port + '"' - command = "sudo firewall-cmd --permanent --zone=public --remove-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'" - else: - command = 'sudo firewall-cmd --permanent --zone-public --remove-port=' + port + '/' + proto + command = "sudo firewall-cmd --permanent --zone=public --remove-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'" cmd = shlex.split(command)