ui - fix example, subpath behind reverse proxy and add socket proxy rights for swarm
This commit is contained in:
parent
0c1883472d
commit
dd7d1a2c78
@ -29,6 +29,7 @@ services:
|
||||
- admin.example.com_USE_REVERSE_PROXY=yes
|
||||
- admin.example.com_REVERSE_PROXY_URL=/admin/ # change it to something hard to guess
|
||||
- admin.example.com_REVERSE_PROXY_HOST=http://myui:5000/
|
||||
- admin.example.com_REVERSE_PROXY_HEADERS=X-Script-Name /admin # must match REVERSE_PROXY_URL
|
||||
- admin.example.com_USE_MODSECURITY=no
|
||||
labels:
|
||||
- "bunkerized-nginx.UI"
|
||||
@ -54,6 +55,8 @@ services:
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
environment:
|
||||
- CONTAINERS=1
|
||||
- SWARM=1
|
||||
- SERVICES=1
|
||||
|
||||
volumes:
|
||||
autoconf:
|
||||
|
||||
@ -7,12 +7,14 @@ from flask_wtf.csrf import CSRFProtect, CSRFError
|
||||
from src.Instances import Instances
|
||||
from src.User import User
|
||||
from src.Config import Config
|
||||
from src.ReverseProxied import ReverseProxied
|
||||
|
||||
import utils
|
||||
import os, json, re, copy, traceback
|
||||
|
||||
# Flask app
|
||||
app = Flask(__name__, static_url_path="/", static_folder="static", template_folder="templates")
|
||||
app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||
|
||||
# Set variables and instantiate objects
|
||||
vars = utils.get_variables()
|
||||
@ -50,7 +52,7 @@ def login() :
|
||||
if request.method == "POST" and "username" in request.form and "password" in request.form :
|
||||
if app.config["USER"].get_id() == request.form["username"] and app.config["USER"].check_password(request.form["password"]) :
|
||||
login_user(app.config["USER"])
|
||||
return redirect("/")
|
||||
return redirect(app.config["ABSOLUTE_URI"])
|
||||
else :
|
||||
fail = True
|
||||
if fail :
|
||||
@ -61,7 +63,7 @@ def login() :
|
||||
@login_required
|
||||
def logout() :
|
||||
logout_user()
|
||||
return redirect("/login")
|
||||
return redirect(app.config["ABSOLUTE_URI"] + "/login")
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/home')
|
||||
|
||||
@ -47,7 +47,6 @@ class Instances :
|
||||
|
||||
# Docker instances (containers or services)
|
||||
if self.__docker != None :
|
||||
if self.__docker.swarm == None :
|
||||
for instance in self.__docker.containers.list(all=True, filters={"label" : "bunkerized-nginx.UI"}) :
|
||||
id = instance.id
|
||||
name = instance.name
|
||||
@ -56,8 +55,8 @@ class Instances :
|
||||
if instance.status == "running" :
|
||||
status = "up"
|
||||
instances.append(self.__instance(id, name, type, status, instance))
|
||||
else :
|
||||
for instance in self.__docker.services.list(all=True, filters={"label" : "bunkerized-nginx.UI"}) :
|
||||
if self.__docker.swarm != None :
|
||||
for instance in self.__docker.services.list(filters={"label" : "bunkerized-nginx.UI"}) :
|
||||
id = instance.id
|
||||
name = instance.name
|
||||
type = "service"
|
||||
|
||||
17
ui/src/ReverseProxied.py
Normal file
17
ui/src/ReverseProxied.py
Normal file
@ -0,0 +1,17 @@
|
||||
class ReverseProxied(object):
|
||||
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
|
||||
if script_name:
|
||||
environ['SCRIPT_NAME'] = script_name
|
||||
path_info = environ['PATH_INFO']
|
||||
if path_info.startswith(script_name):
|
||||
environ['PATH_INFO'] = path_info[len(script_name):]
|
||||
|
||||
scheme = environ.get('HTTP_X_SCHEME', '')
|
||||
if scheme:
|
||||
environ['wsgi.url_scheme'] = scheme
|
||||
return self.app(environ, start_response)
|
||||
Loading…
x
Reference in New Issue
Block a user