2021-07-02 13:35:25 +03:00
|
|
|
|
using ProxySuper.Core.Models.Projects;
|
|
|
|
|
using Renci.SshNet;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace ProxySuper.Core.Services
|
|
|
|
|
{
|
|
|
|
|
public class BrookProject : ProjectBase<BrookSettings>
|
|
|
|
|
{
|
2021-07-07 07:01:41 +03:00
|
|
|
|
private string brookServiceTemp = @"
|
2021-07-12 12:58:51 +03:00
|
|
|
|
[Unit]
|
|
|
|
|
Description=brook service
|
|
|
|
|
After=network.target syslog.target
|
|
|
|
|
Wants=network.target
|
2021-07-07 07:01:41 +03:00
|
|
|
|
|
2021-07-12 12:58:51 +03:00
|
|
|
|
[Service]
|
|
|
|
|
Type=simple
|
|
|
|
|
ExecStart=##run_cmd##
|
2021-07-07 07:01:41 +03:00
|
|
|
|
|
2021-07-12 12:58:51 +03:00
|
|
|
|
[Install]
|
|
|
|
|
WantedBy=multi-user.target";
|
2021-07-07 07:01:41 +03:00
|
|
|
|
|
2021-07-02 13:35:25 +03:00
|
|
|
|
public BrookProject(SshClient sshClient, BrookSettings parameters, Action<string> writeOutput) : base(sshClient, parameters, writeOutput)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Install()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
WriteOutput("检测安装系统环境...");
|
|
|
|
|
EnsureSystemEnv();
|
|
|
|
|
WriteOutput("检测安装系统环境完成");
|
|
|
|
|
|
|
|
|
|
WriteOutput("配置服务器端口...");
|
2021-07-12 12:58:51 +03:00
|
|
|
|
ConfigFirewalld();
|
2021-07-02 13:35:25 +03:00
|
|
|
|
WriteOutput("端口配置完成");
|
|
|
|
|
|
|
|
|
|
WriteOutput("安装必要的系统工具...");
|
|
|
|
|
ConfigureSoftware();
|
|
|
|
|
WriteOutput("系统工具安装完成");
|
|
|
|
|
|
2021-07-13 05:12:15 +03:00
|
|
|
|
WriteOutput("检测网络环境");
|
|
|
|
|
EnsureIP();
|
|
|
|
|
WriteOutput("检测网络环境完成");
|
|
|
|
|
|
2021-07-02 13:35:25 +03:00
|
|
|
|
if (Parameters.BrookType == BrookType.wssserver)
|
|
|
|
|
{
|
|
|
|
|
WriteOutput("检测域名是否绑定本机IP...");
|
|
|
|
|
ValidateDomain();
|
|
|
|
|
WriteOutput("域名检测完成");
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 13:30:14 +03:00
|
|
|
|
InstallBrook();
|
2021-07-02 13:35:25 +03:00
|
|
|
|
|
|
|
|
|
|
2021-07-06 13:30:14 +03:00
|
|
|
|
Console.WriteLine("*************安装完成,尽情享用吧**********");
|
2021-07-02 13:35:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InstallBrook()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("安装Brook");
|
|
|
|
|
|
2021-07-06 13:30:14 +03:00
|
|
|
|
string url = "https://github.com/txthinking/brook/releases/latest/download/brook_linux_amd64";
|
|
|
|
|
if (ArchType == ArchType.arm)
|
|
|
|
|
{
|
|
|
|
|
url = url.Replace("brook_linux_amd64", "brook_linux_arm7");
|
|
|
|
|
}
|
2021-07-02 13:35:25 +03:00
|
|
|
|
|
2021-07-06 13:30:14 +03:00
|
|
|
|
RunCmd($"curl -L {url} -o /usr/bin/brook");
|
|
|
|
|
RunCmd("chmod +x /usr/bin/brook");
|
|
|
|
|
Console.WriteLine("安装Brook完成");
|
2021-07-02 13:35:25 +03:00
|
|
|
|
|
2021-07-07 07:01:41 +03:00
|
|
|
|
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");
|
2021-07-02 13:35:25 +03:00
|
|
|
|
|
2021-07-07 07:01:41 +03:00
|
|
|
|
RunCmd("systemctl enable brook");
|
|
|
|
|
RunCmd("systemctl restart brook");
|
|
|
|
|
|
|
|
|
|
WriteOutput("********************");
|
|
|
|
|
WriteOutput("安装完成,尽情想用吧~ ");
|
|
|
|
|
WriteOutput("*********************");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetRunBrookCommand()
|
|
|
|
|
{
|
2021-07-02 13:35:25 +03:00
|
|
|
|
var runBrookCmd = string.Empty;
|
|
|
|
|
|
|
|
|
|
if (Parameters.BrookType == BrookType.server)
|
|
|
|
|
{
|
2021-07-07 07:01:41 +03:00
|
|
|
|
return $"/usr/bin/brook server --listen :{Parameters.Port} --password {Parameters.Password}";
|
2021-07-02 13:35:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Parameters.BrookType == BrookType.wsserver)
|
|
|
|
|
{
|
2021-07-07 07:01:41 +03:00
|
|
|
|
return $"/usr/bin/brook wsserver --listen :{Parameters.Port} --password {Parameters.Password}";
|
2021-07-02 13:35:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 07:01:41 +03:00
|
|
|
|
if (Parameters.BrookType == BrookType.wssserver)
|
2021-07-02 13:35:25 +03:00
|
|
|
|
{
|
2021-07-07 07:01:41 +03:00
|
|
|
|
return $"/usr/bin/brook wssserver --domain {Parameters.Domain} --password {Parameters.Password}";
|
2021-07-02 13:35:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 13:30:14 +03:00
|
|
|
|
if (Parameters.BrookType == BrookType.socks5)
|
|
|
|
|
{
|
2021-07-07 11:56:53 +03:00
|
|
|
|
var ip = OnlyIpv6 ? IPv6 : IPv4;
|
|
|
|
|
return $"/usr/bin/brook socks5 --socks5 {ip}:{Parameters.Port}";
|
2021-07-06 13:30:14 +03:00
|
|
|
|
}
|
2021-07-07 07:01:41 +03:00
|
|
|
|
|
|
|
|
|
return runBrookCmd;
|
2021-07-02 13:35:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Uninstall()
|
|
|
|
|
{
|
2021-07-07 11:56:53 +03:00
|
|
|
|
RunCmd("systemctl stop brook");
|
|
|
|
|
RunCmd("systemctl disable brook");
|
|
|
|
|
RunCmd("rm -rf /etc/systemd/system/brook.service");
|
|
|
|
|
RunCmd("rm -rf /usr/bin/brook");
|
2021-07-02 13:35:25 +03:00
|
|
|
|
|
|
|
|
|
Console.WriteLine("关闭端口");
|
2021-07-12 12:58:51 +03:00
|
|
|
|
ResetFirewalld();
|
2021-07-02 13:35:25 +03:00
|
|
|
|
|
2021-07-07 11:56:53 +03:00
|
|
|
|
WriteOutput("******卸载完成******");
|
2021-07-02 13:35:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|