From a2b27076b11c64596b8d7825f7652517e832ea43 Mon Sep 17 00:00:00 2001 From: autumn Date: Wed, 30 Jun 2021 18:36:27 +0800 Subject: [PATCH] grpc share link and multi user --- .../Models/Projects/XraySettings.cs | 5 +++ ProxySuper.Core/Services/ShareLink.cs | 8 +++- ProxySuper.Core/Services/XrayConfigBuilder.cs | 37 +++++++++++++++---- .../ViewModels/XrayEditorViewModel.cs | 12 ++++++ .../Controls/XraySettingsControl.xaml | 16 ++++++++ ProxySuper.WPF/Resources/Languages/en.xaml | 2 + ProxySuper.WPF/Resources/Languages/tw_cn.xaml | 2 + ProxySuper.WPF/Resources/Languages/zh_cn.xaml | 2 + 8 files changed, 76 insertions(+), 8 deletions(-) diff --git a/ProxySuper.Core/Models/Projects/XraySettings.cs b/ProxySuper.Core/Models/Projects/XraySettings.cs index 4a55620..1441094 100644 --- a/ProxySuper.Core/Models/Projects/XraySettings.cs +++ b/ProxySuper.Core/Models/Projects/XraySettings.cs @@ -84,6 +84,11 @@ namespace ProxySuper.Core.Models.Projects /// public string UUID { get; set; } + /// + /// 多用户 + /// + public List MulitUUID { get; set; } = new List(); + /// /// 伪装域名 /// diff --git a/ProxySuper.Core/Services/ShareLink.cs b/ProxySuper.Core/Services/ShareLink.cs index 0879484..817d833 100644 --- a/ProxySuper.Core/Services/ShareLink.cs +++ b/ProxySuper.Core/Services/ShareLink.cs @@ -168,7 +168,7 @@ namespace ProxySuper.Core.Services case XrayType.VLESS_gRPC: _protocol = "vless"; _type = "grpc"; - _path = settings.VLESS_gRPC_ServiceName; + _port = settings.VLESS_gRPC_Port; _descriptiveText = "vless-gRPC"; break; case XrayType.Trojan_TCP: @@ -198,6 +198,12 @@ namespace ProxySuper.Core.Services { parametersURL += "&flow=xtls-rprx-direct"; } + + + if (xrayType == XrayType.VLESS_gRPC) + { + parametersURL += $"&serviceName={settings.VLESS_gRPC_ServiceName}&mode=gun"; + } } diff --git a/ProxySuper.Core/Services/XrayConfigBuilder.cs b/ProxySuper.Core/Services/XrayConfigBuilder.cs index f46cbdb..4d53fbe 100644 --- a/ProxySuper.Core/Services/XrayConfigBuilder.cs +++ b/ProxySuper.Core/Services/XrayConfigBuilder.cs @@ -95,8 +95,31 @@ namespace ProxySuper.Core.Services return caddyStr; } + private static void SetClients(dynamic bound, List uuidList, bool withXtls = false) + { + bound.settings.clients.Clear(); + uuidList.ForEach(id => + { + object obj; + if (!withXtls) + { + obj = new { id = id }; + } + else + { + obj = new { id = id, flow = "xtls-rprx-direct" }; + } + + bound.settings.clients.Add(JToken.FromObject(obj)); + }); + } + + public static string BuildXrayConfig(XraySettings parameters) { + var uuidList = parameters.MulitUUID; + uuidList.Insert(0, parameters.UUID); + var xrayConfig = LoadXrayConfig(); var baseBound = GetBound("VLESS_TCP_XTLS.json"); baseBound.port = parameters.Port; @@ -105,13 +128,13 @@ namespace ProxySuper.Core.Services dest = FullbackPort })); xrayConfig.inbounds.Add(baseBound); - baseBound.settings.clients[0].id = parameters.UUID; + SetClients(baseBound, uuidList, withXtls: true); if (parameters.Types.Contains(XrayType.VLESS_WS)) { var wsInbound = GetBound("VLESS_WS.json"); wsInbound.port = VLESS_WS_Port; - wsInbound.settings.clients[0].id = parameters.UUID; + SetClients(wsInbound, uuidList); wsInbound.streamSettings.wsSettings.path = parameters.VLESS_WS_Path; baseBound.settings.fallbacks.Add(JToken.FromObject(new { @@ -126,7 +149,7 @@ namespace ProxySuper.Core.Services { var gRPCInBound = GetBound("VLESS_gRPC.json"); gRPCInBound.port = parameters.VLESS_gRPC_Port; - gRPCInBound.settings.clients[0].id = parameters.UUID; + SetClients(gRPCInBound, uuidList); gRPCInBound.streamSettings.grpcSettings.serviceName = parameters.VLESS_gRPC_ServiceName; gRPCInBound.streamSettings.tlsSettings.serverName = parameters.Domain; xrayConfig.inbounds.Add(JToken.FromObject(gRPCInBound)); @@ -136,7 +159,7 @@ namespace ProxySuper.Core.Services { var kcpBound = GetBound("VLESS_KCP.json"); kcpBound.port = parameters.VLESS_KCP_Port; - kcpBound.settings.clients[0].id = parameters.UUID; + SetClients(kcpBound, uuidList); kcpBound.streamSettings.kcpSettings.header.type = parameters.VLESS_KCP_Type; kcpBound.streamSettings.kcpSettings.seed = parameters.VLESS_KCP_Seed; xrayConfig.inbounds.Add(JToken.FromObject(kcpBound)); @@ -146,7 +169,7 @@ namespace ProxySuper.Core.Services { var mtcpBound = GetBound("VMESS_TCP.json"); mtcpBound.port = VMESS_TCP_Port; - mtcpBound.settings.clients[0].id = parameters.UUID; + SetClients(mtcpBound, uuidList); mtcpBound.streamSettings.tcpSettings.header.request.path = parameters.VMESS_TCP_Path; baseBound.settings.fallbacks.Add(JToken.FromObject(new { @@ -161,7 +184,7 @@ namespace ProxySuper.Core.Services { var mwsBound = GetBound("VMESS_WS.json"); mwsBound.port = VMESS_WS_Port; - mwsBound.settings.clients[0].id = parameters.UUID; + SetClients(mwsBound, uuidList); mwsBound.streamSettings.wsSettings.path = parameters.VMESS_WS_Path; baseBound.settings.fallbacks.Add(JToken.FromObject(new { @@ -176,7 +199,7 @@ namespace ProxySuper.Core.Services { var kcpBound = GetBound("VMESS_KCP.json"); kcpBound.port = parameters.VMESS_KCP_Port; - kcpBound.settings.clients[0].id = parameters.UUID; + SetClients(kcpBound, uuidList); kcpBound.streamSettings.kcpSettings.header.type = parameters.VMESS_KCP_Type; kcpBound.streamSettings.kcpSettings.seed = parameters.VMESS_KCP_Seed; xrayConfig.inbounds.Add(JToken.FromObject(kcpBound)); diff --git a/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs b/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs index 3a2c4c5..20ff3cd 100644 --- a/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs +++ b/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs @@ -110,6 +110,18 @@ namespace ProxySuper.Core.ViewModels } } + public string MultiUUID + { + get => string.Join(",", Settings.MulitUUID); + set + { + var input = value.Replace(',', ','); + var arr = input.Split(',').ToList(); + Settings.MulitUUID = arr; + RaisePropertyChanged("MultiUUID"); + } + } + public string Domain { get => Settings.Domain; diff --git a/ProxySuper.WPF/Controls/XraySettingsControl.xaml b/ProxySuper.WPF/Controls/XraySettingsControl.xaml index 427a8e9..d843b2d 100644 --- a/ProxySuper.WPF/Controls/XraySettingsControl.xaml +++ b/ProxySuper.WPF/Controls/XraySettingsControl.xaml @@ -319,6 +319,22 @@