mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 00:06:09 +01:00
Firewall rules (intermediate version)
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user