first commit
This commit is contained in:
39
app.py
Normal file
39
app.py
Normal file
@@ -0,0 +1,39 @@
|
||||
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]):
|
||||
filtered_routers.append(router)
|
||||
break
|
||||
return filtered_routers
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user