Fix current_endpoint shenanigans in web UI

This commit is contained in:
Théophile Diot 2024-01-31 14:26:40 +01:00
parent e408acfa7d
commit bb29d3b1a0
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
7 changed files with 5 additions and 16 deletions

View file

@ -1260,7 +1260,7 @@ def upload_plugin():
@app.route("/plugins/<plugin>", methods=["GET", "POST"])
@login_required
def custom_plugin(plugin):
def custom_plugin(plugin: str):
message = ""
if not plugin_id_rx.match(plugin):
message = f'Invalid plugin id, "{plugin}" (must be between 1 and 64 characters, only letters, numbers, underscores and hyphens)'
@ -1270,14 +1270,14 @@ def custom_plugin(plugin):
return {"message": f'Invalid plugin id, "{plugin}" (must be between 1 and 64 characters, only letters, numbers, underscores and hyphens)'}, 400
if request.method == "GET":
plugin_id = request.args.get("plugin_id")
page = db.get_plugin_template(plugin_id)
page = db.get_plugin_template(plugin)
if page:
return render_template(
Environment(loader=FileSystemLoader(join(sep, "usr", "share", "bunkerweb", "ui", "templates") + "/")).from_string(page.decode("utf-8")),
dark_mode=app.config["DARK_MODE"],
username=current_user.get_id(),
current_endpoint=plugin,
**app.jinja_env.globals,
)

View file

@ -1,4 +1,4 @@
{% set current_endpoint = url_for(request.endpoint)[1:].split("/")[-1].strip()
{% set current_endpoint = current_endpoint or url_for(request.endpoint)[1:].split("/")[-1].strip()
%}
<head>

View file

@ -1,4 +1,4 @@
{% set current_endpoint = url_for(request.endpoint)[1:].split("/")[-1].strip().replace('_', ' ').replace('-', ' ')
{% set current_endpoint = current_endpoint or url_for(request.endpoint)[1:].split("/")[-1].strip().replace('_', ' ').replace('-', ' ')
%}
<!-- header -->

View file

@ -1,6 +1,3 @@
{% set current_endpoint = url_for(request.endpoint)[1:].split("/")[-1].strip()
%}
<!-- float button-->
<button
aria-controls="sidebar-menu"

View file

@ -1,6 +1,3 @@
{% set current_endpoint = url_for(request.endpoint)[1:].split("/")[-1].strip()
%}
<div class="navigation-wrap bg-custom start-header start-style">
<div class="container">
<div class="row">

View file

@ -1,5 +1,3 @@
{% set current_endpoint = url_for(request.endpoint)[1:].split("/")[-1].strip().replace('_', '-')
%}
{% set global_config = config["CONFIG"].get_config() %}
{% set plugins = config["CONFIG"].get_plugins() %}
<!-- plugin item -->

View file

@ -1,6 +1,3 @@
{% set current_endpoint = url_for(request.endpoint)[1:].split("/")[-1].strip().replace('_', '-')
%}
{% set plugins = config["CONFIG"].get_plugins() %}
<div data-{{current_endpoint}}-tabs class="col-span-12 grid grid-cols-12 {% if current_endpoint == 'services' %}mb-4{% endif %}">
<!-- desktop tabs -->