From 194ecc78c10cb37de147837e1fb8db6803577fff Mon Sep 17 00:00:00 2001 From: ProxySU Date: Wed, 22 Apr 2020 21:13:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Trojan=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E5=AE=89=E8=A3=852?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxySU/MainWindow.xaml | 14 +- ProxySU/MainWindow.xaml.cs | 131 ++++++++++--------- ProxySU/ResultClientInformation.xaml.cs | 1 + ProxySU/TrojanResultClientInfoWindow.xaml | 32 ++++- ProxySU/TrojanResultClientInfoWindow.xaml.cs | 131 +++++++++++++++++++ ProxySU/TrojanTemplateWindow.xaml.cs | 9 +- 6 files changed, 240 insertions(+), 78 deletions(-) diff --git a/ProxySU/MainWindow.xaml b/ProxySU/MainWindow.xaml index 48f5169..6d27f84 100644 --- a/ProxySU/MainWindow.xaml +++ b/ProxySU/MainWindow.xaml @@ -174,7 +174,7 @@ - - - + diff --git a/ProxySU/MainWindow.xaml.cs b/ProxySU/MainWindow.xaml.cs index 6411e24..8a381f3 100644 --- a/ProxySU/MainWindow.xaml.cs +++ b/ProxySU/MainWindow.xaml.cs @@ -1323,7 +1323,7 @@ namespace ProxySU Thread.Sleep(1000); } //检测是否安装有Trojan - currentStatus = "检测系统是否已经安装V2ray......"; + currentStatus = "检测系统是否已经安装Trojan......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); Thread.Sleep(1000); @@ -1422,10 +1422,12 @@ namespace ProxySU } string nativeIp = client.RunCommand("curl -4 ip.sb").Result.ToString(); + //MessageBox.Show(nativeIp); string testDomainCmd = "ping " + ReceiveConfigurationParameters[4] + " -c 1 | grep -oE -m1 \"([0-9]{1,3}\\.){3}[0-9]{1,3}\""; + //MessageBox.Show(testDomainCmd); string resultTestDomainCmd = client.RunCommand(testDomainCmd).Result.ToString(); - - if (String.Equals(nativeIp, resultCmd) == true) + //MessageBox.Show(resultTestDomainCmd); + if (String.Equals(nativeIp, resultTestDomainCmd) == true) { currentStatus = "解析正确!"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); @@ -1505,7 +1507,8 @@ namespace ProxySU //下载官方安装脚本安装 - client.RunCommand("bash -c \"$(curl - fsSL https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh)\""); + client.RunCommand("curl -o /tmp/trojan-quickstart.sh https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh"); + client.RunCommand("yes | bash /tmp/trojan-quickstart.sh"); //client.RunCommand("bash /tmp/go.sh -f"); string installResult = client.RunCommand("find / -name trojan").Result.ToString(); @@ -1575,62 +1578,7 @@ namespace ProxySU } } - //安装nginx - if (serverConfig.Contains("trojan_server") == true) - { - currentStatus = "正在安装Caddy"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - - client.RunCommand("curl https://getcaddy.com -o getcaddy"); - client.RunCommand("bash getcaddy personal hook.service"); - client.RunCommand("mkdir -p /etc/caddy"); - client.RunCommand("mkdir -p /var/www"); - - - currentStatus = "上传Caddy配置文件......"; - textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); - Thread.Sleep(1000); - if (serverConfig.Contains("trojan_server") == true) - { - serverConfig = "TemplateConfg\\trojan_caddy_config.caddyfile"; - } - - upLoadPath = "/etc/caddy/Caddyfile"; - UploadConfig(connectionInfo, serverConfig, upLoadPath); - - //设置Caddyfile文件中的tls 邮箱 - //string sshCmdEmail = $"email={ReceiveConfigurationParameters[4]};email=${{email/./@}};echo $email";//结尾有回车符 - //string email = client.RunCommand(sshCmdEmail).Result.Replace("\n", "");//删除结尾的回车符 - string email = $"user@{ReceiveConfigurationParameters[4]}"; - string sshCmd;// = $"sed -i 's/off/{email}/' {upLoadPath}";//设置Caddyfile中的邮箱 - //client.RunCommand(sshCmd); - //设置Path - //sshCmd = $"sed -i 's/##path##/\\{ReceiveConfigurationParameters[3]}/' {upLoadPath}"; - //MessageBox.Show(sshCmd); - //client.RunCommand(sshCmd); - //设置域名 - sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}/' {upLoadPath}"; - //MessageBox.Show(sshCmd); - client.RunCommand(sshCmd); - //设置伪装网站 - if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false) - { - sshCmd = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; - //MessageBox.Show(sshCmd); - client.RunCommand(sshCmd); - } - Thread.Sleep(2000); - - //安装Caddy服务 - sshCmd = $"caddy -service install -agree -conf /etc/caddy/Caddyfile -email {email}"; - //MessageBox.Show(sshCmd); - client.RunCommand(sshCmd); - - - //启动Caddy服务 - client.RunCommand("caddy -service restart"); - } + if (serverConfig.Contains("trojan_server") == true) { @@ -1664,7 +1612,7 @@ namespace ProxySU //client.RunCommand("mkdir -p /etc/v2ray/ssl"); client.RunCommand($"/root/.acme.sh/acme.sh --issue --standalone -d {ReceiveConfigurationParameters[4]}"); - currentStatus = "安装证书到V2ray......"; + currentStatus = "安装证书到Trojan......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); Thread.Sleep(1000); client.RunCommand($"/root/.acme.sh/acme.sh --installcert -d {ReceiveConfigurationParameters[4]} --certpath /usr/local/etc/trojan/trojan_ssl.crt --keypath /usr/local/etc/trojan/trojan_ssl.key --capath /usr/local/etc/trojan/trojan_ssl.crt --reloadcmd \"systemctl restart trojan\""); @@ -1680,6 +1628,58 @@ namespace ProxySU textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); Thread.Sleep(1000); + //安装Caddy + if (serverConfig.Contains("trojan_server") == true) + { + currentStatus = "正在安装Caddy"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + Thread.Sleep(1000); + + client.RunCommand("curl https://getcaddy.com -o getcaddy"); + client.RunCommand("bash getcaddy personal hook.service"); + client.RunCommand("mkdir -p /etc/caddy"); + client.RunCommand("mkdir -p /var/www"); + + + currentStatus = "上传Caddy配置文件......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + Thread.Sleep(1000); + + string caddyConfig = ""; + if (serverConfig.Contains("trojan_server") == true) + { + caddyConfig = "TemplateConfg\\trojan_caddy_config.caddyfile"; + } + + upLoadPath = "/etc/caddy/Caddyfile"; + UploadConfig(connectionInfo, caddyConfig, upLoadPath); + + //设置Caddyfile文件中的tls 邮箱 + + string email = $"user@{ReceiveConfigurationParameters[4]}"; + string sshCmd; + //设置域名 + sshCmd = $"sed -i 's/##domain##/{ReceiveConfigurationParameters[4]}:80/' {upLoadPath}"; + //MessageBox.Show(sshCmd); + client.RunCommand(sshCmd); + //设置伪装网站 + if (String.IsNullOrEmpty(ReceiveConfigurationParameters[7]) == false) + { + sshCmd = $"sed -i 's/##sites##/proxy \\/ {ReceiveConfigurationParameters[7]}/' {upLoadPath}"; + //MessageBox.Show(sshCmd); + client.RunCommand(sshCmd); + } + Thread.Sleep(2000); + + //安装Caddy服务 + sshCmd = $"caddy -service install -agree -conf /etc/caddy/Caddyfile -email {email}"; + //MessageBox.Show(sshCmd); + client.RunCommand(sshCmd); + + + //启动Caddy服务 + client.RunCommand("caddy -service restart"); + } //生成客户端配置 currentStatus = "生成客户端配置......"; @@ -1711,7 +1711,7 @@ namespace ProxySU Thread.Sleep(1000); //显示服务端连接参数 - //MessageBox.Show("用于V2ray官方客户端的配置文件已保存在config文件夹中"); + //MessageBox.Show("用于Trojan官方客户端的配置文件已保存在config文件夹中"); TrojanResultClientInfoWindow resultClientInformation = new TrojanResultClientInfoWindow(); resultClientInformation.ShowDialog(); @@ -1755,6 +1755,13 @@ namespace ProxySU #endregion } + + private void ButtonTestTrojanClientInfoWin_Click(object sender, RoutedEventArgs e) + { + //TrojanResultClientInfoWindow resultClientInformation = new TrojanResultClientInfoWindow(); + //resultClientInformation.ShowDialog(); + MessageBox.Show(ReceiveConfigurationParameters[4]); + } } } diff --git a/ProxySU/ResultClientInformation.xaml.cs b/ProxySU/ResultClientInformation.xaml.cs index f186a54..e8bd9b1 100644 --- a/ProxySU/ResultClientInformation.xaml.cs +++ b/ProxySU/ResultClientInformation.xaml.cs @@ -329,6 +329,7 @@ namespace ProxySU string saveFileFolderFirst = v2rayNjsonObject["ps"].ToString(); int num = 1; saveFileFolder = saveFileFolderFirst; + CheckDir(@"v2ray_config"); while (Directory.Exists(@"v2ray_config\" + saveFileFolder)) { saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); diff --git a/ProxySU/TrojanResultClientInfoWindow.xaml b/ProxySU/TrojanResultClientInfoWindow.xaml index 3f8da0f..eb1fe82 100644 --- a/ProxySU/TrojanResultClientInfoWindow.xaml +++ b/ProxySU/TrojanResultClientInfoWindow.xaml @@ -14,13 +14,43 @@ + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ProxySU/TrojanResultClientInfoWindow.xaml.cs b/ProxySU/TrojanResultClientInfoWindow.xaml.cs index eab8844..3d7fb7d 100644 --- a/ProxySU/TrojanResultClientInfoWindow.xaml.cs +++ b/ProxySU/TrojanResultClientInfoWindow.xaml.cs @@ -10,6 +10,13 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using System.IO; +using Renci.SshNet; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using System.Drawing; +using QRCoder; namespace ProxySU { @@ -18,9 +25,133 @@ namespace ProxySU /// public partial class TrojanResultClientInfoWindow : Window { + private string saveFileFolder = ""; public TrojanResultClientInfoWindow() { InitializeComponent(); + //主机地址 + TextBoxTrojanServerHost.Text = MainWindow.ReceiveConfigurationParameters[4]; + //主机端口 + TextBoxTrojanServerPort.Text = MainWindow.ReceiveConfigurationParameters[1]; + //密钥(uuid) + TextBoxTrojanServerPassword.Text = MainWindow.ReceiveConfigurationParameters[2]; + + GenerateV2rayShareQRcodeAndBase64Url(); + + } + + //生成v2rayN客户端导入文件 + private void GenerateV2rayShareQRcodeAndBase64Url() + { + + string saveFileFolderFirst = TextBoxTrojanServerHost.Text; + int num = 1; + saveFileFolder = saveFileFolderFirst; + CheckDir("trojan_config"); + while (Directory.Exists(@"trojan_config\" + saveFileFolder)) + { + saveFileFolder = saveFileFolderFirst + "_copy_" + num.ToString(); + num++; + } + CheckDir(@"trojan_config\" + saveFileFolder); + //MessageBox.Show(v2rayNjsonObject.ToString()); + // string vmessUrl = "vmess://" + ToBase64Encode(v2rayNjsonObject.ToString()); + //TextBoxvVmessUrl.Text = vmessUrl; + //using (StreamWriter sw = new StreamWriter($"trojan_config\\{saveFileFolder}\\url.txt")) + //{ + // sw.WriteLine(vmessUrl); + + //} + //CreateQRCode(vmessUrl); + + //移动Trojan官方程序配置文件到相应目录 + if (File.Exists(@"trojan_config\config.json")) + { + File.Move(@"trojan_config\config.json", @"trojan_config\" + saveFileFolder + @"\config.json"); + //File.Delete(@"config\config.json");//删除该文件 + } + + using (StreamWriter sw = new StreamWriter($"trojan_config\\{saveFileFolder}\\说明.txt")) + { + sw.WriteLine("config.json"); + sw.WriteLine("此文件为Trojan官方程序所使用的客户端配置文件,配置为全局模式,socks5地址:127.0.0.1:1080"); + sw.WriteLine("Trojan官方网站:https://trojan-gfw.github.io/trojan/"); + sw.WriteLine("Trojan官方程序下载地址:https://github.com/trojan-gfw/trojan/releases"); + sw.WriteLine("下载相应版本,Windows选择Trojan-x.xx-win.zip,解压后提取trojan.exe。与config.json放在同一目录,运行trojan.exe即可。"); + //sw.WriteLine("-----------------------------------------"); + //sw.WriteLine("QR.bmp"); + //sw.WriteLine("此文件为v2rayN、v2rayNG(Android)、Shadowrocket(ios)扫码导入节点"); + //sw.WriteLine("v2rayN下载网址:https://github.com/2dust/v2rayN/releases"); + //sw.WriteLine("v2rayNG(Android)下载网址:https://github.com/2dust/v2rayNG/releases"); + //sw.WriteLine("v2rayNG(Android)在Google Play下载网址:https://play.google.com/store/apps/details?id=com.v2ray.ang"); + //sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); + + //sw.WriteLine("-----------------------------------------"); + //sw.WriteLine("url.txt"); + //sw.WriteLine("此文件为v2rayN、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址"); + //sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("服务器通用连接配置参数"); + sw.WriteLine($"地址(address):{TextBoxTrojanServerHost.Text}"); + sw.WriteLine($"端口(Port):{TextBoxTrojanServerPort.Text}"); + sw.WriteLine($"密钥:{TextBoxTrojanServerPassword.Text}"); + //sw.WriteLine($"额外ID:{TextBoxUUIDextra.Text}"); + //sw.WriteLine($"加密方式:{TextBoxEncryption.Text}"); + //sw.WriteLine($"传输协议:{TextBoxTransmission.Text}"); + //sw.WriteLine($"伪装类型:{TextBoxCamouflageType.Text}"); + //sw.WriteLine($"是否使用TLS:{TextBoxTLS.Text}"); + //sw.WriteLine($"host:{TextBoxHostAddress.Text}"); + //sw.WriteLine($"路径(Path):{TextBoxPath.Text}"); + //sw.WriteLine($"QUIC密钥:{TextBoxQuicKey.Text}"); + } + + + + } + //生成base64 + private string ToBase64Encode(string text) + { + if (String.IsNullOrEmpty(text)) + { + return text; + } + + byte[] textBytes = Encoding.UTF8.GetBytes(text); + return Convert.ToBase64String(textBytes); + } + //生成QRcoder图片 + private void CreateQRCode(string varBase64) + { + //string varBase64 = varBase64; + QRCodeGenerator qrGenerator = new QRCodeGenerator(); + QRCodeData qrCodeData = qrGenerator.CreateQrCode(varBase64, QRCodeGenerator.ECCLevel.Q); + QRCode qrCode = new QRCode(qrCodeData); + Bitmap qrCodeImage = qrCode.GetGraphic(20); + IntPtr myImagePtr = qrCodeImage.GetHbitmap(); + BitmapSource imgsource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(myImagePtr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); + //ImageShareQRcode.Source = imgsource; + //DeleteObject(myImagePtr); + qrCodeImage.Save($"trojan_config\\{saveFileFolder}\\QR.bmp"); + //ImageShareQRcode.Source = @"config\v2rayN.bmp"; + } + //判断目录是否存在,不存在则创建 + private static bool CheckDir(string folder) + { + try + { + if (!Directory.Exists(folder))//如果不存在就创建file文件夹 + Directory.CreateDirectory(folder);//创建该文件夹   + return true; + } + catch (Exception) + { + return false; + } + } + private void ButtonTrojanResultOpen_Click(object sender, RoutedEventArgs e) + { + string openFolderPath = @"trojan_config\" + saveFileFolder; + System.Diagnostics.Process.Start("explorer.exe", openFolderPath); + this.Close(); } } } diff --git a/ProxySU/TrojanTemplateWindow.xaml.cs b/ProxySU/TrojanTemplateWindow.xaml.cs index d93ec8f..e0f9e99 100644 --- a/ProxySU/TrojanTemplateWindow.xaml.cs +++ b/ProxySU/TrojanTemplateWindow.xaml.cs @@ -53,11 +53,12 @@ namespace ProxySU MainWindow.ReceiveConfigurationParameters[7] = "http:\\/\\/" + TextBoxMaskSites.Text; } } + //传递服务端口 + MainWindow.ReceiveConfigurationParameters[1] = TextBoxServerListenPort.Text.ToString(); + //传递密码(uuid) + MainWindow.ReceiveConfigurationParameters[2] = TextBoxNewUUID.Text.ToString(); } - //传递服务端口 - MainWindow.ReceiveConfigurationParameters[1] = TextBoxServerListenPort.Text.ToString(); - //传递密码(uuid) - MainWindow.ReceiveConfigurationParameters[2] = TextBoxNewUUID.Text.ToString(); + this.Close(); }