Browse Source

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

FreddleSpl0it 2 years ago
parent
commit
9727e4084f

+ 34 - 15
data/web/js/site/debug.js

@@ -51,7 +51,40 @@ $(document).ready(function() {
     showVersionModal("Version " + mailcow_info.version_tag, mailcow_info.version_tag);
     showVersionModal("Version " + mailcow_info.version_tag, mailcow_info.version_tag);
   })
   })
   // get public ips
   // 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();
   update_container_stats();
 });
 });
 jQuery(function($){
 jQuery(function($){
@@ -1224,20 +1257,6 @@ function update_container_stats(timeout=5){
   // run again in n seconds
   // run again in n seconds
   setTimeout(update_container_stats, timeout * 1000);
   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
 // format hosts uptime seconds to readable string
 function formatUptime(seconds){
 function formatUptime(seconds){
   seconds = Number(seconds);
   seconds = Number(seconds);

+ 4 - 0
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_URL, 'http://ipv4.mailcow.email');
                     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                     curl_setopt($curl, CURLOPT_POST, 0);
                     curl_setopt($curl, CURLOPT_POST, 0);
+                    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
+                    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                     $ipv4 = curl_exec($curl);
                     $ipv4 = curl_exec($curl);
                     curl_setopt($curl, CURLOPT_URL, 'http://ipv6.mailcow.email');
                     curl_setopt($curl, CURLOPT_URL, 'http://ipv6.mailcow.email');
                     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                     curl_setopt($curl, CURLOPT_POST, 0);
                     curl_setopt($curl, CURLOPT_POST, 0);
+                    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
+                    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                     $ipv6 = curl_exec($curl);
                     $ipv6 = curl_exec($curl);
                     $ips = array(
                     $ips = array(
                       "ipv4" => $ipv4,
                       "ipv4" => $ipv4,

+ 2 - 0
data/web/lang/lang.de-de.json

@@ -494,6 +494,7 @@
         "current_time": "Systemzeit",
         "current_time": "Systemzeit",
         "disk_usage": "Festplattennutzung",
         "disk_usage": "Festplattennutzung",
         "docs": "Dokumente",
         "docs": "Dokumente",
+        "error_show_ip": "konnte die öffentlichen IP Adressen nicht auflösen",
         "external_logs": "Externe Logs",
         "external_logs": "Externe Logs",
         "history_all_servers": "History (alle Server)",
         "history_all_servers": "History (alle Server)",
         "in_memory_logs": "In-memory Logs",
         "in_memory_logs": "In-memory Logs",
@@ -506,6 +507,7 @@
         "online_users": "Benutzer online",
         "online_users": "Benutzer online",
         "restart_container": "Neustart",
         "restart_container": "Neustart",
         "service": "Dienst",
         "service": "Dienst",
+        "show_ip": "Zeige öffentliche IP",
         "size": "Größe",
         "size": "Größe",
         "solr_dead": "Solr startet, ist deaktiviert oder temporär nicht erreichbar.",
         "solr_dead": "Solr startet, ist deaktiviert oder temporär nicht erreichbar.",
         "solr_status": "Solr Status",
         "solr_status": "Solr Status",

+ 2 - 0
data/web/lang/lang.en-gb.json

@@ -497,6 +497,7 @@
         "current_time": "System Time",
         "current_time": "System Time",
         "disk_usage": "Disk usage",
         "disk_usage": "Disk usage",
         "docs": "Docs",
         "docs": "Docs",
+        "error_show_ip": "Could not resolve the public IP addresses",
         "external_logs": "External logs",
         "external_logs": "External logs",
         "history_all_servers": "History (all servers)",
         "history_all_servers": "History (all servers)",
         "in_memory_logs": "In-memory logs",
         "in_memory_logs": "In-memory logs",
@@ -509,6 +510,7 @@
         "online_users": "Users online",
         "online_users": "Users online",
         "restart_container": "Restart",
         "restart_container": "Restart",
         "service": "Service",
         "service": "Service",
+        "show_ip": "Show public IP",
         "size": "Size",
         "size": "Size",
         "solr_dead": "Solr is starting, disabled or died.",
         "solr_dead": "Solr is starting, disabled or died.",
         "solr_status": "Solr status",
         "solr_status": "Solr status",

+ 8 - 2
data/web/templates/debug.twig

@@ -52,8 +52,14 @@
                       <tr>
                       <tr>
                         <td>IPs</td>
                         <td>IPs</td>
                         <td class="text-break">
                         <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>
                         </td>
                       </tr>
                       </tr>
                       <tr>
                       <tr>