From 399c8528578de58e89e63909a22c261a28975eb9 Mon Sep 17 00:00:00 2001 From: autumn Date: Wed, 7 Jul 2021 12:01:41 +0800 Subject: [PATCH] merge --- .../Models/Projects/BrookSettings.cs | 7 ++- ProxySuper.Core/Services/BrookProject.cs | 55 ++++++++++++++----- ProxySuper.Core/Services/NaiveProxyProject.cs | 4 -- ProxySuper.Core/Services/ProjectBase.cs | 6 +- ProxySuper.Core/Services/TrojanGoProject.cs | 4 -- ProxySuper.Core/Services/XrayProject.cs | 4 -- .../ViewModels/BrookEditorViewModel.cs | 6 ++ 7 files changed, 55 insertions(+), 31 deletions(-) diff --git a/ProxySuper.Core/Models/Projects/BrookSettings.cs b/ProxySuper.Core/Models/Projects/BrookSettings.cs index 0408667..71eda20 100644 --- a/ProxySuper.Core/Models/Projects/BrookSettings.cs +++ b/ProxySuper.Core/Models/Projects/BrookSettings.cs @@ -20,10 +20,11 @@ namespace ProxySuper.Core.Models.Projects { get { - return new List() + if (Port == 443) { - Port - }; + return new List { 80, 443 }; + } + return new List { Port }; } } diff --git a/ProxySuper.Core/Services/BrookProject.cs b/ProxySuper.Core/Services/BrookProject.cs index 9fb4bfa..36cae78 100644 --- a/ProxySuper.Core/Services/BrookProject.cs +++ b/ProxySuper.Core/Services/BrookProject.cs @@ -10,6 +10,19 @@ namespace ProxySuper.Core.Services { public class BrookProject : ProjectBase { + private string brookServiceTemp = @" + [Unit] + Description=brook service + After=network.target syslog.target + Wants=network.target + + [Service] + Type=simple + ExecStart=##run_cmd## + + [Install] + WantedBy=multi-user.target"; + public BrookProject(SshClient sshClient, BrookSettings parameters, Action writeOutput) : base(sshClient, parameters, writeOutput) { } @@ -22,21 +35,17 @@ namespace ProxySuper.Core.Services WriteOutput("检测安装系统环境完成"); WriteOutput("配置服务器端口..."); - ConfigurePort(); + OpenPort(Parameters.FreePorts.ToArray()); + Parameters.FreePorts.ForEach(port => + { + SetPortFree(port); + }); WriteOutput("端口配置完成"); WriteOutput("安装必要的系统工具..."); ConfigureSoftware(); WriteOutput("系统工具安装完成"); - WriteOutput("检测IP6..."); - ConfigureIPv6(); - WriteOutput("检测IP6完成"); - - WriteOutput("配置防火墙..."); - ConfigureFirewall(); - WriteOutput("防火墙配置完成"); - if (Parameters.BrookType == BrookType.wssserver) { WriteOutput("检测域名是否绑定本机IP..."); @@ -64,28 +73,46 @@ namespace ProxySuper.Core.Services RunCmd("chmod +x /usr/bin/brook"); Console.WriteLine("安装Brook完成"); + var brookService = brookServiceTemp.Replace("##run_cmd##", GetRunBrookCommand()); + RunCmd("rm -rf /etc/systemd/system/brook.service"); + RunCmd("touch /etc/systemd/system/brook.service"); + RunCmd($"echo \"{brookService}\" > /etc/systemd/system/brook.service"); + RunCmd("sudo chmod 777 /etc/systemd/system/brook.service"); + + RunCmd("systemctl enable brook"); + RunCmd("systemctl restart brook"); + + WriteOutput("********************"); + WriteOutput("安装完成,尽情想用吧~ "); + WriteOutput("*********************"); + } + + private string GetRunBrookCommand() + { var runBrookCmd = string.Empty; if (Parameters.BrookType == BrookType.server) { - runBrookCmd = $"nohup /usr/bin/brook server --listen :{Parameters.Port} --password {Parameters.Password} &"; + return $"/usr/bin/brook server --listen :{Parameters.Port} --password {Parameters.Password}"; } if (Parameters.BrookType == BrookType.wsserver) { - runBrookCmd = $"nohup /usr/bin/brook wsserver --listen :{Parameters.Port} --password {Parameters.Password} &"; + return $"/usr/bin/brook wsserver --listen :{Parameters.Port} --password {Parameters.Password}"; } - if (Parameters.BrookType == BrookType.wsserver) + if (Parameters.BrookType == BrookType.wssserver) { - runBrookCmd = $"nohup /usr/bin/brook wssserver --domain {Parameters.Domain} --password {Parameters.Password} &"; + return $"/usr/bin/brook wssserver --domain {Parameters.Domain} --password {Parameters.Password}"; } if (Parameters.BrookType == BrookType.socks5) { - runBrookCmd = $"nohup /usr/bin/brook socks5 --socks5 :{Parameters.Port} &"; + return $"/usr/bin/brook socks5 --socks5 :{Parameters.Port}"; } + + return runBrookCmd; } public void Uninstall() diff --git a/ProxySuper.Core/Services/NaiveProxyProject.cs b/ProxySuper.Core/Services/NaiveProxyProject.cs index 6d9ae64..1939167 100644 --- a/ProxySuper.Core/Services/NaiveProxyProject.cs +++ b/ProxySuper.Core/Services/NaiveProxyProject.cs @@ -62,10 +62,6 @@ namespace ProxySuper.Core.Services ConfigureSoftware(); WriteOutput("系统工具安装完成"); - WriteOutput("检测IP6..."); - ConfigureIPv6(); - WriteOutput("检测IP6完成"); - WriteOutput("配置防火墙..."); ConfigureFirewall(); WriteOutput("防火墙配置完成"); diff --git a/ProxySuper.Core/Services/ProjectBase.cs b/ProxySuper.Core/Services/ProjectBase.cs index 85a95fe..dd5cfb9 100644 --- a/ProxySuper.Core/Services/ProjectBase.cs +++ b/ProxySuper.Core/Services/ProjectBase.cs @@ -146,6 +146,8 @@ namespace ProxySuper.Core.Services RunCmd(@"sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config"); } } + + EnsureIP(); } /// @@ -169,7 +171,7 @@ namespace ProxySuper.Core.Services /// /// 配置IPV6环境 /// - protected void ConfigureIPv6() + protected void EnsureIP() { if (IsOnlyIpv6()) { @@ -506,7 +508,7 @@ namespace ProxySuper.Core.Services return OnlyIpv6; } - private bool SetPortFree(int port, bool force = true) + protected bool SetPortFree(int port, bool force = true) { string result = RunCmd($"lsof -n -P -i :{port} | grep LISTEN"); diff --git a/ProxySuper.Core/Services/TrojanGoProject.cs b/ProxySuper.Core/Services/TrojanGoProject.cs index 98783dd..0dd5d13 100644 --- a/ProxySuper.Core/Services/TrojanGoProject.cs +++ b/ProxySuper.Core/Services/TrojanGoProject.cs @@ -91,10 +91,6 @@ namespace ProxySuper.Core.Services ConfigureSoftware(); WriteOutput("系统工具安装完成"); - WriteOutput("检测IP6..."); - ConfigureIPv6(); - WriteOutput("检测IP6完成"); - WriteOutput("配置防火墙..."); ConfigureFirewall(); WriteOutput("防火墙配置完成"); diff --git a/ProxySuper.Core/Services/XrayProject.cs b/ProxySuper.Core/Services/XrayProject.cs index b4fceb7..bef0952 100644 --- a/ProxySuper.Core/Services/XrayProject.cs +++ b/ProxySuper.Core/Services/XrayProject.cs @@ -62,10 +62,6 @@ namespace ProxySuper.Core.Services ConfigureSoftware(); WriteOutput("系统工具安装完成"); - WriteOutput("检测IP6..."); - ConfigureIPv6(); - WriteOutput("检测IP6完成"); - WriteOutput("配置防火墙..."); ConfigureFirewall(); WriteOutput("防火墙配置完成"); diff --git a/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs b/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs index ca53bb4..de36cf0 100644 --- a/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs +++ b/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs @@ -50,6 +50,12 @@ namespace ProxySuper.Core.ViewModels set { Settings.BrookType = (BrookType)Enum.Parse(typeof(BrookType), value); + + if (Settings.BrookType == BrookType.wssserver) + { + Settings.Port = 443; + RaisePropertyChanged("Settings"); + } RaisePropertyChanged("EnablePort"); RaisePropertyChanged("EnableDomain"); }