Do add for ip4 and ip4 by port

This commit is contained in:
rperper
2018-11-14 12:17:24 -05:00
parent 41211c3d87
commit 54c423c311

View File

@@ -14,13 +14,15 @@ 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 + '"'
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
cmd = shlex.split(command)
@@ -44,12 +46,15 @@ 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 + '"'
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
cmd = shlex.split(command)