From 0072c9c99c698fb3b431a204934c6afdb59b85bf Mon Sep 17 00:00:00 2001 From: next-autumn Date: Fri, 12 Mar 2021 15:59:20 +0800 Subject: [PATCH] bbr and domain validation --- ProxySU_Core/Models/XraySettings.cs | 5 +- .../ViewModels/Developers/ConfigBuilder.cs | 11 +++- ProxySU_Core/ViewModels/Developers/Project.cs | 24 +++++--- .../ViewModels/Developers/XrayProject.cs | 61 ++++++++++++++++++- ProxySU_Core/Views/ClientInfoWindow.xaml | 7 +-- 5 files changed, 87 insertions(+), 21 deletions(-) diff --git a/ProxySU_Core/Models/XraySettings.cs b/ProxySU_Core/Models/XraySettings.cs index 9e08eb2..1c125e2 100644 --- a/ProxySU_Core/Models/XraySettings.cs +++ b/ProxySU_Core/Models/XraySettings.cs @@ -12,14 +12,15 @@ namespace ProxySU_Core.Models public XraySettings() { + var guid = Guid.NewGuid().ToString(); Port = 443; - UUID = Guid.NewGuid().ToString(); + UUID = guid; Types = new List { XrayType.VLESS_TCP_XTLS }; VLESS_WS_Path = "/vlessws"; VLESS_TCP_Path = "/vlesstcp"; VMESS_WS_Path = "/vmessws"; VMESS_TCP_Path = "/vmesstcp"; - TrojanPassword = Guid.NewGuid().ToString(); + TrojanPassword = guid; } /// diff --git a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs b/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs index 9efa562..5748161 100644 --- a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs +++ b/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs @@ -66,7 +66,16 @@ namespace ProxySU_Core.ViewModels.Developers caddyStr = caddyStr.Replace("##domain##", parameters.Domain); if (!useCustomWeb && !string.IsNullOrEmpty(parameters.MaskDomain)) { - caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy {parameters.MaskDomain} {{ header_up Host {parameters.MaskDomain} }}"); + var prefix = "http://"; + if (parameters.MaskDomain.StartsWith("https://")) + { + prefix = "https://"; + } + var domain = parameters.MaskDomain + .TrimStart("http://".ToCharArray()) + .TrimStart("https://".ToCharArray()); + + caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy {prefix}{domain} {{ \n header_up Host {domain} \n }}"); } else { diff --git a/ProxySU_Core/ViewModels/Developers/Project.cs b/ProxySU_Core/ViewModels/Developers/Project.cs index a989bec..61aba94 100644 --- a/ProxySU_Core/ViewModels/Developers/Project.cs +++ b/ProxySU_Core/ViewModels/Developers/Project.cs @@ -312,9 +312,7 @@ namespace ProxySU_Core.ViewModels.Developers var cmd = $"dig @resolver1.opendns.com AAAA {Parameters.Domain} +short -6 {cmdFilter}"; var result = RunCmd(cmd).TrimEnd('\r', '\n'); - if (result != IPv6) - { - } + if (result == IPv6) return; } else @@ -323,11 +321,19 @@ namespace ProxySU_Core.ViewModels.Developers var cmd = $"dig @resolver1.opendns.com A {Parameters.Domain} +short -4 {cmdFilter}"; var result = RunCmd(cmd).TrimEnd('\r', '\n'); - if (result != IPv4) - { - throw new Exception("域名未能解析到服务器IP,请检查域名配置"); - } + if (result == IPv4) return; + } + + + var btnResult = MessageBox.Show( + $"{Parameters.Domain}未能正常解析到服务器的IP,如果您使用了CDN请忽略,是否继续安装?", "提示", MessageBoxButton.YesNo); + + if (btnResult == MessageBoxResult.No) + { + throw new Exception($"域名解析失败,安装停止!"); + } + } /// @@ -447,7 +453,7 @@ namespace ProxySU_Core.ViewModels.Developers } } - private void SetNat64() + protected void SetNat64() { var dns64List = FilterFastestIP(); if (dns64List.Count == 0) @@ -468,7 +474,7 @@ namespace ProxySU_Core.ViewModels.Developers } } - private void RemoveNat64() + protected void RemoveNat64() { RunCmd("rm /etc/resolv.conf"); RunCmd("mv /etc/resolv.conf.proxysu /etc/resolv.conf"); diff --git a/ProxySU_Core/ViewModels/Developers/XrayProject.cs b/ProxySU_Core/ViewModels/Developers/XrayProject.cs index c3bec41..588e506 100644 --- a/ProxySU_Core/ViewModels/Developers/XrayProject.cs +++ b/ProxySU_Core/ViewModels/Developers/XrayProject.cs @@ -51,7 +51,6 @@ namespace ProxySU_Core.ViewModels.Developers RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); RunCmd("chmod -R 777 /usr/share/caddy"); UploadCaddyFile(useCustomWeb: true); - RunCmd("systemctl restart caddy"); WriteOutput("************ 上传网站模板完成 ************"); } @@ -76,7 +75,6 @@ namespace ProxySU_Core.ViewModels.Developers WriteOutput("************ 重装Caddy完成 ************"); } - public override void Install() { try @@ -129,6 +127,10 @@ namespace ProxySU_Core.ViewModels.Developers InstallCaddy(); WriteOutput("Caddy安装完成"); + WriteOutput("启动BBR"); + EnableBBR(); + WriteOutput("BBR启动成功"); + UploadCaddyFile(); WriteOutput("************"); WriteOutput("安装完成,尽情享用吧......"); @@ -146,7 +148,60 @@ namespace ProxySU_Core.ViewModels.Developers var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson)); RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); UploadFile(stream, "/etc/caddy/Caddyfile"); - RunCmd("systemctl reload caddy"); + RunCmd("systemctl restart caddy"); + } + + private void EnableBBR() + { + var osVersion = RunCmd("uname -r"); + var canInstallBBR = CheckKernelVersionBBR(osVersion.Split('-')[0]); + + var bbrInfo = RunCmd("sysctl net.ipv4.tcp_congestion_control | grep bbr"); + var installed = bbrInfo.Contains("bbr"); + if (canInstallBBR && !installed) + { + RunCmd(@"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"); + RunCmd(@"sysctl -p"); + + if (OnlyIpv6) + { + RemoveNat64(); + } + } + + if (!canInstallBBR) + { + WriteOutput("****** 系统不满足启用BBR条件,启动失败。 ******"); + } + + } + + private bool CheckKernelVersionBBR(string kernelVer) + { + string[] linuxKernelCompared = kernelVer.Split('.'); + if (int.Parse(linuxKernelCompared[0]) > 4) + { + return true; + } + else if (int.Parse(linuxKernelCompared[0]) < 4) + { + return false; + } + else if (int.Parse(linuxKernelCompared[0]) == 4) + { + if (int.Parse(linuxKernelCompared[1]) >= 9) + { + return true; + } + else if (int.Parse(linuxKernelCompared[1]) < 9) + { + return false; + } + + } + return false; + } private void InstallXrayWithCert() diff --git a/ProxySU_Core/Views/ClientInfoWindow.xaml b/ProxySU_Core/Views/ClientInfoWindow.xaml index 69ecf2d..46e393c 100644 --- a/ProxySU_Core/Views/ClientInfoWindow.xaml +++ b/ProxySU_Core/Views/ClientInfoWindow.xaml @@ -299,13 +299,8 @@ - - -