From 78c2e31bdf789a5eb5b397ea1dff30616bfa09d3 Mon Sep 17 00:00:00 2001 From: thh1451 <119903652+thh1451@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:23:44 +0100 Subject: [PATCH] add 2 acts to V2RaySocks (#516) --- api/v2raysocks/model.go | 13 ++++++++++++ api/v2raysocks/v2raysocks.go | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/api/v2raysocks/model.go b/api/v2raysocks/model.go index c65ae51..d680bfc 100644 --- a/api/v2raysocks/model.go +++ b/api/v2raysocks/model.go @@ -5,3 +5,16 @@ type UserTraffic struct { Upload int64 `json:"u"` Download int64 `json:"d"` } + +type NodeStatus struct { + CPU string `json:"cpu"` + Mem string `json:"mem"` + Net string `json:"net"` + Disk string `json:"disk"` + Uptime int `json:"uptime"` +} + +type NodeOnline struct { + UID int `json:"uid"` + IP string `json:"ip"` +} \ No newline at end of file diff --git a/api/v2raysocks/v2raysocks.go b/api/v2raysocks/v2raysocks.go index b87944f..e02bc9c 100644 --- a/api/v2raysocks/v2raysocks.go +++ b/api/v2raysocks/v2raysocks.go @@ -287,11 +287,49 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) { // ReportNodeStatus implements the API interface func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) { + systemload := NodeStatus{ + Uptime: int(nodeStatus.Uptime), + CPU: fmt.Sprintf("%d%%", int(nodeStatus.CPU)), + Mem: fmt.Sprintf("%d%%", int(nodeStatus.Mem)), + Disk: fmt.Sprintf("%d%%", int(nodeStatus.Disk)), + } + + res, err := c.client.R(). + SetQueryParam("node_id", strconv.Itoa(c.NodeID)). + SetQueryParams(map[string]string{ + "act": "nodestatus", + "nodetype": strings.ToLower(c.NodeType), + }). + SetBody(systemload). + ForceContentType("application/json"). + Post(c.APIHost) + _, err = c.parseResponse(res, "", err) + if err != nil { + return err + } return nil } // ReportNodeOnlineUsers implements the API interface func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) error { + data := make([]NodeOnline, len(*onlineUserList)) + for i, user := range *onlineUserList { + data[i] = NodeOnline{UID: user.UID, IP: user.IP} + } + + res, err := c.client.R(). + SetQueryParam("node_id", strconv.Itoa(c.NodeID)). + SetQueryParams(map[string]string{ + "act": "onlineusers", + "nodetype": strings.ToLower(c.NodeType), + }). + SetBody(data). + ForceContentType("application/json"). + Post(c.APIHost) + _, err = c.parseResponse(res, "", err) + if err != nil { + return err + } return nil }