From 9727e4084f7303208f24da2154e40030b54516c2 Mon Sep 17 00:00:00 2001 From: FreddleSpl0it Date: Fri, 6 Jan 2023 08:40:26 +0100 Subject: [PATCH] [Web] load public ip on click and add curl timeout --- 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 --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 @@ IPs - - - - + - + - +