jtl-wafi-agent.py aktualisiert
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
GeoIP Agent v2.0.0 - WebSocket Real-Time Agent
|
||||
JTL-WAFi Agent v2.0.0 - WebSocket Real-Time Agent
|
||||
|
||||
Vollständige Neuimplementierung mit:
|
||||
- WebSocket-basierte Echtzeit-Kommunikation
|
||||
@@ -37,14 +37,14 @@ from logging.handlers import RotatingFileHandler
|
||||
# =============================================================================
|
||||
# VERSION
|
||||
# =============================================================================
|
||||
VERSION = "2.0.0"
|
||||
VERSION = "2.3.0"
|
||||
|
||||
# =============================================================================
|
||||
# PFADE - AGENT
|
||||
# =============================================================================
|
||||
CONFIG_DIR = "/etc/geoip-agent"
|
||||
TOKEN_FILE = "/etc/geoip-agent/token"
|
||||
LOG_FILE = "/var/log/geoip-agent.log"
|
||||
CONFIG_DIR = "/etc/jtl-wafi"
|
||||
TOKEN_FILE = "/etc/jtl-wafi/token"
|
||||
LOG_FILE = "/var/log/jtl-wafi.log"
|
||||
|
||||
# =============================================================================
|
||||
# PFADE - SHOPS
|
||||
@@ -597,14 +597,14 @@ def setup_logging(debug: bool = False):
|
||||
pass
|
||||
|
||||
# Logger konfigurieren
|
||||
logger = logging.getLogger('geoip_agent')
|
||||
logger = logging.getLogger('jtl_wafi_agent')
|
||||
logger.setLevel(log_level)
|
||||
logger.handlers = handlers
|
||||
|
||||
return logger
|
||||
|
||||
# Global Logger (wird in main() initialisiert)
|
||||
logger = logging.getLogger('geoip_agent')
|
||||
logger = logging.getLogger('jtl_wafi_agent')
|
||||
|
||||
|
||||
# =============================================================================
|
||||
@@ -802,7 +802,7 @@ def generate_php_bot_ip_ranges() -> str:
|
||||
# =============================================================================
|
||||
GEOIP_SCRIPT_TEMPLATE = '''<?php
|
||||
/**
|
||||
* GeoIP Blocking Script - {region_name}
|
||||
* JTL-WAFi Blocking Script - {region_name}
|
||||
* Valid until: {expiry_date}
|
||||
* FAIL-OPEN: If cache is corrupt/empty, traffic is allowed through
|
||||
*/
|
||||
@@ -864,7 +864,7 @@ if (!$cache_valid) {{
|
||||
@file_put_contents($cache_file, serialize($allowed_ranges));
|
||||
$cache_valid = true;
|
||||
}} else {{
|
||||
error_log("GeoIP FAIL-OPEN: Could not load valid IP ranges (got " . count($allowed_ranges) . ", need $min_ranges)");
|
||||
error_log("JTL-WAFi FAIL-OPEN: Could not load valid IP ranges (got " . count($allowed_ranges) . ", need $min_ranges)");
|
||||
return;
|
||||
}}
|
||||
}}
|
||||
@@ -1407,7 +1407,7 @@ def activate_blocking(shop: str, silent: bool = True, mode: str = "geoip",
|
||||
f.write(geoip_content)
|
||||
set_owner(blocking_file, uid, gid)
|
||||
|
||||
# Step 3: Cache generieren (nur bei GeoIP)
|
||||
# Step 3: Cache generieren (nur bei JTL-WAFi)
|
||||
if not bot_mode:
|
||||
success, range_count, error = generate_and_validate_cache(httpdocs, geo_region, uid, gid)
|
||||
if not success and not silent:
|
||||
@@ -1753,7 +1753,7 @@ def rotate_shop_logs():
|
||||
# =============================================================================
|
||||
# GEOIP AGENT - WebSocket Client
|
||||
# =============================================================================
|
||||
class GeoIPAgent:
|
||||
class JTLWAFiAgent:
|
||||
"""
|
||||
WebSocket-basierter Agent für Echtzeit-Kommunikation mit dem Dashboard.
|
||||
"""
|
||||
@@ -2252,7 +2252,7 @@ class GeoIPAgent:
|
||||
def run(self):
|
||||
"""Startet den Agent."""
|
||||
logger.info("=" * 60)
|
||||
logger.info(f"GeoIP Agent v{VERSION} (WebSocket Real-Time)")
|
||||
logger.info(f"JTL-WAFi Agent v{VERSION} (WebSocket Real-Time)")
|
||||
logger.info(f"Hostname: {self.hostname}")
|
||||
logger.info(f"Agent-ID: {self.agent_id}")
|
||||
logger.info(f"Dashboard: {self.dashboard_url}")
|
||||
@@ -2274,12 +2274,12 @@ class GeoIPAgent:
|
||||
def create_systemd_service():
|
||||
"""Erstellt systemd Service-Datei."""
|
||||
service = """[Unit]
|
||||
Description=GeoIP Agent v2.0 (WebSocket)
|
||||
Description=JTL-WAFi Agent v2.0 (WebSocket)
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 /opt/geoip-agent/geoip_agent.py
|
||||
ExecStart=/usr/bin/python3 /opt/jtl-wafi/jtl_wafi_agent.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
User=root
|
||||
@@ -2288,13 +2288,13 @@ Environment=PYTHONUNBUFFERED=1
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
"""
|
||||
service_path = "/etc/systemd/system/geoip-agent.service"
|
||||
service_path = "/etc/systemd/system/jtl-wafi-agent.service"
|
||||
|
||||
try:
|
||||
with open(service_path, 'w') as f:
|
||||
f.write(service)
|
||||
print(f"✅ Service erstellt: {service_path}")
|
||||
print(" Aktivieren mit: systemctl daemon-reload && systemctl enable --now geoip-agent")
|
||||
print(" Aktivieren mit: systemctl daemon-reload && systemctl enable --now jtl-wafi-agent")
|
||||
except PermissionError:
|
||||
print("❌ Root-Rechte erforderlich!")
|
||||
sys.exit(1)
|
||||
@@ -2324,7 +2324,7 @@ def main():
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=f"GeoIP Agent v{VERSION} - WebSocket Real-Time Agent"
|
||||
description=f"JTL-WAFi Agent v{VERSION} - WebSocket Real-Time Agent"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--url",
|
||||
@@ -2372,7 +2372,7 @@ def main():
|
||||
sys.exit(1)
|
||||
|
||||
# Agent starten
|
||||
agent = GeoIPAgent(dashboard_url=args.url)
|
||||
agent = JTLWAFiAgent(dashboard_url=args.url)
|
||||
agent.run()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user