diff --git a/ProxySuper.Core/Models/Projects/BrookSettings.cs b/ProxySuper.Core/Models/Projects/BrookSettings.cs new file mode 100644 index 0000000..0408667 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/BrookSettings.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Models.Projects +{ + public class BrookSettings : IProjectSettings + { + public string Domain { get; set; } + + public string Password { get; set; } + + public BrookType BrookType { get; set; } + + public int Port { get; set; } = 443; + + public List FreePorts + { + get + { + return new List() + { + Port + }; + } + } + + public string Email => "server@brook.com"; + + public ProjectType Type { get; set; } = ProjectType.Brook; + + } +} diff --git a/ProxySuper.Core/Models/Projects/BrookType.cs b/ProxySuper.Core/Models/Projects/BrookType.cs new file mode 100644 index 0000000..944a5e9 --- /dev/null +++ b/ProxySuper.Core/Models/Projects/BrookType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Models.Projects +{ + public enum BrookType + { + server, + wsserver, + wssserver + } +} diff --git a/ProxySuper.Core/Models/Projects/ProjectType.cs b/ProxySuper.Core/Models/Projects/ProjectType.cs index 16b82b2..fe5d8d6 100644 --- a/ProxySuper.Core/Models/Projects/ProjectType.cs +++ b/ProxySuper.Core/Models/Projects/ProjectType.cs @@ -10,6 +10,7 @@ namespace ProxySuper.Core.Models.Projects { Xray = 0, TrojanGo = 1, - NaiveProxy = 2 + NaiveProxy = 2, + Brook = 3, } } diff --git a/ProxySuper.Core/Models/Record.cs b/ProxySuper.Core/Models/Record.cs index f4a6a67..be09559 100644 --- a/ProxySuper.Core/Models/Record.cs +++ b/ProxySuper.Core/Models/Record.cs @@ -53,6 +53,9 @@ namespace ProxySuper.Core.Models [JsonProperty("naiveProxySettings")] public NaiveProxySettings NaiveProxySettings { get; set; } + [JsonProperty("brook")] + public BrookSettings BrookSettings { get; set; } + [JsonIgnore] public ProjectType Type @@ -63,7 +66,9 @@ namespace ProxySuper.Core.Models if (TrojanGoSettings != null) return ProjectType.TrojanGo; - return ProjectType.NaiveProxy; + if (NaiveProxySettings != null) return ProjectType.NaiveProxy; + + return ProjectType.Brook; } } diff --git a/ProxySuper.Core/ProxySuper.Core.csproj b/ProxySuper.Core/ProxySuper.Core.csproj index db1bc85..9067c8a 100644 --- a/ProxySuper.Core/ProxySuper.Core.csproj +++ b/ProxySuper.Core/ProxySuper.Core.csproj @@ -70,6 +70,8 @@ + + @@ -84,6 +86,7 @@ + @@ -91,6 +94,7 @@ + diff --git a/ProxySuper.Core/Services/BrookProject.cs b/ProxySuper.Core/Services/BrookProject.cs new file mode 100644 index 0000000..3ab4c66 --- /dev/null +++ b/ProxySuper.Core/Services/BrookProject.cs @@ -0,0 +1,112 @@ +using ProxySuper.Core.Models.Projects; +using Renci.SshNet; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Services +{ + public class BrookProject : ProjectBase + { + public BrookProject(SshClient sshClient, BrookSettings parameters, Action writeOutput) : base(sshClient, parameters, writeOutput) + { + } + + public override void Install() + { + + WriteOutput("检测安装系统环境..."); + EnsureSystemEnv(); + WriteOutput("检测安装系统环境完成"); + + WriteOutput("配置服务器端口..."); + ConfigurePort(); + WriteOutput("端口配置完成"); + + WriteOutput("安装必要的系统工具..."); + ConfigureSoftware(); + WriteOutput("系统工具安装完成"); + + WriteOutput("检测IP6..."); + ConfigureIPv6(); + WriteOutput("检测IP6完成"); + + WriteOutput("配置防火墙..."); + ConfigureFirewall(); + WriteOutput("防火墙配置完成"); + + if (Parameters.BrookType == BrookType.wssserver) + { + WriteOutput("检测域名是否绑定本机IP..."); + ValidateDomain(); + WriteOutput("域名检测完成"); + } + + + + } + + public void InstallBrook() + { + Console.WriteLine("安装nami"); + RunCmd("source <(curl -L https://git.io/getnami)"); + Console.WriteLine("安装nami完成"); + + Console.WriteLine("安装Brook"); + RunCmd("echo y | nami install github.com/txthinking/brook"); + Console.WriteLine("安装Brook完成"); + + Console.WriteLine("安装joker"); + RunCmd("echo y | nami install github.com/txthinking/joker"); + Console.WriteLine("安装joker完成"); + + Console.WriteLine("安装jinbe"); + RunCmd("echo y | nami install github.com/txthinking/jinbe"); + Console.WriteLine("安装jinbe完成"); + + + var runBrookCmd = string.Empty; + + if (Parameters.BrookType == BrookType.server) + { + runBrookCmd = $"joker brook server --listen :{Parameters.Port} --password {Parameters.Password}"; + } + + if (Parameters.BrookType == BrookType.wsserver) + { + runBrookCmd = $"joker brook wsserver --listen :{Parameters.Port} --password {Parameters.Password}"; + } + + if (Parameters.BrookType == BrookType.wsserver) + { + runBrookCmd = $"joker brook wssserver --domain {Parameters.Domain} --password {Parameters.Password}"; + } + + RunCmd("jinbe " + runBrookCmd); + + Console.WriteLine("*************安装完成,尽情享用吧**********"); + } + + public void Uninstall() + { + RunCmd("jinbe remove 0"); + RunCmd("killall joker"); + + Console.WriteLine("卸载jinbe"); + RunCmd("echo y | nami remove github.com/txthinking/jinbe"); + + Console.WriteLine("卸载joker"); + RunCmd("echo y | nami remove github.com/txthinking/joker"); + + Console.WriteLine("卸载brook"); + RunCmd("echo y | nami remove github.com/txthinking/brook"); + + Console.WriteLine("关闭端口"); + ClosePort(Parameters.FreePorts.ToArray()); + + Console.WriteLine("******卸载完成******"); + } + } +} diff --git a/ProxySuper.Core/Services/ProjectBase.cs b/ProxySuper.Core/Services/ProjectBase.cs index 9563c58..85a95fe 100644 --- a/ProxySuper.Core/Services/ProjectBase.cs +++ b/ProxySuper.Core/Services/ProjectBase.cs @@ -20,6 +20,12 @@ namespace ProxySuper.Core.Services Yum } + public enum ArchType + { + x86, + arm, + } + public abstract class ProjectBase where TSettings : IProjectSettings { private SshClient _sshClient; @@ -28,6 +34,8 @@ namespace ProxySuper.Core.Services protected CmdType CmdType { get; set; } + protected ArchType ArchType { get; set; } + protected bool IsSELinux { get; set; } protected bool OnlyIpv6 { get; set; } @@ -67,6 +75,21 @@ namespace ProxySuper.Core.Services { string cmd; + // cpu架构 + var result = RunCmd("uname -m"); + if (result.Contains("x86")) + { + ArchType = ArchType.x86; + } + else if (result.Contains("arm") || result.Contains("arch")) + { + ArchType = ArchType.arm; + } + else + { + throw new Exception($"未识别的架构处理器架构:{result}"); + } + // 确认安装命令 if (CmdType == CmdType.None) { diff --git a/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs b/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs new file mode 100644 index 0000000..8c9ad58 --- /dev/null +++ b/ProxySuper.Core/ViewModels/BrookEditorViewModel.cs @@ -0,0 +1,76 @@ +using MvvmCross.Commands; +using MvvmCross.Navigation; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class BrookEditorViewModel : MvxViewModel + { + public string Id { get; set; } + + public Host Host { get; set; } + + public BrookSettings Settings { get; set; } + + public List BrookTypes + { + get + { + return new List { + BrookType.server.ToString(), + BrookType.wsserver.ToString(), + BrookType.wssserver.ToString(), + }; + } + } + + public string CheckedBrookType + { + get + { + return Settings.BrookType.ToString(); + } + set + { + Settings.BrookType = (BrookType)Enum.Parse(typeof(BrookType), value); + RaisePropertyChanged("EnablePort"); + RaisePropertyChanged("EnableDomain"); + } + } + + public bool EnablePort => Settings.BrookType != BrookType.wssserver; + + public bool EnableDomain => Settings.BrookType == BrookType.wssserver; + + public IMvxCommand SaveCommand => new MvxCommand(() => Save()); + + public IMvxNavigationService NavigationService { get; } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + Id = record.Id; + Host = record.Host; + Settings = record.BrookSettings; + } + + public void Save() + { + NavigationService.Close(this, new Record() + { + Id = Id, + Host = Host, + BrookSettings = Settings, + }); + } + } +} diff --git a/ProxySuper.Core/ViewModels/HomeViewModel.cs b/ProxySuper.Core/ViewModels/HomeViewModel.cs index 80c6bff..2d09e96 100644 --- a/ProxySuper.Core/ViewModels/HomeViewModel.cs +++ b/ProxySuper.Core/ViewModels/HomeViewModel.cs @@ -66,6 +66,8 @@ namespace ProxySuper.Core.ViewModels public IMvxCommand AddNaiveProxyCommand => new MvxAsyncCommand(AddNaiveProxyRecord); + public IMvxCommand AddBrookCommand => new MvxAsyncCommand(AddBrookRecord); + public IMvxCommand RemoveCommand => new MvxAsyncCommand(DeleteRecord); public IMvxCommand EditCommand => new MvxAsyncCommand(EditRecord); @@ -118,6 +120,21 @@ namespace ProxySuper.Core.ViewModels SaveToJson(); } + public async Task AddBrookRecord() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.BrookSettings = new BrookSettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + + SaveToJson(); + } + public async Task EditRecord(string id) { diff --git a/ProxySuper.WPF/ProxySuper.WPF.csproj b/ProxySuper.WPF/ProxySuper.WPF.csproj index 274b1e9..7dd0f19 100644 --- a/ProxySuper.WPF/ProxySuper.WPF.csproj +++ b/ProxySuper.WPF/ProxySuper.WPF.csproj @@ -111,6 +111,9 @@ MainWindow.xaml + + BrookEditorView.xaml + HomeView.xaml @@ -201,6 +204,10 @@ MSBuild:Compile PreserveNewest + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ProxySuper.WPF/Views/BrookEditorView.xaml b/ProxySuper.WPF/Views/BrookEditorView.xaml new file mode 100644 index 0000000..d33cd95 --- /dev/null +++ b/ProxySuper.WPF/Views/BrookEditorView.xaml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +