diff --git a/src/generator/config/subexport.cpp b/src/generator/config/subexport.cpp index 55f966203..4281263d9 100644 --- a/src/generator/config/subexport.cpp +++ b/src/generator/config/subexport.cpp @@ -234,9 +234,11 @@ void proxyToClash(std::vector &nodes, YAML::Node &yamlnode, const ProxyGr if (!x.ShortId.empty()) singleproxy["reality-opts"]["short-id"] = x.ShortId; } - singleproxy["client-fingerprint"] = "chrome"; - if (!x.Fingerprint.empty()) - singleproxy["client-fingerprint"] = x.Fingerprint; + if (x.Type != ProxyType::WireGuard){ + singleproxy["client-fingerprint"] = "chrome"; + if (!x.Fingerprint.empty()) + singleproxy["client-fingerprint"] = x.Fingerprint; + } switch (x.Type) { case ProxyType::Shadowsocks: //latest clash core removed support for chacha20 encryption @@ -532,6 +534,21 @@ void proxyToClash(std::vector &nodes, YAML::Node &yamlnode, const ProxyGr if(std::all_of(x.Password.begin(), x.Password.end(), ::isdigit) && !x.Password.empty()) singleproxy["password"].SetTag("str"); break; + case ProxyType::WireGuard: + if (x.DNS.size() > 1) + singleproxy["dns"] = x.DNS; + singleproxy["group"] = x.Group; + singleproxy["ip"] = x.Host; + singleproxy["name"] = x.Remark; + singleproxy["port"] = x.Port; + singleproxy["private-key"] = x.WireGuardPrivateKey; + singleproxy["public-key"] = x.WireGuardPublicKey; + singleproxy["remote-dns-resolve"] = true; + singleproxy["server"] = x.Hostname; + singleproxy["type"] = getProxyTypeName(x.Type); + singleproxy["udp"] = true; + singleproxy["mtu"] = 1280; + break; default: continue; } diff --git a/src/parser/config/proxy.h b/src/parser/config/proxy.h index 52265ec36..f0ee2f73b 100644 --- a/src/parser/config/proxy.h +++ b/src/parser/config/proxy.h @@ -20,7 +20,8 @@ enum ProxyType Snell, HTTP, HTTPS, - SOCKS5 + SOCKS5, + WireGuard, }; inline String getProxyTypeName(int type) @@ -49,6 +50,8 @@ inline String getProxyTypeName(int type) return "HTTPS"; case ProxyType::SOCKS5: return "SOCKS5"; + case ProxyType::WireGuard: + return "wireguard"; default: return "Unknown"; } @@ -108,10 +111,13 @@ struct Proxy String Fingerprint; String PublicKey; + String WireGuardPublicKey; + String WireGuardPrivateKey; String ShortId; String OBFSPassword; + std::vector DNS; }; #define SS_DEFAULT_GROUP "SSProvider" diff --git a/src/parser/subparser.cpp b/src/parser/subparser.cpp index ba5a1ee54..5f5d602e8 100644 --- a/src/parser/subparser.cpp +++ b/src/parser/subparser.cpp @@ -172,6 +172,15 @@ void trojanConstruct(Proxy &node, const std::string &group, const std::string &r node.GRPCServiceName = path.empty() ? "/" : urlEncode(urlDecode(trim(path))); } +void wireguardConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &privatekey, const std::string &publickey, tribool udp, std::string host, std::vector dns) +{ + commonConstruct(node, ProxyType::WireGuard, group, remarks, server, port, udp, tribool(), tribool(), tribool()); + node.WireGuardPrivateKey = privatekey; + node.WireGuardPublicKey = publickey; + node.Host = host; + node.DNS = dns; +} + void snellConstruct(Proxy &node, const std::string &group, const std::string &remarks, const std::string &server, const std::string &port, const std::string &password, const std::string &obfs, const std::string &host, uint16_t version, tribool udp, tribool tfo, tribool scv) { commonConstruct(node, ProxyType::Snell, group, remarks, server, port, udp, tfo, scv, tribool()); @@ -879,6 +888,44 @@ void explodeTrojan(std::string trojan, Proxy &node) trojanConstruct(node, group, remark, server, port, psk, network, mode, host, path, flow, tls, tribool(), tfo, scv); } +void explodeWireGuard(std::string wireguard, Proxy &node) +{ + std::string server, port, publicKey, privateKey, dns, ip, flag, name; + std::vector dnsList; + tribool udp; + string_size pos = wireguard.find("#"); + if(pos != wireguard.npos) + { + name = urlDecode(wireguard.substr(pos + 1)); + wireguard = wireguard.substr(0, pos); + } + + wireguard = wireguard.substr(5); + pos = wireguard.rfind(":"); + if(pos == wireguard.npos) + { + return; + } + server = wireguard.substr(0, pos); + wireguard = wireguard.substr(pos + 1); + pos = wireguard.find("?"); + if(pos == wireguard.npos) + { + return; + } + port = wireguard.substr(0, pos); + wireguard = wireguard.substr(pos + 1); + + publicKey = getUrlArg(wireguard, "publicKey"); + privateKey = getUrlArg(wireguard, "privateKey"); + dns = getUrlArg(wireguard, "dns"); + dnsList = split(dns, ","); + ip = getUrlArg(wireguard, "ip"); + udp = getUrlArg(wireguard, "udp") == "1" ? true : false; + flag = getUrlArg(wireguard, "flag"); + wireguardConstruct(node, flag, name, server, port, privateKey, publicKey, udp, ip, dnsList); +} + void explodeQuan(const std::string &quan, Proxy &node) { std::string strTemp, itemName, itemVal; @@ -2441,6 +2488,8 @@ void explode(const std::string &link, Proxy &node) explodeNetch(link, node); else if(strFind(link, "trojan://") || strFind(link, "trojan-go://")) explodeTrojan(link, node); + else if(strFind(link, "wg://")) + explodeWireGuard(link, node); else if(isLink(link)) explodeHTTPSub(link, node); }