From af7d7fae052d2e623662135be86c637339cea2cd Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Mon, 4 May 2020 23:59:43 +0800 Subject: [PATCH] Enhancements Add support for Quantumult X IP6-CIDR rules. Add SNI host settings to Surge VMess nodes. --- src/interfaces.cpp | 6 ++++-- src/speedtestutil.cpp | 21 +++++++++------------ src/subexport.cpp | 11 ++++++++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 16aaec0..282fd98 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -138,7 +138,7 @@ std::string getRuleset(RESPONSE_CALLBACK_ARGS) switch(type_int) { case 2: - if(!std::any_of(quanx_rule_type.begin(), quanx_rule_type.end(), [&strLine](std::string type){return startsWith(strLine, type);}) || startsWith(strLine, "IP-CIDR6")) + if(!std::any_of(quanx_rule_type.begin(), quanx_rule_type.end(), [&strLine](std::string type){return startsWith(strLine, type);})) continue; break; case 1: @@ -206,6 +206,8 @@ std::string getRuleset(RESPONSE_CALLBACK_ARGS) { if(type_int == 2) { + if(startsWith(strLine, "IP-CIDR6")) + strLine.replace(0, 8, "IP6-CIDR"); strLine += "," + group; if(std::count(strLine.begin(), strLine.end(), ',') > 2 && regReplace(strLine, rule_match_regex, "$2") == ",no-resolve") strLine = regReplace(strLine, rule_match_regex, "$1$3$2"); @@ -1954,7 +1956,7 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS) return "Broken profile!"; } auto profile_token = contents.find("profile_token"); - if(profile_token != contents.end()) + if(profiles.size() == 1 && profile_token != contents.end()) { if(token != profile_token->second) { diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index fddbc4e..451f342 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -2124,18 +2124,15 @@ static inline unsigned long long streamToInt(const std::string &stream) if(!stream.size()) return 0; double streamval = 1.0; - if(stream.find("GB") != std::string::npos) - streamval = std::pow(1024, 3) * to_number(stream.substr(0, stream.size() - 2), 0.0); - else if(stream.find("TB") != std::string::npos) - streamval = std::pow(1024, 4) * to_number(stream.substr(0, stream.size() - 2), 0.0); - else if(stream.find("PB") != std::string::npos) - streamval = std::pow(1024, 5) * to_number(stream.substr(0, stream.size() - 2), 0.0); - else if(stream.find("MB") != std::string::npos) - streamval = std::pow(1024, 2) * to_number(stream.substr(0, stream.size() - 2), 0.0); - else if(stream.find("KB") != std::string::npos) - streamval = 1024.0 * to_number(stream.substr(0, stream.size() - 2), 0.0); - else if(stream.find("B") != std::string::npos) - streamval = 1.0 * to_number(stream.substr(0, stream.size() - 1), 0.0); + std::vector units = {"B", "KB", "MB", "GB", "TB", "PB", "EB"}; + for(size_t index = units.size() - 1; index >= 0; index--) + { + if(endsWith(stream, units[index])) + { + streamval = std::pow(1024, index) * to_number(stream.substr(0, stream.size() - units[index].size()), 0.0); + break; + } + } return (unsigned long long)streamval; } diff --git a/src/subexport.cpp b/src/subexport.cpp index 051c935..e058d3f 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -834,9 +834,12 @@ void rulesetToSurge(INIReader &base_rule, std::vector &ruleset_ /// remove unsupported types switch(surge_ver) { - case -1: case -2: - if(!std::any_of(quanx_rule_type.begin(), quanx_rule_type.end(), [strLine](std::string type){return startsWith(strLine, type);}) || startsWith(strLine, "IP-CIDR6")) + if(startsWith(strLine, "IP-CIDR6")) + continue; + [[fallthrough]]; + case -1: + if(!std::any_of(quanx_rule_type.begin(), quanx_rule_type.end(), [strLine](std::string type){return startsWith(strLine, type);})) continue; break; case -3: @@ -859,6 +862,8 @@ void rulesetToSurge(INIReader &base_rule, std::vector &ruleset_ strLine += "," + rule_group; if(surge_ver == -1 || surge_ver == -2) { + if(startsWith(strLine, "IP-CIDR6")) + strLine.replace(0, 8, "IP6-CIDR"); if(std::count(strLine.begin(), strLine.end(), ',') > 2 && regReplace(strLine, rule_match_regex, "$2") == ",no-resolve") strLine = regReplace(strLine, rule_match_regex, "$1$3$2"); else @@ -1388,7 +1393,7 @@ std::string netchToSurge(std::vector &nodes, std::string &base_conf, s case "tcp"_hash: break; case "ws"_hash: - proxy += ", ws=true, ws-path=" + path + ", ws-headers=Host:" + host; + proxy += ", ws=true, ws-path=" + path + ", sni=" + host + ", ws-headers=Host:" + host; if(edge.size()) proxy += "|Edge:" + edge; break;