This commit is contained in:
asdlokj1qpi23 committed 2025-03-25 16:41:46 +08:00
1 parent 3ea867e4b8
commit ffbd262aae
2 files changed
+85 -62

No files matched your search

+84 -61
View File
@@ -25,12 +25,18 @@
extern string_array ss_ciphers, ssr_ciphers;
const string_array clashr_protocols = {"origin", "auth_sha1_v4", "auth_aes128_md5", "auth_aes128_sha1", "auth_chain_a",
"auth_chain_b"};
const string_array clashr_obfs = {"plain", "http_simple", "http_post", "random_head", "tls1.2_ticket_auth",
"tls1.2_ticket_fastauth"};
const string_array clash_ssr_ciphers = {"rc4-md5", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb",
"aes-192-cfb", "aes-256-cfb", "chacha20-ietf", "xchacha20", "none"};
const string_array clashr_protocols = {
"origin", "auth_sha1_v4", "auth_aes128_md5", "auth_aes128_sha1", "auth_chain_a",
"auth_chain_b"
};
const string_array clashr_obfs = {
"plain", "http_simple", "http_post", "random_head", "tls1.2_ticket_auth",
"tls1.2_ticket_fastauth"
};
const string_array clash_ssr_ciphers = {
"rc4-md5", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb",
"aes-192-cfb", "aes-256-cfb", "chacha20-ietf", "xchacha20", "none"
};
std::string
vmessLinkConstruct(const std::string &remarks, const std::string &add, const std::string &port, const std::string &type,
@@ -70,7 +76,8 @@ bool matchRange(const std::string &range, int target) {
bool match = false;
std::string range_begin_str, range_end_str;
int range_begin, range_end;
static const std::string reg_num = "-?\\d+", reg_range = "(\\d+)-(\\d+)", reg_not = "\\!-?(\\d+)", reg_not_range = "\\!(\\d+)-(\\d+)", reg_less = "(\\d+)-", reg_more = "(\\d+)\\+";
static const std::string reg_num = "-?\\d+", reg_range = "(\\d+)-(\\d+)", reg_not = "\\!-?(\\d+)", reg_not_range =
"\\!(\\d+)-(\\d+)", reg_less = "(\\d+)-", reg_more = "(\\d+)\\+";
for (std::string &x: vArray) {
if (regMatch(x, reg_num)) {
if (to_int(x, INT_MAX) == target)
@@ -105,9 +112,12 @@ bool matchRange(const std::string &range, int target) {
bool applyMatcher(const std::string &rule, std::string &real_rule, const Proxy &node) {
std::string target, ret_real_rule;
static const std::string groupid_regex = R"(^!!(?:GROUPID|INSERT)=([\d\-+!,]+)(?:!!(.*))?$)", group_regex = R"(^!!(?:GROUP)=(.+?)(?:!!(.*))?$)";
static const std::string type_regex = R"(^!!(?:TYPE)=(.+?)(?:!!(.*))?$)", port_regex = R"(^!!(?:PORT)=(.+?)(?:!!(.*))?$)", server_regex = R"(^!!(?:SERVER)=(.+?)(?:!!(.*))?$)";
static const std::map<ProxyType, const char *> types = {{ProxyType::Shadowsocks, "SS"},
static const std::string groupid_regex = R"(^!!(?:GROUPID|INSERT)=([\d\-+!,]+)(?:!!(.*))?$)", group_regex =
R"(^!!(?:GROUP)=(.+?)(?:!!(.*))?$)";
static const std::string type_regex = R"(^!!(?:TYPE)=(.+?)(?:!!(.*))?$)", port_regex =
R"(^!!(?:PORT)=(.+?)(?:!!(.*))?$)", server_regex = R"(^!!(?:SERVER)=(.+?)(?:!!(.*))?$)";
static const std::map<ProxyType, const char *> types = {
{ProxyType::Shadowsocks, "SS"},
{ProxyType::ShadowsocksR, "SSR"},
{ProxyType::VMess, "VMESS"},
{ProxyType::Trojan, "TROJAN"},
@@ -118,7 +128,8 @@ bool applyMatcher(const std::string &rule, std::string &real_rule, const Proxy &
{ProxyType::WireGuard, "WIREGUARD"},
{ProxyType::VLESS, "VLESS"},
{ProxyType::Hysteria, "HYSTERIA"},
{ProxyType::Hysteria2, "HYSTERIA2"}};
{ProxyType::Hysteria2, "HYSTERIA2"}
};
if (startsWith(rule, "!!GROUP=")) {
regGetMatch(rule, group_regex, 3, 0, &target, &ret_real_rule);
real_rule = ret_real_rule;
@@ -184,8 +195,7 @@ groupGenerate(const std::string &rule, std::vector<Proxy> &nodelist, string_arra
auto filter = (std::function<std::string(const std::vector<Proxy> &)>) ctx.eval("filter");
std::string result_list = filter(nodelist);
filtered_nodelist = split(regTrim(result_list), "\n");
}
catch (qjs::exception) {
} catch (qjs::exception) {
script_print_stack(ctx);
}
}, global.scriptCleanContext);
@@ -207,17 +217,7 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
std::vector<Proxy> nodelist;
string_array remarks_list;
/// proxies style
bool block = false, compact = false;
switch (hash_(ext.clash_proxies_style)) {
case "block"_hash:
block = true;
break;
default:
case "flow"_hash:
break;
case "compact"_hash:
compact = true;
break;
bool proxy_block = false, proxy_compact = false, group_block = false, group_compact = false;
switch (hash_(ext.clash_proxies_style)) {
case "block"_hash:
@@ -637,7 +637,7 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
// sees in https://dreamacro.github.io/clash/configuration/outbound.html#snell
if (udp && x.Type != ProxyType::Snell && x.Type != ProxyType::TUIC)
singleproxy["udp"] = true;
if (block)
if(proxy_block)
singleproxy.SetStyle(YAML::EmitterStyle::Block);
else
singleproxy.SetStyle(YAML::EmitterStyle::Flow);
@@ -646,7 +646,7 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
nodelist.emplace_back(x);
}
if (compact)
if(proxy_compact)
proxies.SetStyle(YAML::EmitterStyle::Flow);
if (ext.nodelist) {
@@ -753,9 +753,9 @@ proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGroupCo
else
yamlnode["Proxy Group"] = original_groups;
}
}
}
void formatterShortId(std::string &input) {
std::string target = "short-id:";
size_t startPos = input.find(target);
@@ -781,7 +781,6 @@ void formatterShortId(std::string &input) {
// 继续查找下一个实例
startPos = input.find(target, startPos + 1);
}
}
std::string proxyToClash(std::vector<Proxy> &nodes, const std::string &base_conf,
@@ -792,8 +791,7 @@ std::string proxyToClash(std::vector<Proxy> &nodes, const std::string &base_conf
try {
yamlnode = YAML::Load(base_conf);
}
catch (std::exception &e) {
} catch (std::exception &e) {
writeLog(0, std::string("Clash base loader failed with error: ") + e.what(), LOG_LEVEL_ERROR);
return "";
}
@@ -897,7 +895,10 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
processRemark(x.Remark, remarks_list);
std::string &hostname = x.Hostname, &sni = x.ServerName, &username = x.Username, &password = x.Password, &method = x.EncryptMethod, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &edge = x.Edge, &path = x.Path, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &plugin = x.Plugin, &pluginopts = x.PluginOption, &underlying_proxy = x.UnderlyingProxy;
std::string &hostname = x.Hostname, &sni = x.ServerName, &username = x.Username, &password = x.Password, &method
= x.EncryptMethod, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &edge = x.Edge, &
path = x.Path, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.
OBFSParam, &plugin = x.Plugin, &pluginopts = x.PluginOption, &underlying_proxy = x.UnderlyingProxy;
std::string port = std::to_string(x.Port);;
bool &tlssecure = x.TLSSecure;
@@ -963,8 +964,10 @@ std::string proxyToSurge(std::vector<Proxy> &nodes, const std::string &base_conf
if (ext.surge_ssr_path.empty() || surge_ver < 2)
continue;
proxy = "external, exec=\"" + ext.surge_ssr_path + "\", args=\"";
args = {"-l", std::to_string(local_port), "-s", hostname, "-p", port, "-m", method, "-k", password,
"-o", obfs, "-O", protocol};
args = {
"-l", std::to_string(local_port), "-s", hostname, "-p", port, "-m", method, "-k", password,
"-o", obfs, "-O", protocol
};
if (!obfsparam.empty()) {
args.emplace_back("-g");
args.emplace_back(std::move(obfsparam));
@@ -1164,7 +1167,12 @@ std::string proxyToSingle(std::vector<Proxy> &nodes, int types, extra_settings &
for (Proxy &x: nodes) {
std::string remark = x.Remark;
std::string &hostname = x.Hostname, &sni = x.ServerName, &password = x.Password, &method = x.EncryptMethod, &plugin = x.Plugin, &pluginopts = x.PluginOption, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &path = x.Path, &faketype = x.FakeType;
std::string &hostname = x.Hostname, &sni = x.ServerName, &password = x.Password, &method = x.EncryptMethod, &
plugin = x.Plugin, &pluginopts = x.PluginOption, &protocol = x.Protocol, &protoparam = x.
ProtocolParam,
&obfs = x.OBFS, &obfsparam = x.OBFSParam, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.
Host, &
path = x.Path, &faketype = x.FakeType;
bool &tlssecure = x.TLSSecure;
std::string port = std::to_string(x.Port);
std::string aid = std::to_string(x.AlterId);
@@ -1182,8 +1190,9 @@ std::string proxyToSingle(std::vector<Proxy> &nodes, int types, extra_settings &
plugin.empty())
proxyStr = "ssr://" + urlSafeBase64Encode(
hostname + ":" + port + ":origin:" + method + ":plain:" +
urlSafeBase64Encode(password) \
+ "/?group=" + urlSafeBase64Encode(x.Group) + "&remarks=" + urlSafeBase64Encode(remark));
urlSafeBase64Encode(password)
+ "/?group=" + urlSafeBase64Encode(x.Group) + "&remarks=" + urlSafeBase64Encode(
remark));
} else
continue;
break;
@@ -1191,9 +1200,11 @@ std::string proxyToSingle(std::vector<Proxy> &nodes, int types, extra_settings &
if (ssr) {
proxyStr = "ssr://" + urlSafeBase64Encode(
hostname + ":" + port + ":" + protocol + ":" + method + ":" + obfs + ":" +
urlSafeBase64Encode(password) \
+ "/?group=" + urlSafeBase64Encode(x.Group) + "&remarks=" + urlSafeBase64Encode(remark) \
+ "&obfsparam=" + urlSafeBase64Encode(obfsparam) + "&protoparam=" + urlSafeBase64Encode(protoparam));
urlSafeBase64Encode(password)
+ "/?group=" + urlSafeBase64Encode(x.Group) + "&remarks=" + urlSafeBase64Encode(
remark)
+ "&obfsparam=" + urlSafeBase64Encode(obfsparam) + "&protoparam=" +
urlSafeBase64Encode(protoparam));
} else if (ss) {
if (std::find(ss_ciphers.begin(), ss_ciphers.end(), method) != ss_ciphers.end() &&
protocol == "origin" && obfs == "plain")
@@ -1333,7 +1344,12 @@ void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetC
processRemark(x.Remark, remarks_list);
std::string &hostname = x.Hostname, &method = x.EncryptMethod, &password = x.Password, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &path = x.Path, &edge = x.Edge, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &plugin = x.Plugin, &pluginopts = x.PluginOption, &username = x.Username;
std::string &hostname = x.Hostname, &method = x.EncryptMethod, &password = x.Password, &id = x.UserId, &
transproto = x.TransferProtocol, &host = x.Host, &path = x.Path, &edge = x.Edge, &protocol = x.
Protocol,
&protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &plugin = x.Plugin, &pluginopts
= x.
PluginOption, &username = x.Username;
std::string port = std::to_string(x.Port);
bool &tlssecure = x.TLSSecure;
tribool scv;
@@ -1368,9 +1384,11 @@ void proxyToQuan(std::vector<Proxy> &nodes, INIReader &ini, std::vector<RulesetC
if (ext.nodelist) {
proxyStr = "ssr://" + urlSafeBase64Encode(
hostname + ":" + port + ":" + protocol + ":" + method + ":" + obfs + ":" +
urlSafeBase64Encode(password) \
+ "/?group=" + urlSafeBase64Encode(x.Group) + "&remarks=" + urlSafeBase64Encode(x.Remark) \
+ "&obfsparam=" + urlSafeBase64Encode(obfsparam) + "&protoparam=" + urlSafeBase64Encode(protoparam));
urlSafeBase64Encode(password)
+ "/?group=" + urlSafeBase64Encode(x.Group) + "&remarks=" + urlSafeBase64Encode(
x.Remark)
+ "&obfsparam=" + urlSafeBase64Encode(obfsparam) + "&protoparam=" +
urlSafeBase64Encode(protoparam));
} else {
proxyStr = x.Remark + " = shadowsocksr, " + hostname + ", " + port + ", " + method + ", \"" +
password + "\", group=" + x.Group + ", protocol=" + protocol + ", obfs=" + obfs;
@@ -1562,7 +1580,10 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
processRemark(x.Remark, remarks_list);
std::string &hostname = x.Hostname, &method = x.EncryptMethod, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &path = x.Path, &password = x.Password, &plugin = x.Plugin, &pluginopts = x.PluginOption, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &username = x.Username;
std::string &hostname = x.Hostname, &method = x.EncryptMethod, &id = x.UserId, &transproto = x.TransferProtocol,
&host = x.Host, &path = x.Path, &password = x.Password, &plugin = x.Plugin, &pluginopts = x.PluginOption
, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam, &
username = x.Username;
std::string port = std::to_string(x.Port);
bool &tlssecure = x.TLSSecure;
@@ -1827,7 +1848,8 @@ std::string proxyToSSD(std::vector<Proxy> &nodes, std::string &group, std::strin
writer.StartArray();
for (Proxy &x: nodes) {
std::string &hostname = x.Hostname, &password = x.Password, &method = x.EncryptMethod, &plugin = x.Plugin, &pluginopts = x.PluginOption, &protocol = x.Protocol, &obfs = x.OBFS;
std::string &hostname = x.Hostname, &password = x.Password, &method = x.EncryptMethod, &plugin = x.Plugin, &
pluginopts = x.PluginOption, &protocol = x.Protocol, &obfs = x.OBFS;
switch (x.Type) {
case ProxyType::Shadowsocks:
@@ -2062,7 +2084,10 @@ proxyToLoon(std::vector<Proxy> &nodes, const std::string &base_conf,
}
processRemark(x.Remark, remarks_list);
std::string &hostname = x.Hostname, &username = x.Username, &password = x.Password, &method = x.EncryptMethod, &plugin = x.Plugin, &pluginopts = x.PluginOption, &id = x.UserId, &transproto = x.TransferProtocol, &host = x.Host, &path = x.Path, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &obfsparam = x.OBFSParam;
std::string &hostname = x.Hostname, &username = x.Username, &password = x.Password, &method = x.EncryptMethod, &
plugin = x.Plugin, &pluginopts = x.PluginOption, &id = x.UserId, &transproto = x.TransferProtocol, &host
= x.Host, &path = x.Path, &protocol = x.Protocol, &protoparam = x.ProtocolParam, &obfs = x.OBFS, &
obfsparam = x.OBFSParam;
std::string port = std::to_string(x.Port), aid = std::to_string(x.AlterId);
bool &tlssecure = x.TLSSecure;
@@ -2430,16 +2455,16 @@ proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json,
}
break;
}
// case ProxyType::ShadowsocksR: {
// addSingBoxCommonMembers(proxy, x, "shadowsocksr", allocator);
// proxy.AddMember("method", rapidjson::StringRef(x.EncryptMethod.c_str()), allocator);
// proxy.AddMember("password", rapidjson::StringRef(x.Password.c_str()), allocator);
// proxy.AddMember("protocol", rapidjson::StringRef(x.Protocol.c_str()), allocator);
// proxy.AddMember("protocol_param", rapidjson::StringRef(x.ProtocolParam.c_str()), allocator);
// proxy.AddMember("obfs", rapidjson::StringRef(x.OBFS.c_str()), allocator);
// proxy.AddMember("obfs_param", rapidjson::StringRef(x.OBFSParam.c_str()), allocator);
// break;
// }
// case ProxyType::ShadowsocksR: {
// addSingBoxCommonMembers(proxy, x, "shadowsocksr", allocator);
// proxy.AddMember("method", rapidjson::StringRef(x.EncryptMethod.c_str()), allocator);
// proxy.AddMember("password", rapidjson::StringRef(x.Password.c_str()), allocator);
// proxy.AddMember("protocol", rapidjson::StringRef(x.Protocol.c_str()), allocator);
// proxy.AddMember("protocol_param", rapidjson::StringRef(x.ProtocolParam.c_str()), allocator);
// proxy.AddMember("obfs", rapidjson::StringRef(x.OBFS.c_str()), allocator);
// proxy.AddMember("obfs_param", rapidjson::StringRef(x.OBFSParam.c_str()), allocator);
// break;
// }
case ProxyType::VMess: {
addSingBoxCommonMembers(proxy, x, "vmess", allocator);
proxy.AddMember("uuid", rapidjson::StringRef(x.UserId.c_str()), allocator);
@@ -2519,8 +2544,8 @@ proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json,
proxy.AddMember("inet4_bind_address", rapidjson::StringRef(x.SelfIP.c_str()), allocator);
rapidjson::Value addresses(rapidjson::kArrayType);
addresses.PushBack(rapidjson::StringRef(x.SelfIP.append("/32").c_str()), allocator);
// if (!x.SelfIPv6.empty())
// addresses.PushBack(rapidjson::StringRef(x.SelfIPv6.c_str()), allocator);
// if (!x.SelfIPv6.empty())
// addresses.PushBack(rapidjson::StringRef(x.SelfIPv6.c_str()), allocator);
proxy.AddMember("local_address", addresses, allocator);
if (!x.SelfIPv6.empty())
proxy.AddMember("inet6_bind_address", rapidjson::StringRef(x.SelfIPv6.c_str()), allocator);
@@ -2608,7 +2633,6 @@ proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json,
addSingBoxCommonMembers(proxy, x, "hysteria2", allocator);
proxy.AddMember("password", rapidjson::StringRef(x.Password.c_str()), allocator);
if (!x.TLSSecure) {
rapidjson::Value tls(rapidjson::kObjectType);
tls.AddMember("enabled", true, allocator);
if (!x.ServerName.empty())
@@ -2648,7 +2672,6 @@ proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json,
obfs.AddMember("password", rapidjson::StringRef(x.OBFSPassword.c_str()), allocator);
}
proxy.AddMember("obfs", obfs, allocator);
}
break;
}
@@ -2712,7 +2735,7 @@ proxyToSingBox(std::vector<Proxy> &nodes, rapidjson::Document &json,
if (!x.PublicKey.empty()) {
reality.AddMember("public_key", rapidjson::StringRef(x.PublicKey.c_str()), allocator);
}
// auto shortIds = stringArrayToJsonArray(x.ShortId, ",", allocator);
// auto shortIds = stringArrayToJsonArray(x.ShortId, ",", allocator);
if (!x.ShortId.empty()) {
reality.AddMember("short_id", rapidjson::StringRef(x.ShortId.c_str()), allocator);
} else {
+1 -1
View File
@@ -1583,7 +1583,7 @@ void explodeStdVless(std::string vless, Proxy &node) {
remarks = urlDecode(vless.substr(pos + 1));
vless.erase(pos);
}
const std::string stdvless_matcher = R"(^([\da-f]{4}(?:[\da-f]{4}-){4}[\da-f]{12})@\[?([\d\-a-zA-Z:.]+)\]?:(\d+)(?:\/?\?(.*))?$)";
const std::string stdvless_matcher = R"(^([\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12})@\[?([\d\-a-zA-Z:.]+)\]?:(\d+)(?:\/?\?(.*))?$)";
if (regGetMatch(vless, stdvless_matcher, 5, 0, &id, &add, &port, &addition))
return;