[#645] Fix errors when using a server name with multiple values in web UI

This commit is contained in:
Théophile Diot 2023-10-10 16:49:51 +02:00
parent 47a7e16800
commit 4a9fdba42d
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
4 changed files with 17 additions and 16 deletions

View file

@ -244,7 +244,7 @@ def manage_bunkerweb(method: str, *args, operation: str = "reloads"):
if listdir(service_custom_conf):
move(
service_custom_conf,
service_custom_conf.replace(f"{sep}{args[1]}", f"{sep}{args[2]}").replace(join(sep, "etc"), join(sep, "var", "tmp")),
service_custom_conf.replace(f"{sep}{args[1].split(' ')[0]}", f"{sep}{args[2].split(' ')[0]}").replace(join(sep, "etc"), join(sep, "var", "tmp")),
)
moved = True
operation, error = app.config["CONFIG"].edit_service(args[1], args[0])
@ -257,7 +257,7 @@ def manage_bunkerweb(method: str, *args, operation: str = "reloads"):
app.config["TO_FLASH"].append({"content": operation, "type": "success"})
if editing and moved and args[1] != args[2] and service_custom_confs:
for tmp_service_custom_conf in glob(join(sep, "var", "tmp", "bunkerweb", "configs", "*", args[2])):
for tmp_service_custom_conf in glob(join(sep, "var", "tmp", "bunkerweb", "configs", "*", args[2].split(" ")[0])):
move(
tmp_service_custom_conf,
tmp_service_custom_conf.replace(
@ -526,12 +526,7 @@ def services():
Thread(
target=manage_bunkerweb,
name="Reloading instances",
args=(
"services",
variables,
request.form.get("OLD_SERVER_NAME", "").split(" ")[0],
variables.get("SERVER_NAME", "").split(" ")[0],
),
args=("services", variables, request.form.get("OLD_SERVER_NAME", ""), variables.get("SERVER_NAME", "")),
kwargs={"operation": request.form["operation"]},
).start()
@ -554,6 +549,7 @@ def services():
{
"SERVER_NAME": {
"value": service["SERVER_NAME"]["value"].split(" ")[0],
"full_value": service["SERVER_NAME"]["value"],
"method": service["SERVER_NAME"]["method"],
},
"USE_REVERSE_PROXY": service["USE_REVERSE_PROXY"],

View file

@ -231,12 +231,12 @@ class Config:
if changed_server_name:
for k in deepcopy(config):
if k.startswith(old_server_name):
if k.startswith(old_server_name_splitted[0]):
config.pop(k)
self.__gen_conf(config, services)
return (
f"Configuration for {old_server_name.split(' ')[0]} has been edited.",
f"Configuration for {old_server_name_splitted[0]} has been edited.",
0,
)

View file

@ -64,7 +64,11 @@ class ServiceModal {
) {
//set form info and right form
const [action, serviceName] = this.getActionAndServName(e.target);
this.setForm(action, serviceName, this.formNewEdit);
const oldServName = e.target
.closest("[data-services-service]")
.querySelector("[data-old-service-name]")
.getAttribute("data-value");
this.setForm(action, serviceName, oldServName, this.formNewEdit);
//get service data and parse it
//multiple type logic is launch at same time on relate class
const servicesSettings = e.target
@ -87,7 +91,7 @@ class ServiceModal {
) {
//set form info and right form
const [action, serviceName] = this.getActionAndServName(e.target);
this.setForm(action, serviceName, this.formNewEdit);
this.setForm(action, serviceName, serviceName, this.formNewEdit);
//set default value with method default
this.setSettingsDefault();
//server name is unset
@ -110,7 +114,7 @@ class ServiceModal {
) {
//set form info and right form
const [action, serviceName] = this.getActionAndServName(e.target);
this.setForm(action, serviceName, this.formDelete);
this.setForm(action, serviceName, serviceName, this.formDelete);
//show modal
this.openModal();
}
@ -202,7 +206,7 @@ class ServiceModal {
}
}
setForm(action, serviceName, formEl) {
setForm(action, serviceName, oldServName, formEl) {
this.modalTitle.textContent = `${action} ${serviceName}`;
formEl.setAttribute("id", `form-${action}-${serviceName}`);
const opeInp = formEl.querySelector(`input[name="operation"]`);
@ -212,8 +216,8 @@ class ServiceModal {
if (action === "edit" || action === "new") {
this.showNewEditForm();
const oldNameInp = formEl.querySelector(`input[name="OLD_SERVER_NAME"]`);
oldNameInp.setAttribute("value", serviceName);
oldNameInp.value = serviceName;
oldNameInp.setAttribute("value", oldServName);
oldNameInp.value = oldServName;
}
if (action === "delete") {

View file

@ -32,6 +32,7 @@
class="dark:brightness-110 overflow-hidden hover:scale-102 transition col-span-12 lg:col-span-6 3xl:col-span-4 p-4 w-full shadow-md break-words bg-white dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border"
>
<div data-services-settings class="hidden" data-value="{{service['settings']}}"></div>
<div data-old-service-name class="hidden" data-value="{{service['SERVER_NAME']['full_value']}}"></div>
<h5 class="transition duration-300 ease-in-out text-center sm:text-left mb-1 font-bold dark:text-white/90">
{{ service["SERVER_NAME"]['value'] }}
</h5>