bunkerweb/ui/entrypoint.py
2020-12-21 15:32:15 +01:00

40 lines
1.3 KiB
Python

#!/usr/bin/python3
from flask import Flask, render_template, current_app
import wrappers
import os
app = Flask(__name__, static_url_path="/", static_folder="static", template_folder="templates")
ABSOLUTE_URI = ""
if "ABSOLUTE_URI" in os.environ :
ABSOLUTE_URI = os.environ["ABSOLUTE_URI"]
app.config["ABSOLUTE_URI"] = ABSOLUTE_URI
@app.route('/')
@app.route('/home')
def home():
check, instances = wrappers.get_instances()
if not check :
return render_template("error.html", title="Error", error=instances)
check, services = wrappers.get_services()
if not check :
return render_template("error.html", title="Error", error=services)
return render_template("home.html", title="Home", instances_number=len(instances), services_number=len(services))
@app.route('/instances')
def instances():
check, instances = wrappers.get_instances()
if not check :
return render_template("error.html", title="Error", error=instances)
return render_template("instances.html", title="Instances", instances=instances)
@app.route('/services')
def services():
check, services = wrappers.get_services()
print(services, flush=True)
if not check :
return render_template("error.html", title="Error", error=services)
return render_template("services.html", title="Services", services=services)