UI - digging bugs from services, still some work to do
This commit is contained in:
parent
72a09eac6d
commit
3af1b397fa
@ -656,7 +656,7 @@
|
|||||||
"env": "SELF_SIGNED_SSL_COUNTRY",
|
"env": "SELF_SIGNED_SSL_COUNTRY",
|
||||||
"id": "self-signed-ssl-country",
|
"id": "self-signed-ssl-country",
|
||||||
"label": "Country of the self-signed certificate",
|
"label": "Country of the self-signed certificate",
|
||||||
"regex": "^[:print:]+$",
|
"regex": "^[A-Z]{2}$",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -665,7 +665,7 @@
|
|||||||
"env": "SELF_SIGNED_SSL_STATE",
|
"env": "SELF_SIGNED_SSL_STATE",
|
||||||
"id": "self-signed-ssl-state",
|
"id": "self-signed-ssl-state",
|
||||||
"label": "State of the self-signed certificate",
|
"label": "State of the self-signed certificate",
|
||||||
"regex": "^[:print:]+$",
|
"regex": "^[A-Za-z\\-]+$",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -674,7 +674,7 @@
|
|||||||
"env": "SELF_SIGNED_SSL_CITY",
|
"env": "SELF_SIGNED_SSL_CITY",
|
||||||
"id": "self-signed-ssl-city",
|
"id": "self-signed-ssl-city",
|
||||||
"label": "City of the self-signed certificate",
|
"label": "City of the self-signed certificate",
|
||||||
"regex": "^[:print:]+$",
|
"regex": "^[A-Za-z\\-]+$",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -683,7 +683,7 @@
|
|||||||
"env": "SELF_SIGNED_SSL_OU",
|
"env": "SELF_SIGNED_SSL_OU",
|
||||||
"id": "self-signed-ssl-ou",
|
"id": "self-signed-ssl-ou",
|
||||||
"label": "Organizational Unit of the self-signed certificate",
|
"label": "Organizational Unit of the self-signed certificate",
|
||||||
"regex": "^[:print:]+$",
|
"regex": "^[A-Za-z\\-]+$$",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -692,7 +692,7 @@
|
|||||||
"env": "SELF_SIGNED_SSL_ORG",
|
"env": "SELF_SIGNED_SSL_ORG",
|
||||||
"id": "self-signed-ssl-org",
|
"id": "self-signed-ssl-org",
|
||||||
"label": "Organization name of the self-signed certificate",
|
"label": "Organization name of the self-signed certificate",
|
||||||
"regex": "^[:print:]+$",
|
"regex": "^[A-Za-z\\- ]+$$",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -701,7 +701,7 @@
|
|||||||
"env": "SELF_SIGNED_SSL_CN",
|
"env": "SELF_SIGNED_SSL_CN",
|
||||||
"id": "self-signed-ssl-cn",
|
"id": "self-signed-ssl-cn",
|
||||||
"label": "Common Name of the self-signed certificate",
|
"label": "Common Name of the self-signed certificate",
|
||||||
"regex": "^[:print:]+$",
|
"regex": "^[A-Za-z\\-\\.0-9]+$",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
37
ui/Docker.py
37
ui/Docker.py
@ -1,37 +0,0 @@
|
|||||||
import docker
|
|
||||||
|
|
||||||
class Docker :
|
|
||||||
|
|
||||||
def __init__(self, docker_host) :
|
|
||||||
self.__client = docker.DockerClient(base_url=docker_host)
|
|
||||||
|
|
||||||
def get_instances(self) :
|
|
||||||
return self.__client.containers.list(all=True, filters={"label" : "bunkerized-nginx.UI"})
|
|
||||||
|
|
||||||
def reload_instances(self) :
|
|
||||||
for instance in self.get_instances() :
|
|
||||||
instance.kill(signal="SIGHUP")
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_instance(self, id) :
|
|
||||||
return self.__client.containers.get(id)
|
|
||||||
|
|
||||||
def reload_instance(self, id) :
|
|
||||||
self.get_instance(id).kill(signal="SIGHUP")
|
|
||||||
return "Instance " + id + " has been reloaded."
|
|
||||||
|
|
||||||
def start_instance(self, id) :
|
|
||||||
self.get_instance(id).start()
|
|
||||||
return "Instance " + id + " has been started."
|
|
||||||
|
|
||||||
def stop_instance(self, id) :
|
|
||||||
self.get_instance(id).stop()
|
|
||||||
return "Instance " + id + " has been stopped."
|
|
||||||
|
|
||||||
def restart_instance(self, id) :
|
|
||||||
self.get_instance(id).restart()
|
|
||||||
return "Instance " + id + " has been restarted."
|
|
||||||
|
|
||||||
def delete_instance(self, id) :
|
|
||||||
self.get_instance(id).remove(v=True, force=True)
|
|
||||||
return "Instance " + id + " has been deleted."
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
RUN apk add py3-pip bash
|
RUN apk add py3-pip bash build-base python3-dev libffi-dev
|
||||||
COPY ui/requirements.txt /tmp
|
COPY ui/requirements.txt /tmp
|
||||||
RUN pip3 install -r /tmp/requirements.txt
|
RUN pip3 install -r /tmp/requirements.txt
|
||||||
|
|
||||||
@ -19,4 +19,4 @@ EXPOSE 5000
|
|||||||
|
|
||||||
WORKDIR /opt/bunkerized-nginx/ui
|
WORKDIR /opt/bunkerized-nginx/ui
|
||||||
USER nginx:nginx
|
USER nginx:nginx
|
||||||
ENTRYPOINT ["/usr/bin/gunicorn", "--bind", "0.0.0.0:5000", "-m", "007", "wsgi:app"]
|
ENTRYPOINT ["/usr/bin/gunicorn", "--bind", "0.0.0.0:5000", "-m", "007", "wsgi:app"]
|
||||||
|
|||||||
@ -6,9 +6,8 @@ from flask_wtf.csrf import CSRFProtect, CSRFError
|
|||||||
|
|
||||||
from src.Instances import Instances
|
from src.Instances import Instances
|
||||||
from src.User import User
|
from src.User import User
|
||||||
|
from src.Config import Config
|
||||||
|
|
||||||
from Docker import Docker
|
|
||||||
from Config import Config
|
|
||||||
import utils
|
import utils
|
||||||
import os, json, re, copy, traceback
|
import os, json, re, copy, traceback
|
||||||
|
|
||||||
@ -73,7 +72,7 @@ def home() :
|
|||||||
services_number = len(app.config["CONFIG"].get_services())
|
services_number = len(app.config["CONFIG"].get_services())
|
||||||
return render_template("home.html", title="Home", instances_number=instances_number, services_number=services_number)
|
return render_template("home.html", title="Home", instances_number=instances_number, services_number=services_number)
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
return render_template("error.html", title="Error", error=e)
|
return render_template("error.html", title="Error", error=str(e) + "<br />" + traceback.format_exc().replace("\n", "<br />"))
|
||||||
|
|
||||||
@app.route('/instances', methods=["GET", "POST"])
|
@app.route('/instances', methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@ -106,7 +105,7 @@ def instances() :
|
|||||||
return render_template("instances.html", title="Instances", instances=instances, operation=operation)
|
return render_template("instances.html", title="Instances", instances=instances, operation=operation)
|
||||||
|
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
return render_template("error.html", title="Error", error=str(e))
|
return render_template("error.html", title="Error", error=str(e) + "\n" + traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/services', methods=["GET", "POST"])
|
@app.route('/services', methods=["GET", "POST"])
|
||||||
@ -123,6 +122,7 @@ def services():
|
|||||||
|
|
||||||
# Check variables
|
# Check variables
|
||||||
variables = copy.deepcopy(request.form.to_dict())
|
variables = copy.deepcopy(request.form.to_dict())
|
||||||
|
del variables["csrf_token"]
|
||||||
if not "OLD_SERVER_NAME" in request.form and request.form["operation"] == "edit" :
|
if not "OLD_SERVER_NAME" in request.form and request.form["operation"] == "edit" :
|
||||||
raise Exception("Missing OLD_SERVER_NAME parameter.")
|
raise Exception("Missing OLD_SERVER_NAME parameter.")
|
||||||
if request.form["operation"] in ["new", "edit"] :
|
if request.form["operation"] in ["new", "edit"] :
|
||||||
@ -145,13 +145,14 @@ def services():
|
|||||||
elif request.form["operation"] == "delete" :
|
elif request.form["operation"] == "delete" :
|
||||||
operation = app.config["CONFIG"].delete_service(request.form["SERVER_NAME"])
|
operation = app.config["CONFIG"].delete_service(request.form["SERVER_NAME"])
|
||||||
|
|
||||||
# Reload containers
|
# Reload instances
|
||||||
for instance in app.config["DOCKER"].get_instances() :
|
reload = app.config["INSTANCES"].reload_instances()
|
||||||
app.config["DOCKER"].reload_instance(instance.id)
|
if not reload :
|
||||||
|
operation = "Reload failed for at least one instance..."
|
||||||
|
|
||||||
# Display services
|
# Display services
|
||||||
services = app.config["CONFIG"].get_services()
|
services = app.config["CONFIG"].get_services()
|
||||||
return render_template("services.html", title="Services", services=services, operation=operation)
|
return render_template("services.html", title="Services", services=services, operation=operation)
|
||||||
|
|
||||||
except Exception as e :
|
except Exception as e :
|
||||||
return render_template("error.html", title="Error", error=str(e) + traceback.format_exc())
|
return render_template("error.html", title="Error", error=str(e) + "\n" + traceback.format_exc())
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import json, uuid, glob, copy, re, subprocess
|
import json, uuid, glob, copy, re, subprocess, os
|
||||||
|
|
||||||
class Config :
|
class Config :
|
||||||
|
|
||||||
@ -7,6 +7,8 @@ class Config :
|
|||||||
self.__settings = json.loads(f.read())
|
self.__settings = json.loads(f.read())
|
||||||
|
|
||||||
def __env_to_dict(self, filename) :
|
def __env_to_dict(self, filename) :
|
||||||
|
if not os.path.isfile(filename) :
|
||||||
|
return {}
|
||||||
with open(filename, "r") as f :
|
with open(filename, "r") as f :
|
||||||
env = f.read()
|
env = f.read()
|
||||||
data = {}
|
data = {}
|
||||||
@ -25,6 +27,8 @@ class Config :
|
|||||||
|
|
||||||
def __gen_conf(self, global_conf, services_conf) :
|
def __gen_conf(self, global_conf, services_conf) :
|
||||||
conf = copy.deepcopy(global_conf)
|
conf = copy.deepcopy(global_conf)
|
||||||
|
if not "SERVER_NAME" in conf :
|
||||||
|
conf["SERVER_NAME"] = ""
|
||||||
servers = conf["SERVER_NAME"].split(" ")
|
servers = conf["SERVER_NAME"].split(" ")
|
||||||
if conf["SERVER_NAME"] == "" :
|
if conf["SERVER_NAME"] == "" :
|
||||||
servers = []
|
servers = []
|
||||||
@ -39,9 +43,9 @@ class Config :
|
|||||||
self.__dict_to_env(env_file, conf)
|
self.__dict_to_env(env_file, conf)
|
||||||
proc = subprocess.run(["/opt/bunkerized-nginx/gen/main.py", "--settings", "/opt/bunkerized-nginx/settings.json", "--templates", "/opt/bunkerized-nginx/confs", "--output", "/etc/nginx", "--variables", env_file], capture_output=True)
|
proc = subprocess.run(["/opt/bunkerized-nginx/gen/main.py", "--settings", "/opt/bunkerized-nginx/settings.json", "--templates", "/opt/bunkerized-nginx/confs", "--output", "/etc/nginx", "--variables", env_file], capture_output=True)
|
||||||
stderr = proc.stderr.decode("ascii")
|
stderr = proc.stderr.decode("ascii")
|
||||||
#stdout = proc.stdout.decode("ascii")
|
stdout = proc.stdout.decode("ascii")
|
||||||
if stderr != "" or proc.returncode != 0 :
|
if stderr != "" or proc.returncode != 0 :
|
||||||
raise Exception("Error from generator (return code = " + str(proc.returncode) + ") : " + stderr)
|
raise Exception("Error from generator (return code = " + str(proc.returncode) + ") : " + stderr + "\n" + stdout)
|
||||||
|
|
||||||
def get_settings(self) :
|
def get_settings(self) :
|
||||||
return self.__settings
|
return self.__settings
|
||||||
@ -54,6 +58,7 @@ class Config :
|
|||||||
for filename in glob.iglob("/etc/nginx/**/site.env") :
|
for filename in glob.iglob("/etc/nginx/**/site.env") :
|
||||||
env = self.__env_to_dict(filename)
|
env = self.__env_to_dict(filename)
|
||||||
services.append(env)
|
services.append(env)
|
||||||
|
services.append(self.__env_to_dict("/etc/nginx/site.env"))
|
||||||
return services
|
return services
|
||||||
|
|
||||||
def check_variables(self, variables) :
|
def check_variables(self, variables) :
|
||||||
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
<div class="alert alert-danger text-center">
|
<div class="alert alert-danger text-center">
|
||||||
Something went wrong...<br /><br />
|
Something went wrong...<br /><br />
|
||||||
{{ error }}
|
{% autoescape false %}
|
||||||
|
{{ error | replace("\n", "<br/>") }}
|
||||||
|
{% endautoescape %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@ -15,6 +15,12 @@
|
|||||||
|
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
|
|
||||||
|
{% if instances|length == 0 %}
|
||||||
|
<div class="alert alert-primary text-center">
|
||||||
|
No instance to show...
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% for instance in instances %}
|
{% for instance in instances %}
|
||||||
{% set color = "dark" %}
|
{% set color = "dark" %}
|
||||||
{% if instance["status"] == "up" %}
|
{% if instance["status"] == "up" %}
|
||||||
|
|||||||
@ -2,24 +2,25 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{% if operation != "" %}
|
|
||||||
<div class="row justify-content-center">
|
|
||||||
<div class="col col-12 col-md-4 mb-3 text-center">
|
|
||||||
<div class="alert alert-primary alert-dismissible fade show text-break" role="alert">
|
|
||||||
{{ operation }}
|
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
|
|
||||||
<div class="col col-12 mb-3 text-center">
|
<div class="col col-12 mb-3 text-center">
|
||||||
<button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#modal-new"><i class="fas fa-plus"></i> New</button>
|
<button class="btn btn-success" data-bs-toggle="modal" data-bs-target="#modal-new"><i class="fas fa-plus"></i> New</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if operation != "" %}
|
||||||
|
<div class="alert alert-primary alert-dismissible fade show text-break" role="alert">
|
||||||
|
{{ operation }}
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if services|length == 0 %}
|
||||||
|
<div class="alert alert-primary text-center">
|
||||||
|
No service to show...
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% for service in services %}
|
{% for service in services %}
|
||||||
|
|
||||||
{% set id_server_name = service["SERVER_NAME"].replace(".", "-") %}
|
{% set id_server_name = service["SERVER_NAME"].replace(".", "-") %}
|
||||||
@ -58,12 +59,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% include "services-new.html" %}
|
|
||||||
{% include "services-edit.html" %}
|
{% include "services-edit.html" %}
|
||||||
{% include "services-delete.html" %}
|
{% include "services-delete.html" %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% include "services-new.html" %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user