mirror of
https://github.com/proxysu/ProxySU.git
synced 2024-11-22 05:06:08 +03:00
MTProxy-Go
This commit is contained in:
parent
7b7251279f
commit
be9ae4a8de
@ -7,5 +7,6 @@
|
||||
NaiveProxy = 2,
|
||||
Brook = 3,
|
||||
V2ray = 4,
|
||||
MTProxyGo = 5,
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using Newtonsoft.Json;
|
||||
using ProxySuper.Core.Models.Hosts;
|
||||
using ProxySuper.Core.Models.Projects;
|
||||
using ProxySuper.Core.Services;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace ProxySuper.Core.Models
|
||||
@ -64,6 +65,8 @@ namespace ProxySuper.Core.Models
|
||||
|
||||
if (NaiveProxySettings != null) return ProjectType.NaiveProxy;
|
||||
|
||||
if (MTProxyGoSettings != null) return ProjectType.MTProxyGo;
|
||||
|
||||
return ProjectType.Brook;
|
||||
}
|
||||
}
|
||||
@ -82,6 +85,9 @@ namespace ProxySuper.Core.Models
|
||||
}
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public Action OnSave { get; set; } = () => { };
|
||||
|
||||
public string GetShareLink()
|
||||
{
|
||||
if (Type == ProjectType.V2ray)
|
||||
|
@ -105,6 +105,7 @@
|
||||
<Compile Include="ViewModels\BrookInstallViewModel.cs" />
|
||||
<Compile Include="ViewModels\EnableRootViewModel.cs" />
|
||||
<Compile Include="ViewModels\HomeViewModel.cs" />
|
||||
<Compile Include="ViewModels\MTProxyGoConfigViewModel.cs" />
|
||||
<Compile Include="ViewModels\MTProxyGoEditorViewModel.cs" />
|
||||
<Compile Include="ViewModels\MTProxyGoInstallViewModel.cs" />
|
||||
<Compile Include="ViewModels\NaiveProxyConfigViewModel.cs" />
|
||||
|
@ -69,6 +69,9 @@ namespace ProxySuper.Core.Services
|
||||
Progress.Percentage = 100;
|
||||
Progress.Step = "安装Brook成功";
|
||||
Progress.Desc = "安装Brook成功";
|
||||
|
||||
AppendCommand("分享连接:");
|
||||
AppendCommand(ShareLink.BuildBrook(Settings));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ namespace ProxySuper.Core.Services
|
||||
Progress.Percentage = 50;
|
||||
|
||||
Progress.Step = "5. 生成密钥";
|
||||
Settings.SecretText = RunCmd($"docker run nineseconds/mtg generate-secret {Settings.Cleartext}");
|
||||
Settings.SecretText = RunCmd($"docker run nineseconds/mtg generate-secret {Settings.Cleartext}").TrimEnd('\n');
|
||||
Progress.Percentage = 65;
|
||||
|
||||
Progress.Step = "6. 生成配置文件";
|
||||
@ -49,8 +49,8 @@ namespace ProxySuper.Core.Services
|
||||
RunCmd("touch /etc/mtg.toml");
|
||||
|
||||
Progress.Desc = "写入配置内容";
|
||||
RunCmd($"echo secret=\"{Settings.SecretText}\" > /etc/mtg.toml");
|
||||
RunCmd($"echo bind-to=\"0.0.0.0:{Settings.Port}\" >> /etc/mtg.toml");
|
||||
RunCmd($"echo \"secret=\\\"{Settings.SecretText}\\\"\" > /etc/mtg.toml");
|
||||
RunCmd($"echo \"bind-to=\\\"0.0.0.0:{Settings.Port}\\\"\" >> /etc/mtg.toml");
|
||||
Progress.Percentage = 80;
|
||||
|
||||
Progress.Step = "7. 启动MTProxy服务";
|
||||
@ -60,6 +60,10 @@ namespace ProxySuper.Core.Services
|
||||
Progress.Step = "安装完成";
|
||||
Progress.Percentage = 100;
|
||||
|
||||
AppendCommand("Host: " + Settings.Domain);
|
||||
AppendCommand("Port: " + Settings.Port);
|
||||
AppendCommand("Secret: " + Settings.SecretText);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -102,17 +106,20 @@ namespace ProxySuper.Core.Services
|
||||
try
|
||||
{
|
||||
Progress.Percentage = 0;
|
||||
Progress.Step = "卸载MTProxy";
|
||||
Progress.Step = "更新MTProxy配置";
|
||||
|
||||
|
||||
Progress.Desc = "停止MTProxy服务";
|
||||
Progress.Desc = "暂停MTProxy服务";
|
||||
var cid = RunCmd("docker ps -q --filter name=mtg");
|
||||
RunCmd($"docker stop {cid}");
|
||||
Progress.Percentage = 50;
|
||||
|
||||
Progress.Desc = "生成密钥";
|
||||
Settings.SecretText = RunCmd($"docker run nineseconds/mtg generate-secret {Settings.Cleartext}").TrimEnd('\n');
|
||||
Progress.Percentage = 65;
|
||||
|
||||
Progress.Desc = "修改配置文件";
|
||||
RunCmd($"echo secret=\"{Settings.SecretText}\" > /etc/mtg.toml");
|
||||
RunCmd($"echo bind-to=\"0.0.0.0:{Settings.Port}\" >> /etc/mtg.toml");
|
||||
RunCmd($"echo \"secret=\\\"{Settings.SecretText}\\\"\" > /etc/mtg.toml");
|
||||
RunCmd($"echo \"bind-to=\\\"0.0.0.0:{Settings.Port}\\\"\" >> /etc/mtg.toml");
|
||||
Progress.Percentage = 80;
|
||||
|
||||
Progress.Desc = "重启MTProxy服务";
|
||||
@ -120,6 +127,10 @@ namespace ProxySuper.Core.Services
|
||||
|
||||
Progress.Percentage = 100;
|
||||
Progress.Desc = "更新配置成功";
|
||||
|
||||
AppendCommand("Host: " + Settings.Domain);
|
||||
AppendCommand("Port: " + Settings.Port);
|
||||
AppendCommand("Secret: " + Settings.SecretText);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -66,6 +66,9 @@ namespace ProxySuper.Core.Services
|
||||
Progress.Percentage = 100;
|
||||
Progress.Step = "NaiveProxy安装成功";
|
||||
Progress.Desc = string.Empty;
|
||||
|
||||
AppendCommand("分享连接:");
|
||||
AppendCommand(ShareLink.BuildNaiveProxy(Settings));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -561,6 +561,15 @@ namespace ProxySuper.Core.Services
|
||||
RunCmd("mv /etc/resolv.conf.proxysu /etc/resolv.conf");
|
||||
}
|
||||
|
||||
protected void AppendCommand(string command)
|
||||
{
|
||||
if (!command.EndsWith("\n"))
|
||||
{
|
||||
command += "\n";
|
||||
}
|
||||
Progress.Logs += command;
|
||||
}
|
||||
|
||||
private List<string> FilterFastestIP()
|
||||
{
|
||||
string[] gateNat64 = {
|
||||
@ -739,14 +748,6 @@ namespace ProxySuper.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
private void AppendCommand(string command)
|
||||
{
|
||||
if (!command.EndsWith("\n"))
|
||||
{
|
||||
command += "\n";
|
||||
}
|
||||
Progress.Logs += command;
|
||||
}
|
||||
|
||||
private ConnectionInfo CreateConnectionInfo()
|
||||
{
|
||||
|
@ -82,6 +82,8 @@ namespace ProxySuper.Core.Services
|
||||
RunCmd("systemctl enable trojan-go");
|
||||
RunCmd("systemctl restart trojan-go");
|
||||
|
||||
AppendCommand("分享连接:");
|
||||
AppendCommand(ShareLink.BuildTrojanGo(Settings));
|
||||
|
||||
Progress.Percentage = 100;
|
||||
Progress.Step = "安装成功";
|
||||
|
@ -247,6 +247,14 @@ namespace ProxySuper.Core.ViewModels
|
||||
record.Host = result.Host;
|
||||
record.BrookSettings = result.BrookSettings;
|
||||
}
|
||||
if (record.Type == ProjectType.MTProxyGo)
|
||||
{
|
||||
result = await _navigationService.Navigate<MTProxyGoEditorViewModel, Record, Record>(record);
|
||||
if (result == null) return;
|
||||
|
||||
record.Host = result.Host;
|
||||
record.MTProxyGoSettings = result.MTProxyGoSettings;
|
||||
}
|
||||
|
||||
SaveToJson();
|
||||
}
|
||||
@ -291,12 +299,17 @@ namespace ProxySuper.Core.ViewModels
|
||||
{
|
||||
await _navigationService.Navigate<BrookConfigViewModel, BrookSettings>(record.BrookSettings);
|
||||
}
|
||||
if (record.Type == ProjectType.MTProxyGo)
|
||||
{
|
||||
await _navigationService.Navigate<MTProxyGoConfigViewModel, MTProxyGoSettings>(record.MTProxyGoSettings);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task GoToInstall(string id)
|
||||
{
|
||||
var record = Records.FirstOrDefault(x => x.Id == id);
|
||||
if (record == null) return;
|
||||
record.OnSave = SaveToJson;
|
||||
|
||||
if (record.Type == ProjectType.V2ray)
|
||||
{
|
||||
@ -318,6 +331,13 @@ namespace ProxySuper.Core.ViewModels
|
||||
{
|
||||
await _navigationService.Navigate<BrookInstallViewModel, Record>(record);
|
||||
}
|
||||
if (record.Type == ProjectType.MTProxyGo)
|
||||
{
|
||||
await _navigationService.Navigate<MTProxyGoInstallViewModel, Record>(record);
|
||||
}
|
||||
|
||||
SaveToJson();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
21
ProxySuper.Core/ViewModels/MTProxyGoConfigViewModel.cs
Normal file
21
ProxySuper.Core/ViewModels/MTProxyGoConfigViewModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using MvvmCross.ViewModels;
|
||||
using ProxySuper.Core.Models;
|
||||
using ProxySuper.Core.Models.Projects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProxySuper.Core.ViewModels
|
||||
{
|
||||
public class MTProxyGoConfigViewModel : MvxViewModel<MTProxyGoSettings>
|
||||
{
|
||||
public MTProxyGoSettings Settings { get; set; }
|
||||
|
||||
public override void Prepare(MTProxyGoSettings parameter)
|
||||
{
|
||||
Settings = parameter;
|
||||
}
|
||||
}
|
||||
}
|
@ -21,10 +21,13 @@ namespace ProxySuper.Core.ViewModels
|
||||
|
||||
MTProxyGoService _mtproxyService;
|
||||
|
||||
Action _onSave;
|
||||
|
||||
public override void Prepare(Record parameter)
|
||||
{
|
||||
_host = parameter.Host;
|
||||
_settings = parameter.MTProxyGoSettings;
|
||||
_onSave = parameter.OnSave;
|
||||
}
|
||||
|
||||
public override Task Initialize()
|
||||
@ -56,9 +59,21 @@ namespace ProxySuper.Core.ViewModels
|
||||
|
||||
#region Command
|
||||
|
||||
public IMvxCommand InstallCommand => new MvxCommand(_mtproxyService.Install);
|
||||
public IMvxCommand InstallCommand => new MvxCommand(() =>
|
||||
{
|
||||
_mtproxyService.Install();
|
||||
|
||||
public IMvxCommand UpdateSettingsCommand => new MvxCommand(_mtproxyService.UpdateSettings);
|
||||
// 安装时生成的Secret需要保存
|
||||
_onSave();
|
||||
});
|
||||
|
||||
public IMvxCommand UpdateSettingsCommand => new MvxCommand(() =>
|
||||
{
|
||||
_mtproxyService.UpdateSettings();
|
||||
|
||||
// 安装时生成的Secret需要保存
|
||||
_onSave();
|
||||
});
|
||||
|
||||
public IMvxCommand UninstallCommand => new MvxCommand(_mtproxyService.Uninstall);
|
||||
|
||||
|
@ -135,11 +135,14 @@
|
||||
<Compile Include="Views\HomeView.xaml.cs">
|
||||
<DependentUpon>HomeView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\MTProxyGo\MTProxyGoConfigView.xaml.cs">
|
||||
<DependentUpon>MTProxyGoConfigView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\MTProxyGo\MTProxyGoEditorView.xaml.cs">
|
||||
<DependentUpon>MTProxyGoEditorView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\MTProxyGo\MTProxyInstallView.xaml.cs">
|
||||
<DependentUpon>MTProxyInstallView.xaml</DependentUpon>
|
||||
<Compile Include="Views\MTProxyGo\MTProxyGoInstallView.xaml.cs">
|
||||
<DependentUpon>MTProxyGoInstallView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\NaiveProxy\NaiveProxyConfigView.xaml.cs">
|
||||
<DependentUpon>NaiveProxyConfigView.xaml</DependentUpon>
|
||||
@ -284,11 +287,15 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Page>
|
||||
<Page Include="Views\MTProxyGo\MTProxyGoConfigView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\MTProxyGo\MTProxyGoEditorView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\MTProxyGo\MTProxyInstallView.xaml">
|
||||
<Page Include="Views\MTProxyGo\MTProxyGoInstallView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
|
32
ProxySuper.WPF/Views/MTProxyGo/MTProxyGoConfigView.xaml
Normal file
32
ProxySuper.WPF/Views/MTProxyGo/MTProxyGoConfigView.xaml
Normal file
@ -0,0 +1,32 @@
|
||||
<views:MvxWindow x:Class="ProxySuper.WPF.Views.MTProxyGo.MTProxyGoConfigView"
|
||||
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.MTProxyGo"
|
||||
xmlns:views="clr-namespace:MvvmCross.Platforms.Wpf.Views;assembly=MvvmCross.Platforms.Wpf"
|
||||
mc:Ignorable="d"
|
||||
Icon="/Resources/ProxySU.ico"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="MTProxy-Go节点配置" Height="450" Width="800">
|
||||
<Grid Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="140" />
|
||||
<ColumnDefinition Width="300" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="36" />
|
||||
<RowDefinition Height="36" />
|
||||
<RowDefinition Height="36" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Grid.Row="0" Grid.Column="0" Content="地址(Address)" />
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Settings.Domain}" IsReadOnly="True" />
|
||||
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="端口(Port)" />
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Settings.Port}" IsReadOnly="True" />
|
||||
|
||||
<Label Grid.Row="2" Grid.Column="0" Content="密钥(Secret)" />
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Settings.SecretText}" IsReadOnly="True" />
|
||||
</Grid>
|
||||
</views:MvxWindow>
|
28
ProxySuper.WPF/Views/MTProxyGo/MTProxyGoConfigView.xaml.cs
Normal file
28
ProxySuper.WPF/Views/MTProxyGo/MTProxyGoConfigView.xaml.cs
Normal file
@ -0,0 +1,28 @@
|
||||
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.MTProxyGo
|
||||
{
|
||||
/// <summary>
|
||||
/// MTProxyGoConfigView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MTProxyGoConfigView : MvxWindow
|
||||
{
|
||||
public MTProxyGoConfigView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<views:MvxWindow x:Class="ProxySuper.WPF.Views.MTProxyGo.MTProxyInstallView"
|
||||
<views:MvxWindow x:Class="ProxySuper.WPF.Views.MTProxyGo.MTProxyGoInstallView"
|
||||
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"
|
@ -18,9 +18,9 @@ namespace ProxySuper.WPF.Views.MTProxyGo
|
||||
/// <summary>
|
||||
/// MTProxyInstallView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MTProxyInstallView : MvxWindow
|
||||
public partial class MTProxyGoInstallView : MvxWindow
|
||||
{
|
||||
public MTProxyInstallView()
|
||||
public MTProxyGoInstallView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
Loading…
Reference in New Issue
Block a user