瀏覽代碼

shift get_public_ips to json_api.php

FreddleSpl0it 2 年之前
父節點
當前提交
3912fcb238
共有 4 個文件被更改,包括 41 次插入21 次删除
  1. 0 16
      data/web/debug.php
  2. 17 1
      data/web/js/site/debug.js
  3. 22 2
      data/web/json_api.php
  4. 2 2
      data/web/templates/debug.twig

+ 0 - 16
data/web/debug.php

@@ -47,21 +47,6 @@ foreach ($containers as $container => $container_info) {
 // get mailcow data
 // get mailcow data
 $hostname = getenv('MAILCOW_HOSTNAME');
 $hostname = getenv('MAILCOW_HOSTNAME');
 $timezone = getenv('TZ');
 $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 = 'debug.twig';
 $template_data = [
 $template_data = [
@@ -70,7 +55,6 @@ $template_data = [
   'hostname' => $hostname,
   'hostname' => $hostname,
   'timezone' => $timezone,
   'timezone' => $timezone,
   'license_guid' => license('guid'),
   'license_guid' => license('guid'),
-  'ips' => $ips,
   'solr_status' => $solr_status,
   'solr_status' => $solr_status,
   'solr_uptime' => round($solr_status['status']['dovecot-fts']['uptime'] / 1000 / 60 / 60),
   'solr_uptime' => round($solr_status['status']['dovecot-fts']['uptime'] / 1000 / 60 / 60),
   'clamd_status' => $clamd_status,
   'clamd_status' => $clamd_status,

+ 17 - 1
data/web/js/site/debug.js

@@ -47,7 +47,9 @@ $(document).ready(function() {
   if (mailcow_info.branch === "master"){
   if (mailcow_info.branch === "master"){
     check_update(mailcow_info.version_tag, mailcow_info.project_url);
     check_update(mailcow_info.version_tag, mailcow_info.project_url);
   }
   }
-  update_container_stats()
+  // get public ips
+  get_public_ips();
+  update_container_stats();
 });
 });
 jQuery(function($){
 jQuery(function($){
   if (localStorage.getItem("current_page") === null) {
   if (localStorage.getItem("current_page") === null) {
@@ -1218,6 +1220,20 @@ 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);
+
+    if (data){
+      // display host ips
+      $("#host_ipv4").text(data.ipv4);
+      $("#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);

+ 22 - 2
data/web/json_api.php

@@ -1506,8 +1506,28 @@ if (isset($_GET['query'])) {
                   ));
                   ));
                 break;  
                 break;  
                 case "host":
                 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;
                 break;
                 case "version":
                 case "version":
                   echo json_encode(array(
                   echo json_encode(array(

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

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