linted code
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,10 +1,11 @@
|
|||||||
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.
|
||||||
|
|
||||||
@@ -29,11 +30,7 @@ class Iptables(FWType):
|
|||||||
ip = ip.strip()
|
ip = ip.strip()
|
||||||
|
|
||||||
# Build the iptables command
|
# Build the iptables command
|
||||||
rule_parts = [
|
rule_parts = ["iptables", "-A", chain, "-s", ip]
|
||||||
"iptables",
|
|
||||||
"-A", chain,
|
|
||||||
"-s", ip
|
|
||||||
]
|
|
||||||
|
|
||||||
# Add target
|
# Add target
|
||||||
rule_parts.extend(["-j", target])
|
rule_parts.extend(["-j", target])
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,6 @@ import os
|
|||||||
|
|
||||||
from database import get_database
|
from database import get_database
|
||||||
from config import Config, get_config
|
from config import Config, get_config
|
||||||
from firewall.fwtype import FWType
|
|
||||||
|
|
||||||
# imports for the __init_subclass__ method, do not remove pls
|
|
||||||
from firewall.iptables import Iptables
|
|
||||||
from firewall.raw import Raw
|
|
||||||
|
|
||||||
|
|
||||||
from database import get_database
|
from database import get_database
|
||||||
from config import Config,get_config
|
from config import Config,get_config
|
||||||
@@ -947,19 +941,12 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
# API endpoint for downloading malicious IPs blocklist file
|
# API endpoint for downloading malicious IPs blocklist file
|
||||||
if (
|
if (
|
||||||
self.config.dashboard_secret_path
|
|
||||||
and request_path == f"{self.config.dashboard_secret_path}/api/get_banlist"
|
|
||||||
):
|
|
||||||
|
|
||||||
# get fwtype from request params
|
|
||||||
fwtype = query_params.get("fwtype", ["iptables"])[0]
|
|
||||||
|
|
||||||
self.config.dashboard_secret_path and
|
self.config.dashboard_secret_path and
|
||||||
request_path == f"{self.config.dashboard_secret_path}/api/get_banlist"
|
request_path == f"{self.config.dashboard_secret_path}/api/get_banlist"
|
||||||
):
|
):
|
||||||
|
|
||||||
# get fwtype from request params
|
# get fwtype from request params
|
||||||
fwtype = query_params.get("fwtype",["iptables"])[0]
|
fwtype = query_params.get("fwtype", ["iptables"])[0]
|
||||||
|
|
||||||
# Query distinct suspicious IPs
|
# Query distinct suspicious IPs
|
||||||
results = (
|
results = (
|
||||||
@@ -979,7 +966,10 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header("Content-type", "text/plain")
|
self.send_header("Content-type", "text/plain")
|
||||||
self.send_header("Content-Disposition", f'attachment; filename="{fwtype}.txt"',)
|
self.send_header(
|
||||||
|
"Content-Disposition",
|
||||||
|
f'attachment; filename="{fwtype}.txt"',
|
||||||
|
)
|
||||||
self.send_header("Content-Length", str(len(banlist)))
|
self.send_header("Content-Length", str(len(banlist)))
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(banlist.encode())
|
self.wfile.write(banlist.encode())
|
||||||
|
|||||||
Reference in New Issue
Block a user