mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-02 01:33:04 +00:00
Enhancements
Add auto filtering for nodes that are not supported by Clash/R core. Add skip_cert_verify for Surge, Quantumult and Quantumult X subscription. Add "separate links" option for exporting SIP002 subscriptions. Optimize codes.
This commit is contained in:
5 files changed
+57
-14
No files matched your search
+22
-2
@@ -353,13 +353,17 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
//for external configuration
|
//for external configuration
|
||||||
std::string ext_clash_base = clash_rule_base, ext_surge_base = surge_rule_base, ext_mellow_base = mellow_rule_base, ext_surfboard_base = surfboard_rule_base;
|
std::string ext_clash_base = clash_rule_base, ext_surge_base = surge_rule_base, ext_mellow_base = mellow_rule_base, ext_surfboard_base = surfboard_rule_base;
|
||||||
|
|
||||||
|
//validate urls
|
||||||
if(!url.size())
|
if(!url.size())
|
||||||
url = default_url;
|
url = default_url;
|
||||||
if(!url.size() || !target.size())
|
if(!url.size() || !target.size())
|
||||||
return "Invalid request!";
|
return "Invalid request!";
|
||||||
|
|
||||||
|
//check if we need to read configuration
|
||||||
if(!api_mode || cfw_child_process)
|
if(!api_mode || cfw_child_process)
|
||||||
readConf();
|
readConf();
|
||||||
|
|
||||||
|
//check for proxy settings
|
||||||
std::string proxy;
|
std::string proxy;
|
||||||
if(proxy_subscription == "SYSTEM")
|
if(proxy_subscription == "SYSTEM")
|
||||||
proxy = getSystemProxy();
|
proxy = getSystemProxy();
|
||||||
@@ -368,6 +372,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
else
|
else
|
||||||
proxy = proxy_subscription;
|
proxy = proxy_subscription;
|
||||||
|
|
||||||
|
//load external configuration
|
||||||
if(config.size())
|
if(config.size())
|
||||||
{
|
{
|
||||||
std::cerr<<"External configuration file provided. Loading...\n";
|
std::cerr<<"External configuration file provided. Loading...\n";
|
||||||
@@ -398,6 +403,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//loading custom groups
|
||||||
if(groups.size())
|
if(groups.size())
|
||||||
{
|
{
|
||||||
extra_group = split(groups, "@");
|
extra_group = split(groups, "@");
|
||||||
@@ -407,6 +413,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
else
|
else
|
||||||
extra_group = clash_extra_group;
|
extra_group = clash_extra_group;
|
||||||
|
|
||||||
|
//loading custom rulesets
|
||||||
if(ruleset.size())
|
if(ruleset.size())
|
||||||
{
|
{
|
||||||
extra_ruleset = split(ruleset, "@");
|
extra_ruleset = split(ruleset, "@");
|
||||||
@@ -429,6 +436,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check other flags
|
||||||
if(emoji.size())
|
if(emoji.size())
|
||||||
{
|
{
|
||||||
ext.add_emoji = ext.remove_emoji = emoji == "true";
|
ext.add_emoji = ext.remove_emoji = emoji == "true";
|
||||||
@@ -451,10 +459,12 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
ext.nodelist = nodelist == "true";
|
ext.nodelist = nodelist == "true";
|
||||||
ext.surge_ssr_path = surge_ssr_path;
|
ext.surge_ssr_path = surge_ssr_path;
|
||||||
|
|
||||||
|
//loading urls
|
||||||
string_array urls = split(url, "|");
|
string_array urls = split(url, "|");
|
||||||
std::vector<nodeInfo> nodes;
|
std::vector<nodeInfo> nodes;
|
||||||
int groupID = 0;
|
int groupID = 0;
|
||||||
|
|
||||||
|
//check custom include/exclude settings
|
||||||
if(include.size() && regValid(include))
|
if(include.size() && regValid(include))
|
||||||
include_remarks.emplace_back(include);
|
include_remarks.emplace_back(include);
|
||||||
else
|
else
|
||||||
@@ -464,8 +474,11 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
else
|
else
|
||||||
exclude_remarks = def_exclude_remarks;
|
exclude_remarks = def_exclude_remarks;
|
||||||
|
|
||||||
|
//check custom group name
|
||||||
if(group.size())
|
if(group.size())
|
||||||
custom_group = group;
|
custom_group = group;
|
||||||
|
|
||||||
|
//start parsing urls
|
||||||
for(std::string &x : urls)
|
for(std::string &x : urls)
|
||||||
{
|
{
|
||||||
x = trim(x);
|
x = trim(x);
|
||||||
@@ -473,6 +486,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
addNodes(x, nodes, groupID, proxy, exclude_remarks, include_remarks);
|
addNodes(x, nodes, groupID, proxy, exclude_remarks, include_remarks);
|
||||||
groupID++;
|
groupID++;
|
||||||
}
|
}
|
||||||
|
//exit if found nothing
|
||||||
if(!nodes.size())
|
if(!nodes.size())
|
||||||
return "No nodes were found!";
|
return "No nodes were found!";
|
||||||
|
|
||||||
@@ -490,7 +504,11 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
output_content = netchToClash(nodes, base_content, rca, extra_group, target == "clashr", ext);
|
output_content = netchToClash(nodes, base_content, rca, extra_group, target == "clashr", ext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
output_content = YAML::Dump(netchToClash(nodes, clash_base, extra_group, target == "clashr", ext));
|
{
|
||||||
|
YAML::Node yamlnode = clash_base;
|
||||||
|
netchToClash(nodes, yamlnode, extra_group, target == "clashr", ext);
|
||||||
|
output_content = YAML::Dump(yamlnode);
|
||||||
|
}
|
||||||
|
|
||||||
if(upload == "true")
|
if(upload == "true")
|
||||||
uploadGist(target, upload_path, output_content, false);
|
uploadGist(target, upload_path, output_content, false);
|
||||||
@@ -654,7 +672,9 @@ std::string simpleToClashR(RESPONSE_CALLBACK_ARGS)
|
|||||||
|
|
||||||
std::cerr<<"Generate target: ClashR\n";
|
std::cerr<<"Generate target: ClashR\n";
|
||||||
|
|
||||||
return YAML::Dump(netchToClash(nodes, clash_base, extra_group, true, ext));
|
YAML::Node yamlnode = clash_base;
|
||||||
|
netchToClash(nodes, yamlnode, extra_group, true, ext);
|
||||||
|
return YAML::Dump(yamlnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chkArg(int argc, char *argv[])
|
void chkArg(int argc, char *argv[])
|
||||||
|
|||||||
+2
-2
@@ -689,12 +689,12 @@ int fileWrite(std::string path, std::string content, bool overwrite)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isIPv4(std::string address)
|
bool isIPv4(std::string &address)
|
||||||
{
|
{
|
||||||
return regMatch(address, "^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
|
return regMatch(address, "^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isIPv6(std::string address)
|
bool isIPv6(std::string &address)
|
||||||
{
|
{
|
||||||
std::vector<std::string> regLists = {"^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$", "^((?:[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::((?:([0-9A-Fa-f]{1,4}:)*[0-9A-Fa-f]{1,4})?)$", "^(::(?:[0-9A-Fa-f]{1,4})(?::[0-9A-Fa-f]{1,4}){5})|((?:[0-9A-Fa-f]{1,4})(?::[0-9A-Fa-f]{1,4}){5}::)$"};
|
std::vector<std::string> regLists = {"^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$", "^((?:[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})*)?)::((?:([0-9A-Fa-f]{1,4}:)*[0-9A-Fa-f]{1,4})?)$", "^(::(?:[0-9A-Fa-f]{1,4})(?::[0-9A-Fa-f]{1,4}){5})|((?:[0-9A-Fa-f]{1,4})(?::[0-9A-Fa-f]{1,4}){5}::)$"};
|
||||||
for(unsigned int i = 0; i < regLists.size(); i++)
|
for(unsigned int i = 0; i < regLists.size(); i++)
|
||||||
|
|||||||
+2
-2
@@ -46,8 +46,8 @@ std::string regReplace(std::string src, std::string match, std::string rep);
|
|||||||
bool regMatch(std::string src, std::string match);
|
bool regMatch(std::string src, std::string match);
|
||||||
std::string speedCalc(double speed);
|
std::string speedCalc(double speed);
|
||||||
std::string getMD5(std::string data);
|
std::string getMD5(std::string data);
|
||||||
bool isIPv4(std::string address);
|
bool isIPv4(std::string &address);
|
||||||
bool isIPv6(std::string address);
|
bool isIPv6(std::string &address);
|
||||||
void urlParse(std::string url, std::string &host, std::string &path, int &port, bool &isTLS);
|
void urlParse(std::string url, std::string &host, std::string &path, int &port, bool &isTLS);
|
||||||
void removeUTF8BOM(std::string &data);
|
void removeUTF8BOM(std::string &data);
|
||||||
int shortAssemble(unsigned short num_a, unsigned short num_b);
|
int shortAssemble(unsigned short num_a, unsigned short num_b);
|
||||||
|
|||||||
+30
-7
@@ -21,6 +21,9 @@ extern bool add_emoji, remove_old_emoji;
|
|||||||
extern bool api_mode;
|
extern bool api_mode;
|
||||||
extern string_array ss_ciphers, ssr_ciphers;
|
extern string_array ss_ciphers, ssr_ciphers;
|
||||||
|
|
||||||
|
string_array clashr_protocols = {"auth_aes128_md5", "auth_aes128_sha1"};
|
||||||
|
string_array clashr_obfs = {"plain", "http_simple", "http_post", "tls1.2_ticket_auth"};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
std::string hostnameToIPAddr(std::string host)
|
std::string hostnameToIPAddr(std::string host)
|
||||||
{
|
{
|
||||||
@@ -482,7 +485,7 @@ void groupGenerate(std::string &rule, std::vector<nodeInfo> &nodelist, std::vect
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YAML::Node 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)
|
||||||
{
|
{
|
||||||
try_config_lock();
|
try_config_lock();
|
||||||
YAML::Node proxies, singleproxy, singlegroup, original_groups;
|
YAML::Node proxies, singleproxy, singlegroup, original_groups;
|
||||||
@@ -534,6 +537,9 @@ YAML::Node netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, stri
|
|||||||
|
|
||||||
if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSS)
|
if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSS)
|
||||||
{
|
{
|
||||||
|
//latest clash core removed support for chacha20 encryption
|
||||||
|
if(method == "chacha20")
|
||||||
|
continue;
|
||||||
plugin = GetMember(json, "Plugin");
|
plugin = GetMember(json, "Plugin");
|
||||||
pluginopts = replace_all_distinct(GetMember(json, "PluginOption"), ";", "&");
|
pluginopts = replace_all_distinct(GetMember(json, "PluginOption"), ";", "&");
|
||||||
singleproxy["type"] = "ss";
|
singleproxy["type"] = "ss";
|
||||||
@@ -582,9 +588,17 @@ YAML::Node netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, stri
|
|||||||
}
|
}
|
||||||
else if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSSR && clashR)
|
else if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSSR && clashR)
|
||||||
{
|
{
|
||||||
|
//latest clash core removed support for chacha20 encryption
|
||||||
|
if(method == "chacha20")
|
||||||
|
continue;
|
||||||
|
//ignoring all nodes with unsupported obfs and protocols
|
||||||
protocol = GetMember(json, "Protocol");
|
protocol = GetMember(json, "Protocol");
|
||||||
protoparam = GetMember(json, "ProtocolParam");
|
if(std::find(clashr_protocols.cbegin(), clashr_protocols.cend(), protocol) == clashr_protocols.cend())
|
||||||
|
continue;
|
||||||
obfs = GetMember(json, "OBFS");
|
obfs = GetMember(json, "OBFS");
|
||||||
|
if(std::find(clashr_obfs.cbegin(), clashr_obfs.cend(), obfs) == clashr_obfs.cend())
|
||||||
|
continue;
|
||||||
|
protoparam = GetMember(json, "ProtocolParam");
|
||||||
obfsparam = GetMember(json, "OBFSParam");
|
obfsparam = GetMember(json, "OBFSParam");
|
||||||
singleproxy["type"] = "ssr";
|
singleproxy["type"] = "ssr";
|
||||||
singleproxy["cipher"] = method;
|
singleproxy["cipher"] = method;
|
||||||
@@ -622,7 +636,8 @@ YAML::Node netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, stri
|
|||||||
{
|
{
|
||||||
YAML::Node provider;
|
YAML::Node provider;
|
||||||
provider["proxies"] = proxies;
|
provider["proxies"] = proxies;
|
||||||
return provider;
|
yamlnode = provider;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yamlnode["Proxy"] = proxies;
|
yamlnode["Proxy"] = proxies;
|
||||||
@@ -679,8 +694,6 @@ YAML::Node netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &yamlnode, stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
yamlnode["Proxy Group"] = original_groups;
|
yamlnode["Proxy Group"] = original_groups;
|
||||||
|
|
||||||
return yamlnode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -696,7 +709,7 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
|||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
yamlnode = netchToClash(nodes, yamlnode, extra_proxy_group, clashR, ext);
|
netchToClash(nodes, yamlnode, extra_proxy_group, clashR, ext);
|
||||||
|
|
||||||
if(ext.nodelist)
|
if(ext.nodelist)
|
||||||
return YAML::Dump(yamlnode);
|
return YAML::Dump(yamlnode);
|
||||||
@@ -802,6 +815,8 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
|||||||
{
|
{
|
||||||
proxy += ", ws=true, ws-path=" + path + ", ws-headers=Host:" + host;
|
proxy += ", ws=true, ws-path=" + path + ", ws-headers=Host:" + host;
|
||||||
}
|
}
|
||||||
|
if(ext.skip_cert_verify)
|
||||||
|
proxy += ", skip-cert-verify=1";
|
||||||
else if(transproto == "kcp" || transproto == "h2" || transproto == "quic")
|
else if(transproto == "kcp" || transproto == "h2" || transproto == "quic")
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -995,7 +1010,10 @@ std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
|||||||
allLinks += proxyStr + "\n";
|
allLinks += proxyStr + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return base64_encode(allLinks);
|
if(ext.nodelist)
|
||||||
|
return allLinks;
|
||||||
|
else
|
||||||
|
return base64_encode(allLinks);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string netchToSSR(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
std::string netchToSSR(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
||||||
@@ -1175,6 +1193,8 @@ std::string netchToQuan(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
|||||||
proxyStr += ", obfs=ws, obfs-path=" + path + ", obfs-header=\"Host: " + host + "\"";
|
proxyStr += ", obfs=ws, obfs-path=" + path + ", obfs-header=\"Host: " + host + "\"";
|
||||||
if(tlssecure)
|
if(tlssecure)
|
||||||
proxyStr += ", over-tls=true, tls-host=" + host;
|
proxyStr += ", over-tls=true, tls-host=" + host;
|
||||||
|
if(ext.skip_cert_verify)
|
||||||
|
proxyStr += ", certificate=0";
|
||||||
proxyStr = "vmess://" + urlsafe_base64_encode(proxyStr);
|
proxyStr = "vmess://" + urlsafe_base64_encode(proxyStr);
|
||||||
break;
|
break;
|
||||||
case SPEEDTEST_MESSAGE_FOUNDSSR:
|
case SPEEDTEST_MESSAGE_FOUNDSSR:
|
||||||
@@ -1259,6 +1279,8 @@ std::string netchToQuanX(std::vector<nodeInfo> &nodes, extra_settings &ext)
|
|||||||
proxyStr = "vmess = " + hostname + ":" + port + ", method=" + method + ", password=" + id;
|
proxyStr = "vmess = " + hostname + ":" + port + ", method=" + method + ", password=" + id;
|
||||||
if(transproto == "ws")
|
if(transproto == "ws")
|
||||||
proxyStr += ", obfs=ws, obfs-host=" + host + ", obfs-uri=" + path;
|
proxyStr += ", obfs=ws, obfs-host=" + host + ", obfs-uri=" + path;
|
||||||
|
if(ext.skip_cert_verify)
|
||||||
|
proxyStr += ", certificate=0";
|
||||||
break;
|
break;
|
||||||
case SPEEDTEST_MESSAGE_FOUNDSS:
|
case SPEEDTEST_MESSAGE_FOUNDSS:
|
||||||
password = GetMember(json, "Password");
|
password = GetMember(json, "Password");
|
||||||
@@ -1304,6 +1326,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_s
|
|||||||
std::string plugin, pluginopts;
|
std::string plugin, pluginopts;
|
||||||
std::string protocol, protoparam, obfs, obfsparam;
|
std::string protocol, protoparam, obfs, obfsparam;
|
||||||
int port, index = 0;
|
int port, index = 0;
|
||||||
|
|
||||||
if(!group.size())
|
if(!group.size())
|
||||||
group = "SSD";
|
group = "SSD";
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ struct extra_settings
|
|||||||
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array);
|
void rulesetToClash(YAML::Node &base_rule, std::vector<ruleset_content> &ruleset_content_array);
|
||||||
void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_content_array, int surge_ver);
|
void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_content_array, int surge_ver);
|
||||||
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);
|
||||||
YAML::Node netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &base, string_array &extra_proxy_group, bool clashR, extra_settings &ext);
|
void netchToClash(std::vector<nodeInfo> &nodes, YAML::Node &base, 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);
|
||||||
std::string netchToMellow(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 netchToMellow(std::vector<nodeInfo> &nodes, std::string &base_conf, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
||||||
void netchToMellow(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
void netchToMellow(std::vector<nodeInfo> &nodes, INIReader &ini, std::vector<ruleset_content> &ruleset_content_array, string_array &extra_proxy_group, extra_settings &ext);
|
||||||
|
|||||||
Reference in new issue
Block a user