feat: add reverse proxy URL handling in setup and update UI templates

This commit is contained in:
Théophile Diot 2024-12-04 13:29:48 +01:00
parent a8b064cfd2
commit 17ee5443ea
No known key found for this signature in database
GPG key ID: FA995104A0BA376A
4 changed files with 20 additions and 7 deletions

View file

@ -30,6 +30,7 @@ def setup_page():
"MULTISITE",
"USE_UI",
"UI_HOST",
"REVERSE_PROXY_URL",
"AUTO_LETS_ENCRYPT",
"USE_LETS_ENCRYPT_STAGING",
"EMAIL_LETS_ENCRYPT",
@ -46,12 +47,14 @@ def setup_page():
admin_user = DB.get_ui_user()
ui_reverse_proxy = False
ui_reverse_proxy = None
ui_reverse_proxy_url = None
for server_name in db_config["SERVER_NAME"].split(" "):
if server_name and db_config.get(f"{server_name}_USE_UI", db_config.get("USE_UI", "no")) == "yes":
if admin_user:
return redirect(url_for("login.login_page"), 301)
ui_reverse_proxy = True
ui_reverse_proxy = server_name
ui_reverse_proxy_url = db_config.get(f"{server_name}_REVERSE_PROXY_URL", db_config.get("REVERSE_PROXY_URL", "/"))
break
if request.method == "POST":
@ -220,6 +223,7 @@ def setup_page():
"setup.html",
ui_user=admin_user,
ui_reverse_proxy=ui_reverse_proxy,
ui_reverse_proxy_url=ui_reverse_proxy_url,
username=getenv("ADMIN_USERNAME", ""),
password=getenv("ADMIN_PASSWORD", ""),
ui_host=db_config.get("UI_HOST", getenv("UI_HOST", "")),

View file

@ -319,6 +319,7 @@ $(document).ready(() => {
if (
!uiUser &&
currentStep === 2 &&
$("#EMAIL_LETS_ENCRYPT").length &&
$("#EMAIL_LETS_ENCRYPT").val().trim() === ""
) {
$("#EMAIL_LETS_ENCRYPT").val($("#email").val().trim());
@ -526,8 +527,8 @@ $(document).ready(() => {
$(document).on(
"input",
".plugin-setting",
debounce(function () {
const $this = $(this);
debounce(function (event) {
const $this = $(event.target);
const pattern = $this.attr("pattern");
const value = $this.val();
const isValid = pattern ? new RegExp(pattern).test(value) : true;

View file

@ -179,7 +179,7 @@
<script src="{{ url_for('static', filename='libs/ace/src-min/ace.js') }}"
nonce="{{ script_nonce }}"></script>
{% endif %}
{% if current_endpoint in ("loading", "instances") or current_endpoint != "plugins" and "plugins" in request.path %}
{% if current_endpoint in ("setup", "loading", "instances") or current_endpoint != "plugins" and "plugins" in request.path %}
<script src="{{ url_for('static', filename='libs/lottie-player/lottie-player.min.js') }}"
nonce="{{ script_nonce }}"></script>
{% endif %}

View file

@ -815,6 +815,14 @@
</div>
</div>
{% else %}
<input id="SERVER_NAME"
name="SERVER_NAME"
type="hidden"
value="{{ ui_reverse_proxy }}" />
<input id="REVERSE_PROXY_URL"
name="REVERSE_PROXY_URL"
type="hidden"
value="{{ ui_reverse_proxy_url }}" />
<p class="text-center relative w-full p-2 text-primary rounded-lg fw-bold">
↪️ A reverse proxy is already configured for the web interface, please proceed to the next step
</p>
@ -1025,8 +1033,8 @@
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content bg-transparent border-0 shadow-none">
<div class="modal-body text-center">
<div class="spinner-border text-bw-green" role="status">
<span class="visually-hidden">Loading...</span>
<div class="d-flex justify-content-center align-items-center w-100">
<lottie-player src="{{ url_for('static', filename='json/periscop.min.json') }}" background="transparent" speed="1" style="width: 300px; height: 300px;" class="img-fluid" loop autoplay></lottie-player>
</div>
<p class="mt-3 text-white">Setting up your BunkerWeb, please wait...</p>
</div>