From 69b29fce213884c989c9bfea09406e14dfd11c73 Mon Sep 17 00:00:00 2001 From: autumn Date: Wed, 18 Aug 2021 17:34:32 +0800 Subject: [PATCH] save. --- ProxySuper.Core/ProxySuper.Core.csproj | 6 + ProxySuper.Core/Services/BrookService.cs | 165 ++++++++ ProxySuper.Core/Services/NaiveProxyService.cs | 271 ++++++++++++ ProxySuper.Core/Services/ServiceBase.cs | 35 +- ProxySuper.Core/Services/TrojanGoService.cs | 369 ++++++++++++++++ ProxySuper.Core/Services/XrayService.cs | 397 +++++++++++++++--- .../ViewModels/BrookInstallViewModel.cs | 51 +++ ProxySuper.Core/ViewModels/HomeViewModel.cs | 6 +- .../ViewModels/NaiveProxyInstallViewModel.cs | 61 +++ .../ViewModels/TrojanGoInstallViewModel.cs | 71 ++++ .../ViewModels/XrayEditorViewModel.cs | 16 +- .../ViewModels/XrayInstallViewModel.cs | 29 +- .../Controls/VLESS_KCP_Control.xaml | 2 +- .../Controls/VLESS_TCP_TLS_Control.xaml | 2 +- .../Controls/VLESS_WS_TLS_Control.xaml | 2 +- .../Controls/VLESS_XTLS_Control.xaml | 2 +- .../Controls/VLESS_gRPC_Control.xaml | 2 +- .../Controls/VMESS_KCP_Control.xaml | 2 +- .../Controls/VMESS_TCP_TLS_Control.xaml | 2 +- .../Controls/VMESS_WS_TLS_Control.xaml | 2 +- ProxySuper.WPF/ProxySuper.WPF.csproj | 73 ++-- ProxySuper.WPF/Resources/Languages/en.xaml | 3 +- ProxySuper.WPF/Resources/Languages/tw_cn.xaml | 3 +- ProxySuper.WPF/Resources/Languages/zh_cn.xaml | 3 +- .../Views/{ => Brook}/BrookConfigView.xaml | 0 .../Views/{ => Brook}/BrookConfigView.xaml.cs | 0 .../Views/{ => Brook}/BrookEditorView.xaml | 0 .../Views/{ => Brook}/BrookEditorView.xaml.cs | 0 .../Views/Brook/BrookInstallView.xaml | 29 ++ .../Views/Brook/BrookInstallView.xaml.cs | 28 ++ .../Views/{ => Brook}/BrookInstallerView.xaml | 0 .../{ => Brook}/BrookInstallerView.xaml.cs | 0 .../NaiveProxyConfigView.xaml | 0 .../NaiveProxyConfigView.xaml.cs | 0 .../NaiveProxyEditorView.xaml | 0 .../NaiveProxyEditorView.xaml.cs | 0 .../NaiveProxy/NaiveProxyInstallView.xaml | 51 +++ .../NaiveProxy/NaiveProxyInstallView.xaml.cs | 28 ++ .../NaiveProxyInstallerView.xaml | 0 .../NaiveProxyInstallerView.xaml.cs | 0 ProxySuper.WPF/Views/ShareLinkView.xaml | 9 +- .../{ => TrojanGo}/TrojanGoConfigView.xaml | 0 .../{ => TrojanGo}/TrojanGoConfigView.xaml.cs | 0 .../{ => TrojanGo}/TrojanGoEditorView.xaml | 0 .../{ => TrojanGo}/TrojanGoEditorView.xaml.cs | 0 .../Views/TrojanGo/TrojanGoInstallView.xaml | 63 +++ .../TrojanGo/TrojanGoInstallView.xaml.cs | 28 ++ .../{ => TrojanGo}/TrojanGoInstallerView.xaml | 0 .../TrojanGoInstallerView.xaml.cs | 0 .../Views/{ => Xray}/XrayConfigView.xaml | 0 .../Views/{ => Xray}/XrayConfigView.xaml.cs | 0 .../Views/{ => Xray}/XrayEditorView.xaml | 25 +- .../Views/{ => Xray}/XrayEditorView.xaml.cs | 5 - .../Views/Xray/XrayInstallView.xaml | 69 +++ .../Views/{ => Xray}/XrayInstallView.xaml.cs | 0 .../Views/{ => Xray}/XrayInstallerView.xaml | 0 .../{ => Xray}/XrayInstallerView.xaml.cs | 0 ProxySuper.WPF/Views/XrayInstallView.xaml | 38 -- 58 files changed, 1793 insertions(+), 155 deletions(-) create mode 100644 ProxySuper.Core/Services/BrookService.cs create mode 100644 ProxySuper.Core/Services/NaiveProxyService.cs create mode 100644 ProxySuper.Core/Services/TrojanGoService.cs create mode 100644 ProxySuper.Core/ViewModels/BrookInstallViewModel.cs create mode 100644 ProxySuper.Core/ViewModels/NaiveProxyInstallViewModel.cs create mode 100644 ProxySuper.Core/ViewModels/TrojanGoInstallViewModel.cs rename ProxySuper.WPF/Views/{ => Brook}/BrookConfigView.xaml (100%) rename ProxySuper.WPF/Views/{ => Brook}/BrookConfigView.xaml.cs (100%) rename ProxySuper.WPF/Views/{ => Brook}/BrookEditorView.xaml (100%) rename ProxySuper.WPF/Views/{ => Brook}/BrookEditorView.xaml.cs (100%) create mode 100644 ProxySuper.WPF/Views/Brook/BrookInstallView.xaml create mode 100644 ProxySuper.WPF/Views/Brook/BrookInstallView.xaml.cs rename ProxySuper.WPF/Views/{ => Brook}/BrookInstallerView.xaml (100%) rename ProxySuper.WPF/Views/{ => Brook}/BrookInstallerView.xaml.cs (100%) rename ProxySuper.WPF/Views/{ => NaiveProxy}/NaiveProxyConfigView.xaml (100%) rename ProxySuper.WPF/Views/{ => NaiveProxy}/NaiveProxyConfigView.xaml.cs (100%) rename ProxySuper.WPF/Views/{ => NaiveProxy}/NaiveProxyEditorView.xaml (100%) rename ProxySuper.WPF/Views/{ => NaiveProxy}/NaiveProxyEditorView.xaml.cs (100%) create mode 100644 ProxySuper.WPF/Views/NaiveProxy/NaiveProxyInstallView.xaml create mode 100644 ProxySuper.WPF/Views/NaiveProxy/NaiveProxyInstallView.xaml.cs rename ProxySuper.WPF/Views/{ => NaiveProxy}/NaiveProxyInstallerView.xaml (100%) rename ProxySuper.WPF/Views/{ => NaiveProxy}/NaiveProxyInstallerView.xaml.cs (100%) rename ProxySuper.WPF/Views/{ => TrojanGo}/TrojanGoConfigView.xaml (100%) rename ProxySuper.WPF/Views/{ => TrojanGo}/TrojanGoConfigView.xaml.cs (100%) rename ProxySuper.WPF/Views/{ => TrojanGo}/TrojanGoEditorView.xaml (100%) rename ProxySuper.WPF/Views/{ => TrojanGo}/TrojanGoEditorView.xaml.cs (100%) create mode 100644 ProxySuper.WPF/Views/TrojanGo/TrojanGoInstallView.xaml create mode 100644 ProxySuper.WPF/Views/TrojanGo/TrojanGoInstallView.xaml.cs rename ProxySuper.WPF/Views/{ => TrojanGo}/TrojanGoInstallerView.xaml (100%) rename ProxySuper.WPF/Views/{ => TrojanGo}/TrojanGoInstallerView.xaml.cs (100%) rename ProxySuper.WPF/Views/{ => Xray}/XrayConfigView.xaml (100%) rename ProxySuper.WPF/Views/{ => Xray}/XrayConfigView.xaml.cs (100%) rename ProxySuper.WPF/Views/{ => Xray}/XrayEditorView.xaml (71%) rename ProxySuper.WPF/Views/{ => Xray}/XrayEditorView.xaml.cs (79%) create mode 100644 ProxySuper.WPF/Views/Xray/XrayInstallView.xaml rename ProxySuper.WPF/Views/{ => Xray}/XrayInstallView.xaml.cs (100%) rename ProxySuper.WPF/Views/{ => Xray}/XrayInstallerView.xaml (100%) rename ProxySuper.WPF/Views/{ => Xray}/XrayInstallerView.xaml.cs (100%) delete mode 100644 ProxySuper.WPF/Views/XrayInstallView.xaml diff --git a/ProxySuper.Core/ProxySuper.Core.csproj b/ProxySuper.Core/ProxySuper.Core.csproj index 02c6703..ff82855 100644 --- a/ProxySuper.Core/ProxySuper.Core.csproj +++ b/ProxySuper.Core/ProxySuper.Core.csproj @@ -88,27 +88,33 @@ + + + + + + diff --git a/ProxySuper.Core/Services/BrookService.cs b/ProxySuper.Core/Services/BrookService.cs new file mode 100644 index 0000000..ff75996 --- /dev/null +++ b/ProxySuper.Core/Services/BrookService.cs @@ -0,0 +1,165 @@ +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 BrookService : ServiceBase + { + private string brookServiceTemp = @" + [Unit] + Description=brook service + After=network.target syslog.target + Wants=network.target + + [Service] + Type=simple + ExecStart=##run_cmd## + + [Install] + WantedBy=multi-user.target"; + + + public BrookService(Host host, BrookSettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "安装Brook"; + Progress.Percentage = 0; + + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 40; + + Progress.Desc = "配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 50; + + + Progress.Step = "检测网络环境"; + EnsureNetwork(); + Progress.Percentage = 60; + if (Settings.BrookType == BrookType.wssserver) + { + Progress.Desc = "检测域名是否绑定本机IP"; + ValidateDomain(); + Progress.Percentage = 80; + } + + Progress.Step = "安装Brook服务"; + InstallBrook(); + + Progress.Percentage = 100; + Progress.Step = "安装Brook成功"; + Progress.Desc = "安装Brook成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void InstallBrook() + { + Progress.Desc = "执行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"); + + Progress.Desc = "设置Brook服务"; + var brookService = brookServiceTemp.Replace("##run_cmd##", GetRunBrookCommand()); + + RunCmd("rm -rf /etc/systemd/system/brook.service"); + RunCmd("touch /etc/systemd/system/brook.service"); + RunCmd($"echo \"{brookService}\" > /etc/systemd/system/brook.service"); + RunCmd("sudo chmod 777 /etc/systemd/system/brook.service"); + + Progress.Desc = "启动Brook服务"; + RunCmd("systemctl enable brook"); + RunCmd("systemctl restart brook"); + } + + private string GetRunBrookCommand() + { + var runBrookCmd = string.Empty; + + if (Settings.BrookType == BrookType.server) + { + return $"/usr/bin/brook server --listen :{Settings.Port} --password {Settings.Password}"; + } + + if (Settings.BrookType == BrookType.wsserver) + { + return $"/usr/bin/brook wsserver --listen :{Settings.Port} --password {Settings.Password}"; + } + + if (Settings.BrookType == BrookType.wssserver) + { + return $"/usr/bin/brook wssserver --domain {Settings.Domain} --password {Settings.Password}"; + } + + if (Settings.BrookType == BrookType.socks5) + { + var ip = IsOnlyIPv6 ? IPv6 : IPv4; + return $"/usr/bin/brook socks5 --socks5 {ip}:{Settings.Port}"; + } + + return runBrookCmd; + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "卸载Brook"; + Progress.Percentage = 0; + + Progress.Desc = "停止Brook服务"; + RunCmd("systemctl stop brook"); + RunCmd("systemctl disable brook"); + Progress.Percentage = 30; + + Progress.Desc = "删除Brook相关文件"; + RunCmd("rm -rf /etc/systemd/system/brook.service"); + RunCmd("rm -rf /usr/bin/brook"); + Progress.Percentage = 80; + + Progress.Desc = "重置防火墙设置"; + ResetFirewalld(); + + Progress.Percentage = 100; + Progress.Desc = "卸载完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + } +} diff --git a/ProxySuper.Core/Services/NaiveProxyService.cs b/ProxySuper.Core/Services/NaiveProxyService.cs new file mode 100644 index 0000000..af201e1 --- /dev/null +++ b/ProxySuper.Core/Services/NaiveProxyService.cs @@ -0,0 +1,271 @@ +using Microsoft.Win32; +using MvvmCross.ViewModels; +using ProxySuper.Core.Models; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class NaiveProxyService : ServiceBase + { + public NaiveProxyService(Host host, NaiveProxySettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + var index = 1; + + Progress.Step = $"{index++}. 检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Step = $"{index++}. 安装系统必要工具"; + InstallSystemTools(); + Progress.Percentage = 30; + + Progress.Step = $"{index++}. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 40; + + Progress.Step = $"{index++}. 检测网络环境"; + EnsureNetwork(); + Progress.Percentage = 50; + + Progress.Step = $"{index++}. 检测域名是否绑定到本机"; + ValidateDomain(); + Progress.Percentage = 60; + + Progress.Step = $"{index++}. 安装NaiveProxy"; + InstallNaiveProxy(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 优化网络参数"; + ConfigNetwork(); + Progress.Percentage = 90; + + Progress.Step = $"{index++}. 启动BBR"; + EnableBBR(); + + Progress.Percentage = 100; + Progress.Step = "NaiveProxy安装成功"; + Progress.Desc = "NaiveProxy安装成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "卸载NaiveProxy"; + Progress.Percentage = 0; + + Progress.Desc = "正在卸载..."; + RunCmd("rm -rf caddy_install.sh"); + Progress.Percentage = 10; + + RunCmd("curl -o caddy_install.sh https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh"); + Progress.Percentage = 20; + + RunCmd("yes | bash caddy_install.sh uninstall"); + Progress.Percentage = 80; + + RunCmd("rm -rf caddy_install.sh"); + Progress.Percentage = 100; + Progress.Step = "卸载NaiveProxy成功"; + Progress.Desc = "卸载NaiveProxy成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateSettings() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新配置"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 30; + + UploadCaddySettings(); + Progress.Percentage = 100; + + Progress.Step = "更新配置成功"; + Progress.Desc = "更新配置成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UploadWeb() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadWeb; + fileDialog.ShowDialog(); + } + + + #region 似有方法 + + private void DoUploadWeb(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "上传静态网站"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "创建网站目录"; + if (!FileExists("/usr/share/caddy")) + { + RunCmd("mkdir /usr/share/caddy"); + } + RunCmd("rm -rf /usr/share/caddy/*"); + Progress.Percentage = 40; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + UploadFile(stream, "/usr/share/caddy/caddy.zip"); + RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); + RunCmd("chmod -R 777 /usr/share/caddy"); + Progress.Percentage = 700; + } + + Progress.Desc = "上传Caddy配置文件"; + UploadCaddySettings(); + + Progress.Percentage = 100; + Progress.Desc = "上传静态网站成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void InstallNaiveProxy() + { + Progress.Desc = "下载NaiveProxy安装文件"; + RunCmd(@"curl https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh yes | bash"); + + Progress.Desc = "设置NaiveProxy开机启动"; + RunCmd("systemctl enable caddy"); + + Progress.Desc = "上传配置文件"; + UploadCaddySettings(false); + } + + private void ConfigNetwork() + { + RunCmd(@"bash -c 'echo ""fs.file-max = 51200"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.rmem_max = 67108864"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.wmem_max = 67108864"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.rmem_default = 65536"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.wmem_default = 65536"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.netdev_max_backlog = 4096"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.core.somaxconn = 4096"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_syncookies = 1"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_tw_reuse = 1"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_tw_recycle = 0"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_fin_timeout = 30"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_keepalive_time = 1200"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.ip_local_port_range = 10000 65000"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_max_syn_backlog = 4096"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_max_tw_buckets = 5000"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_rmem = 4096 87380 67108864"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_wmem = 4096 65536 67108864"" >> /etc/sysctl.conf'"); + RunCmd(@"bash -c 'echo ""net.ipv4.tcp_mtu_probing = 1"" >> /etc/sysctl.conf'"); + RunCmd(@"sysctl -p"); + } + + private void UploadCaddySettings(bool useCustomWeb = false) + { + Progress.Desc = "生成配置文件"; + var caddyStr = BuildConfig(useCustomWeb); + + if (FileExists("/etc/caddy/Caddyfile")) + { + RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); + } + + Progress.Desc = "上传配置文件"; + WriteToFile(caddyStr, "/etc/caddy/Caddyfile"); + + Progress.Desc = "重启Caddy服务"; + RunCmd("systemctl restart caddy"); + } + + private string BuildConfig(bool useCustomWeb = false) + { + var jsonStr = File.ReadAllText("Templates/NaiveProxy/naive_server.caddyfile"); + jsonStr = jsonStr.Replace("##port##", Settings.Port.ToString()); + jsonStr = jsonStr.Replace("##domain##", Settings.Domain); + jsonStr = jsonStr.Replace("##basicauth##", $"basic_auth {Settings.UserName} {Settings.Password}"); + + if (!useCustomWeb && !string.IsNullOrEmpty(Settings.MaskDomain)) + { + var prefix = "http://"; + if (Settings.MaskDomain.StartsWith("https://")) + { + prefix = "https://"; + } + var domain = Settings.MaskDomain + .TrimStart("http://".ToCharArray()) + .TrimStart("https://".ToCharArray()); + + jsonStr = jsonStr.Replace("##reverse_proxy##", $"reverse_proxy {prefix}{domain} {{ \n header_up Host {domain} \n }}"); + } + else + { + jsonStr = jsonStr.Replace("##reverse_proxy##", ""); + jsonStr = jsonStr.Replace("#file_server", "file_server"); + } + return jsonStr; + } + + #endregion + } +} diff --git a/ProxySuper.Core/Services/ServiceBase.cs b/ProxySuper.Core/Services/ServiceBase.cs index 3d9aad7..9804184 100644 --- a/ProxySuper.Core/Services/ServiceBase.cs +++ b/ProxySuper.Core/Services/ServiceBase.cs @@ -277,15 +277,41 @@ namespace ProxySuper.Core.Services RunCmd($"chmod 755 {dirPath}"); } + protected void UploadFile(Stream stream, string path) + { + using (var sftp = new SftpClient(_sshClient.ConnectionInfo)) + { + sftp.Connect(); + sftp.UploadFile(stream, path, true); + sftp.Disconnect(); + } + } - public bool IsRootUser() + public void EnsureRootUser() { // 禁止一些可能产生的干扰信息 RunCmd(@"sed -i 's/echo/#echo/g' ~/.bashrc"); RunCmd(@"sed -i 's/echo/#echo/g' ~/.profile"); var result = RunCmd("id -u"); - return result.Equals("0\n"); + if (!result.Equals("0\n")) + { + throw new Exception("ProxySU需要使用Root用户进行安装!"); + } + } + + + public void UninstallCaddy() + { + Progress.Desc = "关闭Caddy服务"; + RunCmd("systemctl stop caddy"); + RunCmd("systemctl disable caddy"); + + Progress.Desc = "彻底删除Caddy文件"; + RunCmd("rm -rf /etc/systemd/system/caddy.service"); + RunCmd("rm -rf /usr/bin/caddy"); + RunCmd("rm -rf /usr/share/caddy"); + RunCmd("rm -rf /etc/caddy"); } public void EnsureSystemEnv() @@ -343,6 +369,11 @@ namespace ProxySuper.Core.Services OpenPort(Settings.FreePorts.ToArray()); } + public void ResetFirewalld() + { + ClosePort(Settings.FreePorts.ToArray()); + } + public void EnsureNetwork() { string cmd; diff --git a/ProxySuper.Core/Services/TrojanGoService.cs b/ProxySuper.Core/Services/TrojanGoService.cs new file mode 100644 index 0000000..8026057 --- /dev/null +++ b/ProxySuper.Core/Services/TrojanGoService.cs @@ -0,0 +1,369 @@ +using Microsoft.Win32; +using ProxySuper.Core.Models.Hosts; +using ProxySuper.Core.Models.Projects; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class TrojanGoService : ServiceBase + { + public TrojanGoService(Host host, TrojanGoSettings settings) : base(host, settings) + { + } + + public void Install() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "安装TrojanGo"; + Progress.Desc = "安装TrojanGo"; + EnsureRootUser(); + + if (FileExists("/usr/local/bin/trojan-go")) + { + var btnResult = MessageBox.Show("已经安装Trojan-Go,是否需要重装?", "提示", MessageBoxButton.YesNo); + if (btnResult == MessageBoxResult.No) + { + MessageBox.Show("安装终止", "提示"); + return; + } + } + + var index = 1; + Progress.Step = $"{index++}. 检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 10; + + Progress.Step = $"{index++}. 安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 30; + + Progress.Step = $"{index++}. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 40; + + Progress.Step = $"{index++}. 检测网络环境"; + EnsureNetwork(); + Progress.Percentage = 50; + + Progress.Step = $"{index++}. 检测域名是否解析到本机"; + ValidateDomain(); + Progress.Percentage = 60; + + Progress.Step = $"{index++}. 安装Caddy服务"; + InstallCaddy(); + Progress.Percentage = 70; + + Progress.Step = $"{index++}. 安装TrojanGo"; + InstallTrojanGo(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 上传Caddy配置文件"; + UploadCaddySettings(); + Progress.Percentage = 90; + + + Progress.Step = $"{index++}. 启动BBR"; + EnableBBR(); + + Progress.Percentage = 100; + Progress.Step = "安装成功"; + Progress.Desc = "安装成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "卸载Trojgan-Go"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "停止Trojan—Go服务"; + RunCmd("systemctl stop trojan-go"); + Progress.Percentage = 40; + + + Progress.Desc = "卸载Caddy"; + UninstallCaddy(); + Progress.Percentage = 60; + + Progress.Desc = "卸载Trojan-Go"; + RunCmd("rm -rf /usr/local/bin/trojan-go"); + RunCmd("rm -rf /usr/local/etc/trojan-go"); + Progress.Percentage = 90; + + Progress.Desc = "删除 acme.sh"; + RunCmd("acme.sh --uninstall"); + RunCmd("rm -r ~/.acme.sh"); + + Progress.Percentage = 100; + Progress.Step = "卸载Trojan-Go成功"; + Progress.Desc = "卸载Trojan-Go成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateSettings() + { + Progress.Step = "更新配置文件"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureRootUser(); + EnsureSystemEnv(); + Progress.Percentage = 30; + + Progress.Desc = "更新配置文件"; + UploadTrojanGoSettings(); + + Progress.Percentage = 100; + Progress.Step = "更新配置成功"; + Progress.Desc = "更新配置成功"; + } + + public void UploadWeb() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadWeb; + fileDialog.ShowDialog(); + } + + public void UploadCert() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadCert; + fileDialog.ShowDialog(); + } + + public void ApplyForCert() + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "续签证书"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "安装TLS证书"; + InstallCert( + dirPath: "/usr/local/etc/trojan-go", + certName: "trojan-go.crt", + keyName: "trojan-go.key"); + Progress.Percentage = 90; + + Progress.Desc = "重启Trojan-go服务"; + RunCmd("systemctl restart trojan-go"); + + Progress.Percentage = 100; + Progress.Step = "续签证书成功"; + Progress.Desc = "续签证书成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + #region 私有方法 + + + private void DoUploadCert(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Percentage = 0; + Progress.Step = "上传自有证书"; + Progress.Desc = "检测系统环境"; + + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + var oldFileName = $"ssl_{DateTime.Now.Ticks}"; + RunCmd($"mv /usr/local/etc/trojan-go/ssl /usr/local/etc/trojan-go/{oldFileName}"); + + RunCmd("mkdir /usr/local/etc/trojan-go/ssl"); + UploadFile(stream, "/usr/local/etc/trojan-go/ssl/ssl.zip"); + RunCmd("unzip /usr/local/etc/trojan-go/ssl/ssl.zip -d /usr/local/etc/trojan-go/ssl"); + } + + var crtFiles = RunCmd("find /usr/local/etc/trojan-go/ssl/*.crt").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + var keyFiles = RunCmd("find /usr/local/etc/trojan-go/ssl/*.key").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + if (crtFiles.Length > 0 && keyFiles.Length > 0) + { + RunCmd($"mv {crtFiles[0]} /usr/local/etc/trojan-go/ssl/trojan-go.crt"); + RunCmd($"mv {keyFiles[0]} /usr/local/etc/trojan-go/ssl/trojan-go.key"); + } + else + { + Progress.Step = "上传失败"; + Progress.Desc = "上传证书失败,缺少 .crt 和 .key 文件"; + return; + } + + Progress.Desc = "重启trojan-go服务"; + RunCmd("systemctl restart trojan-go"); + + Progress.Percentage = 100; + Progress.Desc = "上传证书完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void DoUploadWeb(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "上传静态网站"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "创建网站目录"; + if (!FileExists("/usr/share/caddy")) + { + RunCmd("mkdir /usr/share/caddy"); + } + RunCmd("rm -rf /usr/share/caddy/*"); + Progress.Percentage = 40; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + UploadFile(stream, "/usr/share/caddy/caddy.zip"); + RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); + RunCmd("chmod -R 777 /usr/share/caddy"); + Progress.Percentage = 700; + } + + Progress.Desc = "上传Caddy配置文件"; + UploadCaddySettings(); + + Progress.Percentage = 100; + Progress.Desc = "上传静态网站成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void UploadCaddySettings(bool useCustomWeb = false) + { + var config = TrojanGoConfigBuilder.BuildCaddyConfig(Settings, useCustomWeb); + var stream = new MemoryStream(Encoding.UTF8.GetBytes(config)); + if (FileExists("/etc/caddy/Caddyfile")) + { + RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); + } + UploadFile(stream, "/etc/caddy/Caddyfile"); + RunCmd("systemctl restart caddy"); + } + + private void InstallTrojanGo() + { + RunCmd(@"curl https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh yes | bash"); + var success = FileExists("/usr/local/bin/trojan-go"); + if (success == false) + { + throw new Exception("trojan-go 安装失败,请联系开发者!"); + } + + Progress.Desc = "设置Trojan-Go权限"; + RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"systemctl daemon-reload"); + + Progress.Desc = "启用Trojan-Go开机启动"; + RunCmd("systemctl enable trojan-go"); + RunCmd("systemctl start trojan-go"); + + Progress.Desc = "Trojan-Go 安装完成"; + + Progress.Desc = "安装TLS证书"; + InstallCert( + dirPath: "/usr/local/etc/trojan-go", + certName: "trojan-go.crt", + keyName: "trojan-go.key"); + + + Progress.Desc = "上传Trojan-Go配置文件"; + UploadTrojanGoSettings(); + } + + private void UploadTrojanGoSettings() + { + // 上传配置 + Progress.Desc = "生成配置文件"; + var settings = TrojanGoConfigBuilder.BuildTrojanGoConfig(Settings); + var stream = new MemoryStream(Encoding.UTF8.GetBytes(settings)); + + Progress.Desc = "正在上传配置文件"; + UploadFile(stream, "/usr/local/etc/trojan-go/config.json"); + + Progress.Desc = "重启Trojan-Go服务器"; + RunCmd("systemctl restart trojan-go"); + } + + #endregion + + + } +} diff --git a/ProxySuper.Core/Services/XrayService.cs b/ProxySuper.Core/Services/XrayService.cs index 68df0b5..85b06b5 100644 --- a/ProxySuper.Core/Services/XrayService.cs +++ b/ProxySuper.Core/Services/XrayService.cs @@ -1,8 +1,10 @@ -using ProxySuper.Core.Helpers; +using Microsoft.Win32; +using ProxySuper.Core.Helpers; using ProxySuper.Core.Models.Hosts; using ProxySuper.Core.Models.Projects; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -19,61 +21,338 @@ namespace ProxySuper.Core.Services public void Install() { - Task.Run(() => + Task.Factory.StartNew(() => { - int index = 1; - if (!IsRootUser()) + try { - MessageBox.Show("ProxySU需要使用Root用户进行安装!"); - return; + int index = 1; + EnsureRootUser(); + + if (FileExists("/usr/local/bin/xray")) + { + var btnResult = MessageBox.Show("已经安装Xray,是否需要重装?", "提示", MessageBoxButton.YesNo); + if (btnResult == MessageBoxResult.No) + { + MessageBox.Show("安装终止", "提示"); + return; + } + } + + Progress.Step = $"{index++}. 检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 5; + + Progress.Step = $"{index++}. 安装必要的系统工具"; + InstallSystemTools(); + Progress.Percentage = 15; + + Progress.Step = $"{index++}. 配置防火墙"; + ConfigFirewalld(); + Progress.Percentage = 20; + + Progress.Step = $"{index++}. 检测网络环境"; + EnsureNetwork(); + if (Settings.IsIPAddress) + { + Progress.Desc = ("检查域名是否解析正确"); + ValidateDomain(); + } + Progress.Percentage = 25; + + Progress.Step = $"{index}. 同步系统和本地时间"; + SyncTimeDiff(); + Progress.Percentage = 30; + + Progress.Step = $"{index++}. 安装Caddy服务器"; + InstallCaddy(); + Progress.Percentage = 50; + + Progress.Step = $"{index++}. 安装Xray-Core"; + InstallXray(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 上传Web服务器配置"; + UploadCaddyFile(); + Progress.Percentage = 90; + + Progress.Step = $"{index++}. 启动BBR"; + EnableBBR(); + + Progress.Percentage = 100; + Progress.Step = "安装成功"; + Progress.Desc = "安装成功"; } - - Progress.Step = $"{index++}. 检测系统环境"; - EnsureSystemEnv(); - Progress.Percentage = 5; - - Progress.Step = $"{index++}. 安装必要的系统工具"; - InstallSystemTools(); - Progress.Percentage = 15; - - Progress.Step = $"{index++}. 配置防火墙"; - ConfigFirewalld(); - Progress.Percentage = 20; - - Progress.Step = $"{index++}. 检测网络环境"; - EnsureNetwork(); - if (Settings.IsIPAddress) + catch (Exception ex) { - Progress.Desc = ("检查域名是否解析正确"); - ValidateDomain(); + MessageBox.Show(ex.Message); } - Progress.Percentage = 25; - - Progress.Step = $"{index}. 同步系统和本地时间"; - SyncTimeDiff(); - Progress.Percentage = 30; - - Progress.Step = $"{index++}. 安装Caddy服务器"; - InstallCaddy(); - Progress.Percentage = 50; - - Progress.Step = $"{index++}. 安装Xray-Core"; - InstallXray(); - Progress.Percentage = 80; - - Progress.Step = $"{index++}. 上传Web服务器配置"; - UploadCaddyFile(); - Progress.Percentage = 90; - - Progress.Step = $"{index++}. 启动BBR"; - EnableBBR(); - Progress.Percentage = 100; - - Progress.Desc = ("!!!安装Xray完成!!!"); }); } - public void InstallXray() + public void UpdateSettings() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新Xray配置"; + Progress.Percentage = 0; + EnsureRootUser(); + var index = 0; + + Progress.Desc = $"{index++}. 检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = $"{index++}. 配置防火墙"; + RunCmd("systemctl stop xray"); + RunCmd("systemctl stop caddy"); + ConfigFirewalld(); + Progress.Percentage = 40; + + Progress.Desc = $"{index++}. 上传Xray配置文件"; + var configJson = XrayConfigBuilder.BuildXrayConfig(Settings); + WriteToFile(configJson, "/usr/local/etc/xray/config.json"); + Progress.Percentage = 70; + + Progress.Desc = $"{index++}. 上传Caddy配置文件"; + UploadCaddyFile(); + Progress.Percentage = 90; + + Progress.Desc = $"{index++}. 重启xray服务"; + RunCmd("systemctl restart caddy"); + RunCmd("systemctl restart xray"); + Progress.Percentage = 100; + + Progress.Desc = ("更新配置成功"); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UpdateXrayCore() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Step = "更新Xray-Core"; + Progress.Percentage = 0; + + EnsureRootUser(); + Progress.Percentage = 20; + + Progress.Desc = "下载最新版本Xray-Core"; + EnsureSystemEnv(); + Progress.Percentage = 40; + + RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"); + RunCmd("systemctl restart xray"); + Progress.Percentage = 100; + + Progress.Desc = "更新Xray-Core成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void Uninstall() + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + var index = 1; + Progress.Percentage = 0; + + Progress.Step = $"{index++}. 检测系统环境"; + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Step = $"{index++}. 卸载Caddy服务"; + UninstallCaddy(); + Progress.Percentage = 40; + + Progress.Step = $"{index++}. 卸载Xray服务"; + UninstallXray(); + Progress.Percentage = 60; + + Progress.Step = $"{index++}. 卸载Acme证书申请服务"; + UninstallAcme(); + Progress.Percentage = 80; + + Progress.Step = $"{index++}. 重置防火墙端口"; + ResetFirewalld(); + Progress.Percentage = 100; + + Progress.Step = "卸载完成"; + Progress.Desc = "卸载完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + public void UploadCert() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadCert; + fileDialog.ShowDialog(); + } + + public void UploadWeb() + { + var fileDialog = new OpenFileDialog(); + fileDialog.Filter = "压缩文件|*.zip"; + fileDialog.FileOk += DoUploadWeb; + fileDialog.ShowDialog(); + } + + public void ApplyForCert() + { + Task.Factory.StartNew(() => + { + try + { + Progress.Percentage = 0; + Progress.Step = "续签证书"; + + InstallCert( + dirPath: "/usr/local/etc/xray/ssl", + certName: "xray_ssl.crt", + keyName: "xray_ssl.key"); + + Progress.Percentage = 90; + Progress.Desc = "重启服务"; + RunCmd("systemctl restart xray"); + + Progress.Percentage = 100; + Progress.Desc = "续签证书成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + + #region 似有方法 + + private void DoUploadCert(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Percentage = 0; + Progress.Step = "上传自有证书"; + Progress.Desc = "检测系统环境"; + + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + var oldFileName = $"ssl_{DateTime.Now.Ticks}"; + RunCmd($"mv /usr/local/etc/xray/ssl /usr/local/etc/xray/{oldFileName}"); + + RunCmd("mkdir /usr/local/etc/xray/ssl"); + UploadFile(stream, "/usr/local/etc/xray/ssl/ssl.zip"); + RunCmd("unzip /usr/local/etc/xray/ssl/ssl.zip -d /usr/local/etc/xray/ssl"); + } + + var crtFiles = RunCmd("find /usr/local/etc/xray/ssl/*.crt").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + var keyFiles = RunCmd("find /usr/local/etc/xray/ssl/*.key").Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); + if (crtFiles.Length > 0 && keyFiles.Length > 0) + { + RunCmd($"mv {crtFiles[0]} /usr/local/etc/xray/ssl/xray_ssl.crt"); + RunCmd($"mv {keyFiles[0]} /usr/local/etc/xray/ssl/xray_ssl.key"); + } + else + { + Progress.Step = "上传失败"; + Progress.Desc = "上传证书失败,缺少 .crt 和 .key 文件"; + return; + } + + Progress.Desc = "重启Xray服务"; + RunCmd("systemctl restart xray"); + + Progress.Percentage = 100; + Progress.Desc = "上传证书完成"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void DoUploadWeb(object sender, CancelEventArgs e) + { + Task.Factory.StartNew(() => + { + try + { + EnsureRootUser(); + + Progress.Step = "上传静态网站"; + Progress.Desc = "上传静态网站"; + Progress.Percentage = 0; + + Progress.Desc = "检测系统环境"; + EnsureSystemEnv(); + Progress.Percentage = 20; + + Progress.Desc = "创建网站目录"; + if (!FileExists("/usr/share/caddy")) + { + RunCmd("mkdir /usr/share/caddy"); + } + RunCmd("rm -rf /usr/share/caddy/*"); + Progress.Percentage = 40; + + Progress.Desc = "正在上传文件"; + var file = sender as OpenFileDialog; + using (var stream = file.OpenFile()) + { + UploadFile(stream, "/usr/share/caddy/caddy.zip"); + RunCmd("unzip /usr/share/caddy/caddy.zip -d /usr/share/caddy"); + } + RunCmd("chmod -R 777 /usr/share/caddy"); + Progress.Percentage = 80; + + Progress.Desc = "上传Web配置文件"; + UploadCaddyFile(useCustomWeb: true); + Progress.Percentage = 100; + + Progress.Desc = "上传静态网站成功"; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + }); + } + + private void InstallXray() { Progress.Desc = ("开始安装Xray-Core"); RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"); @@ -123,5 +402,27 @@ namespace ProxySuper.Core.Services WriteToFile(configJson, "/etc/caddy/Caddyfile"); RunCmd("systemctl restart caddy"); } + + + private void UninstallXray() + { + Progress.Desc = "关闭Xray服务"; + RunCmd("systemctl stop xray"); + RunCmd("systemctl disable xray"); + + Progress.Desc = "卸载Xray"; + RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ remove"); + } + + private void UninstallAcme() + { + Progress.Desc = "卸载 acme.sh"; + RunCmd("acme.sh --uninstall"); + + Progress.Desc = "删除 acme.sh 相关文件"; + RunCmd("rm -rf ~/.acme.sh"); + } + + #endregion } } diff --git a/ProxySuper.Core/ViewModels/BrookInstallViewModel.cs b/ProxySuper.Core/ViewModels/BrookInstallViewModel.cs new file mode 100644 index 0000000..3db6f21 --- /dev/null +++ b/ProxySuper.Core/ViewModels/BrookInstallViewModel.cs @@ -0,0 +1,51 @@ +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.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class BrookInstallViewModel : MvxViewModel + { + Host _host; + + BrookSettings _settings; + + BrookService _service; + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.BrookSettings; + } + + public override Task Initialize() + { + _service = new BrookService(_host, _settings); + _service.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _service.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _service.Disconnect(); + base.ViewDestroy(viewFinishing); + } + + public ProjectProgress Progress => _service.Progress; + + public string Logs => _service.Progress.Logs; + + public IMvxCommand InstallCommand => new MvxCommand(_service.Install); + + public IMvxCommand UninstallCommand => new MvxCommand(_service.Uninstall); + } +} diff --git a/ProxySuper.Core/ViewModels/HomeViewModel.cs b/ProxySuper.Core/ViewModels/HomeViewModel.cs index c20cd2a..c6c0839 100644 --- a/ProxySuper.Core/ViewModels/HomeViewModel.cs +++ b/ProxySuper.Core/ViewModels/HomeViewModel.cs @@ -225,15 +225,15 @@ namespace ProxySuper.Core.ViewModels } if (record.Type == ProjectType.TrojanGo) { - await _navigationService.Navigate(record); + await _navigationService.Navigate(record); } if (record.Type == ProjectType.NaiveProxy) { - await _navigationService.Navigate(record); + await _navigationService.Navigate(record); } if (record.Type == ProjectType.Brook) { - await _navigationService.Navigate(record); + await _navigationService.Navigate(record); } } } diff --git a/ProxySuper.Core/ViewModels/NaiveProxyInstallViewModel.cs b/ProxySuper.Core/ViewModels/NaiveProxyInstallViewModel.cs new file mode 100644 index 0000000..ec0777a --- /dev/null +++ b/ProxySuper.Core/ViewModels/NaiveProxyInstallViewModel.cs @@ -0,0 +1,61 @@ +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.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class NaiveProxyInstallViewModel : MvxViewModel + { + Host _host; + + NaiveProxySettings _settings; + + NaiveProxyService _service; + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.NaiveProxySettings; + } + + public override Task Initialize() + { + _service = new NaiveProxyService(_host, _settings); + _service.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _service.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _service.Disconnect(); + base.ViewDestroy(viewFinishing); + } + + + public ProjectProgress Progress => _service.Progress; + + public string Logs => _service.Progress.Logs; + + + #region Commands + + public IMvxCommand InstallCommand => new MvxCommand(_service.Install); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(_service.UpdateSettings); + + public IMvxCommand UninstallCommand => new MvxCommand(_service.Uninstall); + + public IMvxCommand UploadWebCommand => new MvxCommand(_service.UploadWeb); + + #endregion + } +} diff --git a/ProxySuper.Core/ViewModels/TrojanGoInstallViewModel.cs b/ProxySuper.Core/ViewModels/TrojanGoInstallViewModel.cs new file mode 100644 index 0000000..3841aee --- /dev/null +++ b/ProxySuper.Core/ViewModels/TrojanGoInstallViewModel.cs @@ -0,0 +1,71 @@ +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.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProxySuper.Core.ViewModels +{ + public class TrojanGoInstallViewModel : MvxViewModel + { + Host _host; + + TrojanGoSettings _settings; + + TrojanGoService _trojanGoService; + + public override void Prepare(Record parameter) + { + _host = parameter.Host; + _settings = parameter.TrojanGoSettings; + } + + public override Task Initialize() + { + _trojanGoService = new TrojanGoService(_host, _settings); + _trojanGoService.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); + _trojanGoService.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); + _trojanGoService.Connect(); + return base.Initialize(); + } + + public override void ViewDestroy(bool viewFinishing = true) + { + _trojanGoService.Disconnect(); + base.ViewDestroy(viewFinishing); + } + + public ProjectProgress Progress + { + get => _trojanGoService.Progress; + } + + public string Logs + { + get => _trojanGoService.Progress.Logs; + } + + + #region Command + + public IMvxCommand InstallCommand => new MvxCommand(_trojanGoService.Install); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(_trojanGoService.UpdateSettings); + + public IMvxCommand UninstallCommand => new MvxCommand(_trojanGoService.Uninstall); + + public IMvxCommand UploadCertCommand => new MvxCommand(_trojanGoService.UploadCert); + + public IMvxCommand UploadWebCommand => new MvxCommand(_trojanGoService.UploadWeb); + + public IMvxCommand ApplyForCertCommand => new MvxCommand(_trojanGoService.ApplyForCert); + + #endregion + } +} diff --git a/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs b/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs index f34b1a4..66dab9b 100644 --- a/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs +++ b/ProxySuper.Core/ViewModels/XrayEditorViewModel.cs @@ -26,7 +26,9 @@ namespace ProxySuper.Core.ViewModels public XraySettings Settings { get; set; } - public IMvxCommand SaveCommand => new MvxCommand(() => Save()); + public IMvxCommand SaveCommand => new MvxCommand(Save); + + public IMvxCommand SaveAndInstallCommand => new MvxCommand(SaveAndInstall); public IMvxNavigationService NavigationService { get; } @@ -47,6 +49,18 @@ namespace ProxySuper.Core.ViewModels XraySettings = Settings, }); } + + public void SaveAndInstall() + { + var record = new Record() + { + Id = Id, + Host = Host, + XraySettings = Settings, + }; + NavigationService.Close(this, record); + NavigationService.Navigate(record); + } } public partial class XrayEditorViewModel diff --git a/ProxySuper.Core/ViewModels/XrayInstallViewModel.cs b/ProxySuper.Core/ViewModels/XrayInstallViewModel.cs index 69ea300..458667b 100644 --- a/ProxySuper.Core/ViewModels/XrayInstallViewModel.cs +++ b/ProxySuper.Core/ViewModels/XrayInstallViewModel.cs @@ -20,8 +20,6 @@ namespace ProxySuper.Core.ViewModels XrayService _xrayService; - MvxInteraction _refreshLogInteraction = new MvxInteraction(); - public override void ViewDestroy(bool viewFinishing = true) { _xrayService.Disconnect(); @@ -38,11 +36,7 @@ namespace ProxySuper.Core.ViewModels { _xrayService = new XrayService(_host, _settings); _xrayService.Progress.StepUpdate = () => RaisePropertyChanged("Progress"); - _xrayService.Progress.LogsUpdate = () => - { - RaisePropertyChanged("Logs"); - _refreshLogInteraction.Raise(); - }; + _xrayService.Progress.LogsUpdate = () => RaisePropertyChanged("Logs"); _xrayService.Connect(); return base.Initialize(); @@ -58,11 +52,24 @@ namespace ProxySuper.Core.ViewModels get => _xrayService.Progress.Logs; } - public IMvxInteraction LogsInteraction - { - get => _refreshLogInteraction; - } + + + #region Command public IMvxCommand InstallCommand => new MvxCommand(_xrayService.Install); + + public IMvxCommand UpdateSettingsCommand => new MvxCommand(_xrayService.UpdateSettings); + + public IMvxCommand UpdateXrayCoreCommand => new MvxCommand(_xrayService.UpdateXrayCore); + + public IMvxCommand UninstallCommand => new MvxCommand(_xrayService.Uninstall); + + public IMvxCommand UploadCertCommand => new MvxCommand(_xrayService.UploadCert); + + public IMvxCommand UploadWebCommand => new MvxCommand(_xrayService.UploadWeb); + + public IMvxCommand ApplyForCertCommand => new MvxCommand(_xrayService.ApplyForCert); + + #endregion } } diff --git a/ProxySuper.WPF/Controls/VLESS_KCP_Control.xaml b/ProxySuper.WPF/Controls/VLESS_KCP_Control.xaml index c9630f5..de8eb9d 100644 --- a/ProxySuper.WPF/Controls/VLESS_KCP_Control.xaml +++ b/ProxySuper.WPF/Controls/VLESS_KCP_Control.xaml @@ -37,7 +37,7 @@ - diff --git a/ProxySuper.WPF/Controls/VLESS_TCP_TLS_Control.xaml b/ProxySuper.WPF/Controls/VLESS_TCP_TLS_Control.xaml index 6328d5a..2a738b9 100644 --- a/ProxySuper.WPF/Controls/VLESS_TCP_TLS_Control.xaml +++ b/ProxySuper.WPF/Controls/VLESS_TCP_TLS_Control.xaml @@ -42,7 +42,7 @@ - diff --git a/ProxySuper.WPF/Controls/VLESS_WS_TLS_Control.xaml b/ProxySuper.WPF/Controls/VLESS_WS_TLS_Control.xaml index 1bde58e..815c24d 100644 --- a/ProxySuper.WPF/Controls/VLESS_WS_TLS_Control.xaml +++ b/ProxySuper.WPF/Controls/VLESS_WS_TLS_Control.xaml @@ -42,7 +42,7 @@ - diff --git a/ProxySuper.WPF/Controls/VLESS_XTLS_Control.xaml b/ProxySuper.WPF/Controls/VLESS_XTLS_Control.xaml index 971d8cd..902dcf1 100644 --- a/ProxySuper.WPF/Controls/VLESS_XTLS_Control.xaml +++ b/ProxySuper.WPF/Controls/VLESS_XTLS_Control.xaml @@ -42,7 +42,7 @@ - diff --git a/ProxySuper.WPF/Controls/VLESS_gRPC_Control.xaml b/ProxySuper.WPF/Controls/VLESS_gRPC_Control.xaml index 42cf4d2..b5ee23a 100644 --- a/ProxySuper.WPF/Controls/VLESS_gRPC_Control.xaml +++ b/ProxySuper.WPF/Controls/VLESS_gRPC_Control.xaml @@ -42,7 +42,7 @@ - diff --git a/ProxySuper.WPF/Controls/VMESS_KCP_Control.xaml b/ProxySuper.WPF/Controls/VMESS_KCP_Control.xaml index 4fbf0e0..69c09a0 100644 --- a/ProxySuper.WPF/Controls/VMESS_KCP_Control.xaml +++ b/ProxySuper.WPF/Controls/VMESS_KCP_Control.xaml @@ -37,7 +37,7 @@ - diff --git a/ProxySuper.WPF/Controls/VMESS_TCP_TLS_Control.xaml b/ProxySuper.WPF/Controls/VMESS_TCP_TLS_Control.xaml index 1747181..d58ebac 100644 --- a/ProxySuper.WPF/Controls/VMESS_TCP_TLS_Control.xaml +++ b/ProxySuper.WPF/Controls/VMESS_TCP_TLS_Control.xaml @@ -37,7 +37,7 @@ - diff --git a/ProxySuper.WPF/Controls/VMESS_WS_TLS_Control.xaml b/ProxySuper.WPF/Controls/VMESS_WS_TLS_Control.xaml index 7e885f7..09e11ca 100644 --- a/ProxySuper.WPF/Controls/VMESS_WS_TLS_Control.xaml +++ b/ProxySuper.WPF/Controls/VMESS_WS_TLS_Control.xaml @@ -37,7 +37,7 @@ - diff --git a/ProxySuper.WPF/ProxySuper.WPF.csproj b/ProxySuper.WPF/ProxySuper.WPF.csproj index a91f06c..3566273 100644 --- a/ProxySuper.WPF/ProxySuper.WPF.csproj +++ b/ProxySuper.WPF/ProxySuper.WPF.csproj @@ -117,52 +117,61 @@ MainWindow.xaml - + BrookConfigView.xaml - + BrookEditorView.xaml - + BrookInstallerView.xaml + + BrookInstallView.xaml + EnableRootView.xaml HomeView.xaml - + NaiveProxyConfigView.xaml - + NaiveProxyEditorView.xaml - + NaiveProxyInstallerView.xaml + + NaiveProxyInstallView.xaml + ShareLinkView.xaml - + TrojanGoConfigView.xaml - + TrojanGoEditorView.xaml - + TrojanGoInstallerView.xaml - + + TrojanGoInstallView.xaml + + XrayEditorView.xaml - + XrayConfigView.xaml - + XrayInstallerView.xaml - + XrayInstallView.xaml @@ -226,15 +235,19 @@ MSBuild:Compile PreserveNewest - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + + Designer + MSBuild:Compile + + Designer MSBuild:Compile @@ -265,15 +278,19 @@ MSBuild:Compile PreserveNewest - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + + Designer + MSBuild:Compile + + Designer MSBuild:Compile @@ -281,31 +298,35 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + 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 87d9958..72caa31 100644 --- a/ProxySuper.WPF/Resources/Languages/en.xaml +++ b/ProxySuper.WPF/Resources/Languages/en.xaml @@ -5,6 +5,7 @@ Random Save + Save And Install SaveAs Install Settings @@ -74,7 +75,7 @@ Trojan over TCP with TLS Trojan Domain/IP - GuiseHost + Redir Url UUID Multi User Multi Id split with "," diff --git a/ProxySuper.WPF/Resources/Languages/tw_cn.xaml b/ProxySuper.WPF/Resources/Languages/tw_cn.xaml index 53ff51e..abc5371 100644 --- a/ProxySuper.WPF/Resources/Languages/tw_cn.xaml +++ b/ProxySuper.WPF/Resources/Languages/tw_cn.xaml @@ -5,6 +5,7 @@ 隨機 保存 + 保存并安裝 另存為 安裝 配置 @@ -73,7 +74,7 @@ 域名/IP - 偽裝域名 + 偽裝網址 UUID 多用戶 多個UUID用“,”分隔 diff --git a/ProxySuper.WPF/Resources/Languages/zh_cn.xaml b/ProxySuper.WPF/Resources/Languages/zh_cn.xaml index dbe87b5..7b39651 100644 --- a/ProxySuper.WPF/Resources/Languages/zh_cn.xaml +++ b/ProxySuper.WPF/Resources/Languages/zh_cn.xaml @@ -5,6 +5,7 @@ 随机 保存 + 保存并安装 另存为 安装 配置 @@ -74,7 +75,7 @@ 域名/IP - 伪装域名 + 伪装网址 UUID 多用户 多个UUID用“,”分隔 diff --git a/ProxySuper.WPF/Views/BrookConfigView.xaml b/ProxySuper.WPF/Views/Brook/BrookConfigView.xaml similarity index 100% rename from ProxySuper.WPF/Views/BrookConfigView.xaml rename to ProxySuper.WPF/Views/Brook/BrookConfigView.xaml diff --git a/ProxySuper.WPF/Views/BrookConfigView.xaml.cs b/ProxySuper.WPF/Views/Brook/BrookConfigView.xaml.cs similarity index 100% rename from ProxySuper.WPF/Views/BrookConfigView.xaml.cs rename to ProxySuper.WPF/Views/Brook/BrookConfigView.xaml.cs diff --git a/ProxySuper.WPF/Views/BrookEditorView.xaml b/ProxySuper.WPF/Views/Brook/BrookEditorView.xaml similarity index 100% rename from ProxySuper.WPF/Views/BrookEditorView.xaml rename to ProxySuper.WPF/Views/Brook/BrookEditorView.xaml diff --git a/ProxySuper.WPF/Views/BrookEditorView.xaml.cs b/ProxySuper.WPF/Views/Brook/BrookEditorView.xaml.cs similarity index 100% rename from ProxySuper.WPF/Views/BrookEditorView.xaml.cs rename to ProxySuper.WPF/Views/Brook/BrookEditorView.xaml.cs diff --git a/ProxySuper.WPF/Views/Brook/BrookInstallView.xaml b/ProxySuper.WPF/Views/Brook/BrookInstallView.xaml new file mode 100644 index 0000000..4a9cf13 --- /dev/null +++ b/ProxySuper.WPF/Views/Brook/BrookInstallView.xaml @@ -0,0 +1,29 @@ + + + + + +