#!/usr/bin/env python3 """ Füge head-matter in die globale /etc/wt/wt_config.xml ein für application-settings location="*" """ import sys import xml.etree.ElementTree as ET from datetime import datetime import shutil CONFIG_FILE = "/etc/wt/wt_config.xml" BACKUP_FILE = f"{CONFIG_FILE}.backup.{datetime.now().strftime('%Y%m%d_%H%M%S')}" print("=== Backup erstellen ===") shutil.copy2(CONFIG_FILE, BACKUP_FILE) print(f"Backup erstellt: {BACKUP_FILE}") print("\n=== Parse XML ===") tree = ET.parse(CONFIG_FILE) root = tree.getroot() print("\n=== Suche application-settings location='*' ===") app_settings = None for settings in root.findall(".//application-settings"): if settings.get("location") == "*": app_settings = settings break if app_settings is None: print("FEHLER: application-settings location='*' nicht gefunden!") sys.exit(1) print(f"Gefunden: application-settings location='*'") print("\n=== Prüfe, ob head-matter bereits existiert ===") if app_settings.find("head-matter") is not None: print("WARNUNG: existiert bereits!") sys.exit(1) print("\n=== Füge head-matter hinzu ===") head_matter = ET.SubElement(app_settings, "head-matter") meta = ET.SubElement(head_matter, "meta") meta.set("name", "robots") meta.set("content", "index,follow") print("Hinzugefügt zu application-settings location='*'") print("\n=== Speichere geänderte Konfiguration ===") # Formatierung verbessern ET.indent(tree, space=" ") tree.write(CONFIG_FILE, encoding="UTF-8", xml_declaration=True) print("\n=== Geänderte Konfiguration anzeigen ===") with open(CONFIG_FILE, 'r') as f: lines = f.readlines() for i, line in enumerate(lines, 1): if 'head-matter' in line or ('robots' in line and i < 20): print(f"{i}: {line.rstrip()}") print("\n=== Fertig! ===") print("Bitte Service neu starten: sudo systemctl restart ypchat.service")