mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-30 01:34:08 +00:00
Opt
This commit is contained in:
parent
298f370f72
commit
d5ebe96f66
14 changed files with 51 additions and 37 deletions
|
|
@ -9,22 +9,23 @@ public class WireguardFmtTests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolveConfig_ShouldParsePeersAndIgnoreInlineComments()
|
public void ResolveConfig_ShouldParsePeersAndIgnoreInlineComments()
|
||||||
{
|
{
|
||||||
var config = """
|
const string config =
|
||||||
[Interface]
|
"""
|
||||||
PrivateKey = interface-private-key
|
[Interface]
|
||||||
Address = 10.0.0.2/32, fd00::2/128 ; inline comment
|
PrivateKey = interface-private-key
|
||||||
MTU = 1420
|
Address = 10.0.0.2/32, fd00::2/128 ; inline comment
|
||||||
|
MTU = 1420
|
||||||
|
|
||||||
[Peer]
|
[Peer]
|
||||||
PublicKey = peer-public-key
|
PublicKey = peer-public-key
|
||||||
PresharedKey = peer-preshared-key
|
PresharedKey = peer-preshared-key
|
||||||
Reserved = 1, 2, 3 # inline comment
|
Reserved = 1, 2, 3 # inline comment
|
||||||
Endpoint = [2001:db8::1]:51820 # inline comment
|
Endpoint = [2001:db8::1]:51820 # inline comment
|
||||||
|
|
||||||
[Peer]
|
[Peer]
|
||||||
PublicKey = peer-public-key-2
|
PublicKey = peer-public-key-2
|
||||||
Endpoint = example.com:12345
|
Endpoint = example.com:12345
|
||||||
""";
|
""";
|
||||||
|
|
||||||
var resolved = WireguardFmt.ResolveConfig(config);
|
var resolved = WireguardFmt.ResolveConfig(config);
|
||||||
|
|
||||||
|
|
@ -43,4 +44,4 @@ public class WireguardFmtTests
|
||||||
second.Address.Should().Be("example.com");
|
second.Address.Should().Be("example.com");
|
||||||
second.Port.Should().Be(12345);
|
second.Port.Should().Be(12345);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -791,9 +791,22 @@ public static class ConfigHandler
|
||||||
profileItem.Address = profileItem.Address.TrimEx();
|
profileItem.Address = profileItem.Address.TrimEx();
|
||||||
profileItem.Password = profileItem.Password.TrimEx();
|
profileItem.Password = profileItem.Password.TrimEx();
|
||||||
var wgReserved = profileItem.GetProtocolExtra().WgReserved?.TrimEx();
|
var wgReserved = profileItem.GetProtocolExtra().WgReserved?.TrimEx();
|
||||||
if (!wgReserved.IsNullOrEmpty())
|
if (!wgReserved.IsNullOrEmpty()
|
||||||
|
&& !wgReserved.Contains(','))
|
||||||
{
|
{
|
||||||
wgReserved = wgReserved.Replace(", ", ",");
|
// 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
|
profileItem.SetProtocolExtra(profileItem.GetProtocolExtra() with
|
||||||
{
|
{
|
||||||
|
|
@ -1735,15 +1748,15 @@ public static class ConfigHandler
|
||||||
{
|
{
|
||||||
await RemoveServersViaSubid(config, subid, isSub);
|
await RemoveServersViaSubid(config, subid, isSub);
|
||||||
}
|
}
|
||||||
var lstSsServer = WireguardFmt.ResolveConfig(strData);
|
var lstServer = WireguardFmt.ResolveConfig(strData);
|
||||||
if (lstSsServer?.Count > 0)
|
if (lstServer?.Count > 0)
|
||||||
{
|
{
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
foreach (var ssItem in lstSsServer)
|
foreach (var item in lstServer)
|
||||||
{
|
{
|
||||||
ssItem.Subid = subid;
|
item.Subid = subid;
|
||||||
ssItem.IsSub = isSub;
|
item.IsSub = isSub;
|
||||||
if (await AddWireguardServer(config, ssItem) == 0)
|
if (await AddWireguardServer(config, item) == 0)
|
||||||
{
|
{
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
2
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
|
@ -3448,7 +3448,7 @@ namespace ServiceLib.Resx {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Reserved (2,3,4) 的本地化字符串。
|
/// 查找类似 Reserved 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string TbReserved {
|
public static string TbReserved {
|
||||||
get {
|
get {
|
||||||
|
|
|
||||||
|
|
@ -1075,7 +1075,7 @@
|
||||||
<value>کلید خصوصی</value>
|
<value>کلید خصوصی</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbReserved" xml:space="preserve">
|
<data name="TbReserved" xml:space="preserve">
|
||||||
<value>Reserved (2,3,4)</value>
|
<value>Reserved</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>آدرس (IPv4, IPv6)</value>
|
<value>آدرس (IPv4, IPv6)</value>
|
||||||
|
|
|
||||||
|
|
@ -1072,7 +1072,7 @@
|
||||||
<value>PrivateKey</value>
|
<value>PrivateKey</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbReserved" xml:space="preserve">
|
<data name="TbReserved" xml:space="preserve">
|
||||||
<value>Reserved (2,3,4)</value>
|
<value>Reserved</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Address (IPv4,IPv6)</value>
|
<value>Address (IPv4,IPv6)</value>
|
||||||
|
|
|
||||||
|
|
@ -1075,7 +1075,7 @@
|
||||||
<value>Privát kulcs</value>
|
<value>Privát kulcs</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbReserved" xml:space="preserve">
|
<data name="TbReserved" xml:space="preserve">
|
||||||
<value>Fenntartott (2,3,4)</value>
|
<value>Fenntartott</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Cím (IPv4, IPv6)</value>
|
<value>Cím (IPv4, IPv6)</value>
|
||||||
|
|
|
||||||
|
|
@ -1075,7 +1075,7 @@
|
||||||
<value>Private Key</value>
|
<value>Private Key</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbReserved" xml:space="preserve">
|
<data name="TbReserved" xml:space="preserve">
|
||||||
<value>Reserved (2,3,4)</value>
|
<value>Reserved</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Address (IPv4, IPv6)</value>
|
<value>Address (IPv4, IPv6)</value>
|
||||||
|
|
|
||||||
|
|
@ -1075,7 +1075,7 @@
|
||||||
<value>Приватный ключ</value>
|
<value>Приватный ключ</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbReserved" xml:space="preserve">
|
<data name="TbReserved" xml:space="preserve">
|
||||||
<value>Зарезервировано (2, 3, 4)</value>
|
<value>Зарезервировано</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Адрес (IPv4, IPv6)</value>
|
<value>Адрес (IPv4, IPv6)</value>
|
||||||
|
|
|
||||||
|
|
@ -1072,7 +1072,7 @@
|
||||||
<value>PrivateKey</value>
|
<value>PrivateKey</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbReserved" xml:space="preserve">
|
<data name="TbReserved" xml:space="preserve">
|
||||||
<value>Reserved (2,3,4)</value>
|
<value>Reserved</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Address (IPv4,IPv6)</value>
|
<value>Address (IPv4,IPv6)</value>
|
||||||
|
|
|
||||||
|
|
@ -1072,7 +1072,7 @@
|
||||||
<value>PrivateKey</value>
|
<value>PrivateKey</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbReserved" xml:space="preserve">
|
<data name="TbReserved" xml:space="preserve">
|
||||||
<value>Reserved (2,3,4)</value>
|
<value>Reserved</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="TbLocalAddress" xml:space="preserve">
|
<data name="TbLocalAddress" xml:space="preserve">
|
||||||
<value>Address (Ipv4,Ipv6)</value>
|
<value>Address (Ipv4,Ipv6)</value>
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,7 @@ public partial class CoreConfigSingboxService
|
||||||
{
|
{
|
||||||
var protocolExtra = _node.GetProtocolExtra();
|
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];
|
endpoint.type = Global.ProtocolTypes[_node.ConfigType];
|
||||||
|
|
||||||
switch (_node.ConfigType)
|
switch (_node.ConfigType)
|
||||||
|
|
@ -320,7 +320,7 @@ public partial class CoreConfigSingboxService
|
||||||
{
|
{
|
||||||
public_key = protocolExtra.WgPublicKey ?? string.Empty,
|
public_key = protocolExtra.WgPublicKey ?? string.Empty,
|
||||||
pre_shared_key = protocolExtra.WgPresharedKey,
|
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,
|
address = _node.Address,
|
||||||
port = _node.Port,
|
port = _node.Port,
|
||||||
allowed_ips = ["0.0.0.0/0", "::/0"],
|
allowed_ips = ["0.0.0.0/0", "::/0"],
|
||||||
|
|
|
||||||
|
|
@ -263,9 +263,9 @@ public partial class CoreConfigV2rayService
|
||||||
};
|
};
|
||||||
var setting = new Outboundsettings4Ray
|
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,
|
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(),
|
mtu = protocolExtra.WgMtu > 0 ? protocolExtra.WgMtu : Global.TunMtus.First(),
|
||||||
peers = [peer]
|
peers = [peer]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -563,7 +563,7 @@
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="400"
|
Width="400"
|
||||||
Margin="{StaticResource Margin4}"
|
Margin="{StaticResource Margin4}"
|
||||||
Watermark="2,3,4" />
|
Watermark="0, 0, 0" />
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="5"
|
Grid.Row="5"
|
||||||
|
|
|
||||||
|
|
@ -745,7 +745,7 @@
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Width="400"
|
Width="400"
|
||||||
Margin="{StaticResource Margin4}"
|
Margin="{StaticResource Margin4}"
|
||||||
materialDesign:HintAssist.Hint="2,3,4"
|
materialDesign:HintAssist.Hint="0, 0, 0"
|
||||||
Style="{StaticResource DefTextBox}" />
|
Style="{StaticResource DefTextBox}" />
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue