diff --git a/ProxySU/MainWindow.xaml b/ProxySU/MainWindow.xaml index b0704e0..1cbe228 100644 --- a/ProxySU/MainWindow.xaml +++ b/ProxySU/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ProxySU" mc:Ignorable="d" - Title="ProxySU - v2.0.4" Height="625" Width="530"> + Title="ProxySU - v2.1.0" Height="625" Width="530"> @@ -126,7 +126,7 @@ - + @@ -185,7 +185,7 @@ - + @@ -238,7 +238,7 @@ - + @@ -277,9 +277,9 @@ - - - + + + @@ -294,7 +294,7 @@ - + @@ -331,8 +331,8 @@ - - + + @@ -343,6 +343,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/ProxySU/MainWindow.xaml.cs b/ProxySU/MainWindow.xaml.cs index e361dc6..9e9ab70 100644 --- a/ProxySU/MainWindow.xaml.cs +++ b/ProxySU/MainWindow.xaml.cs @@ -107,6 +107,9 @@ namespace ProxySU TextBoxNaivePassword.Text = RandomUUID(); TextBoxNaiveUser.Text = RandomUserName(); + //初始化SSR的密码 + TextBoxSSRPassword.Text = RandomUUID(); + //初始化三合一的所有内容 //TextBoxV2rayUUID3in1.Text = RandomUUID(); //TextBoxV2rayPath3in1.Text = "/ray"; @@ -1605,7 +1608,7 @@ namespace ProxySU { //设置Caddy随机监听的端口,用于Trojan-go,Trojan,V2Ray vless TLS Random random = new Random(); - randomCaddyListenPort = random.Next(2000, 9000); + randomCaddyListenPort = random.Next(10001, 30000); //指向Caddy监听的随机端口 serverJson["inbounds"][0]["settings"]["fallbacks"][0]["dest"] = randomCaddyListenPort; } @@ -1999,7 +2002,7 @@ namespace ProxySU TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 //设置域名 - sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; + sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/g' {upLoadPath}"; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 currentShellCommandResult = client.RunCommand(sshShellCommand).Result; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 @@ -2013,7 +2016,7 @@ namespace ProxySU //设置伪装网站 if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7])==false) { - sshShellCommand = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; + 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);//显示命令执行的结果 @@ -3482,7 +3485,7 @@ namespace ProxySU { //设置Caddy随机监听的端口,用于Trojan-go,Trojan,V2Ray vless TLS Random random = new Random(); - randomCaddyListenPort = random.Next(2000, 9000); + randomCaddyListenPort = random.Next(10001, 30000); JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); serverJson["run_type"] = "server"; @@ -3790,7 +3793,7 @@ namespace ProxySU TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 //设置域名 - sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; + sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/g' {upLoadPath}"; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 currentShellCommandResult = client.RunCommand(sshShellCommand).Result; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 @@ -5079,7 +5082,7 @@ namespace ProxySU //设置Caddy随机监听的端口,用于Trojan-go,Trojan,V2Ray vless TLS Random random = new Random(); - randomCaddyListenPort = random.Next(2000, 9000); + randomCaddyListenPort = random.Next(10001, 30000); //设置转发到Caddy的随机监听端口 serverJson["remote_port"] = randomCaddyListenPort; @@ -5372,7 +5375,7 @@ namespace ProxySU //设置域名 - sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; + sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/g' {upLoadPath}"; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 currentShellCommandResult = client.RunCommand(sshShellCommand).Result; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 @@ -5513,7 +5516,7 @@ namespace ProxySU TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 Thread.Sleep(3000); - //****** "正在第二次尝试启动Trojan-go!" ****** + //****** "正在第二次尝试启动Trojan!" ****** currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartSoftSecond").ToString() + "Trojan!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); currentShellCommandResult = currentStatus; @@ -5530,7 +5533,7 @@ namespace ProxySU TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 currentShellCommandResult = client.RunCommand(sshShellCommand).Result; TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 - if (currentShellCommandResult.Contains("usr/local/bin/trojan-go") == true) + if (currentShellCommandResult.Contains("usr/local/bin/trojan") == true) { //****** "Trojan启动成功!" ****** currentStatus = "Trojan" + Application.Current.FindResource("DisplayInstallInfo_StartSoftOK").ToString(); @@ -6023,11 +6026,11 @@ namespace ProxySU if (String.Equals(testDomain, "https:/") || String.Equals(testDomain, "http://")) { //MessageBox.Show(testDomain); - MainWindow.ReceiveConfigurationParameters[7] = TextBoxNaiveSites.Text.Replace("/", "\\/"); + ReceiveConfigurationParameters[7] = TextBoxNaiveSites.Text.Replace("/", "\\/"); } else { - MainWindow.ReceiveConfigurationParameters[7] = "http:\\/\\/" + TextBoxNaiveSites.Text; + ReceiveConfigurationParameters[7] = "http:\\/\\/" + TextBoxNaiveSites.Text; } } @@ -7119,8 +7122,1318 @@ namespace ProxySU { TextBoxNaiveUser.Text = RandomUserName(); } - -#endregion + + #endregion + + #region SSR+TLS+Caddy相关 + + //SSR参数传递 + private void ButtonSSRSetUp_Click(object sender, RoutedEventArgs e) + { + ConnectionInfo connectionInfo = GenerateConnectionInfo(); + if (connectionInfo == null) + { + //****** "远程主机连接信息有误,请检查!" ****** + MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorHostConnection").ToString()); + return; + } + //清空参数空间 + for (int i = 0; i != ReceiveConfigurationParameters.Length; i++) + + { + ReceiveConfigurationParameters[i] = ""; + } + if (string.IsNullOrEmpty(TextBoxSSRHostDomain.Text.ToString()) == true) + { + //****** "域名不能为空,请检查相关参数设置!" ****** + MessageBox.Show(Application.Current.FindResource("MessageBoxShow_DomainNotEmpty").ToString()); + return; + } + + //传递域名 + ReceiveConfigurationParameters[4] = TextBoxSSRHostDomain.Text.ToString(); + //传递伪装网站 + ReceiveConfigurationParameters[7] = TextBoxSSRSites.Text.ToString(); + //处理伪装网站域名中的前缀 + if (TextBoxSSRSites.Text.ToString().Length >= 7) + { + string testDomain = TextBoxSSRSites.Text.Substring(0, 7); + if (String.Equals(testDomain, "https:/") || String.Equals(testDomain, "http://")) + { + //MessageBox.Show(testDomain); + ReceiveConfigurationParameters[7] = TextBoxSSRSites.Text.Replace("/", "\\/"); + } + else + { + ReceiveConfigurationParameters[7] = "http:\\/\\/" + TextBoxSSRSites.Text; + } + } + //传递服务端口 + ReceiveConfigurationParameters[1] = "443"; + //传递密码(uuid) + ReceiveConfigurationParameters[2] = TextBoxSSRPassword.Text.ToString(); + + + string serverConfig = ""; //服务端配置文件 + string clientConfig = ""; //生成的客户端配置文件 + string upLoadPath = ""; //服务端文件位置 + + Thread thread = new Thread(() => StartSetUpSSR(connectionInfo, TextBlockSetUpProcessing, ProgressBarSetUpProcessing, serverConfig, clientConfig, upLoadPath)); + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + } + + //登录远程主机布署SSR+TLS+Caddy程序 + private void StartSetUpSSR(ConnectionInfo connectionInfo, TextBlock textBlockName, ProgressBar progressBar, string serverConfig, string clientConfig, string upLoadPath) + { + //******"正在登录远程主机......"****** + string currentStatus = Application.Current.FindResource("DisplayInstallInfo_Login").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + try + { + #region 主机指纹,暂未启用 + //byte[] expectedFingerPrint = new byte[] { + // 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, + // 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b + // }; + #endregion + using (var client = new SshClient(connectionInfo)) + + { + #region ssh登录验证主机指纹代码块,暂未启用 + // client.HostKeyReceived += (sender, e) => + // { + // if (expectedFingerPrint.Length == e.FingerPrint.Length) + // { + // for (var i = 0; i < expectedFingerPrint.Length; i++) + // { + // if (expectedFingerPrint[i] != e.FingerPrint[i]) + // { + // e.CanTrust = false; + // break; + // } + // } + // } + // else + // { + // e.CanTrust = false; + // } + // }; + #endregion + + client.Connect(); + if (client.IsConnected == true) + { + //******"主机登录成功"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginSuccessful").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果在监视窗口 + + Thread.Sleep(1000); + } + + //******"检测是否运行在root权限下..."****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_DetectionRootPermission").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + 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) + { + //******"请使用具有root权限的账户登录主机!!"****** + MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorRootPermission").ToString()); + client.Disconnect(); + return; + } + else + { + //******"检测结果:OK!"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_DetectionRootOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + //******"检测系统是否已经安装SSR......"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestExistSoft").ToString() + "SSR......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + sshShellCommand = @"if [ -f /usr/local/shadowsocks/server.py ];then echo '1';else echo '0'; fi"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string resultCmdTestTrojanInstalled = currentShellCommandResult; + + if (resultCmdTestTrojanInstalled.Contains("1") == true) + { + MessageBoxResult messageBoxResult = MessageBox.Show( + //******"远程主机已安装"****** + Application.Current.FindResource("MessageBoxShow_ExistedSoft").ToString() + + "SSR" + + //******",是否强制重新安装?"****** + Application.Current.FindResource("MessageBoxShow_ForceInstallSoft").ToString(), "", MessageBoxButton.YesNo, MessageBoxImage.Question); + if (messageBoxResult == MessageBoxResult.No) + { + //******"安装取消,退出"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_InstallationCanceledExit").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + } + else + { + //******"已选择强制安装SSR!"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_ForceInstallSoft").ToString() + "SSR!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + } + } + else + { + //******"检测结果:未安装SSR!"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_NoInstalledSoft").ToString() + "SSR!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus);//显示命令执行的结果 + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //******"检测系统是否符合安装要求......"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_CheckSystemRequirements").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //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) + //{ + // //******"请在x86_64系统中安装Trojan" ****** + // MessageBox.Show(Application.Current.FindResource("MessageBoxShow_PleaseInstallSoftAtX64").ToString() + "NaiveProxy......"); + // //****** "系统环境不满足要求,安装失败!!" ****** + // currentStatus = Application.Current.FindResource("DisplayInstallInfo_MissingSystemComponents").ToString(); + // 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); + + sshShellCommand = @"command -v apt"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getApt = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v dnf"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getDnf = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v yum"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getYum = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v zypper"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getZypper = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v systemctl"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getSystemd = String.IsNullOrEmpty(currentShellCommandResult); + + sshShellCommand = @"command -v getenforce"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + bool getGetenforce = String.IsNullOrEmpty(currentShellCommandResult); + + + //没有安装apt,也没有安装dnf\yum,也没有安装zypper,或者没有安装systemd的,不满足安装条件 + //也就是apt ,dnf\yum, zypper必须安装其中之一,且必须安装Systemd的系统才能安装。 + if ((getApt && getDnf && getYum && getZypper) || getSystemd) + { + //******"系统缺乏必要的安装组件如:apt||dnf||yum||zypper||Syetemd,主机系统推荐使用:CentOS 7/8,Debian 8/9/10,Ubuntu 16.04及以上版本"****** + MessageBox.Show(Application.Current.FindResource("MessageBoxShow_MissingSystemComponents").ToString()); + + //******"系统环境不满足要求,安装失败!!"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_MissingSystemComponents").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + } + else + { + //******"检测结果:OK!"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_SystemRequirementsOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //设置安装软件所用的命令格式 + //为假则表示系统有相应的组件。 + + if (getApt == false) + { + sshCmdUpdate = @"apt -qq update"; + sshCmdInstall = @"apt -y -qq install "; + } + else if (getDnf == false) + { + sshCmdUpdate = @"dnf -q makecache"; + sshCmdInstall = @"dnf -y -q install "; + } + else if (getYum == false) + { + sshCmdUpdate = @"yum -q makecache"; + sshCmdInstall = @"yum -y -q install "; + } + else if (getZypper == false) + { + sshCmdUpdate = @"zypper ref"; + sshCmdInstall = @"zypper -y install "; + } + + //判断是否启用了SELinux,如果启用了,并且工作在Enforcing模式下,则改为Permissive模式 + if (getGetenforce == false) + { + 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) + { + //******"检测到系统启用SELinux,且工作在严格模式下,需改为宽松模式!修改中......"****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableSELinux").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + 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 = Application.Current.FindResource("DisplayInstallInfo_SELinuxModifyOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + } + + //****** "正在检测域名是否解析到当前VPS的IP上......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestDomainResolve").ToString(); + 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);//显示命令执行的结果 + + } + //检测域名是否解析正确 + 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) + { + //****** "解析正确!OK!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_DomainResolveOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + //****** "域名未能正确解析到当前VPS的IP上!安装失败!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_ErrorDomainResolve").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //****** "域名未能正确解析到当前VPS的IP上,请检查!若解析设置正确,请等待生效后再重试安装。如果域名使用了CDN,请先关闭!" ****** + MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorDomainResolve").ToString()); + client.Disconnect(); + return; + } + + //检测是否安装lsof + if (string.IsNullOrEmpty(client.RunCommand("command -v lsof").Result) == true) + { + sshShellCommand = $"{sshCmdUpdate}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = $"{sshCmdInstall}lsof"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //****** "检测端口占用情况......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestPortUsed").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + 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) + { + //****** "80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序?" ****** + MessageBoxResult dialogResult = MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorPortUsed").ToString(), "Stop application", MessageBoxButton.YesNo); + if (dialogResult == MessageBoxResult.No) + { + //****** "端口被占用,安装失败......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_ErrorPortUsedFail").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + client.Disconnect(); + return; + } + + //****** "正在释放80/443端口......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_ReleasePort").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + if (String.IsNullOrEmpty(testPort443) == false) + { + string[] cmdResultArry443 = testPort443.Split(' '); + + 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);//显示命令执行的结果 + + } + + if (String.IsNullOrEmpty(testPort80) == false) + { + string[] cmdResultArry80 = testPort80.Split(' '); + + 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);//显示命令执行的结果 + + } + //****** "80/443端口释放完毕!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_ReleasePortOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + //****** "检测结果:未被占用!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_PortNotUsed").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + //****** "系统环境检测完毕,符合安装要求,开始布署......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstalling").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //****** "开启防火墙相应端口......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_OpenFireWallPort").ToString(); + 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) + { + + 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) + { + 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未安装的情况 + 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);//显示命令执行的结果 + + //下载安装脚本安装 + //****** "正在安装SSR......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallSoft").ToString() + "SSR......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + sshShellCommand = @"curl -o /tmp/ssr.sh https://raw.githubusercontent.com/proxysu/shellscript/master/ssr/ssr.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yes | bash /tmp/ssr.sh"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"if [ -f /usr/local/shadowsocks/server.py ];then echo '1';else echo '0'; fi"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + string installResult = currentShellCommandResult; + + if (!installResult.Contains("1")) + { + //****** "安装失败,官方脚本运行出错!" ****** + MessageBox.Show(Application.Current.FindResource("MessageBoxShow_ErrorInstallSoftFail").ToString()); + //****** "安装失败,官方脚本运行出错!" ****** + currentStatus = Application.Current.FindResource("MessageBoxShow_ErrorInstallSoftFail").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + client.Disconnect(); + return; + } + else + { + //****** "SSR安装成功!" ****** + currentStatus = "SSR" + Application.Current.FindResource("DisplayInstallInfo_SoftInstallSuccess").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //设置开机自启动 + sshShellCommand = @"systemctl enable ssr"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + //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 = Application.Current.FindResource("DisplayInstallInfo_UploadSoftConfig").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //生成服务端配置 + //serverConfig = @"/etc/shadowsocks.json"; + upLoadPath = @"/etc/shadowsocks.json"; + //设置指向Caddy监听的随机端口 + Random random = new Random(); + randomCaddyListenPort = random.Next(10001, 30000); + string randomSSRListenPortStr = randomCaddyListenPort.ToString(); + + sshShellCommand = $"sed -i 's/8800/{randomSSRListenPortStr}/' {upLoadPath}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //设置密码 + sshShellCommand = $"sed -i 's/##password##/{ReceiveConfigurationParameters[2]}/' {upLoadPath}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + //using (StreamReader reader = File.OpenText(serverConfig)) + //{ + // JObject serverJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); + // //设置密码 + // serverJson["password"][0] = ReceiveConfigurationParameters[2]; + + // //设置Caddy随机监听的端口,用于Trojan-go,Trojan,V2Ray vless TLS + // Random random = new Random(); + // randomCaddyListenPort = random.Next(10001, 30000); + + // //设置转发到Caddy的随机监听端口 + // serverJson["remote_port"] = randomCaddyListenPort; + + // using (StreamWriter sw = new StreamWriter(@"config.json")) + // { + // sw.Write(serverJson.ToString()); + // } + //} + //UploadConfig(connectionInfo, @"config.json", upLoadPath); + + //File.Delete(@"config.json"); + + //****** "正在安装acme.sh......" ****** + //currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallAcmeSh").ToString(); + //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + //currentShellCommandResult = currentStatus; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //Thread.Sleep(1000); + + ////安装所依赖的软件 + //sshShellCommand = $"{sshCmdUpdate}"; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //sshShellCommand = $"{sshCmdInstall}socat"; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //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);//显示命令执行的结果 + + //if (currentShellCommandResult.Contains("Install success") == true) + //{ + // //****** "acme.sh安装成功!" ****** + // currentStatus = Application.Current.FindResource("DisplayInstallInfo_AcmeShInstallSuccess").ToString(); + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // currentShellCommandResult = currentStatus; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + // Thread.Sleep(1000); + //} + //else + //{ + // //****** "acme.sh安装失败!原因未知,请向开发者提问!" ****** + // currentStatus = Application.Current.FindResource("DisplayInstallInfo_ErrorAcmeShInstallFail").ToString(); + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // currentShellCommandResult = currentStatus; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + // return; + //} + + //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 = Application.Current.FindResource("DisplayInstallInfo_StartApplyCert").ToString(); + //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + //currentShellCommandResult = currentStatus; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //Thread.Sleep(1000); + + //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);//显示命令执行的结果 + + //if (currentShellCommandResult.Contains("Cert success") == true) + //{ + // //****** "证书申请成功!" ****** + // currentStatus = Application.Current.FindResource("DisplayInstallInfo_ApplyCertSuccess").ToString(); + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // currentShellCommandResult = currentStatus; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + // Thread.Sleep(1000); + //} + //else + //{ + // //****** "证书申请失败!原因未知,请向开发者提问!" ****** + // currentStatus = Application.Current.FindResource("DisplayInstallInfo_ApplyCertFail").ToString(); + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // currentShellCommandResult = currentStatus; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + // return; + //} + + ////****** "安装证书到Trojan......" ****** + //currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoft").ToString() + "Trojan......"; + //textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + //currentShellCommandResult = currentStatus; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //Thread.Sleep(1000); + + //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);//显示命令执行的结果 + + //sshShellCommand = @"if [ ! -f ""/usr/local/etc/trojan/trojan_ssl.key"" ]; then echo ""0""; else echo ""1""; fi | head -n 1"; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //if (currentShellCommandResult.Contains("1") == true) + //{ + // //****** "证书成功安装到Trojan!" ****** + // currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftOK").ToString() + "Trojan!"; + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // currentShellCommandResult = currentStatus; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //} + //else + //{ + // //****** "证书安装到Trojan失败,原因未知,可以向开发者提问!" ****** + // currentStatus = Application.Current.FindResource("DisplayInstallInfo_IntallCertToSoftFail").ToString() + + // "Trojan" + + // Application.Current.FindResource("DisplayInstallInfo_InstallCertFailAsk").ToString(); + // textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + // currentShellCommandResult = currentStatus; + // TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + // return; + //} + + ////设置证书权限 + //sshShellCommand = @"chmod 644 /usr/local/etc/trojan/trojan_ssl.key"; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //****** "安装Caddy......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartInstallCaddy").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //安装Caddy + //为假则表示系统有相应的组件。 + if (getApt == false) + { + 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) + { + + 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) + { + sshShellCommand = @"yum install yum-plugin-copr -y"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yum copr enable @caddy/caddy -y"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //sshShellCommand = @"yum -q makecache"; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + //currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + //TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + sshShellCommand = @"yum -y -q install caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + + sshShellCommand = @"find / -name caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + installResult = currentShellCommandResult; + + if (!installResult.Contains("/usr/bin/caddy")) + { + //****** "安装Caddy失败!" ****** + MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_ErrorInstallCaddyFail").ToString()); + //****** "安装Caddy失败!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_ErrorInstallCaddyFail").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + client.Disconnect(); + return; + } + + //****** "Caddy安装成功!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_InstalledCaddyOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + sshShellCommand = @"systemctl enable caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //****** "上传Caddy配置文件......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfig").ToString(); + 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\\ssr_tls_caddy_config.caddyfile"; + upLoadPath = "/etc/caddy/Caddyfile"; + + UploadConfig(connectionInfo, caddyConfig, upLoadPath); + + //设置Caddy监听的随机端口 + string randomCaddyListenPortStr = randomCaddyListenPort.ToString(); + + sshShellCommand = $"sed -i 's/8800/{randomCaddyListenPortStr}/' {upLoadPath}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + + //设置域名 + + sshShellCommand = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/g' {upLoadPath}"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + //设置伪装网站 + if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false) + { + 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);//显示命令执行的结果 + + } + //****** "Caddy配置文件上传成功,OK!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_UploadCaddyConfigOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //****** "正在启动Caddy......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartCaddyService").ToString(); + 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);//显示命令执行的结果 + + Thread.Sleep(3000); + + sshShellCommand = @"ps aux | grep caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + if (currentShellCommandResult.Contains("/usr/bin/caddy") == true) + { + //****** "Caddy启动成功!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartCaddyServiceOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + //****** "Caddy启动失败!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartCaddyServiceFail").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + + //****** "正在启动Caddy(第二次尝试)!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartCaddyServiceSecond").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + sshShellCommand = @"systemctl restart caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(3000); + + sshShellCommand = @"ps aux | grep caddy"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + if (currentShellCommandResult.Contains("/usr/bin/caddy") == true) + { + //****** "Caddy启动成功!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartCaddyServiceOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + //****** "Caddy启动失败(第二次)!退出安装!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartCaddyServiceSecondFail").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + + //****** "Caddy启动失败,原因未知!请向开发者问询!" ****** + MessageBox.Show(Application.Current.FindResource("DisplayInstallInfo_CaddyServiceFailedExit").ToString()); + return; + } + } + + //****** "正在启动SSR......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartSoft").ToString() + "SSR......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + //启动SSR服务 + sshShellCommand = @"systemctl restart ssr"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(3000); + + sshShellCommand = @"ps aux | grep ssr"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + if (currentShellCommandResult.Contains("/usr/bin/ssr") == true) + { + //****** "SSR启动成功!" ****** + currentStatus = "SSR" + Application.Current.FindResource("DisplayInstallInfo_StartSoftOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + //****** "SSR启动失败!" ****** + currentStatus = "SSR" + Application.Current.FindResource("DisplayInstallInfo_StartSoftFail").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(3000); + + //****** "正在第二次尝试启动SSR!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_StartSoftSecond").ToString() + "SSR!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(3000); + sshShellCommand = @"systemctl restart ssr"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(3000); + + sshShellCommand = @"ps aux | grep ssr"; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, sshShellCommand);//显示执行的命令 + currentShellCommandResult = client.RunCommand(sshShellCommand).Result; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + if (currentShellCommandResult.Contains("usr/bin/ssr") == true) + { + //****** "SSR启动成功!" ****** + currentStatus = "SSR" + Application.Current.FindResource("DisplayInstallInfo_StartSoftOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + } + else + { + //****** "SSR启动失败(第二次)!退出安装!" ****** + currentStatus = "SSR" + Application.Current.FindResource("DisplayInstallInfo_StartSoftSecondFail").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + Thread.Sleep(1000); + + //****** "Trojan启动失败,原因未知!请向开发者问询!" ****** + MessageBox.Show("SSR" + Application.Current.FindResource("DisplayInstallInfo_StartSoftFailedExit").ToString()); + return; + } + } + + + //测试BBR条件,若满足则启用 + //****** "BBR测试......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_TestBBR").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + 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]); + + 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) + { + //****** "正在启用BBR......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_EnableBBR").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + 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) + { + //****** "BBR已经启用了!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_BBRisEnabled").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + else + { + //****** "系统不满足启用BBR的条件,启用失败!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_BBRFailed").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + client.Disconnect();//断开服务器ssh连接 + + //****** "生成客户端配置......" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_GenerateClientConfig").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + if (!Directory.Exists("ssr_config"))//如果不存在就创建file文件夹      + { + Directory.CreateDirectory("ssr_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)); + + // clientJson["remote_addr"] = ReceiveConfigurationParameters[4]; + // clientJson["remote_port"] = int.Parse(ReceiveConfigurationParameters[1]); + // clientJson["password"][0] = ReceiveConfigurationParameters[2]; + + // using (StreamWriter sw = new StreamWriter(@"trojan_config\config.json")) + // { + // sw.Write(clientJson.ToString()); + // } + //} + + //****** "SSR+TLS+Caddy安装成功,祝你玩的愉快!!" ****** + currentStatus = "SSR+TLS+Caddy" + Application.Current.FindResource("DisplayInstallInfo_ProxyInstalledOK").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + Thread.Sleep(1000); + + //显示服务端连接参数 + proxyType = "SSR"; + + ResultClientInformation resultClientInformation = new ResultClientInformation(); + resultClientInformation.ShowDialog(); + return; + } + } + catch (Exception ex1)//例外处理 + #region 例外处理 + { + ProcessException(ex1.Message); + + //****** "主机登录失败!" ****** + currentStatus = Application.Current.FindResource("DisplayInstallInfo_LoginFailed").ToString(); + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + currentShellCommandResult = currentStatus; + TextBoxMonitorCommandResults.Dispatcher.BeginInvoke(updateMonitorAction, TextBoxMonitorCommandResults, currentShellCommandResult);//显示命令执行的结果 + + } + #endregion + + } + + //更新SSR的密码 + private void ButtonSSRPassword_Click(object sender, RoutedEventArgs e) + { + TextBoxSSRPassword.Text = RandomUUID(); + } + + + #endregion #region 其他功能函数及系统工具相关 //上传配置文件 @@ -7541,8 +8854,6 @@ namespace ProxySU } } - - #endregion // #region 三合一安装过程 diff --git a/ProxySU/Properties/AssemblyInfo.cs b/ProxySU/Properties/AssemblyInfo.cs index c6eca19..6a85bfc 100644 --- a/ProxySU/Properties/AssemblyInfo.cs +++ b/ProxySU/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.4.0")] -[assembly: AssemblyFileVersion("2.0.4.0")] +[assembly: AssemblyVersion("2.1.0.0")] +[assembly: AssemblyFileVersion("2.1.0.0")] diff --git a/ProxySU/ResultClientInformation.xaml b/ProxySU/ResultClientInformation.xaml index b19a722..7f8f586 100644 --- a/ProxySU/ResultClientInformation.xaml +++ b/ProxySU/ResultClientInformation.xaml @@ -12,8 +12,8 @@ - - + + @@ -32,7 +32,6 @@ - @@ -72,6 +71,7 @@ + @@ -86,7 +86,6 @@ - @@ -100,9 +99,9 @@ - + @@ -117,8 +116,6 @@ - - @@ -129,10 +126,9 @@ - - + @@ -147,8 +143,6 @@ - - @@ -160,6 +154,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProxySU/ResultClientInformation.xaml.cs b/ProxySU/ResultClientInformation.xaml.cs index a35cf5e..f5bfbd5 100644 --- a/ProxySU/ResultClientInformation.xaml.cs +++ b/ProxySU/ResultClientInformation.xaml.cs @@ -38,6 +38,8 @@ namespace ProxySU GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; GroupBoxTrojanClient.Visibility = Visibility.Collapsed; GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; + GroupBoxSSRClient.Visibility = Visibility.Collapsed; + //主机地址 TextBoxHostAddress.Text = MainWindow.ReceiveConfigurationParameters[4]; //主机端口 @@ -290,6 +292,7 @@ namespace ProxySU GroupBoxTrojanGoClient.Visibility = Visibility.Visible; GroupBoxTrojanClient.Visibility = Visibility.Collapsed; GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; + GroupBoxSSRClient.Visibility = Visibility.Collapsed; TextBoxTrojanGoWSPath.Visibility = Visibility.Hidden; TextBlockTrojanGoWebSocketPath.Visibility = Visibility.Hidden; @@ -322,6 +325,7 @@ namespace ProxySU GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; GroupBoxTrojanClient.Visibility = Visibility.Visible; GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; + GroupBoxSSRClient.Visibility = Visibility.Collapsed; TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainTrojan").ToString(); @@ -341,6 +345,7 @@ namespace ProxySU GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; GroupBoxTrojanClient.Visibility = Visibility.Collapsed; GroupBoxNaiveProxyClient.Visibility = Visibility.Visible; + GroupBoxSSRClient.Visibility = Visibility.Collapsed; TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainNaiveProxy").ToString(); @@ -349,7 +354,33 @@ namespace ProxySU TextBoxNaivePassword.Text = MainWindow.ReceiveConfigurationParameters[2]; GenerateNaivePrxoyShareQRcodeAndBase64Url(); } - + else if (String.Equals(MainWindow.proxyType, "SSR")) + { + GroupBoxV2rayClient.Visibility = Visibility.Collapsed; + GroupBoxTrojanGoClient.Visibility = Visibility.Collapsed; + GroupBoxTrojanClient.Visibility = Visibility.Collapsed; + GroupBoxNaiveProxyClient.Visibility = Visibility.Collapsed; + GroupBoxSSRClient.Visibility = Visibility.Visible; + + TextBlockQrURLexplain.Text = Application.Current.FindResource("TextBlockQrURLexplainSSR").ToString(); + + //主机地址 + TextBoxSSRHostAddress.Text = MainWindow.ReceiveConfigurationParameters[4]; + //主机端口 + TextBoxSSRPort.Text = "443"; + //密码(uuid) + TextBoxSSRUUID.Text = MainWindow.ReceiveConfigurationParameters[2]; + //加密方式 + TextBoxSSREncryption.Text = "none"; + //传输协议 + TextBoxSSRTransmission.Text = "auth_chain_a"; + //混淆 + TextBoxSSRCamouflageType.Text = "tls1.2_ticket_auth"; + + //CheckDir("ssr_config"); + GenerateSSRShareQRcodeAndBase64Url(); + } + } #region 界面控制相关 private void HidePath() @@ -395,6 +426,7 @@ namespace ProxySU } #endregion + //生成v2rayN客户端导入文件 private void GenerateV2rayShareQRcodeAndBase64Url() { @@ -708,31 +740,9 @@ namespace ProxySU sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoPassword").ToString() + $"{TextBoxTrojanGoServerPassword.Text}"); //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoWebSocketPath").ToString() + $"{TextBoxTrojanGoWSPath.Text}"); - //sw.WriteLine("config.json"); - //sw.WriteLine("此文件为Trojan官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080"); - //sw.WriteLine("Trojan官方网站:https://trojan-gfw.github.io/trojan/"); - //sw.WriteLine("Trojan官方程序下载地址:https://github.com/trojan-gfw/trojan/releases"); - //sw.WriteLine("下载相应版本,Windows选择Trojan-x.xx-win.zip,解压后提取trojan.exe。与config.json放在同一目录,运行trojan.exe即可。"); - //sw.WriteLine("-----------------------------------------\n"); - //sw.WriteLine("QR.bmp"); - //sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点"); - //sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); - //sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); - //sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); - - //sw.WriteLine("-----------------------------------------\n"); - //sw.WriteLine("url.txt"); - //sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)复制粘贴导入节点的网址"); - //sw.WriteLine("-----------------------------------------\n"); - //sw.WriteLine("服务器通用连接配置参数"); - //sw.WriteLine($"地址(address):{TextBoxTrojanServerHost.Text}"); - //sw.WriteLine($"端口(Port):{TextBoxTrojanServerPort.Text}"); - //sw.WriteLine($"密钥:{TextBoxTrojanServerPassword.Text}"); } - - } //生成NaiveProxy客户端资料 @@ -783,21 +793,8 @@ namespace ProxySU //sw.WriteLine("下载相应版本,Windows选择naiveproxy-x.xx-win.zip,解压后提取naive.exe。与config.json放在同一目录,运行naive.exe即可。"); sw.WriteLine(Application.Current.FindResource("readmeTxtNaiveProxyExplainLine04").ToString()); - //sw.WriteLine("此文件为NaiveProxy官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080"); - //sw.WriteLine("NaiveProxy官方网站:https://github.com/klzgrad/naiveproxy"); - //sw.WriteLine("NaiveProxy官方程序下载地址:https://github.com/klzgrad/naiveproxy/releases"); - //sw.WriteLine("下载相应版本,Windows选择naiveproxy-x.xx-win.zip,解压后提取naive.exe。与config.json放在同一目录,运行naive.exe即可。"); - sw.WriteLine("-----------------------------------------\n"); - //sw.WriteLine("其他平台的客户端,暂未发布"); - //sw.WriteLine("QR.bmp"); - //sw.WriteLine("此文件为Trojan-QT5 (windows)、igniter(Android)、Shadowrocket(ios)扫码导入节点"); - //sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); - //sw.WriteLine("igniter(Android)下载网址:https://github.com/trojan-gfw/igniter/releases"); - //sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); - - //sw.WriteLine("-----------------------------------------\n"); sw.WriteLine("url.txt"); //sw.WriteLine("此文件为NaiveGUI(windows)复制粘贴导入节点的网址"); @@ -824,6 +821,80 @@ namespace ProxySU } + //生成SSR客户端资料 + private void GenerateSSRShareQRcodeAndBase64Url() + { + + string saveFileFolderFirst = TextBoxSSRHostAddress.Text; + int num = 1; + saveFileFolder = saveFileFolderFirst; + CheckDir("ssr_config"); + while (Directory.Exists(@"ssr_config\" + saveFileFolder)) + { + saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); + num++; + } + CheckDir(@"ssr_config\" + saveFileFolder); + + string ssrUrl = GetSSRLinkForServer(); + TextBoxURL.Text = ssrUrl; + using (StreamWriter sw = new StreamWriter($"ssr_config\\{saveFileFolder}\\url.txt")) + { + sw.WriteLine(ssrUrl); + + } + CreateQRCode(ssrUrl, "ssr_config"); + + using (StreamWriter sw = new StreamWriter($"ssr_config\\{saveFileFolder}\\readme.txt")) + { + //sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("QR.bmp"); + + //***"此文件为ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)扫码导入节点"*** + sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine05").ToString()); + + //***"ShadowsocksR (windows)下载网址:https://github.com/shadowsocksrr/shadowsocksr-csharp/releases"*** + sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine06").ToString()); + + //***"SSRR(Android)下载网址:https://github.com/shadowsocksrr/shadowsocksr-android/releases"*** + sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine07").ToString()); + + //***"Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"*** + sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine08").ToString()); + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("url.txt"); + + //***"此文件为ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)复制粘贴导入节点的网址"*** + sw.WriteLine(Application.Current.FindResource("readmeTxtSSRExplainLine09").ToString()); + sw.WriteLine("-----------------------------------------\n"); + + //***"服务器通用连接配置参数"*** + sw.WriteLine(Application.Current.FindResource("readmeTxtTrojanExplainLine10").ToString()); + + //****** 服务器地址(address): ****** + sw.WriteLine(Application.Current.FindResource("TextBlockServerAddress").ToString() + $"{ TextBoxSSRHostAddress.Text}"); + + //****** 端口(port): ****** + sw.WriteLine(Application.Current.FindResource("TextBlockServerPort").ToString() + $"{TextBoxSSRPort.Text}"); + + //****** 密码: ****** + sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoPassword").ToString() + $"{TextBoxSSRUUID.Text}"); + + //****** 加密方式: ****** + sw.WriteLine(Application.Current.FindResource("TextBlockEncryption").ToString() + $"{TextBoxSSREncryption.Text}"); + + //****** 传输协议: ****** + sw.WriteLine(Application.Current.FindResource("TextBlockTransferProtocol").ToString() + $"{TextBoxSSRTransmission.Text}"); + + //****** 混淆: ****** + sw.WriteLine(Application.Current.FindResource("TextBlockCamouflageType").ToString() + $"{TextBoxSSRCamouflageType.Text}"); + + //****** 密码: ****** + //sw.WriteLine(Application.Current.FindResource("TextBlockTrojanGoWebSocketPath").ToString() + $"{TextBoxTrojanGoWSPath.Text}"); + + } + } + //生成base64 private string ToBase64Encode(string text) { @@ -894,6 +965,69 @@ namespace ProxySU System.Diagnostics.Process.Start("explorer.exe", openFolderPath); this.Close(); } + else if (String.Equals(MainWindow.proxyType, "SSR")) + { + string openFolderPath = @"ssr_config\" + saveFileFolder; + System.Diagnostics.Process.Start("explorer.exe", openFolderPath); + this.Close(); + } + } + + //SSR生成URL链接 + public string GetSSRLinkForServer() + { + string server = TextBoxSSRHostAddress.Text; + string server_port = TextBoxSSRPort.Text; + string password = TextBoxSSRUUID.Text; + string protocol = TextBoxSSRTransmission.Text; + string method = TextBoxSSREncryption.Text; + string obfs = TextBoxSSRCamouflageType.Text; + + string obfsparam=""; + string protocolparam = ""; + string remarks = TextBoxSSRHostAddress.Text; + string group = TextBoxSSRHostAddress.Text; + bool udp_over_tcp = true; + int server_udp_port = 0; + + string main_part = server + ":" + server_port + ":" + protocol + ":" + method + ":" + obfs + ":" + EncodeUrlSafeBase64(password); + string param_str = "obfsparam=" + EncodeUrlSafeBase64(obfsparam ?? ""); + if (!string.IsNullOrEmpty(protocolparam)) + { + param_str += "&protoparam=" + EncodeUrlSafeBase64(protocolparam); + } + if (!string.IsNullOrEmpty(remarks)) + { + param_str += "&remarks=" + EncodeUrlSafeBase64(remarks); + } + if (!string.IsNullOrEmpty(group)) + { + param_str += "&group=" + EncodeUrlSafeBase64(group); + } + if (udp_over_tcp) + { + param_str += "&uot=" + "1"; + } + if (server_udp_port > 0) + { + param_str += "&udpport=" + server_udp_port.ToString(); + } + string base64 = EncodeUrlSafeBase64(main_part + "/?" + param_str); + return "ssr://" + base64; + } + + private string EncodeUrlSafeBase64(byte[] val, bool trim) + { + if (trim) + return Convert.ToBase64String(val).Replace('+', '-').Replace('/', '_').TrimEnd('='); + else + return Convert.ToBase64String(val).Replace('+', '-').Replace('/', '_'); + } + private string EncodeUrlSafeBase64(string val, bool trim = true) + { + return EncodeUrlSafeBase64(Encoding.UTF8.GetBytes(val), trim); } } + + } diff --git a/ProxySU/Translations/ProxySU.en-US.xaml b/ProxySU/Translations/ProxySU.en-US.xaml index c1de2e4..13d620b 100644 --- a/ProxySU/Translations/ProxySU.en-US.xaml +++ b/ProxySU/Translations/ProxySU.en-US.xaml @@ -44,6 +44,9 @@ Random NaiveProxy install Cancel + + Mode: SSR+TLS+Caddy + SSR install Proofreading Time Release 80/443 @@ -134,7 +137,7 @@ The default is 16, and you can fill in a value not exceeding 64. If the client does not have this option, leave it blank Encryption method: Transfer Protocol: - Camouflage type: + Camouflage type(Confuse): TLS: Path: mKCP Seed/QUIC key: @@ -145,6 +148,7 @@ " can be used for ShadowRocket (ios), ignore (Android), Trojan-QT5 (windows) to scan codes and import URLs. Note: some clients may not support WebSocket mode ." "Can be used for ShadowRocket (ios), ignore (Android), Trojan-QT5 (windows) to scan codes and import URLs. Note: Some clients may not support WebSocket mode." URL import link for NaiveGUI (windows) + Used to scan codes and import URL import links for ShadowsocksR (windows), SSRR (android), Shadowrocket (ios) Host address, host port, and user name are required and cannot be empty!! The login password is required and cannot be empty!! @@ -307,7 +311,13 @@ This file is NaiveGUI (windows) copy and paste the URL of the imported node NaiveGUI(windows) download URL: https://github.com/ExcitedCodes/NaiveGUI/releases Server general connection configuration parameters - + + This file is for ShadowsocksR (windows), SSRR (Android), Shadowrocket (ios) scan code import node + ShadowsocksR (windows) download URL: https://github.com/shadowsocksrr/shadowsocksr-csharp/releases + SSRR (Android) download URL: https://github.com/shadowsocksrr/shadowsocksr-android/releases + Shadowrocket(ios) download, you need to use the AppleID of the foreign region. Please Google method yourself. + This file is ShadowsocksR (windows), SSRR (Android), Shadowrocket (ios) copy and paste the URL of the imported node + Server general connection configuration parameters + 模式:SSR+TLS+Caddy + SSR一键安装 + 校对时间 释放80/443端口 @@ -134,7 +138,7 @@ 默认16,可以填不超过64的值,客户端没有此选项可不填 加密方式: 传输协议: - 伪装类型: + 伪装类型(混淆): 是否使用TLS: 路径(Path): mKCP Seed/QUIC密钥: @@ -145,6 +149,7 @@ "可用于ShadowRocket (ios)、igniter(Android)、Trojan-QT5 (windows) 扫码和导入url。注意:有的客户端可能不支持WebSocket模式。" "可用于ShadowRocket (ios)、igniter(Android)、Trojan-QT5 (windows) 扫码和导入url。注意:有的客户端可能不支持WebSocket模式。" 用于NaiveGUI(windows)的URL导入链接 + 用于ShadowsocksR(windows)、SSRR(android)、Shadowrocket(ios)的扫码和导入URL导入链接 主机地址、主机端口、用户名为必填项,不能为空!! 登录密码为必填项,不能为空!! @@ -307,7 +312,13 @@ 此文件为NaiveGUI(windows)复制粘贴导入节点的网址 NaiveGUI(windows)下载网址:https://github.com/ExcitedCodes/NaiveGUI/releases 服务器通用连接配置参数 - + + 此文件为ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)扫码导入节点 + ShadowsocksR (windows)下载网址:https://github.com/shadowsocksrr/shadowsocksr-csharp/releases + SSRR(Android)下载网址:https://github.com/shadowsocksrr/shadowsocksr-android/releases + Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。 + 此文件为ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)复制粘贴导入节点的网址 + 服务器通用连接配置参数 + 模式:SSR+TLS+Caddy + SSR一鍵安裝 校對時間 釋放80/443端口 @@ -134,7 +137,7 @@ 默認16,可以填不超過64的值,客戶端沒有此選項可不填 加密方式: 傳輸協議: - 偽裝類型: + 偽裝類型(混淆): 是否使用TLS: 路徑(Path): mKCP Seed/QUIC密鑰: @@ -145,6 +148,7 @@ "可用於ShadowRocket (ios)、igniter(Android)、Trojan-QT5 (windows) 掃碼和導入url。注意:有的客戶端可能不支持WebSocket模式。" "可用於ShadowRocket (ios)、igniter(Android)、Trojan-QT5 (windows) 掃碼和導入url。注意:有的客戶端可能不支持WebSocket模式。" 用於NaiveGUI(windows)的URL導入鏈接 + 用於ShadowsocksR(windows)、SSRR(android)、Shadowrocket(ios)的掃碼和導入URL導入鏈接 主機地址、主機端口、用戶名為必填項,不能為空!! 登錄密碼為必填項,不能為空!! @@ -308,5 +312,12 @@ 此文件為NaiveGUI(windows)複製粘貼導入節點的網址 NaiveGUI(windows)下載網址:https://github.com/ExcitedCodes/NaiveGUI/releases 服務器通用連接配置參數 + + 此文件為ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)掃碼導入節點 + ShadowsocksR (windows)下載網址:https://github.com/shadowsocksrr/shadowsocksr-csharp/releases + SSRR(Android)下載網址:https://github.com/shadowsocksrr/shadowsocksr-android/releases + Shadowrocket(ios)下載,需要使用國外區的AppleID。請自行谷歌方法。 + 此文件為ShadowsocksR (windows)、SSRR(Android)、Shadowrocket(ios)複製粘貼導入節點的網址 + 服務器通用連接配置參數 \ No newline at end of file diff --git a/ProxySU/TrojanGoTemplateWindow.xaml b/ProxySU/TrojanGoTemplateWindow.xaml index 406c757..31de2ad 100644 --- a/ProxySU/TrojanGoTemplateWindow.xaml +++ b/ProxySU/TrojanGoTemplateWindow.xaml @@ -93,8 +93,8 @@ - - + + diff --git a/ProxySU/V2RayTemplateWindow.xaml.cs b/ProxySU/V2RayTemplateWindow.xaml.cs index ecbd674..b6be90b 100644 --- a/ProxySU/V2RayTemplateWindow.xaml.cs +++ b/ProxySU/V2RayTemplateWindow.xaml.cs @@ -502,7 +502,7 @@ namespace ProxySU Guid uuid = Guid.NewGuid(); TextBoxNewUUID.Text = uuid.ToString(); Random random = new Random(); - int randomServerPort = random.Next(10000, 50000); + int randomServerPort = random.Next(30001, 50000); TextBoxServerListenPort.Text = randomServerPort.ToString(); //清除其他选项卡中的选项 UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); @@ -705,7 +705,7 @@ namespace ProxySU TextBoxQuicUUID.Text = uuid.ToString(); Random random = new Random(); - int randomServerPort = random.Next(10000, 50000); + int randomServerPort = random.Next(30001, 50000); TextBoxServerListenPort.Text = randomServerPort.ToString(); //清除其他选项卡中的选项 UncheckLayouts((TabItem)TabControlTemplate.SelectedItem); @@ -728,7 +728,7 @@ namespace ProxySU private void ButtonServerListenPort_Click(object sender, RoutedEventArgs e) { Random random = new Random(); - int randomServerPort = random.Next(10000, 50000); + int randomServerPort = random.Next(30001, 50000); TextBoxServerListenPort.Text = randomServerPort.ToString(); } //产生随机的Path diff --git a/ProxySU/bin/Beta/Beta.zip b/ProxySU/bin/Beta/Beta.zip index a9b9770..b374ba1 100644 Binary files a/ProxySU/bin/Beta/Beta.zip and b/ProxySU/bin/Beta/Beta.zip differ