From 5289476937fe72f445a95747c5540ab515b8a08a Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 16 Feb 2023 22:45:11 -0800 Subject: [PATCH 1/3] Pass csrf token for unifi login --- src/widgets/unifi/proxy.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/widgets/unifi/proxy.js b/src/widgets/unifi/proxy.js index 9fbeafde..f8d55822 100644 --- a/src/widgets/unifi/proxy.js +++ b/src/widgets/unifi/proxy.js @@ -42,12 +42,15 @@ async function getWidget(req) { return widget; } -async function login(widget) { +async function login(widget, csrfToken) { const endpoint = (widget.prefix === udmpPrefix) ? "auth/login" : "login"; const api = widgets?.[widget.type]?.api?.replace("{prefix}", ""); // no prefix for login url const loginUrl = new URL(formatApiCall(api, { endpoint, ...widget })); const loginBody = { username: widget.username, password: widget.password, remember: true }; const headers = { "Content-Type": "application/json" }; + if (csrfToken) { + headers["X-CSRF-TOKEN"] = csrfToken; + } const [status, contentType, data, responseHeaders] = await httpProxy(loginUrl, { method: "POST", body: JSON.stringify(loginBody), @@ -70,6 +73,7 @@ export default async function unifiProxyHandler(req, res) { let [status, contentType, data, responseHeaders] = []; let prefix = cache.get(`${prefixCacheKey}.${service}`); + let csrfToken; if (prefix === null) { // auto detect if we're talking to a UDM Pro, and cache the result so that we // don't make two requests each time data from Unifi is required @@ -77,12 +81,12 @@ export default async function unifiProxyHandler(req, res) { prefix = ""; if (responseHeaders?.["x-csrf-token"]) { prefix = udmpPrefix; + csrfToken = responseHeaders["x-csrf-token"]; } cache.put(`${prefixCacheKey}.${service}`, prefix); } widget.prefix = prefix; - const { endpoint } = req.query; const url = new URL(formatApiCall(api, { endpoint, ...widget })); const params = { method: "GET", headers: {} }; @@ -92,7 +96,10 @@ export default async function unifiProxyHandler(req, res) { if (status === 401) { logger.debug("Unifi isn't logged in or rejected the reqeust, attempting login."); - [status, contentType, data, responseHeaders] = await login(widget); + if (responseHeaders?.["x-csrf-token"]) { + csrfToken = responseHeaders["x-csrf-token"]; + } + [status, contentType, data, responseHeaders] = await login(widget, csrfToken); if (status !== 200) { logger.error("HTTP %d logging in to Unifi. Data: %s", status, data); From 9b037ce34953ad4e678151fab0b0ee42eb265522 Mon Sep 17 00:00:00 2001 From: gallegonovato Date: Fri, 17 Feb 2023 10:55:12 +0000 Subject: [PATCH 2/3] Translated using Weblate (Spanish) Currently translated at 100.0% (343 of 343 strings) Translation: Homepage/Homepage Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/es/ --- public/locales/es/common.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/public/locales/es/common.json b/public/locales/es/common.json index 4b28e4ad..c8163566 100644 --- a/public/locales/es/common.json +++ b/public/locales/es/common.json @@ -420,10 +420,10 @@ "series": "Serie" }, "octoprint": { - "temp_bed": "Bed temp", + "temp_bed": "temperatura de la plataforma", "printer_state": "Status", - "temp_tool": "Tool temp", - "job_completion": "Completion" + "temp_tool": "Herramienta de temperatura", + "job_completion": "Finalización" }, "cloudflared": { "origin_ip": "IP de origen", @@ -482,9 +482,9 @@ "alertstriggered": "Alertas activadas" }, "nextcloud": { - "cpuload": "Cpu Load", - "memoryusage": "Memory Usage", - "freespace": "Free Space", - "activeusers": "Active Users" + "cpuload": "Carga de la CPU", + "memoryusage": "Uso de la memoria", + "freespace": "Espacio libre", + "activeusers": "Usuarios activos" } } From 806b7f3cab4ac9c0a69648792f21981b70a30765 Mon Sep 17 00:00:00 2001 From: Nonoss117 Date: Fri, 17 Feb 2023 06:27:57 +0000 Subject: [PATCH 3/3] Translated using Weblate (French) Currently translated at 100.0% (343 of 343 strings) Translation: Homepage/Homepage Translate-URL: https://hosted.weblate.org/projects/homepage/homepage/fr/ --- public/locales/fr/common.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/locales/fr/common.json b/public/locales/fr/common.json index e0d98400..4cb38731 100644 --- a/public/locales/fr/common.json +++ b/public/locales/fr/common.json @@ -482,9 +482,9 @@ "alertstriggered": "Alertes déclenchées" }, "nextcloud": { - "freespace": "Free Space", - "activeusers": "Active Users", - "cpuload": "Cpu Load", - "memoryusage": "Memory Usage" + "freespace": "Espace Libre", + "activeusers": "Utilisateurs Actifs", + "cpuload": "Charge Cpu", + "memoryusage": "Utilisation Mémoire" } }