mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
now check if metrics plugin is activated
This commit is contained in:
parent
f2e5a7c1fa
commit
65e9f96587
12 changed files with 119 additions and 67 deletions
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
<!-- info-->
|
||||
<div
|
||||
class="h-fit transition hover:scale-102 col-span-12 md:col-span-6 2xl:col-span-4 3xl:col-span-3 p-4 relative min-w-0 break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
<!-- info-->
|
||||
<div
|
||||
class="h-fit transition hover:scale-102 col-span-12 md:col-span-6 2xl:col-span-4 3xl:col-span-3 p-4 relative min-w-0 break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
<!-- info-->
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
<!-- info-->
|
||||
<div
|
||||
class="h-fit transition hover:scale-102 col-span-12 md:col-span-6 2xl:col-span-4 3xl:col-span-3 p-4 relative min-w-0 break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
<!-- info-->
|
||||
<div
|
||||
class="h-fit transition hover:scale-102 col-span-12 md:col-span-6 2xl:col-span-4 3xl:col-span-3 p-4 relative min-w-0 break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
<!-- info-->
|
||||
<div
|
||||
class="h-fit transition hover:scale-102 col-span-12 md:col-span-4 2xl:col-span-3 p-4 relative min-w-0 break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
|
||||
<!-- info-->
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
<!-- info-->
|
||||
<div
|
||||
class="h-fit transition hover:scale-102 col-span-12 md:col-span-4 2xl:col-span-3 p-4 relative min-w-0 break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used and is_metrics %}
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
<!-- info-->
|
||||
<div
|
||||
|
|
@ -132,5 +134,45 @@
|
|||
},
|
||||
});
|
||||
</script>
|
||||
{% else %}
|
||||
<div
|
||||
class="h-fit transition hover:scale-102 col-span-12 md:col-span-6 2xl:col-span-4 3xl:col-span-3 p-4 relative min-w-0 break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border"
|
||||
>
|
||||
<div class="flex justify-between">
|
||||
<h5 class="mb-2 font-bold dark:text-white/90">Deactivated</h5>
|
||||
<!-- icon -->
|
||||
<div
|
||||
role="img"
|
||||
class="dark:brightness-90 inline-block w-12 h-12 text-center rounded-circle bg-yellow-500"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="1.5"
|
||||
stroke="currentColor"
|
||||
class="scale-75 leading-none text-lg relative fill-yellow-500 stroke-white"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M12 9v3.75m9-.75a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 3.75h.008v.008H12v-.008Z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<!-- end icon -->
|
||||
</div>
|
||||
|
||||
<div class="mx-1 flex justify-start items-center my-2">
|
||||
<p
|
||||
data-info
|
||||
class="transition duration-300 ease-in-out mb-0 font-sans text-sm leading-normal dark:text-gray-100 dark:opacity-80"
|
||||
>
|
||||
This plugin need to be activated to get metrics.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end info -->
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
|
||||
<!-- info-->
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
/>
|
||||
|
||||
<div class="col-span-12 grid grid-cols-12 gap-4">
|
||||
{% if is_used %}
|
||||
{% if is_used and is_metrics %}
|
||||
|
||||
<!-- info-->
|
||||
<div
|
||||
|
|
|
|||
124
src/ui/main.py
124
src/ui/main.py
|
|
@ -1270,63 +1270,75 @@ def custom_plugin(plugin: str):
|
|||
return message, 400
|
||||
return {"message": f'Invalid plugin id, "{plugin}" (must be between 1 and 64 characters, only letters, numbers, underscores and hyphens)'}, 400
|
||||
|
||||
# Get current plugin.json
|
||||
plugins = app.config["CONFIG"].get_plugins()
|
||||
# Case we ware looking for a plugin template
|
||||
# We need to check if a page exists, and if it does, we need to check if the plugin is activated and metrics are on
|
||||
if request.method == "GET":
|
||||
|
||||
curr_plugin = {}
|
||||
plugin_id = None
|
||||
for plug in plugins:
|
||||
if plug["id"] == plugin:
|
||||
plugin_id = plug["id"]
|
||||
curr_plugin = plug
|
||||
break
|
||||
# Check template
|
||||
page = db.get_plugin_template(plugin)
|
||||
|
||||
if not plugin_id:
|
||||
message = f'Plugin "{plugin}" not found'
|
||||
app.logger.error(message)
|
||||
if request.method == "GET":
|
||||
if not page:
|
||||
message = f'The plugin "{plugin}" does not have a template'
|
||||
app.logger.error(message)
|
||||
return message, 404
|
||||
return {"message": f'Plugin "{plugin}" not found'}, 404
|
||||
|
||||
# Case template, prepare data
|
||||
plugins = app.config["CONFIG"].get_plugins()
|
||||
plugin_id = None
|
||||
curr_plugin = {}
|
||||
is_used = False
|
||||
use_key = False
|
||||
is_metrics_on = False
|
||||
context = "multisite"
|
||||
|
||||
# Get USE_<NAME> if exists
|
||||
# Check if the plugin is used by one service
|
||||
config = app.config["CONFIG"].get_config(methods=False)
|
||||
use_key = False
|
||||
is_used = False
|
||||
context = "multisite"
|
||||
for plug in plugins:
|
||||
if plug["id"] == plugin:
|
||||
plugin_id = plug["id"]
|
||||
curr_plugin = plug
|
||||
break
|
||||
|
||||
# {plugin_id: [[setting_name, setting_false], ...]}
|
||||
specific_cases = {
|
||||
"limit": [["USE_LIMIT_REQ", "no"], ["USE_LIMIT_CONN", "no"]],
|
||||
"misc": [["DISABLE_DEFAULT_SERVER", "no"], ["ALLOWED_METHODS", ""]],
|
||||
"modsecurity": [["USE_MODSECURITY", "no"]],
|
||||
"realip": [["USE_REALIP", "no"]],
|
||||
"reverseproxy": [["USE_REVERSE_PROXY", "no"]],
|
||||
"selfsigned": [["GENERATE_SELF_SIGNED_SSL", "no"]],
|
||||
"letsencrypt": [["AUTO_LETS_ENCRYPT", "no"]],
|
||||
"country": [["BLACKLIST_COUNTRY", ""], ["WHITELIST_COUNTRY", ""]],
|
||||
}
|
||||
# Case no plugin found
|
||||
if plugin_id is None:
|
||||
message = f'Plugin "{plugin}" not found'
|
||||
app.logger.error(message)
|
||||
return message, 404
|
||||
|
||||
config = app.config["CONFIG"].get_config(methods=False)
|
||||
|
||||
# Check if we are using metrics
|
||||
for service in config.get("SERVER_NAME", "").split(" "):
|
||||
# specific case
|
||||
if config.get(f"{service}_USE_METRICS", "no") != "no":
|
||||
is_metrics_on = True
|
||||
break
|
||||
|
||||
# {plugin_id: [[setting_name, setting_false], ...]}
|
||||
specific_cases = {
|
||||
"limit": [["USE_LIMIT_REQ", "no"], ["USE_LIMIT_CONN", "no"]],
|
||||
"misc": [["DISABLE_DEFAULT_SERVER", "no"], ["ALLOWED_METHODS", ""]],
|
||||
"modsecurity": [["USE_MODSECURITY", "no"]],
|
||||
"realip": [["USE_REALIP", "no"]],
|
||||
"reverseproxy": [["USE_REVERSE_PROXY", "no"]],
|
||||
"selfsigned": [["GENERATE_SELF_SIGNED_SSL", "no"]],
|
||||
"letsencrypt": [["AUTO_LETS_ENCRYPT", "no"]],
|
||||
"country": [["BLACKLIST_COUNTRY", ""], ["WHITELIST_COUNTRY", ""]],
|
||||
}
|
||||
|
||||
# specific cases
|
||||
for key, data in curr_plugin["settings"].items():
|
||||
# specific cases
|
||||
if plugin_id in specific_cases:
|
||||
use_key = "SPECIFIC"
|
||||
context = data["context"]
|
||||
break
|
||||
for key, data in curr_plugin["settings"].items():
|
||||
# specific cases
|
||||
if plugin_id in specific_cases:
|
||||
use_key = "SPECIFIC"
|
||||
context = data["context"]
|
||||
break
|
||||
|
||||
# default case (one USE_)
|
||||
if key.upper().startswith("USE_"):
|
||||
use_key = key
|
||||
context = data["context"]
|
||||
break
|
||||
# default case (one USE_)
|
||||
if key.upper().startswith("USE_"):
|
||||
use_key = key
|
||||
context = data["context"]
|
||||
break
|
||||
|
||||
# Case no USE_<NAME>, it means always show
|
||||
if not use_key:
|
||||
is_used = True
|
||||
|
||||
# Case USE_<NAME>, it means show only if used by one service
|
||||
if use_key and not is_used:
|
||||
# Case USE_<NAME>, it means show only if used by one service
|
||||
if context == "global":
|
||||
if plugin_id in specific_cases:
|
||||
for key in specific_cases[plugin_id]:
|
||||
|
|
@ -1336,8 +1348,11 @@ def custom_plugin(plugin: str):
|
|||
is_used = True
|
||||
break
|
||||
|
||||
is_used = config.get(use_key, "no") != "no"
|
||||
else:
|
||||
if config.get(use_key, "no") != "no":
|
||||
is_used = True
|
||||
|
||||
|
||||
if context == "multisite":
|
||||
for service in config.get("SERVER_NAME", "").split(" "):
|
||||
# specific case
|
||||
if plugin_id in specific_cases:
|
||||
|
|
@ -1352,11 +1367,8 @@ def custom_plugin(plugin: str):
|
|||
if config.get(f"{service}_{use_key}", "no") != "no":
|
||||
is_used = True
|
||||
break
|
||||
|
||||
|
||||
if request.method == "GET":
|
||||
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"],
|
||||
|
|
@ -1364,14 +1376,12 @@ def custom_plugin(plugin: str):
|
|||
current_endpoint=plugin,
|
||||
plugin=curr_plugin,
|
||||
is_used=is_used,
|
||||
is_metrics=is_metrics_on,
|
||||
**app.jinja_env.globals,
|
||||
is_pro_version=PRO_VERSION,
|
||||
plugins_pro=PRO_PLUGINS_LIST,
|
||||
)
|
||||
|
||||
message = f'The plugin "{plugin}" does not have a template'
|
||||
app.logger.error(message)
|
||||
return message, 404
|
||||
|
||||
module = db.get_plugin_actions(plugin)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue