From 57e5908312c6805f18e310f9a28d574782c3ca87 Mon Sep 17 00:00:00 2001 From: Willard Nilges Date: Tue, 21 Jan 2025 01:12:49 -0500 Subject: [PATCH] Move iframe escape logic to onAdminPanelLoad --- src/meshweb/static/admin/iframe_check.js | 7 ------- src/meshweb/static/admin/map.js | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/meshweb/static/admin/iframe_check.js b/src/meshweb/static/admin/iframe_check.js index 8abd9976..be471a53 100644 --- a/src/meshweb/static/admin/iframe_check.js +++ b/src/meshweb/static/admin/iframe_check.js @@ -4,13 +4,6 @@ async function checkIframed() { // If we are, do nothing if (inIframe) { - // ...Unless the iframe is at the login page, in which case, redirect the parent - // to the login - const iframeLocation = window.location.href; - if (iframeLocation.includes("login")) { - window.top.location.href = "/admin/login/"; - } - return; } diff --git a/src/meshweb/static/admin/map.js b/src/meshweb/static/admin/map.js index 508a34da..41ea3548 100644 --- a/src/meshweb/static/admin/map.js +++ b/src/meshweb/static/admin/map.js @@ -246,18 +246,25 @@ async function updateMapLocation(url) { // Helper function to wrap everything that needs to happen when the admin panel // loads async function onAdminPanelLoad() { - const adminPanelIframeUrl = admin_panel_iframe.contentWindow.location.href; + const adminPanelIframeUrl = new URL(admin_panel_iframe.contentWindow.location.href); + + // If the admin panel iframe leaves the admin panel (by logging out, going to homescreen, etc) + // we should leave this iframed view and go there. + const escURLs = ["login", "password_reset"] + var shouldEscape = escURLs.some(url => adminPanelIframeUrl.pathname.includes(url)); + if (!adminPanelIframeUrl.pathname.includes("admin") || shouldEscape) { + window.location.href = adminPanelIframeUrl; + } // Save the new admin location. We do this here because it means that the admin panel has // recently reloaded. - const adminPanelIframeLastPageVisited = new URL(adminPanelIframeUrl).pathname; - localStorage.setItem(MESHDB_LAST_PAGE_VISITED, adminPanelIframeLastPageVisited); + localStorage.setItem(MESHDB_LAST_PAGE_VISITED, adminPanelIframeUrl.pathname); // Update the URL bar in the browser for viz - window.history.pushState("MeshDB Admin Panel", "", adminPanelIframeLastPageVisited); + window.history.pushState("MeshDB Admin Panel", "", adminPanelIframeUrl.pathname); // Finally, update the map view - updateMapLocation(adminPanelIframeUrl); + updateMapLocation(adminPanelIframeUrl.toString()); } // Configures the listener that updates the map based on admin panel activity