feat:显示当前ip,系统网络代理地址 (#6251)

pull/6271/head
trom 2024-08-27 13:39:36 +08:00 committed by GitHub
parent a5e7f78a1f
commit b18689a0d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 57 additions and 6 deletions

View File

@ -16,10 +16,11 @@ type DashboardBase struct {
KernelArch string `json:"kernelArch"`
KernelVersion string `json:"kernelVersion"`
VirtualizationSystem string `json:"virtualizationSystem"`
CPUCores int `json:"cpuCores"`
CPULogicalCores int `json:"cpuLogicalCores"`
CPUModelName string `json:"cpuModelName"`
IpV4Addr string `json:"ipv4Addr"`
SystemProxy string `json:"SystemProxy"`
CPUCores int `json:"cpuCores"`
CPULogicalCores int `json:"cpuLogicalCores"`
CPUModelName string `json:"cpuModelName"`
CurrentInfo DashboardCurrent `json:"currentInfo"`
}

View File

@ -3,6 +3,8 @@ package service
import (
"encoding/json"
"fmt"
network "net"
"os"
"sort"
"strings"
"sync"
@ -94,11 +96,20 @@ func (u *DashboardService) LoadBaseInfo(ioOption string, netOption string) (*dto
baseInfo.KernelVersion = hostInfo.KernelVersion
ss, _ := json.Marshal(hostInfo)
baseInfo.VirtualizationSystem = string(ss)
baseInfo.IpV4Addr = GetOutboundIP()
httpProxy := os.Getenv("http_proxy")
if httpProxy == "" {
httpProxy = os.Getenv("HTTP_PROXY")
}
if httpProxy != "" {
baseInfo.SystemProxy = httpProxy
}
baseInfo.SystemProxy = "noProxy"
appInstall, err := appInstallRepo.ListBy()
if err != nil {
return nil, err
}
baseInfo.AppInstalledNumber = len(appInstall)
postgresqlDbs, err := postgresqlRepo.List()
if err != nil {
@ -208,6 +219,18 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d
return &currentInfo
}
func GetOutboundIP() string {
conn, err := network.Dial("udp", "8.8.8.8:80")
if err != nil {
return "IPNotFound"
}
defer conn.Close()
localAddr := conn.LocalAddr().(*network.UDPAddr)
return localAddr.IP.String()
}
type diskInfo struct {
Type string
Mount string

View File

@ -22,6 +22,8 @@ export namespace Dashboard {
kernelArch: string;
kernelVersion: string;
virtualizationSystem: string;
ipv4Addr: string;
systemProxy: string;
cpuCores: number;
cpuLogicalCores: number;

View File

@ -337,6 +337,8 @@ const message = {
kernelArch: '',
network: '',
io: ' IO',
ip: '',
proxy: '',
baseInfo: '',
totalSend: '',
totalRecv: '',

View File

@ -225,6 +225,28 @@
</template>
{{ loadUpTime(currentInfo.uptime) }}
</el-descriptions-item>
<el-descriptions-item
v-if="baseInfo.ipv4Addr && baseInfo.ipv4Addr !== 'IPNotFound'"
class-name="system-content"
>
<template #label>
<span class="system-label">
{{ $t('home.ip') }}
</span>
</template>
{{ baseInfo.ipv4Addr }}
</el-descriptions-item>
<el-descriptions-item
v-if="baseInfo.systemProxy && baseInfo.systemProxy !== 'noProxy'"
class-name="system-content"
>
<template #label>
<span class="system-label">
{{ $t('home.proxy') }}
</span>
</template>
{{ baseInfo.systemProxy }}
</el-descriptions-item>
</el-descriptions>
</el-scrollbar>
</template>
@ -303,7 +325,8 @@ const baseInfo = ref<Dashboard.BaseInfo>({
kernelArch: '',
kernelVersion: '',
virtualizationSystem: '',
ipv4Addr: '',
systemProxy: '',
cpuCores: 0,
cpuLogicalCores: 0,
cpuModelName: '',