mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-15 17:56:12 +01:00
Do add for ip4 and ip4 by port
This commit is contained in:
@@ -14,13 +14,15 @@ class FirewallUtilities:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def addRule(proto,port,ipAddress):
|
def addRule(proto,port,ipAddress):
|
||||||
try:
|
try:
|
||||||
|
if ipAddress != '':
|
||||||
|
ruleFamily = 'rule family="ipv4"'
|
||||||
|
sourceAddress = 'source address="' + ipAddress + '"'
|
||||||
|
ruleProtocol = 'port protocol="' + proto + '"'
|
||||||
|
rulePort = 'port="' + port + '"'
|
||||||
|
|
||||||
ruleFamily = 'rule family="ipv4"'
|
command = "sudo firewall-cmd --permanent --zone=public --add-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'"
|
||||||
sourceAddress = 'source address="' + ipAddress + '"'
|
else:
|
||||||
ruleProtocol = 'port protocol="' + proto + '"'
|
command = "sudo firewall-cmd --permanent --zone=public --add-port=" + port + '/' + proto
|
||||||
rulePort = 'port="' + port + '"'
|
|
||||||
|
|
||||||
command = "sudo firewall-cmd --permanent --zone=public --add-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'"
|
|
||||||
|
|
||||||
cmd = shlex.split(command)
|
cmd = shlex.split(command)
|
||||||
|
|
||||||
@@ -42,14 +44,17 @@ class FirewallUtilities:
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def deleteRule(proto, port,ipAddress):
|
def deleteRule(proto, port, ipAddress):
|
||||||
try:
|
try:
|
||||||
ruleFamily = 'rule family="ipv4"'
|
if ipAddress != '':
|
||||||
sourceAddress = 'source address="' + ipAddress + '"'
|
ruleFamily = 'rule family="ipv4"'
|
||||||
ruleProtocol = 'port protocol="' + proto + '"'
|
sourceAddress = 'source address="' + ipAddress + '"'
|
||||||
rulePort = 'port="' + port + '"'
|
ruleProtocol = 'port protocol="' + proto + '"'
|
||||||
|
rulePort = 'port="' + port + '"'
|
||||||
|
|
||||||
command = "sudo firewall-cmd --permanent --zone=public --remove-rich-rule='" + ruleFamily + " " + sourceAddress + " " + ruleProtocol + " " + rulePort + " " + "accept'"
|
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)
|
cmd = shlex.split(command)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user