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

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
.src

12
Dockerfile Normal file
View file

@ -0,0 +1,12 @@
FROM python:3.12-alpine
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
EXPOSE 5000
CMD ["python", "app.py"]

26
app.py Normal file
View file

@ -0,0 +1,26 @@
from flask import Flask, render_template, request, jsonify
import threading
app = Flask(__name__)
# Speicher für Proxy-Subdomains (dict mit Liste für jeden Server)
proxy_data = {}
@app.route('/')
def index():
return render_template('index.html', proxies=proxy_data)
@app.route('/update', methods=['POST'])
def update():
"""Empfängt Subdomain-Daten von Caddy-Proxies"""
data = request.json
if not data or "server" not in data or "entries" not in data:
return jsonify({"error": "Invalid data"}), 400
server_name = data["server"]
proxy_data[server_name] = data["entries"]
return jsonify({"message": "Updated successfully"}), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

5
compose.yml Normal file
View file

@ -0,0 +1,5 @@
services:
caddydb:
image: caddydb:latest
ports:
- 5000:5000

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
flask

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()

35
templates/index.html Normal file
View file

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Zentrales Caddy-Dashboard</title>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<body>
<header>
<h1>Zentrales Caddy-Dashboard</h1>
</header>
<main>
{% for server, entries in proxies.items() %}
<h2>{{ server }}</h2>
<table>
<thead>
<tr>
<th>Domain</th>
<th>Ziel</th>
</tr>
</thead>
<tbody>
{% for domain, target in entries.items() %}
<tr>
<td><a href="https://{{ domain }}" target="_blank">{{ domain }}</a></td>
<td>{{ target }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endfor %}
</main>
</body>
</html>