1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-22 05:06:08 +03:00
This commit is contained in:
autumn 2021-07-07 12:01:41 +08:00
parent d5878079f1
commit 399c852857
7 changed files with 55 additions and 31 deletions

View File

@ -20,10 +20,11 @@ namespace ProxySuper.Core.Models.Projects
{ {
get get
{ {
return new List<int>() if (Port == 443)
{ {
Port return new List<int> { 80, 443 };
}; }
return new List<int> { Port };
} }
} }

View File

@ -10,6 +10,19 @@ namespace ProxySuper.Core.Services
{ {
public class BrookProject : ProjectBase<BrookSettings> public class BrookProject : ProjectBase<BrookSettings>
{ {
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<string> writeOutput) : base(sshClient, parameters, writeOutput) public BrookProject(SshClient sshClient, BrookSettings parameters, Action<string> writeOutput) : base(sshClient, parameters, writeOutput)
{ {
} }
@ -22,21 +35,17 @@ namespace ProxySuper.Core.Services
WriteOutput("检测安装系统环境完成"); WriteOutput("检测安装系统环境完成");
WriteOutput("配置服务器端口..."); WriteOutput("配置服务器端口...");
ConfigurePort(); OpenPort(Parameters.FreePorts.ToArray());
Parameters.FreePorts.ForEach(port =>
{
SetPortFree(port);
});
WriteOutput("端口配置完成"); WriteOutput("端口配置完成");
WriteOutput("安装必要的系统工具..."); WriteOutput("安装必要的系统工具...");
ConfigureSoftware(); ConfigureSoftware();
WriteOutput("系统工具安装完成"); WriteOutput("系统工具安装完成");
WriteOutput("检测IP6...");
ConfigureIPv6();
WriteOutput("检测IP6完成");
WriteOutput("配置防火墙...");
ConfigureFirewall();
WriteOutput("防火墙配置完成");
if (Parameters.BrookType == BrookType.wssserver) if (Parameters.BrookType == BrookType.wssserver)
{ {
WriteOutput("检测域名是否绑定本机IP..."); WriteOutput("检测域名是否绑定本机IP...");
@ -64,28 +73,46 @@ namespace ProxySuper.Core.Services
RunCmd("chmod +x /usr/bin/brook"); RunCmd("chmod +x /usr/bin/brook");
Console.WriteLine("安装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; var runBrookCmd = string.Empty;
if (Parameters.BrookType == BrookType.server) 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) 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) 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() public void Uninstall()

View File

@ -62,10 +62,6 @@ namespace ProxySuper.Core.Services
ConfigureSoftware(); ConfigureSoftware();
WriteOutput("系统工具安装完成"); WriteOutput("系统工具安装完成");
WriteOutput("检测IP6...");
ConfigureIPv6();
WriteOutput("检测IP6完成");
WriteOutput("配置防火墙..."); WriteOutput("配置防火墙...");
ConfigureFirewall(); ConfigureFirewall();
WriteOutput("防火墙配置完成"); WriteOutput("防火墙配置完成");

View File

@ -146,6 +146,8 @@ namespace ProxySuper.Core.Services
RunCmd(@"sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config"); RunCmd(@"sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config");
} }
} }
EnsureIP();
} }
/// <summary> /// <summary>
@ -169,7 +171,7 @@ namespace ProxySuper.Core.Services
/// <summary> /// <summary>
/// 配置IPV6环境 /// 配置IPV6环境
/// </summary> /// </summary>
protected void ConfigureIPv6() protected void EnsureIP()
{ {
if (IsOnlyIpv6()) if (IsOnlyIpv6())
{ {
@ -506,7 +508,7 @@ namespace ProxySuper.Core.Services
return OnlyIpv6; 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"); string result = RunCmd($"lsof -n -P -i :{port} | grep LISTEN");

View File

@ -91,10 +91,6 @@ namespace ProxySuper.Core.Services
ConfigureSoftware(); ConfigureSoftware();
WriteOutput("系统工具安装完成"); WriteOutput("系统工具安装完成");
WriteOutput("检测IP6...");
ConfigureIPv6();
WriteOutput("检测IP6完成");
WriteOutput("配置防火墙..."); WriteOutput("配置防火墙...");
ConfigureFirewall(); ConfigureFirewall();
WriteOutput("防火墙配置完成"); WriteOutput("防火墙配置完成");

View File

@ -62,10 +62,6 @@ namespace ProxySuper.Core.Services
ConfigureSoftware(); ConfigureSoftware();
WriteOutput("系统工具安装完成"); WriteOutput("系统工具安装完成");
WriteOutput("检测IP6...");
ConfigureIPv6();
WriteOutput("检测IP6完成");
WriteOutput("配置防火墙..."); WriteOutput("配置防火墙...");
ConfigureFirewall(); ConfigureFirewall();
WriteOutput("防火墙配置完成"); WriteOutput("防火墙配置完成");

View File

@ -50,6 +50,12 @@ namespace ProxySuper.Core.ViewModels
set set
{ {
Settings.BrookType = (BrookType)Enum.Parse(typeof(BrookType), value); Settings.BrookType = (BrookType)Enum.Parse(typeof(BrookType), value);
if (Settings.BrookType == BrookType.wssserver)
{
Settings.Port = 443;
RaisePropertyChanged("Settings");
}
RaisePropertyChanged("EnablePort"); RaisePropertyChanged("EnablePort");
RaisePropertyChanged("EnableDomain"); RaisePropertyChanged("EnableDomain");
} }