55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from flask import Flask, render_template
|
|
import requests
|
|
import re
|
|
|
|
app = Flask(__name__)
|
|
|
|
TRAEFIK_API_URL = "https://norman.lan/api/http/routers"
|
|
REGEX_PATTERNS = [r".*\.gederico\.dynu\.net"]
|
|
|
|
def get_routers():
|
|
response = requests.get(TRAEFIK_API_URL, verify=False) # Ignore SSL certificate verification
|
|
if response.status_code == 200:
|
|
routers = response.json()
|
|
filtered_routers = filter_routers(routers)
|
|
return filtered_routers
|
|
return []
|
|
|
|
def filter_routers(routers):
|
|
filtered_routers = []
|
|
for router in routers:
|
|
for pattern in REGEX_PATTERNS:
|
|
if re.match(pattern, router['rule'].split('`')[1]):
|
|
router['description'] = get_router_description(router['name'])
|
|
filtered_routers.append(router)
|
|
break
|
|
return filtered_routers
|
|
|
|
def get_router_description(router_name):
|
|
try:
|
|
service_name = router_name.split('@')[0]
|
|
response = requests.get("http://localhost:2375/containers/json?filters={%22name%22:[%22" + service_name + "%22]}")
|
|
containers = response.json()
|
|
if containers:
|
|
container = containers[0]
|
|
labels = container.get('Labels', {})
|
|
print(labels)
|
|
return labels.get('traefik.http.routers.' + service_name + '.description', 'No description available')
|
|
except Exception as e:
|
|
print(f"Error fetching description for {router_name}: {e}")
|
|
return 'No description available'
|
|
|
|
def truncate_and_uppercase_name(name):
|
|
return name.split('@')[0].upper()
|
|
|
|
@app.route('/')
|
|
def index():
|
|
routers = get_routers()
|
|
for router in routers:
|
|
router['truncated_name'] = truncate_and_uppercase_name(router['name'])
|
|
return render_template('index.html', routers=routers)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|
|
|