This commit is contained in:
pika 2025-03-10 18:24:23 +01:00
parent 2e919145ec
commit 9eb8f24845
7 changed files with 114 additions and 0 deletions

34
src/update.py Normal file
View file

@ -0,0 +1,34 @@
import requests
import re
import os
CADDYFILE_PATH = "/opt/docker/caddy/conf/Caddyfile" # Pfad zur Caddyfile
DASHBOARD_URL = "http://10.0.0.25:5000/update" # Anpassen!
SERVER_NAME = os.getenv("CADDY_SERVER_NAME", "Unknown Server")
def parse_caddyfile():
entries = {}
try:
with open(CADDYFILE_PATH, "r") as file:
content = file.read()
pattern = re.compile(r"(?P<domains>[^\s{]+(?:,\s*[^\s{]+)*)\s*{.*?reverse_proxy\s+(?P<target>https?:\/\/[\d\.]+:\d+|[\d\.]+:\d+).*?}", re.DOTALL)
matches = pattern.findall(content)
for domains, target in matches:
for domain in domains.split(", "):
entries[domain] = target.strip()
except Exception as e:
print(f"Fehler beim Lesen der Caddyfile: {e}")
return entries
def send_update():
data = {"server": SERVER_NAME, "entries": parse_caddyfile()}
try:
response = requests.post(DASHBOARD_URL, json=data)
print(response.json())
except Exception as e:
print(f"Fehler beim Senden: {e}")
if __name__ == "__main__":
send_update()