diff --git a/ProxySuper.Core/Models/Projects/MTProxyGoSettings.cs b/ProxySuper.Core/Models/Projects/MTProxyGoSettings.cs new file mode 100644 index 0000000..532207b --- /dev/null +++ b/ProxySuper.Core/Models/Projects/MTProxyGoSettings.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.Models.Projects +{ + public class MTProxyGoSettings : IProjectSettings + { + public MTProxyGoSettings() + { + Port = 443; + + Domain = string.Empty; + + Cleartext = "bing.com"; + + SecretText = string.Empty; + } + + public int Port { get; set; } + + public string Domain { get; set; } + + public List FreePorts => new List { Port }; + + public string Email => ""; + + public string Cleartext { get; set; } + + public string SecretText { get; set; } + } +} diff --git a/ProxySuper.Core/Models/Record.cs b/ProxySuper.Core/Models/Record.cs index 6d3fed3..ac36903 100644 --- a/ProxySuper.Core/Models/Record.cs +++ b/ProxySuper.Core/Models/Record.cs @@ -47,6 +47,9 @@ namespace ProxySuper.Core.Models [JsonProperty("brook")] public BrookSettings BrookSettings { get; set; } + [JsonProperty("mtProxyGoSettings")] + public MTProxyGoSettings MTProxyGoSettings { get; set; } + [JsonIgnore] public ProjectType Type diff --git a/ProxySuper.Core/ProxySuper.Core.csproj b/ProxySuper.Core/ProxySuper.Core.csproj index 21e8ee9..6d6fd8e 100644 --- a/ProxySuper.Core/ProxySuper.Core.csproj +++ b/ProxySuper.Core/ProxySuper.Core.csproj @@ -75,6 +75,7 @@ + @@ -89,6 +90,7 @@ + @@ -103,6 +105,8 @@ + + diff --git a/ProxySuper.Core/Services/MTProxyGoService.cs b/ProxySuper.Core/Services/MTProxyGoService.cs new file mode 100644 index 0000000..5c429d9 --- /dev/null +++ b/ProxySuper.Core/Services/MTProxyGoService.cs @@ -0,0 +1,143 @@ +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class MTProxyGoService : ServiceBase + { + public MTProxyGoService(Host host, MTProxyGoSettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "1. 检测系统环境"; + Progress.Percentage = 0; + + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 15; + + Progress.Step = "2. 安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 25; + + Progress.Step = "3. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 35; + + Progress.Step = "4. 安装docker"; + InstallDocker(); + Progress.Percentage = 50; + + Progress.Step = "5. 生成密钥"; + Settings.SecretText = RunCmd($"docker run nineseconds/mtg generate-secret {Settings.Cleartext}"); + Progress.Percentage = 65; + + Progress.Step = "6. 生成配置文件"; + Progress.Desc = "创建配置"; + 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"); + Progress.Percentage = 80; + + Progress.Step = "7. 启动MTProxy服务"; + RunCmd($"docker run -d -v /etc/mtg.toml:/config.toml --name=mtg --restart=always -p {Settings.Port + ":" + Settings.Port} nineseconds/mtg"); + Progress.Desc = "设置自启动MTProxy服务"; + + Progress.Step = "安装完成"; + Progress.Percentage = 100; + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "卸载MTProxy"; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + Progress.Percentage = 30; + + Progress.Desc = "删除docker容器"; + var cid = RunCmd("docker ps -q --filter name=mtg"); + RunCmd($"docker stop {cid}"); + RunCmd($"docker rm {cid}"); + Progress.Percentage = 100; + Progress.Desc = "卸载完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateSettings() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "卸载MTProxy"; + + + Progress.Desc = "停止MTProxy服务"; + var cid = RunCmd("docker ps -q --filter name=mtg"); + RunCmd($"docker stop {cid}"); + Progress.Percentage = 50; + + Progress.Desc = "修改配置文件"; + 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服务"; + RunCmd($"docker restart {cid}"); + + Progress.Percentage = 100; + Progress.Desc = "更新配置成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void InstallDocker() + { + Progress.Desc = "执行docker安装脚本"; + RunCmd("yes | curl https://get.docker.com | sh"); + + if (!FileExists("/usr/bin/docker")) + { + Progress.Desc = "docker安装失败"; + throw new Exception("docker安装失败"); + } + } + } +} diff --git a/ProxySuper.Core/ViewModels/HomeViewModel.cs b/ProxySuper.Core/ViewModels/HomeViewModel.cs index 87baad7..370d28f 100644 --- a/ProxySuper.Core/ViewModels/HomeViewModel.cs +++ b/ProxySuper.Core/ViewModels/HomeViewModel.cs @@ -100,6 +100,8 @@ namespace ProxySuper.Core.ViewModels public IMvxCommand AddNaiveProxyCommand => new MvxAsyncCommand(AddNaiveProxyRecord); + public IMvxCommand AddMTProxyGoCommand => new MvxAsyncCommand(AddMTProxyGoRecord); + public IMvxCommand AddBrookCommand => new MvxAsyncCommand(AddBrookRecord); public IMvxCommand RemoveCommand => new MvxAsyncCommand(DeleteRecord); @@ -153,6 +155,21 @@ namespace ProxySuper.Core.ViewModels SaveToJson(); } + public async Task AddMTProxyGoRecord() + { + Record record = new Record(); + record.Id = Utils.GetTickID(); + record.Host = new Host(); + record.MTProxyGoSettings = new MTProxyGoSettings(); + + var result = await _navigationService.Navigate(record); + if (result == null) return; + + Records.Add(result); + + SaveToJson(); + } + public async Task AddNaiveProxyRecord() { Record record = new Record(); diff --git a/ProxySuper.Core/ViewModels/MTProxyGoEditorViewModel.cs b/ProxySuper.Core/ViewModels/MTProxyGoEditorViewModel.cs new file mode 100644 index 0000000..4ab5336 --- /dev/null +++ b/ProxySuper.Core/ViewModels/MTProxyGoEditorViewModel.cs @@ -0,0 +1,66 @@ +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 MTProxyGoEditorViewModel : MvxViewModel + { + public MTProxyGoEditorViewModel(IMvxNavigationService navigationService) + { + NavigationService = navigationService; + } + + public IMvxNavigationService NavigationService { get; } + + public IMvxCommand SaveCommand => new MvxCommand(Save); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); + + public string Id { get; set; } + + public Host Host { get; set; } + + public MTProxyGoSettings Settings { get; set; } + + public override void Prepare(Record parameter) + { + var record = Utils.DeepClone(parameter); + + Id = record.Id; + Host = record.Host; + Settings = record.MTProxyGoSettings; + } + + private void Save() + { + NavigationService.Close(this, new Record + { + Id = this.Id, + Host = this.Host, + MTProxyGoSettings = Settings, + }); + } + + private void SaveAndInstall() + { + var record = new Record + { + Id = this.Id, + Host = this.Host, + MTProxyGoSettings = Settings, + }; + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } + } +} diff --git a/ProxySuper.Core/ViewModels/MTProxyGoInstallViewModel.cs b/ProxySuper.Core/ViewModels/MTProxyGoInstallViewModel.cs new file mode 100644 index 0000000..59886cd --- /dev/null +++ b/ProxySuper.Core/ViewModels/MTProxyGoInstallViewModel.cs @@ -0,0 +1,79 @@ +using MvvmCross.Commands; +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.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class MTProxyGoInstallViewModel : MvxViewModel + { + Host _host; + + MTProxyGoSettings _settings; + + MTProxyGoService _mtproxyService; + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.MTProxyGoSettings; + } + + public override Task Initialize() + { + _mtproxyService = new MTProxyGoService(_host, _settings); + _mtproxyService.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _mtproxyService.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _mtproxyService.Connect(); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _mtproxyService.Disconnect(); + this.SaveInstallLog(); + base.ViewDestroy(viewFinishing); + } + + public ProjectProgress Progress + { + get => _mtproxyService.Progress; + } + + public string Logs + { + get => _mtproxyService.Progress.Logs; + } + + + #region Command + + public IMvxCommand InstallCommand => new MvxCommand(_mtproxyService.Install); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(_mtproxyService.UpdateSettings); + + public IMvxCommand UninstallCommand => new MvxCommand(_mtproxyService.Uninstall); + + #endregion + + + private void SaveInstallLog() + { + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + var fileName = System.IO.Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".mtproxy-go.txt"); + File.WriteAllText(fileName, Logs); + } + } +} diff --git a/ProxySuper.Core/ViewModels/V2rayInstallViewModel.cs b/ProxySuper.Core/ViewModels/V2rayInstallViewModel.cs index 5a27854..0bfa7aa 100644 --- a/ProxySuper.Core/ViewModels/V2rayInstallViewModel.cs +++ b/ProxySuper.Core/ViewModels/V2rayInstallViewModel.cs @@ -81,7 +81,7 @@ namespace ProxySuper.Core.ViewModels Directory.CreateDirectory("Logs"); } - var fileName = Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".xary.txt"); + var fileName = Path.Combine("Logs", DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".v2ray.txt"); File.WriteAllText(fileName, Logs); } } diff --git a/ProxySuper.WPF/ProxySuper.WPF.csproj b/ProxySuper.WPF/ProxySuper.WPF.csproj index c22f086..66be202 100644 --- a/ProxySuper.WPF/ProxySuper.WPF.csproj +++ b/ProxySuper.WPF/ProxySuper.WPF.csproj @@ -135,6 +135,12 @@ HomeView.xaml + + MTProxyGoEditorView.xaml + + + MTProxyInstallView.xaml + NaiveProxyConfigView.xaml @@ -278,6 +284,14 @@ MSBuild:Compile PreserveNewest + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ProxySuper.WPF/Resources/Languages/en.xaml b/ProxySuper.WPF/Resources/Languages/en.xaml index d1a4178..f9872c9 100644 --- a/ProxySuper.WPF/Resources/Languages/en.xaml +++ b/ProxySuper.WPF/Resources/Languages/en.xaml @@ -1,7 +1,7 @@  - + Random Save @@ -65,7 +65,7 @@ Http Socks5 - + VLESS over TCP With XTLS Preferred VLESS over TCP with TLS XTLS is Preferred @@ -100,7 +100,7 @@ Trojan Port xray Port default port is 443 - + Install UpdateSettings @@ -119,11 +119,17 @@ GuiseHost WS Path WS Domain - + Address Port UserName Password GuiseHost + + + Address + Port + Cleantext + Secret \ No newline at end of file diff --git a/ProxySuper.WPF/Resources/Languages/tw_cn.xaml b/ProxySuper.WPF/Resources/Languages/tw_cn.xaml index b95be88..dce35ce 100644 --- a/ProxySuper.WPF/Resources/Languages/tw_cn.xaml +++ b/ProxySuper.WPF/Resources/Languages/tw_cn.xaml @@ -126,4 +126,10 @@ 用戶名 密碼 偽裝網站 + + + 域名/IP + 端口 + 加密前字符 + 密鑰 \ No newline at end of file diff --git a/ProxySuper.WPF/Resources/Languages/zh_cn.xaml b/ProxySuper.WPF/Resources/Languages/zh_cn.xaml index a3bf221..4aeb1bd 100644 --- a/ProxySuper.WPF/Resources/Languages/zh_cn.xaml +++ b/ProxySuper.WPF/Resources/Languages/zh_cn.xaml @@ -127,4 +127,10 @@ 用户名 密码 伪装网站 + + + 域名/IP + 端口 + 加密前字符 + 密钥 \ No newline at end of file diff --git a/ProxySuper.WPF/Views/HomeView.xaml b/ProxySuper.WPF/Views/HomeView.xaml index 07e0781..7e5d14b 100644 --- a/ProxySuper.WPF/Views/HomeView.xaml +++ b/ProxySuper.WPF/Views/HomeView.xaml @@ -17,6 +17,7 @@ + diff --git a/ProxySuper.WPF/Views/MTProxyGo/MTProxyGoEditorView.xaml b/ProxySuper.WPF/Views/MTProxyGo/MTProxyGoEditorView.xaml new file mode 100644 index 0000000..da02520 --- /dev/null +++ b/ProxySuper.WPF/Views/MTProxyGo/MTProxyGoEditorView.xaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +