From 3912fcb23852dec4193c39642d77df25b0f2f774 Mon Sep 17 00:00:00 2001 From: FreddleSpl0it Date: Tue, 11 Oct 2022 17:40:46 +0200 Subject: [PATCH] shift get_public_ips to json_api.php --- data/web/debug.php | 16 ---------------- data/web/js/site/debug.js | 18 +++++++++++++++++- data/web/json_api.php | 24 ++++++++++++++++++++++-- data/web/templates/debug.twig | 4 ++-- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/data/web/debug.php b/data/web/debug.php index 5d50dc85..5618ec00 100644 --- a/data/web/debug.php +++ b/data/web/debug.php @@ -47,21 +47,6 @@ foreach ($containers as $container => $container_info) { // get mailcow data $hostname = getenv('MAILCOW_HOSTNAME'); $timezone = getenv('TZ'); -// get public ips -$curl = curl_init(); -curl_setopt($curl, CURLOPT_URL, 'http://ipv4.mailcow.email'); -curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); -curl_setopt($curl, CURLOPT_POST, 0); -$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); -$ipv6 = curl_exec($curl); -$ips = array( - "ipv4" => $ipv4, - "ipv6" => $ipv6 -); -curl_close($curl); $template = 'debug.twig'; $template_data = [ @@ -70,7 +55,6 @@ $template_data = [ 'hostname' => $hostname, 'timezone' => $timezone, 'license_guid' => license('guid'), - 'ips' => $ips, 'solr_status' => $solr_status, 'solr_uptime' => round($solr_status['status']['dovecot-fts']['uptime'] / 1000 / 60 / 60), 'clamd_status' => $clamd_status, diff --git a/data/web/js/site/debug.js b/data/web/js/site/debug.js index 03189e93..dcc04210 100644 --- a/data/web/js/site/debug.js +++ b/data/web/js/site/debug.js @@ -47,7 +47,9 @@ $(document).ready(function() { if (mailcow_info.branch === "master"){ check_update(mailcow_info.version_tag, mailcow_info.project_url); } - update_container_stats() + // get public ips + get_public_ips(); + update_container_stats(); }); jQuery(function($){ if (localStorage.getItem("current_page") === null) { @@ -1218,6 +1220,20 @@ 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); + + if (data){ + // display host ips + $("#host_ipv4").text(data.ipv4); + $("#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 15bc8b5e..1953d17c 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -1506,8 +1506,28 @@ if (isset($_GET['query'])) { )); break; case "host": - $stats = docker("host_stats"); - echo json_encode($stats); + if (!$extra){ + $stats = docker("host_stats"); + echo json_encode($stats); + } + else if ($extra == "ip") { + // get public ips + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, 'http://ipv4.mailcow.email'); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_POST, 0); + $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); + $ipv6 = curl_exec($curl); + $ips = array( + "ipv4" => $ipv4, + "ipv6" => $ipv6 + ); + curl_close($curl); + echo json_encode($ips); + } break; case "version": echo json_encode(array( diff --git a/data/web/templates/debug.twig b/data/web/templates/debug.twig index 2a542da6..7c36501e 100644 --- a/data/web/templates/debug.twig +++ b/data/web/templates/debug.twig @@ -52,8 +52,8 @@ IPs - {{ ips.ipv4 }} - {{ ips.ipv6 }} + - + -