mirror of
https://github.com/proxysu/ProxySU.git
synced 2025-02-16 14:43:14 +03:00
merge
This commit is contained in:
parent
5bd7529bec
commit
d5878079f1
@ -10,6 +10,7 @@ namespace ProxySuper.Core.Models.Projects
|
|||||||
{
|
{
|
||||||
server,
|
server,
|
||||||
wsserver,
|
wsserver,
|
||||||
wssserver
|
wssserver,
|
||||||
|
socks5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@
|
|||||||
<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\BrookEditorViewModel.cs" />
|
||||||
|
<Compile Include="ViewModels\BrookInstallerViewModel.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" />
|
||||||
|
@ -44,64 +44,53 @@ namespace ProxySuper.Core.Services
|
|||||||
WriteOutput("域名检测完成");
|
WriteOutput("域名检测完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InstallBrook();
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("*************安装完成,尽情享用吧**********");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InstallBrook()
|
public void InstallBrook()
|
||||||
{
|
{
|
||||||
Console.WriteLine("安装nami");
|
|
||||||
RunCmd("source <(curl -L https://git.io/getnami)");
|
|
||||||
Console.WriteLine("安装nami完成");
|
|
||||||
|
|
||||||
Console.WriteLine("安装Brook");
|
Console.WriteLine("安装Brook");
|
||||||
RunCmd("echo y | nami install github.com/txthinking/brook");
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
RunCmd($"curl -L {url} -o /usr/bin/brook");
|
||||||
|
RunCmd("chmod +x /usr/bin/brook");
|
||||||
Console.WriteLine("安装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;
|
var runBrookCmd = string.Empty;
|
||||||
|
|
||||||
if (Parameters.BrookType == BrookType.server)
|
if (Parameters.BrookType == BrookType.server)
|
||||||
{
|
{
|
||||||
runBrookCmd = $"joker brook server --listen :{Parameters.Port} --password {Parameters.Password}";
|
runBrookCmd = $"nohup /usr/bin/brook server --listen :{Parameters.Port} --password {Parameters.Password} &";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Parameters.BrookType == BrookType.wsserver)
|
if (Parameters.BrookType == BrookType.wsserver)
|
||||||
{
|
{
|
||||||
runBrookCmd = $"joker brook wsserver --listen :{Parameters.Port} --password {Parameters.Password}";
|
runBrookCmd = $"nohup /usr/bin/brook wsserver --listen :{Parameters.Port} --password {Parameters.Password} &";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Parameters.BrookType == BrookType.wsserver)
|
if (Parameters.BrookType == BrookType.wsserver)
|
||||||
{
|
{
|
||||||
runBrookCmd = $"joker brook wssserver --domain {Parameters.Domain} --password {Parameters.Password}";
|
runBrookCmd = $"nohup /usr/bin/brook wssserver --domain {Parameters.Domain} --password {Parameters.Password} &";
|
||||||
}
|
}
|
||||||
|
|
||||||
RunCmd("jinbe " + runBrookCmd);
|
if (Parameters.BrookType == BrookType.socks5)
|
||||||
|
{
|
||||||
Console.WriteLine("*************安装完成,尽情享用吧**********");
|
runBrookCmd = $"nohup /usr/bin/brook socks5 --socks5 :{Parameters.Port} &";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Uninstall()
|
public void Uninstall()
|
||||||
{
|
{
|
||||||
RunCmd("jinbe remove 0");
|
RunCmd("killall brook");
|
||||||
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("关闭端口");
|
Console.WriteLine("关闭端口");
|
||||||
ClosePort(Parameters.FreePorts.ToArray());
|
ClosePort(Parameters.FreePorts.ToArray());
|
||||||
|
@ -15,6 +15,13 @@ namespace ProxySuper.Core.ViewModels
|
|||||||
{
|
{
|
||||||
public class BrookEditorViewModel : MvxViewModel<Record, Record>
|
public class BrookEditorViewModel : MvxViewModel<Record, Record>
|
||||||
{
|
{
|
||||||
|
public BrookEditorViewModel(IMvxNavigationService navigationService)
|
||||||
|
{
|
||||||
|
NavigationService = navigationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMvxNavigationService NavigationService { get; }
|
||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
public Host Host { get; set; }
|
public Host Host { get; set; }
|
||||||
@ -29,6 +36,7 @@ namespace ProxySuper.Core.ViewModels
|
|||||||
BrookType.server.ToString(),
|
BrookType.server.ToString(),
|
||||||
BrookType.wsserver.ToString(),
|
BrookType.wsserver.ToString(),
|
||||||
BrookType.wssserver.ToString(),
|
BrookType.wssserver.ToString(),
|
||||||
|
BrookType.socks5.ToString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,8 +61,6 @@ namespace ProxySuper.Core.ViewModels
|
|||||||
|
|
||||||
public IMvxCommand SaveCommand => new MvxCommand(() => Save());
|
public IMvxCommand SaveCommand => new MvxCommand(() => Save());
|
||||||
|
|
||||||
public IMvxNavigationService NavigationService { get; }
|
|
||||||
|
|
||||||
public override void Prepare(Record parameter)
|
public override void Prepare(Record parameter)
|
||||||
{
|
{
|
||||||
var record = Utils.DeepClone(parameter);
|
var record = Utils.DeepClone(parameter);
|
||||||
|
44
ProxySuper.Core/ViewModels/BrookInstallerViewModel.cs
Normal file
44
ProxySuper.Core/ViewModels/BrookInstallerViewModel.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
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 BrookInstallerViewModel : MvxViewModel<Record>
|
||||||
|
{
|
||||||
|
|
||||||
|
public Host Host { get; set; }
|
||||||
|
|
||||||
|
public BrookSettings Settings { get; set; }
|
||||||
|
|
||||||
|
public override void Prepare(Record parameter)
|
||||||
|
{
|
||||||
|
var record = Utils.DeepClone(parameter);
|
||||||
|
Host = record.Host;
|
||||||
|
Settings = record.BrookSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _connected;
|
||||||
|
public bool Connected
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _connected;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_connected = value;
|
||||||
|
RaisePropertyChanged("Connected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CommandText { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -166,6 +166,14 @@ namespace ProxySuper.Core.ViewModels
|
|||||||
record.Host = result.Host;
|
record.Host = result.Host;
|
||||||
record.NaiveProxySettings = result.NaiveProxySettings;
|
record.NaiveProxySettings = result.NaiveProxySettings;
|
||||||
}
|
}
|
||||||
|
if (record.Type == ProjectType.Brook)
|
||||||
|
{
|
||||||
|
result = await _navigationService.Navigate<BrookEditorViewModel, Record, Record>(record);
|
||||||
|
if (result == null) return;
|
||||||
|
|
||||||
|
record.Host = result.Host;
|
||||||
|
record.BrookSettings = result.BrookSettings;
|
||||||
|
}
|
||||||
|
|
||||||
SaveToJson();
|
SaveToJson();
|
||||||
}
|
}
|
||||||
@ -221,6 +229,10 @@ namespace ProxySuper.Core.ViewModels
|
|||||||
{
|
{
|
||||||
await _navigationService.Navigate<NaiveProxyInstallerViewModel, Record>(record);
|
await _navigationService.Navigate<NaiveProxyInstallerViewModel, Record>(record);
|
||||||
}
|
}
|
||||||
|
if (record.Type == ProjectType.Brook)
|
||||||
|
{
|
||||||
|
await _navigationService.Navigate<BrookInstallerViewModel, Record>(record);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,9 @@
|
|||||||
<Compile Include="Views\BrookEditorView.xaml.cs">
|
<Compile Include="Views\BrookEditorView.xaml.cs">
|
||||||
<DependentUpon>BrookEditorView.xaml</DependentUpon>
|
<DependentUpon>BrookEditorView.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Views\BrookInstallerView.xaml.cs">
|
||||||
|
<DependentUpon>BrookInstallerView.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>
|
||||||
@ -208,6 +211,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="Views\BrookInstallerView.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>
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
BorderThickness="0,1,0,0"
|
BorderThickness="0,1,0,0"
|
||||||
BorderBrush="#eee"
|
BorderBrush="#eee"
|
||||||
|
Icon="/Resources/ProxySU.ico"
|
||||||
|
WindowStartupLocation="CenterScreen"
|
||||||
Title="BrookEditorView" Height="600" Width="1000">
|
Title="BrookEditorView" Height="600" Width="1000">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
|
34
ProxySuper.WPF/Views/BrookInstallerView.xaml
Normal file
34
ProxySuper.WPF/Views/BrookInstallerView.xaml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<views:MvxWindow x:Class="ProxySuper.WPF.Views.BrookInstallerView"
|
||||||
|
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:views="clr-namespace:MvvmCross.Platforms.Wpf.Views;assembly=MvvmCross.Platforms.Wpf"
|
||||||
|
xmlns:local="clr-namespace:ProxySuper.WPF.Views"
|
||||||
|
Icon="/Resources/ProxySU.ico"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
WindowStartupLocation="CenterScreen"
|
||||||
|
Title="Brook" Height="450" Width="800">
|
||||||
|
<StackPanel>
|
||||||
|
<TextBox IsReadOnly="True"
|
||||||
|
Block.LineHeight="18"
|
||||||
|
Background="#000"
|
||||||
|
Foreground="LawnGreen"
|
||||||
|
FontSize="14"
|
||||||
|
FontFamily="Consolas"
|
||||||
|
x:Name="OutputTextBox"
|
||||||
|
Height="260"
|
||||||
|
Padding="10"
|
||||||
|
BorderThickness="0"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
VerticalContentAlignment="Top"
|
||||||
|
TextWrapping="WrapWithOverflow"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<StackPanel Margin="5" Orientation="Horizontal">
|
||||||
|
<Label Content="{DynamicResource Install}" />
|
||||||
|
<Button Height="24" Padding="10,0" Margin="10,0,0,0" IsEnabled="{Binding Connected}" Click="Install" Content="{DynamicResource XrayInstallerInstall}" />
|
||||||
|
<Button Height="24" Padding="10,0" Margin="10,0,0,0" IsEnabled="{Binding Connected}" Click="Uninstall" Content="{DynamicResource XrayInstallerUninstall}" />
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</views:MvxWindow>
|
157
ProxySuper.WPF/Views/BrookInstallerView.xaml.cs
Normal file
157
ProxySuper.WPF/Views/BrookInstallerView.xaml.cs
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
using MvvmCross.Platforms.Wpf.Views;
|
||||||
|
using ProxySuper.Core.Models.Hosts;
|
||||||
|
using ProxySuper.Core.Services;
|
||||||
|
using ProxySuper.Core.ViewModels;
|
||||||
|
using Renci.SshNet;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
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>
|
||||||
|
/// BrookInstallerView.xaml 的交互逻辑
|
||||||
|
/// </summary>
|
||||||
|
public partial class BrookInstallerView : MvxWindow
|
||||||
|
{
|
||||||
|
public BrookInstallerView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public new BrookInstallerViewModel ViewModel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return (BrookInstallerViewModel)base.ViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BrookProject Project { get; set; }
|
||||||
|
|
||||||
|
private SshClient _sshClient;
|
||||||
|
private void OpenConnect()
|
||||||
|
{
|
||||||
|
|
||||||
|
WriteOutput("正在登陆服务器 ...");
|
||||||
|
var conneInfo = CreateConnectionInfo(ViewModel.Host);
|
||||||
|
_sshClient = new SshClient(conneInfo);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_sshClient.Connect();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
WriteOutput("登陆失败!");
|
||||||
|
WriteOutput(ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WriteOutput("登陆服务器成功!");
|
||||||
|
|
||||||
|
ViewModel.Connected = true;
|
||||||
|
Project = new BrookProject(_sshClient, ViewModel.Settings, WriteOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteOutput(string outShell)
|
||||||
|
{
|
||||||
|
if (!outShell.EndsWith("\n"))
|
||||||
|
{
|
||||||
|
outShell += "\n";
|
||||||
|
}
|
||||||
|
ViewModel.CommandText += outShell;
|
||||||
|
|
||||||
|
Dispatcher.Invoke(() =>
|
||||||
|
{
|
||||||
|
OutputTextBox.AppendText(outShell);
|
||||||
|
OutputTextBox.ScrollToEnd();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConnectionInfo CreateConnectionInfo(Host host)
|
||||||
|
{
|
||||||
|
AuthenticationMethod auth = null;
|
||||||
|
|
||||||
|
if (host.SecretType == LoginSecretType.Password)
|
||||||
|
{
|
||||||
|
auth = new PasswordAuthenticationMethod(host.UserName, host.Password);
|
||||||
|
}
|
||||||
|
else if (host.SecretType == LoginSecretType.PrivateKey)
|
||||||
|
{
|
||||||
|
auth = new PrivateKeyAuthenticationMethod(host.UserName, new PrivateKeyFile(host.PrivateKeyPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (host.Proxy.Type == LocalProxyType.None)
|
||||||
|
{
|
||||||
|
return new ConnectionInfo(host.Address, host.Port, host.UserName, auth);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new ConnectionInfo(
|
||||||
|
host: host.Address,
|
||||||
|
port: host.Port,
|
||||||
|
username: host.UserName,
|
||||||
|
proxyType: (ProxyTypes)(int)host.Proxy.Type,
|
||||||
|
proxyHost: host.Proxy.Address,
|
||||||
|
proxyPort: host.Proxy.Port,
|
||||||
|
proxyUsername: host.Proxy.UserName,
|
||||||
|
proxyPassword: host.Proxy.Password,
|
||||||
|
authenticationMethods: auth);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnInitialized(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnInitialized(e);
|
||||||
|
base.Loaded += (sender, arg) =>
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(OpenConnect);
|
||||||
|
};
|
||||||
|
base.Closed += SaveInstallLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveInstallLog(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists("Logs"))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory("Logs");
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileName = System.IO.Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".brook.txt");
|
||||||
|
File.WriteAllText(fileName, ViewModel.CommandText);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenLink(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Hyperlink link = sender as Hyperlink;
|
||||||
|
Process.Start(new ProcessStartInfo(link.NavigateUri.AbsoluteUri));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Install(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(Project.Install);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void Uninstall(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var result = MessageBox.Show("您确认要卸载代理吗?", "提示", MessageBoxButton.YesNo);
|
||||||
|
if (result == MessageBoxResult.Yes)
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(Project.Uninstall);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user