diff --git a/ProxySU/MainWindow.xaml b/ProxySU/MainWindow.xaml index 8605dea..c1a6a93 100644 --- a/ProxySU/MainWindow.xaml +++ b/ProxySU/MainWindow.xaml @@ -317,7 +317,6 @@ - @@ -412,7 +411,7 @@ - + diff --git a/ProxySU/MainWindow.xaml.cs b/ProxySU/MainWindow.xaml.cs index a0da549..7c28837 100644 --- a/ProxySU/MainWindow.xaml.cs +++ b/ProxySU/MainWindow.xaml.cs @@ -46,13 +46,9 @@ namespace ProxySU //public static ConnectionInfo ConnectionInfo; static bool testDomain = false; //设置标识--域名是否需要检测解析,初始化为不需要 static string sshShellCommand;//定义保存执行的命令 - //sshShellCommand = ; - //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - static string currentShellCommandResult;//定义Shell命令执行结果保存变量 - //currentShellCommandResult = ; - //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - + static string sshCmdUpdate;//保存软件安装所用更新软件库命令 + static string sshCmdInstall;//保存软件安装所用命令格式 public MainWindow() { @@ -469,6 +465,8 @@ namespace ProxySU { string currentStatus = "正在登录远程主机......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 try { @@ -507,23 +505,54 @@ namespace ProxySU { currentStatus = "主机登录成功"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 Thread.Sleep(1000); } //检测是否运行在root权限下 - string testRootAuthority = client.RunCommand(@"id -u").Result; - if (testRootAuthority.Equals("0\n")==false) + 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);//显示命令执行的结果 + + } + //string testRootAuthority = client.RunCommand(@"id -u").Result; + //if (testRootAuthority.Equals("0\n")==false) + //{ + // MessageBox.Show("请使用具有root权限的账户登录主机!!"); + // client.Disconnect(); + // return; + //} //检测是否安装有V2ray currentStatus = "检测系统是否已经安装V2ray......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - string cmdTestV2rayInstalled = @"find / -name v2ray"; - string resultCmdTestV2rayInstalled = client.RunCommand(cmdTestV2rayInstalled).Result; + //string cmdTestV2rayInstalled = @"find / -name v2ray"; + sshShellCommand = @"find / -name v2ray"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string resultCmdTestV2rayInstalled = currentShellCommandResult; if (resultCmdTestV2rayInstalled.Contains("/usr/bin/v2ray") == true || resultCmdTestV2rayInstalled.Contains("/usr/local/bin/v2ray") == true) { MessageBoxResult messageBoxResult = MessageBox.Show("远程主机已安装V2ray,是否强制重新安装?", "", MessageBoxButton.YesNo, MessageBoxImage.Question); @@ -531,18 +560,45 @@ namespace ProxySU { currentStatus = "安装取消,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); client.Disconnect(); return; } + else + { + currentStatus = "已选择强制安装V2Ray!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + } + } + else + { + currentShellCommandResult = "检测结果:未安装V2Ray!"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + 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); - string result = client.RunCommand("uname -r").Result; + //string result = client.RunCommand("uname -r").Result; + sshShellCommand = @"uname -r"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + string result = currentShellCommandResult; string[] linuxKernelVerStr= result.Split('-'); bool detectResult = DetectKernelVersion(linuxKernelVerStr[0]); @@ -551,17 +607,57 @@ namespace ProxySU MessageBox.Show($"当前系统内核版本为{linuxKernelVerStr[0]},V2ray要求内核为2.6.23及以上。请升级内核再安装!"); currentStatus = "系统内核版本不符合要求,安装失败!!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); } //检测系统是否支持yum 或 apt-get或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); + //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的系统才能安装。 @@ -570,50 +666,168 @@ namespace ProxySU 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; } - //在相应系统内安装curl(如果没有安装curl) + 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; + + 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);//显示命令执行的结果 + + } + + } + //在相应系统内安装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 -qq update"); - client.RunCommand("apt -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"); - } + //if (getApt == false) + //{ + // client.RunCommand("apt -qq update"); + // client.RunCommand("apt -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"); //} } + ////在相应系统内安装curl(如果没有安装curl) + //if (string.IsNullOrEmpty(client.RunCommand("command -v curl").Result) == true) + //{ + // //为假则表示系统有相应的组件。 + // if (getApt == false) + // { + // client.RunCommand("apt -qq update"); + // client.RunCommand("apt -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"); + // //} + //} - //判断是否启用了SELinux,如果启用了,并且工作在Enforcing模式下,则改为Permissive模式 - if (getGetenforce == false) - { - string testSELinux = client.RunCommand("getenforce").Result; - if (testSELinux.Contains("Enforcing")==true) - { - client.RunCommand("setenforce 0");//不重启改为Permissive模式 - client.RunCommand("sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config");//重启也工作在Permissive模式下 - } - } + ////判断是否启用了SELinux,如果启用了,并且工作在Enforcing模式下,则改为Permissive模式 + //if (getGetenforce == false) + //{ + // string testSELinux = client.RunCommand("getenforce").Result; + // if (testSELinux.Contains("Enforcing")==true) + // { + // client.RunCommand("setenforce 0");//不重启改为Permissive模式 + // client.RunCommand("sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config");//重启也工作在Permissive模式下 + // } + //} //校对时间 currentStatus = "校对时间......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //获取远程主机的时间戳 long timeStampVPS = Convert.ToInt64(client.RunCommand("date +%s").Result.ToString()); @@ -627,78 +841,134 @@ namespace ProxySU MessageBox.Show("本地时间与远程主机时间相差超过限制(90秒),请先用\"系统工具-->时间校对\"校对时间后再设置"); currentStatus = "时间较对失败......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); client.Disconnect(); return; } + currentStatus = "时间差符合要求,OK!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + //如果使用是WebSocket + TLS + Web/http2/Http2Web/tcp_TLS/WebSocket_TLS模式,需要检测域名解析是否正确 if (testDomain == true) { currentStatus = "正在检测域名是否解析到当前VPS的IP上......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - - string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString(); - string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; - string resultCmd = client.RunCommand(testDomainCmd).Result.ToString(); + //string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString(); + //string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; + //string resultCmd = client.RunCommand(testDomainCmd).Result.ToString(); - if (String.Equals(nativeIp, resultCmd) == true) + 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 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; } - - } - if (testDomain == true) { + //检测是否安装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"); - //} + //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); - - if (String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result) == false || String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :443 | grep LISTEN").Result) == false) + + 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) { - //MessageBox.Show("80/443端口之一,或全部被占用,请先用系统工具中的“释放80/443端口”工具,释放出,再重新安装"); 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; @@ -706,42 +976,254 @@ namespace ProxySU 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(cmdResult) == false) + //string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; + //string cmdResult = client.RunCommand(cmdTestPort).Result; + + if (String.IsNullOrEmpty(testPort443) == false) { - string[] cmdResultArry443 = cmdResult.Split(' '); - client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); - client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); - client.RunCommand($"kill -9 {cmdResultArry443[3]}"); + 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(cmdResult) == false) + //cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; + //cmdResult = client.RunCommand(cmdTestPort).Result; + if (String.IsNullOrEmpty(testPort80) == false) { - string[] cmdResultArry80 = cmdResult.Split(' '); - client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); - client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); - client.RunCommand($"kill -9 {cmdResultArry80[3]}"); + 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);//显示命令执行的结果 + + } + + //if (String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result) == false || String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :443 | grep LISTEN").Result) == false) + //{ + // //MessageBox.Show("80/443端口之一,或全部被占用,请先用系统工具中的“释放80/443端口”工具,释放出,再重新安装"); + // MessageBoxResult dialogResult = MessageBox.Show("80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序?", "Stop application", MessageBoxButton.YesNo); + // if (dialogResult == MessageBoxResult.No) + // { + // currentStatus = "端口被占用,安装失败......"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // Thread.Sleep(1000); + // client.Disconnect(); + // return; + // } + + // currentStatus = "正在释放80/443端口......"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // Thread.Sleep(1000); + + // string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; + // string cmdResult = client.RunCommand(cmdTestPort).Result; + // if (String.IsNullOrEmpty(cmdResult) == false) + // { + // string[] cmdResultArry443 = cmdResult.Split(' '); + // client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); + // client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); + // client.RunCommand($"kill -9 {cmdResultArry443[3]}"); + // } + + // cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; + // cmdResult = client.RunCommand(cmdTestPort).Result; + // if (String.IsNullOrEmpty(cmdResult) == false) + // { + // string[] cmdResultArry80 = cmdResult.Split(' '); + // client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); + // client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); + // client.RunCommand($"kill -9 {cmdResultArry80[3]}"); + // } + // currentStatus = "80/443端口释放完毕!"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // Thread.Sleep(1000); + + //} + + } + 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);//显示命令执行的结果 + + string openFireWallPort = ReceiveConfigurationParameters[1]; + if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false) + { + if (String.Equals(openFireWallPort, "443")) + { + //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);//显示命令执行的结果 + } + else + { + //client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/tcp --permanent"); + //client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/udp --permanent"); + //client.RunCommand("firewall-cmd --reload"); + + sshShellCommand = $"firewall-cmd --zone=public --add-port={openFireWallPort}/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={openFireWallPort}/udp --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);//显示命令执行的结果 } } - currentStatus = "符合安装要求,布署中......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - - //下载官方安装脚本安装 + if (String.IsNullOrEmpty(client.RunCommand("command -v ufw").Result) == false) + { + if (String.Equals(openFireWallPort, "443")) + { + //client.RunCommand("ufw allow 80"); + //client.RunCommand("ufw allow 443"); + //client.RunCommand("yes | ufw reload"); - client.RunCommand("curl -o /tmp/go.sh https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"); - client.RunCommand("yes | bash /tmp/go.sh -f"); - string installResult = client.RunCommand("find / -name v2ray").Result.ToString(); + 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);//显示命令执行的结果 + + } + else + { + //client.RunCommand($"ufw allow {openFireWallPort}/tcp"); + //client.RunCommand($"ufw allow {openFireWallPort}/udp"); + //client.RunCommand("yes | ufw reload"); + sshShellCommand = $"ufw allow {openFireWallPort}/tcp"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"ufw allow {openFireWallPort}/udp"; + 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 = "正在安装V2Ray......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //client.RunCommand("curl -o /tmp/go.sh https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"); + //client.RunCommand("yes | bash /tmp/go.sh -f"); + //string installResult = client.RunCommand("find / -name v2ray").Result.ToString(); + sshShellCommand = @"curl -o /tmp/go.sh https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | bash /tmp/go.sh -f"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"find / -name trojan"; + 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/v2ray")) { @@ -749,6 +1231,9 @@ namespace ProxySU currentStatus = "安装V2ray失败(官方脚本运行出错!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + client.Disconnect(); return; } @@ -756,18 +1241,34 @@ namespace ProxySU { currentStatus = "V2ray安装成功!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - client.RunCommand("systemctl enable v2ray; systemctl start v2ray"); + //client.RunCommand("systemctl enable v2ray; systemctl start v2ray"); + sshShellCommand = @"systemctl enable v2ray"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + } - - client.RunCommand("mv /etc/v2ray/config.json /etc/v2ray/config.json.1"); + + //client.RunCommand("mv /usr/local/etc/v2ray/config.json /usr/local/etc/v2ray/config.json.1"); + sshShellCommand = @"mv /usr/local/etc/v2ray/config.json /usr/local/etc/v2ray/config.json.1"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 //上传配置文件 - currentStatus = "V2ray配置文件上传中......"; + currentStatus = "上传V2ray配置文件......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //生成服务端配置 + //serverConfig = @""; using (StreamReader reader = File.OpenText(serverConfig)) { JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); @@ -827,75 +1328,132 @@ namespace ProxySU File.Delete(@"config.json"); - //打开防火墙端口 - string openFireWallPort = ReceiveConfigurationParameters[1]; - if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false) - { - if (String.Equals(openFireWallPort, "443")) - { - 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"); - } - else - { - client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/tcp --permanent"); - client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/udp --permanent"); - client.RunCommand("firewall-cmd --reload"); - } - } - if (String.IsNullOrEmpty(client.RunCommand("command -v ufw").Result) == false) - { - if (String.Equals(openFireWallPort, "443")) - { - client.RunCommand("ufw allow 80"); - client.RunCommand("ufw allow 443"); - client.RunCommand("yes | ufw reload"); - } - else - { - client.RunCommand($"ufw allow {openFireWallPort}/tcp"); - client.RunCommand($"ufw allow {openFireWallPort}/udp"); - client.RunCommand("yes | ufw reload"); - } - } - //如果是WebSocket + TLS + Web模式,需要安装Caddy if (ReceiveConfigurationParameters[0].Contains("WebSocketTLS2Web") ==true || ReceiveConfigurationParameters[0].Contains("http2Web") == true) { currentStatus = "使用WebSocket+TLS+Web/HTTP2+TLS+Web模式,正在安装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"); + //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"); + //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"); + //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);//显示命令执行的结果 + } + //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"); + //} + //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"); + //} + //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"); + //} //else if (getZypper == false) //{ // client.RunCommand("zypper ref"); // client.RunCommand("zypper -y install curl"); //} - installResult = client.RunCommand("find / -name caddy").Result.ToString(); + + 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")) { @@ -903,31 +1461,123 @@ namespace ProxySU currentStatus = "安装Caddy失败!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + client.Disconnect(); return; } - else { - currentStatus = "Caddy安装成功!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - client.RunCommand("systemctl enable caddy"); - } + + 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);//显示命令执行的结果 + + //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"); + //} + //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"); + //} + //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"); + //} + ////else if (getZypper == false) + ////{ + //// client.RunCommand("zypper ref"); + //// client.RunCommand("zypper -y install curl"); + ////} + //installResult = client.RunCommand("find / -name caddy").Result.ToString(); + + //if (!installResult.Contains("/usr/bin/caddy")) + //{ + // MessageBox.Show("安装Caddy失败!"); + + // currentStatus = "安装Caddy失败!"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // client.Disconnect(); + // return; + //} + //else { + // currentStatus = "Caddy安装成功!"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // Thread.Sleep(1000); + // client.RunCommand("systemctl enable caddy"); + //} //在Caddy 2还未推出2.2.0的正式版之前,先用测试版替代 if (String.Equals(ReceiveConfigurationParameters[0], "http2Web")) { currentStatus = "正在为Http2Web模式升级Caddy v2.2.0测试版!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - client.RunCommand(@"curl -o /tmp/caddy.zip https://raw.githubusercontent.com/proxysu/Resources/master/Caddy2/caddy.zip"); - client.RunCommand(@"unzip /tmp/caddy.zip"); - client.RunCommand(@"chmod +x caddy"); - client.RunCommand(@"systemctl stop caddy;rm -f /usr/bin/caddy"); - client.RunCommand(@"cp /root/caddy /usr/bin/"); + //client.RunCommand(@"curl -o /tmp/caddy.zip https://raw.githubusercontent.com/proxysu/Resources/master/Caddy2/caddy.zip"); + //client.RunCommand(@"unzip /tmp/caddy.zip"); + //client.RunCommand(@"chmod +x caddy"); + //client.RunCommand(@"systemctl stop caddy;rm -f /usr/bin/caddy"); + //client.RunCommand(@"cp /root/caddy /usr/bin/"); + + sshShellCommand = @"curl -o /tmp/caddy.zip https://raw.githubusercontent.com/proxysu/Resources/master/Caddy2/caddy.zip"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"unzip /tmp/caddy.zip"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"chmod +x caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"systemctl stop caddy;rm -f /usr/bin/caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"cp /root/caddy /usr/bin/"; + 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); + + 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);//显示命令执行的结果 + if (ReceiveConfigurationParameters[0].Contains("WebSocketTLS2Web") == true) { serverConfig = "TemplateConfg\\WebSocketTLSWeb_server_config.caddyfile"; @@ -948,97 +1598,269 @@ namespace ProxySU //client.RunCommand(sshCmd); //设置域名 - string sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; - client.RunCommand(sshCmd); + //string sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; + //client.RunCommand(sshCmd); + 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);//显示命令执行的结果 + //设置Path - sshCmd = $"sed -i 's/##path##/\\{ReceiveConfigurationParameters[3]}/' {upLoadPath}"; - client.RunCommand(sshCmd); + //sshCmd = $"sed -i 's/##path##/\\{ReceiveConfigurationParameters[3]}/' {upLoadPath}"; + //client.RunCommand(sshCmd); + sshShellCommand = $"sed -i 's/##path##/\\{ReceiveConfigurationParameters[3]}/' {upLoadPath}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + - //设置伪装网站 if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7])==false) { - sshCmd = $"sed -i 's/##sites##/reverse_proxy {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; - client.RunCommand(sshCmd); + //sshCmd = $"sed -i 's/##sites##/reverse_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);//显示命令执行的结果 + } - Thread.Sleep(2000); - + currentStatus = "Caddy配置文件上传成功,OK!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //启动Caddy服务 - client.RunCommand("systemctl restart caddy"); + //client.RunCommand("systemctl restart caddy"); + currentStatus = "正在启动Caddy......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + // Thread.Sleep(1000); + //启动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); } 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); - 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"); - } + //安装所依赖的软件 + 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"); + //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 /usr/local/etc/v2ray/ssl"); - client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"); + //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\""); + // 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); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //启动V2ray服务 - client.RunCommand("systemctl restart v2ray"); + //client.RunCommand("systemctl restart v2ray"); + sshShellCommand = @"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); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //测试BBR条件,若满足提示是否启用 - result = client.RunCommand("uname -r").Result; - //var result = client.RunCommand("cat /root/test.ver"); - linuxKernelVerStr = result.Split('-'); + currentStatus = "BBR测试......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - detectResult = DetectKernelVersionBBR(linuxKernelVerStr[0]); - string resultCmdTestBBR = client.RunCommand(@"sysctl net.ipv4.tcp_congestion_control | grep bbr").Result; + 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[] linuxKernelVerStrBBR = currentShellCommandResult.Split('-'); + + bool detectResultBBR = DetectKernelVersionBBR(linuxKernelVerStrBBR[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) + if (detectResultBBR == 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 = "正在启用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连接 + //result = client.RunCommand("uname -r").Result; + ////var result = client.RunCommand("cat /root/test.ver"); + //linuxKernelVerStr = result.Split('-'); + + //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("v2ray_config"))//如果不存在就创建file文件夹      { @@ -1088,10 +1910,12 @@ namespace ProxySU } } - client.Disconnect(); + //client.Disconnect(); - currentStatus = "安装成功"; + currentStatus = "V2Ray安装成功,祝您使用愉快!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 Thread.Sleep(1000); //显示服务端连接参数 @@ -1134,6 +1958,8 @@ namespace ProxySU } currentStatus = "主机登录失败"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 } #endregion @@ -1159,8 +1985,10 @@ namespace ProxySU private void UpdateV2ray(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar) { string currentStatus = "正在登录远程主机......"; - Action updateAction = new Action(UpdateTextBlock); + //Action updateAction = new Action(UpdateTextBlock); textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 try { @@ -1199,22 +2027,54 @@ namespace ProxySU { currentStatus = "主机登录成功"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 + Thread.Sleep(1000); } //检测是否运行在root权限下 - string testRootAuthority = client.RunCommand(@"id -u").Result; + 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);//显示命令执行的结果 + + } + //string testRootAuthority = client.RunCommand(@"id -u").Result; + //if (testRootAuthority.Equals("0\n") == false) + //{ + // MessageBox.Show("请使用具有root权限的账户登录主机!!"); + // client.Disconnect(); + // return; + //} //检测远程主机V2ray版本 currentStatus = "检测远程主机V2ray版本......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //检测是否安装V2Ray - string resultCmdTestV2rayInstalled = client.RunCommand(@"find / -name v2ray").Result; + sshShellCommand = @"find / -name v2ray"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string resultCmdTestV2rayInstalled = currentShellCommandResult; if (resultCmdTestV2rayInstalled.Contains("/usr/bin/v2ray") == false && resultCmdTestV2rayInstalled.Contains("/usr/local/bin/v2ray") == false) { @@ -1222,6 +2082,9 @@ namespace ProxySU currentStatus = "未安装V2ray,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); client.Disconnect(); return; @@ -1229,47 +2092,142 @@ namespace ProxySU } else if (resultCmdTestV2rayInstalled.Contains("/usr/bin/v2ray") == true) { - client.RunCommand("curl -o /tmp/go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/v2ray/go.sh"); - client.RunCommand("yes | bash /tmp/go.sh --remove"); - string installResult = client.RunCommand("find / -name v2ray").Result.ToString(); + currentStatus = "检测到使用旧安装脚本的V2Ray......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + MessageBoxResult messageBoxResult = MessageBox.Show("检测到使用旧安装脚本的V2Ray,是否卸载旧版本并使用新安装脚本重新安装?", "", 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 = "正在卸载旧版本......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + } + + + //client.RunCommand("curl -o /tmp/go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/v2ray/go.sh"); + //client.RunCommand("yes | bash /tmp/go.sh --remove"); + + sshShellCommand = @"curl -o /tmp/go.sh https://raw.githubusercontent.com/proxysu/shellscript/master/v2ray/go.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | bash /tmp/go.sh --remove"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"find / -name v2ray"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string installResult = currentShellCommandResult; if (!installResult.Contains("/usr/bin/v2ray")) { - currentStatus = "删除旧版本,OK"; + currentStatus = "卸载旧版本,OK"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); } - currentStatus = "安装新版本。。。。。。"; + currentStatus = "安装新版本......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - client.RunCommand("curl -o /tmp/go.sh https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"); - client.RunCommand("yes | bash /tmp/go.sh -f"); - installResult = client.RunCommand("find / -name v2ray").Result.ToString(); + //client.RunCommand("curl -o /tmp/go.sh https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"); + //client.RunCommand("yes | bash /tmp/go.sh -f"); + //installResult = client.RunCommand("find / -name v2ray").Result.ToString(); + sshShellCommand = @"curl -o /tmp/go.sh https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + sshShellCommand = @"yes | bash /tmp/go.sh -f"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"find / -name v2ray"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + installResult = currentShellCommandResult; if (!installResult.Contains("/usr/local/bin/v2ray")) { MessageBox.Show("安装V2ray失败(官方脚本运行出错!"); currentStatus = "安装V2ray失败(官方脚本运行出错!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + client.Disconnect(); return; } - client.RunCommand(@"mv /etc/v2ray/config.json /usr/local/etc/v2ray/"); - client.RunCommand(@"systemctl restart v2ray"); + + currentStatus = "迁移原配置文件。"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //client.RunCommand(@"mv /etc/v2ray/config.json /usr/local/etc/v2ray/"); + //client.RunCommand(@"systemctl restart v2ray"); + sshShellCommand = @"mv /etc/v2ray/config.json /usr/local/etc/v2ray/"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"systemctl restart v2ray"; + 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); } - string sshcmd; - sshcmd = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; + //string sshcmd; + //sshcmd = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; + sshShellCommand = @"/usr/local/bin/v2ray -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 v2rayCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v + string v2rayCurrentVersion = currentShellCommandResult;//不含字母v - sshcmd = @"curl -H ""Accept: application/json"" -H ""User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"" -s ""https://api.github.com/repos/v2fly/v2ray-core/releases/latest"" --connect-timeout 10| grep 'tag_name' | cut -d\"" -f4"; - string v2rayNewVersion = client.RunCommand(sshcmd).Result;//包含字母v + //sshcmd = @"curl -H ""Accept: application/json"" -H ""User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"" -s ""https://api.github.com/repos/v2fly/v2ray-core/releases/latest"" --connect-timeout 10| grep 'tag_name' | cut -d\"" -f4"; + sshShellCommand = @"curl -H ""Accept: application/json"" -H ""User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0"" -s ""https://api.github.com/repos/v2fly/v2ray-core/releases/latest"" --connect-timeout 10 | grep 'tag_name' | cut -d\"" -f4"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string v2rayNewVersion = currentShellCommandResult;//包含字母v if (v2rayNewVersion.Contains(v2rayCurrentVersion) == false) { @@ -1278,16 +2236,32 @@ namespace ProxySU { currentStatus = "正在升级V2ray到最新版本......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - client.RunCommand(@"bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)"); - sshcmd = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - v2rayCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v + Thread.Sleep(1000); + //client.RunCommand(@"bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)"); + sshShellCommand = @"bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //sshcmd = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; + sshShellCommand = @"/usr/local/bin/v2ray -version | head -n 1 | cut -d "" "" -f2"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + v2rayCurrentVersion = currentShellCommandResult;//不含字母v if (v2rayNewVersion.Contains(v2rayCurrentVersion) == true) { MessageBox.Show($"升级成功!!\n当前版本为:v{v2rayCurrentVersion}\n最新版本为:{v2rayNewVersion}"); currentStatus = "升级成功!当前已是最新版本!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); } else @@ -1295,6 +2269,9 @@ namespace ProxySU MessageBox.Show("升级失败,原因未知,请向开发者提问,以寻求支持!"); currentStatus = "升级失败!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); } } @@ -1302,6 +2279,9 @@ namespace ProxySU { currentStatus = "升级取消,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); client.Disconnect(); return; @@ -1312,6 +2292,9 @@ namespace ProxySU MessageBox.Show($"远程主机当前已是最新版本:{v2rayNewVersion}\n无需升级!"); currentStatus = "已是最新版本,无需升级,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); } @@ -1351,6 +2334,8 @@ namespace ProxySU } currentStatus = "主机登录失败"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 } #endregion @@ -1409,6 +2394,8 @@ namespace ProxySU string currentStatus = "正在登录远程主机......"; Action updateAction = new Action(UpdateTextBlock); textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 try { @@ -1447,37 +2434,57 @@ namespace ProxySU { currentStatus = "主机登录成功"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 + Thread.Sleep(1000); } - //检测是否运行在root权限下 - string testRootAuthority = client.RunCommand(@"id -u").Result; + 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; } - //检测远程主机系统环境是否符合要求 - currentStatus = "检测系统是否符合安装要求......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - - string resultCmd = client.RunCommand("uname -m").Result; - - if (resultCmd.Contains("x86_64") == false) + else { - MessageBox.Show($"请在x86_64系统中安装Trojan"); - currentStatus = "系统不符合要求,安装失败!!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); + 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; + //} + //检测是否安装有Trojan currentStatus = "检测系统是否已经安装Trojan......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - string resultCmdTestTrojanInstalled = client.RunCommand(@"find / -name trojan").Result; + //string resultCmdTestTrojanInstalled = client.RunCommand(@"find / -name trojan").Result; + sshShellCommand = @"find / -name trojan"; + 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") == true) { @@ -1486,20 +2493,103 @@ namespace ProxySU { 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!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + } } + else + { + currentShellCommandResult = "检测结果:未安装Trojan!"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + 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); + + //string resultCmd = client.RunCommand("uname -m").Result; + sshShellCommand = @"uname -m"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string resultCmd = currentShellCommandResult; + if (resultCmd.Contains("x86_64") == false) + { + MessageBox.Show($"请在x86_64系统中安装Trojan"); + currentStatus = "系统不符合要求,安装失败!!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + //检测系统是否支持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); + //如果不存在组件,则命令结果为空,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的系统才能安装。 @@ -1508,42 +2598,129 @@ namespace ProxySU MessageBox.Show($"系统缺乏必要的安装组件如:apt-get||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; - //MessageBox.Show(testSELinux); + //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; + 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模式下 + //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 -qq update"); - client.RunCommand("apt -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"); - } + //if (getApt == false) + //{ + // client.RunCommand("apt -qq update"); + // client.RunCommand("apt -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"); @@ -1551,22 +2728,42 @@ namespace ProxySU //} } //检测域名是否解析正确 - currentStatus = "正在检测域名是否解析到当前VPS的IP上......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString(); - string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; - string resultTestDomainCmd = client.RunCommand(testDomainCmd).Result.ToString(); + //currentStatus = "正在检测域名是否解析到当前VPS的IP上......"; + //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + //Thread.Sleep(1000); + //string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString(); + //string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; + //string resultTestDomainCmd = client.RunCommand(testDomainCmd).Result.ToString(); + 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(); @@ -1576,22 +2773,32 @@ namespace ProxySU //检测是否安装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"); - } + //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"); @@ -1599,16 +2806,35 @@ namespace ProxySU //} } currentStatus = "正在检测端口占用情况......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - if (String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result) == false || String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :443 | grep LISTEN").Result) == false) + Thread.Sleep(1000); + + 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; @@ -1616,53 +2842,182 @@ namespace ProxySU 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; + //string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; + //string cmdResult = client.RunCommand(cmdTestPort).Result; - if (String.IsNullOrEmpty(cmdResult) == false) + if (String.IsNullOrEmpty(testPort443) == false) { - string[] cmdResultArry443 = cmdResult.Split(' '); - client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); - client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); - client.RunCommand($"kill -9 {cmdResultArry443[3]}"); + 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(cmdResult) == false) + //cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; + //cmdResult = client.RunCommand(cmdTestPort).Result; + if (String.IsNullOrEmpty(testPort80) == false) { - string[] cmdResultArry80 = cmdResult.Split(' '); - client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); - client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); - client.RunCommand($"kill -9 {cmdResultArry80[3]}"); + 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); } - currentStatus = "符合安装要求,布署中......"; + else + { + currentStatus = "检测结果:未被占用!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //if (String.IsNullOrEmpty() == false) + // { + // string[] cmdResultArry443 = cmdResult.Split(' '); + // client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); + // client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); + // client.RunCommand($"kill -9 {cmdResultArry443[3]}"); + // } + + // cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; + // cmdResult = client.RunCommand(cmdTestPort).Result; + // if (String.IsNullOrEmpty(cmdResult) == false) + // { + // string[] cmdResultArry80 = cmdResult.Split(' '); + // client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); + // client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); + // client.RunCommand($"kill -9 {cmdResultArry80[3]}"); + // } + // currentStatus = "80/443端口释放完毕!"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // Thread.Sleep(1000); + //} + + 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);//显示命令执行的结果 + + } //处理极其少见的xz-utils未安装的情况 - if (getApt == false) - { - client.RunCommand("apt -qq update"); - client.RunCommand("apt -y -qq install xz-utils"); - } - else if (getDnf == false) - { - //client.RunCommand("yum -q makecache"); - client.RunCommand("dnf -y -q install xz-utils"); - } - else if (getYum == false) - { - client.RunCommand("yum -q makecache"); - client.RunCommand("yum -y -q install xz-utils"); - } + sshShellCommand = $"{sshCmdUpdate}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"{sshCmdInstall}xz-utils"; + 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 xz-utils"); + //} + //else if (getDnf == false) + //{ + // //client.RunCommand("yum -q makecache"); + // client.RunCommand("dnf -y -q install xz-utils"); + //} + //else if (getYum == false) + //{ + // client.RunCommand("yum -q makecache"); + // client.RunCommand("yum -y -q install xz-utils"); + //} //else if (getZypper == false) //{ // client.RunCommand("zypper ref"); @@ -1670,12 +3025,34 @@ namespace ProxySU //} - //下载官方安装脚本安装 + //下载安装脚本安装 + currentStatus = "正在安装Trojan......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - client.RunCommand("curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"); - client.RunCommand("yes | bash /tmp/trojan-quickstart.sh"); + Thread.Sleep(1000); - string installResult = client.RunCommand("find / -name trojan").Result.ToString(); + //client.RunCommand("curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"); + //client.RunCommand("yes | bash /tmp/trojan-quickstart.sh"); + sshShellCommand = @"curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | bash /tmp/trojan-quickstart.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"find / -name trojan"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string installResult = currentShellCommandResult; + + //string installResult = client.RunCommand("find / -name trojan").Result.ToString(); if (!installResult.Contains("/usr/local/bin/trojan")) { @@ -1683,6 +3060,9 @@ namespace ProxySU currentStatus = "安装Trojan失败(官方脚本运行出错!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + client.Disconnect(); return; } @@ -1690,14 +3070,29 @@ namespace ProxySU { currentStatus = "Trojan安装成功!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - client.RunCommand("systemctl enable trojan"); + //client.RunCommand("systemctl enable trojan"); + sshShellCommand = @"systemctl enable trojan"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + } - client.RunCommand("mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.1"); + //client.RunCommand("mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.1"); + sshShellCommand = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.1"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 //上传配置文件 currentStatus = "Trojan程序安装完毕,配置文件上传中......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //生成服务端配置 @@ -1718,91 +3113,138 @@ namespace ProxySU File.Delete(@"config.json"); - //打开防火墙端口 - string openFireWallPort = ReceiveConfigurationParameters[1]; - if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false) - { - if (String.Equals(openFireWallPort, "443")) - { - 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"); - } - else - { - client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/tcp --permanent"); - client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/udp --permanent"); - client.RunCommand("firewall-cmd --reload"); - } - } - if (String.IsNullOrEmpty(client.RunCommand("command -v ufw").Result) == false) - { - if (String.Equals(openFireWallPort, "443")) - { - client.RunCommand("ufw allow 80"); - client.RunCommand("ufw allow 443"); - client.RunCommand("yes | ufw reload"); - } - else - { - client.RunCommand($"ufw allow {openFireWallPort}/tcp"); - client.RunCommand($"ufw allow {openFireWallPort}/udp"); - client.RunCommand("yes | ufw reload"); - } - } + ////打开防火墙端口 + //string openFireWallPort = ReceiveConfigurationParameters[1]; + //if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false) + //{ + // if (String.Equals(openFireWallPort, "443")) + // { + // 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"); + // } + // else + // { + // client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/tcp --permanent"); + // client.RunCommand($"firewall-cmd --zone=public --add-port={openFireWallPort}/udp --permanent"); + // client.RunCommand("firewall-cmd --reload"); + // } + //} + //if (String.IsNullOrEmpty(client.RunCommand("command -v ufw").Result) == false) + //{ + // if (String.Equals(openFireWallPort, "443")) + // { + // client.RunCommand("ufw allow 80"); + // client.RunCommand("ufw allow 443"); + // client.RunCommand("yes | ufw reload"); + // } + // else + // { + // client.RunCommand($"ufw allow {openFireWallPort}/tcp"); + // client.RunCommand($"ufw allow {openFireWallPort}/udp"); + // client.RunCommand("yes | ufw reload"); + // } + //} - currentStatus = "使用Trojan+TLS+Web模式,正在安装acme.sh......"; + currentStatus = "正在安装acme.sh......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - 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"); - } + //安装所依赖的软件 + 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"); + //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]}"); + //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......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - client.RunCommand($"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan/trojan_ssl.crt --keypath /usr/local/etc/trojan/trojan_ssl.key --capath /usr/local/etc/trojan/trojan_ssl.crt --reloadcmd \"systemctl restart trojan\""); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - currentStatus = "正在启动Trojan......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); Thread.Sleep(1000); - client.RunCommand("systemctl restart trojan"); + //client.RunCommand($"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan/trojan_ssl.crt --keypath /usr/local/etc/trojan/trojan_ssl.key --capath /usr/local/etc/trojan/trojan_ssl.crt --reloadcmd \"systemctl restart trojan\""); + sshShellCommand = $"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan/trojan_ssl.crt --keypath /usr/local/etc/trojan/trojan_ssl.key --capath /usr/local/etc/trojan/trojan_ssl.crt --reloadcmd \"systemctl restart trojan\""; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - currentStatus = "Trojan启动成功!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); + //currentStatus = "正在启动Trojan......"; + //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + //Thread.Sleep(1000); + + //client.RunCommand("systemctl restart trojan"); + + //currentStatus = "Trojan启动成功!"; + //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + //Thread.Sleep(1000); currentStatus = "正在安装Caddy"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //client.RunCommand("curl https://getcaddy.com -o getcaddy"); @@ -1814,55 +3256,176 @@ namespace ProxySU //为假则表示系统有相应的组件。 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"); + //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"); + //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"); + //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);//显示命令执行的结果 + } + //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"); + //} + //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"); + //} + //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"); + //} //else if (getZypper == false) //{ // client.RunCommand("zypper ref"); // client.RunCommand("zypper -y install curl"); //} - installResult = client.RunCommand("find / -name caddy").Result.ToString(); + + 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; } - else - { - currentStatus = "Caddy安装成功!"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - client.RunCommand("systemctl enable caddy"); - } + + 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);//显示命令执行的结果 + + + //if (!installResult.Contains("/usr/bin/caddy")) + //{ + // MessageBox.Show("安装Caddy失败!"); + // currentStatus = "安装Caddy失败!"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // client.Disconnect(); + // return; + //} + //else + //{ + // currentStatus = "Caddy安装成功!"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // Thread.Sleep(1000); + // client.RunCommand("systemctl enable caddy"); + //} currentStatus = "上传Caddy配置文件......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + 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"; - client.RunCommand("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"); + //client.RunCommand("mv /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak"); UploadConfig(connectionInfo, caddyConfig, upLoadPath); ////设置Caddyfile文件中的tls 邮箱 @@ -1870,50 +3433,172 @@ namespace ProxySU //string email = $"user@{ReceiveConfigurationParameters[4]}"; //string sshCmd; //设置域名 - string sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}:80/' {upLoadPath}"; - client.RunCommand(sshCmd); + //string sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; + //client.RunCommand(sshCmd); + 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);//显示命令执行的结果 + //设置伪装网站 if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false) { - sshCmd = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; - //MessageBox.Show(sshCmd); - client.RunCommand(sshCmd); - } - // Thread.Sleep(2000); - - //安装Caddy服务 - //sshCmd = $"caddy -service install -agree -conf /etc/caddy/Caddyfile -email {email}"; - //MessageBox.Show(sshCmd); + //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); + // Thread.Sleep(2000); + + //安装Caddy服务 + //sshCmd = $"caddy -service install -agree -conf /etc/caddy/Caddyfile -email {email}"; + //MessageBox.Show(sshCmd); + //client.RunCommand(sshCmd); + + currentStatus = "正在启动Caddy......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //启动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......"; + 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"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - //启动Caddy服务 - client.RunCommand("systemctl restart caddy"); - //} + currentStatus = "Trojan启动成功!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); //测试BBR条件,若满足提示是否启用 - var result = client.RunCommand("uname -r"); - string[] linuxKernelVerStr = result.Result.Split('-'); + 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]); - string resultCmdTestBBR = client.RunCommand(@"sysctl net.ipv4.tcp_congestion_control | grep bbr").Result; + //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) { - 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 = "正在启用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连接 + //var result = client.RunCommand("uname -r"); + //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_config"))//如果不存在就创建file文件夹      { Directory.CreateDirectory("trojan_config");//创建该文件夹   } //string clientConfig = "TemplateConfg\\tcp_client_config.json"; + clientConfig = "TemplateConfg\\trojan_client_config.json"; using (StreamReader reader = File.OpenText(clientConfig)) { JObject clientJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); @@ -1928,10 +3613,13 @@ namespace ProxySU } } - client.Disconnect(); + //client.Disconnect(); - currentStatus = "安装成功"; + currentStatus = "Trojan安装成功,祝您使用愉快!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //显示服务端连接参数 @@ -1974,13 +3662,15 @@ namespace ProxySU } currentStatus = "主机登录失败"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 } #endregion } - //检测升级远程主机Trojan版本 + //检测升级远程主机Trojan版本传递参数 private void ButtonUpdateTrojan_Click(object sender, RoutedEventArgs e) { ConnectionInfo connectionInfo = GenerateConnectionInfo(); @@ -1999,8 +3689,10 @@ namespace ProxySU private void UpdateTojan(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar) { string currentStatus = "正在登录远程主机......"; - Action updateAction = new Action(UpdateTextBlock); + //Action updateAction = new Action(UpdateTextBlock); textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 try { @@ -2039,23 +3731,55 @@ namespace ProxySU { currentStatus = "主机登录成功"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 + Thread.Sleep(1000); } //检测是否运行在root权限下 - string testRootAuthority = client.RunCommand(@"id -u").Result; + 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; } - //检测远程主机V2ray版本 + else + { + currentShellCommandResult = "检测结果:OK!"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //string testRootAuthority = client.RunCommand(@"id -u").Result; + //if (testRootAuthority.Equals("0\n") == false) + //{ + // MessageBox.Show("请使用具有root权限的账户登录主机!!"); + // client.Disconnect(); + // return; + //} + //检测远程主机Trojan版本 currentStatus = "检测远程主机Trojan版本......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - string cmdTestTrojanInstalled = @"find / -name trojan"; - string resultCmdTestTrojanInstalled = client.RunCommand(cmdTestTrojanInstalled).Result; + //string cmdTestTrojanInstalled = @"find / -name trojan"; + //string resultCmdTestTrojanInstalled = client.RunCommand(cmdTestTrojanInstalled).Result; + sshShellCommand = @"find / -name trojan"; + 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") == false) { @@ -2063,18 +3787,34 @@ namespace ProxySU currentStatus = "未安装Trojan,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); client.Disconnect(); return; } - //string sshcmd; - string sshcmd = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; - string trojanCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v + //获取当前安装的版本 + //string sshcmd = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; + //string trojanCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v + sshShellCommand = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - sshcmd = @"curl -fsSL https://api.github.com/repos/trojan-gfw/trojan/releases/latest | grep tag_name | sed -E 's/.*""v(.*)"".*/\1/'"; + string trojanCurrentVersion = currentShellCommandResult;//不含字母v + - string trojanNewVersion = client.RunCommand(sshcmd).Result;//不包含字母v + //sshcmd = @"curl -fsSL https://api.github.com/repos/trojan-gfw/trojan/releases/latest | grep tag_name | sed -E 's/.*""v(.*)"".*/\1/'"; + //获取最新版本 + + sshShellCommand = @"curl -fsSL https://api.github.com/repos/trojan-gfw/trojan/releases/latest | grep tag_name | sed -E 's/.*""v(.*)"".*/\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) { @@ -2083,27 +3823,73 @@ namespace ProxySU { currentStatus = "正在升级Trojan到最新版本......"; 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主程序 - client.RunCommand("curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"); - client.RunCommand("yes | bash /tmp/trojan-quickstart.sh"); - sshcmd = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; + currentStatus = "备份Trojan配置文件......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - trojanCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母v + //string sshcmd = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.bak"; + //client.RunCommand(sshcmd); + sshShellCommand = @"mv /usr/local/etc/trojan/config.json /usr/local/etc/trojan/config.json.bak"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //升级Trojan主程序 + //client.RunCommand("curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"); + //client.RunCommand("yes | bash /tmp/trojan-quickstart.sh"); + sshShellCommand = @"curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | bash /tmp/trojan-quickstart.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //sshcmd = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; + sshShellCommand = @"echo ""$(/usr/local/bin/trojan -v 2>&1)"" | head -n 1 | cut -d "" "" -f4"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + trojanCurrentVersion = currentShellCommandResult;//不含字母v + //trojanCurrentVersion = client.RunCommand(sshcmd).Result;//不含字母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); + currentStatus = "恢复Trojan配置文件......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //sshcmd = @"rm -f /usr/local/etc/trojan/config.json"; + //client.RunCommand(sshcmd); + sshShellCommand = @"rm -f /usr/local/etc/trojan/config.json"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //sshcmd = @"mv /usr/local/etc/trojan/config.json.bak /usr/local/etc/trojan/config.json"; + //client.RunCommand(sshcmd); + sshShellCommand = @"mv /usr/local/etc/trojan/config.json.bak /usr/local/etc/trojan/config.json"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + 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 @@ -2111,6 +3897,9 @@ namespace ProxySU MessageBox.Show("升级失败,原因未知,请向开发者提问,以寻求支持!"); currentStatus = "升级失败!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); } } @@ -2119,6 +3908,9 @@ namespace ProxySU { currentStatus = "升级取消,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); client.Disconnect(); return; @@ -2129,6 +3921,9 @@ namespace ProxySU MessageBox.Show($"远程主机当前已是最新版本:{trojanNewVersion}\n无需升级!"); currentStatus = "已是最新版本,无需升级,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); } @@ -2168,6 +3963,8 @@ namespace ProxySU } currentStatus = "主机登录失败"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 } #endregion @@ -2223,8 +4020,10 @@ namespace ProxySU private void StartSetUpTrojanGo(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar, string serverConfig, string clientConfig, string upLoadPath) { string currentStatus = "正在登录远程主机......"; - Action updateAction = new Action(UpdateTextBlock); + //Action updateAction = new Action(UpdateTextBlock); textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 try { @@ -2263,24 +4062,48 @@ namespace ProxySU { currentStatus = "主机登录成功"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 + Thread.Sleep(1000); } //检测是否运行在root权限下 - string testRootAuthority = client.RunCommand(@"id -u").Result; + 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); - //string cmdTestTrojanInstalled = @"find / -name trojan"; - string resultCmdTestTrojanInstalled = client.RunCommand(@"find / -name trojan-go").Result; + 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) { @@ -2289,48 +4112,176 @@ namespace ProxySU { 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 + { + currentShellCommandResult = "检测结果:未安装Trojan-go!"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + 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); - //检测系统是否支持yum 或 apt-get或zypper,且支持Systemd + //检测系统是否支持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); + //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 && getYum && getZypper) || getSystemd) + if ((getApt && getDnf && getYum && getZypper) || getSystemd) { - MessageBox.Show($"系统缺乏必要的安装组件如:apt-get||yum||zypper||Syetemd,主机系统推荐使用:CentOS 7/8,Debian 8/9/10,Ubuntu 16.04及以上版本"); + 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; + // 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模式下 + // 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);//显示命令执行的结果 + } } @@ -2339,48 +4290,78 @@ namespace ProxySU 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) { - //为假则表示系统有相应的组件。 - 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 = $"{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"); + //} } - string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString(); - string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; - string resultTestDomainCmd = client.RunCommand(testDomainCmd).Result.ToString(); + 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(); @@ -2390,40 +4371,68 @@ namespace ProxySU //检测是否安装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"); - } + //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); - if (String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result) == false || String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :443 | grep LISTEN").Result) == false) + 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; @@ -2431,42 +4440,162 @@ namespace ProxySU 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; + //string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; + //string cmdResult = client.RunCommand(cmdTestPort).Result; - if (String.IsNullOrEmpty(cmdResult) == false) + if (String.IsNullOrEmpty(testPort443) == false) { - string[] cmdResultArry443 = cmdResult.Split(' '); - client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); - client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); - client.RunCommand($"kill -9 {cmdResultArry443[3]}"); + 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(cmdResult) == false) + //cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; + //cmdResult = client.RunCommand(cmdTestPort).Result; + if (String.IsNullOrEmpty(testPort80) == false) { - string[] cmdResultArry80 = cmdResult.Split(' '); - client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); - client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); - client.RunCommand($"kill -9 {cmdResultArry80[3]}"); + 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); } - currentStatus = "符合安装要求,布署中......"; + 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);//显示命令执行的结果 - 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"); + if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false) + { - string installResult = client.RunCommand("find / -name trojan-go").Result.ToString(); + //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")) { @@ -2474,6 +4603,9 @@ namespace ProxySU currentStatus = "安装Trojan-Go失败(安装脚本运行出错!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + client.Disconnect(); return; } @@ -2481,14 +4613,30 @@ namespace ProxySU { 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"); + //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"); + //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); //生成服务端配置 @@ -2499,7 +4647,7 @@ namespace ProxySU serverJson["local_addr"] = "0.0.0.0"; serverJson["local_port"] = 443; serverJson["remote_addr"] = "127.0.0.1"; - serverJson["remote_port"] = 80; + serverJson["remote_port"] = 88; //设置密码 serverJson["password"][0] = ReceiveConfigurationParameters[2]; //设置证书 @@ -2523,97 +4671,188 @@ namespace ProxySU File.Delete(@"config.json"); - //打开防火墙端口 - string openFireWallPort = ReceiveConfigurationParameters[1]; - 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"); - - } - 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"); - - } - currentStatus = "正在安装acme.sh......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); - 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 = $"{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]}"); + //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\""); + //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"); + //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"); + //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"); + //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);//显示命令执行的结果 + } - //else if (getZypper == false) - //{ - // client.RunCommand("zypper ref"); - // client.RunCommand("zypper -y install curl"); - //} - installResult = client.RunCommand("find / -name caddy").Result.ToString(); + + 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")) { @@ -2621,39 +4860,73 @@ namespace ProxySU 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"); + // 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); - //Thread.Sleep(1000); - //string caddyConfig = "TemplateConfg\\trojan_caddy_config.caddyfile"; + currentStatus = "上传Caddy配置文件......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - //upLoadPath = "/etc/caddy/Caddyfile"; - //UploadConfig(connectionInfo, caddyConfig, upLoadPath); + 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]}:80/' {upLoadPath}"; - //MessageBox.Show(sshCmd); + //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); - //} - //Thread.Sleep(2000); + 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}"; @@ -2661,42 +4934,138 @@ namespace ProxySU //启动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"); + //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); - //启动V2ray服务 - client.RunCommand("systemctl restart trojan-go"); + //启动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条件,若满足提示是否启用 - var result = client.RunCommand("uname -r"); - //var result = client.RunCommand("cat /root/test.ver"); - string[] linuxKernelVerStr = result.Result.Split('-'); + 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]); - string resultCmdTestBBR = client.RunCommand(@"sysctl net.ipv4.tcp_congestion_control | grep bbr").Result; + //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) { - 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 = "正在启用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文件夹      { @@ -2726,10 +5095,13 @@ namespace ProxySU } } - client.Disconnect(); + - currentStatus = "安装成功"; + currentStatus = "Trojan-go安装成功,祝您使用愉快!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); //显示服务端连接参数 @@ -2772,13 +5144,15 @@ namespace ProxySU } currentStatus = "主机登录失败"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 } #endregion } - //检测升级Trojan-Go版本 + //检测升级Trojan-Go版本传递参数 private void ButtonUpdateTrojanGo_Click(object sender, RoutedEventArgs e) { ConnectionInfo connectionInfo = GenerateConnectionInfo(); @@ -2797,8 +5171,10 @@ namespace ProxySU private void UpdateTojanGo(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar) { string currentStatus = "正在登录远程主机......"; - Action updateAction = new Action(UpdateTextBlock); + //Action updateAction = new Action(UpdateTextBlock); textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 try { @@ -2837,23 +5213,56 @@ namespace ProxySU { currentStatus = "主机登录成功"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 + Thread.Sleep(1000); } //检测是否运行在root权限下 - string testRootAuthority = client.RunCommand(@"id -u").Result; + 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"; - string resultCmdTestTrojanInstalled = client.RunCommand(cmdTestTrojanInstalled).Result; + //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) { @@ -2861,17 +5270,30 @@ namespace ProxySU 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"; - string trojanCurrentVersion = client.RunCommand(sshcmd).Result;//含字母v + //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"; - string trojanNewVersion = client.RunCommand(sshcmd).Result;//含字母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) { @@ -2880,17 +5302,35 @@ namespace ProxySU { 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"); + //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"; - trojanCurrentVersion = client.RunCommand(sshcmd).Result;//含字母v + //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) { //恢复原来的配置文件备份 @@ -2901,6 +5341,9 @@ namespace ProxySU 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 @@ -2908,6 +5351,9 @@ namespace ProxySU MessageBox.Show("升级失败,原因未知,请向开发者提问,以寻求支持!"); currentStatus = "升级失败!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); client.Disconnect(); return; @@ -2918,6 +5364,9 @@ namespace ProxySU { currentStatus = "升级取消,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); client.Disconnect(); return; @@ -2928,6 +5377,9 @@ namespace ProxySU MessageBox.Show($"远程主机当前已是最新版本:{trojanNewVersion}\n无需升级!"); currentStatus = "已是最新版本,无需升级,退出"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); } @@ -2967,6 +5419,8 @@ namespace ProxySU } currentStatus = "主机登录失败"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 } #endregion @@ -3216,7 +5670,7 @@ namespace ProxySU //也就是apt,dnf\yum, zypper必须安装其中之一,且必须安装Systemd的系统才能安装。 if ((getApt && getDnf && getYum && getZypper) || getSystemd) { - MessageBox.Show($"系统缺乏必要的安装组件如:apt-get||yum||zypper||Syetemd,主机系统推荐使用:CentOS 7/8,Debian 8/9/10,Ubuntu 16.04及以上版本"); + 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; @@ -3234,6 +5688,36 @@ namespace ProxySU 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) @@ -3276,66 +5760,76 @@ namespace ProxySU currentShellCommandResult = currentStatus; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - if (getApt == false) - { - //client.RunCommand("apt -qq update"); - //client.RunCommand("apt -y -qq install curl libnss3 xz-utils lsof unzip"); - sshShellCommand = @"apt -qq update"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + sshShellCommand = $"{sshCmdUpdate}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - sshShellCommand = @"apt -y -qq install curl libnss3 xz-utils lsof unzip"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + sshShellCommand = $"{sshCmdInstall}curl libnss3 xz-utils lsof unzip"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - } - else if (getDnf == false) - { - //client.RunCommand("dnf -q makecache"); - //client.RunCommand("dnf -y -q install curl nss xz lsof unzip"); - sshShellCommand = @"dnf -q makecache"; - 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 curl libnss3 xz-utils lsof unzip"); + // sshShellCommand = @"apt -qq update"; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + // currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - sshShellCommand = @"dnf -y -q install curl nss xz lsof unzip"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + // sshShellCommand = @"apt -y -qq install curl libnss3 xz-utils lsof unzip"; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + // currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - } - else if (getYum == false) - { - //client.RunCommand("yum -q makecache"); - //client.RunCommand("yum -y -q install curl nss xz lsof unzip"); - sshShellCommand = @"yum -q makecache"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + //} + //else if (getDnf == false) + //{ + // //client.RunCommand("dnf -q makecache"); + // //client.RunCommand("dnf -y -q install curl nss xz lsof unzip"); + // sshShellCommand = @"dnf -q makecache"; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + // currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - sshShellCommand = @"yum -y -q install curl nss xz lsof unzip"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + // sshShellCommand = @"dnf -y -q install curl nss xz lsof unzip"; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + // currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - } - else if (getZypper == false) - { - //client.RunCommand("zypper ref"); - //client.RunCommand("zypper -y install curl nss xz lsof unzip"); - sshShellCommand = @"zypper ref"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + //} + //else if (getYum == false) + //{ + // //client.RunCommand("yum -q makecache"); + // //client.RunCommand("yum -y -q install curl nss xz lsof unzip"); + // sshShellCommand = @"yum -q makecache"; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + // currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - sshShellCommand = @"zypper -y install curl nss xz lsof unzip"; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 - currentShellCommandResult = client.RunCommand(sshShellCommand).Result; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + // sshShellCommand = @"yum -y -q install curl nss xz lsof unzip"; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + // currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - } + //} + //else if (getZypper == false) + //{ + // //client.RunCommand("zypper ref"); + // //client.RunCommand("zypper -y install curl nss xz lsof unzip"); + // sshShellCommand = @"zypper ref"; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + // currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + // sshShellCommand = @"zypper -y install curl nss xz lsof unzip"; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + // currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //} currentStatus = "安装完毕!OK!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); currentShellCommandResult = currentStatus; @@ -3497,7 +5991,6 @@ namespace ProxySU currentShellCommandResult = currentStatus; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - //string openFireWallPort = "443";//ReceiveConfigurationParameters[1]; if (String.IsNullOrEmpty(client.RunCommand("command -v firewall-cmd").Result) == false) { @@ -5545,14 +8038,7 @@ namespace ProxySU } #endregion - private void Button_Click(object sender, RoutedEventArgs e) - { - string currentStatus = "正在登录远程主机......"; - - currentShellCommandResult = currentStatus; - TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult); - - } + } } diff --git a/ProxySU/Properties/AssemblyInfo.cs b/ProxySU/Properties/AssemblyInfo.cs index a850403..1bc4460 100644 --- a/ProxySU/Properties/AssemblyInfo.cs +++ b/ProxySU/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.2.0")] -[assembly: AssemblyFileVersion("1.8.2.0")] +[assembly: AssemblyVersion("1.8.3.0")] +[assembly: AssemblyFileVersion("1.8.3.0")] diff --git a/ProxySU/bin/Beta/Beta.zip b/ProxySU/bin/Beta/Beta.zip index d8f324a..404632e 100644 Binary files a/ProxySU/bin/Beta/Beta.zip and b/ProxySU/bin/Beta/Beta.zip differ diff --git a/TemplateConfg/trojan_caddy_config.caddyfile b/TemplateConfg/trojan_caddy_config.caddyfile index 420847d..f6bf8a8 100644 --- a/TemplateConfg/trojan_caddy_config.caddyfile +++ b/TemplateConfg/trojan_caddy_config.caddyfile @@ -1,5 +1,8 @@ -##domain## { +:88 { root * /usr/share/caddy file_server ##sites## +} +##domain##:80 { + redir https://##domain##{uri} } \ No newline at end of file diff --git a/TemplateConfg/trojan_server_config.json b/TemplateConfg/trojan_server_config.json index 041d26d..608ff61 100644 --- a/TemplateConfg/trojan_server_config.json +++ b/TemplateConfg/trojan_server_config.json @@ -3,7 +3,7 @@ "local_addr": "::", "local_port": 443, "remote_addr": "127.0.0.1", - "remote_port": 80, + "remote_port": 88, "password": [ "" ],