mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
[Netch] Support WireGuard protocol
This commit is contained in:
@@ -69,6 +69,10 @@
|
||||
"Plugin": "插件",
|
||||
"Plugin Options": "插件参数",
|
||||
"Remote Address": "远端地址",
|
||||
"Local Addresses": "本地地址(可多个)",
|
||||
"Public Key": "节点公钥",
|
||||
"Private Key": "私钥",
|
||||
"PSK": "节点预共享密钥",
|
||||
|
||||
"Subscription": "订阅",
|
||||
"Manage Subscriptions": "管理订阅",
|
||||
|
||||
@@ -47,6 +47,16 @@ public class OutboundConfiguration
|
||||
public string pluginOpts { get; set; }
|
||||
|
||||
public string[] pluginArgs { get; set; }
|
||||
|
||||
public string[] localAddresses { get; set; }
|
||||
|
||||
public string peerPublicKey { get; set; }
|
||||
|
||||
public string privateKey { get; set; }
|
||||
|
||||
public string preSharedKey { get; set; }
|
||||
|
||||
public int mtu { get; set; }
|
||||
}
|
||||
|
||||
public class VnextItem
|
||||
|
||||
@@ -186,14 +186,17 @@ public static class V2rayConfigUtils
|
||||
break;
|
||||
case TrojanServer trojan:
|
||||
outbound.protocol = "trojan";
|
||||
outbound.settings.servers = new[]
|
||||
outbound.settings = new OutboundConfiguration
|
||||
{
|
||||
new ShadowsocksServerItem // I'm not serious
|
||||
servers = new[]
|
||||
{
|
||||
address = await server.AutoResolveHostnameAsync(),
|
||||
port = server.Port,
|
||||
method = "",
|
||||
password = trojan.Password
|
||||
new ShadowsocksServerItem // I'm not serious
|
||||
{
|
||||
address = await server.AutoResolveHostnameAsync(),
|
||||
port = server.Port,
|
||||
method = "",
|
||||
password = trojan.Password
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -221,6 +224,19 @@ public static class V2rayConfigUtils
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WireGuardServer wg:
|
||||
outbound.protocol = "wireguard";
|
||||
outbound.settings = new OutboundConfiguration
|
||||
{
|
||||
address = await server.AutoResolveHostnameAsync(),
|
||||
port = server.Port,
|
||||
localAddresses = wg.LocalAddresses.SplitOrDefault(),
|
||||
peerPublicKey = wg.PeerPublicKey,
|
||||
privateKey = wg.PrivateKey,
|
||||
preSharedKey = wg.PreSharedKey,
|
||||
mtu = wg.MTU
|
||||
};
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
20
Netch/Servers/WireGuard/WireGuardForm.cs
Normal file
20
Netch/Servers/WireGuard/WireGuardForm.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Netch.Forms;
|
||||
|
||||
namespace Netch.Servers;
|
||||
|
||||
[Fody.ConfigureAwait(true)]
|
||||
public class WireGuardForm : ServerForm
|
||||
{
|
||||
public WireGuardForm(WireGuardServer? server = default)
|
||||
{
|
||||
server ??= new WireGuardServer();
|
||||
Server = server;
|
||||
CreateTextBox("LocalAddresses", "Local Addresses", s => true, s => server.LocalAddresses = s, server.LocalAddresses);
|
||||
CreateTextBox("PeerPublicKey", "Public Key", s => true, s => server.PeerPublicKey = s, server.PeerPublicKey);
|
||||
CreateTextBox("PrivateKey", "Private Key", s => true, s => server.PrivateKey = s, server.PrivateKey);
|
||||
CreateTextBox("PreSharedKey", "PSK", s => true, s => server.PreSharedKey = s, server.PreSharedKey);
|
||||
CreateTextBox("MTU", "MTU", s => int.TryParse(s, out _), s => server.MTU = int.Parse(s), server.MTU.ToString(), 76);
|
||||
}
|
||||
|
||||
protected override string TypeName { get; } = "WireGuard";
|
||||
}
|
||||
38
Netch/Servers/WireGuard/WireGuardServer.cs
Normal file
38
Netch/Servers/WireGuard/WireGuardServer.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Netch.Models;
|
||||
|
||||
namespace Netch.Servers;
|
||||
|
||||
public class WireGuardServer : Server
|
||||
{
|
||||
public override string Type { get; } = "WireGuard";
|
||||
|
||||
public override string MaskedData()
|
||||
{
|
||||
return $"{LocalAddress} + {MTU}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本地地址
|
||||
/// </summary>
|
||||
public string LocalAddresses { get; set; } = "172.16.0.2";
|
||||
|
||||
/// <summary>
|
||||
/// 节点公钥
|
||||
/// </summary>
|
||||
public string PeerPublicKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 私钥
|
||||
/// </summary>
|
||||
public string PrivateKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点预共享密钥
|
||||
/// </summary>
|
||||
public string? PreSharedKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MTU
|
||||
/// </summary>
|
||||
public int MTU { get; set; } = 1420;
|
||||
}
|
||||
53
Netch/Servers/WireGuard/WireGuardUtil.cs
Normal file
53
Netch/Servers/WireGuard/WireGuardUtil.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Netch.Interfaces;
|
||||
using Netch.Models;
|
||||
using Netch.Utils;
|
||||
|
||||
namespace Netch.Servers;
|
||||
|
||||
public class WireGuardUtil : IServerUtil
|
||||
{
|
||||
public ushort Priority { get; } = 4;
|
||||
|
||||
public string TypeName { get; } = "WireGuard";
|
||||
|
||||
public string FullName { get; } = "WireGuard";
|
||||
|
||||
public string ShortName { get; } = "WG";
|
||||
|
||||
public string[] UriScheme { get; } = { "wireguard" };
|
||||
|
||||
public Type ServerType { get; } = typeof(WireGuardServer);
|
||||
|
||||
public void Edit(Server s)
|
||||
{
|
||||
new WireGuardForm((WireGuardServer)s).ShowDialog();
|
||||
}
|
||||
|
||||
public void Create()
|
||||
{
|
||||
new WireGuardForm().ShowDialog();
|
||||
}
|
||||
|
||||
public string GetShareLink(Server s)
|
||||
{
|
||||
return V2rayUtils.GetVShareLink(s, "wireguard");
|
||||
}
|
||||
|
||||
public IServerController GetController()
|
||||
{
|
||||
return new V2rayController();
|
||||
}
|
||||
|
||||
public IEnumerable<Server> ParseUri(string text)
|
||||
{
|
||||
return V2rayUtils.ParseVUri(text);
|
||||
}
|
||||
|
||||
public bool CheckServer(Server s)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user