NobGit
public nobgit read

NobMail

Based on mailcow: dockerized

Languages

Repository composition by tracked source files.

PHP
PHP 49% JavaScript 35% HTML 9% CSS 4% Shell 2% Python 1% Lua 0% Perl 0% Ruby 0% SCSS 0%
Create file Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git

Commit

[SOGo] fix custom html elements and wrong redirection

766c270b
FreddleSpl0it <[email protected]> 2 years, 5 months ago
data/conf/sogo/custom-sogo.js | 60 ++++++++++++++++++++++++-------------------
 data/web/sogo-auth.php        |  2 +-
 2 files changed, 34 insertions(+), 28 deletions(-)

Diff

diff --git a/data/conf/sogo/custom-sogo.js b/data/conf/sogo/custom-sogo.js
index 44afa299..0f1d5d34 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 = '<a class="md-icon-button md-button md-ink-ripple" aria-label="mailcow" href="/user" aria-hidden="false" tabindex="-1">' +
+            '<md-icon class="material-icons" role="img" aria-label="build">build</md-icon>' +
+            '</a><a class="md-icon-button md-button md-ink-ripple" aria-label="mailcow" href="#" onclick="mc_logout.submit()" aria-hidden="false" tabindex="-1">' +
+            '<md-icon class="material-icons" role="img" aria-label="settings_power">settings_power</md-icon>' +
+            '</a><form action="/" method="post" id="mc_logout"><input type="hidden" name="logout"></form>';
+        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 = '<a class="md-icon-button md-button md-ink-ripple" aria-label="mailcow" href="/user" aria-hidden="false" tabindex="-1">' +
-                '<md-icon class="material-icons" role="img" aria-label="build">build</md-icon>' +
-                '</a><a class="md-icon-button md-button md-ink-ripple" aria-label="mailcow" href="#" onclick="logout.submit()" aria-hidden="false" tabindex="-1">' +
-                '<md-icon class="material-icons" role="img" aria-label="settings_power">settings_power</md-icon>' +
-                '</a><form action="/" method="post" id="logout"><input type="hidden" name="logout"></form>';
-
-            toolbarElement.insertAdjacentHTML('beforeend', htmlCode);
-        }
-    });
+    observe();
 });
 
 // Custom SOGo JS
diff --git a/data/web/sogo-auth.php b/data/web/sogo-auth.php
index d93c1254..640a8e00 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