fix instances + add plugin custom page + format

* fix instances services adding condition for actions buttons
* update main.py to retrieve plugins page and update sidebar component to handle it + add default values to check
* start formatting settings data for services : add a only_multisite param to get only plugins with at least one multisite settings + update modes builder
This commit is contained in:
Jordan Blasenhauer 2024-08-08 14:42:17 +02:00
parent c61f0d1784
commit 997392da6f
23 changed files with 174 additions and 53 deletions

View file

@ -28,7 +28,7 @@ def advanced_mode_builder(templates: list[dict], plugins: list, global_config: d
{
"type": "Templates",
"data": {
"templates": get_forms(templates, plugins, settings, ("advanced",), is_new),
"templates": get_forms(templates, plugins, settings, ("advanced",), is_new, True),
"operation": "new" if is_new else "edit",
"oldServerName": service_name if service_name else "",
},

View file

@ -28,7 +28,7 @@ def easy_mode_builder(templates: list[dict], plugins: list, global_config: dict,
{
"type": "Templates",
"data": {
"templates": get_forms(templates, plugins, settings, ("easy",), is_new),
"templates": get_forms(templates, plugins, settings, ("easy",), is_new, True),
"operation": "new" if is_new else "edit",
"oldServerName": service_name if service_name else "",
},

View file

@ -37,7 +37,7 @@ def raw_mode_builder(templates: list[dict], plugins: list, global_config: dict,
{
"type": "Templates",
"data": {
"templates": get_forms(templates, plugins, settings, ("raw",), is_new),
"templates": get_forms(templates, plugins, settings, ("raw",), is_new, True),
"operation": "new" if is_new else "edit",
"oldServerName": service_name if service_name else "",
},

View file

@ -24,19 +24,51 @@ def get_service_settings(service_name: str, global_config: dict, total_config: d
return global_config
def get_forms(templates: list = [], plugins: list = [], settings: dict = {}, render_forms: tuple = ("advanced", "easy", "raw"), is_new: bool = False) -> dict:
def get_plugins_multisite(plugins: list) -> list:
# loop on plugins with list index
plugins_multisite = []
for index, plugin in enumerate(plugins):
multisite_settings = {}
# loop on settings
for setting, value in plugin.get("settings").items():
# check if setting is multisite
if value.get("context") != "multisite":
continue
# add multisite key to plugin
multisite_settings[setting] = value
# add multisite settings to plugin
if len(multisite_settings):
plugin_multisite = copy.deepcopy(plugin)
plugin_multisite["settings"] = multisite_settings
plugins_multisite.append(plugin_multisite)
return plugins
def get_forms(
templates: list = [],
plugins: list = [],
settings: dict = {},
render_forms: tuple = ("advanced", "easy", "raw"),
is_new: bool = False,
only_multisite: bool = False,
) -> dict:
"""
Will generate every needed form using templates, plugins and settings.
We will run on each plugins, set template value if one, and override by the custom settings value if exists.
We will format to fit each form type (easy, advanced, raw) in case
"""
# Copy of the plugins, and get the plugins by context if needed
# In services page, we want only multisite settings, but in global config we want both
plugins_base = get_plugins_multisite(plugins) if only_multisite else copy.deepcopy(plugins)
# Update SERVER_NAME to be empty if new
if is_new and "SERVER_NAME" in settings:
settings["SERVER_NAME"]["value"] = ""
if is_new and not "SERVER_NAME" in settings:
settings["SERVER_NAME"] = {"value": "", "method": "ui", "global": True}
settings["SERVER_NAME"] = {"value": "", "method": "ui", "global": False}
forms = {}
for form in render_forms:
@ -44,13 +76,13 @@ def get_forms(templates: list = [], plugins: list = [], settings: dict = {}, ren
for template in templates:
if "advanced" in forms:
forms["advanced"][template.get("name")] = set_advanced(template, plugins, settings, is_new)
forms["advanced"][template.get("name")] = set_advanced(template, plugins_base, settings, is_new)
if "raw" in forms:
forms["raw"][template.get("name")] = set_raw(template, plugins, settings, is_new)
forms["raw"][template.get("name")] = set_raw(template, plugins_base, settings, is_new)
if "easy" in forms:
forms["easy"][template.get("name")] = set_easy(template, plugins, settings, is_new)
forms["easy"][template.get("name")] = set_easy(template, plugins_base, settings, is_new)
return forms

View file

@ -202,6 +202,7 @@ onBeforeMount(() => {
? JSON.parse(dataEl.getAttribute(dataAtt))
: {};
menu.username = data?.username || "";
menu.pagePlugins = data?.plugins_page || [];
});
</script>
@ -365,13 +366,12 @@ onBeforeMount(() => {
:tabindex="
menu.isDesktop ? menuIndex : menu.isActive ? menuIndex : '-1'
"
target="_blank"
class="menu-page-plugin-anchor"
:href="`/plugins?plugin_id=${plugin.id}`"
:href="`plugins/${plugin.id}`"
>
<div aria-hidden="true" class="menu-page-plugin-svg-container">
<Icons
:iconName="plugin.type === 'pro' ? 'crown' : 'free'"
:iconName="plugin.type === 'pro' ? 'crown' : 'document'"
:color="plugin.type === 'pro' ? 'amber' : 'dark'"
/>
</div>

View file

@ -59,7 +59,7 @@ const groupEl = ref(null);
onMounted(() => {
group.class =
props.boutonGroupClass || groupEl.value.closest("[data-is]")
props.boutonGroupClass || groupEl?.value?.closest("[data-is]")
? `button-group-${groupEl.value
.closest("[data-is]")
.getAttribute("data-is")}`

View file

@ -65,6 +65,6 @@ const props = defineProps({
<Status :id="props.title" :status="props.status" />
<Title type="card" :title="props.title" />
<ListPairs :pairs="props.pairs" />
<ButtonGroup :buttons="props.buttons" />
<ButtonGroup v-if="props.buttons.length > 0" :buttons="props.buttons" />
</Container>
</template>

View file

@ -74,7 +74,7 @@ const textIconEl = ref(null);
onMounted(() => {
// Check if next sibling is a
const renderEl = textEl.value || textIconEl.value || null;
const isVoid = renderEl.closest('[data-is="void"]') ? "void" : "";
const isVoid = renderEl?.closest('[data-is="void"]') ? "void" : "";
text.class =
props.textClass || renderEl.closest("[data-is]")
? `text-${

View file

@ -9,13 +9,18 @@
<title>BunkerWeb | Bans</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'>
</div>
<div class="hidden"
data-server-builder='[{"type":"card","containerColumns":{"pc":6,"tablet":6,"mobile":12},"widgets":[{"type":"Instance","data":{"details":[{"key":"instances_hostname","value":"bunkerweb"},{"key":"instances_type","value":"manual"},{"key":"instances_status","value":"instances_active"}],"status":"success","title":"bunkerweb","buttons":[{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"reload","data-submit-form":"true"},"text":"action_reload","color":"warning","size":"normal"},{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"stop","data-submit-form":"true"},"text":"action_stop","color":"error","size":"normal"}]}}]}]'>
</div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'
></div>
<div
class="hidden"
data-server-builder='[{"type":"card","containerColumns":{"pc":6,"tablet":6,"mobile":12},"widgets":[{"type":"Instance","data":{"details":[{"key":"instances_hostname","value":"bunkerweb"},{"key":"instances_type","value":"manual"},{"key":"instances_status","value":"instances_active"}],"status":"success","title":"bunkerweb","buttons":[{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"reload","data-submit-form":"true"},"text":"action_reload","color":"warning","size":"normal"},{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"stop","data-submit-form":"true"},"text":"action_stop","color":"error","size":"normal"}]}}]}]'
></div>
<div id="app"></div>
<script type="module" src="bans.js"></script>
</body>

View file

@ -9,8 +9,14 @@
<title>BunkerWeb | DASHBOARD</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div class="hidden" data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'></div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'
></div>
<div id="app"></div>
<script type="module" src="dashboard.js"></script>
</body>

View file

@ -9,7 +9,10 @@
<title>BunkerWeb | Global config</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'

View file

@ -9,7 +9,10 @@
<title>BunkerWeb | Home</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "success", "message" : "Success feedback"}, {"type" : "error", "title" : "error", "message" : "Error feedback"}, {"type" : "warning", "title" : "warning", "message" : "Warning feedback"}, {"type" : "info", "title" : "info", "message" : "Info feedback"}]'

View file

@ -9,14 +9,17 @@
<title>BunkerWeb | Instances</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'
></div>
<div
class="hidden"
data-server-builder="W3sidHlwZSI6ICJjYXJkIiwgImNvbnRhaW5lckNvbHVtbnMiOiB7InBjIjogNiwgInRhYmxldCI6IDYsICJtb2JpbGUiOiAxMn0sICJ3aWRnZXRzIjogW3sidHlwZSI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Y6NTgifV0sICJzdGF0dXMiOiAiZXJyb3IiLCAidGl0bGUiOiAiYnVua2Vyd2ViIiwgImJ1dHRvbnMiOiBbXX19XX1d"
></div>
<div id="app"></div>
<script type="module" src="instances.js"></script>

View file

@ -9,7 +9,10 @@
<title>BunkerWeb | Jobs</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'

View file

@ -9,7 +9,10 @@
<title>BunkerWeb | Logs</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'

View file

@ -9,7 +9,10 @@
<title>BunkerWeb | Modes</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'

View file

@ -9,13 +9,18 @@
<title>BunkerWeb | Plugins</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'>
</div>
<div class="hidden"
data-server-builder='[{"type":"card","containerColumns":{"pc":6,"tablet":6,"mobile":12},"widgets":[{"type":"Instance","data":{"details":[{"key":"instances_hostname","value":"bunkerweb"},{"key":"instances_type","value":"manual"},{"key":"instances_status","value":"instances_active"}],"status":"success","title":"bunkerweb","buttons":[{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"reload","data-submit-form":"true"},"text":"action_reload","color":"warning","size":"normal"},{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"stop","data-submit-form":"true"},"text":"action_stop","color":"error","size":"normal"}]}}]}]'>
</div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'
></div>
<div
class="hidden"
data-server-builder='[{"type":"card","containerColumns":{"pc":6,"tablet":6,"mobile":12},"widgets":[{"type":"Instance","data":{"details":[{"key":"instances_hostname","value":"bunkerweb"},{"key":"instances_type","value":"manual"},{"key":"instances_status","value":"instances_active"}],"status":"success","title":"bunkerweb","buttons":[{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"reload","data-submit-form":"true"},"text":"action_reload","color":"warning","size":"normal"},{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"stop","data-submit-form":"true"},"text":"action_stop","color":"error","size":"normal"}]}}]}]'
></div>
<div id="app"></div>
<script type="module" src="plugins.js"></script>
</body>

View file

@ -9,13 +9,18 @@
<title>BunkerWeb | Reports</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'>
</div>
<div class="hidden"
data-server-builder='[{"type":"card","containerColumns":{"pc":6,"tablet":6,"mobile":12},"widgets":[{"type":"Instance","data":{"details":[{"key":"instances_hostname","value":"bunkerweb"},{"key":"instances_type","value":"manual"},{"key":"instances_status","value":"instances_active"}],"status":"success","title":"bunkerweb","buttons":[{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"reload","data-submit-form":"true"},"text":"action_reload","color":"warning","size":"normal"},{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"stop","data-submit-form":"true"},"text":"action_stop","color":"error","size":"normal"}]}}]}]'>
</div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'
></div>
<div
class="hidden"
data-server-builder='[{"type":"card","containerColumns":{"pc":6,"tablet":6,"mobile":12},"widgets":[{"type":"Instance","data":{"details":[{"key":"instances_hostname","value":"bunkerweb"},{"key":"instances_type","value":"manual"},{"key":"instances_status","value":"instances_active"}],"status":"success","title":"bunkerweb","buttons":[{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"reload","data-submit-form":"true"},"text":"action_reload","color":"warning","size":"normal"},{"attrs":{"data-form-INSTANCE_ID":"bunkerweb","data-form-operation":"stop","data-submit-form":"true"},"text":"action_stop","color":"error","size":"normal"}]}}]}]'
></div>
<div id="app"></div>
<script type="module" src="reports.js"></script>
</body>

View file

@ -9,7 +9,10 @@
<title>BunkerWeb | Services</title>
</head>
<body>
<div class="hidden" data-server-global='{"username" : "admin"}'></div>
<div
class="hidden"
data-server-global='{"username" : "admin", "plugins_page": [{"id" : "antibot", "name": "Antibot"}, {"id": "backup", "name" : "backup"}]}'
></div>
<div
class="hidden"
data-server-flash='[{"type" : "success", "title" : "title", "message" : "Success feedback"}, {"type" : "error", "title" : "title", "message" : "Error feedback"}, {"type" : "warning", "title" : "title", "message" : "Warning feedback"}, {"type" : "info", "title" : "title", "message" : "Info feedback"}]'

View file

@ -24,19 +24,51 @@ def get_service_settings(service_name: str, global_config: dict, total_config: d
return global_config
def get_forms(templates: list = [], plugins: list = [], settings: dict = {}, render_forms: tuple = ("advanced", "easy", "raw"), is_new: bool = False) -> dict:
def get_plugins_multisite(plugins: list) -> list:
# loop on plugins with list index
plugins_multisite = []
for index, plugin in enumerate(plugins):
multisite_settings = {}
# loop on settings
for setting, value in plugin.get("settings").items():
# check if setting is multisite
if value.get("context") != "multisite":
continue
# add multisite key to plugin
multisite_settings[setting] = value
# add multisite settings to plugin
if len(multisite_settings):
plugin_multisite = copy.deepcopy(plugin)
plugin_multisite["settings"] = multisite_settings
plugins_multisite.append(plugin_multisite)
return plugins
def get_forms(
templates: list = [],
plugins: list = [],
settings: dict = {},
render_forms: tuple = ("advanced", "easy", "raw"),
is_new: bool = False,
only_multisite: bool = False,
) -> dict:
"""
Will generate every needed form using templates, plugins and settings.
We will run on each plugins, set template value if one, and override by the custom settings value if exists.
We will format to fit each form type (easy, advanced, raw) in case
"""
# Copy of the plugins, and get the plugins by context if needed
# In services page, we want only multisite settings, but in global config we want both
plugins_base = get_plugins_multisite(plugins) if only_multisite else copy.deepcopy(plugins)
# Update SERVER_NAME to be empty if new
if is_new and "SERVER_NAME" in settings:
settings["SERVER_NAME"]["value"] = ""
if is_new and not "SERVER_NAME" in settings:
settings["SERVER_NAME"] = {"value": "", "method": "ui", "global": True}
settings["SERVER_NAME"] = {"value": "", "method": "ui", "global": False}
forms = {}
for form in render_forms:
@ -44,13 +76,13 @@ def get_forms(templates: list = [], plugins: list = [], settings: dict = {}, ren
for template in templates:
if "advanced" in forms:
forms["advanced"][template.get("name")] = set_advanced(template, plugins, settings, is_new)
forms["advanced"][template.get("name")] = set_advanced(template, plugins_base, settings, is_new)
if "raw" in forms:
forms["raw"][template.get("name")] = set_raw(template, plugins, settings, is_new)
forms["raw"][template.get("name")] = set_raw(template, plugins_base, settings, is_new)
if "easy" in forms:
forms["easy"][template.get("name")] = set_easy(template, plugins, settings, is_new)
forms["easy"][template.get("name")] = set_easy(template, plugins_base, settings, is_new)
return forms

View file

@ -10003,17 +10003,29 @@
},
"raw": {
"default": {
"MULTISITE": "yes",
"SERVER_NAME": "app1.example.com www.example.com",
"LOG_LEVEL": "info",
"API_WHITELIST_IP": "127.0.0.0/24 10.20.30.0/24",
"BUNKERWEB_INSTANCES": "bunkerweb",
"USE_BLACKLIST": "no",
"USE_BUNKERNET": "no",
"CORS_ALLOW_ORIGIN": "self",
"CROSS_ORIGIN_OPENER_POLICY": "same-origin",
"CROSS_ORIGIN_EMBEDDER_POLICY": "require-corp",
"CROSS_ORIGIN_RESOURCE_POLICY": "same-site",
"USE_CLIENT_CACHE": "yes",
"USE_GZIP": "yes",
"REMOVE_HEADERS": "Server Expect-CT X-Powered-By X-AspNet-Version X-AspNetMvc-Version Public-Key-Pins",
"KEEP_UPSTREAM_HEADERS": "Content-Security-Policy Permissions-Policy X-Frame-Options",
"STRICT_TRANSPORT_SECURITY": "max-age=31536000; includeSubDomains; preload",
"PERMISSIONS_POLICY": "accelerometer=(), ambient-light-sensor=(), attribution-reporting=(), autoplay=(), battery=(), bluetooth=(), browsing-topics=(), camera=(), compute-pressure=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), gamepad=(), geolocation=(), gyroscope=(), hid=(), identity-credentials-get=(), idle-detection=(), local-fonts=(), magnetometer=(), microphone=(), midi=(), otp-credentials=(), payment=(), picture-in-picture=(), publickey-credentials-create=(), publickey-credentials-get=(), screen-wake-lock=(), serial=(), speaker-selection=(), storage-access=(), usb=(), web-share=(), window-management=(), xr-spatial-tracking=()",
"DISABLE_DEFAULT_SERVER": "yes",
"SERVE_FILES": "no",
"SEND_ANONYMOUS_REPORT": "no",
"MODSECURITY_CRS_VERSION": "4",
"REVERSE_PROXY_HOST": "dzq"
"REVERSE_PROXY_HOST": "dzq",
"USE_WHITELIST": "no"
}
}
}

File diff suppressed because one or more lines are too long

View file

@ -544,9 +544,12 @@ def inject_variables():
flash("The last changes have been applied successfully.", "success")
app.data["CONFIG_CHANGED"] = False
# Keep only plugins with a page to display on sidebar
plugins_page = [{"id": plugin.get("id"), "name": plugin.get("name")} for plugin in app.bw_config.get_plugins() if plugin.get("page", False)]
# check that is value is in tuple
return dict(
data_server_global=json.dumps({"username": current_user.get_id() if current_user.is_authenticated else ""}),
data_server_global=json.dumps({"username": current_user.get_id() if current_user.is_authenticated else "", "plugins_page": plugins_page}),
script_nonce=app.config["SCRIPT_NONCE"],
is_pro_version=metadata["is_pro"],
pro_status=metadata["pro_status"],