diff --git a/ProxySuper.Core/Models/Projects/NaiveProxySettings.cs b/ProxySuper.Core/Models/Projects/NaiveProxySettings.cs index 55d2f27..72927e1 100644 --- a/ProxySuper.Core/Models/Projects/NaiveProxySettings.cs +++ b/ProxySuper.Core/Models/Projects/NaiveProxySettings.cs @@ -8,12 +8,21 @@ namespace ProxySuper.Core.Models.Projects { public class NaiveProxySettings : IProjectSettings { + public NaiveProxySettings() + { + Port = 443; + } + + public List FreePorts => new List(); + + public ProjectType Type { get; set; } = ProjectType.NaiveProxy; + public int Port { get; set; } public string Domain { get; set; } - public List FreePorts => throw new NotImplementedException(); + public string UserName { get; set; } - public ProjectType Type { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public string Password { get; set; } } } diff --git a/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs b/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs index 0c3b993..cf84518 100644 --- a/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs +++ b/ProxySuper.Core/Models/Projects/TrojanGoSettings.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using ProxySuper.Core.Services; using System; using System.Collections.Generic; using System.Linq; @@ -12,6 +13,7 @@ namespace ProxySuper.Core.Models.Projects public TrojanGoSettings() { Port = 443; + WebSocketPath = "/ws"; } public List FreePorts @@ -52,7 +54,7 @@ namespace ProxySuper.Core.Models.Projects { get { - return !string.IsNullOrEmpty(WebSocketPath) && !string.IsNullOrEmpty(WebSocketDomain); + return !string.IsNullOrEmpty(WebSocketPath); } } @@ -61,9 +63,5 @@ namespace ProxySuper.Core.Models.Projects /// public string WebSocketPath { get; set; } - /// - /// websocket域名 - /// - public string WebSocketDomain { get; set; } } } diff --git a/ProxySuper.Core/ProxySuper.Core.csproj b/ProxySuper.Core/ProxySuper.Core.csproj index fcc87b8..ffee9a3 100644 --- a/ProxySuper.Core/ProxySuper.Core.csproj +++ b/ProxySuper.Core/ProxySuper.Core.csproj @@ -83,6 +83,7 @@ + diff --git a/ProxySuper.Core/Services/NaiveProxyProject.cs b/ProxySuper.Core/Services/NaiveProxyProject.cs new file mode 100644 index 0000000..4d49668 --- /dev/null +++ b/ProxySuper.Core/Services/NaiveProxyProject.cs @@ -0,0 +1,102 @@ +using ProxySuper.Core.Models.Projects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace ProxySuper.Core.Services +{ + public class NaiveProxyProject : ProjectBase + { + public override void Install() + { + try + { + EnsureRootAuth(); + + if (FileExists("/usr/local/bin/trojan-go")) + { + var btnResult = MessageBox.Show("已经安装Trojan-Go,是否需要重装?", "提示", MessageBoxButton.YesNo); + if (btnResult == MessageBoxResult.No) + { + MessageBox.Show("安装终止", "提示"); + return; + } + } + + WriteOutput("检测安装系统环境..."); + EnsureSystemEnv(); + WriteOutput("检测安装系统环境完成"); + + WriteOutput("配置服务器端口..."); + ConfigurePort(); + WriteOutput("端口配置完成"); + + WriteOutput("安装必要的系统工具..."); + ConfigureSoftware(); + WriteOutput("系统工具安装完成"); + + WriteOutput("检测IP6..."); + ConfigureIPv6(); + WriteOutput("检测IP6完成"); + + WriteOutput("配置防火墙..."); + ConfigureFirewall(); + WriteOutput("防火墙配置完成"); + + WriteOutput("同步系统和本地时间..."); + SyncTimeDiff(); + WriteOutput("时间同步完成"); + + WriteOutput("检测域名是否绑定本机IP..."); + ValidateDomain(); + WriteOutput("域名检测完成"); + + WriteOutput("安装Trojan-Go..."); + // InstallTrojanGo(); + WriteOutput("Trojan-Go安装完成"); + + WriteOutput("安装Caddy..."); + InstallCaddy(); + // UploadCaddyFile(); + WriteOutput("Caddy安装完成"); + + WriteOutput("启动BBR"); + EnableBBR(); + + RunCmd("systemctl restart trojan-go"); + WriteOutput("************"); + WriteOutput("安装完成,尽情享用吧......"); + WriteOutput("************"); + } + catch (Exception ex) + { + var errorLog = "安装终止," + ex.Message; + WriteOutput(errorLog); + MessageBox.Show(errorLog); + } + } + + private void InstallNaiveProxy() + { + WriteOutput("安装 NaiveProxy"); + RunCmd(@"curl https://raw.githubusercontent.com/proxysu/shellscript/master/Caddy-Naive/caddy-naive-install.sh yes | bash"); + var success = FileExists("/usr/local/bin/trojan-go"); + if (success == false) + { + throw new Exception("trojan-go 安装失败,请联系开发者!"); + } + + RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"systemctl daemon-reload"); + + RunCmd("systemctl enable trojan-go"); + RunCmd("systemctl start trojan-go"); + WriteOutput("NaiveProxy 安装完成"); + } + } +} diff --git a/ProxySuper.Core/Services/ShareLink.cs b/ProxySuper.Core/Services/ShareLink.cs index 78d9419..ce72bf3 100644 --- a/ProxySuper.Core/Services/ShareLink.cs +++ b/ProxySuper.Core/Services/ShareLink.cs @@ -13,12 +13,20 @@ namespace ProxySuper.Core.Services { public static string BuildTrojanGo(TrojanGoSettings settings) { - throw new NotImplementedException(); StringBuilder strBuilder = new StringBuilder(); strBuilder.Append("trojan-go://"); - strBuilder.Append($"{settings.Password}@{settings.Domain}:{settings.Port}/?"); - strBuilder.Append($"sni={settings.Domain}&"); + strBuilder.Append($"{HttpUtility.UrlEncode(settings.Password)}@{settings.Domain}:{settings.Port}/?"); + strBuilder.Append($"sni={HttpUtility.UrlEncode(settings.Domain)}&"); + if (settings.EnableWebSocket) + { + strBuilder.Append($"type=ws&host={HttpUtility.UrlEncode(settings.Domain)}&path={HttpUtility.UrlEncode(settings.WebSocketPath)}&"); + } + else + { + strBuilder.Append("type=original&"); + } + strBuilder.Append($"#{HttpUtility.UrlEncode("trojan-go")}"); return strBuilder.ToString(); } diff --git a/ProxySuper.Core/Services/TrojanGoConfigBuilder.cs b/ProxySuper.Core/Services/TrojanGoConfigBuilder.cs index 0943d41..d9743c3 100644 --- a/ProxySuper.Core/Services/TrojanGoConfigBuilder.cs +++ b/ProxySuper.Core/Services/TrojanGoConfigBuilder.cs @@ -32,7 +32,7 @@ namespace ProxySuper.Core.Services { settings["websocket"]["enabled"] = true; settings["websocket"]["path"] = parameters.WebSocketPath; - settings["websocket"]["host"] = parameters.WebSocketDomain; + settings["websocket"]["host"] = parameters.Domain; } return JsonConvert.SerializeObject(settings, Formatting.Indented, new JsonSerializerSettings() diff --git a/ProxySuper.Core/Services/TrojanGoProject.cs b/ProxySuper.Core/Services/TrojanGoProject.cs index ec08408..7570d05 100644 --- a/ProxySuper.Core/Services/TrojanGoProject.cs +++ b/ProxySuper.Core/Services/TrojanGoProject.cs @@ -50,6 +50,7 @@ namespace ProxySuper.Core.Services { RunCmd("systemctl stop trojan-go"); RunCmd("systemctl stop caddy"); + base.UninstallCaddy(); RunCmd("rm -rf /usr/local/bin/trojan-go"); RunCmd("rm -rf /usr/local/etc/trojan-go"); @@ -110,12 +111,13 @@ namespace ProxySuper.Core.Services WriteOutput("安装Caddy..."); InstallCaddy(); + UploadCaddyFile(); WriteOutput("Caddy安装完成"); WriteOutput("启动BBR"); EnableBBR(); - UploadCaddyFile(); + RunCmd("systemctl restart trojan-go"); WriteOutput("************"); WriteOutput("安装完成,尽情享用吧......"); WriteOutput("************"); @@ -138,9 +140,9 @@ namespace ProxySuper.Core.Services throw new Exception("trojan-go 安装失败,请联系开发者!"); } - RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/xray.service"); - RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/xray.service"); - RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/xray.service"); + RunCmd($"sed -i 's/User=nobody/User=root/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"sed -i 's/CapabilityBoundingSet=/#CapabilityBoundingSet=/g' /etc/systemd/system/trojan-go.service"); + RunCmd($"sed -i 's/AmbientCapabilities=/#AmbientCapabilities=/g' /etc/systemd/system/trojan-go.service"); RunCmd($"systemctl daemon-reload"); RunCmd("systemctl enable trojan-go"); diff --git a/ProxySuper.Core/ViewModels/HomeViewModel.cs b/ProxySuper.Core/ViewModels/HomeViewModel.cs index 0f982c7..50c4f73 100644 --- a/ProxySuper.Core/ViewModels/HomeViewModel.cs +++ b/ProxySuper.Core/ViewModels/HomeViewModel.cs @@ -111,12 +111,16 @@ namespace ProxySuper.Core.ViewModels if (record.Type == ProjectType.Xray) { result = await _navigationService.Navigate(record); + if (result == null) return; + record.Host = result.Host; record.XraySettings = result.XraySettings; } if (record.Type == ProjectType.TrojanGo) { result = await _navigationService.Navigate(record); + if (result == null) return; + record.Host = result.Host; record.TrojanGoSettings = result.TrojanGoSettings; } diff --git a/ProxySuper.Core/ViewModels/TrojanGoConfigViewModel.cs b/ProxySuper.Core/ViewModels/TrojanGoConfigViewModel.cs index 0dbc970..63e4fca 100644 --- a/ProxySuper.Core/ViewModels/TrojanGoConfigViewModel.cs +++ b/ProxySuper.Core/ViewModels/TrojanGoConfigViewModel.cs @@ -1,5 +1,6 @@ using MvvmCross.ViewModels; using ProxySuper.Core.Models.Projects; +using ProxySuper.Core.Services; using System; using System.Collections.Generic; using System.Linq; @@ -17,6 +18,12 @@ namespace ProxySuper.Core.ViewModels Settings = parameter; } - + public string Link + { + get + { + return ShareLink.BuildTrojanGo(Settings); + } + } } } diff --git a/ProxySuper.WPF/Resources/Languages/en.xaml b/ProxySuper.WPF/Resources/Languages/en.xaml index 466d693..b433a4e 100644 --- a/ProxySuper.WPF/Resources/Languages/en.xaml +++ b/ProxySuper.WPF/Resources/Languages/en.xaml @@ -8,7 +8,8 @@ SaveAs Install Settings - + The following is a static web page connection provided by netizens, please check whether there is an index.html file by yourself + Add Host Actions diff --git a/ProxySuper.WPF/Resources/Languages/zh_cn.xaml b/ProxySuper.WPF/Resources/Languages/zh_cn.xaml index ec97a36..81b4201 100644 --- a/ProxySuper.WPF/Resources/Languages/zh_cn.xaml +++ b/ProxySuper.WPF/Resources/Languages/zh_cn.xaml @@ -8,6 +8,7 @@ 另存为 安装 配置 + 如下是网友提供的静态网页连接,请自行检查是否有index.html文件 添加主机 diff --git a/ProxySuper.WPF/Views/TrojanGoConfigView.xaml b/ProxySuper.WPF/Views/TrojanGoConfigView.xaml index ad3ef79..0592742 100644 --- a/ProxySuper.WPF/Views/TrojanGoConfigView.xaml +++ b/ProxySuper.WPF/Views/TrojanGoConfigView.xaml @@ -19,6 +19,8 @@ + +