From dc38de67d5336c82a5f34ad233d40f228190f426 Mon Sep 17 00:00:00 2001 From: nuxt-autumn Date: Mon, 5 Apr 2021 10:22:43 +0800 Subject: [PATCH] release v3.1.1 fix acme issue --- .../Models/Developers/ConfigBuilder.cs | 34 ++++++++++------- ProxySU_Core/Models/Developers/IParameters.cs | 4 ++ ProxySU_Core/Models/Developers/Project.cs | 8 ++-- ProxySU_Core/Models/Developers/XrayProject.cs | 12 +++--- ProxySU_Core/Models/ShareLink.cs | 4 +- ProxySU_Core/Models/XraySettings.cs | 11 ++++++ ProxySU_Core/Properties/AssemblyInfo.cs | 4 +- ProxySU_Core/ProxySU_Core.csproj | 1 + .../Templates/xray/caddy/base.caddyfile | 2 +- ProxySU_Core/ViewModels/BaseModel.cs | 38 +++++++++++++++++++ .../ViewModels/XraySettingsViewModel.cs | 33 +++++++++++++++- ProxySU_Core/Views/ClientInfoWindow.xaml | 4 +- ProxySU_Core/Views/MainWindow.xaml | 22 ++++++++++- ProxySU_Core/Views/RecordEditorWindow.xaml | 12 ++++++ ProxySU_Core/Views/TerminalWindow.xaml | 32 ++++++++++------ 15 files changed, 178 insertions(+), 43 deletions(-) create mode 100644 ProxySU_Core/ViewModels/BaseModel.cs diff --git a/ProxySU_Core/Models/Developers/ConfigBuilder.cs b/ProxySU_Core/Models/Developers/ConfigBuilder.cs index fdd6425..8786fdf 100644 --- a/ProxySU_Core/Models/Developers/ConfigBuilder.cs +++ b/ProxySU_Core/Models/Developers/ConfigBuilder.cs @@ -25,20 +25,18 @@ namespace ProxySU_Core.Models.Developers private const string ServerReverseDir = @"Templates\xray\server\09_reverse"; private const string CaddyFileDir = @"Templates\xray\caddy"; - public const int VLESS_TCP_Port = 1110; - public const int VLESS_WS_Port = 1111; - public const int VLESS_H2_Port = 1112; - public const int VLESS_mKCP_Port = 1113; + public static int VLESS_TCP_Port = 1110; + public static int VLESS_WS_Port = 1111; + public static int VLESS_H2_Port = 1112; + public static int VLESS_mKCP_Port = 1113; - public const int VMESS_TCP_Port = 2110; - public const int VMESS_WS_Port = 2111; - public const int VMESS_H2_Port = 2112; - public const int VMESS_mKCP_Port = 2113; + public static int VMESS_TCP_Port = 1210; + public static int VMESS_WS_Port = 1211; + public static int VMESS_H2_Port = 1212; - public const int Trojan_TCP_Port = 3110; - public const int Trojan_WS_Port = 3111; + public static int Trojan_TCP_Port = 1310; + public static int Trojan_WS_Port = 1311; - public const int ShadowSocksPort = 4110; public static dynamic LoadXrayConfig() @@ -73,6 +71,16 @@ 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()); + } + if (!useCustomWeb && !string.IsNullOrEmpty(parameters.MaskDomain)) { var prefix = "http://"; @@ -167,7 +175,7 @@ namespace ProxySU_Core.Models.Developers if (parameters.Types.Contains(XrayType.VMESS_KCP)) { var kcpBound = GetBound("VMESS_KCP.json"); - kcpBound.port = VMESS_mKCP_Port; + kcpBound.port = parameters.KcpPort; kcpBound.settings.clients[0].id = parameters.UUID; kcpBound.streamSettings.kcpSettings.header.type = parameters.VMESS_KCP_Type; kcpBound.streamSettings.kcpSettings.seed = parameters.VMESS_KCP_Seed; @@ -178,7 +186,7 @@ namespace ProxySU_Core.Models.Developers if (parameters.Types.Contains(XrayType.ShadowsocksAEAD)) { var ssBound = GetBound("Shadowsocks-AEAD.json"); - ssBound.port = ShadowSocksPort; + ssBound.port = parameters.ShadowSocksPort; ssBound.settings.clients[0].password = parameters.ShadowsocksPassword; ssBound.settings.clients[0].method = parameters.ShadowsocksMethod; xrayConfig.inbounds.Add(JToken.FromObject(ssBound)); diff --git a/ProxySU_Core/Models/Developers/IParameters.cs b/ProxySU_Core/Models/Developers/IParameters.cs index e532214..56ec5e0 100644 --- a/ProxySU_Core/Models/Developers/IParameters.cs +++ b/ProxySU_Core/Models/Developers/IParameters.cs @@ -8,6 +8,10 @@ namespace ProxySU_Core.Models.Developers { int Port { get; set; } + int KcpPort { get; set; } + + int ShadowSocksPort { get; set; } + string Domain { get; set; } List Types { get; set; } diff --git a/ProxySU_Core/Models/Developers/Project.cs b/ProxySU_Core/Models/Developers/Project.cs index 7f23b83..93e69aa 100644 --- a/ProxySU_Core/Models/Developers/Project.cs +++ b/ProxySU_Core/Models/Developers/Project.cs @@ -308,12 +308,12 @@ namespace ProxySU_Core.Models.Developers if (Parameters.Types.Contains(XrayType.ShadowsocksAEAD)) { - portList.Add(ConfigBuilder.ShadowSocksPort); + portList.Add(Parameters.ShadowSocksPort); } if (Parameters.Types.Contains(XrayType.VMESS_KCP)) { - portList.Add(ConfigBuilder.VMESS_mKCP_Port); + portList.Add(Parameters.KcpPort); } OpenPort(portList.ToArray()); @@ -468,7 +468,7 @@ namespace ProxySU_Core.Models.Developers return true; } - public void ConfigurePort(bool force = true) + public void ConfigurePort() { if (Parameters.Port == 80 || Parameters.Port == 443) { @@ -480,6 +480,8 @@ namespace ProxySU_Core.Models.Developers SetPortFree(80); SetPortFree(443); SetPortFree(Parameters.Port); + SetPortFree(Parameters.KcpPort); + SetPortFree(Parameters.ShadowSocksPort); } } diff --git a/ProxySU_Core/Models/Developers/XrayProject.cs b/ProxySU_Core/Models/Developers/XrayProject.cs index 98a550e..3690790 100644 --- a/ProxySU_Core/Models/Developers/XrayProject.cs +++ b/ProxySU_Core/Models/Developers/XrayProject.cs @@ -87,7 +87,6 @@ namespace ProxySU_Core.Models.Developers WriteOutput("启动BBR"); EnableBBR(); - WriteOutput("BBR启动成功"); UploadCaddyFile(); WriteOutput("************"); @@ -112,7 +111,7 @@ namespace ProxySU_Core.Models.Developers WriteOutput("卸载证书"); UninstallAcme(); WriteOutput("关闭端口"); - ClosePort(ConfigBuilder.ShadowSocksPort, ConfigBuilder.VLESS_mKCP_Port, ConfigBuilder.VMESS_mKCP_Port); + ClosePort(Parameters.ShadowSocksPort, Parameters.KcpPort); WriteOutput("************ 卸载完成 ************"); } @@ -141,6 +140,8 @@ namespace ProxySU_Core.Models.Developers var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson)); RunCmd("rm -rf /usr/local/etc/xray/config.json"); UploadFile(stream, "/usr/local/etc/xray/config.json"); + ConfigurePort(); + UploadCaddyFile(string.IsNullOrEmpty(Parameters.MaskDomain)); RunCmd("systemctl restart xray"); WriteOutput("************ 更新Xray配置成功,更新配置不包含域名,如果域名更换请重新安装。 ************"); } @@ -268,6 +269,7 @@ namespace ProxySU_Core.Models.Developers { RemoveNat64(); } + WriteOutput("BBR启动成功"); } if (!canInstallBBR) @@ -382,14 +384,14 @@ namespace ProxySU_Core.Models.Developers result = RunCmd(cmd); } - if (result.Contains("Cert success")) + if (result.Contains("success")) { WriteOutput("申请证书成功"); } else { - WriteOutput("申请证书失败,请联系开发者!"); - throw new Exception("申请证书失败,请联系开发者!"); + WriteOutput("申请证书失败,如果申请次数过多请更换二级域名,或联系开发者!"); + throw new Exception("申请证书失败,如果申请次数过多请更换二级域名,或联系开发者!"); } // 安装证书到xray diff --git a/ProxySU_Core/Models/ShareLink.cs b/ProxySU_Core/Models/ShareLink.cs index 13a33be..94d4608 100644 --- a/ProxySU_Core/Models/ShareLink.cs +++ b/ProxySU_Core/Models/ShareLink.cs @@ -38,7 +38,7 @@ namespace ProxySU_Core.Models var _method = settings.ShadowsocksMethod; var _password = settings.ShadowsocksPassword; var _server = settings.Domain; - var _port = ConfigBuilder.ShadowSocksPort; + var _port = settings.ShadowSocksPort; var base64URL = Base64.Encode($"{_method}:{_password}@{_server}:{_port}"); return "ss://" + base64URL; @@ -77,7 +77,7 @@ namespace ProxySU_Core.Models break; case XrayType.VMESS_KCP: vmess.ps = "vmess-mKCP"; - vmess.port = ConfigBuilder.VMESS_mKCP_Port.ToString(); + vmess.port = settings.KcpPort.ToString(); vmess.net = "kcp"; vmess.type = settings.VMESS_KCP_Type; vmess.path = settings.VMESS_KCP_Seed; diff --git a/ProxySU_Core/Models/XraySettings.cs b/ProxySU_Core/Models/XraySettings.cs index fcea1fb..2d10b1c 100644 --- a/ProxySU_Core/Models/XraySettings.cs +++ b/ProxySU_Core/Models/XraySettings.cs @@ -17,6 +17,9 @@ namespace ProxySU_Core.Models { var guid = Guid.NewGuid().ToString(); Port = 443; + KcpPort = 10443; + ShadowSocksPort = 11443; + UUID = guid; Types = new List(); @@ -41,6 +44,14 @@ namespace ProxySU_Core.Models /// public int Port { get; set; } + /// + /// kcp端口 + /// + public int KcpPort { get; set; } + + // ss端口 + public int ShadowSocksPort { get; set; } + /// /// UUID /// diff --git a/ProxySU_Core/Properties/AssemblyInfo.cs b/ProxySU_Core/Properties/AssemblyInfo.cs index 52079d5..ab14e0d 100644 --- a/ProxySU_Core/Properties/AssemblyInfo.cs +++ b/ProxySU_Core/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.1.0.0")] -[assembly: AssemblyFileVersion("3.1.0.0")] +[assembly: AssemblyVersion("3.1.1.0")] +[assembly: AssemblyFileVersion("3.1.1.0")] diff --git a/ProxySU_Core/ProxySU_Core.csproj b/ProxySU_Core/ProxySU_Core.csproj index b9a1d8e..5d6064e 100644 --- a/ProxySU_Core/ProxySU_Core.csproj +++ b/ProxySU_Core/ProxySU_Core.csproj @@ -129,6 +129,7 @@ + diff --git a/ProxySU_Core/Templates/xray/caddy/base.caddyfile b/ProxySU_Core/Templates/xray/caddy/base.caddyfile index 537fbdc..e5105a3 100644 --- a/ProxySU_Core/Templates/xray/caddy/base.caddyfile +++ b/ProxySU_Core/Templates/xray/caddy/base.caddyfile @@ -1,4 +1,4 @@ -##domain##:80 { +##domain##:##port## { root * /usr/share/caddy file_server ##reverse_proxy## diff --git a/ProxySU_Core/ViewModels/BaseModel.cs b/ProxySU_Core/ViewModels/BaseModel.cs new file mode 100644 index 0000000..5255ebb --- /dev/null +++ b/ProxySU_Core/ViewModels/BaseModel.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySU_Core.ViewModels +{ + public class BaseViewModel2 : INotifyPropertyChanged + { + + protected bool SetProperty(ref T backingStore, T value, + string propertyName = "", + Action onChanged = null) + { + if (EqualityComparer.Default.Equals(backingStore, value)) + return false; + + backingStore = value; + onChanged?.Invoke(); + OnPropertyChanged(propertyName); + return true; + } + + #region INotifyPropertyChanged + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string propertyName = "") + { + var changed = PropertyChanged; + if (changed == null) + return; + + changed.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + #endregion + } +} diff --git a/ProxySU_Core/ViewModels/XraySettingsViewModel.cs b/ProxySU_Core/ViewModels/XraySettingsViewModel.cs index eacf8ec..6b71a4c 100644 --- a/ProxySU_Core/ViewModels/XraySettingsViewModel.cs +++ b/ProxySU_Core/ViewModels/XraySettingsViewModel.cs @@ -23,6 +23,37 @@ namespace ProxySU_Core.ViewModels Notify("VMESS_KCP_Type"); } + public int Port + { + get => settings.Port; + set + { + settings.Port = value; + Notify("Port"); + } + } + + public int KcpPort + { + get => settings.KcpPort; + set + { + settings.KcpPort = value; + Notify("KcpPort"); + } + } + + public int ShadowSocksPort + { + get => settings.ShadowSocksPort; + set + { + settings.KcpPort = value; + Notify("ShadowSocksPort"); + } + } + + public string UUID { get => settings.UUID; @@ -168,7 +199,7 @@ namespace ProxySU_Core.ViewModels { get => ShareLink.Build(XrayType.VMESS_WS, settings); } - + // vmess kcp public string VMESS_KCP_Seed { diff --git a/ProxySU_Core/Views/ClientInfoWindow.xaml b/ProxySU_Core/Views/ClientInfoWindow.xaml index 18ba595..c1cbeb0 100644 --- a/ProxySU_Core/Views/ClientInfoWindow.xaml +++ b/ProxySU_Core/Views/ClientInfoWindow.xaml @@ -322,7 +322,7 @@ @@ -404,7 +404,7 @@ diff --git a/ProxySU_Core/Views/MainWindow.xaml b/ProxySU_Core/Views/MainWindow.xaml index cfbdef0..b3fdecc 100644 --- a/ProxySU_Core/Views/MainWindow.xaml +++ b/ProxySU_Core/Views/MainWindow.xaml @@ -125,9 +125,27 @@ + Header="说明文档"> - + + + + + + + + + + + + + + + + + + + diff --git a/ProxySU_Core/Views/RecordEditorWindow.xaml b/ProxySU_Core/Views/RecordEditorWindow.xaml index ce79ebb..d8490cd 100644 --- a/ProxySU_Core/Views/RecordEditorWindow.xaml +++ b/ProxySU_Core/Views/RecordEditorWindow.xaml @@ -222,6 +222,8 @@ +