diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 997a89a..e55771e 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -1523,6 +1523,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) { groupID = -1; urls = split(insert_url, "|"); + importItems(urls, true); for(std::string &x : urls) { x = regTrim(x); @@ -1536,6 +1537,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) } } urls = split(url, "|"); + importItems(urls, true); groupID = 0; for(std::string &x : urls) { diff --git a/src/misc.cpp b/src/misc.cpp index 5fdc383..e3e58c2 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -796,21 +796,25 @@ std::string getMD5(const std::string &data) return result; } +bool isInScope(const std::string &path) +{ +#ifdef _WIN32 + if(path.find(":\\") != path.npos || path.find("..") != path.npos) + return false; +#else + if(path.find("/") == 0 || path.find("..") != path.npos) + return false; +#endif // _WIN32 + return true; +} + // TODO: Add preprocessor option to disable (open web service safety) std::string fileGet(const std::string &path, bool scope_limit) { std::string content; - if(scope_limit) - { -#ifdef _WIN32 - if(path.find(":\\") != path.npos || path.find("..") != path.npos) - return std::string(); -#else - if(path.find("/") == 0 || path.find("..") != path.npos) - return std::string(); -#endif // _WIN32 - } + if(scope_limit && !isInScope(path)) + return std::string(); std::FILE *fp = std::fopen(path.c_str(), "rb"); if(fp) @@ -846,10 +850,12 @@ std::string fileGet(const std::string &path, bool scope_limit) return content; } -bool fileExist(const std::string &path) +bool fileExist(const std::string &path, bool scope_limit) { //using c++17 standard, but may cause problem on clang //return std::filesystem::exists(path); + if(scope_limit && !isInScope(path)) + return false; return _access(path.data(), 4) != -1; } diff --git a/src/misc.h b/src/misc.h index c927409..4d4269b 100644 --- a/src/misc.h +++ b/src/misc.h @@ -82,7 +82,7 @@ std::string toUpper(const std::string &str); std::string fileGet(const std::string &path, bool scope_limit = false); int fileWrite(const std::string &path, const std::string &content, bool overwrite); -bool fileExist(const std::string &path); +bool fileExist(const std::string &path, bool scope_limit = false); bool fileCopy(const std::string &source, const std::string &dest); std::string fileToBase64(const std::string &filepath); std::string fileGetMD5(const std::string &filepath); diff --git a/src/multithread.cpp b/src/multithread.cpp index dae434b..68562d6 100644 --- a/src/multithread.cpp +++ b/src/multithread.cpp @@ -74,7 +74,7 @@ void safe_set_times(string_array &data) std::shared_future fetchFileAsync(const std::string &path, const std::string &proxy, int cache_ttl, bool async) { std::shared_future retVal; - if(fileExist(path)) + if(fileExist(path, true)) retVal = std::async(std::launch::async, [path](){return fileGet(path, true);}); else if(isLink(path)) retVal = std::async(std::launch::async, [path, proxy, cache_ttl](){return webGet(path, proxy, cache_ttl);}); diff --git a/src/nodemanip.cpp b/src/nodemanip.cpp index 1cc1544..b2f990e 100644 --- a/src/nodemanip.cpp +++ b/src/nodemanip.cpp @@ -67,6 +67,13 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, std } } + if(link == "nullnode") + { + writeLog(0, "Adding node placeholder..."); + allNodes.emplace_back(nodeInfo{-1, -1, 0}); + return 0; + } + writeLog(LOG_TYPE_INFO, "Received Link."); if(startsWith(link, "https://t.me/socks") || startsWith(link, "tg://socks")) linkType = SPEEDTEST_MESSAGE_FOUNDSOCKS; @@ -168,7 +175,7 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, std node.groupID = groupID; if(custom_group.size()) node.group = custom_group; - allNodes.push_back(node); + allNodes.emplace_back(node); } return 0; } diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index 188930d..b8c3060 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -769,6 +769,7 @@ void explodeHTTPSub(std::string link, const std::string &custom_port, nodeInfo & void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo &node) { std::string server, port, psk, addition, remark, host; + tribool tfo, scv; string_array vArray; trojan.erase(0, 9); string_size pos = trojan.rfind("#"); @@ -778,7 +779,7 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo remark = UrlDecode(trojan.substr(pos + 1)); trojan.erase(pos); } - pos = trojan.rfind("?"); + pos = trojan.find("?"); if(pos != trojan.npos) { addition = trojan.substr(pos + 1); @@ -803,6 +804,8 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo return; host = getUrlArg(addition, "peer"); + tfo = getUrlArg(addition, "tfo"); + scv = getUrlArg(addition, "allowInsecure"); if(remark.empty()) remark = server + ":" + port; @@ -814,7 +817,7 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo node.remarks = remark; node.server = server; node.port = to_int(port, 1); - node.proxyStr = trojanConstruct(node.group, remark, server, port, psk, host, true); + node.proxyStr = trojanConstruct(node.group, remark, server, port, psk, host, true, tribool(), tfo, scv); } void explodeQuan(std::string quan, const std::string &custom_port, nodeInfo &node) diff --git a/src/templates.cpp b/src/templates.cpp index f6f69df..34b5c5e 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -290,7 +290,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules } if(remote_path_prefix.size()) { - if(isLink(rule_path) || startsWith(rule_path, "data:")) + if(fileExist(rule_path, true) || isLink(rule_path)) { rule_name = std::to_string(hash_(rule_group + rule_path)); names[rule_name] = rule_group; @@ -314,6 +314,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules continue; } + retrieved_rules = convertRuleset(retrieved_rules, x.rule_type); char delimiter = getLineBreak(retrieved_rules); strStrm.clear();