jtl-wafi-agent.py aktualisiert
This commit is contained in:
@@ -2811,40 +2811,64 @@ def download_country_ranges_async():
|
|||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
def ensure_country_cache_symlink(ratelimit_path: str) -> bool:
|
def copy_country_cache_to_shop(ratelimit_path: str) -> int:
|
||||||
"""
|
"""
|
||||||
Erstellt einen Symlink vom Shop-spezifischen Pfad zum globalen Country-Cache.
|
Kopiert Country-Cache vom globalen Verzeichnis in den Shop.
|
||||||
|
(Symlinks funktionieren nicht wegen PHP open_basedir Restriction)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
ratelimit_path: Pfad zum jtl-wafi_ratelimit Verzeichnis des Shops
|
ratelimit_path: Pfad zum jtl-wafi_ratelimit Verzeichnis des Shops
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True wenn erfolgreich, False sonst
|
Anzahl der kopierten Dateien
|
||||||
"""
|
"""
|
||||||
symlink_path = os.path.join(ratelimit_path, 'country_cache')
|
shop_cache_dir = os.path.join(ratelimit_path, 'country_cache')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Falls bereits existiert
|
# Shop-Cache Verzeichnis erstellen
|
||||||
if os.path.islink(symlink_path):
|
os.makedirs(shop_cache_dir, exist_ok=True)
|
||||||
# Prüfe ob Symlink korrekt ist
|
|
||||||
if os.readlink(symlink_path) == GLOBAL_COUNTRY_CACHE_DIR:
|
|
||||||
return True
|
|
||||||
# Falsches Ziel - entfernen und neu erstellen
|
|
||||||
os.remove(symlink_path)
|
|
||||||
elif os.path.isdir(symlink_path):
|
|
||||||
# Altes Verzeichnis existiert - entfernen (war vorher Kopie)
|
|
||||||
shutil.rmtree(symlink_path)
|
|
||||||
elif os.path.exists(symlink_path):
|
|
||||||
os.remove(symlink_path)
|
|
||||||
|
|
||||||
# Symlink erstellen
|
# Falls Symlink existiert (von alter Version), entfernen
|
||||||
os.symlink(GLOBAL_COUNTRY_CACHE_DIR, symlink_path)
|
if os.path.islink(shop_cache_dir):
|
||||||
logger.debug(f"Country-Cache Symlink erstellt: {symlink_path} -> {GLOBAL_COUNTRY_CACHE_DIR}")
|
os.remove(shop_cache_dir)
|
||||||
return True
|
os.makedirs(shop_cache_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# Prüfe ob globaler Cache existiert
|
||||||
|
if not os.path.isdir(GLOBAL_COUNTRY_CACHE_DIR):
|
||||||
|
logger.debug(f"Globaler Country-Cache nicht vorhanden: {GLOBAL_COUNTRY_CACHE_DIR}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
copied = 0
|
||||||
|
for filename in os.listdir(GLOBAL_COUNTRY_CACHE_DIR):
|
||||||
|
if filename.endswith('.ranges'):
|
||||||
|
src = os.path.join(GLOBAL_COUNTRY_CACHE_DIR, filename)
|
||||||
|
dst = os.path.join(shop_cache_dir, filename)
|
||||||
|
|
||||||
|
# Nur kopieren wenn Quelle neuer ist oder Ziel nicht existiert
|
||||||
|
if not os.path.isfile(dst) or os.path.getmtime(src) > os.path.getmtime(dst):
|
||||||
|
shutil.copy2(src, dst)
|
||||||
|
copied += 1
|
||||||
|
|
||||||
|
if copied > 0:
|
||||||
|
logger.debug(f"Country-Cache kopiert: {copied} Dateien nach {shop_cache_dir}")
|
||||||
|
|
||||||
|
return copied
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Fehler beim Erstellen des Country-Cache Symlinks: {e}")
|
logger.error(f"Fehler beim Kopieren des Country-Cache: {e}")
|
||||||
return False
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def copy_country_cache_to_shop_async(ratelimit_path: str):
|
||||||
|
"""Kopiert Country-Cache im Hintergrund."""
|
||||||
|
def _copy():
|
||||||
|
# Erst sicherstellen, dass globaler Cache existiert
|
||||||
|
if not os.path.isdir(GLOBAL_COUNTRY_CACHE_DIR) or not os.listdir(GLOBAL_COUNTRY_CACHE_DIR):
|
||||||
|
download_country_ranges(force=False)
|
||||||
|
copy_country_cache_to_shop(ratelimit_path)
|
||||||
|
|
||||||
|
thread = threading.Thread(target=_copy, daemon=True)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
@@ -3009,8 +3033,8 @@ def activate_blocking(shop: str, silent: bool = True,
|
|||||||
monitor_only=monitor_only
|
monitor_only=monitor_only
|
||||||
)
|
)
|
||||||
|
|
||||||
# Step 5: Country-Cache Symlink erstellen (zeigt auf globalen Cache)
|
# Step 5: Country-Cache vom globalen Cache kopieren (wegen PHP open_basedir)
|
||||||
ensure_country_cache_symlink(ratelimit_path)
|
copy_country_cache_to_shop_async(ratelimit_path)
|
||||||
|
|
||||||
if not silent:
|
if not silent:
|
||||||
logger.info(f"Blocking aktiviert für {shop}")
|
logger.info(f"Blocking aktiviert für {shop}")
|
||||||
|
|||||||
Reference in New Issue
Block a user