web ui - mostly finished templating integration (needs some testing)

This commit is contained in:
bunkerity 2021-06-01 15:22:03 +02:00
parent 7323525b69
commit ee178de6ab
No known key found for this signature in database
GPG Key ID: 3D80806F12602A7C
16 changed files with 141 additions and 50 deletions

View File

@ -1,9 +1,5 @@
FROM nginx:1.20.1-alpine AS builder
FROM alpine FROM alpine
COPY --from=builder /etc/nginx/ /opt/confs/nginx
COPY autoconf/dependencies.sh /tmp COPY autoconf/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \
/tmp/dependencies.sh && \ /tmp/dependencies.sh && \

View File

@ -1,9 +1,5 @@
FROM nginx:1.20.1-alpine AS builder
FROM amd64/alpine FROM amd64/alpine
COPY --from=builder /etc/nginx/ /opt/confs/nginx
COPY autoconf/dependencies.sh /tmp COPY autoconf/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \
/tmp/dependencies.sh && \ /tmp/dependencies.sh && \

View File

@ -3,12 +3,9 @@ FROM alpine AS builder
ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-arm.tar.gz ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-arm.tar.gz
RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1
FROM nginx:1.20.1-alpine AS builder2
FROM arm32v7/alpine FROM arm32v7/alpine
COPY --from=builder qemu-arm-static /usr/bin COPY --from=builder qemu-arm-static /usr/bin
COPY --from=builder2 /etc/nginx/ /opt/confs/nginx
COPY autoconf/dependencies.sh /tmp COPY autoconf/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \

View File

@ -3,12 +3,9 @@ FROM alpine AS builder
ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-aarch64.tar.gz ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-aarch64.tar.gz
RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1
FROM nginx:1.20.1-alpine AS builder2
FROM arm64v8/alpine FROM arm64v8/alpine
COPY --from=builder qemu-aarch64-static /usr/bin COPY --from=builder qemu-aarch64-static /usr/bin
COPY --from=builder2 /etc/nginx/ /opt/confs/nginx
COPY autoconf/dependencies.sh /tmp COPY autoconf/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \

View File

@ -1,9 +1,5 @@
FROM nginx:1.20.1-alpine AS builder
FROM i386/alpine FROM i386/alpine
COPY --from=builder /etc/nginx/ /opt/confs/nginx
COPY autoconf/dependencies.sh /tmp COPY autoconf/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \
/tmp/dependencies.sh && \ /tmp/dependencies.sh && \

96
confs/global/mime.types Normal file
View File

@ -0,0 +1,96 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}

View File

@ -29,6 +29,7 @@ services:
- admin.website.com_USE_REVERSE_PROXY=yes - admin.website.com_USE_REVERSE_PROXY=yes
- admin.website.com_REVERSE_PROXY_URL=/admin/ # change it to something hard to guess - admin.website.com_REVERSE_PROXY_URL=/admin/ # change it to something hard to guess
- admin.website.com_REVERSE_PROXY_HOST=http://myui:5000/ - admin.website.com_REVERSE_PROXY_HOST=http://myui:5000/
- admin.website.com_USE_MODSECURITY=no
labels: labels:
- "bunkerized-nginx.UI" - "bunkerized-nginx.UI"

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import argparse, os, sys import argparse, os, sys, shutil
import utils import utils
from Configurator import Configurator from Configurator import Configurator
@ -51,6 +51,14 @@ if __name__ == "__main__" :
config = configurator.get_config() config = configurator.get_config()
print(config) print(config)
# Remove old config
for filename in os.listdir(args.output):
file_path = os.path.join(args.output, filename)
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
# Generate the files from templates and config # Generate the files from templates and config
templator = Templator(config, args.templates, args.output, args.target) templator = Templator(config, args.templates, args.output, args.target)
templator.render_global() templator.render_global()

View File

@ -1,4 +1,4 @@
import json, uuid, glob, copy import json, uuid, glob, copy, re, subprocess
class Config : class Config :
@ -25,10 +25,16 @@ 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)
servers = conf["SERVER_NAME"].split(" ")
if conf["SERVER_NAME"] == "" :
servers = []
for service in services_conf : for service in services_conf :
first_server = service["SERVER_NAME"].split(" ")[0] first_server = service["SERVER_NAME"].split(" ")[0]
if not first_server in servers :
servers.append(first_server)
for k, v in service.items() : for k, v in service.items() :
conf[first_server + "_" + k] = v conf[first_server + "_" + k] = v
conf["SERVER_NAME"] = " ".join(servers)
env_file = "/tmp/" + str(uuid.uuid4()) + ".env" env_file = "/tmp/" + str(uuid.uuid4()) + ".env"
self.__dict_to_env(env_file, conf) self.__dict_to_env(env_file, conf)
proc = subprocess.run(["/bin/su", "-c", "/opt/gen/main.py --settings /opt/settings.json --templates /opt/confs --output /etc/nginx --variables " + env_file, "nginx"], capture_output=True) proc = subprocess.run(["/bin/su", "-c", "/opt/gen/main.py --settings /opt/settings.json --templates /opt/confs --output /etc/nginx --variables " + env_file, "nginx"], capture_output=True)
@ -38,7 +44,7 @@ class Config :
def get_settings(self) : def get_settings(self) :
return self.__settings return self.__settings
def get_config(self) : def get_config(self) :
return self.__env_to_dict("/etc/nginx/global.env") return self.__env_to_dict("/etc/nginx/global.env")
@ -54,10 +60,10 @@ class Config :
check = False check = False
for category in self.__settings : for category in self.__settings :
for param in self.__settings[category]["params"] : for param in self.__settings[category]["params"] :
if type != "multiple" : if param["type"] != "multiple" :
real_params = [param] real_params = [param]
else : else :
real_params = param real_params = param["params"]
for real_param in real_params : for real_param in real_params :
if k == real_param["env"] and real_param["context"] == "multisite" and re.search(real_param["regex"], v) : if k == real_param["env"] and real_param["context"] == "multisite" and re.search(real_param["regex"], v) :
check = True check = True
@ -72,10 +78,12 @@ class Config :
raise Exception("Service " + service["SERVER_NAME"] + " already exists.") raise Exception("Service " + service["SERVER_NAME"] + " already exists.")
services.append(variables) services.append(variables)
self.__gen_conf(global_env, services) self.__gen_conf(global_env, services)
return "Configuration for " + variables["SERVER_NAME"] + " has been generated."
def edit_service(self, old_server_name, variables) : def edit_service(self, old_server_name, variables) :
self.delete_service(old_server_name) self.delete_service(old_server_name)
self.new_service(variables) self.new_service(variables)
return "Configuration for " + old_server_name + " has been edited."
def delete_service(self, server_name) : def delete_service(self, server_name) :
@ -90,5 +98,10 @@ class Config :
new_services.append(service) new_services.append(service)
if not found : if not found :
raise Exception("Can't delete missing " + server_name + " configuration.") raise Exception("Can't delete missing " + server_name + " configuration.")
new_servers = global_env["SERVER_NAME"].split(" ")
if server_name in new_servers :
new_servers.remove(server_name)
global_env["SERVER_NAME"] = " ".join(new_servers)
self.__gen_conf(global_env, new_services) self.__gen_conf(global_env, new_services)
return "Configuration for " + server_name + " has been deleted."

View File

@ -1,9 +1,5 @@
FROM nginx:1.20.1-alpine AS builder
FROM alpine FROM alpine
COPY --from=builder /etc/nginx/ /opt/confs/nginx
COPY ui/dependencies.sh /tmp COPY ui/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \
/tmp/dependencies.sh && \ /tmp/dependencies.sh && \
@ -11,6 +7,7 @@ RUN chmod +x /tmp/dependencies.sh && \
COPY gen/ /opt/gen COPY gen/ /opt/gen
COPY confs/site/ /opt/confs/site COPY confs/site/ /opt/confs/site
COPY confs/global/ /opt/confs/global
COPY ui/ /opt/entrypoint COPY ui/ /opt/entrypoint
COPY settings.json /opt COPY settings.json /opt

View File

@ -1,9 +1,5 @@
FROM nginx:1.20.1-alpine AS builder
FROM amd64/alpine FROM amd64/alpine
COPY --from=builder /etc/nginx/ /opt/confs/nginx
COPY ui/dependencies.sh /tmp COPY ui/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \
/tmp/dependencies.sh && \ /tmp/dependencies.sh && \
@ -11,6 +7,7 @@ RUN chmod +x /tmp/dependencies.sh && \
COPY gen/ /opt/gen COPY gen/ /opt/gen
COPY confs/site/ /opt/confs/site COPY confs/site/ /opt/confs/site
COPY confs/global/ /opt/confs/global
COPY ui/ /opt/entrypoint COPY ui/ /opt/entrypoint
COPY settings.json /opt COPY settings.json /opt

View File

@ -1,14 +1,11 @@
FROM alpine AS builder1 FROM alpine AS builder
ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-arm.tar.gz ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-arm.tar.gz
RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1
FROM nginx:1.20.1-alpine AS builder2
FROM arm32v7/alpine FROM arm32v7/alpine
COPY --from=builder1 qemu-arm-static /usr/bin COPY --from=builder qemu-arm-static /usr/bin
COPY --from=builder2 /etc/nginx/ /opt/confs/nginx
COPY ui/dependencies.sh /tmp COPY ui/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \
@ -17,6 +14,7 @@ RUN chmod +x /tmp/dependencies.sh && \
COPY gen/ /opt/gen COPY gen/ /opt/gen
COPY confs/site/ /opt/confs/site COPY confs/site/ /opt/confs/site
COPY confs/global/ /opt/confs/global
COPY ui/ /opt/entrypoint COPY ui/ /opt/entrypoint
COPY settings.json /opt COPY settings.json /opt

View File

@ -1,14 +1,11 @@
FROM alpine AS builder1 FROM alpine AS builder
ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-aarch64.tar.gz ENV QEMU_URL https://github.com/balena-io/qemu/releases/download/v4.0.0%2Bbalena2/qemu-4.0.0.balena2-aarch64.tar.gz
RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1 RUN apk add curl && curl -L ${QEMU_URL} | tar zxvf - -C . --strip-components 1
FROM nginx:1.20.1-alpine AS builder2
FROM arm64v8/alpine FROM arm64v8/alpine
COPY --from=builder1 qemu-aarch64-static /usr/bin COPY --from=builder qemu-aarch64-static /usr/bin
COPY --from=builder2 /etc/nginx/ /opt/confs/nginx
COPY ui/dependencies.sh /tmp COPY ui/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \
@ -17,6 +14,7 @@ RUN chmod +x /tmp/dependencies.sh && \
COPY gen/ /opt/gen COPY gen/ /opt/gen
COPY confs/site/ /opt/confs/site COPY confs/site/ /opt/confs/site
COPY confs/global/ /opt/confs/global
COPY ui/ /opt/entrypoint COPY ui/ /opt/entrypoint
COPY settings.json /opt COPY settings.json /opt

View File

@ -1,9 +1,5 @@
FROM nginx:1.20.1-alpine AS builder
FROM i386/alpine FROM i386/alpine
COPY --from=builder /etc/nginx/ /opt/confs/nginx
COPY ui/dependencies.sh /tmp COPY ui/dependencies.sh /tmp
RUN chmod +x /tmp/dependencies.sh && \ RUN chmod +x /tmp/dependencies.sh && \
/tmp/dependencies.sh && \ /tmp/dependencies.sh && \
@ -11,6 +7,7 @@ RUN chmod +x /tmp/dependencies.sh && \
COPY gen/ /opt/gen COPY gen/ /opt/gen
COPY confs/site/ /opt/confs/site COPY confs/site/ /opt/confs/site
COPY confs/global/ /opt/confs/global
COPY ui/ /opt/entrypoint COPY ui/ /opt/entrypoint
COPY settings.json /opt COPY settings.json /opt

View File

@ -5,7 +5,7 @@ from flask import Flask, render_template, current_app, request
from Docker import Docker from Docker import Docker
from Config import Config from Config import Config
import utils import utils
import os, json, re, traceback import os, json, re, copy, traceback
app = Flask(__name__, static_url_path="/", static_folder="static", template_folder="templates") app = Flask(__name__, static_url_path="/", static_folder="static", template_folder="templates")
ABSOLUTE_URI = "" ABSOLUTE_URI = ""
@ -76,7 +76,7 @@ def services():
raise Exception("Missing operation parameter on /services.") raise Exception("Missing operation parameter on /services.")
# Check variables # Check variables
variables = copy.deepcopy(request.form) variables = copy.deepcopy(request.form.to_dict())
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"] :
@ -98,10 +98,14 @@ def services():
operation = app.config["CONFIG"].edit_service(request.form["OLD_SERVER_NAME"], variables) operation = app.config["CONFIG"].edit_service(request.form["OLD_SERVER_NAME"], variables)
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
for instance in app.config["DOCKER"].get_instances() :
app.config["DOCKER"].reload_instance(instance.id)
# 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) + traceback.format_exc())

View File

@ -24,9 +24,9 @@
<div class="tab-pane fade {{ check.class }}" id="edit-{{ v["id"] }}-{{ id_server_name }}" role="tabpanel" aria-labelledby="edit-{{ v["id"] }}-{{ id_server_name }}-tab"> <div class="tab-pane fade {{ check.class }}" id="edit-{{ v["id"] }}-{{ id_server_name }}" role="tabpanel" aria-labelledby="edit-{{ v["id"] }}-{{ id_server_name }}-tab">
{% for param in v["params"] %} {% for param in v["params"] %}
<div class="row mb-3" id="form-edit-{{ id_server_name }}-{{ param["id"] }}"> <div class="row mb-3" id="form-edit-{{ id_server_name }}-{{ param["id"] }}">
{% if param["type"] != "multiple" %} {% if param["type"] != "multiple" and param["context"] == "multisite" %}
{{ form_service_gen("form-edit-" + id_server_name + "-" + param["id"], param["label"], param["type"], service[param["env"]], param["env"])|safe }} {{ form_service_gen("form-edit-" + id_server_name + "-" + param["id"], param["label"], param["type"], service[param["env"]], param["env"])|safe }}
{% else %} {% elif param["context"] == "multisite" %}
{{ form_service_gen_multiple("form-edit-" + id_server_name + "-" + param["id"], param["label"], param["params"])|safe }} {{ form_service_gen_multiple("form-edit-" + id_server_name + "-" + param["id"], param["label"], param["params"])|safe }}
{% if template_data.update({"javascript": template_data.javascript + form_service_gen_multiple_values("form-edit-" + id_server_name + "-" + param["id"], param["params"], service)}) %} {% if template_data.update({"javascript": template_data.javascript + form_service_gen_multiple_values("form-edit-" + id_server_name + "-" + param["id"], param["params"], service)}) %}
{% endif %} {% endif %}