diff --git a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs b/ProxySU_Core/Models/Developers/ConfigBuilder.cs similarity index 96% rename from ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs rename to ProxySU_Core/Models/Developers/ConfigBuilder.cs index 5748161..c7e8723 100644 --- a/ProxySU_Core/ViewModels/Developers/ConfigBuilder.cs +++ b/ProxySU_Core/Models/Developers/ConfigBuilder.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Text; -namespace ProxySU_Core.ViewModels.Developers +namespace ProxySU_Core.Models.Developers { public class ConfigBuilder { @@ -96,16 +96,10 @@ namespace ProxySU_Core.ViewModels.Developers xver = 1, })); xrayConfig.inbounds.Add(baseBound); - - if (parameters.Types.Contains(XrayType.VLESS_TCP_XTLS)) - { - baseBound.settings.clients[0].id = parameters.UUID; - } + baseBound.settings.clients[0].id = parameters.UUID; if (parameters.Types.Contains(XrayType.VLESS_WS_TLS)) { - baseBound.settings.clients[0].id = parameters.UUID; - var wsInbound = LoadJsonObj(Path.Combine(ServerInboundsDir, "VLESS_WS_TLS.json")); wsInbound.port = VLESS_WS_Port; wsInbound.settings.clients[0].id = parameters.UUID; diff --git a/ProxySU_Core/ViewModels/Developers/IParameters.cs b/ProxySU_Core/Models/Developers/IParameters.cs similarity index 80% rename from ProxySU_Core/ViewModels/Developers/IParameters.cs rename to ProxySU_Core/Models/Developers/IParameters.cs index c54bcbf..11554c0 100644 --- a/ProxySU_Core/ViewModels/Developers/IParameters.cs +++ b/ProxySU_Core/Models/Developers/IParameters.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace ProxySU_Core.ViewModels.Developers +namespace ProxySU_Core.Models.Developers { public interface IParameters { diff --git a/ProxySU_Core/ViewModels/Developers/Project.cs b/ProxySU_Core/Models/Developers/Project.cs similarity index 99% rename from ProxySU_Core/ViewModels/Developers/Project.cs rename to ProxySU_Core/Models/Developers/Project.cs index 61aba94..c0bc53a 100644 --- a/ProxySU_Core/ViewModels/Developers/Project.cs +++ b/ProxySU_Core/Models/Developers/Project.cs @@ -1,4 +1,5 @@ using ProxySU_Core.Tools; +using ProxySU_Core.ViewModels; using Renci.SshNet; using System; using System.Collections.Generic; @@ -9,7 +10,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; -namespace ProxySU_Core.ViewModels.Developers +namespace ProxySU_Core.Models.Developers { public enum CmdType { diff --git a/ProxySU_Core/ViewModels/Developers/XrayProject.cs b/ProxySU_Core/Models/Developers/XrayProject.cs similarity index 99% rename from ProxySU_Core/ViewModels/Developers/XrayProject.cs rename to ProxySU_Core/Models/Developers/XrayProject.cs index 1d028e1..4c65360 100644 --- a/ProxySU_Core/ViewModels/Developers/XrayProject.cs +++ b/ProxySU_Core/Models/Developers/XrayProject.cs @@ -8,7 +8,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using ProxySU_Core.Models; -namespace ProxySU_Core.ViewModels.Developers +namespace ProxySU_Core.Models.Developers { public class XrayProject : Project { diff --git a/ProxySU_Core/Models/ShareLink.cs b/ProxySU_Core/Models/ShareLink.cs new file mode 100644 index 0000000..dec2823 --- /dev/null +++ b/ProxySU_Core/Models/ShareLink.cs @@ -0,0 +1,170 @@ +using Newtonsoft.Json; +using ProxySU_Core.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web; + +namespace ProxySU_Core.Models +{ + public class ShareLink + { + public static string Build(XrayType xrayType, XraySettings settings) + { + switch (xrayType) + { + case XrayType.VLESS_TCP_TLS: + case XrayType.VLESS_TCP_XTLS: + case XrayType.VLESS_WS_TLS: + case XrayType.Trojan_TCP_TLS: + return BuildVlessShareLink(xrayType, settings); + case XrayType.VMESS_TCP_TLS: + case XrayType.VMESS_WS_TLS: + return BuildVmessShareLink(xrayType, settings); + default: + return string.Empty; + } + } + + + private static string BuildVmessShareLink(XrayType xrayType, XraySettings settings) + { + var vmess = new Vmess + { + v = "2", + add = settings.Domain, + port = settings.Port.ToString(), + id = settings.UUID, + aid = "0", + net = "", + type = "none", + host = settings.Domain, + path = "", + tls = "tls", + ps = "", + }; + + + switch (xrayType) + { + case XrayType.VMESS_TCP_TLS: + vmess.ps = "vmess-tcp-tls"; + vmess.net = "tcp"; + vmess.type = "http"; + vmess.path = settings.VMESS_TCP_Path; + break; + case XrayType.VMESS_WS_TLS: + vmess.ps = "vmess-ws-tls"; + vmess.net = "ws"; + vmess.type = "none"; + vmess.path = settings.VMESS_WS_Path; + break; + default: + return string.Empty; + } + + var base64Url = Base64.Encode(JsonConvert.SerializeObject(vmess)); + return $"vmess://" + base64Url; + } + + private static string BuildVlessShareLink(XrayType xrayType, XraySettings settings) + { + var _protocol = string.Empty; + var _uuid = settings.UUID; + var _domain = settings.Domain; + var _port = settings.Port; + var _type = string.Empty; + var _encryption = string.Empty; + var _security = "tls"; + var _path = "/"; + var _host = settings.Domain; + var _descriptiveText = string.Empty; + + switch (xrayType) + { + case XrayType.VLESS_TCP_TLS: + _protocol = "vless"; + _type = "tcp"; + _path = settings.VLESS_TCP_Path; + _encryption = "none"; + _descriptiveText = "vless-tcp-tls"; + break; + case XrayType.VLESS_TCP_XTLS: + _protocol = "vless"; + _type = "tcp"; + _security = "xtls"; + _encryption = "none"; + _descriptiveText = "vless-tcp-xtls"; + break; + case XrayType.VLESS_WS_TLS: + _protocol = "vless"; + _type = "ws"; + _path = settings.VLESS_WS_Path; + _encryption = "none"; + _descriptiveText = "vless-ws-tls"; + break; + case XrayType.VMESS_TCP_TLS: + _protocol = "vmess"; + _type = "tcp"; + _path = settings.VMESS_TCP_Path; + _encryption = "auto"; + _descriptiveText = "vmess-tcp-tls"; + break; + case XrayType.VMESS_WS_TLS: + _protocol = "vmess"; + _type = "ws"; + _path = settings.VMESS_WS_Path; + _encryption = "auto"; + _descriptiveText = "vmess-ws-tls"; + break; + case XrayType.Trojan_TCP_TLS: + _protocol = "trojan"; + _descriptiveText = "trojan-tcp"; + break; + default: + throw new Exception("暂未实现的协议"); + } + + + string parametersURL = string.Empty; + if (xrayType != XrayType.Trojan_TCP_TLS) + { + // 4.3 传输层相关段 + parametersURL = $"?type={_type}&encryption={_encryption}&security={_security}&host={_host}&path={HttpUtility.UrlEncode(_path)}"; + + + // if mKCP + // if QUIC + + // 4.4 TLS 相关段 + if (xrayType == XrayType.VLESS_TCP_XTLS) + { + parametersURL += "&flow=xtls-rprx-direct"; + } + } + + + return $"{_protocol}://{HttpUtility.UrlEncode(_uuid)}@{_domain}:{_port}{parametersURL}#{HttpUtility.UrlEncode(_descriptiveText)}"; + } + + } + + + + class Vmess + { + public string v { get; set; } + public string ps { get; set; } + public string add { get; set; } + public string port { get; set; } + public string id { get; set; } + public string aid { get; set; } + public string net { get; set; } + public string type { get; set; } + public string host { get; set; } + public string path { get; set; } + public string tls { get; set; } + } +} diff --git a/ProxySU_Core/Models/XraySettings.cs b/ProxySU_Core/Models/XraySettings.cs index 2b1206f..36b914f 100644 --- a/ProxySU_Core/Models/XraySettings.cs +++ b/ProxySU_Core/Models/XraySettings.cs @@ -1,9 +1,12 @@ -using ProxySU_Core.ViewModels.Developers; +using Newtonsoft.Json; +using ProxySU_Core.Common; +using ProxySU_Core.Models.Developers; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Web; namespace ProxySU_Core.Models { @@ -15,7 +18,7 @@ namespace ProxySU_Core.Models var guid = Guid.NewGuid().ToString(); Port = 443; UUID = guid; - Types = new List { XrayType.VLESS_TCP_XTLS }; + Types = new List(); VLESS_WS_Path = "/vlessws"; VLESS_TCP_Path = "/vlesstcp"; VMESS_WS_Path = "/vmessws"; @@ -94,8 +97,10 @@ namespace ProxySU_Core.Models return string.Empty; } } + } + public enum XrayType { VLESS_TCP_TLS, diff --git a/ProxySU_Core/ProxySU_Core.csproj b/ProxySU_Core/ProxySU_Core.csproj index abc4170..c7f9b9e 100644 --- a/ProxySU_Core/ProxySU_Core.csproj +++ b/ProxySU_Core/ProxySU_Core.csproj @@ -120,15 +120,16 @@ + - - - - + + + + @@ -149,6 +150,9 @@ TerminalWindow.xaml + + TextBoxWindow.xaml + @@ -237,6 +241,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -294,6 +301,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + diff --git a/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_WS_TLS.json b/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_WS_TLS.json new file mode 100644 index 0000000..229a245 --- /dev/null +++ b/ProxySU_Core/Templates/xray/server/05_inbounds/Trojan_WS_TLS.json @@ -0,0 +1,28 @@ +{ + "port": 1320, + "listen": "127.0.0.1", + "protocol": "trojan", + "settings": { + "clients": [ + { + "password": "", + "level": 0, + "email": "love@example.com" + } + ], + "fallbacks": [ + { + "dest": 80 + } + ] + }, + + "streamSettings": { + "network": "ws", + "security": "none", + "wsSettings": { + "acceptProxyProtocol": true, + "path": "/trojanws" + } + } +} diff --git a/ProxySU_Core/ViewModels/HostViewModel.cs b/ProxySU_Core/ViewModels/HostViewModel.cs index 1d06af0..04ceb62 100644 --- a/ProxySU_Core/ViewModels/HostViewModel.cs +++ b/ProxySU_Core/ViewModels/HostViewModel.cs @@ -15,6 +15,7 @@ namespace ProxySU_Core.ViewModels private readonly ICommand _selectKeyCommand; + public HostViewModel(Host host) { _selectKeyCommand = new BaseCommand(obj => OpenFileDialog(obj)); diff --git a/ProxySU_Core/ViewModels/RecordViewModel.cs b/ProxySU_Core/ViewModels/RecordViewModel.cs index 70f0b81..e2270be 100644 --- a/ProxySU_Core/ViewModels/RecordViewModel.cs +++ b/ProxySU_Core/ViewModels/RecordViewModel.cs @@ -11,10 +11,22 @@ namespace ProxySU_Core.ViewModels public class RecordViewModel : BaseViewModel { public Record record; + private bool _isChecked; public RecordViewModel(Record record) { this.record = record; + this._isChecked = false; + } + + public bool IsChecked + { + get => _isChecked; + set + { + _isChecked = value; + Notify("IsChecked"); + } } public Host Host diff --git a/ProxySU_Core/ViewModels/XraySettingsViewModel.cs b/ProxySU_Core/ViewModels/XraySettingsViewModel.cs index 9f00785..54d1435 100644 --- a/ProxySU_Core/ViewModels/XraySettingsViewModel.cs +++ b/ProxySU_Core/ViewModels/XraySettingsViewModel.cs @@ -1,7 +1,6 @@ using Newtonsoft.Json; using ProxySU_Core.Common; using ProxySU_Core.Models; -using ProxySU_Core.ViewModels.Developers; using System; using System.Collections.Generic; using System.Linq; @@ -239,164 +238,29 @@ namespace ProxySU_Core.ViewModels public string VLESS_TCP_XTLS_ShareLink { - get => BuildVlessShareLink(XrayType.VLESS_TCP_XTLS); + get => ShareLink.Build(XrayType.VLESS_TCP_XTLS, settings); } public string VLESS_TCP_TLS_ShareLink { - get => BuildVlessShareLink(XrayType.VLESS_TCP_TLS); + get => ShareLink.Build(XrayType.VLESS_TCP_TLS, settings); } public string VLESS_WS_TLS_ShareLink { - get => BuildVlessShareLink(XrayType.VLESS_WS_TLS); + get => ShareLink.Build(XrayType.VLESS_WS_TLS, settings); } public string VMESS_TCP_TLS_ShareLink { - get => BuildVmessShareLink(XrayType.VMESS_TCP_TLS); + get => ShareLink.Build(XrayType.VMESS_TCP_TLS, settings); } public string VMESS_WS_TLS_ShareLink { - get => BuildVmessShareLink(XrayType.VMESS_WS_TLS); + get => ShareLink.Build(XrayType.VMESS_WS_TLS, settings); } public string Trojan_TCP_TLS_ShareLink { - get => BuildVlessShareLink(XrayType.Trojan_TCP_TLS); + get => ShareLink.Build(XrayType.Trojan_TCP_TLS, settings); } - public string BuildVmessShareLink(XrayType xrayType) - { - var vmess = new Vmess - { - v = "2", - add = settings.Domain, - port = settings.Port.ToString(), - id = settings.UUID, - aid = "0", - net = "", - type = "none", - host = settings.Domain, - path = "", - tls = "tls", - ps = "", - }; - - - switch (xrayType) - { - case XrayType.VMESS_TCP_TLS: - vmess.ps = "vmess-tcp-tls"; - vmess.net = "tcp"; - vmess.type = "http"; - vmess.path = VMESS_TCP_Path; - break; - case XrayType.VMESS_WS_TLS: - vmess.ps = "vmess-ws-tls"; - vmess.net = "ws"; - vmess.type = "none"; - vmess.path = VMESS_WS_Path; - break; - default: - return string.Empty; - } - - var base64Url = Base64.Encode(JsonConvert.SerializeObject(vmess)); - return $"vmess://" + base64Url; - } - - public string BuildVlessShareLink(XrayType xrayType) - { - var _protocol = string.Empty; - var _uuid = settings.UUID; - var _domain = settings.Domain; - var _port = settings.Port; - var _type = string.Empty; - var _encryption = string.Empty; - var _security = "tls"; - var _path = "/"; - var _host = settings.Domain; - var _descriptiveText = string.Empty; - - switch (xrayType) - { - case XrayType.VLESS_TCP_TLS: - _protocol = "vless"; - _type = "tcp"; - _path = VLESS_TCP_Path; - _encryption = "none"; - _descriptiveText = "vless-tcp-tls"; - break; - case XrayType.VLESS_TCP_XTLS: - _protocol = "vless"; - _type = "tcp"; - _security = "xtls"; - _encryption = "none"; - _descriptiveText = "vless-tcp-xtls"; - break; - case XrayType.VLESS_WS_TLS: - _protocol = "vless"; - _type = "ws"; - _path = VLESS_WS_Path; - _encryption = "none"; - _descriptiveText = "vless-ws-tls"; - break; - case XrayType.VMESS_TCP_TLS: - _protocol = "vmess"; - _type = "tcp"; - _path = VMESS_TCP_Path; - _encryption = "auto"; - _descriptiveText = "vmess-tcp-tls"; - break; - case XrayType.VMESS_WS_TLS: - _protocol = "vmess"; - _type = "ws"; - _path = VMESS_WS_Path; - _encryption = "auto"; - _descriptiveText = "vmess-ws-tls"; - break; - case XrayType.Trojan_TCP_TLS: - _protocol = "trojan"; - _descriptiveText = "trojan-tcp"; - break; - default: - throw new Exception("暂未实现的协议"); - } - - - string parametersURL = string.Empty; - if (xrayType != XrayType.Trojan_TCP_TLS) - { - // 4.3 传输层相关段 - parametersURL = $"?type={_type}&encryption={_encryption}&security={_security}&host={_host}&path={HttpUtility.UrlEncode(_path)}"; - - - // if mKCP - // if QUIC - - // 4.4 TLS 相关段 - if (xrayType == XrayType.VLESS_TCP_XTLS) - { - parametersURL += "&flow=xtls-rprx-direct"; - } - } - - - return $"{_protocol}://{HttpUtility.UrlEncode(_uuid)}@{_domain}:{_port}{parametersURL}#{HttpUtility.UrlEncode(_descriptiveText)}"; - } - - } - public class Vmess - { - public string v { get; set; } - public string ps { get; set; } - public string add { get; set; } - public string port { get; set; } - public string id { get; set; } - public string aid { get; set; } - public string net { get; set; } - public string type { get; set; } - public string host { get; set; } - public string path { get; set; } - public string tls { get; set; } - } } diff --git a/ProxySU_Core/Views/MainWindow.xaml b/ProxySU_Core/Views/MainWindow.xaml index 9fe598d..2649b91 100644 --- a/ProxySU_Core/Views/MainWindow.xaml +++ b/ProxySU_Core/Views/MainWindow.xaml @@ -54,9 +54,21 @@