mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-07-30 22:16:54 +00:00
feature: add support v2board new API
update: add eTag on fetch users for save resources update: split cert monitor service update: refactor log format update: add support shadowsocks_2022 The cert monitor period = UpdatePeriodic * 60 The xray-core official is not implementation of proxy.UserManager feature. So it may change in the future.
This commit is contained in:
@@ -2,11 +2,15 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
|
||||
C "github.com/sagernet/sing/common"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/uuid"
|
||||
"github.com/xtls/xray-core/core"
|
||||
"github.com/xtls/xray-core/infra/conf"
|
||||
|
||||
@@ -49,9 +53,10 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
setting json.RawMessage
|
||||
)
|
||||
|
||||
var proxySetting interface{}
|
||||
var proxySetting any
|
||||
// Build Protocol and Protocol setting
|
||||
if nodeInfo.NodeType == "V2ray" {
|
||||
switch nodeInfo.NodeType {
|
||||
case "V2ray":
|
||||
if nodeInfo.EnableVless {
|
||||
protocol = "vless"
|
||||
// Enable fallback
|
||||
@@ -74,7 +79,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
protocol = "vmess"
|
||||
proxySetting = &conf.VMessInboundConfig{}
|
||||
}
|
||||
} else if nodeInfo.NodeType == "Trojan" {
|
||||
case "Trojan":
|
||||
protocol = "trojan"
|
||||
// Enable fallback
|
||||
if config.EnableFallback {
|
||||
@@ -89,23 +94,30 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
} else {
|
||||
proxySetting = &conf.TrojanServerConfig{}
|
||||
}
|
||||
} else if nodeInfo.NodeType == "Shadowsocks" || nodeInfo.NodeType == "Shadowsocks-Plugin" {
|
||||
case "Shadowsocks", "Shadowsocks-Plugin":
|
||||
protocol = "shadowsocks"
|
||||
proxySetting = &conf.ShadowsocksServerConfig{}
|
||||
randomPasswd := uuid.New()
|
||||
defaultSSuser := &conf.ShadowsocksUserConfig{
|
||||
Cipher: "aes-128-gcm",
|
||||
Password: randomPasswd.String(),
|
||||
cipher := strings.ToLower(nodeInfo.CypherMethod)
|
||||
|
||||
proxySetting = &conf.ShadowsocksServerConfig{
|
||||
Cipher: cipher,
|
||||
Password: nodeInfo.ServerKey, // shadowsocks2022 shareKey
|
||||
}
|
||||
|
||||
proxySetting, _ := proxySetting.(*conf.ShadowsocksServerConfig)
|
||||
proxySetting.Users = append(proxySetting.Users, defaultSSuser)
|
||||
// shadowsocks must have a random password
|
||||
if !C.Contains(shadowaead_2022.List, cipher) {
|
||||
b := make([]byte, 16)
|
||||
rand.Read(b)
|
||||
proxySetting.Password = hex.EncodeToString(b)
|
||||
}
|
||||
|
||||
proxySetting.NetworkList = &conf.NetworkList{"tcp", "udp"}
|
||||
proxySetting.IVCheck = true
|
||||
if config.DisableIVCheck {
|
||||
proxySetting.IVCheck = false
|
||||
}
|
||||
|
||||
} else if nodeInfo.NodeType == "dokodemo-door" {
|
||||
case "dokodemo-door":
|
||||
protocol = "dokodemo-door"
|
||||
proxySetting = struct {
|
||||
Host string `json:"address"`
|
||||
@@ -114,7 +126,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
Host: "v1.mux.cool",
|
||||
NetworkList: []string{"tcp", "udp"},
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported node type: %s, Only support: V2ray, Trojan, Shadowsocks, and Shadowsocks-Plugin", nodeInfo.NodeType)
|
||||
}
|
||||
|
||||
@@ -122,6 +134,8 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
||||
}
|
||||
inboundDetourConfig.Protocol = protocol
|
||||
inboundDetourConfig.Settings = &setting
|
||||
|
||||
// Build streamSettings
|
||||
streamSetting = new(conf.StreamConfig)
|
||||
@@ -130,13 +144,15 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("convert TransportProtocol failed: %s", err)
|
||||
}
|
||||
if networkType == "tcp" {
|
||||
|
||||
switch networkType {
|
||||
case "tcp":
|
||||
tcpSetting := &conf.TCPConfig{
|
||||
AcceptProxyProtocol: config.EnableProxyProtocol,
|
||||
HeaderConfig: nodeInfo.Header,
|
||||
}
|
||||
streamSetting.TCPSettings = tcpSetting
|
||||
} else if networkType == "websocket" {
|
||||
case "websocket":
|
||||
headers := make(map[string]string)
|
||||
headers["Host"] = nodeInfo.Host
|
||||
wsSettings := &conf.WebSocketConfig{
|
||||
@@ -145,14 +161,14 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
Headers: headers,
|
||||
}
|
||||
streamSetting.WSSettings = wsSettings
|
||||
} else if networkType == "http" {
|
||||
case "http":
|
||||
hosts := conf.StringList{nodeInfo.Host}
|
||||
httpSettings := &conf.HTTPConfig{
|
||||
Host: &hosts,
|
||||
Path: nodeInfo.Path,
|
||||
}
|
||||
streamSetting.HTTPSettings = httpSettings
|
||||
} else if networkType == "grpc" {
|
||||
case "grpc":
|
||||
grpcSettings := &conf.GRPCConfig{
|
||||
ServiceName: nodeInfo.ServiceName,
|
||||
}
|
||||
@@ -160,6 +176,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
}
|
||||
|
||||
streamSetting.Network = &transportProtocol
|
||||
|
||||
// Build TLS and XTLS settings
|
||||
if nodeInfo.EnableTLS && config.CertConfig.CertMode != "none" {
|
||||
streamSetting.Security = nodeInfo.TLSType
|
||||
@@ -182,6 +199,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
streamSetting.XTLSSettings = xtlsSettings
|
||||
}
|
||||
}
|
||||
|
||||
// Support ProxyProtocol for any transport protocol
|
||||
if networkType != "tcp" && networkType != "ws" && config.EnableProxyProtocol {
|
||||
sockoptConfig := &conf.SocketConfig{
|
||||
@@ -189,9 +207,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
|
||||
}
|
||||
streamSetting.SocketSettings = sockoptConfig
|
||||
}
|
||||
inboundDetourConfig.Protocol = protocol
|
||||
inboundDetourConfig.StreamSetting = streamSetting
|
||||
inboundDetourConfig.Settings = &setting
|
||||
|
||||
return inboundDetourConfig.Build()
|
||||
}
|
||||
|
Reference in New Issue
Block a user