diff --git a/ui/Dockerfile b/ui/Dockerfile index 550e944..7219923 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -1,9 +1,8 @@ FROM alpine -COPY ui/dependencies.sh /tmp -RUN chmod +x /tmp/dependencies.sh && \ - /tmp/dependencies.sh && \ - rm -f /tmp/dependencies.sh +RUN apk add py3-pip bash +COPY ui/requirements.txt /tmp +RUN pip3 install -r /tmp/requirements.txt COPY gen/ /opt/bunkerized-nginx/gen COPY confs/site/ /opt/bunkerized-nginx/confs/site diff --git a/ui/dependencies.sh b/ui/dependencies.sh deleted file mode 100644 index 6588f63..0000000 --- a/ui/dependencies.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -apk add py3-pip bash -pip3 install docker flask flask-login requests gunicorn diff --git a/ui/entrypoint.py b/ui/entrypoint.py index 65413b6..203814f 100644 --- a/ui/entrypoint.py +++ b/ui/entrypoint.py @@ -2,6 +2,7 @@ from flask import Flask, render_template, current_app, request, redirect from flask_login import LoginManager, login_required, login_user, logout_user +from flask_wtf.csrf import CSRFProtect, CSRFError from src.Instances import Instances from src.User import User @@ -33,11 +34,17 @@ login_manager.init_app(app) login_manager.login_view = "login" user = User(vars["ADMIN_USERNAME"], vars["ADMIN_PASSWORD"]) app.config["USER"] = user - @login_manager.user_loader def load_user(user_id): return User(user_id, vars["ADMIN_PASSWORD"]) +# CSRF protection +csrf = CSRFProtect() +csrf.init_app(app) +@app.errorhandler(CSRFError) +def handle_csrf_error(e): + return render_template("error.html", title="Error", error="Wrong CSRF token !"), 401 + @app.route('/login', methods=["GET", "POST"]) def login() : fail = False diff --git a/ui/requirements.txt b/ui/requirements.txt index 7a71572..c3df929 100644 --- a/ui/requirements.txt +++ b/ui/requirements.txt @@ -3,4 +3,5 @@ requests docker flask-login bcrypt -gunicorn \ No newline at end of file +gunicorn +Flask-WTF \ No newline at end of file diff --git a/ui/templates/error.html b/ui/templates/error.html index a4247c8..e5927c4 100644 --- a/ui/templates/error.html +++ b/ui/templates/error.html @@ -2,13 +2,9 @@ {% block content %} -
-
-
- Something went wrong...
- {{ error }} -
+
+ Something went wrong...

+ {{ error }}
-
{% endblock %} diff --git a/ui/templates/instances.html b/ui/templates/instances.html index 494c793..aa11bbc 100644 --- a/ui/templates/instances.html +++ b/ui/templates/instances.html @@ -25,6 +25,7 @@
+
diff --git a/ui/templates/login.html b/ui/templates/login.html index 96ba982..3f637f4 100644 --- a/ui/templates/login.html +++ b/ui/templates/login.html @@ -9,7 +9,13 @@

Authentication required

+ {% if fail %} + + {% endif %}
+
@@ -22,5 +28,4 @@
- -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/ui/templates/services-delete.html b/ui/templates/services-delete.html index 35f01b1..06e9483 100644 --- a/ui/templates/services-delete.html +++ b/ui/templates/services-delete.html @@ -8,6 +8,7 @@ diff --git a/ui/templates/services-edit.html b/ui/templates/services-edit.html index bef7aaa..cad24bd 100644 --- a/ui/templates/services-edit.html +++ b/ui/templates/services-edit.html @@ -17,6 +17,7 @@ {% endfor %}
+
{% set check = {"class": "show active"} %} diff --git a/ui/templates/services-new.html b/ui/templates/services-new.html index c5285d7..3281462 100644 --- a/ui/templates/services-new.html +++ b/ui/templates/services-new.html @@ -17,6 +17,7 @@ {% endfor %} +
{% set check = {"class": "show active"} %} {% for k, v in config["CONFIG"].get_settings().items() %}