Skip to content

Commit

Permalink
Use NGINX mode in all editors while ModSecurity highlighting syntaxes…
Browse files Browse the repository at this point in the history
… aren't available
  • Loading branch information
TheophileDiot committed Oct 2, 2024
1 parent 7fc869a commit 91637a9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
39 changes: 19 additions & 20 deletions src/ui/app/static/js/pages/config_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ $(document).ready(function () {
$typeDropdownItems.each(function () {
const item = $(this);
item.toggle(
selectedService === "no service" ||
item.data("context") === "multisite",
selectedService === "no service" || item.data("context") === "multisite"
);
});
};
Expand All @@ -87,13 +86,13 @@ $(document).ready(function () {
if (visibleItems === 0) {
if ($serviceDropdownMenu.find(".no-service-items").length === 0) {
$serviceDropdownMenu.append(
'<li class="no-service-items dropdown-item text-muted">No Item</li>',
'<li class="no-service-items dropdown-item text-muted">No Item</li>'
);
}
} else {
$serviceDropdownMenu.find(".no-service-items").remove();
}
}, 50),
}, 50)
);

$(document).on("hidden.bs.dropdown", "#select-service", function () {
Expand All @@ -108,15 +107,15 @@ $(document).ready(function () {
$(`#config-type-${selectedType}`).data("context") !== "multisite"
) {
const firstMultisiteType = $(
`#types-dropdown-menu li.nav-item[data-context="multisite"]`,
`#types-dropdown-menu li.nav-item[data-context="multisite"]`
).first();
$("#select-type")
.parent()
.attr(
"data-bs-original-title",
`Switched to ${firstMultisiteType
.text()
.trim()} as ${selectedType} is not a valid multisite type.`,
.trim()} as ${selectedType} is not a valid multisite type.`
)
.tooltip("show");

Expand All @@ -133,12 +132,13 @@ $(document).ready(function () {
});

$typeDropdownItems.on("click", function () {
selectedType = $(this).text().trim();
if (selectedType.startsWith("CRS") || selectedType.startsWith("MODSEC")) {
editor.session.setMode("ace/mode/text"); // TODO: Support ModSecurity
} else {
editor.session.setMode("ace/mode/nginx");
}
editor.session.setMode("ace/mode/nginx");
// selectedType = $(this).text().trim();
// if (selectedType.startsWith("CRS") || selectedType.startsWith("MODSEC")) {
// editor.session.setMode("ace/mode/text"); // TODO: Support ModSecurity
// } else {
// editor.session.setMode("ace/mode/nginx");
// }
});

$(".save-config").on("click", function () {
Expand Down Expand Up @@ -167,14 +167,13 @@ $(document).ready(function () {
if (!configName) {
errorMessage = "A custom configuration name is required.";
isValid = false;
} else if (pattern && !new RegExp(pattern).test(configName))
isValid = false;
} else if (pattern && !new RegExp(pattern).test(configName)) isValid = false;

if (!isValid) {
$configInput
.attr(
"data-bs-original-title",
errorMessage || "Please enter a valid configuration name.",
errorMessage || "Please enter a valid configuration name."
)
.tooltip("show");

Expand All @@ -196,35 +195,35 @@ $(document).ready(function () {
type: "hidden",
name: "service",
value: $("<div>").text(selectedService).html(),
}),
})
);
form.append(
$("<input>", {
type: "hidden",
name: "type",
value: $("<div>").text(selectedType).html(),
}),
})
);
form.append(
$("<input>", {
type: "hidden",
name: "name",
value: $("<div>").text(configName).html(),
}),
})
);
form.append(
$("<input>", {
type: "hidden",
name: "value",
value: $("<div>").text(value).html(),
}),
})
);
form.append(
$("<input>", {
type: "hidden",
name: "csrf_token",
value: $("<div>").text($("#csrf_token").val()).html(), // Sanitize the value
}),
})
);

$(window).off("beforeunload");
Expand Down
57 changes: 29 additions & 28 deletions src/ui/app/static/js/plugins-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ $(document).ready(() => {
if ($collapseContainer.length && !$collapseContainer.hasClass("show")) {
// Expand the multiple setting group if it's collapsed
const toggleButton = $(
`[data-bs-target="#${$collapseContainer.attr("id")}"]`,
`[data-bs-target="#${$collapseContainer.attr("id")}"]`
);
toggleButton.trigger("click");
}
Expand Down Expand Up @@ -195,7 +195,7 @@ $(document).ready(() => {
let $feedback = $input.next(".invalid-feedback");
if (!$feedback.length) {
$feedback = $('<div class="invalid-feedback"></div>').insertAfter(
$input,
$input
);
}

Expand Down Expand Up @@ -229,7 +229,7 @@ $(document).ready(() => {
type: "hidden",
name: name,
value: $("<div>").text(value).html(), // Sanitize the value
}),
})
);
};

Expand Down Expand Up @@ -400,13 +400,13 @@ $(document).ready(() => {
if (visibleItems === 0) {
if ($pluginDropdownMenu.find(".no-plugin-items").length === 0) {
$pluginDropdownMenu.append(
'<li class="no-plugin-items dropdown-item text-muted">No Item</li>',
'<li class="no-plugin-items dropdown-item text-muted">No Item</li>'
);
}
} else {
$pluginDropdownMenu.find(".no-plugin-items").remove();
}
}, 50),
}, 50)
);

$("#select-template").on("click", () => $templateSearch.focus());
Expand All @@ -431,13 +431,13 @@ $(document).ready(() => {
if (visibleItems === 0) {
if ($templateDropdownMenu.find(".no-template-items").length === 0) {
$templateDropdownMenu.append(
'<li class="no-template-items dropdown-item text-muted">No Item</li>',
'<li class="no-template-items dropdown-item text-muted">No Item</li>'
);
}
} else {
$templateDropdownMenu.find(".no-template-items").remove();
}
}, 50),
}, 50)
);

$(document).on("hidden.bs.dropdown", "#select-plugin", function () {
Expand All @@ -453,21 +453,21 @@ $(document).ready(() => {
"shown.bs.tab",
(e) => {
handleModeChange($(e.target).data("bs-target"));
},
}
);

$('#plugins-dropdown-menu button[data-bs-toggle="tab"]').on(
"shown.bs.tab",
(e) => {
handleTabChange($(e.target).data("bs-target"));
},
}
);

$('#templates-dropdown-menu button[data-bs-toggle="tab"]').on(
"shown.bs.tab",
(e) => {
handleTabChange($(e.target).data("bs-target"));
},
}
);

$(document).on("input", ".plugin-setting", function () {
Expand Down Expand Up @@ -553,23 +553,23 @@ $(document).ready(() => {
if (matchedPlugin) {
// Automatically switch to the plugin tab
$(`button[data-bs-target="#navs-plugins-${matchedPlugin}"]`).tab(
"show",
"show"
);

// Highlight all matched settings
if (matchedSettings.length > 0) {
highlightSettings(matchedSettings, 1000);
}
}
}, 100),
}, 100)
);

$(document).on("click", ".show-multiple", function () {
const toggleText = $(this).text().trim() === "SHOW" ? "HIDE" : "SHOW";
$(this).html(
`<i class="bx bx-${
toggleText === "SHOW" ? "hide" : "show-alt"
} bx-sm"></i>&nbsp;${toggleText}`,
} bx-sm"></i>&nbsp;${toggleText}`
);
});

Expand All @@ -584,7 +584,7 @@ $(document).ready(() => {
$(this)
.find(".multiple-collapse")
.attr("id")
.replace(`${multipleId}-`, ""),
.replace(`${multipleId}-`, "")
);
})
.get()
Expand Down Expand Up @@ -696,7 +696,7 @@ $(document).ready(() => {
$(this)
.find(".multiple-collapse")
.attr("id")
.replace(`${multipleId}-`, ""),
.replace(`${multipleId}-`, "")
);
if (containerSuffix > suffix) {
$(this).before(multipleClone); // Insert before the first container with a higher suffix
Expand Down Expand Up @@ -797,7 +797,7 @@ $(document).ready(() => {
$(".toggle-draft").html(
`<i class="bx bx-sm bx-${
isDraft ? "globe" : "file-blank"
} bx-sm"></i>&nbsp;${isDraft ? "Online" : "Draft"}`,
} bx-sm"></i>&nbsp;${isDraft ? "Online" : "Draft"}`
);
});

Expand Down Expand Up @@ -961,7 +961,7 @@ $(document).ready(() => {
.parent()
.attr(
"title",
"Cannot remove because one or more settings are disabled",
"Cannot remove because one or more settings are disabled"
);

new bootstrap.Tooltip(
Expand All @@ -970,7 +970,7 @@ $(document).ready(() => {
.get(0),
{
placement: "top",
},
}
);
}
});
Expand All @@ -986,7 +986,7 @@ $(document).ready(() => {

if (currentMode === "easy" && currentTemplate !== "high") {
$(`button[data-bs-target="#navs-templates-${currentTemplate}"]`).tab(
"show",
"show"
);
}

Expand All @@ -1012,7 +1012,7 @@ $(document).ready(() => {
const hash = window.location.hash;
if (hash) {
const targetTab = $(
`button[data-bs-target="#navs-plugins-${hash.substring(1)}"]`,
`button[data-bs-target="#navs-plugins-${hash.substring(1)}"]`
);
if (targetTab.length) targetTab.tab("show");
}
Expand All @@ -1029,7 +1029,7 @@ $(document).ready(() => {
$pluginTypeSelect.val("all");
} else
$(`button[data-bs-target="#navs-plugins-${currentPlugin}"]`).tab(
"show",
"show"
);

if (currentPlugin !== "general") {
Expand All @@ -1053,7 +1053,7 @@ $(document).ready(() => {
feedbackToast
.find("div.toast-body")
.html(
"<p>As the service method is set to autoconf, the configuration is locked. <div class='fw-bolder'>Any changes made will not be saved.</div><div class='fst-italic'>This is to prevent conflicts with the autoconf and the web UI.</div></p>",
"<p>As the service method is set to autoconf, the configuration is locked. <div class='fw-bolder'>Any changes made will not be saved.</div><div class='fst-italic'>This is to prevent conflicts with the autoconf and the web UI.</div></p>"
);
feedbackToast.attr("data-bs-autohide", "false");
feedbackToast.appendTo("#feedback-toast-container"); // Ensure the toast is appended to the container
Expand All @@ -1066,12 +1066,13 @@ $(document).ready(() => {
const editor = ace.edit(this);
editor.setTheme("ace/theme/cloud9_day"); // cloud9_night when dark mode is supported

const language = $(this).data("language"); // TODO: Support ModSecurity
if (language === "NGINX") {
editor.session.setMode("ace/mode/nginx");
} else {
editor.session.setMode("ace/mode/text"); // Default mode if language is unrecognized
}
editor.session.setMode("ace/mode/nginx");
// const language = $(this).data("language"); // TODO: Support ModSecurity
// if (language === "NGINX") {
// editor.session.setMode("ace/mode/nginx");
// } else {
// editor.session.setMode("ace/mode/text"); // Default mode if language is unrecognized
// }

const method = $(this).data("method");
if (method !== "ui") {
Expand Down

0 comments on commit 91637a9

Please sign in to comment.