From 14401058dc3b377ea52d9ca08a3ff09fcda383c5 Mon Sep 17 00:00:00 2001 From: next-autumn Date: Thu, 11 Mar 2021 12:05:50 +0800 Subject: [PATCH] merge --- .../ViewModels/Developers/ConfigBuilder.cs | 6 ++--- ProxySU_Core/ViewModels/Developers/Project.cs | 6 ++--- .../ViewModels/Developers/XrayProject.cs | 11 ++++----- ProxySU_Core/ViewModels/Terminal.cs | 23 +------------------ ProxySU_Core/Views/TerminalWindow.xaml | 12 ++++------ ProxySU_Core/Views/TerminalWindow.xaml.cs | 14 +++++++---- 6 files changed, 25 insertions(+), 47 deletions(-) diff --git a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs b/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs index e375ad7..9efa562 100644 --- a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs +++ b/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs @@ -60,13 +60,13 @@ namespace ProxySU_Core.ViewModels.Developers }; } - public static string BuildCaddyConfig(XraySettings parameters) + public static string BuildCaddyConfig(XraySettings parameters, bool useCustomWeb = false) { var caddyStr = File.ReadAllText(Path.Combine(CaddyFileDir, "base.caddyfile")); caddyStr = caddyStr.Replace("##domain##", parameters.Domain); - if (!string.IsNullOrEmpty(parameters.MaskDomain)) + if (!useCustomWeb && !string.IsNullOrEmpty(parameters.MaskDomain)) { - caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy http://{parameters.MaskDomain} {{ header_up Host {parameters.MaskDomain} }}"); + caddyStr = caddyStr.Replace("##reverse_proxy##", $"reverse_proxy {parameters.MaskDomain} {{ header_up Host {parameters.MaskDomain} }}"); } else { diff --git a/ProxySU_Core/ViewModels/Developers/Project.cs b/ProxySU_Core/ViewModels/Developers/Project.cs index 8b78a5e..a989bec 100644 --- a/ProxySU_Core/ViewModels/Developers/Project.cs +++ b/ProxySU_Core/ViewModels/Developers/Project.cs @@ -553,15 +553,15 @@ namespace ProxySU_Core.ViewModels.Developers { if (CmdType == CmdType.Apt) { - return "apt-get install " + soft; + return "echo y | apt-get install " + soft; } else if (CmdType == CmdType.Dnf) { - return "dnf -y install " + soft; + return "echo y | dnf -y install " + soft; } else if (CmdType == CmdType.Yum) { - return "yum -y install " + soft; + return "echo y | yum -y install " + soft; } throw new Exception("未识别的系统"); diff --git a/ProxySU_Core/ViewModels/Developers/XrayProject.cs b/ProxySU_Core/ViewModels/Developers/XrayProject.cs index 17900f1..f4ee4da 100644 --- a/ProxySU_Core/ViewModels/Developers/XrayProject.cs +++ b/ProxySU_Core/ViewModels/Developers/XrayProject.cs @@ -52,10 +52,9 @@ namespace ProxySU_Core.ViewModels.Developers 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"); + UploadCaddyFile(useCustomWeb: true); RunCmd("systemctl restart caddy"); - WriteOutput("************"); - WriteOutput("上传网站模板完成"); - WriteOutput("************"); + WriteOutput("************\n上传网站模板完成\n************"); } public void ReinstallCaddy() @@ -133,9 +132,9 @@ namespace ProxySU_Core.ViewModels.Developers } } - private void UploadCaddyFile() + private void UploadCaddyFile(bool useCustomWeb = false) { - var configJson = ConfigBuilder.BuildCaddyConfig(Parameters); + var configJson = ConfigBuilder.BuildCaddyConfig(Parameters, useCustomWeb); var stream = new MemoryStream(Encoding.UTF8.GetBytes(configJson)); RunCmd("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.back"); UploadFile(stream, "/etc/caddy/Caddyfile"); @@ -179,7 +178,7 @@ namespace ProxySU_Core.ViewModels.Developers RunCmd(GetInstallCmd("socat")); // 解决搬瓦工CentOS缺少问题 - RunCmd("echo y | " + GetInstallCmd("automake autoconf libtool")); + RunCmd(GetInstallCmd("automake autoconf libtool")); // 安装Acme var result = RunCmd($"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | sh -s -- --install-online -m {GetRandomEmail()}"); diff --git a/ProxySU_Core/ViewModels/Terminal.cs b/ProxySU_Core/ViewModels/Terminal.cs index 942edc5..1f2a92a 100644 --- a/ProxySU_Core/ViewModels/Terminal.cs +++ b/ProxySU_Core/ViewModels/Terminal.cs @@ -8,7 +8,6 @@ namespace ProxySU_Core.ViewModels { public class Terminal : BaseViewModel { - private string outputText; private bool hasConnected; public Terminal(Host host) @@ -34,26 +33,6 @@ namespace ProxySU_Core.ViewModels public string CommandText { get; set; } - public string OutputText - { - get => outputText; - } - - public void ClearOutput() - { - outputText = ""; - Notify("OutputText"); - } - - public void AddOutput(string text) - { - outputText += text; - - if (!text.EndsWith("\n")) - { - outputText += "\n"; - } - Notify("OutputText"); - } + public string OutputText { get; set; } } } diff --git a/ProxySU_Core/Views/TerminalWindow.xaml b/ProxySU_Core/Views/TerminalWindow.xaml index 1bfd9f3..08468b0 100644 --- a/ProxySU_Core/Views/TerminalWindow.xaml +++ b/ProxySU_Core/Views/TerminalWindow.xaml @@ -8,20 +8,16 @@ mc:Ignorable="d" Title="主机控制台" Height="500" Width="800"> - - - - - - - + Height="320" + Text="{Binding Path=OutputText}" + /> { try @@ -108,17 +108,21 @@ namespace ProxySU_Core var conneInfo = CreateConnectionInfo(host); _sshClient = new SshClient(conneInfo); _sshClient.Connect(); - _vm.AddOutput("Connected"); + WriteOutput("Connected"); _vm.HasConnected = true; - project = new XrayProject(_sshClient, Record.Settings, WriteShell); + project = new XrayProject(_sshClient, Record.Settings, WriteOutput); } - private void WriteShell(string outShell) + private void WriteOutput(string outShell) { - _vm.AddOutput(outShell); + if (!outShell.EndsWith("\n")) + { + outShell += "\n"; + } Dispatcher.Invoke(() => { + OutputTextBox.AppendText(outShell); OutputTextBox.ScrollToEnd(); }); }