1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-22 13:16:09 +03:00

add brook

This commit is contained in:
autumn 2021-07-02 18:35:25 +08:00
parent a2b27076b1
commit 5bd7529bec
13 changed files with 398 additions and 2 deletions

View File

@ -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<int> FreePorts
{
get
{
return new List<int>()
{
Port
};
}
}
public string Email => "server@brook.com";
public ProjectType Type { get; set; } = ProjectType.Brook;
}
}

View File

@ -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
}
}

View File

@ -10,6 +10,7 @@ namespace ProxySuper.Core.Models.Projects
{ {
Xray = 0, Xray = 0,
TrojanGo = 1, TrojanGo = 1,
NaiveProxy = 2 NaiveProxy = 2,
Brook = 3,
} }
} }

View File

@ -53,6 +53,9 @@ namespace ProxySuper.Core.Models
[JsonProperty("naiveProxySettings")] [JsonProperty("naiveProxySettings")]
public NaiveProxySettings NaiveProxySettings { get; set; } public NaiveProxySettings NaiveProxySettings { get; set; }
[JsonProperty("brook")]
public BrookSettings BrookSettings { get; set; }
[JsonIgnore] [JsonIgnore]
public ProjectType Type public ProjectType Type
@ -63,7 +66,9 @@ namespace ProxySuper.Core.Models
if (TrojanGoSettings != null) return ProjectType.TrojanGo; if (TrojanGoSettings != null) return ProjectType.TrojanGo;
return ProjectType.NaiveProxy; if (NaiveProxySettings != null) return ProjectType.NaiveProxy;
return ProjectType.Brook;
} }
} }

View File

@ -70,6 +70,8 @@
<Compile Include="Models\Hosts\Host.cs" /> <Compile Include="Models\Hosts\Host.cs" />
<Compile Include="Models\Hosts\LocalProxyType.cs" /> <Compile Include="Models\Hosts\LocalProxyType.cs" />
<Compile Include="Models\Hosts\LoginSecretType.cs" /> <Compile Include="Models\Hosts\LoginSecretType.cs" />
<Compile Include="Models\Projects\BrookSettings.cs" />
<Compile Include="Models\Projects\BrookType.cs" />
<Compile Include="Models\Projects\IProjectSettings.cs" /> <Compile Include="Models\Projects\IProjectSettings.cs" />
<Compile Include="Models\Hosts\LocalProxy.cs" /> <Compile Include="Models\Hosts\LocalProxy.cs" />
<Compile Include="Models\Projects\NaiveProxySettings.cs" /> <Compile Include="Models\Projects\NaiveProxySettings.cs" />
@ -84,6 +86,7 @@
<Compile Include="Models\Record.cs" /> <Compile Include="Models\Record.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helpers\Utils.cs" /> <Compile Include="Helpers\Utils.cs" />
<Compile Include="Services\BrookProject.cs" />
<Compile Include="Services\NaiveProxyProject.cs" /> <Compile Include="Services\NaiveProxyProject.cs" />
<Compile Include="Services\ProjectBase.cs" /> <Compile Include="Services\ProjectBase.cs" />
<Compile Include="Services\ShareLink.cs" /> <Compile Include="Services\ShareLink.cs" />
@ -91,6 +94,7 @@
<Compile Include="Services\TrojanGoProject.cs" /> <Compile Include="Services\TrojanGoProject.cs" />
<Compile Include="Services\XrayConfigBuilder.cs" /> <Compile Include="Services\XrayConfigBuilder.cs" />
<Compile Include="Services\XrayProject.cs" /> <Compile Include="Services\XrayProject.cs" />
<Compile Include="ViewModels\BrookEditorViewModel.cs" />
<Compile Include="ViewModels\HomeViewModel.cs" /> <Compile Include="ViewModels\HomeViewModel.cs" />
<Compile Include="ViewModels\NaiveProxyConfigViewModel.cs" /> <Compile Include="ViewModels\NaiveProxyConfigViewModel.cs" />
<Compile Include="ViewModels\NaiveProxyEditorViewModel.cs" /> <Compile Include="ViewModels\NaiveProxyEditorViewModel.cs" />

View File

@ -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<BrookSettings>
{
public BrookProject(SshClient sshClient, BrookSettings parameters, Action<string> 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("******卸载完成******");
}
}
}

View File

@ -20,6 +20,12 @@ namespace ProxySuper.Core.Services
Yum Yum
} }
public enum ArchType
{
x86,
arm,
}
public abstract class ProjectBase<TSettings> where TSettings : IProjectSettings public abstract class ProjectBase<TSettings> where TSettings : IProjectSettings
{ {
private SshClient _sshClient; private SshClient _sshClient;
@ -28,6 +34,8 @@ namespace ProxySuper.Core.Services
protected CmdType CmdType { get; set; } protected CmdType CmdType { get; set; }
protected ArchType ArchType { get; set; }
protected bool IsSELinux { get; set; } protected bool IsSELinux { get; set; }
protected bool OnlyIpv6 { get; set; } protected bool OnlyIpv6 { get; set; }
@ -67,6 +75,21 @@ namespace ProxySuper.Core.Services
{ {
string cmd; 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) if (CmdType == CmdType.None)
{ {

View File

@ -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<Record, Record>
{
public string Id { get; set; }
public Host Host { get; set; }
public BrookSettings Settings { get; set; }
public List<string> BrookTypes
{
get
{
return new List<string> {
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,
});
}
}
}

View File

@ -66,6 +66,8 @@ namespace ProxySuper.Core.ViewModels
public IMvxCommand AddNaiveProxyCommand => new MvxAsyncCommand(AddNaiveProxyRecord); public IMvxCommand AddNaiveProxyCommand => new MvxAsyncCommand(AddNaiveProxyRecord);
public IMvxCommand AddBrookCommand => new MvxAsyncCommand(AddBrookRecord);
public IMvxCommand RemoveCommand => new MvxAsyncCommand<string>(DeleteRecord); public IMvxCommand RemoveCommand => new MvxAsyncCommand<string>(DeleteRecord);
public IMvxCommand EditCommand => new MvxAsyncCommand<string>(EditRecord); public IMvxCommand EditCommand => new MvxAsyncCommand<string>(EditRecord);
@ -118,6 +120,21 @@ namespace ProxySuper.Core.ViewModels
SaveToJson(); 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<BrookEditorViewModel, Record, Record>(record);
if (result == null) return;
Records.Add(result);
SaveToJson();
}
public async Task EditRecord(string id) public async Task EditRecord(string id)
{ {

View File

@ -111,6 +111,9 @@
<Compile Include="MainWindow.xaml.cs"> <Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\BrookEditorView.xaml.cs">
<DependentUpon>BrookEditorView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\HomeView.xaml.cs"> <Compile Include="Views\HomeView.xaml.cs">
<DependentUpon>HomeView.xaml</DependentUpon> <DependentUpon>HomeView.xaml</DependentUpon>
</Compile> </Compile>
@ -201,6 +204,10 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page> </Page>
<Page Include="Views\BrookEditorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\HomeView.xaml"> <Page Include="Views\HomeView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>

View File

@ -0,0 +1,70 @@
<views:MvxWindow x:Class="ProxySuper.WPF.Views.BrookEditorView"
xmlns:views="clr-namespace:MvvmCross.Platforms.Wpf.Views;assembly=MvvmCross.Platforms.Wpf"
xmlns:ctrl="clr-namespace:ProxySuper.WPF.Controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ProxySuper.WPF.Views"
mc:Ignorable="d"
BorderThickness="0,1,0,0"
BorderBrush="#eee"
Title="BrookEditorView" Height="600" Width="1000">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="310" />
<ColumnDefinition Width="1" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="10">
<ctrl:HostControl />
</StackPanel>
<StackPanel Grid.Column="1" Background="#EEE"></StackPanel>
<StackPanel Grid.Column="2">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="36" />
<RowDefinition Height="36" />
<RowDefinition Height="36" />
<RowDefinition Height="36" />
<RowDefinition Height="36" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Content="类型" Grid.Row="0" Grid.Column="0" />
<ComboBox Width="200"
Height="24"
Grid.Row="0"
Grid.Column="1"
ItemsSource="{Binding Path=BrookTypes}"
SelectedValue="{Binding CheckedBrookType,Mode=TwoWay}">
</ComboBox>
<Label Content="端口" Grid.Row="1" Grid.Column="0" />
<TextBox IsEnabled="{Binding EnablePort}" Text="{Binding Settings.Port}" Grid.Row="1" Grid.Column="1" />
<Label Content="密码" Grid.Row="2" Grid.Column="0" />
<TextBox Text="{Binding Settings.Password}" Grid.Row="2" Grid.Column="1" />
<Label Content="域名" Grid.Row="3" Grid.Column="0" />
<TextBox IsEnabled="{Binding EnableDomain}" Text="{Binding Settings.Domain}" Grid.Row="3" Grid.Column="1" />
</Grid>
<Border BorderBrush="#eee" BorderThickness="0,1,0,0">
<Button Content="{DynamicResource Save}"
Command="{Binding SaveCommand}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Height="30"
Width="100"
Margin="40,20" />
</Border>
</StackPanel>
</Grid>
</views:MvxWindow>

View File

@ -0,0 +1,30 @@
using MvvmCross.Platforms.Wpf.Presenters.Attributes;
using MvvmCross.Platforms.Wpf.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ProxySuper.WPF.Views
{
/// <summary>
/// BrookEditorView.xaml 的交互逻辑
/// </summary>
[MvxWindowPresentation(Identifier = nameof(XrayEditorView), Modal = false)]
public partial class BrookEditorView : MvxWindow
{
public BrookEditorView()
{
InitializeComponent();
}
}
}

View File

@ -18,6 +18,7 @@
<MenuItem Padding="0,5" Header="Xray" Command="{Binding AddXrayCommand}"></MenuItem> <MenuItem Padding="0,5" Header="Xray" Command="{Binding AddXrayCommand}"></MenuItem>
<MenuItem Padding="0,5" Header="Trojan-Go" Command="{Binding AddTrojanGoCommand}"></MenuItem> <MenuItem Padding="0,5" Header="Trojan-Go" Command="{Binding AddTrojanGoCommand}"></MenuItem>
<MenuItem Padding="0,5" Header="NaiveProxy" Command="{Binding AddNaiveProxyCommand}"></MenuItem> <MenuItem Padding="0,5" Header="NaiveProxy" Command="{Binding AddNaiveProxyCommand}"></MenuItem>
<MenuItem Padding="0,5" Header="Brook" Command="{Binding AddBrookCommand}"></MenuItem>
</MenuItem> </MenuItem>
<MenuItem Header="{DynamicResource MainMenuActions}" Padding="10,3"> <MenuItem Header="{DynamicResource MainMenuActions}" Padding="10,3">