From 95380c5e4754fef9d42c6cc750f1e7e66cd2d5ac Mon Sep 17 00:00:00 2001 From: next-autumn Date: Mon, 19 Apr 2021 12:12:23 +0800 Subject: [PATCH] review --- .../Models/Developers/ConfigBuilder.cs | 19 +- ProxySU_Core/Models/Developers/XrayProject.cs | 10 +- ProxySU_Core/Models/XraySettings.cs | 25 -- ProxySU_Core/Models/XrayType.cs | 34 +++ ProxySU_Core/ProxySU_Core.csproj | 5 + .../Templates/xray/caddy/base.caddyfile | 6 +- .../xray/server/05_inbounds/Trojan_TCP.json | 2 +- .../xray/server/05_inbounds/VLESS_gRPC.json | 1 + .../Views/ClientInfo/ClientInfoWindow.xaml | 55 ++-- .../Views/ClientInfo/ClientInfoWindow.xaml.cs | 69 +++++ ProxySU_Core/Views/MainWindow.xaml | 36 ++- ProxySU_Core/Views/MainWindow.xaml.cs | 26 +- .../RecordEditor/RecordEditorWindow.xaml | 178 +----------- .../ShadowSocksEditorControl.xaml | 77 +++-- .../RecordEditor/TrojanEditorControl.xaml | 42 +-- .../RecordEditor/VlessEditorControl.xaml | 270 ++++++++---------- .../RecordEditor/VmessEditorControl.xaml | 220 +++++++------- ProxySU_Core/Views/TerminalWindow.xaml | 34 ++- ProxySU_Core/Views/TerminalWindow.xaml.cs | 6 +- ProxySU_Core/packages.config | 1 + 20 files changed, 496 insertions(+), 620 deletions(-) create mode 100644 ProxySU_Core/Models/XrayType.cs diff --git a/ProxySU_Core/Models/Developers/ConfigBuilder.cs b/ProxySU_Core/Models/Developers/ConfigBuilder.cs index 5587e62..66e5b6f 100644 --- a/ProxySU_Core/Models/Developers/ConfigBuilder.cs +++ b/ProxySU_Core/Models/Developers/ConfigBuilder.cs @@ -37,6 +37,8 @@ namespace ProxySU_Core.Models.Developers public static int Trojan_TCP_Port = 1310; public static int Trojan_WS_Port = 1311; + public static int FullbackPort = 8080; + public static dynamic LoadXrayConfig() @@ -71,15 +73,7 @@ namespace ProxySU_Core.Models.Developers { var caddyStr = File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile")); caddyStr = caddyStr.Replace("##domain##", parameters.Domain); - - if (parameters.Port != 443) - { - caddyStr = caddyStr.Replace(":##port##", ""); - } - else - { - caddyStr = caddyStr.Replace("##port##", 80.ToString()); - } + caddyStr = caddyStr.Replace("##port##", FullbackPort.ToString()); if (!useCustomWeb && !string.IsNullOrEmpty(parameters.MaskDomain)) { @@ -109,7 +103,7 @@ namespace ProxySU_Core.Models.Developers baseBound.port = parameters.Port; baseBound.settings.fallbacks.Add(JToken.FromObject(new { - dest = 80 + dest = FullbackPort })); xrayConfig.inbounds.Add(baseBound); baseBound.settings.clients[0].id = parameters.UUID; @@ -129,7 +123,7 @@ namespace ProxySU_Core.Models.Developers xrayConfig.inbounds.Add(JToken.FromObject(wsInbound)); } - if(parameters.Types.Contains(XrayType.VLESS_gRPC)) + if (parameters.Types.Contains(XrayType.VLESS_gRPC)) { var gRPCInBound = GetBound("VLESS_gRPC.json"); gRPCInBound.port = parameters.VLESS_gRPC_Port; @@ -138,7 +132,7 @@ namespace ProxySU_Core.Models.Developers xrayConfig.inbounds.Add(JToken.FromObject(gRPCInBound)); } - if(parameters.Types.Contains(XrayType.VLESS_KCP)) + if (parameters.Types.Contains(XrayType.VLESS_KCP)) { var kcpBound = GetBound("VLESS_KCP.json"); kcpBound.port = parameters.VLESS_KCP_Port; @@ -193,6 +187,7 @@ namespace ProxySU_Core.Models.Developers var trojanTcpBound = GetBound("Trojan_TCP.json"); trojanTcpBound.port = Trojan_TCP_Port; trojanTcpBound.settings.clients[0].password = parameters.TrojanPassword; + trojanTcpBound.settings.fallbacks[0].dest = FullbackPort; baseBound.settings.fallbacks[0] = JToken.FromObject(new { dest = Trojan_TCP_Port, diff --git a/ProxySU_Core/Models/Developers/XrayProject.cs b/ProxySU_Core/Models/Developers/XrayProject.cs index 1a160b2..482ac4b 100644 --- a/ProxySU_Core/Models/Developers/XrayProject.cs +++ b/ProxySU_Core/Models/Developers/XrayProject.cs @@ -101,7 +101,7 @@ namespace ProxySU_Core.Models.Developers } } - public void Uninstall() + public void UninstallProxy() { EnsureRootAuth(); WriteOutput("卸载Caddy"); @@ -149,13 +149,11 @@ namespace ProxySU_Core.Models.Developers /// /// 重装Caddy /// - public void ReinstallCaddy() + public void DoUninstallCaddy() { EnsureRootAuth(); - EnsureSystemEnv(); - InstallCaddy(); - UploadCaddyFile(); - WriteOutput("************ 重装Caddy完成 ************"); + UninstallCaddy(); + WriteOutput("************ 卸载Caddy完成 ************"); } /// diff --git a/ProxySU_Core/Models/XraySettings.cs b/ProxySU_Core/Models/XraySettings.cs index 69d5354..ed0efba 100644 --- a/ProxySU_Core/Models/XraySettings.cs +++ b/ProxySU_Core/Models/XraySettings.cs @@ -204,29 +204,4 @@ namespace ProxySU_Core.Models } - public enum XrayType - { - // 入口 - VLESS_TCP_XTLS = 100, - - // VLESS 101开头 - VLESS_TCP = 101, - VLESS_WS = 102, - VLESS_H2 = 103, - VLESS_KCP = 104, - VLESS_gRPC = 110, - - // VMESS 201开头 - VMESS_TCP = 201, - VMESS_WS = 202, - VMESS_H2 = 203, - VMESS_KCP = 204, - - // Trojan 301开头 - Trojan_TCP = 301, - Trojan_WS = 302, - - // SS - ShadowsocksAEAD = 401 - } } diff --git a/ProxySU_Core/Models/XrayType.cs b/ProxySU_Core/Models/XrayType.cs new file mode 100644 index 0000000..6611113 --- /dev/null +++ b/ProxySU_Core/Models/XrayType.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySU_Core.Models +{ + public enum XrayType + { + // 入口 + VLESS_TCP_XTLS = 100, + + // VLESS 101开头 + VLESS_TCP = 101, + VLESS_WS = 102, + VLESS_H2 = 103, + VLESS_KCP = 104, + VLESS_gRPC = 110, + + // VMESS 201开头 + VMESS_TCP = 201, + VMESS_WS = 202, + VMESS_H2 = 203, + VMESS_KCP = 204, + + // Trojan 301开头 + Trojan_TCP = 301, + Trojan_WS = 302, + + // SS + ShadowsocksAEAD = 401 + } +} diff --git a/ProxySU_Core/ProxySU_Core.csproj b/ProxySU_Core/ProxySU_Core.csproj index e136d8a..9717368 100644 --- a/ProxySU_Core/ProxySU_Core.csproj +++ b/ProxySU_Core/ProxySU_Core.csproj @@ -89,6 +89,9 @@ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\QRCoder.1.4.1\lib\net40\QRCoder.dll + ..\packages\SSH.NET.2020.0.1\lib\net40\Renci.SshNet.dll @@ -96,6 +99,7 @@ + @@ -126,6 +130,7 @@ + diff --git a/ProxySU_Core/Templates/xray/caddy/base.caddyfile b/ProxySU_Core/Templates/xray/caddy/base.caddyfile index e5105a3..7975d73 100644 --- a/ProxySU_Core/Templates/xray/caddy/base.caddyfile +++ b/ProxySU_Core/Templates/xray/caddy/base.caddyfile @@ -1,5 +1,9 @@ -##domain##:##port## { +:##port## { root * /usr/share/caddy file_server ##reverse_proxy## +} + +##domain##:80 { + redir https://##domain##{uri} } \ No newline at end of file diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_TCP.json b/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_TCP.json index 5f17571..8ea5ad9 100644 --- a/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_TCP.json +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_TCP.json @@ -10,7 +10,7 @@ ], "fallbacks": [ { - "dest": 80 + "dest": 8080 } ] }, diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_gRPC.json b/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_gRPC.json index d223f32..9ae0b21 100644 --- a/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_gRPC.json +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/VLESS_gRPC.json @@ -1,5 +1,6 @@ { "port": 2002, + "listen": "127.0.0.1", "protocol": "vless", "settings": { "clients": [ diff --git a/ProxySU_Core/Views/ClientInfo/ClientInfoWindow.xaml b/ProxySU_Core/Views/ClientInfo/ClientInfoWindow.xaml index b6f62d9..701f8d7 100644 --- a/ProxySU_Core/Views/ClientInfo/ClientInfoWindow.xaml +++ b/ProxySU_Core/Views/ClientInfo/ClientInfoWindow.xaml @@ -5,33 +5,43 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls" xmlns:local="clr-namespace:ProxySU_Core.Views.ClientInfo" - xmlns:dev="clr-namespace:ProxySU_Core.Models.Developers" + xmlns:dev="clr-namespace:ProxySU_Core.Models.Developers" + xmlns:models="clr-namespace:ProxySU_Core.Models" mc:Ignorable="d" Title="查看配置" Height="500" Width="800"> - + + + + + + - - + - + @@ -39,41 +49,46 @@ - - + --> - + + Tag="{x:Static models:XrayType.VMESS_WS}" + IsEnabled="{Binding Settings.Checked_VMESS_WS}" + Style="{StaticResource MaterialDesignNavigationRailTabItem}" + Header="VMESS-WebSocket-TLS"> + Tag="{x:Static models:XrayType.VMESS_KCP}" + IsEnabled="{Binding Settings.Checked_VMESS_KCP}" + Style="{StaticResource MaterialDesignNavigationRailTabItem}" + Header="VMESS-mKCP"> @@ -81,9 +96,11 @@ @@ -94,9 +111,11 @@ @@ -105,5 +124,7 @@ + + diff --git a/ProxySU_Core/Views/ClientInfo/ClientInfoWindow.xaml.cs b/ProxySU_Core/Views/ClientInfo/ClientInfoWindow.xaml.cs index e1361ba..2eed951 100644 --- a/ProxySU_Core/Views/ClientInfo/ClientInfoWindow.xaml.cs +++ b/ProxySU_Core/Views/ClientInfo/ClientInfoWindow.xaml.cs @@ -1,7 +1,10 @@ using ProxySU_Core.Models; using ProxySU_Core.ViewModels; +using QRCoder; using System; using System.Collections.Generic; +using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -32,5 +35,71 @@ namespace ProxySU_Core.Views.ClientInfo Settings = new XraySettingsViewModel(record.Settings); DataContext = this; } + + private void BuildQrCode(object sender, SelectionChangedEventArgs e) + { + var tabControl = e.Source as TabControl; + var item = (tabControl.SelectedItem as TabItem); + var type = (XrayType)item.Tag; + + string shareLink = string.Empty; + switch (type) + { + case XrayType.VLESS_TCP_XTLS: + shareLink = Settings.VLESS_TCP_XTLS_ShareLink; + break; + case XrayType.VLESS_TCP: + shareLink = Settings.VLESS_TCP_ShareLink; + break; + case XrayType.VLESS_WS: + shareLink = Settings.VLESS_WS_ShareLink; + break; + case XrayType.VLESS_H2: + break; + case XrayType.VLESS_KCP: + shareLink = Settings.VLESS_KCP_ShareLink; + break; + case XrayType.VLESS_gRPC: + shareLink = Settings.VLESS_gRPC_ShareLink; + break; + case XrayType.VMESS_TCP: + shareLink = Settings.VMESS_TCP_ShareLink; + break; + case XrayType.VMESS_WS: + shareLink = Settings.VMESS_WS_ShareLink; + break; + case XrayType.VMESS_H2: + break; + case XrayType.VMESS_KCP: + shareLink = Settings.VMESS_KCP_ShareLink; + break; + case XrayType.Trojan_TCP: + shareLink = Settings.Trojan_TCP_ShareLink; + break; + case XrayType.Trojan_WS: + break; + case XrayType.ShadowsocksAEAD: + shareLink = Settings.ShadowSocksShareLink; + break; + default: + break; + } + + + QRCodeGenerator qrGenerator = new QRCodeGenerator(); + QRCodeData qrCodeData = qrGenerator.CreateQrCode(shareLink, QRCodeGenerator.ECCLevel.Q); + QRCode qrCode = new QRCode(qrCodeData); + + Bitmap qrCodeImage = qrCode.GetGraphic(20); + MemoryStream ms = new MemoryStream(); + qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); + byte[] bytes = ms.GetBuffer(); + ms.Close(); + BitmapImage image = new BitmapImage(); + image.BeginInit(); + image.StreamSource = new MemoryStream(bytes); + image.EndInit(); + QrImage.Source = image; + } } } diff --git a/ProxySU_Core/Views/MainWindow.xaml b/ProxySU_Core/Views/MainWindow.xaml index 1423698..dab8d11 100644 --- a/ProxySU_Core/Views/MainWindow.xaml +++ b/ProxySU_Core/Views/MainWindow.xaml @@ -9,7 +9,7 @@ xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls" xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" TextElement.FontSize="14" - Title="ProxySU Core" Height="800" Width="1200"> + Title="ProxySU Core" Height="670" Width="1050"> @@ -44,16 +44,18 @@ + Padding="20"> - - +