From e46dc1d8d7dd07221cb93bc02d88b0803923e30c Mon Sep 17 00:00:00 2001 From: pocketW <104479902+pocketW@users.noreply.github.com> Date: Tue, 2 Aug 2022 19:42:29 +1000 Subject: [PATCH] fix: fix incorrect conversion between integer type --- api/apimodel.go | 4 ++-- api/pmpanel/model.go | 2 +- api/pmpanel/pmpanel.go | 5 +---- api/proxypanel/model.go | 6 +++--- api/sspanel/model.go | 2 +- api/sspanel/sspanel.go | 15 ++++++++++----- api/v2board/v2board.go | 8 ++++---- service/controller/inboundbuilder.go | 2 +- 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/api/apimodel.go b/api/apimodel.go index db32c73..893bc77 100644 --- a/api/apimodel.go +++ b/api/apimodel.go @@ -31,7 +31,7 @@ type NodeStatus struct { type NodeInfo struct { NodeType string // Must be V2ray, Trojan, and Shadowsocks NodeID int - Port int + Port uint32 SpeedLimit uint64 // Bps AlterID uint16 TransportProtocol string @@ -50,7 +50,7 @@ type UserInfo struct { UID int Email string Passwd string - Port int + Port uint32 Method string SpeedLimit uint64 // Bps DeviceLimit int diff --git a/api/pmpanel/model.go b/api/pmpanel/model.go index 9a2d5ce..540f6d6 100644 --- a/api/pmpanel/model.go +++ b/api/pmpanel/model.go @@ -9,7 +9,7 @@ type NodeInfoResponse struct { Method string `json:"method"` TrafficRate float64 `json:"trafficRate"` RawServerString string `json:"outServer"` - Port int `json:"outPort"` + Port uint32 `json:"outPort"` AlterId uint16 `json:"alterId"` Network string `json:"network"` Security string `json:"security"` diff --git a/api/pmpanel/pmpanel.go b/api/pmpanel/pmpanel.go index 72c406f..dc2383e 100644 --- a/api/pmpanel/pmpanel.go +++ b/api/pmpanel/pmpanel.go @@ -411,11 +411,8 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) ( // ParseSSNodeResponse parse the response for the given nodeinfor format func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*api.NodeInfo, error) { - var port int = 0 var speedlimit uint64 = 0 - port = nodeInfoResponse.Port - if c.SpeedLimit > 0 { speedlimit = uint64((c.SpeedLimit * 1000000) / 8) } else { @@ -425,7 +422,7 @@ func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*ap nodeinfo := &api.NodeInfo{ NodeType: c.NodeType, NodeID: c.NodeID, - Port: port, + Port: nodeInfoResponse.Port, SpeedLimit: speedlimit, TransportProtocol: "tcp", CypherMethod: nodeInfoResponse.Method, diff --git a/api/proxypanel/model.go b/api/proxypanel/model.go index 42dfa2b..515dda2 100644 --- a/api/proxypanel/model.go +++ b/api/proxypanel/model.go @@ -20,7 +20,7 @@ type V2rayNodeInfo struct { Cert string `json:"pem"` V2License string `json:"v2_license"` V2AlterID uint16 `json:"v2_alter_id"` - V2Port int `json:"v2_port"` + V2Port uint32 `json:"v2_port"` V2Method string `json:"v2_method"` V2Net string `json:"v2_net"` V2Type string `json:"v2_type"` @@ -37,7 +37,7 @@ type ShadowsocksNodeInfo struct { SpeedLimit uint64 `json:"speed_limit"` ClientLimit int `json:"client_limit"` Method string `json:"method"` - Port int `json:"port"` + Port uint32 `json:"port"` } type TrojanNodeInfo struct { @@ -46,7 +46,7 @@ type TrojanNodeInfo struct { SpeedLimit uint64 `json:"speed_limit"` ClientLimit int `json:"client_limit"` PushPort int `json:"push_port"` - TrojanPort int `json:"trojan_port"` + TrojanPort uint32 `json:"trojan_port"` } // Node status report diff --git a/api/sspanel/model.go b/api/sspanel/model.go index 0f87b0c..1773fee 100644 --- a/api/sspanel/model.go +++ b/api/sspanel/model.go @@ -49,7 +49,7 @@ type UserResponse struct { ID int `json:"id"` Email string `json:"email"` Passwd string `json:"passwd"` - Port int `json:"port"` + Port uint32 `json:"port"` Method string `json:"method"` SpeedLimit float64 `json:"node_speedlimit"` DeviceLimit int `json:"node_connector"` diff --git a/api/sspanel/sspanel.go b/api/sspanel/sspanel.go index e7f2f27..228d09b 100644 --- a/api/sspanel/sspanel.go +++ b/api/sspanel/sspanel.go @@ -382,10 +382,12 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) ( } //nodeInfo.RawServerString = strings.ToLower(nodeInfo.RawServerString) serverConf := strings.Split(nodeInfoResponse.RawServerString, ";") - port, err := strconv.Atoi(serverConf[1]) + + parsedPort, err := strconv.ParseInt(serverConf[1], 10, 32) if err != nil { return nil, err } + port := uint32(parsedPort) parsedAlterID, err := strconv.ParseInt(serverConf[2], 10, 16) if err != nil { @@ -467,7 +469,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *NodeInfoResponse) ( // ParseSSNodeResponse parse the response for the given nodeinfor format func (c *APIClient) ParseSSNodeResponse(nodeInfoResponse *NodeInfoResponse) (*api.NodeInfo, error) { - var port int = 0 + var port uint32 = 0 var speedlimit uint64 = 0 var method string path := "/mod_mu/users" @@ -524,10 +526,11 @@ func (c *APIClient) ParseSSPluginNodeResponse(nodeInfoResponse *NodeInfoResponse var speedlimit uint64 = 0 serverConf := strings.Split(nodeInfoResponse.RawServerString, ";") - port, err := strconv.Atoi(serverConf[1]) + parsedPort, err := strconv.ParseInt(serverConf[1], 10, 32) if err != nil { return nil, err } + port := uint32(parsedPort) port = port - 1 // Shadowsocks-Plugin requires two ports, one for ss the other for other stream protocol if port <= 0 { return nil, fmt.Errorf("Shadowsocks-Plugin listen port must bigger than 1") @@ -618,10 +621,11 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *NodeInfoResponse) p = outsidePort } - port, err := strconv.Atoi(p) + parsedPort, err := strconv.ParseInt(p, 10, 32) if err != nil { return nil, err } + port := uint32(parsedPort) serverConf := strings.Split(nodeInfoResponse.RawServerString, ";") extraServerConf := strings.Split(serverConf[1], "|") @@ -742,10 +746,11 @@ func (c *APIClient) ParseSSPanelNodeInfo(nodeInfoResponse *NodeInfoResponse) (*a speedlimit = uint64((nodeInfoResponse.SpeedLimit * 1000000) / 8) } - port, err := strconv.Atoi(nodeConfig.OffsetPortNode) + parsedPort, err := strconv.ParseInt(nodeConfig.OffsetPortNode, 10, 32) if err != nil { return nil, err } + port := uint32(parsedPort) if c.NodeType == "Shadowsocks" { transportProtocol = "tcp" diff --git a/api/v2board/v2board.go b/api/v2board/v2board.go index aea3e4d..88c8bb9 100644 --- a/api/v2board/v2board.go +++ b/api/v2board/v2board.go @@ -219,7 +219,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) { user.Email = response.Get("data").GetIndex(i).Get("secret").MustString() user.Passwd = response.Get("data").GetIndex(i).Get("secret").MustString() user.Method = response.Get("data").GetIndex(i).Get("cipher").MustString() - user.Port = response.Get("data").GetIndex(i).Get("port").MustInt() + user.Port = uint32(response.Get("data").GetIndex(i).Get("port").MustUint64()) case "Trojan": user.UUID = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString() user.Email = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString() @@ -308,7 +308,7 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *simplejson.Json) ( if c.EnableXTLS { TLSType = "xtls" } - port := nodeInfoResponse.Get("local_port").MustInt() + port := uint32(nodeInfoResponse.Get("local_port").MustUint64()) host := nodeInfoResponse.Get("ssl").Get("sni").MustString() // Create GeneralNodeInfo @@ -326,7 +326,7 @@ func (c *APIClient) ParseTrojanNodeResponse(nodeInfoResponse *simplejson.Json) ( // ParseSSNodeResponse parse the response for the given nodeinfor format func (c *APIClient) ParseSSNodeResponse() (*api.NodeInfo, error) { - var port int + var port uint32 var method string userInfo, err := c.GetUserList() if err != nil { @@ -372,7 +372,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (* return nil, fmt.Errorf("Unable to find inbound(s) in the nodeInfo.") } - port := inboundInfo.Get("port").MustInt() + port := uint32(inboundInfo.Get("port").MustUint64()) transportProtocol := inboundInfo.Get("streamSettings").Get("network").MustString() switch transportProtocol { diff --git a/service/controller/inboundbuilder.go b/service/controller/inboundbuilder.go index 988becd..dc0bd16 100644 --- a/service/controller/inboundbuilder.go +++ b/service/controller/inboundbuilder.go @@ -27,7 +27,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I // Build Port portList := &conf.PortList{ - Range: []conf.PortRange{{From: uint32(nodeInfo.Port), To: uint32(nodeInfo.Port)}}, + Range: []conf.PortRange{{From: nodeInfo.Port, To: nodeInfo.Port}}, } inboundDetourConfig.PortList = portList // Build Tag