mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-09-18 14:16:02 +00:00
fix: fix get cpu usage error in openbsd
fix: fix incorrect conversion between integer types fix: fix test file error chore: update dependencies
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ main/cert
|
|||||||
main/config.yml
|
main/config.yml
|
||||||
./vscode
|
./vscode
|
||||||
.idea/*
|
.idea/*
|
||||||
|
.DS_Store
|
@@ -25,7 +25,7 @@ type NodeStatus struct {
|
|||||||
CPU float64
|
CPU float64
|
||||||
Mem float64
|
Mem float64
|
||||||
Disk float64
|
Disk float64
|
||||||
Uptime int
|
Uptime uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type NodeInfo struct {
|
type NodeInfo struct {
|
||||||
@@ -33,7 +33,7 @@ type NodeInfo struct {
|
|||||||
NodeID int
|
NodeID int
|
||||||
Port int
|
Port int
|
||||||
SpeedLimit uint64 // Bps
|
SpeedLimit uint64 // Bps
|
||||||
AlterID int
|
AlterID uint16
|
||||||
TransportProtocol string
|
TransportProtocol string
|
||||||
FakeType string
|
FakeType string
|
||||||
Host string
|
Host string
|
||||||
@@ -59,7 +59,7 @@ type UserInfo struct {
|
|||||||
Obfs string
|
Obfs string
|
||||||
ObfsParam string
|
ObfsParam string
|
||||||
UUID string
|
UUID string
|
||||||
AlterID int
|
AlterID uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
type OnlineUser struct {
|
type OnlineUser struct {
|
||||||
|
@@ -10,7 +10,7 @@ type NodeInfoResponse struct {
|
|||||||
TrafficRate float64 `json:"trafficRate"`
|
TrafficRate float64 `json:"trafficRate"`
|
||||||
RawServerString string `json:"outServer"`
|
RawServerString string `json:"outServer"`
|
||||||
Port int `json:"outPort"`
|
Port int `json:"outPort"`
|
||||||
AlterId int `json:"alterId"`
|
AlterId uint16 `json:"alterId"`
|
||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
Security string `json:"security"`
|
Security string `json:"security"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
|
@@ -19,7 +19,7 @@ type V2rayNodeInfo struct {
|
|||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Cert string `json:"pem"`
|
Cert string `json:"pem"`
|
||||||
V2License string `json:"v2_license"`
|
V2License string `json:"v2_license"`
|
||||||
V2AlterID int `json:"v2_alter_id"`
|
V2AlterID uint16 `json:"v2_alter_id"`
|
||||||
V2Port int `json:"v2_port"`
|
V2Port int `json:"v2_port"`
|
||||||
V2Method string `json:"v2_method"`
|
V2Method string `json:"v2_method"`
|
||||||
V2Net string `json:"v2_net"`
|
V2Net string `json:"v2_net"`
|
||||||
|
@@ -238,7 +238,7 @@ func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
systemload := NodeStatus{
|
systemload := NodeStatus{
|
||||||
Uptime: nodeStatus.Uptime,
|
Uptime: int(nodeStatus.Uptime),
|
||||||
CPU: fmt.Sprintf("%d%%", int(nodeStatus.CPU)),
|
CPU: fmt.Sprintf("%d%%", int(nodeStatus.CPU)),
|
||||||
Mem: fmt.Sprintf("%d%%", int(nodeStatus.Mem)),
|
Mem: fmt.Sprintf("%d%%", int(nodeStatus.Mem)),
|
||||||
Disk: fmt.Sprintf("%d%%", int(nodeStatus.Disk)),
|
Disk: fmt.Sprintf("%d%%", int(nodeStatus.Disk)),
|
||||||
|
@@ -239,7 +239,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
|||||||
func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) {
|
func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) {
|
||||||
path := fmt.Sprintf("/mod_mu/nodes/%d/info", c.NodeID)
|
path := fmt.Sprintf("/mod_mu/nodes/%d/info", c.NodeID)
|
||||||
systemload := SystemLoad{
|
systemload := SystemLoad{
|
||||||
Uptime: strconv.Itoa(nodeStatus.Uptime),
|
Uptime: strconv.FormatUint(nodeStatus.Uptime, 10),
|
||||||
Load: fmt.Sprintf("%.2f %.2f %.2f", nodeStatus.CPU/100, nodeStatus.CPU/100, nodeStatus.CPU/100),
|
Load: fmt.Sprintf("%.2f %.2f %.2f", nodeStatus.CPU/100, nodeStatus.CPU/100, nodeStatus.CPU/100),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,10 +386,13 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
alterID, err := strconv.Atoi(serverConf[2])
|
|
||||||
|
parsedAlterID, err := strconv.ParseInt(serverConf[2], 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
alterID := uint16(parsedAlterID)
|
||||||
|
|
||||||
// Compatible with more node types config
|
// Compatible with more node types config
|
||||||
for _, value := range serverConf[3:5] {
|
for _, value := range serverConf[3:5] {
|
||||||
switch value {
|
switch value {
|
||||||
@@ -727,7 +730,7 @@ func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*a
|
|||||||
|
|
||||||
var speedlimit uint64 = 0
|
var speedlimit uint64 = 0
|
||||||
var EnableTLS, EnableVless bool
|
var EnableTLS, EnableVless bool
|
||||||
var AlterID int = 0
|
var AlterID uint16 = 0
|
||||||
var TLSType, transportProtocol string
|
var TLSType, transportProtocol string
|
||||||
|
|
||||||
nodeConfig := new(CustomConfig)
|
nodeConfig := new(CustomConfig)
|
||||||
@@ -751,9 +754,12 @@ func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*a
|
|||||||
if c.NodeType == "V2ray" {
|
if c.NodeType == "V2ray" {
|
||||||
transportProtocol = nodeConfig.Network
|
transportProtocol = nodeConfig.Network
|
||||||
TLSType = nodeConfig.Security
|
TLSType = nodeConfig.Security
|
||||||
if AlterID, err = strconv.Atoi(nodeConfig.AlterID); err != nil {
|
if parsedAlterID, err := strconv.ParseInt(nodeConfig.AlterID, 10, 16); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else {
|
||||||
|
AlterID = uint16(parsedAlterID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if TLSType == "tls" || TLSType == "xtls" {
|
if TLSType == "tls" || TLSType == "xtls" {
|
||||||
EnableTLS = true
|
EnableTLS = true
|
||||||
}
|
}
|
||||||
|
@@ -226,7 +226,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
|
|||||||
case "V2ray":
|
case "V2ray":
|
||||||
user.UUID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("uuid").MustString()
|
user.UUID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("uuid").MustString()
|
||||||
user.Email = response.Get("data").GetIndex(i).Get("v2ray_user").Get("email").MustString()
|
user.Email = response.Get("data").GetIndex(i).Get("v2ray_user").Get("email").MustString()
|
||||||
user.AlterID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("alter_id").MustInt()
|
user.AlterID = uint16(response.Get("data").GetIndex(i).Get("v2ray_user").Get("alter_id").MustUint64())
|
||||||
}
|
}
|
||||||
userList[i] = user
|
userList[i] = user
|
||||||
}
|
}
|
||||||
@@ -355,7 +355,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
|
|||||||
var path, host, serviceName string
|
var path, host, serviceName string
|
||||||
var header json.RawMessage
|
var header json.RawMessage
|
||||||
var enableTLS bool
|
var enableTLS bool
|
||||||
var alterID int = 0
|
var alterID uint16 = 0
|
||||||
if c.EnableXTLS {
|
if c.EnableXTLS {
|
||||||
TLSType = "xtls"
|
TLSType = "xtls"
|
||||||
}
|
}
|
||||||
|
@@ -3,39 +3,51 @@ package serverstatus
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/v3/cpu"
|
||||||
"github.com/shirou/gopsutil/disk"
|
"github.com/shirou/gopsutil/v3/disk"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/v3/host"
|
||||||
|
"github.com/shirou/gopsutil/v3/mem"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetSystemInfo get the system info of a given periodic
|
// GetSystemInfo get the system info of a given periodic
|
||||||
func GetSystemInfo() (Cpu float64, Mem float64, Disk float64, Uptime int, err error) {
|
func GetSystemInfo() (Cpu float64, Mem float64, Disk float64, Uptime uint64, err error) {
|
||||||
|
|
||||||
|
error_string := ""
|
||||||
|
|
||||||
upTime := time.Now()
|
|
||||||
cpuPercent, err := cpu.Percent(0, false)
|
cpuPercent, err := cpu.Percent(0, false)
|
||||||
// Check if cpuPercent is empty
|
// Check if cpuPercent is empty
|
||||||
if len(cpuPercent) > 0 {
|
if len(cpuPercent) > 0 && err == nil {
|
||||||
Cpu = cpuPercent[0]
|
Cpu = cpuPercent[0]
|
||||||
} else {
|
} else {
|
||||||
Cpu = 0
|
Cpu = 0
|
||||||
}
|
error_string += fmt.Sprintf("get cpu usage failed: %s ", err)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return 0, 0, 0, 0, fmt.Errorf("get cpu usage failed: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memUsage, err := mem.VirtualMemory()
|
memUsage, err := mem.VirtualMemory()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, 0, 0, fmt.Errorf("get mem usage failed: %s", err)
|
error_string += fmt.Sprintf("get mem usage failed: %s ", err)
|
||||||
|
} else {
|
||||||
|
Mem = memUsage.UsedPercent
|
||||||
}
|
}
|
||||||
|
|
||||||
diskUsage, err := disk.Usage("/")
|
diskUsage, err := disk.Usage("/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, 0, 0, fmt.Errorf("et disk usage failed: %s", err)
|
error_string += fmt.Sprintf("get disk usage failed: %s ", err)
|
||||||
|
} else {
|
||||||
|
Disk = diskUsage.UsedPercent
|
||||||
}
|
}
|
||||||
|
|
||||||
Uptime = int(time.Since(upTime).Seconds())
|
uptime, err := host.Uptime()
|
||||||
return Cpu, memUsage.UsedPercent, diskUsage.UsedPercent, Uptime, nil
|
if err != nil {
|
||||||
|
error_string += fmt.Sprintf("get uptime failed: %s ", err)
|
||||||
|
} else {
|
||||||
|
Uptime = uptime
|
||||||
|
}
|
||||||
|
|
||||||
|
if error_string != "" {
|
||||||
|
err = fmt.Errorf(error_string)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Cpu, Mem, Disk, Uptime, err
|
||||||
}
|
}
|
||||||
|
4
go.mod
4
go.mod
@@ -14,7 +14,7 @@ require (
|
|||||||
github.com/imdario/mergo v0.3.13
|
github.com/imdario/mergo v0.3.13
|
||||||
github.com/juju/ratelimit v1.0.1
|
github.com/juju/ratelimit v1.0.1
|
||||||
github.com/r3labs/diff/v2 v2.15.1
|
github.com/r3labs/diff/v2 v2.15.1
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
github.com/shirou/gopsutil/v3 v3.22.7
|
||||||
github.com/spf13/viper v1.12.0
|
github.com/spf13/viper v1.12.0
|
||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.8.0
|
||||||
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
||||||
@@ -87,6 +87,7 @@ require (
|
|||||||
github.com/liquidweb/liquidweb-cli v0.6.10 // indirect
|
github.com/liquidweb/liquidweb-cli v0.6.10 // indirect
|
||||||
github.com/liquidweb/liquidweb-go v1.6.3 // indirect
|
github.com/liquidweb/liquidweb-go v1.6.3 // indirect
|
||||||
github.com/lucas-clemente/quic-go v0.28.0 // indirect
|
github.com/lucas-clemente/quic-go v0.28.0 // indirect
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||||
github.com/magiconair/properties v1.8.6 // indirect
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
|
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
|
||||||
github.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect
|
github.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect
|
||||||
@@ -117,6 +118,7 @@ require (
|
|||||||
github.com/pires/go-proxyproto v0.6.2 // indirect
|
github.com/pires/go-proxyproto v0.6.2 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
github.com/pquerna/otp v1.3.0 // indirect
|
github.com/pquerna/otp v1.3.0 // indirect
|
||||||
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2 // indirect
|
github.com/rainycape/memcache v0.0.0-20150622160815-1031fa0ce2f2 // indirect
|
||||||
github.com/refraction-networking/utls v1.1.0 // indirect
|
github.com/refraction-networking/utls v1.1.0 // indirect
|
||||||
|
9
go.sum
9
go.sum
@@ -491,6 +491,8 @@ github.com/liquidweb/liquidweb-go v1.6.3 h1:NVHvcnX3eb3BltiIoA+gLYn15nOpkYkdizOE
|
|||||||
github.com/liquidweb/liquidweb-go v1.6.3/go.mod h1:SuXXp+thr28LnjEw18AYtWwIbWMHSUiajPQs8T9c/Rc=
|
github.com/liquidweb/liquidweb-go v1.6.3/go.mod h1:SuXXp+thr28LnjEw18AYtWwIbWMHSUiajPQs8T9c/Rc=
|
||||||
github.com/lucas-clemente/quic-go v0.28.0 h1:9eXVRgIkMQQyiyorz/dAaOYIx3TFzXsIFkNFz4cxuJM=
|
github.com/lucas-clemente/quic-go v0.28.0 h1:9eXVRgIkMQQyiyorz/dAaOYIx3TFzXsIFkNFz4cxuJM=
|
||||||
github.com/lucas-clemente/quic-go v0.28.0/go.mod h1:oGz5DKK41cJt5+773+BSO9BXDsREY4HLf7+0odGAPO0=
|
github.com/lucas-clemente/quic-go v0.28.0/go.mod h1:oGz5DKK41cJt5+773+BSO9BXDsREY4HLf7+0odGAPO0=
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
|
||||||
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||||
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
||||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||||
github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||||
@@ -628,6 +630,8 @@ github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw
|
|||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
|
||||||
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||||
github.com/pquerna/otp v1.3.0 h1:oJV/SkzR33anKXwQU3Of42rL4wbrffP4uvUf1SvS5Xs=
|
github.com/pquerna/otp v1.3.0 h1:oJV/SkzR33anKXwQU3Of42rL4wbrffP4uvUf1SvS5Xs=
|
||||||
github.com/pquerna/otp v1.3.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
github.com/pquerna/otp v1.3.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
||||||
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
@@ -681,8 +685,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
|
|||||||
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U=
|
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U=
|
||||||
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
|
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
|
||||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
|
github.com/shirou/gopsutil/v3 v3.22.7 h1:flKnuCMfUUrO+oAvwAd6GKZgnPzr098VA/UJ14nhJd4=
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
github.com/shirou/gopsutil/v3 v3.22.7/go.mod h1:s648gW4IywYzUfE/KjXxUsqrqx/T2xO5VqOXxONeRfI=
|
||||||
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
|
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
|
||||||
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
|
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
|
||||||
github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0=
|
github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0=
|
||||||
@@ -1050,6 +1054,7 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20201110211018-35f3e6cf4a65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201110211018-35f3e6cf4a65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
@@ -3,7 +3,6 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -346,19 +345,14 @@ func (c *Controller) addNewUser(userInfo *[]api.UserInfo, nodeInfo *api.NodeInfo
|
|||||||
if nodeInfo.EnableVless {
|
if nodeInfo.EnableVless {
|
||||||
users = c.buildVlessUser(userInfo)
|
users = c.buildVlessUser(userInfo)
|
||||||
} else {
|
} else {
|
||||||
alterID := 0
|
var alterID uint16 = 0
|
||||||
if c.panelType == "V2board" {
|
if c.panelType == "V2board" {
|
||||||
// use latest userInfo
|
// use latest userInfo
|
||||||
alterID = (*userInfo)[0].AlterID
|
alterID = (*userInfo)[0].AlterID
|
||||||
} else {
|
} else {
|
||||||
alterID = nodeInfo.AlterID
|
alterID = nodeInfo.AlterID
|
||||||
}
|
}
|
||||||
if alterID >= 0 && alterID < math.MaxUint16 {
|
users = c.buildVmessUser(userInfo, alterID)
|
||||||
users = c.buildVmessUser(userInfo, uint16(alterID))
|
|
||||||
} else {
|
|
||||||
users = c.buildVmessUser(userInfo, 0)
|
|
||||||
return fmt.Errorf("AlterID should between 0 to 1<<16 - 1, set it to 0 for now")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if nodeInfo.NodeType == "Trojan" {
|
} else if nodeInfo.NodeType == "Trojan" {
|
||||||
users = c.buildTrojanUser(userInfo)
|
users = c.buildTrojanUser(userInfo)
|
||||||
|
@@ -62,7 +62,7 @@ func TestController(t *testing.T) {
|
|||||||
NodeType: "V2ray",
|
NodeType: "V2ray",
|
||||||
}
|
}
|
||||||
apiclient := sspanel.New(apiConfig)
|
apiclient := sspanel.New(apiConfig)
|
||||||
c := New(server, apiclient, controlerconfig)
|
c := New(server, apiclient, controlerconfig, "SSpanel")
|
||||||
fmt.Println("Sleep 1s")
|
fmt.Println("Sleep 1s")
|
||||||
err = c.Start()
|
err = c.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -29,7 +29,7 @@ func TestBuildV2ray(t *testing.T) {
|
|||||||
config := &Config{
|
config := &Config{
|
||||||
CertConfig: certConfig,
|
CertConfig: certConfig,
|
||||||
}
|
}
|
||||||
_, err := InboundBuilder(config, nodeInfo)
|
_, err := InboundBuilder(config, nodeInfo, "test_tag")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ func TestBuildTrojan(t *testing.T) {
|
|||||||
config := &Config{
|
config := &Config{
|
||||||
CertConfig: certConfig,
|
CertConfig: certConfig,
|
||||||
}
|
}
|
||||||
_, err := InboundBuilder(config, nodeInfo)
|
_, err := InboundBuilder(config, nodeInfo, "test_tag")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ func TestBuildSS(t *testing.T) {
|
|||||||
config := &Config{
|
config := &Config{
|
||||||
CertConfig: certConfig,
|
CertConfig: certConfig,
|
||||||
}
|
}
|
||||||
_, err := InboundBuilder(config, nodeInfo)
|
_, err := InboundBuilder(config, nodeInfo, "test_tag")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user