From 992343769185d5ba8d193a21a79c159975a9676c Mon Sep 17 00:00:00 2001 From: autumn Date: Tue, 29 Jun 2021 17:43:48 +0800 Subject: [PATCH] add grpc params --- ProxySuper.Core/Helpers/Utils.cs | 8 ++++ .../Models/Projects/XraySettings.cs | 9 +++-- ProxySuper.Core/ProxySuper.Core.csproj | 1 - ProxySuper.Core/Services/XrayConfigBuilder.cs | 15 +++++++- .../Controls/XraySettingsControl.xaml | 38 +++++++++++-------- ProxySuper.WPF/ProxySuper.WPF.csproj | 36 ++---------------- ProxySuper.WPF/Resources/Languages/en.xaml | 2 + ProxySuper.WPF/Resources/Languages/tw_cn.xaml | 2 + ProxySuper.WPF/Resources/Languages/zh_cn.xaml | 2 + .../Templates/xray/caddy/grpc.caddyfile | 10 +++++ .../xray/server/05_inbounds/VLESS_gRPC.json | 10 +---- 11 files changed, 72 insertions(+), 61 deletions(-) create mode 100644 ProxySuper.WPF/Templates/xray/caddy/grpc.caddyfile diff --git a/ProxySuper.Core/Helpers/Utils.cs b/ProxySuper.Core/Helpers/Utils.cs index 6d5d0ff..bb68b88 100644 --- a/ProxySuper.Core/Helpers/Utils.cs +++ b/ProxySuper.Core/Helpers/Utils.cs @@ -33,5 +33,13 @@ namespace ProxySuper.Core.Services { return DateTime.Now.Ticks.ToString(); } + + private static Random random = new Random(); + public static string RandomString(int length) + { + const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + return new string(Enumerable.Repeat(chars, length) + .Select(s => s[random.Next(s.Length)]).ToArray()); + } } } diff --git a/ProxySuper.Core/Models/Projects/XraySettings.cs b/ProxySuper.Core/Models/Projects/XraySettings.cs index f74272a..f554109 100644 --- a/ProxySuper.Core/Models/Projects/XraySettings.cs +++ b/ProxySuper.Core/Models/Projects/XraySettings.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using ProxySuper.Core.Services; using System; using System.Collections.Generic; using System.Linq; @@ -21,13 +22,13 @@ namespace ProxySuper.Core.Models.Projects UUID = guid; Types = new List(); - VLESS_WS_Path = "/vlessws"; + VLESS_WS_Path = "/" + Utils.RandomString(6); VLESS_KCP_Type = "none"; VLESS_KCP_Seed = guid; - VLESS_gRPC_ServiceName = "xray_gRPC"; + VLESS_gRPC_ServiceName = "/" + Utils.RandomString(7); - VMESS_WS_Path = "/vmessws"; - VMESS_TCP_Path = "/vmesstcp"; + VMESS_WS_Path = "/" + Utils.RandomString(8); + VMESS_TCP_Path = "/" + Utils.RandomString(9); VMESS_KCP_Seed = guid; VMESS_KCP_Type = "none"; diff --git a/ProxySuper.Core/ProxySuper.Core.csproj b/ProxySuper.Core/ProxySuper.Core.csproj index ef51069..db1bc85 100644 --- a/ProxySuper.Core/ProxySuper.Core.csproj +++ b/ProxySuper.Core/ProxySuper.Core.csproj @@ -67,7 +67,6 @@ - diff --git a/ProxySuper.Core/Services/XrayConfigBuilder.cs b/ProxySuper.Core/Services/XrayConfigBuilder.cs index 09f19b2..e2e0144 100644 --- a/ProxySuper.Core/Services/XrayConfigBuilder.cs +++ b/ProxySuper.Core/Services/XrayConfigBuilder.cs @@ -29,6 +29,7 @@ namespace ProxySuper.Core.Services public static int VLESS_WS_Port = 1111; public static int VLESS_H2_Port = 1112; public static int VLESS_mKCP_Port = 1113; + public static int VLESS_gRPC_Port = 1114; public static int VMESS_TCP_Port = 1210; public static int VMESS_WS_Port = 1211; @@ -93,6 +94,18 @@ namespace ProxySuper.Core.Services caddyStr = caddyStr.Replace("##reverse_proxy##", ""); } + if (parameters.Types.Contains(XrayType.VLESS_gRPC)) + { + var grpcCaddyfile = File.ReadAllText(Path.Combine(CaddyFileDir, "grpc.caddyfile")); + grpcCaddyfile = grpcCaddyfile.Replace("##domain##", parameters.Domain); + grpcCaddyfile = grpcCaddyfile.Replace("##port##", parameters.VLESS_gRPC_Port.ToString()); + grpcCaddyfile = grpcCaddyfile.Replace("##local_port##", VLESS_gRPC_Port.ToString()); + grpcCaddyfile = grpcCaddyfile.Replace("##path##", parameters.VLESS_gRPC_ServiceName); + + caddyStr += "\n"; + caddyStr += grpcCaddyfile; + } + return caddyStr; } @@ -126,7 +139,7 @@ namespace ProxySuper.Core.Services if (parameters.Types.Contains(XrayType.VLESS_gRPC)) { var gRPCInBound = GetBound("VLESS_gRPC.json"); - gRPCInBound.port = parameters.VLESS_gRPC_Port; + gRPCInBound.port = VLESS_gRPC_Port; gRPCInBound.settings.clients[0].id = parameters.UUID; gRPCInBound.streamSettings.grpcSettings.serviceName = parameters.VLESS_gRPC_ServiceName; xrayConfig.inbounds.Add(JToken.FromObject(gRPCInBound)); diff --git a/ProxySuper.WPF/Controls/XraySettingsControl.xaml b/ProxySuper.WPF/Controls/XraySettingsControl.xaml index d9e9b48..427a8e9 100644 --- a/ProxySuper.WPF/Controls/XraySettingsControl.xaml +++ b/ProxySuper.WPF/Controls/XraySettingsControl.xaml @@ -42,6 +42,14 @@