changed workflow from live computation to scheduled job to support previous structure
This commit is contained in:
@@ -4,8 +4,12 @@ import os
|
||||
from logger import get_app_logger
|
||||
from database import get_database
|
||||
from config import get_config
|
||||
from models import IpStats
|
||||
from models import IpStats, AccessLog
|
||||
from ip_utils import is_valid_public_ip
|
||||
from sqlalchemy import distinct
|
||||
from firewall.fwtype import FWType
|
||||
from firewall.iptables import Iptables
|
||||
from firewall.raw import Raw
|
||||
|
||||
app_logger = get_app_logger()
|
||||
|
||||
@@ -61,14 +65,20 @@ def main():
|
||||
os.makedirs(EXPORTS_DIR, exist_ok=True)
|
||||
|
||||
# Write IPs to file (one per line)
|
||||
with open(OUTPUT_FILE, "w") as f:
|
||||
for ip in public_ips:
|
||||
f.write(f"{ip}\n")
|
||||
for fwname in FWType._registry:
|
||||
|
||||
app_logger.info(
|
||||
f"[Background Task] {task_name} exported {len(public_ips)} attacker IPs "
|
||||
f"(filtered {len(attackers) - len(public_ips)} local/private IPs) to {OUTPUT_FILE}"
|
||||
)
|
||||
# get banlist for specific ip
|
||||
fw = FWType.create(fwname)
|
||||
banlist = fw.getBanlist(public_ips)
|
||||
|
||||
output_file = os.path.join(EXPORTS_DIR, f"{fwname}.txt")
|
||||
with open(output_file, "w") as f:
|
||||
f.write(f"{banlist}\n")
|
||||
|
||||
app_logger.info(
|
||||
f"[Background Task] {task_name} exported {len(public_ips)} in {fwname} public IPs"
|
||||
f"(filtered {len(attackers) - len(public_ips)} local/private IPs) to {output_file}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
app_logger.error(f"[Background Task] {task_name} failed: {e}")
|
||||
|
||||
Reference in New Issue
Block a user