New transports and api changes for V2RaySocks (#685)

* New transports and api changes for V2RaySocks

* version++
This commit is contained in:
RyarX 2024-10-19 16:03:05 +02:00 committed by GitHub
parent eb16b709e2
commit 9391c759c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 67 additions and 32 deletions

View File

@ -1,7 +1,7 @@
package v2raysocks package v2raysocks
type UserTraffic struct { type UserTraffic struct {
UID int `json:"user_id"` UID int `json:"uid"`
Upload int64 `json:"u"` Upload int64 `json:"u"`
Download int64 `json:"d"` Download int64 `json:"d"`
} }
@ -19,6 +19,10 @@ type NodeOnline struct {
IP string `json:"ip"` IP string `json:"ip"`
} }
type IllegalItem struct {
UID int `json:"uid"`
}
type REALITYConfig struct { type REALITYConfig struct {
Dest string `json:"dest,omitempty"` Dest string `json:"dest,omitempty"`
ProxyProtocolVer uint64 `json:"proxy_protocol_ver,omitempty"` ProxyProtocolVer uint64 `json:"proxy_protocol_ver,omitempty"`

View File

@ -159,8 +159,8 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
res, err := c.client.R(). res, err := c.client.R().
SetHeader("If-None-Match", c.eTags["config"]). SetHeader("If-None-Match", c.eTags["config"]).
SetQueryParams(map[string]string{ SetQueryParams(map[string]string{
"act": "config", "act": "config",
"nodetype": nodeType, "node_type": nodeType,
}). }).
ForceContentType("application/json"). ForceContentType("application/json").
Get(c.APIHost) Get(c.APIHost)
@ -213,8 +213,8 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
res, err := c.client.R(). res, err := c.client.R().
SetHeader("If-None-Match", c.eTags["user"]). SetHeader("If-None-Match", c.eTags["user"]).
SetQueryParams(map[string]string{ SetQueryParams(map[string]string{
"act": "user", "act": "user",
"nodetype": nodeType, "node_type": nodeType,
}). }).
ForceContentType("application/json"). ForceContentType("application/json").
Get(c.APIHost) Get(c.APIHost)
@ -239,22 +239,21 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
user.UID = response.Get("data").GetIndex(i).Get("id").MustInt() user.UID = response.Get("data").GetIndex(i).Get("id").MustInt()
switch c.NodeType { switch c.NodeType {
case "Shadowsocks": case "Shadowsocks":
user.Email = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("secret").MustString() user.Email = response.Get("data").GetIndex(i).Get("secret").MustString()
user.Passwd = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("secret").MustString() user.Passwd = response.Get("data").GetIndex(i).Get("secret").MustString()
user.Method = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("cipher").MustString() user.Method = response.Get("data").GetIndex(i).Get("cipher").MustString()
user.SpeedLimit = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("speed_limit").MustUint64() * 1000000 / 8 user.SpeedLimit = response.Get("data").GetIndex(i).Get("st").MustUint64() * 1000000 / 8
user.DeviceLimit = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("device_limit").MustInt() user.DeviceLimit = response.Get("data").GetIndex(i).Get("dt").MustInt()
case "Trojan": case "Trojan":
user.UUID = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString() user.UUID = response.Get("data").GetIndex(i).Get("password").MustString()
user.Email = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString() user.Email = response.Get("data").GetIndex(i).Get("password").MustString()
user.SpeedLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("speed_limit").MustUint64() * 1000000 / 8 user.SpeedLimit = response.Get("data").GetIndex(i).Get("st").MustUint64() * 1000000 / 8
user.DeviceLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("device_limit").MustInt() user.DeviceLimit = response.Get("data").GetIndex(i).Get("dt").MustInt()
case "V2ray", "Vmess", "Vless": case "V2ray", "Vmess", "Vless":
user.UUID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("uuid").MustString() user.UUID = response.Get("data").GetIndex(i).Get("uuid").MustString()
user.Email = response.Get("data").GetIndex(i).Get("v2ray_user").Get("email").MustString() user.Email = user.UUID + "@x.com"
user.AlterID = uint16(response.Get("data").GetIndex(i).Get("v2ray_user").Get("alter_id").MustUint64()) user.SpeedLimit = response.Get("data").GetIndex(i).Get("st").MustUint64() * 1000000 / 8
user.SpeedLimit = response.Get("data").GetIndex(i).Get("v2ray_user").Get("speed_limit").MustUint64() * 1000000 / 8 user.DeviceLimit = response.Get("data").GetIndex(i).Get("dt").MustInt()
user.DeviceLimit = response.Get("data").GetIndex(i).Get("v2ray_user").Get("device_limit").MustInt()
} }
if c.SpeedLimit > 0 { if c.SpeedLimit > 0 {
user.SpeedLimit = uint64((c.SpeedLimit * 1000000) / 8) user.SpeedLimit = uint64((c.SpeedLimit * 1000000) / 8)
@ -283,8 +282,8 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
res, err := c.client.R(). res, err := c.client.R().
SetQueryParam("node_id", strconv.Itoa(c.NodeID)). SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
SetQueryParams(map[string]string{ SetQueryParams(map[string]string{
"act": "submit", "act": "submit",
"nodetype": strings.ToLower(c.NodeType), "node_type": strings.ToLower(c.NodeType),
}). }).
SetBody(data). SetBody(data).
ForceContentType("application/json"). ForceContentType("application/json").
@ -327,8 +326,8 @@ func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) {
res, err := c.client.R(). res, err := c.client.R().
SetQueryParam("node_id", strconv.Itoa(c.NodeID)). SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
SetQueryParams(map[string]string{ SetQueryParams(map[string]string{
"act": "nodestatus", "act": "nodestatus",
"nodetype": strings.ToLower(c.NodeType), "node_type": strings.ToLower(c.NodeType),
}). }).
SetBody(systemload). SetBody(systemload).
ForceContentType("application/json"). ForceContentType("application/json").
@ -350,8 +349,8 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro
res, err := c.client.R(). res, err := c.client.R().
SetQueryParam("node_id", strconv.Itoa(c.NodeID)). SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
SetQueryParams(map[string]string{ SetQueryParams(map[string]string{
"act": "onlineusers", "act": "onlineusers",
"nodetype": strings.ToLower(c.NodeType), "node_type": strings.ToLower(c.NodeType),
}). }).
SetBody(data). SetBody(data).
ForceContentType("application/json"). ForceContentType("application/json").
@ -365,6 +364,26 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro
// ReportIllegal implements the API interface // ReportIllegal implements the API interface
func (c *APIClient) ReportIllegal(detectResultList *[]api.DetectResult) error { func (c *APIClient) ReportIllegal(detectResultList *[]api.DetectResult) error {
data := make([]IllegalItem, len(*detectResultList))
for i, r := range *detectResultList {
data[i] = IllegalItem{
UID: r.UID,
}
}
res, err := c.client.R().
SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
SetQueryParams(map[string]string{
"act": "illegal",
"node_type": strings.ToLower(c.NodeType),
}).
SetBody(data).
ForceContentType("application/json").
Post(c.APIHost)
_, err = c.parseResponse(res, "", err)
if err != nil {
return err
}
return nil return nil
} }
@ -423,7 +442,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
var enableTLS bool var enableTLS bool
var enableVless bool var enableVless bool
var enableReality bool var enableReality bool
var alterID uint16 = 0 var vlessFlow string
tmpInboundInfo := nodeInfoResponse.Get("inbounds").MustArray() tmpInboundInfo := nodeInfoResponse.Get("inbounds").MustArray()
marshalByte, _ := json.Marshal(tmpInboundInfo[0].(map[string]interface{})) marshalByte, _ := json.Marshal(tmpInboundInfo[0].(map[string]interface{}))
@ -436,6 +455,12 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
case "ws": case "ws":
path = inboundInfo.Get("streamSettings").Get("wsSettings").Get("path").MustString() path = inboundInfo.Get("streamSettings").Get("wsSettings").Get("path").MustString()
host = inboundInfo.Get("streamSettings").Get("wsSettings").Get("headers").Get("Host").MustString() host = inboundInfo.Get("streamSettings").Get("wsSettings").Get("headers").Get("Host").MustString()
case "httpupgrade":
host = inboundInfo.Get("streamSettings").Get("httpupgradeSettings").Get("Host").MustString()
path = inboundInfo.Get("streamSettings").Get("httpupgradeSettings").Get("path").MustString()
case "splithttp":
host = inboundInfo.Get("streamSettings").Get("splithttpSettings").Get("Host").MustString()
path = inboundInfo.Get("streamSettings").Get("splithttpSettings").Get("path").MustString()
case "grpc": case "grpc":
if data, ok := inboundInfo.Get("streamSettings").Get("grpcSettings").CheckGet("serviceName"); ok { if data, ok := inboundInfo.Get("streamSettings").Get("grpcSettings").CheckGet("serviceName"); ok {
serviceName = data.MustString() serviceName = data.MustString()
@ -448,12 +473,11 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
header = httpHeader header = httpHeader
} }
} }
} }
enableTLS = inboundInfo.Get("streamSettings").Get("security").MustString() == "tls" enableTLS = inboundInfo.Get("streamSettings").Get("security").MustString() == "tls"
enableVless = inboundInfo.Get("streamSettings").Get("security").MustString() == "reality" enableVless = inboundInfo.Get("protocol").MustString() == "vless"
enableReality = enableVless enableReality = inboundInfo.Get("streamSettings").Get("security").MustString() == "reality"
realityConfig := new(api.REALITYConfig) realityConfig := new(api.REALITYConfig)
if enableVless { if enableVless {
@ -470,19 +494,26 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
} }
} }
// XTLS only supports TLS and REALITY directly for now
if transportProtocol == "tcp" && enableReality {
vlessFlow = "xtls-rprx-vision"
} else {
vlessFlow = c.VlessFlow
}
// Create GeneralNodeInfo // Create GeneralNodeInfo
// AlterID will be updated after next sync // AlterID will be updated after next sync
nodeInfo := &api.NodeInfo{ nodeInfo := &api.NodeInfo{
NodeType: c.NodeType, NodeType: c.NodeType,
NodeID: c.NodeID, NodeID: c.NodeID,
Port: port, Port: port,
AlterID: alterID, AlterID: 0,
TransportProtocol: transportProtocol, TransportProtocol: transportProtocol,
EnableTLS: enableTLS, EnableTLS: enableTLS,
Path: path, Path: path,
Host: host, Host: host,
EnableVless: enableVless, EnableVless: enableVless,
VlessFlow: c.VlessFlow, VlessFlow: vlessFlow,
ServiceName: serviceName, ServiceName: serviceName,
Header: header, Header: header,
EnableREALITY: enableReality, EnableREALITY: enableReality,

View File

@ -7,7 +7,7 @@ import (
) )
var ( var (
version = "0.9.4" version = "0.9.5"
codename = "XrayR" codename = "XrayR"
intro = "A Xray backend that supports many panels" intro = "A Xray backend that supports many panels"
) )