public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
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
shift get_public_ips to json_api.php
3912fcb2
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
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 @@
<tr>
<td>IPs</td>
<td class="text-break">
- <span class="d-block">{{ ips.ipv4 }}</span>
- <span class="d-block">{{ ips.ipv6 }}</span>
+ <span class="d-block" id="host_ipv4">-</span>
+ <span class="d-block" id="host_ipv6">-</span>
</td>
</tr>
<tr>