diff --git a/ProxySU/MainWindow.xaml.cs b/ProxySU/MainWindow.xaml.cs index 8a381f3..8c3a05c 100644 --- a/ProxySU/MainWindow.xaml.cs +++ b/ProxySU/MainWindow.xaml.cs @@ -628,11 +628,46 @@ namespace ProxySU //MessageBox.Show(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result); if (String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result) == false || String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :443 | grep LISTEN").Result) == false) { - MessageBox.Show("80/443端口之一,或全部被占用,请先用系统工具中的“释放80/443端口”工具,释放出,再重新安装"); - currentStatus = "端口被占用,安装失败......"; + //MessageBox.Show("80/443端口之一,或全部被占用,请先用系统工具中的“释放80/443端口”工具,释放出,再重新安装"); + MessageBoxResult dialogResult = MessageBox.Show("80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序?", "Stop application", MessageBoxButton.YesNo); + if (dialogResult == MessageBoxResult.No) + { + currentStatus = "端口被占用,安装失败......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + Thread.Sleep(1000); + return; + } + + currentStatus = "正在释放80/443端口......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); Thread.Sleep(1000); - return; + + string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; + string cmdResult = client.RunCommand(cmdTestPort).Result; + //MessageBox.Show(cmdTestPort); + if (String.IsNullOrEmpty(cmdResult) == false) + { + //MessageBox.Show(cmdResult); + string[] cmdResultArry443 = cmdResult.Split(' '); + //MessageBox.Show(cmdResultArry443[3]); + client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); + client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); + client.RunCommand($"kill -9 {cmdResultArry443[3]}"); + } + + cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; + cmdResult = client.RunCommand(cmdTestPort).Result; + if (String.IsNullOrEmpty(cmdResult) == false) + { + string[] cmdResultArry80 = cmdResult.Split(' '); + client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); + client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); + client.RunCommand($"kill -9 {cmdResultArry80[3]}"); + } + currentStatus = "80/443端口释放完毕!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + Thread.Sleep(1000); + } } currentStatus = "符合安装要求,布署中......"; @@ -1148,6 +1183,7 @@ namespace ProxySU { return; } + ConnectionInfo testconnect = GenerateConnectionInfo(); try { @@ -1178,7 +1214,7 @@ namespace ProxySU client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); client.RunCommand($"kill -9 {cmdResultArry80[3]}"); } - MessageBox.Show("执行完毕!"); + MessageBox.Show("释放完毕!"); client.Disconnect(); } } @@ -1472,11 +1508,45 @@ namespace ProxySU //MessageBox.Show(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result); if (String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :80 | grep LISTEN").Result) == false || String.IsNullOrEmpty(client.RunCommand(@"lsof -n -P -i :443 | grep LISTEN").Result) == false) { - MessageBox.Show("80/443端口之一,或全部被占用,请先用系统工具中的“释放80/443端口”工具,释放出,再重新安装"); - currentStatus = "端口被占用,安装失败......"; + MessageBoxResult dialogResult = MessageBox.Show("80/443端口之一,或全部被占用,将强制停止占用80/443端口的程序?", "Stop application", MessageBoxButton.YesNo); + if (dialogResult == MessageBoxResult.No) + { + currentStatus = "端口被占用,安装失败......"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + Thread.Sleep(1000); + return; + } + + currentStatus = "正在释放80/443端口......"; textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); Thread.Sleep(1000); - return; + + string cmdTestPort = @"lsof -n -P -i :443 | grep LISTEN"; + string cmdResult = client.RunCommand(cmdTestPort).Result; + //MessageBox.Show(cmdTestPort); + if (String.IsNullOrEmpty(cmdResult) == false) + { + //MessageBox.Show(cmdResult); + string[] cmdResultArry443 = cmdResult.Split(' '); + //MessageBox.Show(cmdResultArry443[3]); + client.RunCommand($"systemctl stop {cmdResultArry443[0]}"); + client.RunCommand($"systemctl disable {cmdResultArry443[0]}"); + client.RunCommand($"kill -9 {cmdResultArry443[3]}"); + } + + cmdTestPort = @"lsof -n -P -i :80 | grep LISTEN"; + cmdResult = client.RunCommand(cmdTestPort).Result; + if (String.IsNullOrEmpty(cmdResult) == false) + { + string[] cmdResultArry80 = cmdResult.Split(' '); + client.RunCommand($"systemctl stop {cmdResultArry80[0]}"); + client.RunCommand($"systemctl disable {cmdResultArry80[0]}"); + client.RunCommand($"kill -9 {cmdResultArry80[3]}"); + } + currentStatus = "80/443端口释放完毕!"; + textBlockName.Dispatcher.BeginInvoke(updateAction, textBlockName, progressBar, currentStatus); + Thread.Sleep(1000); + } } currentStatus = "符合安装要求,布署中......"; @@ -1509,7 +1579,7 @@ namespace ProxySU 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(); if (!installResult.Contains("/usr/local/bin/trojan")) diff --git a/ProxySU/ProxySU.csproj b/ProxySU/ProxySU.csproj index 9ad6c79..357b256 100644 --- a/ProxySU/ProxySU.csproj +++ b/ProxySU/ProxySU.csproj @@ -167,6 +167,6 @@ del "$(TargetDir)*.xml" del "$(TargetDir)*.pdb" del "$(TargetDir)*.zip" -"D:\Program Files\7-Zip\7z.exe" a $(TargetDir)Release.zip $(TargetDir) -xr!config +"D:\Program Files\7-Zip\7z.exe" a $(TargetDir)Release.zip $(TargetDir) -xr!*config \ No newline at end of file diff --git a/ProxySU/TrojanResultClientInfoWindow.xaml b/ProxySU/TrojanResultClientInfoWindow.xaml index eb1fe82..ec3867c 100644 --- a/ProxySU/TrojanResultClientInfoWindow.xaml +++ b/ProxySU/TrojanResultClientInfoWindow.xaml @@ -42,7 +42,20 @@ - + + + + + + + + + + + + + + diff --git a/ProxySU/TrojanResultClientInfoWindow.xaml.cs b/ProxySU/TrojanResultClientInfoWindow.xaml.cs index 3d7fb7d..67f991b 100644 --- a/ProxySU/TrojanResultClientInfoWindow.xaml.cs +++ b/ProxySU/TrojanResultClientInfoWindow.xaml.cs @@ -54,15 +54,16 @@ namespace ProxySU num++; } CheckDir(@"trojan_config\" + saveFileFolder); + string trojanUrl = $"trojan://{TextBoxTrojanServerPassword.Text}@{TextBoxTrojanServerHost.Text}:{TextBoxTrojanServerPort.Text}#{TextBoxTrojanServerHost.Text}"; //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); + //string trojanUrl = "trojan://" + ToBase64Encode(v2rayNjsonObject.ToString()); + TextBoxTrojanUrl.Text = trojanUrl; + using (StreamWriter sw = new StreamWriter($"trojan_config\\{saveFileFolder}\\url.txt")) + { + sw.WriteLine(trojanUrl); - //} - //CreateQRCode(vmessUrl); + } + CreateQRCode(trojanUrl); //移动Trojan官方程序配置文件到相应目录 if (File.Exists(@"trojan_config\config.json")) @@ -78,46 +79,38 @@ namespace ProxySU 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("-----------------------------------------\n"); + sw.WriteLine("QR.bmp"); + sw.WriteLine("此文件为Trojan-QT5 (windows)、Shadowrocket(ios)扫码导入节点"); + sw.WriteLine("Trojan-QT5 (windows)下载网址:https://github.com/TheWanderingCoel/Trojan-Qt5/releases"); + sw.WriteLine("Shadowrocket(ios)下载,需要使用国外区的AppleID。请自行谷歌方法。"); - //sw.WriteLine("-----------------------------------------"); - //sw.WriteLine("url.txt"); - //sw.WriteLine("此文件为v2rayN、v2rayNG(Android)、Shadowrocket(ios)复制粘贴导入节点的vmess网址"); - //sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("-----------------------------------------\n"); + sw.WriteLine("url.txt"); + sw.WriteLine("此文件为Trojan-QT5 (windows)、Shadowrocket(ios)复制粘贴导入节点的网址"); + 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; - } + //private string ToBase64Encode(string text) + //{ + // if (String.IsNullOrEmpty(text)) + // { + // return text; + // } + + // byte[] textBytes = Encoding.UTF8.GetBytes(text); + // return Convert.ToBase64String(textBytes); + //} - byte[] textBytes = Encoding.UTF8.GetBytes(text); - return Convert.ToBase64String(textBytes); - } //生成QRcoder图片 private void CreateQRCode(string varBase64) { @@ -128,10 +121,10 @@ namespace ProxySU 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; + ImageTrojanShareQRurl.Source = imgsource; //DeleteObject(myImagePtr); qrCodeImage.Save($"trojan_config\\{saveFileFolder}\\QR.bmp"); - //ImageShareQRcode.Source = @"config\v2rayN.bmp"; + } //判断目录是否存在,不存在则创建 private static bool CheckDir(string folder) diff --git a/ProxySU/bin/Release/ProxySU.exe b/ProxySU/bin/Release/ProxySU.exe index 23952f7..e5543e1 100644 Binary files a/ProxySU/bin/Release/ProxySU.exe and b/ProxySU/bin/Release/ProxySU.exe differ diff --git a/ProxySU/bin/Release/Release.zip b/ProxySU/bin/Release/Release.zip index 169ab9d..e5ec49f 100644 Binary files a/ProxySU/bin/Release/Release.zip and b/ProxySU/bin/Release/Release.zip differ diff --git a/ProxySU/bin/Release/TemplateConfg/WebSocketTLSWeb_server_config.caddyfile b/ProxySU/bin/Release/TemplateConfg/WebSocketTLSWeb_server_config.caddyfile index 9ba684f..fbb8bc6 100644 --- a/ProxySU/bin/Release/TemplateConfg/WebSocketTLSWeb_server_config.caddyfile +++ b/ProxySU/bin/Release/TemplateConfg/WebSocketTLSWeb_server_config.caddyfile @@ -1,6 +1,6 @@ ##domain## { - log stdout - errors stderr + log stdout + errors stderr root /var/www tls off ##sites## diff --git a/ProxySU/bin/Release/TemplateConfg/trojan_caddy_config.caddyfile b/ProxySU/bin/Release/TemplateConfg/trojan_caddy_config.caddyfile new file mode 100644 index 0000000..a477583 --- /dev/null +++ b/ProxySU/bin/Release/TemplateConfg/trojan_caddy_config.caddyfile @@ -0,0 +1,7 @@ +##domain## { + log stdout + errors stderr + root /var/www + tls off + ##sites## +} \ No newline at end of file diff --git a/ProxySU/bin/Release/TemplateConfg/trojan_client_config.json b/ProxySU/bin/Release/TemplateConfg/trojan_client_config.json new file mode 100644 index 0000000..6d98767 --- /dev/null +++ b/ProxySU/bin/Release/TemplateConfg/trojan_client_config.json @@ -0,0 +1,31 @@ +{ + "run_type": "client", + "local_addr": "127.0.0.1", + "local_port": 1080, + "remote_addr": null, + "remote_port": 443, + "password": [ + "" + ], + "log_level": 1, + "ssl": { + "verify": true, + "verify_hostname": true, + "cert": "", + "cipher": "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:RSA-AES128-GCM-SHA256:RSA-AES256-GCM-SHA384:RSA-AES128-SHA:RSA-AES256-SHA:RSA-3DES-EDE-SHA", + "sni": "", + "alpn": [ + "h2", + "http/1.1" + ], + "reuse_session": true, + "session_ticket": false, + "curves": "" + }, + "tcp": { + "no_delay": true, + "keep_alive": true, + "fast_open": false, + "fast_open_qlen": 20 + } +} diff --git a/ProxySU/bin/Release/TemplateConfg/trojan_nginx_config.nginx b/ProxySU/bin/Release/TemplateConfg/trojan_nginx_config.nginx new file mode 100644 index 0000000..f594ced --- /dev/null +++ b/ProxySU/bin/Release/TemplateConfg/trojan_nginx_config.nginx @@ -0,0 +1,11 @@ +server { + listen 80; + listen [::]:80; + server_name ##domain##; + root /var/www/html; + index index.html index.htm; + location / { + proxy_pass ##sites##; + try_files $uri $uri/ =404; + } +} diff --git a/ProxySU/bin/Release/TemplateConfg/trojan_server_config.json b/ProxySU/bin/Release/TemplateConfg/trojan_server_config.json new file mode 100644 index 0000000..fa0735c --- /dev/null +++ b/ProxySU/bin/Release/TemplateConfg/trojan_server_config.json @@ -0,0 +1,42 @@ +{ + "run_type": "server", + "local_addr": "0.0.0.0", + "local_port": 443, + "remote_addr": "127.0.0.1", + "remote_port": 80, + "password": [ + "" + ], + "log_level": 1, + "ssl": { + "cert": "/usr/local/etc/trojan/trojan_ssl.crt", + "key": "/usr/local/etc/trojan/trojan_ssl.key", + "key_password": "", + "cipher": "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256", + "prefer_server_cipher": true, + "alpn": [ + "http/1.1" + ], + "reuse_session": true, + "session_ticket": false, + "session_timeout": 600, + "plain_http_response": "", + "curves": "", + "dhparam": "" + }, + "tcp": { + "prefer_ipv4": false, + "no_delay": true, + "keep_alive": true, + "fast_open": false, + "fast_open_qlen": 20 + }, + "mysql": { + "enabled": false, + "server_addr": "127.0.0.1", + "server_port": 3306, + "database": "trojan", + "username": "trojan", + "password": "" + } +}