2024-07-22 18:14:12 -03:00
|
|
|
from flask import Flask, render_template
|
|
|
|
import re
|
2024-07-22 18:57:14 -03:00
|
|
|
import docker
|
|
|
|
import requests
|
2024-07-22 18:14:12 -03:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
TRAEFIK_API_URL = "https://norman.lan/api/http/routers"
|
|
|
|
REGEX_PATTERNS = [r".*\.gederico\.dynu\.net"]
|
|
|
|
|
2024-07-22 18:57:14 -03:00
|
|
|
client = docker.from_env()
|
|
|
|
containers = client.containers.list(all=True) # Get all containers
|
|
|
|
|
2024-07-22 18:14:12 -03:00
|
|
|
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]):
|
2024-07-22 18:25:30 -03:00
|
|
|
router['description'] = get_router_description(router['name'])
|
2024-07-22 18:14:12 -03:00
|
|
|
filtered_routers.append(router)
|
|
|
|
break
|
|
|
|
return filtered_routers
|
|
|
|
|
2024-07-22 18:25:30 -03:00
|
|
|
def get_router_description(router_name):
|
|
|
|
try:
|
|
|
|
service_name = router_name.split('@')[0]
|
2024-07-22 18:57:14 -03:00
|
|
|
for container in containers:
|
|
|
|
labels = container.attrs.get('Config', {}).get('Labels', {})
|
|
|
|
description = labels.get('traefik-frontend.http.routers.' + service_name + '.description')
|
|
|
|
if description:
|
|
|
|
return description
|
2024-07-22 18:25:30 -03:00
|
|
|
except Exception as e:
|
|
|
|
print(f"Error fetching description for {router_name}: {e}")
|
|
|
|
return 'No description available'
|
|
|
|
|
2024-07-22 18:14:12 -03:00
|
|
|
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__':
|
2024-07-22 18:57:14 -03:00
|
|
|
app.run(host='0.0.0.0', debug=True)
|
2024-07-22 18:14:12 -03:00
|
|
|
|