From 766c270b1fa5a634c10391d23830191fa71a2967 Mon Sep 17 00:00:00 2001 From: FreddleSpl0it Date: Fri, 23 Feb 2024 09:12:17 +0100 Subject: [PATCH] [SOGo] fix custom html elements and wrong redirection --- data/conf/sogo/custom-sogo.js | 60 +++++++++++++++++++---------------- data/web/sogo-auth.php | 2 +- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/data/conf/sogo/custom-sogo.js b/data/conf/sogo/custom-sogo.js index 44afa2998..0f1d5d342 100644 --- a/data/conf/sogo/custom-sogo.js +++ b/data/conf/sogo/custom-sogo.js @@ -6,42 +6,48 @@ document.addEventListener('DOMContentLoaded', function () { } angularReady = false; - // Wait for the Angular components to be initialized - function waitForAngularComponents(callback) { - const targetNode = document.body; + function observe() { + angularReady = toolbarExists(); + if (angularReady && !mcElementsExists()) addMCElements(); const observer = new MutationObserver(function(mutations) { - mutations.forEach(function(mutation) { - if (mutation.addedNodes.length > 0) { - const toolbarElement = document.body.querySelector('md-toolbar'); - if (toolbarElement) { - observer.disconnect(); - callback(); - } + if (!angularReady) { + mutations.forEach(function(mutation) { + if (mutation.addedNodes.length > 0) angularReady = toolbarExists(); + }); + } else if (angularReady && !mcElementsExists()) { + addMCElements(); } - }); }); + const targetNode = document.body; const config = { childList: true, subtree: true }; observer.observe(targetNode, config); } + function toolbarExists() { + const toolbarElement = document.body.querySelector('md-toolbar'); + if (toolbarElement) + return true; + else + return false; + } + function mcElementsExists() { + if (document.getElementById("mc_logout")) + return true; + else + return false; + } + function addMCElements() { + const toolbarElement = document.body.querySelector('.md-toolbar-tools.sg-toolbar-group-last.layout-align-end-center.layout-row'); + var htmlCode = '' + + 'build' + + '' + + 'settings_power' + + '
'; + toolbarElement.insertAdjacentHTML('beforeend', htmlCode); + } - // Usage - waitForAngularComponents(function() { - if (!angularReady){ - angularReady = true; - - const toolbarElement = document.body.querySelector('.md-toolbar-tools.sg-toolbar-group-last.layout-align-end-center.layout-row'); - - var htmlCode = '' + - 'build' + - '' + - 'settings_power' + - '
'; - - toolbarElement.insertAdjacentHTML('beforeend', htmlCode); - } - }); + observe(); }); // Custom SOGo JS diff --git a/data/web/sogo-auth.php b/data/web/sogo-auth.php index d93c12543..640a8e00c 100644 --- a/data/web/sogo-auth.php +++ b/data/web/sogo-auth.php @@ -72,7 +72,7 @@ elseif (isset($_GET['login'])) { } } } - header("Location: /SOGo/"); + header("Location: /"); exit; } // only check for admin-login on sogo GUI requests