Enhancements

Add support for Quantumult X style Trojan nodes.
Optimize codes.
This commit is contained in:
Tindy X committed 2020-03-17 15:37:57 +08:00
1 parent 9e305bc900
commit 7e489788e3
5 files changed
+164 -298

No files matched your search

+3
View File
@@ -1194,6 +1194,9 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
if(subInfo.size() && (append_sub_userinfo.size() ? append_sub_userinfo == "true" : append_userinfo)) if(subInfo.size() && (append_sub_userinfo.size() ? append_sub_userinfo == "true" : append_userinfo))
extra_headers.emplace("Subscription-UserInfo", subInfo); extra_headers.emplace("Subscription-UserInfo", subInfo);
//do pre-process now
preprocessNodes(nodes, ext);
string_array dummy_group; string_array dummy_group;
std::vector<ruleset_content> dummy_ruleset; std::vector<ruleset_content> dummy_ruleset;
+98 -70
View File
@@ -14,6 +14,7 @@
#include "webget.h" #include "webget.h"
#include "rapidjson_extra.h" #include "rapidjson_extra.h"
#include "ini_reader.h" #include "ini_reader.h"
#include "string_hash.h"
using namespace rapidjson; using namespace rapidjson;
using namespace YAML; using namespace YAML;
@@ -634,7 +635,7 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, int local
node.remarks = remark; node.remarks = remark;
node.server = server; node.server = server;
node.port = to_int(port, 0); node.port = to_int(port, 0);
node.proxyStr = trojanConstruct(remark, server, port, psk); node.proxyStr = trojanConstruct(remark, server, port, psk, "", false);
} }
void explodeQuan(std::string quan, const std::string &custom_port, int local_port, nodeInfo &node) void explodeQuan(std::string quan, const std::string &custom_port, int local_port, nodeInfo &node)
@@ -1135,13 +1136,15 @@ bool explodeSurge(std::string surge, const std::string &custom_port, int local_p
continue; continue;
itemName = trim(vArray[0]); itemName = trim(vArray[0]);
itemVal = trim(vArray[1]); itemVal = trim(vArray[1]);
if(itemName == "obfs") switch(hash_(itemName))
{ {
plugin = "simple-obfs"; case "obfs"_hash:
pluginopts_mode = itemVal; plugin = "simple-obfs";
pluginopts_mode = itemVal;
break;
case "obfs-host"_hash: pluginopts_host = itemVal; break;
default: continue;
} }
else if(itemName == "obfs-host")
pluginopts_host = itemVal;
} }
if(plugin.size()) if(plugin.size())
{ {
@@ -1168,17 +1171,17 @@ bool explodeSurge(std::string surge, const std::string &custom_port, int local_p
continue; continue;
itemName = trim(vArray[0]); itemName = trim(vArray[0]);
itemVal = trim(vArray[1]); itemVal = trim(vArray[1]);
if(itemName == "encrypt-method") switch(hash_(itemName))
method = itemVal;
else if(itemName == "password")
password = itemVal;
else if(itemName == "obfs")
{ {
plugin = "simple-obfs"; case "encrypt-method"_hash: method = itemVal; break;
pluginopts_mode = itemVal; case "password"_hash: id = itemVal; break;
case "obfs"_hash:
plugin = "simple-obfs";
pluginopts_mode = itemVal;
break;
case "obfs-host"_hash: pluginopts_host = itemVal; break;
default: continue;
} }
else if(itemName == "obfs-host")
pluginopts_host = itemVal;
} }
if(plugin.size()) if(plugin.size())
{ {
@@ -1217,29 +1220,25 @@ bool explodeSurge(std::string surge, const std::string &custom_port, int local_p
continue; continue;
itemName = trim(vArray[0]); itemName = trim(vArray[0]);
itemVal = trim(vArray[1]); itemVal = trim(vArray[1]);
if(itemName == "username") switch(hash_(itemName))
id = itemVal;
else if(itemName == "ws")
{ {
net = itemVal == "true" ? "ws" : "tcp"; case "username"_hash: id = itemVal; break;
} case "ws"_hash: net = itemVal == "true" ? "ws" : "tcp"; break;
else if(itemName == "tls") case "tls"_hash: tls = itemVal == "true" ? "tls" : ""; break;
{ case "ws-path"_hash: path = itemVal; break;
tls = itemVal == "true" ? "tls" : ""; case "obfs-host"_hash: host = itemVal; break;
} case "ws-headers"_hash:
else if(itemName == "ws-path") headers = split(itemVal, "|");
path = itemVal; for(auto &y : headers)
else if(itemName == "ws-headers") {
{ header = split(trim(y), ":");
headers = split(itemVal, "|"); if(regMatch(header[0], "(?i)host"))
for(auto &y : headers) host = trim_quote(header[1]);
{ else if(regMatch(header[0], "(?i)edge"))
header = split(trim(y), ":"); edge = trim_quote(header[1]);
if(regMatch(header[0], "(?i)host")) }
host = trim_quote(header[1]); break;
else if(regMatch(header[0], "(?i)edge")) default: continue;
edge = trim_quote(header[1]);
}
} }
} }
if(host.empty() && !isIPv4(server) && !isIPv6(server)) if(host.empty() && !isIPv4(server) && !isIPv6(server))
@@ -1279,7 +1278,10 @@ bool explodeSurge(std::string surge, const std::string &custom_port, int local_p
if(itemName == "password") if(itemName == "password")
password = itemVal; password = itemVal;
} }
node.proxyStr = trojanConstruct(remarks, server, port, password); if(host.empty() && !isIPv4(server) && !isIPv6(server))
host = server;
node.proxyStr = trojanConstruct(remarks, server, port, password, host, false);
} }
else if(remarks == "shadowsocks") //quantumult x style ss/ssr link else if(remarks == "shadowsocks") //quantumult x style ss/ssr link
{ {
@@ -1293,23 +1295,20 @@ bool explodeSurge(std::string surge, const std::string &custom_port, int local_p
continue; continue;
itemName = trim(vArray[0]); itemName = trim(vArray[0]);
itemVal = trim(vArray[1]); itemVal = trim(vArray[1]);
if(itemName == "method") switch(hash_(itemName))
method = itemVal;
else if(itemName == "password")
password = itemVal;
else if(itemName == "tag")
remarks = itemVal;
else if(itemName == "ssr-protocol")
protocol = itemVal;
else if(itemName == "ssr-protocol-param")
protoparam = itemVal;
else if(itemName == "obfs")
{ {
plugin = "simple-obfs"; case "method"_hash: method = itemVal; break;
pluginopts_mode = itemVal; case "password"_hash: id = itemVal; break;
case "tag"_hash: remarks = itemVal; break;
case "ssr-protocol"_hash: protocol = itemVal; break;
case "ssr-protocol-param"_hash: protoparam = itemVal; break;
case "obfs"_hash:
plugin = "simple-obfs";
pluginopts_mode = itemVal;
break;
case "obfs-host"_hash: pluginopts_host = itemVal; break;
default: continue;
} }
else if(itemName == "obfs-host")
pluginopts_host = itemVal;
} }
if(remarks.empty()) if(remarks.empty())
remarks = server + ":" + port; remarks = server + ":" + port;
@@ -1346,25 +1345,23 @@ bool explodeSurge(std::string surge, const std::string &custom_port, int local_p
continue; continue;
itemName = trim(vArray[0]); itemName = trim(vArray[0]);
itemVal = trim(vArray[1]); itemVal = trim(vArray[1]);
if(itemName == "method") switch(hash_(itemName))
method = itemVal;
else if(itemName == "password")
id = itemVal;
else if(itemName == "tag")
remarks = itemVal;
else if(itemName == "obfs")
{ {
if(itemVal == "ws") case "method"_hash: method = itemVal; break;
net = "ws"; case "password"_hash: id = itemVal; break;
else if(itemVal == "over-tls") case "tag"_hash: remarks = itemVal; break;
tls = "tls"; case "obfs"_hash:
switch(hash_(itemVal))
{
case "ws"_hash: net = "ws"; break;
case "over-tls"_hash: tls = "tls"; break;
}
break;
case "obfs-host"_hash: host = itemVal; break;
case "obfs-uri"_hash: path = itemVal; break;
case "over-tls"_hash: tls = itemVal == "true" ? "tls" : ""; break;
default: continue;
} }
else if(itemName == "obfs-host")
host = itemVal;
else if(itemName == "obfs-uri")
path = itemVal;
else if(itemName == "over-tls")
tls = itemVal == "true" ? "tls" : "";
} }
if(remarks.empty()) if(remarks.empty())
remarks = server + ":" + port; remarks = server + ":" + port;
@@ -1376,6 +1373,37 @@ bool explodeSurge(std::string surge, const std::string &custom_port, int local_p
node.group = V2RAY_DEFAULT_GROUP; node.group = V2RAY_DEFAULT_GROUP;
node.proxyStr = vmessConstruct(server, port, "", id, "0", net, method, path, host, "", tls, local_port); node.proxyStr = vmessConstruct(server, port, "", id, "0", net, method, path, host, "", tls, local_port);
} }
else if(remarks == "trojan") //quantumult x style trojan link
{
server = trim(configs[0].substr(0, configs[0].rfind(":")));
port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port;
for(i = 1; i < configs.size(); i++)
{
vArray = split(trim(configs[i]), "=");
if(vArray.size() != 2)
continue;
itemName = trim(vArray[0]);
itemVal = trim(vArray[1]);
switch(hash_(itemName))
{
case "password"_hash: password = itemVal; break;
case "tag"_hash: remarks = itemVal; break;
case "over-tls"_hash: tls = itemVal; break;
case "tls-host"_hash: host = itemVal; break;
default: continue;
}
}
if(remarks.empty())
remarks = server + ":" + port;
if(host.empty() && !isIPv4(server) && !isIPv6(server))
host = server;
node.linkType = SPEEDTEST_MESSAGE_FOUNDTROJAN;
node.group = TROJAN_DEFAULT_GROUP;
node.proxyStr = trojanConstruct(remarks, server, port, password, host, tls == "true");
}
else else
continue; continue;
+1 -1
View File
@@ -12,7 +12,7 @@ std::string ssrConstruct(std::string group, std::string remarks, std::string rem
std::string ssConstruct(std::string server, std::string port, std::string password, std::string method, std::string plugin, std::string pluginopts, std::string remarks, int local_port, bool libev); std::string ssConstruct(std::string server, std::string port, std::string password, std::string method, std::string plugin, std::string pluginopts, std::string remarks, int local_port, bool libev);
std::string socksConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password); std::string socksConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password);
std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password, bool tls = false); std::string httpConstruct(std::string remarks, std::string server, std::string port, std::string username, std::string password, bool tls = false);
std::string trojanConstruct(std::string remarks, std::string server, std::string port, std::string password); std::string trojanConstruct(std::string remarks, std::string server, std::string port, std::string password, std::string host, bool tlssecure);
void explodeVmess(std::string vmess, const std::string &custom_port, int local_port, nodeInfo &node); void explodeVmess(std::string vmess, const std::string &custom_port, int local_port, nodeInfo &node);
void explodeSSR(std::string ssr, bool ss_libev, bool libev, const std::string &custom_port, int local_port, nodeInfo &node); void explodeSSR(std::string ssr, bool ss_libev, bool libev, const std::string &custom_port, int local_port, nodeInfo &node);
void explodeSS(std::string ss, bool libev, const std::string &custom_port, int local_port, nodeInfo &node); void explodeSS(std::string ss, bool libev, const std::string &custom_port, int local_port, nodeInfo &node);
+59 -227
View File
@@ -215,7 +215,7 @@ std::string httpConstruct(std::string remarks, std::string server, std::string p
return sb.GetString(); return sb.GetString();
} }
std::string trojanConstruct(std::string remarks, std::string server, std::string port, std::string password) std::string trojanConstruct(std::string remarks, std::string server, std::string port, std::string password, std::string host, bool tlssecure)
{ {
rapidjson::StringBuffer sb; rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb); rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
@@ -230,6 +230,10 @@ std::string trojanConstruct(std::string remarks, std::string server, std::string
writer.Int(to_int(port)); writer.Int(to_int(port));
writer.Key("Password"); writer.Key("Password");
writer.String(password.data()); writer.String(password.data());
writer.Key("Host");
writer.String(host.data());
writer.Key("TLSSecure");
writer.Bool(tlssecure);
writer.EndObject(); writer.EndObject();
return sb.GetString(); return sb.GetString();
} }
@@ -674,18 +678,8 @@ void groupGenerate(std::string &rule, std::vector<nodeInfo> &nodelist, std::vect
} }
} }
void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_array &extra_proxy_group, bool clashR, extra_settings &ext) void preprocessNodes(std::vector<nodeInfo> &nodes, extra_settings &ext)
{ {
YAML::Node proxies, singleproxy, singlegroup, original_groups;
rapidjson::Document json;
std::string type, remark, hostname, port, username, password, method;
std::string plugin, pluginopts;
std::string protocol, protoparam, obfs, obfsparam;
std::string id, aid, transproto, faketype, host, edge, path, quicsecure, quicsecret;
std::vector<nodeInfo> nodelist;
bool tlssecure, replace_flag;
string_array vArray, remarks_list, filtered_nodelist;
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x) std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{ {
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array); x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
@@ -703,6 +697,19 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
return a.remarks < b.remarks; return a.remarks < b.remarks;
}); });
} }
}
void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_array &extra_proxy_group, bool clashR, extra_settings &ext)
{
YAML::Node proxies, singleproxy, singlegroup, original_groups;
rapidjson::Document json;
std::string type, remark, hostname, port, username, password, method;
std::string plugin, pluginopts;
std::string protocol, protoparam, obfs, obfsparam;
std::string id, aid, transproto, faketype, host, edge, path, quicsecure, quicsecret;
std::vector<nodeInfo> nodelist;
bool tlssecure, replace_flag;
string_array vArray, remarks_list, filtered_nodelist;
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
@@ -740,14 +747,15 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
singleproxy["password"] = password; singleproxy["password"] = password;
if(std::all_of(password.begin(), password.end(), ::isdigit)) if(std::all_of(password.begin(), password.end(), ::isdigit))
singleproxy["password"].SetTag("str"); singleproxy["password"].SetTag("str");
if(plugin == "simple-obfs" || plugin == "obfs-local") switch(hash_(plugin))
{ {
case "simple-obfs"_hash:
case "obfs-local"_hash:
singleproxy["plugin"] = "obfs"; singleproxy["plugin"] = "obfs";
singleproxy["plugin-opts"]["mode"] = UrlDecode(getUrlArg(pluginopts, "obfs")); singleproxy["plugin-opts"]["mode"] = UrlDecode(getUrlArg(pluginopts, "obfs"));
singleproxy["plugin-opts"]["host"] = UrlDecode(getUrlArg(pluginopts, "obfs-host")); singleproxy["plugin-opts"]["host"] = UrlDecode(getUrlArg(pluginopts, "obfs-host"));
} break;
else if(plugin == "v2ray-plugin") case "v2ray-plugin"_hash:
{
singleproxy["plugin"] = "v2ray-plugin"; singleproxy["plugin"] = "v2ray-plugin";
singleproxy["plugin-opts"]["mode"] = getUrlArg(pluginopts, "mode"); singleproxy["plugin-opts"]["mode"] = getUrlArg(pluginopts, "mode");
singleproxy["plugin-opts"]["host"] = getUrlArg(pluginopts, "host"); singleproxy["plugin-opts"]["host"] = getUrlArg(pluginopts, "host");
@@ -756,6 +764,7 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
singleproxy["plugin-opts"]["mux"] = pluginopts.find("mux") != pluginopts.npos; singleproxy["plugin-opts"]["mux"] = pluginopts.find("mux") != pluginopts.npos;
if(ext.skip_cert_verify) if(ext.skip_cert_verify)
singleproxy["plugin-opts"]["skip-cert-verify"] = true; singleproxy["plugin-opts"]["skip-cert-verify"] = true;
break;
} }
break; break;
case SPEEDTEST_MESSAGE_FOUNDVMESS: case SPEEDTEST_MESSAGE_FOUNDVMESS:
@@ -773,8 +782,11 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
singleproxy["tls"] = tlssecure; singleproxy["tls"] = tlssecure;
if(ext.skip_cert_verify) if(ext.skip_cert_verify)
singleproxy["skip-cert-verify"] = true; singleproxy["skip-cert-verify"] = true;
if(transproto == "ws") switch(hash_(transproto))
{ {
case "tcp"_hash:
break;
case "ws"_hash:
singleproxy["network"] = transproto; singleproxy["network"] = transproto;
singleproxy["ws-path"] = path; singleproxy["ws-path"] = path;
singleproxy["ws-headers"]["Host"] = host; singleproxy["ws-headers"]["Host"] = host;
@@ -784,9 +796,10 @@ void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_arr
singleproxy["ws-headers"]["Edge"] = edge; singleproxy["ws-headers"]["Edge"] = edge;
singleproxy["headers"]["Edge"] = edge; singleproxy["headers"]["Edge"] = edge;
} }
} break;
else if(transproto == "kcp" || transproto == "h2" || transproto == "quic") default:
continue; continue;
}
break; break;
case SPEEDTEST_MESSAGE_FOUNDSSR: case SPEEDTEST_MESSAGE_FOUNDSSR:
if(!clashR) if(!clashR)
@@ -973,24 +986,6 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
ini.EraseSection(); ini.EraseSection();
ini.Set("{NONAME}", "DIRECT = direct"); ini.Set("{NONAME}", "DIRECT = direct");
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -1038,16 +1033,20 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
path = GetMember(json, "Path"); path = GetMember(json, "Path");
tlssecure = GetMember(json, "TLSSecure") == "true"; tlssecure = GetMember(json, "TLSSecure") == "true";
proxy = "vmess, " + hostname + ", " + port + ", username=" + id + ", tls=" + (tlssecure ? "true" : "false"); proxy = "vmess, " + hostname + ", " + port + ", username=" + id + ", tls=" + (tlssecure ? "true" : "false");
if(transproto == "ws") switch(hash_(transproto))
{ {
case "tcp"_hash:
break;
case "ws"_hash:
proxy += ", ws=true, ws-path=" + path + ", ws-headers=Host:" + host; proxy += ", ws=true, ws-path=" + path + ", ws-headers=Host:" + host;
if(edge.size()) if(edge.size())
proxy += "|Edge:" + edge; proxy += "|Edge:" + edge;
break;
default:
continue;
} }
if(ext.skip_cert_verify) if(ext.skip_cert_verify)
proxy += ", skip-cert-verify=1"; proxy += ", skip-cert-verify=1";
else if(transproto == "kcp" || transproto == "h2" || transproto == "quic")
continue;
break; break;
case SPEEDTEST_MESSAGE_FOUNDSSR: case SPEEDTEST_MESSAGE_FOUNDSSR:
if(ext.surge_ssr_path.empty() || surge_ver < 2) if(ext.surge_ssr_path.empty() || surge_ver < 2)
@@ -1191,24 +1190,6 @@ std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext)
std::string protocol, protoparam, obfs, obfsparam; std::string protocol, protoparam, obfs, obfsparam;
std::string proxyStr, allLinks; std::string proxyStr, allLinks;
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -1262,25 +1243,6 @@ std::string netchToSSSub(std::vector<nodeInfo> &nodes, extra_settings &ext)
int port; int port;
writer.StartArray(); writer.StartArray();
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -1336,24 +1298,6 @@ std::string netchToSSR(std::vector<nodeInfo> &nodes, extra_settings &ext)
std::string protocol, protoparam, obfs, obfsparam; std::string protocol, protoparam, obfs, obfsparam;
std::string proxyStr, allLinks; std::string proxyStr, allLinks;
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -1397,24 +1341,6 @@ std::string netchToVMess(std::vector<nodeInfo> &nodes, extra_settings &ext)
std::string proxyStr, allLinks; std::string proxyStr, allLinks;
bool tlssecure; bool tlssecure;
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -1451,24 +1377,6 @@ std::string netchToTrojan(std::vector<nodeInfo> &nodes, extra_settings &ext)
std::string server, port, psk, remark; std::string server, port, psk, remark;
std::string proxyStr, allLinks; std::string proxyStr, allLinks;
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -1529,24 +1437,6 @@ void netchToQuan(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rules
std::vector<nodeInfo> nodelist; std::vector<nodeInfo> nodelist;
string_array remarks_list; string_array remarks_list;
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
ini.SetCurrentSection("SERVER"); ini.SetCurrentSection("SERVER");
ini.EraseSection(); ini.EraseSection();
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
@@ -1755,24 +1645,6 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
std::vector<nodeInfo> nodelist; std::vector<nodeInfo> nodelist;
string_array remarks_list; string_array remarks_list;
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
ini.SetCurrentSection("server_local"); ini.SetCurrentSection("server_local");
ini.EraseSection(); ini.EraseSection();
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
@@ -1835,6 +1707,17 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
if(obfsparam.size()) if(obfsparam.size())
proxyStr += ", obfs-host=" + obfsparam; proxyStr += ", obfs-host=" + obfsparam;
break; break;
case SPEEDTEST_MESSAGE_FOUNDTROJAN:
password = GetMember(json, "Password");
host = GetMember(json, "Host");
tlssecure = GetMember(json, "TLSSecure") == "true";
proxyStr = "trojan = " + hostname + ":" + port + ", password=" + password;
if(tlssecure)
{
proxyStr += ", over-tls=true, tls-host=" + host;
}
break;
default: default:
continue; continue;
} }
@@ -2033,24 +1916,6 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, std::st
writer.Key("servers"); writer.Key("servers");
writer.StartArray(); writer.StartArray();
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -2148,24 +2013,6 @@ void netchToMellow(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rul
ini.SetCurrentSection("Endpoint"); ini.SetCurrentSection("Endpoint");
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -2319,24 +2166,6 @@ std::string netchToLoon(std::vector<nodeInfo> &nodes, std::string &base_conf, st
ini.SetCurrentSection("Proxy"); ini.SetCurrentSection("Proxy");
ini.EraseSection(); ini.EraseSection();
std::for_each(nodes.begin(), nodes.end(), [ext](nodeInfo &x)
{
x.remarks = nodeRename(x.remarks, x.groupID, ext.rename_array);
if(ext.remove_emoji)
x.remarks = trim(removeEmoji(x.remarks));
if(ext.add_emoji)
x.remarks = addEmoji(x.remarks, x.groupID, ext.emoji_array);
});
if(ext.sort_flag)
{
std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
}
for(nodeInfo &x : nodes) for(nodeInfo &x : nodes)
{ {
json.Parse(x.proxyStr.data()); json.Parse(x.proxyStr.data());
@@ -2386,14 +2215,17 @@ std::string netchToLoon(std::vector<nodeInfo> &nodes, std::string &base_conf, st
proxy = "vmess," + hostname + "," + port + "," + method + ",\"" + id + "\",over-tls:" + (tlssecure ? "true" : "false"); proxy = "vmess," + hostname + "," + port + "," + method + ",\"" + id + "\",over-tls:" + (tlssecure ? "true" : "false");
if(tlssecure) if(tlssecure)
proxy += ",tls-name:" + host; proxy += ",tls-name:" + host;
if(transproto == "ws") switch(hash_(transproto))
{ {
proxy += ",transport:ws,path:" + path + ",host:" + host; case "tcp"_hash:
}
else if(transproto == "kcp" || transproto == "h2" || transproto == "quic")
continue;
else
proxy += ",transport:tcp"; proxy += ",transport:tcp";
break;
case "ws"_hash:
proxy += ",transport:ws,path:" + path + ",host:" + host;
break;
default:
continue;
}
if(ext.skip_cert_verify) if(ext.skip_cert_verify)
proxy += ",skip-cert-verify:1"; proxy += ",skip-cert-verify:1";
break; break;
+3
View File
@@ -37,6 +37,8 @@ struct extra_settings
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules); void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array, bool overwrite_original_rules);
void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_content_array, int surge_ver, bool overwrite_original_rules, std::string remote_path_prefix); void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_content_array, int surge_ver, bool overwrite_original_rules, std::string remote_path_prefix);
void preprocessNodes(std::vector<nodeInfo> &nodes, extra_settings &ext);
std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, bool clashR, extra_settings &ext); std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, bool clashR, extra_settings &ext);
void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_array &extra_proxy_group, bool clashR, extra_settings &ext); void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, string_array &extra_proxy_group, bool clashR, extra_settings &ext);
std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, int surge_ver, extra_settings &ext); std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, int surge_ver, extra_settings &ext);
@@ -53,6 +55,7 @@ void netchToQuanX(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<rule
std::string netchToQuan(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext); std::string netchToQuan(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
void netchToQuan(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext); void netchToQuan(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, std::string &userinfo, extra_settings &ext); std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, std::string &userinfo, extra_settings &ext);
std::string buildGistData(std::string name, std::string content); std::string buildGistData(std::string name, std::string content);
int uploadGist(std::string name, std::string path, std::string content, bool writeManageURL); int uploadGist(std::string name, std::string path, std::string content, bool writeManageURL);