Manual xo fixes and suppressions

Signed-off-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
XhmikosR
2025-02-23 07:57:38 +02:00
parent f8a0a1d4ec
commit f598a8e35c
13 changed files with 49 additions and 75 deletions

View File

@@ -156,9 +156,7 @@ const customTooltips = function (context) {
// Set Text // Set Text
if (tooltip.body) { if (tooltip.body) {
const titleLines = tooltip.title || []; const titleLines = tooltip.title || [];
const bodyLines = tooltip.body.map(bodyItem => { const bodyLines = tooltip.body.map(bodyItem => bodyItem.lines);
return bodyItem.lines;
});
let innerHtml = "<thead>"; let innerHtml = "<thead>";
for (const title of titleLines) { for (const title of titleLines) {
@@ -216,10 +214,10 @@ const customTooltips = function (context) {
tooltipX = offsetX + caretX; tooltipX = offsetX + caretX;
if (tooltip.yAlign === "top" || tooltip.yAlign === "bottom") { if (tooltip.yAlign === "top" || tooltip.yAlign === "bottom") {
switch (tooltip.xAlign) { switch (tooltip.xAlign) {
case "center": case "center": {
// set a minimal X position to 5px to prevent // set a minimal X position to 5px to prevent
// the tooltip to stick out left of the viewport // the tooltip to stick out left of the viewport
var minX = 5; const minX = 5;
if (2 * tooltipX < tooltipWidth + minX) { if (2 * tooltipX < tooltipWidth + minX) {
arrowX = tooltipX - minX; arrowX = tooltipX - minX;
tooltipX = minX; tooltipX = minX;
@@ -228,6 +226,8 @@ const customTooltips = function (context) {
} }
break; break;
}
case "left": case "left":
tooltipX -= arrowMinIndent; tooltipX -= arrowMinIndent;
arrowX = arrowMinIndent; arrowX = arrowMinIndent;

View File

@@ -7,7 +7,7 @@
/* global utils:false, moment:false */ /* global utils:false, moment:false */
const _isLoginPage = false; globalThis._isLoginPage = false;
const REFRESH_INTERVAL = { const REFRESH_INTERVAL = {
logs: 500, // 0.5 sec (logs page) logs: 500, // 0.5 sec (logs page)
@@ -587,7 +587,7 @@ function updateVersionInfo() {
} }
$(() => { $(() => {
if (!_isLoginPage) updateInfo(); if (!globalThis._isLoginPage) updateInfo();
const enaT = $("#enableTimer"); const enaT = $("#enableTimer");
const target = new Date(Number.parseInt(enaT.html(), 10)); const target = new Date(Number.parseInt(enaT.html(), 10));
const seconds = Math.round((target.getTime() - Date.now()) / 1000); const seconds = Math.round((target.getTime() - Date.now()) / 1000);
@@ -602,7 +602,7 @@ $(() => {
// Apply icheckbox/iradio style // Apply icheckbox/iradio style
applyCheckboxRadioStyle(); applyCheckboxRadioStyle();
if (!_isLoginPage) { if (!globalThis._isLoginPage) {
// Run check immediately after page loading ... // Run check immediately after page loading ...
utils.checkMessages(); utils.checkMessages();
// ... and then periodically // ... and then periodically
@@ -707,7 +707,7 @@ function addAdvancedInfo() {
const advancedInfoTarget = $("#advanced-info"); const advancedInfoTarget = $("#advanced-info");
const isTLS = location.protocol === "https:"; const isTLS = location.protocol === "https:";
const clientIP = advancedInfoSource.data("client-ip"); const clientIP = advancedInfoSource.data("client-ip");
const XForwardedFor = globalThis.atob(advancedInfoSource.data("xff") ?? ""); const XForwardedFor = globalThis.atob(advancedInfoSource.data("xff") || "") || null;
const starttime = Number.parseFloat(advancedInfoSource.data("starttime")); const starttime = Number.parseFloat(advancedInfoSource.data("starttime"));
const endtime = Number.parseFloat(advancedInfoSource.data("endtime")); const endtime = Number.parseFloat(advancedInfoSource.data("endtime"));
const totaltime = 1e3 * (endtime - starttime); const totaltime = 1e3 * (endtime - starttime);
@@ -725,7 +725,7 @@ function addAdvancedInfo() {
); );
// Add client IP info // Add client IP info
$("#client-id").text(XForwardedFor ? XForwardedFor : clientIP); $("#client-id").text(XForwardedFor ?? clientIP);
if (XForwardedFor) { if (XForwardedFor) {
// If X-Forwarded-For is set, show the X-Forwarded-For in italics and add // If X-Forwarded-For is set, show the X-Forwarded-For in italics and add
// the real client IP as tooltip // the real client IP as tooltip

View File

@@ -172,10 +172,7 @@ function initTable() {
const selectEl = $("#multiselect_" + dataId, row); const selectEl = $("#multiselect_" + dataId, row);
// Add all known groups // Add all known groups
for (const group of groups) { for (const group of groups) {
let dataSub = ""; const dataSub = group.enabled ? "" : 'data-subtext="(disabled)"';
if (!group.enabled) {
dataSub = 'data-subtext="(disabled)"';
}
selectEl.append( selectEl.append(
$("<option " + dataSub + "/>") $("<option " + dataSub + "/>")
@@ -184,6 +181,8 @@ function initTable() {
); );
} }
const applyBtn = "#btn_apply_" + dataId;
// Select assigned groups // Select assigned groups
selectEl.val(data.groups); selectEl.val(data.groups);
// Initialize bootstrap-select // Initialize bootstrap-select
@@ -228,8 +227,6 @@ function initTable() {
' class="btn btn-block btn-sm" disabled>Apply</button>' ' class="btn btn-block btn-sm" disabled>Apply</button>'
); );
var applyBtn = "#btn_apply_" + dataId;
const button = const button =
'<button type="button" class="btn btn-danger btn-xs" id="deleteClient_' + '<button type="button" class="btn btn-danger btn-xs" id="deleteClient_' +
dataId + dataId +
@@ -358,14 +355,12 @@ function addClient() {
// Check if the user wants to add multiple IPs (space or newline separated) // Check if the user wants to add multiple IPs (space or newline separated)
// If so, split the input and store it in an array // If so, split the input and store it in an array
let ips = $("#select") const ips = $("#select")
.val() .val()
.trim() .trim()
.split(/[\s,]+/); .split(/[\s,]+/)
// Remove empty elements // Remove empty elements
ips = ips.filter(el => { .filter(el => el !== "");
return el !== "";
});
const ipStr = JSON.stringify(ips); const ipStr = JSON.stringify(ips);
// Validate input, can be: // Validate input, can be:

View File

@@ -17,10 +17,7 @@ function populateGroupSelect(selectEl) {
// Add all known groups // Add all known groups
for (const group of groups) { for (const group of groups) {
let dataSub = ""; const dataSub = group.enabled ? "" : 'data-subtext="(disabled)"';
if (!group.enabled) {
dataSub = 'data-subtext="(disabled)"';
}
selectEl.append( selectEl.append(
$("<option " + dataSub + "/>") $("<option " + dataSub + "/>")

View File

@@ -50,6 +50,9 @@ $(() => {
// Show a list of suggested domains based on the user's input // Show a list of suggested domains based on the user's input
function showSuggestDomains(value) { function showSuggestDomains(value) {
const newDomainEl = $("#new_domain");
const suggestDomainEl = $("#suggest_domains");
function createButton(hostname) { function createButton(hostname) {
// Purposefully omit 'btn' class to save space on padding // Purposefully omit 'btn' class to save space on padding
return $('<button type="button" class="btn-link btn-block text-right">') return $('<button type="button" class="btn-link btn-block text-right">')
@@ -60,9 +63,6 @@ function showSuggestDomains(value) {
}); });
} }
var newDomainEl = $("#new_domain");
const suggestDomainEl = $("#suggest_domains");
try { try {
const parts = new URL(value).hostname.split("."); const parts = new URL(value).hostname.split(".");
const table = $("<table>"); const table = $("<table>");
@@ -228,10 +228,7 @@ function initTable() {
const selectEl = $("#multiselect_" + dataId, row); const selectEl = $("#multiselect_" + dataId, row);
// Add all known groups // Add all known groups
for (const group of groups) { for (const group of groups) {
let dataSub = ""; const dataSub = group.enabled ? "" : 'data-subtext="(disabled)"';
if (!group.enabled) {
dataSub = 'data-subtext="(disabled)"';
}
selectEl.append( selectEl.append(
$("<option " + dataSub + "/>") $("<option " + dataSub + "/>")
@@ -490,9 +487,7 @@ function addDomain() {
// If so, split the input and store it in an array // If so, split the input and store it in an array
let domains = domainEl.val().split(/\s+/); let domains = domainEl.val().split(/\s+/);
// Remove empty elements // Remove empty elements
domains = domains.filter(el => { domains = domains.filter(el => el !== "");
return el !== "";
});
const domainStr = JSON.stringify(domains); const domainStr = JSON.stringify(domains);
utils.disableAll(); utils.disableAll();

View File

@@ -281,10 +281,7 @@ function initTable() {
const selectEl = $("#multiselect_" + dataId, row); const selectEl = $("#multiselect_" + dataId, row);
// Add all known groups // Add all known groups
for (const group of groups) { for (const group of groups) {
let dataSub = ""; const dataSub = group.enabled ? "" : 'data-subtext="(disabled)"';
if (!group.enabled) {
dataSub = 'data-subtext="(disabled)"';
}
selectEl.append( selectEl.append(
$("<option " + dataSub + "/>") $("<option " + dataSub + "/>")
@@ -506,9 +503,7 @@ function addList(event) {
.val() .val()
.split(/[\s,]+/); .split(/[\s,]+/);
// Remove empty elements // Remove empty elements
addresses = addresses.filter(el => { addresses = addresses.filter(el => el !== "");
return el !== "";
});
const addressestr = JSON.stringify(addresses); const addressestr = JSON.stringify(addresses);
utils.disableAll(); utils.disableAll();

View File

@@ -242,13 +242,9 @@ function addGroup() {
.escapeHtml($("#new_name")) .escapeHtml($("#new_name"))
.val() .val()
.match(/(?:[^\s"]+|"[^"]*")+/g) .match(/(?:[^\s"]+|"[^"]*")+/g)
.map(name => { .map(name => name.replaceAll(/(^"|"$)/g, ""));
return name.replaceAll(/(^"|"$)/g, "");
});
// Remove empty elements // Remove empty elements
names = names.filter(el => { names = names.filter(el => el !== "");
return el !== "";
});
const groupStr = JSON.stringify(names); const groupStr = JSON.stringify(names);
utils.disableAll(); utils.disableAll();

View File

@@ -7,7 +7,7 @@
/* global utils:false, NProgress:false */ /* global utils:false, NProgress:false */
const _isLoginPage = true; globalThis._isLoginPage = true;
function redirect() { function redirect() {
// Login succeeded or not needed (empty password) // Login succeeded or not needed (empty password)

View File

@@ -13,9 +13,7 @@ function addAllowedValues(allowed) {
return ( return (
"<p>Available options:</p><ul><li>" + "<p>Available options:</p><ul><li>" +
allowed allowed
.map(option => { .map(option => "<code>" + option.item + "</code>: " + utils.escapeHtml(option.description))
return "<code>" + option.item + "</code>: " + utils.escapeHtml(option.description);
})
.join("</li><li>") + .join("</li><li>") +
"</li></ul>" "</li></ul>"
); );

View File

@@ -212,13 +212,13 @@ function deleteMultipleSessions(ids) {
// Exploit prevention: Return early for non-numeric IDs // Exploit prevention: Return early for non-numeric IDs
for (const id of ids) { for (const id of ids) {
// TODO Fix eslint
// eslint-disable-next-line unicorn/prefer-number-properties
if (Object.hasOwn(ids, id) && isNaN(ids[id])) return; if (Object.hasOwn(ids, id) && isNaN(ids[id])) return;
} }
// Convert all ids to integers // Convert all ids to integers
ids = ids.map(value => { ids = ids.map(value => Number.parseInt(value, 10));
return Number.parseInt(value, 10);
});
// Check if own session is selected and remove it when deleting multiple // Check if own session is selected and remove it when deleting multiple
// We need this only when multiple sessions are removed to ensure we do not // We need this only when multiple sessions are removed to ensure we do not
@@ -228,9 +228,7 @@ function deleteMultipleSessions(ids) {
if (ids.includes(ownSessionID) && ids.length > 1) { if (ids.includes(ownSessionID) && ids.length > 1) {
ownSessionDelete = true; ownSessionDelete = true;
// Strip own session ID from array // Strip own session ID from array
ids = ids.filter(value => { ids = ids.filter(value => value !== ownSessionID);
return value !== ownSessionID;
});
} }
// Loop through IDs and delete them // Loop through IDs and delete them

View File

@@ -241,6 +241,8 @@ $(document).ready(() => {
utils.disableAll(); utils.disableAll();
let elem = $("#Cdomain").val() + "," + $("#Ctarget").val(); let elem = $("#Cdomain").val() + "," + $("#Ctarget").val();
const ttlVal = Number.parseInt($("#Cttl").val(), 10); const ttlVal = Number.parseInt($("#Cttl").val(), 10);
// TODO Fix eslint
// eslint-disable-next-line unicorn/prefer-number-properties
if (isFinite(ttlVal) && ttlVal >= 0) elem += "," + ttlVal; if (isFinite(ttlVal) && ttlVal >= 0) elem += "," + ttlVal;
const url = const url =
document.body.dataset.apiurl + "/config/dns/cnameRecords/" + encodeURIComponent(elem); document.body.dataset.apiurl + "/config/dns/cnameRecords/" + encodeURIComponent(elem);

View File

@@ -69,6 +69,8 @@ function formatFTL(line, prio) {
return `<span class="${prioClass}">${utils.escapeHtml(prio)}</span> ${line}`; return `<span class="${prioClass}">${utils.escapeHtml(prio)}</span> ${line}`;
} }
let gAutoScrolling;
// Function that asks the API for new data // Function that asks the API for new data
function getData() { function getData() {
// Only update when spinner is spinning // Only update when spinner is spinning
@@ -168,7 +170,7 @@ function getData() {
}); });
} }
var gAutoScrolling = true; gAutoScrolling = true;
$("#output").on("scroll", () => { $("#output").on("scroll", () => {
// Check if we are at the bottom of the output // Check if we are at the bottom of the output
// //

View File

@@ -30,9 +30,7 @@ function escapeHtml(text) {
// Return early when text is not a string // Return early when text is not a string
if (typeof text !== "string") return text; if (typeof text !== "string") return text;
return text.replaceAll(/[&<>"']/g, m => { return text.replaceAll(/[&<>"']/g, m => map[m]);
return map[m];
});
} }
function unescapeHtml(text) { function unescapeHtml(text) {
@@ -53,22 +51,19 @@ function unescapeHtml(text) {
if (text === null) return null; if (text === null) return null;
return text.replaceAll(/&(?:amp|lt|gt|quot|#039|Uuml|uuml|Auml|auml|Ouml|ouml|szlig);/g, m => { return text.replaceAll(
return map[m]; /&(?:amp|lt|gt|quot|#039|Uuml|uuml|Auml|auml|Ouml|ouml|szlig);/g,
}); m => map[m]
);
} }
// Helper function for converting Objects to Arrays after sorting the keys // Helper function for converting Objects to Arrays after sorting the keys
function objectToArray(obj) { function objectToArray(obj) {
const arr = []; const arr = [];
const idx = []; const idx = [];
const keys = Object.keys(obj); const sortedKeys = Object.keys(obj).sort((a, b) => a - b);
keys.sort((a, b) => { for (const key of sortedKeys) {
return a - b;
});
for (const key of keys) {
arr.push(obj[key]); arr.push(obj[key]);
idx.push(key); idx.push(key);
} }
@@ -297,7 +292,8 @@ function stateLoadCallback(itemName) {
data = JSON.parse(data); data = JSON.parse(data);
// Clear possible filtering settings // Clear possible filtering settings
for (const [index, value] of data.columns.entries()) { // TODO Maybe Object.values() is meant to be used here?
for (const [index, _value] of data.columns.entries()) {
data.columns[index].search.search = ""; data.columns[index].search.search = "";
} }
@@ -566,7 +562,7 @@ function hexDecode(string) {
return back; return back;
} }
function listAlert(type, items, data) { function listsAlert(type, items, data) {
// Show simple success message if there is no "processed" object in "data" or // Show simple success message if there is no "processed" object in "data" or
// if all items were processed successfully // if all items were processed successfully
if (data.processed === undefined || data.processed.success.length === items.length) { if (data.processed === undefined || data.processed.success.length === items.length) {
@@ -751,7 +747,7 @@ globalThis.utils = (function () {
parseQueryString, parseQueryString,
hexEncode, hexEncode,
hexDecode, hexDecode,
listsAlert: listAlert, listsAlert,
loadingOverlay, loadingOverlay,
setTimer, setTimer,
setInter, setInter,