Firewall rules (intermediate version)

This commit is contained in:
rperper
2018-11-14 12:39:42 -05:00
parent 54c423c311
commit 457bd42dcb

View File

@@ -14,19 +14,21 @@ class FirewallUtilities:
@staticmethod
def addRule(proto,port):
try:
if port == "21":
command = "sudo firewall-cmd --add-service=ftp --permanent"
cmd = shlex.split(command)
res = subprocess.call(cmd)
command = 'sudo firewall-cmd --permanent --zone-public --add-port=' + port + '/' + proto
ipAddress = "0.0.0.0/0"
#if port == "21":
# command = "sudo firewall-cmd --add-service=ftp --permanent"
# cmd = shlex.split(command)
# res = subprocess.call(cmd)
ruleFamily = 'rule family="ipv4"'
sourceAddress = 'source address="' + ipAddress + '"'
ruleProtocol = 'port protocol="' + proto + '"'
rulePort = 'port="' + port + '"'
#ipAddress = "0.0.0.0/0"
command = "sudo firewall-cmd --permanent --zone=public --add-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'"
#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'"
cmd = shlex.split(command)
@@ -50,19 +52,21 @@ class FirewallUtilities:
@staticmethod
def deleteRule(proto, port):
try:
if port=="21":
command = "sudo firewall-cmd --remove-service=ftp --permanent"
cmd = shlex.split(command)
res = subprocess.call(cmd)
command = 'sudo firewall-cmd --permanent --zone-public --remove-port=' + port + '/' + proto
ipAddress = "0.0.0.0/0"
#if port=="21":
# command = "sudo firewall-cmd --remove-service=ftp --permanent"
# cmd = shlex.split(command)
# res = subprocess.call(cmd)
ruleFamily = 'rule family="ipv4"'
sourceAddress = 'source address="' + ipAddress + '"'
ruleProtocol = 'port protocol="' + proto + '"'
rulePort = 'port="' + port + '"'
#ipAddress = "0.0.0.0/0"
command = "sudo firewall-cmd --permanent --zone=public --remove-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'"
#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'"
cmd = shlex.split(command)