From 816c304249c8417449c17cfa678edc522f3176ec Mon Sep 17 00:00:00 2001 From: next-autumn Date: Tue, 9 Mar 2021 17:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AE=89=E8=A3=85=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxySU_Core/ViewModels/Developers/Project.cs | 10 +- .../ViewModels/Developers/XrayProject.cs | 46 ++- ProxySU_Core/ViewModels/Terminal.cs | 15 + ProxySU_Core/Views/ClientInfoWindow.xaml | 306 +++++++++++++++++- ProxySU_Core/Views/ClientInfoWindow.xaml.cs | 8 +- ProxySU_Core/Views/RecordEditorWindow.xaml | 2 +- ProxySU_Core/Views/TerminalWindow.xaml | 39 ++- ProxySU_Core/Views/TerminalWindow.xaml.cs | 46 ++- 8 files changed, 448 insertions(+), 24 deletions(-) diff --git a/ProxySU_Core/ViewModels/Developers/Project.cs b/ProxySU_Core/ViewModels/Developers/Project.cs index 5c24a10..dc6cce5 100644 --- a/ProxySU_Core/ViewModels/Developers/Project.cs +++ b/ProxySU_Core/ViewModels/Developers/Project.cs @@ -156,8 +156,14 @@ namespace ProxySU_Core.ViewModels.Developers /// protected void ConfigureSoftware() { + string cmd = RunCmd("command -v sudo"); + if (string.IsNullOrEmpty(cmd)) + { + RunCmd(GetInstallCmd("sudo")); + } + // 安装curl,wget,unzip - string cmd = RunCmd("command -v curl"); + cmd = RunCmd("command -v curl"); if (string.IsNullOrEmpty(cmd)) { RunCmd(GetInstallCmd("curl")); @@ -399,7 +405,7 @@ namespace ProxySU_Core.ViewModels.Developers { if (force) { - var btnResult = MessageBox.Show("80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序?", "提示", MessageBoxButton.YesNo); + var btnResult = MessageBox.Show($"{port}端口被占用,将强制停止占用{port}端口的程序?", "提示", MessageBoxButton.YesNo); if (btnResult == MessageBoxResult.No) { throw new Exception($"{port}端口被占用,安装停止!"); diff --git a/ProxySU_Core/ViewModels/Developers/XrayProject.cs b/ProxySU_Core/ViewModels/Developers/XrayProject.cs index 420cad9..cd0cf31 100644 --- a/ProxySU_Core/ViewModels/Developers/XrayProject.cs +++ b/ProxySU_Core/ViewModels/Developers/XrayProject.cs @@ -29,6 +29,25 @@ namespace ProxySU_Core.ViewModels.Developers { } + public void InstallCert() + { + EnsureRootAuth(); + EnsureSystemEnv(); + this.InstallCertToXray(); + RunCmd("systemctl restart xray"); + } + + public void UploadWeb(Stream stream) + { + EnsureRootAuth(); + EnsureSystemEnv(); + RunCmd("rm -rf /usr/share/caddy/*"); + 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"); + } + + public override void Install() { try @@ -45,25 +64,46 @@ namespace ProxySU_Core.ViewModels.Developers } } + WriteOutput("检测安装系统环境..."); EnsureSystemEnv(); + WriteOutput("检测安装系统环境完成"); + WriteOutput("配置服务器端口..."); ConfigurePort(); + WriteOutput("端口配置完成"); + WriteOutput("安装必要的系统工具..."); ConfigureSoftware(); + WriteOutput("系统工具安装完成"); + WriteOutput("检测IP6..."); ConfigureIPv6(); + WriteOutput("检测IP6完成"); + WriteOutput("配置防火墙..."); ConfigureFirewall(); + WriteOutput("防火墙配置完成"); + WriteOutput("同步系统和本地世间..."); SyncTimeDiff(); + WriteOutput("时间同步完成"); + WriteOutput("检测域名是否绑定本机IP..."); ValidateDomain(); + WriteOutput("域名检测完成"); + WriteOutput("安装Xray-Core..."); InstallXrayWithCert(); + WriteOutput("Xray-Core安装完成"); + WriteOutput("安装Caddy..."); InstallCaddy(); + WriteOutput("Caddy安装完成"); UploadCaddyFile(); + WriteOutput("************"); + WriteOutput("安装完成,尽情享用吧......"); + WriteOutput("************"); } catch (Exception ex) { @@ -84,9 +124,9 @@ namespace ProxySU_Core.ViewModels.Developers { RunCmd("bash -c \"$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)\" @ install"); - if (FileExists("/usr/local/bin/xray")) + if (!FileExists("/usr/local/bin/xray")) { - WriteOutput("Xray安装成功"); + throw new Exception("Xray-Core安装失败,请联系开发者"); } RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/xray.service"); @@ -99,7 +139,9 @@ namespace ProxySU_Core.ViewModels.Developers RunCmd(@"mv /usr/local/etc/xray/config.json /usr/local/etc/xray/config.json.1"); } + WriteOutput("安装TLS证书"); InstallCertToXray(); + WriteOutput("TLS证书安装完成"); var configJson = ConfigBuilder.BuildXrayConfig(Parameters); diff --git a/ProxySU_Core/ViewModels/Terminal.cs b/ProxySU_Core/ViewModels/Terminal.cs index 4c5028b..942edc5 100644 --- a/ProxySU_Core/ViewModels/Terminal.cs +++ b/ProxySU_Core/ViewModels/Terminal.cs @@ -9,10 +9,25 @@ namespace ProxySU_Core.ViewModels public class Terminal : BaseViewModel { private string outputText; + private bool hasConnected; public Terminal(Host host) { Host = host; + HasConnected = false; + } + + public bool HasConnected + { + get + { + return hasConnected; + } + set + { + hasConnected = value; + Notify("HasConnected"); + } } public Host Host { get; set; } diff --git a/ProxySU_Core/Views/ClientInfoWindow.xaml b/ProxySU_Core/Views/ClientInfoWindow.xaml index 5e01deb..687bcc4 100644 --- a/ProxySU_Core/Views/ClientInfoWindow.xaml +++ b/ProxySU_Core/Views/ClientInfoWindow.xaml @@ -6,19 +6,309 @@ xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls" xmlns:local="clr-namespace:ProxySU_Core.Views" mc:Ignorable="d" - Title="ClientInfoWindow" Height="450" Width="800"> + Title="查看配置" Height="450" Width="800"> - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProxySU_Core/Views/ClientInfoWindow.xaml.cs b/ProxySU_Core/Views/ClientInfoWindow.xaml.cs index 00a0f5d..600d0cb 100644 --- a/ProxySU_Core/Views/ClientInfoWindow.xaml.cs +++ b/ProxySU_Core/Views/ClientInfoWindow.xaml.cs @@ -1,4 +1,5 @@ using ProxySU_Core.Models; +using ProxySU_Core.ViewModels; using System; using System.Collections.Generic; using System.Linq; @@ -20,13 +21,14 @@ namespace ProxySU_Core.Views /// public partial class ClientInfoWindow { - Record Record { get; set; } + public XraySettingsViewModel Settings { get; set; } + public ClientInfoWindow(Record record) { InitializeComponent(); - this.Record = record; - DataContext = this.Record; + Settings = new XraySettingsViewModel(record.Settings); + DataContext = this; } } } diff --git a/ProxySU_Core/Views/RecordEditorWindow.xaml b/ProxySU_Core/Views/RecordEditorWindow.xaml index b3d048a..785af14 100644 --- a/ProxySU_Core/Views/RecordEditorWindow.xaml +++ b/ProxySU_Core/Views/RecordEditorWindow.xaml @@ -8,7 +8,7 @@ xmlns:local="clr-namespace:ProxySU_Core.Views" xmlns:converters="clr-namespace:ProxySU_Core.Converters" mc:Ignorable="d" - Title="RecordEditorWindow" Height="800" Width="710"> + Title="编辑主机信息" Height="800" Width="710"> diff --git a/ProxySU_Core/Views/TerminalWindow.xaml b/ProxySU_Core/Views/TerminalWindow.xaml index 30cb0e4..0820d2d 100644 --- a/ProxySU_Core/Views/TerminalWindow.xaml +++ b/ProxySU_Core/Views/TerminalWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:ProxySU_Core" xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls" mc:Ignorable="d" - Title="TerminalWindow" Height="500" Width="800"> + Title="主机控制台" Height="500" Width="800"> - + +