diff --git a/v2rayN/ServiceLib.Tests/Fmt/WireguardFmtTests.cs b/v2rayN/ServiceLib.Tests/Fmt/WireguardFmtTests.cs new file mode 100644 index 00000000..717fa1bc --- /dev/null +++ b/v2rayN/ServiceLib.Tests/Fmt/WireguardFmtTests.cs @@ -0,0 +1,47 @@ +using AwesomeAssertions; +using ServiceLib.Handler.Fmt; +using Xunit; + +namespace ServiceLib.Tests.Fmt; + +public class WireguardFmtTests +{ + [Fact] + public void ResolveConfig_ShouldParsePeersAndIgnoreInlineComments() + { + const string config = + """ + [Interface] + PrivateKey = interface-private-key + Address = 10.0.0.2/32, fd00::2/128 ; inline comment + MTU = 1420 + + [Peer] + PublicKey = peer-public-key + PresharedKey = peer-preshared-key + Reserved = 1, 2, 3 # inline comment + Endpoint = [2001:db8::1]:51820 # inline comment + + [Peer] + PublicKey = peer-public-key-2 + Endpoint = example.com:12345 + """; + + var resolved = WireguardFmt.ResolveConfig(config); + + resolved.Should().NotBeNull(); + resolved.Should().HaveCount(2); + + var first = resolved![0]; + first.Address.Should().Be("2001:db8::1"); + first.Port.Should().Be(51820); + first.Password.Should().Be("interface-private-key"); + first.GetProtocolExtra().WgReserved.Should().Be("1, 2, 3"); + first.GetProtocolExtra().WgInterfaceAddress.Should().Be("10.0.0.2/32, fd00::2/128"); + first.GetProtocolExtra().WgMtu.Should().Be(1420); + + var second = resolved[1]; + second.Address.Should().Be("example.com"); + second.Port.Should().Be(12345); + } +} diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 6fa8e65b..c4c7b8e9 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -790,12 +790,30 @@ public static class ConfigHandler profileItem.Address = profileItem.Address.TrimEx(); profileItem.Password = profileItem.Password.TrimEx(); + var wgReserved = profileItem.GetProtocolExtra().WgReserved?.TrimEx(); + if (!wgReserved.IsNullOrEmpty() + && !wgReserved.Contains(',')) + { + // Base64 format, convert to standard format + try + { + var bytes = Convert.FromBase64String(wgReserved); + var reserved = new byte[3]; + Array.Copy(bytes, reserved, Math.Min(bytes.Length, 3)); + + wgReserved = string.Join(", ", reserved); + } + catch + { + // If conversion fails, keep the original value + } + } profileItem.SetProtocolExtra(profileItem.GetProtocolExtra() with { WgPublicKey = profileItem.GetProtocolExtra().WgPublicKey?.TrimEx(), WgPresharedKey = profileItem.GetProtocolExtra().WgPresharedKey?.TrimEx(), WgInterfaceAddress = profileItem.GetProtocolExtra().WgInterfaceAddress?.TrimEx(), - WgReserved = profileItem.GetProtocolExtra().WgReserved?.TrimEx(), + WgReserved = wgReserved, WgMtu = profileItem.GetProtocolExtra().WgMtu is null or <= 0 ? Global.TunMtus.First() : profileItem.GetProtocolExtra().WgMtu, }); @@ -1639,30 +1657,18 @@ public static class ConfigHandler ProfileItem? profileItem = null; //Is sing-box configuration - if (profileItem is null) - { - profileItem = SingboxFmt.ResolveFull(strData, subRemarks); - } + profileItem ??= SingboxFmt.ResolveFull(strData, subRemarks); //Is v2ray configuration - if (profileItem is null) - { - profileItem = V2rayFmt.ResolveFull(strData, subRemarks); - } + profileItem ??= V2rayFmt.ResolveFull(strData, subRemarks); //Is Html Page if (profileItem is null && HtmlPageFmt.IsHtmlPage(strData)) { return -1; } //Is Clash configuration - if (profileItem is null) - { - profileItem = ClashFmt.ResolveFull(strData, subRemarks); - } + profileItem ??= ClashFmt.ResolveFull(strData, subRemarks); //Is hysteria configuration - if (profileItem is null) - { - profileItem = Hysteria2Fmt.ResolveFull2(strData, subRemarks); - } + profileItem ??= Hysteria2Fmt.ResolveFull2(strData, subRemarks); if (profileItem is null || profileItem.Address.IsNullOrEmpty()) { return -1; @@ -1727,6 +1733,40 @@ public static class ConfigHandler return -1; } + private static async Task AddBatchServers4Wireguard(Config config, string strData, string subid, bool isSub) + { + if (strData.IsNullOrEmpty()) + { + return -1; + } + if (!(strData.Contains("[Interface]", StringComparison.OrdinalIgnoreCase) + && strData.Contains("[Peer]", StringComparison.OrdinalIgnoreCase))) + { + return -1; + } + if (isSub && subid.IsNotEmpty()) + { + await RemoveServersViaSubid(config, subid, isSub); + } + var lstServer = WireguardFmt.ResolveConfig(strData); + if (lstServer?.Count > 0) + { + var counter = 0; + foreach (var item in lstServer) + { + item.Subid = subid; + item.IsSub = isSub; + if (await AddWireguardServer(config, item) == 0) + { + counter++; + } + } + await SaveConfig(config); + return counter; + } + return -1; + } + /// /// Main entry point for adding batch servers from various formats /// Tries different parsing methods to import as many servers as possible @@ -1769,6 +1809,12 @@ public static class ConfigHandler counter = await AddBatchServers4SsSIP008(config, strData, subid, isSub); } + //maybe wireguard config + if (counter < 1) + { + counter = await AddBatchServers4Wireguard(config, strData, subid, isSub); + } + //maybe other sub if (counter < 1) { diff --git a/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs index 73cb6a85..b0de1068 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/WireguardFmt.cs @@ -27,9 +27,10 @@ public class WireguardFmt : BaseFmt item.SetProtocolExtra(item.GetProtocolExtra() with { WgPublicKey = GetQueryDecoded(query, "publickey"), + WgPresharedKey = GetQueryDecoded(query, "presharedkey"), WgReserved = GetQueryDecoded(query, "reserved"), WgInterfaceAddress = GetQueryDecoded(query, "address"), - WgMtu = int.TryParse(GetQueryDecoded(query, "mtu"), out var mtuVal) ? mtuVal : 1280, + WgMtu = int.TryParse(GetQueryDecoded(query, "mtu"), out var mtuVal) ? mtuVal : null, }); return item; @@ -48,20 +49,183 @@ public class WireguardFmt : BaseFmt remark = "#" + Utils.UrlEncode(item.Remarks); } + var protoExtra = item.GetProtocolExtra(); var dicQuery = new Dictionary(); - if (!item.GetProtocolExtra().WgPublicKey.IsNullOrEmpty()) + if (!protoExtra.WgPublicKey.IsNullOrEmpty()) { - dicQuery.Add("publickey", Utils.UrlEncode(item.GetProtocolExtra().WgPublicKey)); + dicQuery.Add("publickey", Utils.UrlEncode(protoExtra.WgPublicKey)); } - if (!item.GetProtocolExtra().WgReserved.IsNullOrEmpty()) + if (!protoExtra.WgPresharedKey.IsNullOrEmpty()) { - dicQuery.Add("reserved", Utils.UrlEncode(item.GetProtocolExtra().WgReserved)); + dicQuery.Add("presharedkey", Utils.UrlEncode(protoExtra.WgPresharedKey)); } - if (!item.GetProtocolExtra().WgInterfaceAddress.IsNullOrEmpty()) + if (!protoExtra.WgReserved.IsNullOrEmpty()) { - dicQuery.Add("address", Utils.UrlEncode(item.GetProtocolExtra().WgInterfaceAddress)); + dicQuery.Add("reserved", Utils.UrlEncode(protoExtra.WgReserved)); + } + if (!protoExtra.WgInterfaceAddress.IsNullOrEmpty()) + { + dicQuery.Add("address", Utils.UrlEncode(protoExtra.WgInterfaceAddress)); + } + if (protoExtra.WgMtu > 0) + { + dicQuery.Add("mtu", protoExtra.WgMtu.ToString()); } - dicQuery.Add("mtu", Utils.UrlEncode(item.GetProtocolExtra().WgMtu > 0 ? item.GetProtocolExtra().WgMtu.ToString() : "1280")); return ToUri(EConfigType.WireGuard, item.Address, item.Port, item.Password, dicQuery, remark); } + + public static List? ResolveConfig(string strData) + { + var interfaceDic = new Dictionary(StringComparer.OrdinalIgnoreCase); + var peerDicList = new List>(); + var currentDicRef = interfaceDic; + using (var reader = new StringReader(strData)) + { + while (reader.ReadLine() is { } line) + { + if (line.IsNullOrEmpty()) + { + continue; + } + + var trimmedLine = line.Trim(); + + if (trimmedLine.Equals("[Interface]", StringComparison.OrdinalIgnoreCase)) + { + currentDicRef = interfaceDic; + continue; + } + if (trimmedLine.Equals("[Peer]", StringComparison.OrdinalIgnoreCase)) + { + var peerDic = new Dictionary(StringComparer.OrdinalIgnoreCase); + peerDicList.Add(peerDic); + currentDicRef = peerDic; + continue; + } + + if (trimmedLine.StartsWith('[') || trimmedLine.StartsWith('#') || trimmedLine.StartsWith(';')) + { + continue; + } + + var idx = line.IndexOf('='); + if (idx <= 0) + { + continue; + } + + var key = line[..idx].Trim(); + var value = line[(idx + 1)..].Trim(); + var commentPos = value.IndexOfAny(['#', ';']); + if (commentPos >= 0) + { + value = value[..commentPos].TrimEnd(); + } + + currentDicRef[key] = value; + } + } + + if (!interfaceDic.TryGetValue("PrivateKey", out var privateKey) || privateKey.IsNullOrEmpty()) + { + return null; + } + + var wgMtu = interfaceDic.TryGetValue("MTU", out var mtuStr) && int.TryParse(mtuStr, out var mtuVal) ? mtuVal : 0; + var wgInterfaceAddress = interfaceDic.TryGetValue("Address", out var interfaceAddress) ? interfaceAddress : string.Empty; + + var index = 0; + var resultList = new List(); + + foreach (var peerDic in peerDicList) + { + if (!peerDic.TryGetValue("Endpoint", out var endpoint) || endpoint.IsNullOrEmpty()) + { + continue; + } + + if (!TryParseEndpoint(endpoint, out var peerAddress, out var peerPort)) + { + continue; + } + + var protoExtra = new ProtocolExtraItem + { + WgPublicKey = (peerDic.TryGetValue("PublicKey", out var publicKey) ? publicKey : string.Empty).NullIfEmpty(), + WgPresharedKey = (peerDic.TryGetValue("PresharedKey", out var presharedKey) ? presharedKey : string.Empty).NullIfEmpty(), + WgInterfaceAddress = wgInterfaceAddress, + WgReserved = (peerDic.TryGetValue("Reserved", out var reserved) ? reserved : string.Empty).NullIfEmpty(), + WgMtu = wgMtu > 0 ? wgMtu : null, + }; + + var item = new ProfileItem + { + Remarks = $"{nameof(EConfigType.WireGuard)} Peer {index + 1}", + ConfigType = EConfigType.WireGuard, + Address = peerAddress, + Port = peerPort, + Password = privateKey, + }; + item.SetProtocolExtra(protoExtra); + resultList.Add(item); + + index += 1; + } + + return resultList; + } + + private static bool TryParseEndpoint(string endpoint, out string address, out int port) + { + address = string.Empty; + port = 2408; + + var trimmedEndpoint = endpoint.Trim(); + if (trimmedEndpoint.IsNullOrEmpty()) + { + return false; + } + + if (trimmedEndpoint[0] == '[') + { + var closeIndex = trimmedEndpoint.IndexOf(']'); + if (closeIndex <= 1) + { + return false; + } + + address = trimmedEndpoint[1..closeIndex].Trim(); + var portIndex = closeIndex + 1; + if (portIndex < trimmedEndpoint.Length && trimmedEndpoint[portIndex] == ':' && + int.TryParse(trimmedEndpoint[(portIndex + 1)..].Trim(), out var bracketedPort) && bracketedPort is > 0 and <= 65535) + { + port = bracketedPort; + } + + return address.IsNotEmpty(); + } + + var lastColonIndex = trimmedEndpoint.LastIndexOf(':'); + if (lastColonIndex <= 0) + { + address = trimmedEndpoint; + return true; + } + + address = trimmedEndpoint[..lastColonIndex].Trim(); + var portText = trimmedEndpoint[(lastColonIndex + 1)..].Trim(); + if (address.IsNullOrEmpty()) + { + return false; + } + + if (int.TryParse(portText, out var parsedPortValue) && parsedPortValue is > 0 and <= 65535) + { + port = parsedPortValue; + return true; + } + + address = trimmedEndpoint; + return true; + } } diff --git a/v2rayN/ServiceLib/Models/SingboxConfig.cs b/v2rayN/ServiceLib/Models/SingboxConfig.cs index 2282e830..0e2bb530 100644 --- a/v2rayN/ServiceLib/Models/SingboxConfig.cs +++ b/v2rayN/ServiceLib/Models/SingboxConfig.cs @@ -173,7 +173,7 @@ public class Peer4Sbox public string? pre_shared_key { get; set; } public List allowed_ips { get; set; } public int? persistent_keepalive_interval { get; set; } - public List reserved { get; set; } + public List? reserved { get; set; } } public class Tls4Sbox diff --git a/v2rayN/ServiceLib/Models/V2rayConfig.cs b/v2rayN/ServiceLib/Models/V2rayConfig.cs index 26739b69..10420dad 100644 --- a/v2rayN/ServiceLib/Models/V2rayConfig.cs +++ b/v2rayN/ServiceLib/Models/V2rayConfig.cs @@ -163,6 +163,7 @@ public class WireguardPeer4Ray { public string endpoint { get; set; } public string publicKey { get; set; } + public string? preSharedKey { get; set; } } public class VnextItem4Ray diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index a948dee9..81efe4a5 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3222,6 +3222,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 MTU 的本地化字符串。 + /// + public static string TbMtu { + get { + return ResourceManager.GetString("TbMtu", resourceCulture); + } + } + /// /// 查找类似 Transport protocol(network) 的本地化字符串。 /// @@ -3312,6 +3321,15 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 PreSharedKey 的本地化字符串。 + /// + public static string TbPreSharedKey { + get { + return ResourceManager.GetString("TbPreSharedKey", resourceCulture); + } + } + /// /// 查找类似 Socks port 的本地化字符串。 /// @@ -3430,7 +3448,7 @@ namespace ServiceLib.Resx { } /// - /// 查找类似 Reserved (2,3,4) 的本地化字符串。 + /// 查找类似 Reserved 的本地化字符串。 /// public static string TbReserved { get { @@ -4365,15 +4383,6 @@ namespace ServiceLib.Resx { } } - /// - /// 查找类似 MTU 的本地化字符串。 - /// - public static string TbSettingsTunMtu { - get { - return ResourceManager.GetString("TbSettingsTunMtu", resourceCulture); - } - } - /// /// 查找类似 Stack 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index c3f53c89..e21d3fec 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1062,7 +1062,7 @@ پشته شبکه - + MTU @@ -1075,7 +1075,7 @@ کلید خصوصی - Reserved (2,3,4) + Reserved آدرس (IPv4, IPv6) @@ -1725,4 +1725,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.fr.resx b/v2rayN/ServiceLib/Resx/ResUI.fr.resx index 2a5d8823..898acc2a 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fr.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fr.resx @@ -1059,7 +1059,7 @@ Pile de protocoles - + MTU @@ -1072,7 +1072,7 @@ PrivateKey - Reserved (2,3,4) + Reserved Address (IPv4,IPv6) @@ -1716,4 +1716,13 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if Pour les environnements multi-interfaces, entrez le nom de l'interface à lier. Ne fonctionne que sur les systèmes Windows et en mode TUN + + Test Configurations UDP Delay + + + UDP Test Url + + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index 33656ba8..4eb6fc35 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1062,7 +1062,7 @@ Hálózati verem - + MTU @@ -1075,7 +1075,7 @@ Privát kulcs - Fenntartott (2,3,4) + Fenntartott Cím (IPv4, IPv6) @@ -1725,4 +1725,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 9659926b..b5d832c6 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1062,7 +1062,7 @@ Stack - + MTU @@ -1075,7 +1075,7 @@ Private Key - Reserved (2,3,4) + Reserved Address (IPv4, IPv6) @@ -1725,4 +1725,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 07e0e841..fa9bbce1 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1062,7 +1062,7 @@ Сетевой стек - + MTU @@ -1075,7 +1075,7 @@ Приватный ключ - Зарезервировано (2, 3, 4) + Зарезервировано Адрес (IPv4, IPv6) @@ -1725,4 +1725,7 @@ Для среды с несколькими сетевыми интерфейсами укажите имя интерфейса для привязки. Работает только в Windows и режиме TUN + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index f1d0406f..c6a6378b 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1059,7 +1059,7 @@ 协议栈 - + MTU @@ -1072,7 +1072,7 @@ PrivateKey - Reserved (2,3,4) + Reserved Address (IPv4,IPv6) @@ -1722,4 +1722,7 @@ 用于多网口环境,填写要绑定的网口名称,仅生效于 Windows 系统和 TUN 模式 + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 4dd3ea86..821485e8 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1059,7 +1059,7 @@ 協定堆疊 - + MTU @@ -1072,7 +1072,7 @@ PrivateKey - Reserved (2,3,4) + Reserved Address (Ipv4,Ipv6) @@ -1722,4 +1722,7 @@ For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + + PreSharedKey + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs index c438dabd..8d36b353 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs @@ -309,7 +309,7 @@ public partial class CoreConfigSingboxService { var protocolExtra = _node.GetProtocolExtra(); - endpoint.address = Utils.String2List(protocolExtra.WgInterfaceAddress); + endpoint.address = Utils.String2List(protocolExtra.WgInterfaceAddress)?.Select(s => s.Trim()).ToList() ?? ["172.16.0.2/32"]; endpoint.type = Global.ProtocolTypes[_node.ConfigType]; switch (_node.ConfigType) @@ -318,13 +318,12 @@ public partial class CoreConfigSingboxService { var peer = new Peer4Sbox { - public_key = protocolExtra.WgPublicKey, + public_key = protocolExtra.WgPublicKey ?? string.Empty, pre_shared_key = protocolExtra.WgPresharedKey, - reserved = Utils.String2List(protocolExtra.WgReserved)?.Select(int.Parse).ToList(), + reserved = Utils.String2List(protocolExtra.WgReserved)?.Select(s => s.Trim()).Select(int.Parse).ToList(), address = _node.Address, port = _node.Port, - // TODO default ["0.0.0.0/0", "::/0"] - allowed_ips = new() { "0.0.0.0/0", "::/0" }, + allowed_ips = ["0.0.0.0/0", "::/0"], }; endpoint.private_key = _node.Password; endpoint.mtu = protocolExtra.WgMtu > 0 ? protocolExtra.WgMtu : Global.TunMtus.First(); diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index aeae3618..f3836960 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -258,13 +258,14 @@ public partial class CoreConfigV2rayService var peer = new WireguardPeer4Ray { publicKey = protocolExtra.WgPublicKey ?? "", - endpoint = address + ":" + _node.Port.ToString() + endpoint = address + ":" + _node.Port.ToString(), + preSharedKey = protocolExtra.WgPresharedKey, }; var setting = new Outboundsettings4Ray { - address = Utils.String2List(protocolExtra.WgInterfaceAddress), + address = Utils.String2List(protocolExtra.WgInterfaceAddress)?.Select(s => s.Trim()).ToList() ?? ["172.16.0.2/32"], secretKey = _node.Password, - reserved = Utils.String2List(protocolExtra.WgReserved)?.Select(int.Parse).ToList(), + reserved = Utils.String2List(protocolExtra.WgReserved)?.Select(s => s.Trim()).Select(int.Parse).ToList(), mtu = protocolExtra.WgMtu > 0 ? protocolExtra.WgMtu : Global.TunMtus.First(), peers = [peer] }; diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs index 20439a03..169e8a44 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs @@ -53,8 +53,9 @@ public class AddServerViewModel : MyReactiveObject [Reactive] public string WgPublicKey { get; set; } - //[Reactive] - //public string WgPresharedKey { get; set; } + [Reactive] + public string WgPresharedKey { get; set; } + [Reactive] public string WgInterfaceAddress { get; set; } @@ -159,17 +160,8 @@ public class AddServerViewModel : MyReactiveObject switch (SelectedSource.GetNetwork()) { case nameof(ETransport.raw): - Host = value; - break; - case nameof(ETransport.ws): - Host = value; - break; - case nameof(ETransport.httpupgrade): - Host = value; - break; - case nameof(ETransport.xhttp): Host = value; break; @@ -202,13 +194,7 @@ public class AddServerViewModel : MyReactiveObject break; case nameof(ETransport.ws): - Path = value; - break; - case nameof(ETransport.httpupgrade): - Path = value; - break; - case nameof(ETransport.xhttp): Path = value; break; @@ -303,6 +289,7 @@ public class AddServerViewModel : MyReactiveObject VlessEncryption = protocolExtra.VlessEncryption?.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None; SsMethod = protocolExtra.SsMethod ?? string.Empty; WgPublicKey = protocolExtra.WgPublicKey ?? string.Empty; + WgPresharedKey = protocolExtra.WgPresharedKey ?? string.Empty; WgInterfaceAddress = protocolExtra.WgInterfaceAddress ?? string.Empty; WgReserved = protocolExtra.WgReserved ?? string.Empty; WgMtu = protocolExtra.WgMtu ?? 1280; @@ -401,6 +388,7 @@ public class AddServerViewModel : MyReactiveObject VlessEncryption = VlessEncryption.NullIfEmpty(), SsMethod = SsMethod.NullIfEmpty(), WgPublicKey = WgPublicKey.NullIfEmpty(), + WgPresharedKey = WgPresharedKey.NullIfEmpty(), WgInterfaceAddress = WgInterfaceAddress.NullIfEmpty(), WgReserved = WgReserved.NullIfEmpty(), WgMtu = WgMtu >= 576 ? WgMtu : null, diff --git a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml index 3ab748b1..dbf031b1 100644 --- a/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/AddServerWindow.axaml @@ -508,7 +508,7 @@ Grid.Row="2" ColumnDefinitions="300,Auto" IsVisible="False" - RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto"> + RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto"> + Text="{x:Static resx:ResUI.TbPreSharedKey}" /> + HorizontalAlignment="Left" /> + + + + Text="{x:Static resx:ResUI.TbMtu}" /> + Watermark="1280" /> + Text="{x:Static resx:ResUI.TbMtu}" /> case EConfigType.WireGuard: this.Bind(ViewModel, vm => vm.SelectedSource.Password, v => v.txtId9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgPublicKey, v => v.txtPublicKey9.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.WgPresharedKey, v => v.txtPreSharedKey9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgReserved, v => v.txtPath9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgInterfaceAddress, v => v.txtRequestHost9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgMtu, v => v.txtShortId9.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml index c7833fe9..d47deb2e 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml @@ -869,7 +869,7 @@ Grid.Column="0" Margin="{StaticResource Margin4}" VerticalAlignment="Center" - Text="{x:Static resx:ResUI.TbSettingsTunMtu}" /> + Text="{x:Static resx:ResUI.TbMtu}" /> + @@ -721,14 +722,14 @@ Margin="{StaticResource Margin4}" VerticalAlignment="Center" Style="{StaticResource ToolbarTextBlock}" - Text="{x:Static resx:ResUI.TbReserved}" /> + Text="{x:Static resx:ResUI.TbPreSharedKey}" /> + + + + Text="{x:Static resx:ResUI.TbMtu}" /> + Text="{x:Static resx:ResUI.TbMtu}" /> vm.SelectedSource.Password, v => v.txtId9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgPublicKey, v => v.txtPublicKey9.Text).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.WgPresharedKey, v => v.txtPreSharedKey9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgReserved, v => v.txtPath9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgInterfaceAddress, v => v.txtRequestHost9.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.WgMtu, v => v.txtShortId9.Text).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml index 9e85b501..0a5208e3 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -469,7 +469,7 @@ Margin="{StaticResource Margin8}" VerticalAlignment="Center" Style="{StaticResource ToolbarTextBlock}" - Text="{x:Static resx:ResUI.TbSettingsTunMtu}" /> + Text="{x:Static resx:ResUI.TbMtu}" /> + Text="{x:Static resx:ResUI.TbMtu}" />