Add centralized constants module and .env configuration support
This commit is contained in:
1 parent
94be1da199
commit
eea5ef6885
14 files changed
+334
-126
No files matched your search
+4
-3
@@ -9,6 +9,7 @@ from typing import Iterable
|
||||
|
||||
from .ip_utils import is_ipv4, is_ipv6, is_whitelisted, parse_ip
|
||||
from .whitelists import WHITELISTS
|
||||
from .constants import BLOCKLIST_NAME
|
||||
|
||||
|
||||
def split_cidr_versions(targets: Iterable[str]) -> tuple[list[str], list[str]]:
|
||||
@@ -76,12 +77,12 @@ def mikrotik_script(tag: str, blocked_ips_or_subnets: Iterable[str],
|
||||
if block_v4:
|
||||
lines.append(f"# Blocked IPv4 ({len(block_v4)}, non-whitelisted)")
|
||||
lines.append("/ip firewall address-list")
|
||||
lines += [f"add list=Blocked address={t}" for t in block_v4]
|
||||
lines += [f"add list={BLOCKLIST_NAME} address={t}" for t in block_v4]
|
||||
lines.append("")
|
||||
if block_v6:
|
||||
lines.append(f"# Blocked IPv6 ({len(block_v6)}, non-whitelisted)")
|
||||
lines.append("/ipv6 firewall address-list")
|
||||
lines += [f"add list=Blocked address={t}" for t in block_v6]
|
||||
lines += [f"add list={BLOCKLIST_NAME} address={t}" for t in block_v6]
|
||||
lines.append("")
|
||||
|
||||
for version, cmd, blocks in ((4, "/ip firewall filter", block_v4),
|
||||
@@ -94,7 +95,7 @@ def mikrotik_script(tag: str, blocked_ips_or_subnets: Iterable[str],
|
||||
if blocks:
|
||||
for chain in ("input", "forward"):
|
||||
lines.append(
|
||||
f"add chain={chain} action=drop src-address-list=Blocked "
|
||||
f"add chain={chain} action=drop src-address-list={BLOCKLIST_NAME} "
|
||||
f'comment="{tag} blocked (v{version})"')
|
||||
lines.append("")
|
||||
|
||||
|
||||
Reference in new issue
Block a user