From 6475544bbfcd81226f6280aeb92916d487e4719f Mon Sep 17 00:00:00 2001 From: ProxySU Date: Tue, 25 Aug 2020 07:59:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0vless+tcp+tls+web,=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=87=A0=E5=A4=84Bug,=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxySU/MainWindow.xaml | 10 +- ProxySU/MainWindow.xaml.cs | 3183 +++++++++-------- ProxySU/NaiveProxyResultInfoWindow.xaml | 44 - ProxySU/NaiveProxyResultInfoWindow.xaml.cs | 119 - ProxySU/ProxySU.csproj | 27 +- ProxySU/ResultClientInformation.xaml | 178 +- ProxySU/ResultClientInformation.xaml.cs | 772 ++-- ProxySU/TrojanGoResultClientInfoWindow.xaml | 72 - .../TrojanGoResultClientInfoWindow.xaml.cs | 161 - ProxySU/TrojanGoTemplateWindow.xaml | 4 +- ProxySU/TrojanResultClientInfoWindow.xaml | 72 - ProxySU/TrojanResultClientInfoWindow.xaml.cs | 163 - ...guration.xaml => V2RayTemplateWindow.xaml} | 23 +- ...on.xaml.cs => V2RayTemplateWindow.xaml.cs} | 104 +- ProxySU/bin/Beta/Beta.zip | Bin 496548 -> 497406 bytes TemplateConfg/tcp_TLS_client_config.json | 88 +- .../tcp_vless_tls_caddy_cilent_config.json | 43 + .../tcp_vless_tls_caddy_server_config.json | 42 + 18 files changed, 2532 insertions(+), 2573 deletions(-) delete mode 100644 ProxySU/NaiveProxyResultInfoWindow.xaml delete mode 100644 ProxySU/NaiveProxyResultInfoWindow.xaml.cs delete mode 100644 ProxySU/TrojanGoResultClientInfoWindow.xaml delete mode 100644 ProxySU/TrojanGoResultClientInfoWindow.xaml.cs delete mode 100644 ProxySU/TrojanResultClientInfoWindow.xaml delete mode 100644 ProxySU/TrojanResultClientInfoWindow.xaml.cs rename ProxySU/{TemplateConfiguration.xaml => V2RayTemplateWindow.xaml} (90%) rename ProxySU/{TemplateConfiguration.xaml.cs => V2RayTemplateWindow.xaml.cs} (88%) create mode 100644 TemplateConfg/tcp_vless_tls_caddy_cilent_config.json create mode 100644 TemplateConfg/tcp_vless_tls_caddy_server_config.json diff --git a/ProxySU/MainWindow.xaml b/ProxySU/MainWindow.xaml index e57612c..36ff75f 100644 --- a/ProxySU/MainWindow.xaml +++ b/ProxySU/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ProxySU" mc:Ignorable="d" - Title="ProxySU - v1.8.4" Height="600" Width="530"> + Title="ProxySU - v1.8.5" Height="600" Width="530"> @@ -60,12 +60,12 @@ - - + + - - + + diff --git a/ProxySU/MainWindow.xaml.cs b/ProxySU/MainWindow.xaml.cs index f52ad46..c3c5288 100644 --- a/ProxySU/MainWindow.xaml.cs +++ b/ProxySU/MainWindow.xaml.cs @@ -44,11 +44,12 @@ namespace ProxySU //ReceiveConfigurationParameters[6]----QUIC密钥 //ReceiveConfigurationParameters[7]----伪装网站 //public static ConnectionInfo ConnectionInfo; - static bool testDomain = false; //设置标识--域名是否需要检测解析,初始化为不需要 - static string sshShellCommand;//定义保存执行的命令 - static string currentShellCommandResult;//定义Shell命令执行结果保存变量 - static string sshCmdUpdate;//保存软件安装所用更新软件库命令 - static string sshCmdInstall;//保存软件安装所用命令格式 + public static string proxyType = "V2Ray"; //代理类型标识: V2Ray\TrojanGo\Trojan\NaiveProxy + static bool testDomain = false; //设置标识--域名是否需要检测解析,初始化为不需要 + static string sshShellCommand; //定义保存执行的命令 + static string currentShellCommandResult; //定义Shell命令执行结果保存变量 + static string sshCmdUpdate; //保存软件安装所用更新软件库命令 + static string sshCmdInstall; //保存软件安装所用命令格式 public MainWindow() { @@ -396,6 +397,12 @@ namespace ProxySU serverConfig = "TemplateConfg\\tcpTLSselfSigned_server_config.json"; clientConfig = "TemplateConfg\\tcpTLSselfSigned_client_config.json"; } + else if (String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb")) + { + testDomain = true; + serverConfig = "TemplateConfg\\tcp_vless_tls_caddy_server_config.json"; + clientConfig = "TemplateConfg\\tcp_vless_tls_caddy_cilent_config.json"; + } else if (String.Equals(ReceiveConfigurationParameters[0], "webSocket")) { testDomain = false; @@ -1277,8 +1284,8 @@ namespace ProxySU JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); //设置uuid serverJson["inbounds"][0]["settings"]["clients"][0]["id"] = ReceiveConfigurationParameters[2]; - //除WebSocketTLSWeb/http2Web模式外设置监听端口 - if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == false && String.Equals(ReceiveConfigurationParameters[0], "http2Web") == false) + //除WebSocketTLSWeb/http2Web/VlessTcpTlsWeb模式外设置监听端口 + if (String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS2Web") == false && String.Equals(ReceiveConfigurationParameters[0], "http2Web") == false && String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == false) { serverJson["inbounds"][0]["port"] = int.Parse(ReceiveConfigurationParameters[1]); } @@ -1331,10 +1338,118 @@ namespace ProxySU File.Delete(@"config.json"); - //如果是WebSocket + TLS + Web模式,需要安装Caddy - if (ReceiveConfigurationParameters[0].Contains("WebSocketTLS2Web") ==true || ReceiveConfigurationParameters[0].Contains("http2Web") == true) + //如果使用http2/WebSocketTLS/tcpTLS/VlessTcpTlsWeb模式,先要安装acme.sh,申请证书 + if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true || String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true || String.Equals(ReceiveConfigurationParameters[0], "VlessTcpTlsWeb") == true) { - currentStatus = "使用WebSocket+TLS+Web/HTTP2+TLS+Web模式,正在安装Caddy......"; + currentStatus = "正在安装acme.sh......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //安装所依赖的软件 + sshShellCommand = $"{sshCmdUpdate}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"{sshCmdInstall}socat"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //if (getApt == false) + //{ + // //client.RunCommand("apt-get -qq update"); + // client.RunCommand("apt -y -qq install socat"); + //} + //else if (getDnf == false) + //{ + // //client.RunCommand("yum -q makecache"); + // client.RunCommand("dnf -y -q install socat"); + //} + //else if (getYum == false) + //{ + // //client.RunCommand("yum -q makecache"); + // client.RunCommand("yum -y -q install socat"); + //} + //if (getZypper == false) + //{ + // // client.RunCommand("zypper ref"); + // client.RunCommand("zypper -y install socat"); + //} + //client.RunCommand("curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"); + //client.RunCommand("cd ~/.acme.sh/"); + //client.RunCommand("alias acme.sh=~/.acme.sh/acme.sh"); + sshShellCommand = @"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"cd ~/.acme.sh/"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"alias acme.sh=~/.acme.sh/acme.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + currentStatus = "申请域名证书......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //client.RunCommand("mkdir -p /etc/v2ray/ssl"); + //client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"); + sshShellCommand = $"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + //currentStatus = "申请域名证书......"; + //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + //Thread.Sleep(1000); + + //client.RunCommand("mkdir -p /usr/local/etc/v2ray/ssl"); + //client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"); + + currentStatus = "安装证书到V2ray......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + sshShellCommand = @"mkdir -p /usr/local/etc/v2ray/ssl"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + // client.RunCommand($"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --keypath /usr/local/etc/v2ray/ssl/v2ray_ssl.key --capath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --reloadcmd \"systemctl restart v2ray\""); + sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --keypath /usr/local/etc/v2ray/ssl/v2ray_ssl.key --capath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --reloadcmd \"systemctl restart v2ray\""; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //设置私钥权限 + sshShellCommand = @"chmod 644 /usr/local/etc/v2ray/ssl/v2ray_ssl.key"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + //如果是WebSocket+TLS+Web/http2Web/vlessTcpTlsWeb模式,需要安装Caddy + if (ReceiveConfigurationParameters[0].Contains("WebSocketTLS2Web") ==true || ReceiveConfigurationParameters[0].Contains("http2Web") == true || ReceiveConfigurationParameters[0].Contains("VlessTcpTlsWeb") == true) + { + currentStatus = "正在安装Caddy......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); currentShellCommandResult = currentStatus; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 @@ -1589,6 +1704,10 @@ namespace ProxySU { serverConfig = "TemplateConfg\\Http2Web_server_config.caddyfile"; } + else if(ReceiveConfigurationParameters[0].Contains("VlessTcpTlsWeb")==true) + { + serverConfig = "TemplateConfg\\trojan_caddy_config.caddyfile"; + } upLoadPath = "/etc/caddy/Caddyfile"; client.RunCommand("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"); UploadConfig(connectionInfo, serverConfig, upLoadPath); @@ -1608,7 +1727,6 @@ namespace ProxySU currentShellCommandResult = client.RunCommand(sshShellCommand).Result; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - //设置Path //sshCmd = $"sed -i 's/##path##/\\{ReceiveConfigurationParameters[3]}/' {upLoadPath}"; //client.RunCommand(sshCmd); @@ -1617,8 +1735,6 @@ namespace ProxySU currentShellCommandResult = client.RunCommand(sshShellCommand).Result; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //设置伪装网站 if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7])==false) { @@ -1659,100 +1775,7 @@ namespace ProxySU Thread.Sleep(1000); } - if (String.Equals(ReceiveConfigurationParameters[0], "Http2") == true || String.Equals(ReceiveConfigurationParameters[0], "WebSocketTLS") == true|| String.Equals(ReceiveConfigurationParameters[0], "tcpTLS") == true) - { - currentStatus = "使用Http2/WebSocket+TLS/tcp+TLS模式,正在安装acme.sh......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //安装所依赖的软件 - sshShellCommand = $"{sshCmdUpdate}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"{sshCmdInstall}socat"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //if (getApt == false) - //{ - // //client.RunCommand("apt-get -qq update"); - // client.RunCommand("apt -y -qq install socat"); - //} - //else if (getDnf == false) - //{ - // //client.RunCommand("yum -q makecache"); - // client.RunCommand("dnf -y -q install socat"); - //} - //else if (getYum == false) - //{ - // //client.RunCommand("yum -q makecache"); - // client.RunCommand("yum -y -q install socat"); - //} - //if (getZypper == false) - //{ - // // client.RunCommand("zypper ref"); - // client.RunCommand("zypper -y install socat"); - //} - //client.RunCommand("curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"); - //client.RunCommand("cd ~/.acme.sh/"); - //client.RunCommand("alias acme.sh=~/.acme.sh/acme.sh"); - sshShellCommand = @"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"cd ~/.acme.sh/"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"alias acme.sh=~/.acme.sh/acme.sh"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - - currentStatus = "申请域名证书......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //client.RunCommand("mkdir -p /etc/v2ray/ssl"); - //client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"); - sshShellCommand = $"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - - //currentStatus = "申请域名证书......"; - //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - //Thread.Sleep(1000); - - //client.RunCommand("mkdir -p /usr/local/etc/v2ray/ssl"); - //client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"); - - currentStatus = "安装证书到V2ray......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - // client.RunCommand($"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --keypath /usr/local/etc/v2ray/ssl/v2ray_ssl.key --capath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --reloadcmd \"systemctl restart v2ray\""); - sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --keypath /usr/local/etc/v2ray/ssl/v2ray_ssl.key --capath /usr/local/etc/v2ray/ssl/v2ray_ssl.crt --reloadcmd \"systemctl restart v2ray\""; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } + currentStatus = "正在启动V2ray......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); @@ -1915,14 +1938,14 @@ namespace ProxySU //client.Disconnect(); - currentStatus = "V2Ray安装成功,祝您使用愉快!"; + currentStatus = "V2Ray安装成功,祝你玩的愉快!!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); currentShellCommandResult = currentStatus; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 Thread.Sleep(1000); //显示服务端连接参数 - //MessageBox.Show("用于V2ray官方客户端的配置文件已保存在config文件夹中"); + proxyType = "V2Ray"; ResultClientInformation resultClientInformation = new ResultClientInformation(); resultClientInformation.ShowDialog(); @@ -2346,6 +2369,1470 @@ namespace ProxySU } #endregion + #region Trojan-go相关 + + //打开设置TrojanGo参数窗口 + private void ButtonTrojanGoTemplate_Click(object sender, RoutedEventArgs e) + { + for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) + + { + ReceiveConfigurationParameters[i] = ""; + } + TrojanGoTemplateWindow windowTrojanGoTemplateConfiguration = new TrojanGoTemplateWindow(); + windowTrojanGoTemplateConfiguration.ShowDialog(); + } + + //传递TrojanGo参数 + private void ButtonTrojanGoSetUp_Click(object sender, RoutedEventArgs e) + { + ConnectionInfo connectionInfo = GenerateConnectionInfo(); + if (connectionInfo == null) + { + MessageBox.Show("远程主机连接信息有误,请检查"); + return; + } + string serverConfig = "TemplateConfg\\trojan-go_all_config.json"; //服务端配置文件 + string clientConfig = "TemplateConfg\\trojan-go_all_config.json"; //生成的客户端配置文件 + string upLoadPath = "/usr/local/etc/trojan-go/config.json"; //服务端文件位置 + + + if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) + { + MessageBox.Show("未选择配置模板或模板选择错误!"); + return; + } + if (String.IsNullOrEmpty(ReceiveConfigurationParameters[4]) == true) + { + MessageBox.Show("空域名,请检查相关参数设置!"); + return; + } + + Thread thread = new Thread(() => StartSetUpTrojanGo(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing, serverConfig, clientConfig, upLoadPath)); + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + } + + //登录远程主机布署Trojan-Go程序 + private void StartSetUpTrojanGo(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar, string serverConfig, string clientConfig, string upLoadPath) + { + string currentStatus = "正在登录远程主机......"; + //Action updateAction = new Action(UpdateTextBlock); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + try + { + #region 主机指纹,暂未启用 + //byte[] expectedFingerPrint = new byte[] { + // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, + // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b + // }; + #endregion + using (var client = new SshClient(connectionInfo)) + + { + #region ssh登录验证主机指纹代码块,暂未启用 + // client.HostKeyReceived += (sender, e) => + // { + // if (expectedFingerPrint.Length == e.FingerPrint.Length) + // { + // for (var i = 0; i < expectedFingerPrint.Length; i++) + // { + // if (expectedFingerPrint[i] != e.FingerPrint[i]) + // { + // e.CanTrust = false; + // break; + // } + // } + // } + // else + // { + // e.CanTrust = false; + // } + // }; + #endregion + + client.Connect(); + if (client.IsConnected == true) + { + currentStatus = "主机登录成功"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 + + Thread.Sleep(1000); + } + + //检测是否运行在root权限下 + currentShellCommandResult = "检测是否运行在root权限下..."; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"id -u"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string testRootAuthority = currentShellCommandResult; + if (testRootAuthority.Equals("0\n") == false) + { + MessageBox.Show("请使用具有root权限的账户登录主机!!"); + client.Disconnect(); + return; + } + else + { + currentShellCommandResult = "检测结果:OK!"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //检测是否安装有Trojan-Go + currentStatus = "检测系统是否已经安装Trojan-Go......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + sshShellCommand = @"find / -name trojan-go"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string resultCmdTestTrojanInstalled = currentShellCommandResult; + + if (resultCmdTestTrojanInstalled.Contains("/usr/local/bin/trojan-go") == true) + { + MessageBoxResult messageBoxResult = MessageBox.Show("远程主机已安装Trojan,是否强制重新安装?", "", MessageBoxButton.YesNo, MessageBoxImage.Question); + if (messageBoxResult == MessageBoxResult.No) + { + currentStatus = "安装取消,退出"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + } + else + { + currentStatus = "已选择强制安装Trojan-go!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + } + } + else + { + currentStatus = "检测结果:未安装Trojan-go!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);//显示命令执行的结果 + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + //检测远程主机系统环境是否符合要求 + currentStatus = "检测系统是否符合安装要求......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + + //检测系统是否支持dnf\yum 或 apt或zypper,且支持Systemd + //如果不存在组件,则命令结果为空,string.IsNullOrEmpty值为真, + //bool getApt = String.IsNullOrEmpty(client.RunCommand("command -v apt").Result); + //bool getDnf = String.IsNullOrEmpty(client.RunCommand("command -v dnf").Result); + //bool getYum = String.IsNullOrEmpty(client.RunCommand("command -v yum").Result); + //bool getZypper = String.IsNullOrEmpty(client.RunCommand("command -v zypper").Result); + //bool getSystemd = String.IsNullOrEmpty(client.RunCommand("command -v systemctl").Result); + //bool getGetenforce = String.IsNullOrEmpty(client.RunCommand("command -v getenforce").Result); + + sshShellCommand = @"command -v apt"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getApt = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v dnf"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getDnf = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v yum"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getYum = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v zypper"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getZypper = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v systemctl"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getSystemd = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v getenforce"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getGetenforce = String.IsNullOrEmpty(currentShellCommandResult); + + //没有安装apt,也没有安装dnf\yum,也没有安装zypper,或者没有安装systemd的,不满足安装条件 + //也就是apt ,dnf\yum, zypper必须安装其中之一,且必须安装Systemd的系统才能安装。 + if ((getApt && getDnf && getYum && getZypper) || getSystemd) + { + MessageBox.Show($"系统缺乏必要的安装组件如:apt||dnf||yum||zypper||Syetemd,主机系统推荐使用:CentOS 7/8,Debian 8/9/10,Ubuntu 16.04及以上版本"); + currentStatus = "系统环境不满足要求,安装失败!!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + } + else + { + currentStatus = "检测结果:OK!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //设置安装软件所用的命令格式 + //为假则表示系统有相应的组件。 + + if (getApt == false) + { + //client.RunCommand("apt -qq update"); + //client.RunCommand("apt -y -qq install curl"); + sshCmdUpdate = @"apt -qq update"; + sshCmdInstall = @"apt -y -qq install "; + } + else if (getDnf == false) + { + //client.RunCommand("dnf -q makecache"); + //client.RunCommand("dnf -y -q install curl"); + sshCmdUpdate = @"dnf -q makecache"; + sshCmdInstall = @"dnf -y -q install "; + } + else if (getYum == false) + { + //client.RunCommand("yum -q makecache"); + //client.RunCommand("yum -y -q install curl"); + sshCmdUpdate = @"yum -q makecache"; + sshCmdInstall = @"yum -y -q install "; + } + else if (getZypper == false) + { + //client.RunCommand("zypper ref"); + //client.RunCommand("zypper -y install curl"); + sshCmdUpdate = @"zypper ref"; + sshCmdInstall = @"zypper -y install "; + } + + //判断是否启用了SELinux,如果启用了,并且工作在Enforcing模式下,则改为Permissive模式 + if (getGetenforce == false) + { + // string testSELinux = client.RunCommand("getenforce").Result; + sshShellCommand = @"getenforce"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string testSELinux = currentShellCommandResult; + //MessageBox.Show(testSELinux); + if (testSELinux.Contains("Enforcing") == true) + { + currentStatus = "检测到系统启用SELinux,且工作在严格模式下,需改为宽松模式!修改中..."; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //MessageBox.Show("Enforcing"); + // client.RunCommand("setenforce 0");//不重启改为Permissive模式 + // client.RunCommand("sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config");//重启也工作在Permissive模式下 + sshShellCommand = @"setenforce 0"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + sshShellCommand = @"sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + currentStatus = "修改完毕!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + } + + //检测域名解析是否正确 + + currentStatus = "正在检测域名是否解析到当前VPS的IP上......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //在相应系统内安装curl(如果没有安装curl) + if (string.IsNullOrEmpty(client.RunCommand("command -v curl").Result) == true) + { + sshShellCommand = $"{sshCmdUpdate}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"{sshCmdInstall}curl"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + ////为假则表示系统有相应的组件。 + //if (getApt == false) + //{ + // client.RunCommand("apt-get -qq update"); + // client.RunCommand("apt-get -y -qq install curl"); + //} + //else if (getDnf == false) + //{ + // client.RunCommand("dnf -q makecache"); + // client.RunCommand("dnf -y -q install curl"); + //} + //else if (getYum == false) + //{ + // client.RunCommand("yum -q makecache"); + // client.RunCommand("yum -y -q install curl"); + //} + //else if (getZypper == false) + //{ + // client.RunCommand("zypper ref"); + // client.RunCommand("zypper -y install curl"); + //} + } + + sshShellCommand = @"curl -4 ip.sb"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string nativeIp = currentShellCommandResult; + + sshShellCommand = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; + string resultTestDomainCmd = currentShellCommandResult; + + if (String.Equals(nativeIp, resultTestDomainCmd) == true) + { + currentStatus = "解析正确!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + currentStatus = "域名未能正确解析到当前VPS的IP上!安装失败!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + MessageBox.Show("域名未能正确解析到当前VPS的IP上,请检查!若解析设置正确,请等待生效后再重试安装。如果域名使用了CDN,请先关闭!"); + client.Disconnect(); + return; + } + + //检测是否安装lsof + if (string.IsNullOrEmpty(client.RunCommand("command -v lsof").Result) == true) + { + sshShellCommand = $"{sshCmdUpdate}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"{sshCmdInstall}lsof"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //为假则表示系统有相应的组件。 + //if (getApt == false) + //{ + // client.RunCommand("apt -qq update"); + // client.RunCommand("apt -y -qq install lsof"); + //} + //else if (getDnf == false) + //{ + // client.RunCommand("dnf -q makecache"); + // client.RunCommand("dnf -y -q install lsof"); + //} + //else if (getYum == false) + //{ + // client.RunCommand("yum -q makecache"); + // client.RunCommand("yum -y -q install lsof"); + //} + //else if (getZypper == false) + //{ + // client.RunCommand("zypper ref"); + // client.RunCommand("zypper -y install lsof"); + //} + } + currentStatus = "正在检测端口占用情况......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //MessageBox.Show(@"lsof -n -P -i :80 | grep LISTEN"); + //MessageBox.Show(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result); + sshShellCommand = @"lsof -n -P -i :80 | grep LISTEN"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + string testPort80 = currentShellCommandResult; + + sshShellCommand = @"lsof -n -P -i :443 | grep LISTEN"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + string testPort443 = currentShellCommandResult; + + if (String.IsNullOrEmpty(testPort80) == false || String.IsNullOrEmpty(testPort443) == false) + { + MessageBoxResult dialogResult = MessageBox.Show("80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序?", "Stop application", MessageBoxButton.YesNo); + if (dialogResult == MessageBoxResult.No) + { + currentStatus = "端口被占用,安装失败......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + } + + currentStatus = "正在释放80/443端口......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; + //string cmdResult = client.RunCommand(cmdTestPort).Result; + + if (String.IsNullOrEmpty(testPort443) == false) + { + string[] cmdResultArry443 = testPort443.Split(' '); + //client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); + //client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); + //client.RunCommand($"kill -9 {cmdResultArry443[3]}"); + sshShellCommand = $"systemctl stop {cmdResultArry443[0]}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"systemctl disable {cmdResultArry443[0]}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"kill -9 {cmdResultArry443[3]}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + //cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; + //cmdResult = client.RunCommand(cmdTestPort).Result; + if (String.IsNullOrEmpty(testPort80) == false) + { + string[] cmdResultArry80 = testPort80.Split(' '); + //client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); + //client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); + //client.RunCommand($"kill -9 {cmdResultArry80[3]}"); + sshShellCommand = $"systemctl stop {cmdResultArry80[0]}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"systemctl disable {cmdResultArry80[0]}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"kill -9 {cmdResultArry80[3]}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + currentStatus = "80/443端口释放完毕!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + currentStatus = "检测结果:未被占用!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + currentStatus = "系统环境检测完毕,符合安装要求,开始布署......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //打开防火墙端口 + currentStatus = "开启防火墙相应端口......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false) + { + + //client.RunCommand("firewall-cmd --zone=public --add-port=80/tcp --permanent"); + //client.RunCommand("firewall-cmd --zone=public --add-port=443/tcp --permanent"); + //client.RunCommand("firewall-cmd --reload"); + sshShellCommand = @"firewall-cmd --zone=public --add-port=80/tcp --permanent"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"firewall-cmd --zone=public --add-port=443/tcp --permanent"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | firewall-cmd --reload"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + if (String.IsNullOrEmpty(client.RunCommand("command -v ufw").Result) == false) + { + //client.RunCommand("ufw allow 80"); + //client.RunCommand("ufw allow 443"); + //client.RunCommand("yes | ufw reload"); + + sshShellCommand = @"ufw allow 80"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"ufw allow 443"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | ufw reload"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + //下载安装脚本安装 + currentStatus = "正在安装Trojan-go......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //client.RunCommand("curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"); + //client.RunCommand("yes | bash /tmp/trojan-go.sh -f"); + + sshShellCommand = @"curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | bash /tmp/trojan-go.sh -f"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"find / -name trojan-go"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string installResult = currentShellCommandResult; + + if (!installResult.Contains("/usr/local/bin/trojan-go")) + { + MessageBox.Show("安装Trojan-Go失败(安装脚本运行出错!"); + + currentStatus = "安装Trojan-Go失败(安装脚本运行出错!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + client.Disconnect(); + return; + } + else + { + currentStatus = "Trojan-Go安装成功!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //client.RunCommand("systemctl enable trojan-go"); + sshShellCommand = @"systemctl enable trojan-go"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //client.RunCommand("mv /etc/trojan-go/config.json /etc/trojan-go/config.json.1"); + sshShellCommand = @"mv /etc/trojan-go/config.json /etc/trojan-go/config.json.1"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + //上传配置文件 + currentStatus = "Trojan-Go程序安装完毕,配置文件上传中......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //生成服务端配置 + using (StreamReader reader = File.OpenText(serverConfig)) + { + JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); + serverJson["run_type"] = "server"; + serverJson["local_addr"] = "0.0.0.0"; + serverJson["local_port"] = 443; + serverJson["remote_addr"] = "127.0.0.1"; + serverJson["remote_port"] = 88; + //设置密码 + serverJson["password"][0] = ReceiveConfigurationParameters[2]; + //设置证书 + serverJson["ssl"]["cert"] = "/usr/local/etc/trojan-go/trojan-go.crt"; + serverJson["ssl"]["key"] = "/usr/local/etc/trojan-go/trojan-go.key"; + //serverJson["ssl"]["sni"] = ReceiveConfigurationParameters[4]; + + if (String.Equals(ReceiveConfigurationParameters[0], "TrojanGoWebSocketTLS2Web")) + { + serverJson["websocket"]["enabled"] = true; + serverJson["websocket"]["path"] = ReceiveConfigurationParameters[3]; + } + + using (StreamWriter sw = new StreamWriter(@"config.json")) + { + sw.Write(serverJson.ToString()); + } + } + upLoadPath = "/usr/local/etc/trojan-go/config.json"; + UploadConfig(connectionInfo, @"config.json", upLoadPath); + + File.Delete(@"config.json"); + + currentStatus = "正在安装acme.sh......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //安装所依赖的软件 + sshShellCommand = $"{sshCmdUpdate}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"{sshCmdInstall}socat"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //if (getApt == false) + //{ + // //client.RunCommand("apt-get -qq update"); + // client.RunCommand("apt-get -y -qq install socat"); + //} + //else if (getDnf == false) + //{ + // //client.RunCommand("yum -q makecache"); + // client.RunCommand("dnf -y -q install socat"); + //} + //else if (getYum == false) + //{ + // //client.RunCommand("yum -q makecache"); + // client.RunCommand("yum -y -q install socat"); + //} + //else if (getZypper == false) + //{ + // // client.RunCommand("zypper ref"); + // client.RunCommand("zypper -y install socat"); + //} + //client.RunCommand("curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"); + //client.RunCommand("cd ~/.acme.sh/"); + //client.RunCommand("alias acme.sh=~/.acme.sh/acme.sh"); + + sshShellCommand = @"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"cd ~/.acme.sh/"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"alias acme.sh=~/.acme.sh/acme.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + currentStatus = "申请域名证书......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //client.RunCommand("mkdir -p /etc/v2ray/ssl"); + //client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"); + sshShellCommand = $"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + currentStatus = "安装证书到Trojan-Go......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //client.RunCommand($"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan-go/trojan-go.crt --keypath /usr/local/etc/trojan-go/trojan-go.key --capath /usr/local/etc/trojan-go/trojan-go.crt --reloadcmd \"systemctl restart trojan-go\""); + sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan-go/trojan-go.crt --keypath /usr/local/etc/trojan-go/trojan-go.key --capath /usr/local/etc/trojan-go/trojan-go.crt --reloadcmd \"systemctl restart trojan-go\""; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //设置证书权限 + sshShellCommand = @"chmod 644 /usr/local/etc/trojan-go/trojan-go.key"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //安装Caddy + currentStatus = "正在安装Caddy"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //安装Caddy + //为假则表示系统有相应的组件。 + if (getApt == false) + { + //client.RunCommand(@"echo ""deb [trusted=yes] https://apt.fury.io/caddy/ /"" | tee -a /etc/apt/sources.list.d/caddy-fury.list"); + //client.RunCommand("apt install -y apt-transport-https"); + //client.RunCommand("apt -qq update"); + //client.RunCommand("apt -y -qq install caddy"); + sshShellCommand = @"echo ""deb [trusted=yes] https://apt.fury.io/caddy/ /"" | tee -a /etc/apt/sources.list.d/caddy-fury.list"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"apt install -y apt-transport-https"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"apt -qq update"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"apt -y -qq install caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + else if (getDnf == false) + { + //client.RunCommand(@"dnf install 'dnf-command(copr)' -y"); + //client.RunCommand(@"dnf copr enable @caddy/caddy -y"); + ////client.RunCommand("dnf -q makecache"); + //client.RunCommand("dnf -y -q install caddy"); + sshShellCommand = @"dnf install 'dnf-command(copr)' -y"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"dnf copr enable @caddy/caddy -y"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //sshShellCommand = @"dnf -q makecache"; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"dnf -y -q install caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + else if (getYum == false) + { + //client.RunCommand(@"yum install yum-plugin-copr -y"); + //client.RunCommand(@"yum copr enable @caddy/caddy -y"); + ////client.RunCommand("yum -q makecache"); + //client.RunCommand("yum -y -q install caddy"); + sshShellCommand = @"yum install yum-plugin-copr -y"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yum copr enable @caddy/caddy -y"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //sshShellCommand = @"yum -q makecache"; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yum -y -q install caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + sshShellCommand = @"find / -name caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + installResult = currentShellCommandResult; + + if (!installResult.Contains("/usr/bin/caddy")) + { + MessageBox.Show("安装Caddy失败!"); + + currentStatus = "安装Caddy失败!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + client.Disconnect(); + return; + } + + currentStatus = "Caddy安装成功!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + // client.RunCommand("systemctl enable caddy"); + sshShellCommand = @"systemctl enable caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + + currentStatus = "上传Caddy配置文件......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //client.RunCommand("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak");//备份原文件 + sshShellCommand = @"mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + string caddyConfig = "TemplateConfg\\trojan_caddy_config.caddyfile"; + + upLoadPath = "/etc/caddy/Caddyfile"; + UploadConfig(connectionInfo, caddyConfig, upLoadPath); + + //设置Caddyfile文件中的tls 邮箱 + + //string email = $"user@{ReceiveConfigurationParameters[4]}"; + //设置域名 + //string sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; + sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //client.RunCommand(sshCmd); + //设置伪装网站 + if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false) + { + // sshCmd = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; + //client.RunCommand(sshCmd); + sshShellCommand = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + } + currentStatus = "Caddy配置文件上传成功,OK!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //安装Caddy服务 + //sshCmd = $"caddy -service install -agree -conf /etc/caddy/Caddyfile -email {email}"; + //client.RunCommand(sshCmd); + //启动Caddy服务 + currentStatus = "正在启动Caddy......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //启动Caddy服务 + //client.RunCommand("systemctl restart caddy"); + sshShellCommand = @"systemctl restart caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + currentStatus = "Caddy启动成功!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + currentStatus = "正在启动Trojan-Go......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //启动Trojan-go服务 + //client.RunCommand("systemctl restart trojan-go"); + sshShellCommand = @"systemctl restart trojan-go"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + currentStatus = "Trojan-go启动成功!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //测试BBR条件,若满足提示是否启用 + currentStatus = "BBR测试......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //var result = client.RunCommand("uname -r"); + sshShellCommand = @"uname -r"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string[] linuxKernelVerStr = currentShellCommandResult.Split('-'); + + bool detectResult = DetectKernelVersionBBR(linuxKernelVerStr[0]); + //client.RunCommand(@"sysctl net.ipv4.tcp_congestion_control | grep bbr").Result; + sshShellCommand = @"sysctl net.ipv4.tcp_congestion_control | grep bbr"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + string resultCmdTestBBR = currentShellCommandResult; + //如果内核满足大于等于4.9,且还未启用BBR,则启用BBR + if (detectResult == true && resultCmdTestBBR.Contains("bbr") == false) + { + currentStatus = "正在启用BBR......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //client.RunCommand(@"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"); + //client.RunCommand(@"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"); + //client.RunCommand(@"sysctl -p"); + sshShellCommand = @"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"sysctl -p"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + else if (resultCmdTestBBR.Contains("bbr") == true) + { + currentStatus = "BBR已经启用了!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + else + { + currentStatus = "系统不满足启用BBR的条件,启用失败!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + client.Disconnect();//断开服务器ssh连接 + + ////测试BBR条件,若满足提示是否启用 + //var result = client.RunCommand("uname -r"); + ////var result = client.RunCommand("cat /root/test.ver"); + //string[] linuxKernelVerStr = result.Result.Split('-'); + + //bool detectResult = DetectKernelVersionBBR(linuxKernelVerStr[0]); + //string resultCmdTestBBR = client.RunCommand(@"sysctl net.ipv4.tcp_congestion_control | grep bbr").Result; + ////如果内核满足大于等于4.9,且还未启用BBR,则启用BBR + //if (detectResult == true && resultCmdTestBBR.Contains("bbr") == false) + //{ + // client.RunCommand(@"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"); + // client.RunCommand(@"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"); + // client.RunCommand(@"sysctl -p"); + //} + + //生成客户端配置 + currentStatus = "生成客户端配置......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + if (!Directory.Exists("trojan-go_config"))//如果不存在就创建file文件夹      + { + Directory.CreateDirectory("trojan-go_config");//创建该文件夹   + } + clientConfig = "TemplateConfg\\trojan-go_all_config.json"; + using (StreamReader reader = File.OpenText(clientConfig)) + { + JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); + clientJson["run_type"] = "client"; + clientJson["local_addr"] = "127.0.0.1"; + clientJson["local_port"] = 1080; + clientJson["remote_addr"] = ReceiveConfigurationParameters[4]; + clientJson["remote_port"] = 443; + //设置密码 + clientJson["password"][0] = ReceiveConfigurationParameters[2]; + //如果是WebSocket协议则设置路径 + if (String.Equals(ReceiveConfigurationParameters[0], "TrojanGoWebSocketTLS2Web")) + { + clientJson["websocket"]["enabled"] = true; + clientJson["websocket"]["path"] = ReceiveConfigurationParameters[3]; + } + + using (StreamWriter sw = new StreamWriter(@"trojan-go_config\config.json")) + { + sw.Write(clientJson.ToString()); + } + } + + + + currentStatus = "Trojan-go安装成功,祝你玩的愉快!!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //显示服务端连接参数 + //MessageBox.Show("用于Trojan官方客户端的配置文件已保存在config文件夹中"); + proxyType = "TrojanGo"; + //TrojanGoResultClientInfoWindow resultClientInformation = new TrojanGoResultClientInfoWindow(); + //resultClientInformation.ShowDialog(); + ResultClientInformation resultClientInformation = new ResultClientInformation(); + resultClientInformation.ShowDialog(); + return; + } + } + catch (Exception ex1)//例外处理 + #region 例外处理 + { + //MessageBox.Show(ex1.Message); + if (ex1.Message.Contains("连接尝试失败") == true) + { + MessageBox.Show($"{ex1.Message}\n请检查主机地址及端口是否正确,如果通过代理,请检查代理是否正常工作"); + } + + else if (ex1.Message.Contains("denied (password)") == true) + { + MessageBox.Show($"{ex1.Message}\n密码错误或用户名错误"); + } + else if (ex1.Message.Contains("Invalid private key file") == true) + { + MessageBox.Show($"{ex1.Message}\n所选密钥文件错误或者格式不对"); + } + else if (ex1.Message.Contains("denied (publickey)") == true) + { + MessageBox.Show($"{ex1.Message}\n使用密钥登录,密钥文件错误或用户名错误"); + } + else if (ex1.Message.Contains("目标计算机积极拒绝") == true) + { + MessageBox.Show($"{ex1.Message}\n主机地址错误,如果使用了代理,也可能是连接代理的端口错误"); + } + else + { + MessageBox.Show("发生错误"); + MessageBox.Show(ex1.Message); + } + currentStatus = "主机登录失败"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + #endregion + + } + + //检测升级Trojan-Go版本传递参数 + private void ButtonUpdateTrojanGo_Click(object sender, RoutedEventArgs e) + { + ConnectionInfo connectionInfo = GenerateConnectionInfo(); + if (connectionInfo == null) + { + MessageBox.Show("远程主机连接信息有误,请检查"); + return; + } + + Thread thread = new Thread(() => UpdateTojanGo(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing)); + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + } + + //升级Trojan-go主程序 + private void UpdateTojanGo(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar) + { + string currentStatus = "正在登录远程主机......"; + //Action updateAction = new Action(UpdateTextBlock); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + try + { + #region 主机指纹,暂未启用 + //byte[] expectedFingerPrint = new byte[] { + // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, + // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b + // }; + #endregion + using (var client = new SshClient(connectionInfo)) + + { + #region ssh登录验证主机指纹代码块,暂未启用 + // client.HostKeyReceived += (sender, e) => + // { + // if (expectedFingerPrint.Length == e.FingerPrint.Length) + // { + // for (var i = 0; i < expectedFingerPrint.Length; i++) + // { + // if (expectedFingerPrint[i] != e.FingerPrint[i]) + // { + // e.CanTrust = false; + // break; + // } + // } + // } + // else + // { + // e.CanTrust = false; + // } + // }; + #endregion + + client.Connect(); + if (client.IsConnected == true) + { + currentStatus = "主机登录成功"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 + + Thread.Sleep(1000); + } + //检测是否运行在root权限下 + currentShellCommandResult = "检测是否运行在root权限下..."; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"id -u"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string testRootAuthority = currentShellCommandResult; + if (testRootAuthority.Equals("0\n") == false) + { + MessageBox.Show("请使用具有root权限的账户登录主机!!"); + client.Disconnect(); + return; + } + else + { + currentShellCommandResult = "检测结果:OK!"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + ////检测是否运行在root权限下 + //string testRootAuthority = client.RunCommand(@"id -u").Result; + //if (testRootAuthority.Equals("0\n") == false) + //{ + // MessageBox.Show("请使用具有root权限的账户登录主机!!"); + // client.Disconnect(); + // return; + //} + //检测当前安装的版本 + currentStatus = "检测远程主机Trojan-Go版本......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //string cmdTestTrojanInstalled = @"find / -name trojan-go"; + + sshShellCommand = @"find / -name trojan-go"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + string resultCmdTestTrojanInstalled = currentShellCommandResult; + + if (resultCmdTestTrojanInstalled.Contains("/usr/local/bin/trojan-go") == false) + { + MessageBoxResult messageBoxResult = MessageBox.Show("远程主机未安装Trojan-Go!"); + + currentStatus = "未安装Trojan-Go,退出"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + + } + //获取当前安装的版本 + //string sshcmd = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; + sshShellCommand = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string trojanCurrentVersion = currentShellCommandResult;//含字母v + //获取最新版本 + //sshcmd = @"curl -s https://api.github.com/repos/p4gefau1t/trojan-go/tags | grep 'name' | cut -d\"" -f4 | head -1"; + sshShellCommand = @"curl -s https://api.github.com/repos/p4gefau1t/trojan-go/tags | grep 'name' | cut -d\"" -f4 | head -1"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string trojanNewVersion = currentShellCommandResult;//含字母v + + if (trojanNewVersion.Equals(trojanCurrentVersion) == false) + { + MessageBoxResult messageBoxResult = MessageBox.Show($"远程主机当前版本为:v{trojanCurrentVersion}\n最新版本为:{trojanNewVersion}\n是否升级为最新版本?", "", MessageBoxButton.YesNo, MessageBoxImage.Question); + if (messageBoxResult == MessageBoxResult.Yes) + { + currentStatus = "正在升级Trojan-Go到最新版本......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //备份配置文件 + //sshcmd = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.bak"; + //client.RunCommand(sshcmd); + //升级Trojan-Go主程序 + //client.RunCommand("curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"); + //client.RunCommand("yes | bash /tmp/trojan-go.sh -f"); + sshShellCommand = @"curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | bash /tmp/trojan-go.sh -f"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //获取升级后的版本 + //sshcmd = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; + sshShellCommand = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + trojanCurrentVersion = currentShellCommandResult;//含字母v + if (trojanNewVersion.Equals(trojanCurrentVersion) == true) + { + //恢复原来的配置文件备份 + //sshcmd = @"rm -f /usr/local/etc/trojan/config.json"; + //client.RunCommand(sshcmd); + //sshcmd = @"mv /usr/local/etc/trojan/config.json.bak /usr/local/etc/trojan/config.json"; + //client.RunCommand(sshcmd); + MessageBox.Show($"升级成功!!\n当前版本为:v{trojanCurrentVersion}\n最新版本为:{trojanNewVersion}"); + currentStatus = "升级成功!当前已是最新版本!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + MessageBox.Show("升级失败,原因未知,请向开发者提问,以寻求支持!"); + currentStatus = "升级失败!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + } + } + + else + { + currentStatus = "升级取消,退出"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + } + } + else + { + MessageBox.Show($"远程主机当前已是最新版本:{trojanNewVersion}\n无需升级!"); + currentStatus = "已是最新版本,无需升级,退出"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + + client.Disconnect(); + return; + } + } + catch (Exception ex1)//例外处理 + #region 例外处理 + { + //MessageBox.Show(ex1.Message); + if (ex1.Message.Contains("连接尝试失败") == true) + { + MessageBox.Show($"{ex1.Message}\n请检查主机地址及端口是否正确,如果通过代理,请检查代理是否正常工作"); + } + + else if (ex1.Message.Contains("denied (password)") == true) + { + MessageBox.Show($"{ex1.Message}\n密码错误或用户名错误"); + } + else if (ex1.Message.Contains("Invalid private key file") == true) + { + MessageBox.Show($"{ex1.Message}\n所选密钥文件错误或者格式不对"); + } + else if (ex1.Message.Contains("denied (publickey)") == true) + { + MessageBox.Show($"{ex1.Message}\n使用密钥登录,密钥文件错误或用户名错误"); + } + else if (ex1.Message.Contains("目标计算机积极拒绝") == true) + { + MessageBox.Show($"{ex1.Message}\n主机地址错误,如果使用了代理,也可能是连接代理的端口错误"); + } + else + { + MessageBox.Show("发生错误"); + MessageBox.Show(ex1.Message); + } + currentStatus = "主机登录失败"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + #endregion + + } + #endregion + #region Trojan相关 //打开Trojan参数设置界面 @@ -2359,7 +3846,7 @@ namespace ProxySU // TrojanTemplateWindow windowTrojanTemplateConfiguration = new TrojanTemplateWindow(); // windowTrojanTemplateConfiguration.ShowDialog(); //} - + //Trojan参数传递 private void ButtonTrojanSetUp_Click(object sender, RoutedEventArgs e) { @@ -3656,7 +5143,7 @@ namespace ProxySU //client.Disconnect(); - currentStatus = "Trojan安装成功,祝您使用愉快!"; + currentStatus = "Trojan安装成功,祝你玩的愉快!!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); currentShellCommandResult = currentStatus; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 @@ -3664,10 +5151,11 @@ namespace ProxySU Thread.Sleep(1000); //显示服务端连接参数 - //MessageBox.Show("用于Trojan官方客户端的配置文件已保存在config文件夹中"); - TrojanResultClientInfoWindow resultClientInformation = new TrojanResultClientInfoWindow(); + proxyType = "Trojan"; + //TrojanResultClientInfoWindow resultClientInformation = new TrojanResultClientInfoWindow(); + //resultClientInformation.ShowDialog(); + ResultClientInformation resultClientInformation = new ResultClientInformation(); resultClientInformation.ShowDialog(); - return; } } @@ -4019,1462 +5507,6 @@ namespace ProxySU } #endregion - #region Trojan-go相关 - - //打开设置TrojanGo参数窗口 - private void ButtonTrojanGoTemplate_Click(object sender, RoutedEventArgs e) - { - for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) - - { - ReceiveConfigurationParameters[i] = ""; - } - TrojanGoTemplateWindow windowTrojanGoTemplateConfiguration = new TrojanGoTemplateWindow(); - windowTrojanGoTemplateConfiguration.ShowDialog(); - } - - //传递TrojanGo参数 - private void ButtonTrojanGoSetUp_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - MessageBox.Show("远程主机连接信息有误,请检查"); - return; - } - string serverConfig = "TemplateConfg\\trojan-go_all_config.json"; //服务端配置文件 - string clientConfig = "TemplateConfg\\trojan-go_all_config.json"; //生成的客户端配置文件 - string upLoadPath = "/usr/local/etc/trojan-go/config.json"; //服务端文件位置 - - - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[0]) == true) - { - MessageBox.Show("未选择配置模板或模板选择错误!"); - return; - } - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[4]) == true) - { - MessageBox.Show("空域名,请检查相关参数设置!"); - return; - } - - Thread thread = new Thread(() => StartSetUpTrojanGo(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing, serverConfig, clientConfig, upLoadPath)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //登录远程主机布署Trojan-Go程序 - private void StartSetUpTrojanGo(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar, string serverConfig, string clientConfig, string upLoadPath) - { - string currentStatus = "正在登录远程主机......"; - //Action updateAction = new Action(UpdateTextBlock); - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - currentStatus = "主机登录成功"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 - - Thread.Sleep(1000); - } - - //检测是否运行在root权限下 - currentShellCommandResult = "检测是否运行在root权限下..."; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"id -u"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string testRootAuthority = currentShellCommandResult; - if (testRootAuthority.Equals("0\n") == false) - { - MessageBox.Show("请使用具有root权限的账户登录主机!!"); - client.Disconnect(); - return; - } - else - { - currentShellCommandResult = "检测结果:OK!"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - //检测是否安装有Trojan-Go - currentStatus = "检测系统是否已经安装Trojan-Go......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - sshShellCommand = @"find / -name trojan-go"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string resultCmdTestTrojanInstalled = currentShellCommandResult; - - if (resultCmdTestTrojanInstalled.Contains("/usr/local/bin/trojan-go") == true) - { - MessageBoxResult messageBoxResult = MessageBox.Show("远程主机已安装Trojan,是否强制重新安装?", "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.No) - { - currentStatus = "安装取消,退出"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - client.Disconnect(); - return; - } - else - { - currentStatus = "已选择强制安装Trojan-go!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - } - } - else - { - currentStatus = "检测结果:未安装Trojan-go!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);//显示命令执行的结果 - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - - //检测远程主机系统环境是否符合要求 - currentStatus = "检测系统是否符合安装要求......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - - //检测系统是否支持dnf\yum 或 apt或zypper,且支持Systemd - //如果不存在组件,则命令结果为空,string.IsNullOrEmpty值为真, - //bool getApt = String.IsNullOrEmpty(client.RunCommand("command -v apt").Result); - //bool getDnf = String.IsNullOrEmpty(client.RunCommand("command -v dnf").Result); - //bool getYum = String.IsNullOrEmpty(client.RunCommand("command -v yum").Result); - //bool getZypper = String.IsNullOrEmpty(client.RunCommand("command -v zypper").Result); - //bool getSystemd = String.IsNullOrEmpty(client.RunCommand("command -v systemctl").Result); - //bool getGetenforce = String.IsNullOrEmpty(client.RunCommand("command -v getenforce").Result); - - sshShellCommand = @"command -v apt"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - bool getApt = String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v dnf"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - bool getDnf = String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v yum"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - bool getYum = String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v zypper"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - bool getZypper = String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v systemctl"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - bool getSystemd = String.IsNullOrEmpty(currentShellCommandResult); - - sshShellCommand = @"command -v getenforce"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - bool getGetenforce = String.IsNullOrEmpty(currentShellCommandResult); - - //没有安装apt,也没有安装dnf\yum,也没有安装zypper,或者没有安装systemd的,不满足安装条件 - //也就是apt ,dnf\yum, zypper必须安装其中之一,且必须安装Systemd的系统才能安装。 - if ((getApt && getDnf && getYum && getZypper) || getSystemd) - { - MessageBox.Show($"系统缺乏必要的安装组件如:apt||dnf||yum||zypper||Syetemd,主机系统推荐使用:CentOS 7/8,Debian 8/9/10,Ubuntu 16.04及以上版本"); - currentStatus = "系统环境不满足要求,安装失败!!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - client.Disconnect(); - return; - } - else - { - currentStatus = "检测结果:OK!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - //设置安装软件所用的命令格式 - //为假则表示系统有相应的组件。 - - if (getApt == false) - { - //client.RunCommand("apt -qq update"); - //client.RunCommand("apt -y -qq install curl"); - sshCmdUpdate = @"apt -qq update"; - sshCmdInstall = @"apt -y -qq install "; - } - else if (getDnf == false) - { - //client.RunCommand("dnf -q makecache"); - //client.RunCommand("dnf -y -q install curl"); - sshCmdUpdate = @"dnf -q makecache"; - sshCmdInstall = @"dnf -y -q install "; - } - else if (getYum == false) - { - //client.RunCommand("yum -q makecache"); - //client.RunCommand("yum -y -q install curl"); - sshCmdUpdate = @"yum -q makecache"; - sshCmdInstall = @"yum -y -q install "; - } - else if (getZypper == false) - { - //client.RunCommand("zypper ref"); - //client.RunCommand("zypper -y install curl"); - sshCmdUpdate = @"zypper ref"; - sshCmdInstall = @"zypper -y install "; - } - - //判断是否启用了SELinux,如果启用了,并且工作在Enforcing模式下,则改为Permissive模式 - if (getGetenforce == false) - { - // string testSELinux = client.RunCommand("getenforce").Result; - sshShellCommand = @"getenforce"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string testSELinux = currentShellCommandResult; - //MessageBox.Show(testSELinux); - if (testSELinux.Contains("Enforcing") == true) - { - currentStatus = "检测到系统启用SELinux,且工作在严格模式下,需改为宽松模式!修改中..."; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //MessageBox.Show("Enforcing"); - // client.RunCommand("setenforce 0");//不重启改为Permissive模式 - // client.RunCommand("sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config");//重启也工作在Permissive模式下 - sshShellCommand = @"setenforce 0"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - sshShellCommand = @"sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - currentStatus = "修改完毕!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - - } - - //检测域名解析是否正确 - - currentStatus = "正在检测域名是否解析到当前VPS的IP上......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //在相应系统内安装curl(如果没有安装curl) - if (string.IsNullOrEmpty(client.RunCommand("command -v curl").Result) == true) - { - sshShellCommand = $"{sshCmdUpdate}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"{sshCmdInstall}curl"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - ////为假则表示系统有相应的组件。 - //if (getApt == false) - //{ - // client.RunCommand("apt-get -qq update"); - // client.RunCommand("apt-get -y -qq install curl"); - //} - //else if (getDnf == false) - //{ - // client.RunCommand("dnf -q makecache"); - // client.RunCommand("dnf -y -q install curl"); - //} - //else if (getYum == false) - //{ - // client.RunCommand("yum -q makecache"); - // client.RunCommand("yum -y -q install curl"); - //} - //else if (getZypper == false) - //{ - // client.RunCommand("zypper ref"); - // client.RunCommand("zypper -y install curl"); - //} - } - - sshShellCommand = @"curl -4 ip.sb"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string nativeIp = currentShellCommandResult; - - sshShellCommand = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; - string resultTestDomainCmd = currentShellCommandResult; - - if (String.Equals(nativeIp, resultTestDomainCmd) == true) - { - currentStatus = "解析正确!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - } - else - { - currentStatus = "域名未能正确解析到当前VPS的IP上!安装失败!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - MessageBox.Show("域名未能正确解析到当前VPS的IP上,请检查!若解析设置正确,请等待生效后再重试安装。如果域名使用了CDN,请先关闭!"); - client.Disconnect(); - return; - } - - //检测是否安装lsof - if (string.IsNullOrEmpty(client.RunCommand("command -v lsof").Result) == true) - { - sshShellCommand = $"{sshCmdUpdate}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"{sshCmdInstall}lsof"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //为假则表示系统有相应的组件。 - //if (getApt == false) - //{ - // client.RunCommand("apt -qq update"); - // client.RunCommand("apt -y -qq install lsof"); - //} - //else if (getDnf == false) - //{ - // client.RunCommand("dnf -q makecache"); - // client.RunCommand("dnf -y -q install lsof"); - //} - //else if (getYum == false) - //{ - // client.RunCommand("yum -q makecache"); - // client.RunCommand("yum -y -q install lsof"); - //} - //else if (getZypper == false) - //{ - // client.RunCommand("zypper ref"); - // client.RunCommand("zypper -y install lsof"); - //} - } - currentStatus = "正在检测端口占用情况......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - //MessageBox.Show(@"lsof -n -P -i :80 | grep LISTEN"); - //MessageBox.Show(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result); - sshShellCommand = @"lsof -n -P -i :80 | grep LISTEN"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - string testPort80 = currentShellCommandResult; - - sshShellCommand = @"lsof -n -P -i :443 | grep LISTEN"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - string testPort443 = currentShellCommandResult; - - if (String.IsNullOrEmpty(testPort80) == false || String.IsNullOrEmpty(testPort443) == false) - { - MessageBoxResult dialogResult = MessageBox.Show("80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序?", "Stop application", MessageBoxButton.YesNo); - if (dialogResult == MessageBoxResult.No) - { - currentStatus = "端口被占用,安装失败......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - client.Disconnect(); - return; - } - - currentStatus = "正在释放80/443端口......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; - //string cmdResult = client.RunCommand(cmdTestPort).Result; - - if (String.IsNullOrEmpty(testPort443) == false) - { - string[] cmdResultArry443 = testPort443.Split(' '); - //client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); - //client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); - //client.RunCommand($"kill -9 {cmdResultArry443[3]}"); - sshShellCommand = $"systemctl stop {cmdResultArry443[0]}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"systemctl disable {cmdResultArry443[0]}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"kill -9 {cmdResultArry443[3]}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - - //cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; - //cmdResult = client.RunCommand(cmdTestPort).Result; - if (String.IsNullOrEmpty(testPort80) == false) - { - string[] cmdResultArry80 = testPort80.Split(' '); - //client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); - //client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); - //client.RunCommand($"kill -9 {cmdResultArry80[3]}"); - sshShellCommand = $"systemctl stop {cmdResultArry80[0]}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"systemctl disable {cmdResultArry80[0]}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"kill -9 {cmdResultArry80[3]}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - currentStatus = "80/443端口释放完毕!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - } - else - { - currentStatus = "检测结果:未被占用!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - - currentStatus = "系统环境检测完毕,符合安装要求,开始布署......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //打开防火墙端口 - currentStatus = "开启防火墙相应端口......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false) - { - - //client.RunCommand("firewall-cmd --zone=public --add-port=80/tcp --permanent"); - //client.RunCommand("firewall-cmd --zone=public --add-port=443/tcp --permanent"); - //client.RunCommand("firewall-cmd --reload"); - sshShellCommand = @"firewall-cmd --zone=public --add-port=80/tcp --permanent"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"firewall-cmd --zone=public --add-port=443/tcp --permanent"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"yes | firewall-cmd --reload"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - if (String.IsNullOrEmpty(client.RunCommand("command -v ufw").Result) == false) - { - //client.RunCommand("ufw allow 80"); - //client.RunCommand("ufw allow 443"); - //client.RunCommand("yes | ufw reload"); - - sshShellCommand = @"ufw allow 80"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"ufw allow 443"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"yes | ufw reload"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - - //下载安装脚本安装 - currentStatus = "正在安装Trojan-go......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //client.RunCommand("curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"); - //client.RunCommand("yes | bash /tmp/trojan-go.sh -f"); - - sshShellCommand = @"curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"yes | bash /tmp/trojan-go.sh -f"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"find / -name trojan-go"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string installResult = currentShellCommandResult; - - if (!installResult.Contains("/usr/local/bin/trojan-go")) - { - MessageBox.Show("安装Trojan-Go失败(安装脚本运行出错!"); - - currentStatus = "安装Trojan-Go失败(安装脚本运行出错!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - client.Disconnect(); - return; - } - else - { - currentStatus = "Trojan-Go安装成功!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - //client.RunCommand("systemctl enable trojan-go"); - sshShellCommand = @"systemctl enable trojan-go"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - //client.RunCommand("mv /etc/trojan-go/config.json /etc/trojan-go/config.json.1"); - sshShellCommand = @"mv /etc/trojan-go/config.json /etc/trojan-go/config.json.1"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - - //上传配置文件 - currentStatus = "Trojan-Go程序安装完毕,配置文件上传中......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //生成服务端配置 - using (StreamReader reader = File.OpenText(serverConfig)) - { - JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - serverJson["run_type"] = "server"; - serverJson["local_addr"] = "0.0.0.0"; - serverJson["local_port"] = 443; - serverJson["remote_addr"] = "127.0.0.1"; - serverJson["remote_port"] = 88; - //设置密码 - serverJson["password"][0] = ReceiveConfigurationParameters[2]; - //设置证书 - serverJson["ssl"]["cert"] = "/usr/local/etc/trojan-go/trojan-go.crt"; - serverJson["ssl"]["key"] = "/usr/local/etc/trojan-go/trojan-go.key"; - //serverJson["ssl"]["sni"] = ReceiveConfigurationParameters[4]; - - if (String.Equals(ReceiveConfigurationParameters[0], "TrojanGoWebSocketTLS2Web")) - { - serverJson["websocket"]["enabled"] = true; - serverJson["websocket"]["path"] = ReceiveConfigurationParameters[3]; - } - - using (StreamWriter sw = new StreamWriter(@"config.json")) - { - sw.Write(serverJson.ToString()); - } - } - upLoadPath = "/usr/local/etc/trojan-go/config.json"; - UploadConfig(connectionInfo, @"config.json", upLoadPath); - - File.Delete(@"config.json"); - - currentStatus = "正在安装acme.sh......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //安装所依赖的软件 - sshShellCommand = $"{sshCmdUpdate}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = $"{sshCmdInstall}socat"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //if (getApt == false) - //{ - // //client.RunCommand("apt-get -qq update"); - // client.RunCommand("apt-get -y -qq install socat"); - //} - //else if (getDnf == false) - //{ - // //client.RunCommand("yum -q makecache"); - // client.RunCommand("dnf -y -q install socat"); - //} - //else if (getYum == false) - //{ - // //client.RunCommand("yum -q makecache"); - // client.RunCommand("yum -y -q install socat"); - //} - //else if (getZypper == false) - //{ - // // client.RunCommand("zypper ref"); - // client.RunCommand("zypper -y install socat"); - //} - //client.RunCommand("curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"); - //client.RunCommand("cd ~/.acme.sh/"); - //client.RunCommand("alias acme.sh=~/.acme.sh/acme.sh"); - - sshShellCommand = @"curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | INSTALLONLINE=1 sh"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"cd ~/.acme.sh/"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"alias acme.sh=~/.acme.sh/acme.sh"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - - currentStatus = "申请域名证书......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //client.RunCommand("mkdir -p /etc/v2ray/ssl"); - //client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"); - sshShellCommand = $"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - currentStatus = "安装证书到Trojan-Go......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - //client.RunCommand($"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan-go/trojan-go.crt --keypath /usr/local/etc/trojan-go/trojan-go.key --capath /usr/local/etc/trojan-go/trojan-go.crt --reloadcmd \"systemctl restart trojan-go\""); - sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan-go/trojan-go.crt --keypath /usr/local/etc/trojan-go/trojan-go.key --capath /usr/local/etc/trojan-go/trojan-go.crt --reloadcmd \"systemctl restart trojan-go\""; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //安装Caddy - currentStatus = "正在安装Caddy"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //安装Caddy - //为假则表示系统有相应的组件。 - if (getApt == false) - { - //client.RunCommand(@"echo ""deb [trusted=yes] https://apt.fury.io/caddy/ /"" | tee -a /etc/apt/sources.list.d/caddy-fury.list"); - //client.RunCommand("apt install -y apt-transport-https"); - //client.RunCommand("apt -qq update"); - //client.RunCommand("apt -y -qq install caddy"); - sshShellCommand = @"echo ""deb [trusted=yes] https://apt.fury.io/caddy/ /"" | tee -a /etc/apt/sources.list.d/caddy-fury.list"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"apt install -y apt-transport-https"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"apt -qq update"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"apt -y -qq install caddy"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - else if (getDnf == false) - { - //client.RunCommand(@"dnf install 'dnf-command(copr)' -y"); - //client.RunCommand(@"dnf copr enable @caddy/caddy -y"); - ////client.RunCommand("dnf -q makecache"); - //client.RunCommand("dnf -y -q install caddy"); - sshShellCommand = @"dnf install 'dnf-command(copr)' -y"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"dnf copr enable @caddy/caddy -y"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //sshShellCommand = @"dnf -q makecache"; - //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"dnf -y -q install caddy"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - else if (getYum == false) - { - //client.RunCommand(@"yum install yum-plugin-copr -y"); - //client.RunCommand(@"yum copr enable @caddy/caddy -y"); - ////client.RunCommand("yum -q makecache"); - //client.RunCommand("yum -y -q install caddy"); - sshShellCommand = @"yum install yum-plugin-copr -y"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"yum copr enable @caddy/caddy -y"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //sshShellCommand = @"yum -q makecache"; - //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"yum -y -q install caddy"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - - sshShellCommand = @"find / -name caddy"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - installResult = currentShellCommandResult; - - if (!installResult.Contains("/usr/bin/caddy")) - { - MessageBox.Show("安装Caddy失败!"); - - currentStatus = "安装Caddy失败!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - client.Disconnect(); - return; - } - - currentStatus = "Caddy安装成功!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - // client.RunCommand("systemctl enable caddy"); - sshShellCommand = @"systemctl enable caddy"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - - - currentStatus = "上传Caddy配置文件......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //client.RunCommand("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak");//备份原文件 - sshShellCommand = @"mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - - string caddyConfig = "TemplateConfg\\trojan_caddy_config.caddyfile"; - - upLoadPath = "/etc/caddy/Caddyfile"; - UploadConfig(connectionInfo, caddyConfig, upLoadPath); - - //设置Caddyfile文件中的tls 邮箱 - - //string email = $"user@{ReceiveConfigurationParameters[4]}"; - //设置域名 - //string sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; - sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //client.RunCommand(sshCmd); - //设置伪装网站 - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false) - { - // sshCmd = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; - //client.RunCommand(sshCmd); - sshShellCommand = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - } - currentStatus = "Caddy配置文件上传成功,OK!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //安装Caddy服务 - //sshCmd = $"caddy -service install -agree -conf /etc/caddy/Caddyfile -email {email}"; - //client.RunCommand(sshCmd); - //启动Caddy服务 - currentStatus = "正在启动Caddy......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - //启动Caddy服务 - //client.RunCommand("systemctl restart caddy"); - sshShellCommand = @"systemctl restart caddy"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - - currentStatus = "Caddy启动成功!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - currentStatus = "正在启动Trojan-Go......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - //启动Trojan-go服务 - //client.RunCommand("systemctl restart trojan-go"); - sshShellCommand = @"systemctl restart trojan-go"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - - currentStatus = "Trojan-go启动成功!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //测试BBR条件,若满足提示是否启用 - currentStatus = "BBR测试......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //var result = client.RunCommand("uname -r"); - sshShellCommand = @"uname -r"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string[] linuxKernelVerStr = currentShellCommandResult.Split('-'); - - bool detectResult = DetectKernelVersionBBR(linuxKernelVerStr[0]); - //client.RunCommand(@"sysctl net.ipv4.tcp_congestion_control | grep bbr").Result; - sshShellCommand = @"sysctl net.ipv4.tcp_congestion_control | grep bbr"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - string resultCmdTestBBR = currentShellCommandResult; - //如果内核满足大于等于4.9,且还未启用BBR,则启用BBR - if (detectResult == true && resultCmdTestBBR.Contains("bbr") == false) - { - currentStatus = "正在启用BBR......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //client.RunCommand(@"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"); - //client.RunCommand(@"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"); - //client.RunCommand(@"sysctl -p"); - sshShellCommand = @"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"sysctl -p"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - else if (resultCmdTestBBR.Contains("bbr") == true) - { - currentStatus = "BBR已经启用了!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - else - { - currentStatus = "系统不满足启用BBR的条件,启用失败!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - - client.Disconnect();//断开服务器ssh连接 - - ////测试BBR条件,若满足提示是否启用 - //var result = client.RunCommand("uname -r"); - ////var result = client.RunCommand("cat /root/test.ver"); - //string[] linuxKernelVerStr = result.Result.Split('-'); - - //bool detectResult = DetectKernelVersionBBR(linuxKernelVerStr[0]); - //string resultCmdTestBBR = client.RunCommand(@"sysctl net.ipv4.tcp_congestion_control | grep bbr").Result; - ////如果内核满足大于等于4.9,且还未启用BBR,则启用BBR - //if (detectResult == true && resultCmdTestBBR.Contains("bbr") == false) - //{ - // client.RunCommand(@"bash -c 'echo ""net.core.default_qdisc=fq"" >> /etc/sysctl.conf'"); - // client.RunCommand(@"bash -c 'echo ""net.ipv4.tcp_congestion_control=bbr"" >> /etc/sysctl.conf'"); - // client.RunCommand(@"sysctl -p"); - //} - - //生成客户端配置 - currentStatus = "生成客户端配置......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - if (!Directory.Exists("trojan-go_config"))//如果不存在就创建file文件夹      - { - Directory.CreateDirectory("trojan-go_config");//创建该文件夹   - } - clientConfig = "TemplateConfg\\trojan-go_all_config.json"; - using (StreamReader reader = File.OpenText(clientConfig)) - { - JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); - clientJson["run_type"] = "client"; - clientJson["local_addr"] = "127.0.0.1"; - clientJson["local_port"] = 1080; - clientJson["remote_addr"] = ReceiveConfigurationParameters[4]; - clientJson["remote_port"] = 443; - //设置密码 - clientJson["password"][0] = ReceiveConfigurationParameters[2]; - //如果是WebSocket协议则设置路径 - if (String.Equals(ReceiveConfigurationParameters[0], "TrojanGoWebSocketTLS2Web")) - { - clientJson["websocket"]["enabled"] = true; - clientJson["websocket"]["path"] = ReceiveConfigurationParameters[3]; - } - - using (StreamWriter sw = new StreamWriter(@"trojan-go_config\config.json")) - { - sw.Write(clientJson.ToString()); - } - } - - - - currentStatus = "Trojan-go安装成功,祝您使用愉快!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //显示服务端连接参数 - //MessageBox.Show("用于Trojan官方客户端的配置文件已保存在config文件夹中"); - TrojanGoResultClientInfoWindow resultClientInformation = new TrojanGoResultClientInfoWindow(); - resultClientInformation.ShowDialog(); - - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - //MessageBox.Show(ex1.Message); - if (ex1.Message.Contains("连接尝试失败") == true) - { - MessageBox.Show($"{ex1.Message}\n请检查主机地址及端口是否正确,如果通过代理,请检查代理是否正常工作"); - } - - else if (ex1.Message.Contains("denied (password)") == true) - { - MessageBox.Show($"{ex1.Message}\n密码错误或用户名错误"); - } - else if (ex1.Message.Contains("Invalid private key file") == true) - { - MessageBox.Show($"{ex1.Message}\n所选密钥文件错误或者格式不对"); - } - else if (ex1.Message.Contains("denied (publickey)") == true) - { - MessageBox.Show($"{ex1.Message}\n使用密钥登录,密钥文件错误或用户名错误"); - } - else if (ex1.Message.Contains("目标计算机积极拒绝") == true) - { - MessageBox.Show($"{ex1.Message}\n主机地址错误,如果使用了代理,也可能是连接代理的端口错误"); - } - else - { - MessageBox.Show("发生错误"); - MessageBox.Show(ex1.Message); - } - currentStatus = "主机登录失败"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - #endregion - - } - - //检测升级Trojan-Go版本传递参数 - private void ButtonUpdateTrojanGo_Click(object sender, RoutedEventArgs e) - { - ConnectionInfo connectionInfo = GenerateConnectionInfo(); - if (connectionInfo == null) - { - MessageBox.Show("远程主机连接信息有误,请检查"); - return; - } - - Thread thread = new Thread(() => UpdateTojanGo(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - } - - //升级Trojan-go主程序 - private void UpdateTojanGo(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar) - { - string currentStatus = "正在登录远程主机......"; - //Action updateAction = new Action(UpdateTextBlock); - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - try - { - #region 主机指纹,暂未启用 - //byte[] expectedFingerPrint = new byte[] { - // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - // }; - #endregion - using (var client = new SshClient(connectionInfo)) - - { - #region ssh登录验证主机指纹代码块,暂未启用 - // client.HostKeyReceived += (sender, e) => - // { - // if (expectedFingerPrint.Length == e.FingerPrint.Length) - // { - // for (var i = 0; i < expectedFingerPrint.Length; i++) - // { - // if (expectedFingerPrint[i] != e.FingerPrint[i]) - // { - // e.CanTrust = false; - // break; - // } - // } - // } - // else - // { - // e.CanTrust = false; - // } - // }; - #endregion - - client.Connect(); - if (client.IsConnected == true) - { - currentStatus = "主机登录成功"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 - - Thread.Sleep(1000); - } - //检测是否运行在root权限下 - currentShellCommandResult = "检测是否运行在root权限下..."; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"id -u"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string testRootAuthority = currentShellCommandResult; - if (testRootAuthority.Equals("0\n") == false) - { - MessageBox.Show("请使用具有root权限的账户登录主机!!"); - client.Disconnect(); - return; - } - else - { - currentShellCommandResult = "检测结果:OK!"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - ////检测是否运行在root权限下 - //string testRootAuthority = client.RunCommand(@"id -u").Result; - //if (testRootAuthority.Equals("0\n") == false) - //{ - // MessageBox.Show("请使用具有root权限的账户登录主机!!"); - // client.Disconnect(); - // return; - //} - //检测当前安装的版本 - currentStatus = "检测远程主机Trojan-Go版本......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //string cmdTestTrojanInstalled = @"find / -name trojan-go"; - - sshShellCommand = @"find / -name trojan-go"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - string resultCmdTestTrojanInstalled = currentShellCommandResult; - - if (resultCmdTestTrojanInstalled.Contains("/usr/local/bin/trojan-go") == false) - { - MessageBoxResult messageBoxResult = MessageBox.Show("远程主机未安装Trojan-Go!"); - - currentStatus = "未安装Trojan-Go,退出"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - client.Disconnect(); - return; - - } - //获取当前安装的版本 - //string sshcmd = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; - sshShellCommand = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string trojanCurrentVersion = currentShellCommandResult;//含字母v - //获取最新版本 - //sshcmd = @"curl -s https://api.github.com/repos/p4gefau1t/trojan-go/tags | grep 'name' | cut -d\"" -f4 | head -1"; - sshShellCommand = @"curl -s https://api.github.com/repos/p4gefau1t/trojan-go/tags | grep 'name' | cut -d\"" -f4 | head -1"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - string trojanNewVersion = currentShellCommandResult;//含字母v - - if (trojanNewVersion.Equals(trojanCurrentVersion) == false) - { - MessageBoxResult messageBoxResult = MessageBox.Show($"远程主机当前版本为:v{trojanCurrentVersion}\n最新版本为:{trojanNewVersion}\n是否升级为最新版本?", "", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (messageBoxResult == MessageBoxResult.Yes) - { - currentStatus = "正在升级Trojan-Go到最新版本......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - - //备份配置文件 - //sshcmd = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.bak"; - //client.RunCommand(sshcmd); - //升级Trojan-Go主程序 - //client.RunCommand("curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"); - //client.RunCommand("yes | bash /tmp/trojan-go.sh -f"); - sshShellCommand = @"curl -o /tmp/trojan-go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/trojan-go.sh"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - sshShellCommand = @"yes | bash /tmp/trojan-go.sh -f"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - //获取升级后的版本 - //sshcmd = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; - sshShellCommand = @"echo ""$(/usr/local/bin/trojan-go -version)"" | head -n 1 | cut -d "" "" -f2"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - trojanCurrentVersion = currentShellCommandResult;//含字母v - if (trojanNewVersion.Equals(trojanCurrentVersion) == true) - { - //恢复原来的配置文件备份 - //sshcmd = @"rm -f /usr/local/etc/trojan/config.json"; - //client.RunCommand(sshcmd); - //sshcmd = @"mv /usr/local/etc/trojan/config.json.bak /usr/local/etc/trojan/config.json"; - //client.RunCommand(sshcmd); - MessageBox.Show($"升级成功!!\n当前版本为:v{trojanCurrentVersion}\n最新版本为:{trojanNewVersion}"); - currentStatus = "升级成功!当前已是最新版本!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - } - else - { - MessageBox.Show("升级失败,原因未知,请向开发者提问,以寻求支持!"); - currentStatus = "升级失败!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - client.Disconnect(); - return; - } - } - - else - { - currentStatus = "升级取消,退出"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - client.Disconnect(); - return; - } - } - else - { - MessageBox.Show($"远程主机当前已是最新版本:{trojanNewVersion}\n无需升级!"); - currentStatus = "已是最新版本,无需升级,退出"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - Thread.Sleep(1000); - } - - client.Disconnect(); - return; - } - } - catch (Exception ex1)//例外处理 - #region 例外处理 - { - //MessageBox.Show(ex1.Message); - if (ex1.Message.Contains("连接尝试失败") == true) - { - MessageBox.Show($"{ex1.Message}\n请检查主机地址及端口是否正确,如果通过代理,请检查代理是否正常工作"); - } - - else if (ex1.Message.Contains("denied (password)") == true) - { - MessageBox.Show($"{ex1.Message}\n密码错误或用户名错误"); - } - else if (ex1.Message.Contains("Invalid private key file") == true) - { - MessageBox.Show($"{ex1.Message}\n所选密钥文件错误或者格式不对"); - } - else if (ex1.Message.Contains("denied (publickey)") == true) - { - MessageBox.Show($"{ex1.Message}\n使用密钥登录,密钥文件错误或用户名错误"); - } - else if (ex1.Message.Contains("目标计算机积极拒绝") == true) - { - MessageBox.Show($"{ex1.Message}\n主机地址错误,如果使用了代理,也可能是连接代理的端口错误"); - } - else - { - MessageBox.Show("发生错误"); - MessageBox.Show(ex1.Message); - } - currentStatus = "主机登录失败"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - - } - #endregion - - } - #endregion - #region NaiveProxy相关 //NaiveProxy一键安装开始传递参数 @@ -6564,7 +6596,7 @@ namespace ProxySU } client.Disconnect(); - currentStatus = "NaiveProxy安装成功!祝您使用愉快!"; + currentStatus = "NaiveProxy安装成功!祝你玩的愉快!!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); currentShellCommandResult = currentStatus; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 @@ -6572,8 +6604,10 @@ namespace ProxySU Thread.Sleep(1000); //显示服务端连接参数 - //MessageBox.Show("用于Trojan官方客户端的配置文件已保存在config文件夹中"); - NaiveProxyResultInfoWindow resultClientInformation = new NaiveProxyResultInfoWindow(); + proxyType = "NaiveProxy"; + //NaiveProxyResultInfoWindow resultClientInformation = new NaiveProxyResultInfoWindow(); + //resultClientInformation.ShowDialog(); + ResultClientInformation resultClientInformation = new ResultClientInformation(); resultClientInformation.ShowDialog(); return; } @@ -8084,7 +8118,8 @@ namespace ProxySU } #endregion - + + } } diff --git a/ProxySU/NaiveProxyResultInfoWindow.xaml b/ProxySU/NaiveProxyResultInfoWindow.xaml deleted file mode 100644 index ab1b958..0000000 --- a/ProxySU/NaiveProxyResultInfoWindow.xaml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/NaiveProxyResultInfoWindow.xaml.cs b/ProxySU/NaiveProxyResultInfoWindow.xaml.cs deleted file mode 100644 index 22c7424..0000000 --- a/ProxySU/NaiveProxyResultInfoWindow.xaml.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -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; -using System.IO; -using Renci.SshNet; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System.Drawing; -using QRCoder; -namespace ProxySU -{ - /// - /// NaiveProxyResultInfoWindow.xaml 的交互逻辑 - /// - public partial class NaiveProxyResultInfoWindow : Window - { - private string saveFileFolder = ""; - public NaiveProxyResultInfoWindow() - { - InitializeComponent(); - TextBoxNaiveServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxNaiveUser.Text = MainWindow.ReceiveConfigurationParameters[3]; - TextBoxNaivePassword.Text= MainWindow.ReceiveConfigurationParameters[2]; - GenerateV2rayShareQRcodeAndBase64Url(); - } - - private void GenerateV2rayShareQRcodeAndBase64Url() - { - - string saveFileFolderFirst = TextBoxNaiveServerHost.Text; - int num = 1; - saveFileFolder = saveFileFolderFirst; - CheckDir("naive_config"); - while (Directory.Exists(@"naive_config\" + saveFileFolder)) - { - saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - num++; - } - CheckDir(@"naive_config\" + saveFileFolder); - string naiveUrl = $"https://{TextBoxNaiveUser.Text}:{TextBoxNaivePassword.Text}@{TextBoxNaiveServerHost.Text}:443/?name={TextBoxNaiveServerHost.Text}&padding=true"; - //MessageBox.Show(v2rayNjsonObject.ToString()); - //string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString()); - TextBoxNaiveGUIurl.Text = naiveUrl; - using (StreamWriter sw = new StreamWriter($"naive_config\\{saveFileFolder}\\url.txt")) - { - sw.WriteLine(naiveUrl); - - } - //CreateQRCode(trojanUrl); - - //移动NaiveProxy官方程序配置文件到相应目录 - if (File.Exists(@"naive_config\config.json")) - { - File.Move(@"naive_config\config.json", @"naive_config\" + saveFileFolder + @"\config.json"); - //File.Delete(@"config\config.json");//删除该文件 - } - - using (StreamWriter sw = new StreamWriter($"naive_config\\{saveFileFolder}\\说明.txt")) - { - sw.WriteLine("config.json"); - sw.WriteLine("此文件为NaiveProxy官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080"); - sw.WriteLine("NaiveProxy官方网站:https://github.com/klzgrad/naiveproxy"); - sw.WriteLine("NaiveProxy官方程序下载地址:https://github.com/klzgrad/naiveproxy/releases"); - sw.WriteLine("下载相应版本,Windows选择naiveproxy-x.xx-win.zip,解压后提取naive.exe。与config.json放在同一目录,运行naive.exe即可。"); - sw.WriteLine("-----------------------------------------\n"); - //sw.WriteLine("其他平台的客户端,暂未发布"); - //sw.WriteLine("QR.bmp"); - //sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点"); - //sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); - //sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); - //sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); - - //sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("url.txt"); - sw.WriteLine("此文件为NaiveGUI(windows)复制粘贴导入节点的网址"); - sw.WriteLine("NaiveGUI(windows)下载网址:https://github.com/ExcitedCodes/NaiveGUI/releases"); - - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("服务器通用连接配置参数"); - sw.WriteLine($"地址(address):{TextBoxNaiveServerHost.Text}"); - sw.WriteLine($"用户名:{TextBoxNaiveUser.Text}"); - sw.WriteLine($"密钥:{TextBoxNaivePassword.Text}"); - - } - - } - - //判断目录是否存在,不存在则创建 - private static bool CheckDir(string folder) - { - try - { - if (!Directory.Exists(folder))//如果不存在就创建file文件夹 - Directory.CreateDirectory(folder);//创建该文件夹   - return true; - } - catch (Exception) - { - return false; - } - } - private void ButtonOpenDir_Click(object sender, RoutedEventArgs e) - { - string openFolderPath = @"naive_config\" + saveFileFolder; - System.Diagnostics.Process.Start("explorer.exe", openFolderPath); - this.Close(); - } - } -} diff --git a/ProxySU/ProxySU.csproj b/ProxySU/ProxySU.csproj index 5eeaa37..ec40860 100644 --- a/ProxySU/ProxySU.csproj +++ b/ProxySU/ProxySU.csproj @@ -81,27 +81,18 @@ MSBuild:Compile Designer - - NaiveProxyResultInfoWindow.xaml - ProofreadTimeWindow.xaml ResultClientInformation.xaml - - TemplateConfiguration.xaml - - - TrojanGoResultClientInfoWindow.xaml + + V2RayTemplateWindow.xaml TrojanGoTemplateWindow.xaml - - TrojanResultClientInfoWindow.xaml - MSBuild:Compile Designer @@ -114,10 +105,6 @@ MainWindow.xaml Code - - Designer - MSBuild:Compile - Designer MSBuild:Compile @@ -126,11 +113,7 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - - + Designer MSBuild:Compile @@ -138,10 +121,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - diff --git a/ProxySU/ResultClientInformation.xaml b/ProxySU/ResultClientInformation.xaml index 2a2b55d..adaeb31 100644 --- a/ProxySU/ResultClientInformation.xaml +++ b/ProxySU/ResultClientInformation.xaml @@ -7,8 +7,13 @@ mc:Ignorable="d" Title="ResultClientInformation" Height="650" Width="600"> - - + + + + + + + @@ -26,14 +31,7 @@ - - - - - - - - + @@ -44,9 +42,9 @@ - + - + @@ -70,21 +68,149 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProxySU/ResultClientInformation.xaml.cs b/ProxySU/ResultClientInformation.xaml.cs index ffb2912..a69a2ff 100644 --- a/ProxySU/ResultClientInformation.xaml.cs +++ b/ProxySU/ResultClientInformation.xaml.cs @@ -31,236 +31,323 @@ namespace ProxySU { InitializeComponent(); - //主机端口 - TextBoxPort.Text = MainWindow.ReceiveConfigurationParameters[1]; - //用户ID(uuid) - TextBoxUUID.Text = MainWindow.ReceiveConfigurationParameters[2]; - //额外ID - TextBoxUUIDextra.Text = "16"; - //路径Path - TextBoxPath.Text = MainWindow.ReceiveConfigurationParameters[3]; - //主机地址 - TextBoxHostAddress.Text = MainWindow.ReceiveConfigurationParameters[4]; - //TLS的Host - TextBoxHost.Text = ""; - //加密方式,一般都为auto - TextBoxEncryption.Text = "auto"; - //伪装类型 - TextBoxCamouflageType.Text = MainWindow.ReceiveConfigurationParameters[5]; - //QUIC密钥 - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + if (String.Equals(MainWindow.proxyType, "V2Ray")) + { + GroupBoxV2rayClient.Visibility = Visibility.Visible; + GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; + GroupBoxTrojanClient.Visibility = Visibility.Collapsed; + GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; + //主机地址 + TextBoxHostAddress.Text = MainWindow.ReceiveConfigurationParameters[4]; + //主机端口 + TextBoxPort.Text = MainWindow.ReceiveConfigurationParameters[1]; + //用户ID(uuid) + TextBoxUUID.Text = MainWindow.ReceiveConfigurationParameters[2]; + //额外ID + TextBoxUUIDextra.Text = "16"; + //加密方式,一般都为auto + TextBoxEncryption.Text = "auto"; + //传输协议 + TextBoxTransmission.Text = ""; + //伪装类型 + TextBoxCamouflageType.Text = MainWindow.ReceiveConfigurationParameters[5]; + //是否启用TLS + TextBoxTLS.Text = "none"; + //TLS的Host + TextBoxHost.Text = ""; + //路径Path + TextBoxPath.Text = MainWindow.ReceiveConfigurationParameters[3]; + //QUIC密钥 + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLS2Web")) - { - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "tls"; - ShowPath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "TCP")) - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "none"; - HidePath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "TCPhttp")) - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "http"; - TextBoxTLS.Text = "none"; - HidePath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "tcpTLS")) - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "tls"; - HidePath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "tcpTLSselfSigned")) - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "tls"; - HidePath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "webSocket")) - { - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "none"; - HidePath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLS")) - { - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "tls"; - ShowPath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned")) - { - TextBoxTransmission.Text = "ws"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "tls"; - ShowPath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "Http2")) - { - TextBoxTransmission.Text = "h2"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "tls"; - ShowPath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "http2Web")) - { - TextBoxTransmission.Text = "h2"; - TextBoxCamouflageType.Text = "none"; - TextBoxHost.Text = MainWindow.ReceiveConfigurationParameters[4]; - TextBoxTLS.Text = "tls"; - ShowPath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "http2selfSigned")) - { - TextBoxTransmission.Text = "h2"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "tls"; - ShowPath(); - HideQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCPNone")) - { - TextBoxTransmission.Text = "kcp"; - TextBoxCamouflageType.Text = "none"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2SRTP")) - { - TextBoxTransmission.Text = "kcp"; - TextBoxCamouflageType.Text = "srtp"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCPuTP")) - { - TextBoxTransmission.Text = "kcp"; - TextBoxCamouflageType.Text = "utp"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2WechatVideo")) - { - TextBoxTransmission.Text = "kcp"; - TextBoxCamouflageType.Text = "wechat-video"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2DTLS")) - { - TextBoxTransmission.Text = "kcp"; - TextBoxCamouflageType.Text = "dtls"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2WireGuard")) - { - TextBoxTransmission.Text = "kcp"; - TextBoxCamouflageType.Text = "wireguard"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicNone")) - { - TextBoxTransmission.Text = "quic"; - TextBoxCamouflageType.Text = "none"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicSRTP")) - { - TextBoxTransmission.Text = "quic"; - TextBoxCamouflageType.Text = "srtp"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "Quic2uTP")) - { - TextBoxTransmission.Text = "quic"; - TextBoxCamouflageType.Text = "utp"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicWechatVideo")) - { - TextBoxTransmission.Text = "quic"; - TextBoxCamouflageType.Text = "wechat-video"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicDTLS")) - { - TextBoxTransmission.Text = "quic"; - TextBoxCamouflageType.Text = "dtls"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } - else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicWireGuard")) - { - TextBoxTransmission.Text = "quic"; - TextBoxCamouflageType.Text = "wireguard"; - TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; - TextBoxTLS.Text = "none"; - HidePath(); - ShowQuicKey(); - } + if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLS2Web")) + { + TextBoxTransmission.Text = "ws"; //传输协议 + TextBoxCamouflageType.Text = "none"; //伪装类型 + TextBoxTLS.Text = "tls"; //是否启用TLS + ShowPath(); //显示路径 + HideQuicKey(); //隐藏Quic\mKCP密钥 + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "TCP")) + { + TextBoxTransmission.Text = "tcp"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "none"; + HidePath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "TCPhttp")) + { + TextBoxTransmission.Text = "tcp"; + TextBoxCamouflageType.Text = "http"; + TextBoxTLS.Text = "none"; + HidePath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "tcpTLS")) + { + TextBoxTransmission.Text = "tcp"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "tls"; + HidePath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "tcpTLSselfSigned")) + { + TextBoxTransmission.Text = "tcp"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "tls"; + HidePath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "VlessTcpTlsWeb")) + { + TextBoxTransmission.Text = "tcp"; + TextBoxCamouflageType.Text = "none"; + TextBoxEncryption.Text = "none"; + TextBoxTLS.Text = "tls"; + HideAlterId(); + HidePath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "webSocket")) + { + TextBoxTransmission.Text = "ws"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "none"; + HidePath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLS")) + { + TextBoxTransmission.Text = "ws"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "tls"; + ShowPath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "WebSocketTLSselfSigned")) + { + TextBoxTransmission.Text = "ws"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "tls"; + ShowPath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "Http2")) + { + TextBoxTransmission.Text = "h2"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "tls"; + ShowPath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "http2Web")) + { + TextBoxTransmission.Text = "h2"; + TextBoxCamouflageType.Text = "none"; + TextBoxHost.Text = MainWindow.ReceiveConfigurationParameters[4]; + TextBoxTLS.Text = "tls"; + ShowPath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "http2selfSigned")) + { + TextBoxTransmission.Text = "h2"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "tls"; + ShowPath(); + HideQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCPNone")) + { + TextBoxTransmission.Text = "kcp"; + TextBoxCamouflageType.Text = "none"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2SRTP")) + { + TextBoxTransmission.Text = "kcp"; + TextBoxCamouflageType.Text = "srtp"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCPuTP")) + { + TextBoxTransmission.Text = "kcp"; + TextBoxCamouflageType.Text = "utp"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2WechatVideo")) + { + TextBoxTransmission.Text = "kcp"; + TextBoxCamouflageType.Text = "wechat-video"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2DTLS")) + { + TextBoxTransmission.Text = "kcp"; + TextBoxCamouflageType.Text = "dtls"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "mKCP2WireGuard")) + { + TextBoxTransmission.Text = "kcp"; + TextBoxCamouflageType.Text = "wireguard"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicNone")) + { + TextBoxTransmission.Text = "quic"; + TextBoxCamouflageType.Text = "none"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicSRTP")) + { + TextBoxTransmission.Text = "quic"; + TextBoxCamouflageType.Text = "srtp"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "Quic2uTP")) + { + TextBoxTransmission.Text = "quic"; + TextBoxCamouflageType.Text = "utp"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicWechatVideo")) + { + TextBoxTransmission.Text = "quic"; + TextBoxCamouflageType.Text = "wechat-video"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicDTLS")) + { + TextBoxTransmission.Text = "quic"; + TextBoxCamouflageType.Text = "dtls"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } + else if (String.Equals(MainWindow.ReceiveConfigurationParameters[0], "QuicWireGuard")) + { + TextBoxTransmission.Text = "quic"; + TextBoxCamouflageType.Text = "wireguard"; + TextBoxQuicKey.Text = MainWindow.ReceiveConfigurationParameters[6]; + TextBoxTLS.Text = "none"; + HidePath(); + ShowQuicKey(); + } - else - { - TextBoxTransmission.Text = "tcp"; - TextBoxCamouflageType.Text = "none"; - TextBoxTLS.Text = "none"; - HidePath(); - HideQuicKey(); + else + { + TextBoxTransmission.Text = "tcp"; + TextBoxCamouflageType.Text = "none"; + TextBoxTLS.Text = "none"; + HidePath(); + HideQuicKey(); + } + CheckDir("v2ray_config"); + + GenerateV2rayShareQRcodeAndBase64Url(); } - CheckDir("v2ray_config"); + else if (String.Equals(MainWindow.proxyType, "TrojanGo")) + { + //GroupBoxTrojanClient.Header = "Trojan-go 客户端配置参数"; + GroupBoxV2rayClient.Visibility = Visibility.Collapsed; + GroupBoxTrojanGoClient.Visibility = Visibility.Visible; + GroupBoxTrojanClient.Visibility = Visibility.Collapsed; + GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; - GenerateV2rayShareQRcodeAndBase64Url(); + TextBoxTrojanGoWSPath.Visibility = Visibility.Hidden; + TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Hidden; + TextBlockTrojanGoCaption.Visibility = Visibility.Hidden; + TextBlockQrURLexplain.Text = "可用于ShadowRocket (ios)、igniter(Android)、Trojan-QT5 (windows) 扫码和导入url"; + + //主机地址 + TextBoxTrojanGoServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; + //主机端口 + TextBoxTrojanGoServerPort.Text = "443"; + //密钥(uuid) + TextBoxTrojanGoServerPassword.Text = MainWindow.ReceiveConfigurationParameters[2]; + //WebSocket路径 + if (MainWindow.ReceiveConfigurationParameters[0].Equals("TrojanGoWebSocketTLS2Web")) + { + TextBoxTrojanGoWSPath.Text = MainWindow.ReceiveConfigurationParameters[3]; + TextBoxTrojanGoWSPath.Visibility = Visibility.Visible; + TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Visible; + TextBlockTrojanGoCaption.Visibility = Visibility.Visible; + + } + CheckDir("trojan-go_config"); + GenerateTrojanGoShareQRcodeAndBase64Url(); + } + else if (String.Equals(MainWindow.proxyType, "Trojan")) + { + GroupBoxV2rayClient.Visibility = Visibility.Collapsed; + GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; + GroupBoxTrojanClient.Visibility = Visibility.Visible; + GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; + + //主机地址 + TextBoxTrojanServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; + //主机端口 + TextBoxTrojanServerPort.Text = "443"; + //密钥(uuid) + TextBoxTrojanServerPassword.Text = MainWindow.ReceiveConfigurationParameters[2]; + + TextBlockQrURLexplain.Text = "可用于ShadowRocket (ios)、igniter(Android)、Trojan-QT5 (windows) 扫码和导入url"; + + CheckDir("trojan_config"); + GenerateTrojanShareQRcodeAndBase64Url(); + } + else if (String.Equals(MainWindow.proxyType, "NaiveProxy")) + { + GroupBoxV2rayClient.Visibility = Visibility.Collapsed; + GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; + GroupBoxTrojanClient.Visibility = Visibility.Collapsed; + GroupBoxNaiveProxyClient.Visibility = Visibility.Visible; + + TextBlockQrURLexplain.Text = "用于NaiveGUI(windows)的URL导入链接"; + + TextBoxNaiveServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; + TextBoxNaiveUser.Text = MainWindow.ReceiveConfigurationParameters[3]; + TextBoxNaivePassword.Text = MainWindow.ReceiveConfigurationParameters[2]; + GenerateNaivePrxoyShareQRcodeAndBase64Url(); + } + } + #region 界面控制相关 private void HidePath() { TextBlockPath.Visibility = Visibility.Collapsed; @@ -281,6 +368,20 @@ namespace ProxySU TextBoxQuicKey.Visibility = Visibility.Collapsed; TextBlockQuicKeyExplain.Visibility = Visibility.Collapsed; + } + private void ShowAlterId() + { + TextBlockUUIDextra.Visibility = Visibility.Visible; + TextBoxUUIDextra.Visibility = Visibility.Visible; + TextBlockUUIDextraExplanation.Visibility = Visibility.Visible; + + } + private void HideAlterId() + { + TextBlockUUIDextra.Visibility = Visibility.Collapsed; + TextBoxUUIDextra.Visibility = Visibility.Collapsed; + TextBlockUUIDextraExplanation.Visibility = Visibility.Collapsed; + } private void ShowQuicKey() { @@ -289,6 +390,7 @@ namespace ProxySU TextBlockQuicKeyExplain.Visibility = Visibility.Visible; } + #endregion //生成v2rayN客户端导入文件 private void GenerateV2rayShareQRcodeAndBase64Url() { @@ -344,13 +446,13 @@ namespace ProxySU CheckDir(@"v2ray_config\" + saveFileFolder); //MessageBox.Show(v2rayNjsonObject.ToString()); string vmessUrl = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); - TextBoxvVmessUrl.Text = vmessUrl; + TextBoxURL.Text = vmessUrl; using (StreamWriter sw = new StreamWriter($"v2ray_config\\{saveFileFolder}\\url.txt")) { sw.WriteLine(vmessUrl); } - CreateQRCode(vmessUrl); + CreateQRCode(vmessUrl,"v2ray_config"); if (File.Exists(@"v2ray_config\config.json")) { @@ -395,6 +497,190 @@ namespace ProxySU } + + //生成TrojanGo客户端资料 + private void GenerateTrojanGoShareQRcodeAndBase64Url() + { + + string saveFileFolderFirst = TextBoxTrojanServerHost.Text; + int num = 1; + saveFileFolder = saveFileFolderFirst; + CheckDir("trojan-go_config"); + while (Directory.Exists(@"trojan-go_config\" + saveFileFolder)) + { + saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); + num++; + } + CheckDir(@"trojan-go_config\" + saveFileFolder); + string trojanUrl = $"trojan://{TextBoxTrojanServerPassword.Text}@{TextBoxTrojanServerHost.Text}:{TextBoxTrojanServerPort.Text}?allowinsecure=0&tfo=0&sni=&mux=0&ws=0&group=#{TextBoxTrojanServerHost.Text}"; + //MessageBox.Show(v2rayNjsonObject.ToString()); + //string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString()); + TextBoxURL.Text = trojanUrl; + using (StreamWriter sw = new StreamWriter($"trojan-go_config\\{saveFileFolder}\\url.txt")) + { + sw.WriteLine(trojanUrl); + + } + CreateQRCode(trojanUrl, "trojan-go_config"); + + //移动Trojan官方程序配置文件到相应目录 + if (File.Exists(@"trojan-go_config\config.json")) + { + File.Move(@"trojan-go_config\config.json", @"trojan-go_config\" + saveFileFolder + @"\config.json"); + //File.Delete(@"config\config.json");//删除该文件 + } + + using (StreamWriter sw = new StreamWriter($"trojan-go_config\\{saveFileFolder}\\说明.txt")) + { + sw.WriteLine("config.json"); + sw.WriteLine("此文件为Trojan-go官方程序所使用的客户端配置文件,配置为全局模式,http与socks5地址:127.0.0.1:1080"); + sw.WriteLine("Trojan-go官方网站:https://github.com/p4gefau1t/trojan-go"); + sw.WriteLine("Trojan-go官方程序下载地址:https://github.com/p4gefau1t/trojan-go/releases"); + sw.WriteLine("下载相应版本,Windows选择Trojan-x.xx-win.zip,解压后提取trojan.exe。与config.json放在同一目录,运行trojan.exe即可。"); + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("QR.bmp"); + sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点(Trojan-Go的WebSocket模式暂不支持)"); + sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); + sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); + sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); + + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("url.txt"); + sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)复制粘贴导入节点的网址(Trojan-Go的WebSocket模式暂不支持)"); + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("服务器通用连接配置参数"); + sw.WriteLine($"地址(address):{TextBoxTrojanServerHost.Text}"); + sw.WriteLine($"端口(Port):{TextBoxTrojanServerPort.Text}"); + sw.WriteLine($"密钥:{TextBoxTrojanServerPassword.Text}"); + sw.WriteLine($"WebSocket路径:{TextBoxTrojanGoWSPath.Text}"); + + } + + } + + //生成Trojan客户端资料 + private void GenerateTrojanShareQRcodeAndBase64Url() + { + + string saveFileFolderFirst = TextBoxTrojanServerHost.Text; + int num = 1; + saveFileFolder = saveFileFolderFirst; + CheckDir("trojan_config"); + while (Directory.Exists(@"trojan_config\" + saveFileFolder)) + { + saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); + num++; + } + CheckDir(@"trojan_config\" + saveFileFolder); + string trojanUrl = $"trojan://{TextBoxTrojanServerPassword.Text}@{TextBoxTrojanServerHost.Text}:{TextBoxTrojanServerPort.Text}#{TextBoxTrojanServerHost.Text}"; + //MessageBox.Show(v2rayNjsonObject.ToString()); + //string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString()); + TextBoxURL.Text = trojanUrl; + using (StreamWriter sw = new StreamWriter($"trojan_config\\{saveFileFolder}\\url.txt")) + { + sw.WriteLine(trojanUrl); + + } + CreateQRCode(trojanUrl, "trojan_config"); + + //移动Trojan官方程序配置文件到相应目录 + if (File.Exists(@"trojan_config\config.json")) + { + File.Move(@"trojan_config\config.json", @"trojan_config\" + saveFileFolder + @"\config.json"); + //File.Delete(@"config\config.json");//删除该文件 + } + + using (StreamWriter sw = new StreamWriter($"trojan_config\\{saveFileFolder}\\说明.txt")) + { + sw.WriteLine("config.json"); + sw.WriteLine("此文件为Trojan官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080"); + sw.WriteLine("Trojan官方网站:https://trojan-gfw.github.io/trojan/"); + sw.WriteLine("Trojan官方程序下载地址:https://github.com/trojan-gfw/trojan/releases"); + sw.WriteLine("下载相应版本,Windows选择Trojan-x.xx-win.zip,解压后提取trojan.exe。与config.json放在同一目录,运行trojan.exe即可。"); + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("QR.bmp"); + sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点"); + sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); + sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); + sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); + + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("url.txt"); + sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)复制粘贴导入节点的网址"); + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("服务器通用连接配置参数"); + sw.WriteLine($"地址(address):{TextBoxTrojanServerHost.Text}"); + sw.WriteLine($"端口(Port):{TextBoxTrojanServerPort.Text}"); + sw.WriteLine($"密钥:{TextBoxTrojanServerPassword.Text}"); + + } + + + + } + + //生成NaiveProxy客户端资料 + private void GenerateNaivePrxoyShareQRcodeAndBase64Url() + { + + string saveFileFolderFirst = TextBoxNaiveServerHost.Text; + int num = 1; + saveFileFolder = saveFileFolderFirst; + CheckDir("naive_config"); + while (Directory.Exists(@"naive_config\" + saveFileFolder)) + { + saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); + num++; + } + CheckDir(@"naive_config\" + saveFileFolder); + string naiveUrl = $"https://{TextBoxNaiveUser.Text}:{TextBoxNaivePassword.Text}@{TextBoxNaiveServerHost.Text}:443/?name={TextBoxNaiveServerHost.Text}&extra_headers="; + //MessageBox.Show(v2rayNjsonObject.ToString()); + //string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString()); + TextBoxURL.Text = naiveUrl; + using (StreamWriter sw = new StreamWriter($"naive_config\\{saveFileFolder}\\url.txt")) + { + sw.WriteLine(naiveUrl); + + } + //CreateQRCode(trojanUrl); + + //移动NaiveProxy官方程序配置文件到相应目录 + if (File.Exists(@"naive_config\config.json")) + { + File.Move(@"naive_config\config.json", @"naive_config\" + saveFileFolder + @"\config.json"); + //File.Delete(@"config\config.json");//删除该文件 + } + + using (StreamWriter sw = new StreamWriter($"naive_config\\{saveFileFolder}\\说明.txt")) + { + sw.WriteLine("config.json"); + sw.WriteLine("此文件为NaiveProxy官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080"); + sw.WriteLine("NaiveProxy官方网站:https://github.com/klzgrad/naiveproxy"); + sw.WriteLine("NaiveProxy官方程序下载地址:https://github.com/klzgrad/naiveproxy/releases"); + sw.WriteLine("下载相应版本,Windows选择naiveproxy-x.xx-win.zip,解压后提取naive.exe。与config.json放在同一目录,运行naive.exe即可。"); + sw.WriteLine("-----------------------------------------\n"); + //sw.WriteLine("其他平台的客户端,暂未发布"); + //sw.WriteLine("QR.bmp"); + //sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点"); + //sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); + //sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); + //sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); + + //sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("url.txt"); + sw.WriteLine("此文件为NaiveGUI(windows)复制粘贴导入节点的网址"); + sw.WriteLine("NaiveGUI(windows)下载网址:https://github.com/ExcitedCodes/NaiveGUI/releases"); + + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("服务器通用连接配置参数"); + sw.WriteLine($"地址(address):{TextBoxNaiveServerHost.Text}"); + sw.WriteLine($"用户名:{TextBoxNaiveUser.Text}"); + sw.WriteLine($"密钥:{TextBoxNaivePassword.Text}"); + + } + + } + //生成base64 private string ToBase64Encode(string text) { @@ -406,8 +692,9 @@ namespace ProxySU byte[] textBytes = Encoding.UTF8.GetBytes(text); return Convert.ToBase64String(textBytes); } + //生成QRcoder图片 - private void CreateQRCode(string varBase64) + private void CreateQRCode(string varBase64,string configPath) { //string varBase64 = varBase64; QRCodeGenerator qrGenerator = new QRCodeGenerator(); @@ -418,9 +705,10 @@ namespace ProxySU BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); ImageShareQRcode.Source = imgsource; //DeleteObject(myImagePtr); - qrCodeImage.Save($"v2ray_config\\{saveFileFolder}\\QR.bmp"); + qrCodeImage.Save($"{configPath}\\{saveFileFolder}\\QR.bmp"); //ImageShareQRcode.Source = @"config\v2rayN.bmp"; } + //判断目录是否存在,不存在则创建 private static bool CheckDir(string folder) { @@ -436,11 +724,33 @@ namespace ProxySU } } + //打开文件夹 private void ButtonOpenSaveDir_Click(object sender, RoutedEventArgs e) { - string openFolderPath = @"v2ray_config\" + saveFileFolder; - System.Diagnostics.Process.Start("explorer.exe", openFolderPath); - this.Close(); + if (String.Equals(MainWindow.proxyType, "V2Ray")) + { + string openFolderPath = @"v2ray_config\" + saveFileFolder; + System.Diagnostics.Process.Start("explorer.exe", openFolderPath); + this.Close(); + } + else if (String.Equals(MainWindow.proxyType, "TrojanGo")) + { + string openFolderPath = @"trojan-go_config\" + saveFileFolder; + System.Diagnostics.Process.Start("explorer.exe", openFolderPath); + this.Close(); + } + else if (String.Equals(MainWindow.proxyType, "Trojan")) + { + string openFolderPath = @"trojan_config\" + saveFileFolder; + System.Diagnostics.Process.Start("explorer.exe", openFolderPath); + this.Close(); + } + else if (String.Equals(MainWindow.proxyType, "NaiveProxy")) + { + string openFolderPath = @"naive_config\" + saveFileFolder; + System.Diagnostics.Process.Start("explorer.exe", openFolderPath); + this.Close(); + } } } } diff --git a/ProxySU/TrojanGoResultClientInfoWindow.xaml b/ProxySU/TrojanGoResultClientInfoWindow.xaml deleted file mode 100644 index 7e185ea..0000000 --- a/ProxySU/TrojanGoResultClientInfoWindow.xaml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/TrojanGoResultClientInfoWindow.xaml.cs b/ProxySU/TrojanGoResultClientInfoWindow.xaml.cs deleted file mode 100644 index 619585e..0000000 --- a/ProxySU/TrojanGoResultClientInfoWindow.xaml.cs +++ /dev/null @@ -1,161 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -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; -using System.IO; -using Renci.SshNet; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System.Drawing; -using QRCoder; - -namespace ProxySU -{ - /// - /// TrojanGoResultClientInfoWindow.xaml 的交互逻辑 - /// - public partial class TrojanGoResultClientInfoWindow : Window - { - private string saveFileFolder = ""; - public TrojanGoResultClientInfoWindow() - { - InitializeComponent(); - TextBoxTrojanGoWSPath.Visibility = Visibility.Hidden; - TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Hidden; - TextBlockTrojanGoCaption.Visibility = Visibility.Hidden; - //主机地址 - TextBoxTrojanServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; - //主机端口 - TextBoxTrojanServerPort.Text = "443"; - //密钥(uuid) - TextBoxTrojanServerPassword.Text = MainWindow.ReceiveConfigurationParameters[2]; - //WebSocket路径 - if (MainWindow.ReceiveConfigurationParameters[0].Equals("TrojanGoWebSocketTLS2Web")) - { - TextBoxTrojanGoWSPath.Text = MainWindow.ReceiveConfigurationParameters[3]; - TextBoxTrojanGoWSPath.Visibility = Visibility.Visible; - TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Visible; - TextBlockTrojanGoCaption.Visibility = Visibility.Visible; - - } - - GenerateV2rayShareQRcodeAndBase64Url(); - } - private void GenerateV2rayShareQRcodeAndBase64Url() - { - - string saveFileFolderFirst = TextBoxTrojanServerHost.Text; - int num = 1; - saveFileFolder = saveFileFolderFirst; - CheckDir("trojan-go_config"); - while (Directory.Exists(@"trojan-go_config\" + saveFileFolder)) - { - saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - num++; - } - CheckDir(@"trojan-go_config\" + saveFileFolder); - string trojanUrl = $"trojan://{TextBoxTrojanServerPassword.Text}@{TextBoxTrojanServerHost.Text}:{TextBoxTrojanServerPort.Text}?allowinsecure=0&tfo=0&sni=&mux=0&ws=0&group=#{TextBoxTrojanServerHost.Text}"; - //MessageBox.Show(v2rayNjsonObject.ToString()); - //string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString()); - TextBoxTrojanUrl.Text = trojanUrl; - using (StreamWriter sw = new StreamWriter($"trojan-go_config\\{saveFileFolder}\\url.txt")) - { - sw.WriteLine(trojanUrl); - - } - CreateQRCode(trojanUrl); - - //移动Trojan官方程序配置文件到相应目录 - if (File.Exists(@"trojan-go_config\config.json")) - { - File.Move(@"trojan-go_config\config.json", @"trojan-go_config\" + saveFileFolder + @"\config.json"); - //File.Delete(@"config\config.json");//删除该文件 - } - - using (StreamWriter sw = new StreamWriter($"trojan-go_config\\{saveFileFolder}\\说明.txt")) - { - sw.WriteLine("config.json"); - sw.WriteLine("此文件为Trojan-go官方程序所使用的客户端配置文件,配置为全局模式,http与socks5地址:127.0.0.1:1080"); - sw.WriteLine("Trojan-go官方网站:https://github.com/p4gefau1t/trojan-go"); - sw.WriteLine("Trojan-go官方程序下载地址:https://github.com/p4gefau1t/trojan-go/releases"); - sw.WriteLine("下载相应版本,Windows选择Trojan-x.xx-win.zip,解压后提取trojan.exe。与config.json放在同一目录,运行trojan.exe即可。"); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("QR.bmp"); - sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点(Trojan-Go的WebSocket模式暂不支持)"); - sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); - sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); - sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); - - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("url.txt"); - sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)复制粘贴导入节点的网址(Trojan-Go的WebSocket模式暂不支持)"); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("服务器通用连接配置参数"); - sw.WriteLine($"地址(address):{TextBoxTrojanServerHost.Text}"); - sw.WriteLine($"端口(Port):{TextBoxTrojanServerPort.Text}"); - sw.WriteLine($"密钥:{TextBoxTrojanServerPassword.Text}"); - sw.WriteLine($"WebSocket路径:{TextBoxTrojanGoWSPath.Text}"); - - } - - - - } - //生成base64 - //private string ToBase64Encode(string text) - //{ - // if (String.IsNullOrEmpty(text)) - // { - // return text; - // } - - // byte[] textBytes = Encoding.UTF8.GetBytes(text); - // return Convert.ToBase64String(textBytes); - //} - - //生成QRcoder图片 - private void CreateQRCode(string varBase64) - { - //string varBase64 = varBase64; - QRCodeGenerator qrGenerator = new QRCodeGenerator(); - QRCodeData qrCodeData = qrGenerator.CreateQrCode(varBase64, QRCodeGenerator.ECCLevel.Q); - QRCode qrCode = new QRCode(qrCodeData); - Bitmap qrCodeImage = qrCode.GetGraphic(20); - IntPtr myImagePtr = qrCodeImage.GetHbitmap(); - BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); - ImageTrojanShareQRurl.Source = imgsource; - //DeleteObject(myImagePtr); - qrCodeImage.Save($"trojan-go_config\\{saveFileFolder}\\QR.bmp"); - - } - //判断目录是否存在,不存在则创建 - private static bool CheckDir(string folder) - { - try - { - if (!Directory.Exists(folder))//如果不存在就创建file文件夹 - Directory.CreateDirectory(folder);//创建该文件夹   - return true; - } - catch (Exception) - { - return false; - } - } - private void ButtonTrojanResultOpen_Click(object sender, RoutedEventArgs e) - { - string openFolderPath = @"trojan-go_config\" + saveFileFolder; - System.Diagnostics.Process.Start("explorer.exe", openFolderPath); - this.Close(); - } - } -} diff --git a/ProxySU/TrojanGoTemplateWindow.xaml b/ProxySU/TrojanGoTemplateWindow.xaml index 15c45d0..ed95f43 100644 --- a/ProxySU/TrojanGoTemplateWindow.xaml +++ b/ProxySU/TrojanGoTemplateWindow.xaml @@ -54,9 +54,9 @@ - + - + diff --git a/ProxySU/TrojanResultClientInfoWindow.xaml b/ProxySU/TrojanResultClientInfoWindow.xaml deleted file mode 100644 index 915b6ae..0000000 --- a/ProxySU/TrojanResultClientInfoWindow.xaml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ProxySU/TrojanResultClientInfoWindow.xaml.cs b/ProxySU/TrojanResultClientInfoWindow.xaml.cs deleted file mode 100644 index a1080f6..0000000 --- a/ProxySU/TrojanResultClientInfoWindow.xaml.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -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; -using System.IO; -using Renci.SshNet; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System.Drawing; -using QRCoder; - -namespace ProxySU -{ - /// - /// TrojanResultClientInfoWindow.xaml 的交互逻辑 - /// - public partial class TrojanResultClientInfoWindow : Window - { - private string saveFileFolder = ""; - public TrojanResultClientInfoWindow() - { - InitializeComponent(); - //TextBoxTrojanGoWSPath.Visibility = Visibility.Hidden; - //TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Hidden; - //TextBlockTrojanGoCaption.Visibility = Visibility.Hidden; - //主机地址 - TextBoxTrojanServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; - //主机端口 - TextBoxTrojanServerPort.Text = "443"; - //密钥(uuid) - TextBoxTrojanServerPassword.Text = MainWindow.ReceiveConfigurationParameters[2]; - //WebSocket路径 - //if (MainWindow.ReceiveConfigurationParameters[0].Equals("TrojanGoWebSocketTLS2Web")) - //{ - // TextBoxTrojanGoWSPath.Text = MainWindow.ReceiveConfigurationParameters[3]; - // TextBoxTrojanGoWSPath.Visibility = Visibility.Visible; - // TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Visible; - // TextBlockTrojanGoCaption.Visibility = Visibility.Visible; - - //} - - GenerateV2rayShareQRcodeAndBase64Url(); - - } - - //生成Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)客户端导入文件 - private void GenerateV2rayShareQRcodeAndBase64Url() - { - - string saveFileFolderFirst = TextBoxTrojanServerHost.Text; - int num = 1; - saveFileFolder = saveFileFolderFirst; - CheckDir("trojan_config"); - while (Directory.Exists(@"trojan_config\" + saveFileFolder)) - { - saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); - num++; - } - CheckDir(@"trojan_config\" + saveFileFolder); - string trojanUrl = $"trojan://{TextBoxTrojanServerPassword.Text}@{TextBoxTrojanServerHost.Text}:{TextBoxTrojanServerPort.Text}#{TextBoxTrojanServerHost.Text}"; - //MessageBox.Show(v2rayNjsonObject.ToString()); - //string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString()); - TextBoxTrojanUrl.Text = trojanUrl; - using (StreamWriter sw = new StreamWriter($"trojan_config\\{saveFileFolder}\\url.txt")) - { - sw.WriteLine(trojanUrl); - - } - CreateQRCode(trojanUrl); - - //移动Trojan官方程序配置文件到相应目录 - if (File.Exists(@"trojan_config\config.json")) - { - File.Move(@"trojan_config\config.json", @"trojan_config\" + saveFileFolder + @"\config.json"); - //File.Delete(@"config\config.json");//删除该文件 - } - - using (StreamWriter sw = new StreamWriter($"trojan_config\\{saveFileFolder}\\说明.txt")) - { - sw.WriteLine("config.json"); - sw.WriteLine("此文件为Trojan官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080"); - sw.WriteLine("Trojan官方网站:https://trojan-gfw.github.io/trojan/"); - sw.WriteLine("Trojan官方程序下载地址:https://github.com/trojan-gfw/trojan/releases"); - sw.WriteLine("下载相应版本,Windows选择Trojan-x.xx-win.zip,解压后提取trojan.exe。与config.json放在同一目录,运行trojan.exe即可。"); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("QR.bmp"); - sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点"); - sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); - sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); - sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); - - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("url.txt"); - sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)复制粘贴导入节点的网址"); - sw.WriteLine("-----------------------------------------\n"); - sw.WriteLine("服务器通用连接配置参数"); - sw.WriteLine($"地址(address):{TextBoxTrojanServerHost.Text}"); - sw.WriteLine($"端口(Port):{TextBoxTrojanServerPort.Text}"); - sw.WriteLine($"密钥:{TextBoxTrojanServerPassword.Text}"); - - } - - - - } - //生成base64 - //private string ToBase64Encode(string text) - //{ - // if (String.IsNullOrEmpty(text)) - // { - // return text; - // } - - // byte[] textBytes = Encoding.UTF8.GetBytes(text); - // return Convert.ToBase64String(textBytes); - //} - - //生成QRcoder图片 - private void CreateQRCode(string varBase64) - { - //string varBase64 = varBase64; - QRCodeGenerator qrGenerator = new QRCodeGenerator(); - QRCodeData qrCodeData = qrGenerator.CreateQrCode(varBase64, QRCodeGenerator.ECCLevel.Q); - QRCode qrCode = new QRCode(qrCodeData); - Bitmap qrCodeImage = qrCode.GetGraphic(20); - IntPtr myImagePtr = qrCodeImage.GetHbitmap(); - BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); - ImageTrojanShareQRurl.Source = imgsource; - //DeleteObject(myImagePtr); - qrCodeImage.Save($"trojan_config\\{saveFileFolder}\\QR.bmp"); - - } - //判断目录是否存在,不存在则创建 - private static bool CheckDir(string folder) - { - try - { - if (!Directory.Exists(folder))//如果不存在就创建file文件夹 - Directory.CreateDirectory(folder);//创建该文件夹   - return true; - } - catch (Exception) - { - return false; - } - } - private void ButtonTrojanResultOpen_Click(object sender, RoutedEventArgs e) - { - string openFolderPath = @"trojan_config\" + saveFileFolder; - System.Diagnostics.Process.Start("explorer.exe", openFolderPath); - this.Close(); - } - } -} diff --git a/ProxySU/TemplateConfiguration.xaml b/ProxySU/V2RayTemplateWindow.xaml similarity index 90% rename from ProxySU/TemplateConfiguration.xaml rename to ProxySU/V2RayTemplateWindow.xaml index 15f47c1..d31e552 100644 --- a/ProxySU/TemplateConfiguration.xaml +++ b/ProxySU/V2RayTemplateWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ProxySU" mc:Ignorable="d" - Title="TemplateConfiguration" Height="600" Width="850"> + Title="V2RayTemplateConfiguration" Height="600" Width="850">