added firewall strategy pattern
This commit is contained in:
@@ -14,7 +14,7 @@ class FWType(ABC):
|
|||||||
cls._registry[cls.__name__.lower()] = cls
|
cls._registry[cls.__name__.lower()] = cls
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, fw_type: str, **kwargs) -> "FWType":
|
def create(cls, fw_type: str, **kwargs) -> 'FWType':
|
||||||
"""
|
"""
|
||||||
Factory method to create instances of child classes.
|
Factory method to create instances of child classes.
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
from firewall.fwtype import FWType
|
from firewall.fwtype import FWType
|
||||||
|
|
||||||
|
|
||||||
class Iptables(FWType):
|
class Iptables(FWType):
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def getBanlist(self, ips) -> str:
|
def getBanlist(self,ips) -> str:
|
||||||
"""
|
"""
|
||||||
Generate iptables ban rules from an array of IP addresses.
|
Generate iptables ban rules from an array of IP addresses.
|
||||||
|
|
||||||
@@ -30,7 +29,11 @@ class Iptables(FWType):
|
|||||||
ip = ip.strip()
|
ip = ip.strip()
|
||||||
|
|
||||||
# Build the iptables command
|
# Build the iptables command
|
||||||
rule_parts = ["iptables", "-A", chain, "-s", ip]
|
rule_parts = [
|
||||||
|
"iptables",
|
||||||
|
"-A", chain,
|
||||||
|
"-s", ip
|
||||||
|
]
|
||||||
|
|
||||||
# Add target
|
# Add target
|
||||||
rule_parts.extend(["-j", target])
|
rule_parts.extend(["-j", target])
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
from firewall.fwtype import FWType
|
from firewall.fwtype import FWType
|
||||||
|
|
||||||
|
|
||||||
class Raw(FWType):
|
class Raw(FWType):
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def getBanlist(self, ips) -> str:
|
def getBanlist(self,ips) -> str:
|
||||||
"""
|
"""
|
||||||
Generate raw list of bad IP addresses.
|
Generate raw list of bad IP addresses.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user