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

[Web] load public ip on click and add curl timeout

9727e408
FreddleSpl0it <[email protected]> 3 years, 7 months ago
data/web/js/site/debug.js     | 49 ++++++++++++++++++++++++++++++-------------
 data/web/json_api.php         |  4 ++++
 data/web/lang/lang.de-de.json |  2 ++
 data/web/lang/lang.en-gb.json |  2 ++
 data/web/templates/debug.twig | 10 +++++++--
 5 files changed, 50 insertions(+), 17 deletions(-)

Diff

diff --git a/data/web/js/site/debug.js b/data/web/js/site/debug.js
index 85e6b789..ea7b9fd3 100644
--- a/data/web/js/site/debug.js
+++ b/data/web/js/site/debug.js
@@ -51,7 +51,40 @@ $(document).ready(function() {
     showVersionModal("Version " + mailcow_info.version_tag, mailcow_info.version_tag);
   })
   // get public ips
-  get_public_ips();
+  $("#host_show_ip").click(function(){  
+    $("#host_show_ip").find(".text").addClass("d-none");
+    $("#host_show_ip").find(".spinner-border").removeClass("d-none");
+
+    window.fetch("/api/v1/get/status/host/ip", { method:'GET', cache:'no-cache' }).then(function(response) {
+      return response.json();
+    }).then(function(data) {
+      console.log(data);
+
+      // display host ips
+      if (data.ipv4)
+        $("#host_ipv4").text(data.ipv4);
+      if (data.ipv6)
+        $("#host_ipv6").text(data.ipv6);
+
+      $("#host_show_ip").addClass("d-none");
+      $("#host_show_ip").find(".text").removeClass("d-none");
+      $("#host_show_ip").find(".spinner-border").addClass("d-none");
+      $("#host_ipv4").removeClass("d-none");
+      $("#host_ipv6").removeClass("d-none");
+      $("#host_ipv6").removeClass("text-danger");
+      $("#host_ipv4").addClass("d-block");
+      $("#host_ipv6").addClass("d-block");
+    }).catch(function(error){
+      console.log(error);
+      
+      $("#host_ipv6").removeClass("d-none");
+      $("#host_ipv6").addClass("d-block");
+      $("#host_ipv6").addClass("text-danger");
+      $("#host_ipv6").text(lang_debug.error_show_ip);
+      $("#host_show_ip").find(".text").removeClass("d-none");
+      $("#host_show_ip").find(".spinner-border").addClass("d-none");
+    });
+  });
   update_container_stats();
 });
 jQuery(function($){
@@ -1224,20 +1257,6 @@ function update_container_stats(timeout=5){
   // run again in n seconds
   setTimeout(update_container_stats, timeout * 1000);
 }
-// get public ips
-function get_public_ips(){
-  window.fetch("/api/v1/get/status/host/ip", {method:'GET',cache:'no-cache'}).then(function(response) {
-    return response.json();
-  }).then(function(data) {
-    console.log(data);
-
-    // display host ips
-    if (data.ipv4)
-      $("#host_ipv4").text(data.ipv4);
-    if (data.ipv6)
-      $("#host_ipv6").text(data.ipv6);
-  });
-}
 // format hosts uptime seconds to readable string
 function formatUptime(seconds){
   seconds = Number(seconds);
diff --git a/data/web/json_api.php b/data/web/json_api.php
index 79b6bfd5..0d3dbb2f 100644
--- a/data/web/json_api.php
+++ b/data/web/json_api.php
@@ -1548,10 +1548,14 @@ if (isset($_GET['query'])) {
                     curl_setopt($curl, CURLOPT_URL, 'http://ipv4.mailcow.email');
                     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                     curl_setopt($curl, CURLOPT_POST, 0);
+                    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
+                    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                     $ipv4 = curl_exec($curl);
                     curl_setopt($curl, CURLOPT_URL, 'http://ipv6.mailcow.email');
                     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                     curl_setopt($curl, CURLOPT_POST, 0);
+                    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
+                    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                     $ipv6 = curl_exec($curl);
                     $ips = array(
                       "ipv4" => $ipv4,
diff --git a/data/web/lang/lang.de-de.json b/data/web/lang/lang.de-de.json
index 7b4b1f46..89942e4e 100644
--- a/data/web/lang/lang.de-de.json
+++ b/data/web/lang/lang.de-de.json
@@ -494,6 +494,7 @@
         "current_time": "Systemzeit",
         "disk_usage": "Festplattennutzung",
         "docs": "Dokumente",
+        "error_show_ip": "konnte die öffentlichen IP Adressen nicht auflösen",
         "external_logs": "Externe Logs",
         "history_all_servers": "History (alle Server)",
         "in_memory_logs": "In-memory Logs",
@@ -506,6 +507,7 @@
         "online_users": "Benutzer online",
         "restart_container": "Neustart",
         "service": "Dienst",
+        "show_ip": "Zeige öffentliche IP",
         "size": "Größe",
         "solr_dead": "Solr startet, ist deaktiviert oder temporär nicht erreichbar.",
         "solr_status": "Solr Status",
diff --git a/data/web/lang/lang.en-gb.json b/data/web/lang/lang.en-gb.json
index 00b14f07..bec5351d 100644
--- a/data/web/lang/lang.en-gb.json
+++ b/data/web/lang/lang.en-gb.json
@@ -497,6 +497,7 @@
         "current_time": "System Time",
         "disk_usage": "Disk usage",
         "docs": "Docs",
+        "error_show_ip": "Could not resolve the public IP addresses",
         "external_logs": "External logs",
         "history_all_servers": "History (all servers)",
         "in_memory_logs": "In-memory logs",
@@ -509,6 +510,7 @@
         "online_users": "Users online",
         "restart_container": "Restart",
         "service": "Service",
+        "show_ip": "Show public IP",
         "size": "Size",
         "solr_dead": "Solr is starting, disabled or died.",
         "solr_status": "Solr status",
diff --git a/data/web/templates/debug.twig b/data/web/templates/debug.twig
index 6c96de88..a9399a12 100644
--- a/data/web/templates/debug.twig
+++ b/data/web/templates/debug.twig
@@ -52,8 +52,14 @@
                       <tr>
                         <td>IPs</td>
                         <td class="text-break">
-                          <span class="d-block" id="host_ipv4">-</span>
-                          <span class="d-block" id="host_ipv6">-</span>
+                          <span class="d-none" id="host_ipv4">-</span>
+                          <span class="d-none mb-2" id="host_ipv6">-</span>
+                          <button class="d-block btn btn-primary btn-sm" id="host_show_ip">
+                            <span class="text">{{ lang.debug.show_ip }}</span>
+                            <div class="spinner-border spinner-border-sm d-none" role="status">
+                              <span class="visually-hidden">Loading...</span>
+                            </div>  
+                          </button>
                         </td>
                       </tr>
                       <tr>