mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
Merge branch 'dev' of github.com:naiba/nezha-v1 into dev
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
)
|
||||
|
||||
@@ -105,8 +107,6 @@ type Host struct {
|
||||
Arch string `json:"arch,omitempty"`
|
||||
Virtualization string `json:"virtualization,omitempty"`
|
||||
BootTime uint64 `json:"boot_time,omitempty"`
|
||||
IP string `json:"ip,omitempty"`
|
||||
CountryCode string `json:"country_code,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
GPU []string `json:"gpu,omitempty"`
|
||||
}
|
||||
@@ -122,8 +122,6 @@ func (h *Host) PB() *pb.Host {
|
||||
Arch: h.Arch,
|
||||
Virtualization: h.Virtualization,
|
||||
BootTime: h.BootTime,
|
||||
Ip: h.IP,
|
||||
CountryCode: h.CountryCode,
|
||||
Version: h.Version,
|
||||
Gpu: h.GPU,
|
||||
}
|
||||
@@ -140,9 +138,36 @@ func PB2Host(h *pb.Host) Host {
|
||||
Arch: h.GetArch(),
|
||||
Virtualization: h.GetVirtualization(),
|
||||
BootTime: h.GetBootTime(),
|
||||
IP: h.GetIp(),
|
||||
CountryCode: h.GetCountryCode(),
|
||||
Version: h.GetVersion(),
|
||||
GPU: h.GetGpu(),
|
||||
}
|
||||
}
|
||||
|
||||
type IP struct {
|
||||
IPv4Addr string `json:"ipv4_addr,omitempty"`
|
||||
IPv6Addr string `json:"ipv6_addr,omitempty"`
|
||||
}
|
||||
|
||||
func (p *IP) Join() string {
|
||||
if p.IPv4Addr != "" && p.IPv6Addr != "" {
|
||||
return fmt.Sprintf("%s/%s", p.IPv4Addr, p.IPv6Addr)
|
||||
} else if p.IPv4Addr != "" {
|
||||
return p.IPv4Addr
|
||||
}
|
||||
return p.IPv6Addr
|
||||
}
|
||||
|
||||
type GeoIP struct {
|
||||
IP IP `json:"ip,omitempty"`
|
||||
CountryCode string `json:"country_code,omitempty"`
|
||||
}
|
||||
|
||||
func PB2GeoIP(p *pb.GeoIP) GeoIP {
|
||||
pbIP := p.GetIp()
|
||||
return GeoIP{
|
||||
IP: IP{
|
||||
IPv4Addr: pbIP.GetIpv4(),
|
||||
IPv6Addr: pbIP.GetIpv6(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ func (ns *NotificationServerBundle) replaceParamsInString(str string, message st
|
||||
str = strings.ReplaceAll(str, "#SERVER.UDPCONNCOUNT#", mod(fmt.Sprintf("%d", ns.Server.State.UdpConnCount)))
|
||||
|
||||
var ipv4, ipv6, validIP string
|
||||
ipList := strings.Split(ns.Server.Host.IP, "/")
|
||||
ipList := strings.Split(ns.Server.GeoIP.IP.Join(), "/")
|
||||
if len(ipList) > 1 {
|
||||
// 双栈
|
||||
ipv4 = ipList[0]
|
||||
@@ -201,7 +201,7 @@ func (ns *NotificationServerBundle) replaceParamsInString(str string, message st
|
||||
validIP = ipv4
|
||||
} else if len(ipList) == 1 {
|
||||
// 仅ipv4|ipv6
|
||||
if strings.Contains(ipList[0], ":") {
|
||||
if strings.IndexByte(ipList[0], ':') != -1 {
|
||||
ipv6 = ipList[0]
|
||||
validIP = ipv6
|
||||
} else {
|
||||
|
||||
@@ -49,8 +49,6 @@ func execCase(t *testing.T, item testSt) {
|
||||
Arch: "",
|
||||
Virtualization: "",
|
||||
BootTime: 0,
|
||||
IP: "1.1.1.1",
|
||||
CountryCode: "",
|
||||
Version: "",
|
||||
},
|
||||
State: &HostState{
|
||||
@@ -70,6 +68,12 @@ func execCase(t *testing.T, item testSt) {
|
||||
UdpConnCount: 0,
|
||||
ProcessCount: 0,
|
||||
},
|
||||
GeoIP: &GeoIP{
|
||||
IP: IP{
|
||||
IPv4Addr: "1.1.1.1",
|
||||
},
|
||||
CountryCode: "",
|
||||
},
|
||||
LastActive: time.Time{},
|
||||
TaskClose: nil,
|
||||
TaskStream: nil,
|
||||
|
||||
@@ -27,6 +27,7 @@ type Server struct {
|
||||
|
||||
Host *Host `gorm:"-" json:"host,omitempty"`
|
||||
State *HostState `gorm:"-" json:"state,omitempty"`
|
||||
GeoIP *GeoIP `gorm:"-" json:"geoip,omitempty"`
|
||||
LastActive time.Time `gorm:"-" json:"last_active,omitempty"`
|
||||
|
||||
TaskClose chan error `gorm:"-" json:"-"`
|
||||
@@ -40,6 +41,7 @@ type Server struct {
|
||||
func (s *Server) CopyFromRunningServer(old *Server) {
|
||||
s.Host = old.Host
|
||||
s.State = old.State
|
||||
s.GeoIP = old.GeoIP
|
||||
s.LastActive = old.LastActive
|
||||
s.TaskClose = old.TaskClose
|
||||
s.TaskCloseLock = old.TaskCloseLock
|
||||
|
||||
Reference in New Issue
Block a user