Enhancements

Fix not adding local rulesets as Clash rule-providers.
Add "nullnode" as node placeholder to export configurations without adding any real node.
Add support for using !!import in source subscription URLs.
Add support for allowInsecure and tfo argument in Trojan links.
Optimize codes.
This commit is contained in:
Tindy X committed 2020-06-25 00:53:38 +08:00
1 parent 8138fadd48
commit d042f00a8e
7 files changed
+36 -17

No files matched your search

+2
View File
@@ -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)
{
+17 -11
View File
@@ -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;
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -74,7 +74,7 @@ void safe_set_times(string_array &data)
std::shared_future<std::string> fetchFileAsync(const std::string &path, const std::string &proxy, int cache_ttl, bool async)
{
std::shared_future<std::string> 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);});
+8 -1
View File
@@ -67,6 +67,13 @@ int addNodes(std::string link, std::vector<nodeInfo> &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<nodeInfo> &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;
}
+5 -2
View File
@@ -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)
+2 -1
View File
@@ -290,7 +290,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector<ruleset_content> &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<ruleset_content> &rules
continue;
}
retrieved_rules = convertRuleset(retrieved_rules, x.rule_type);
char delimiter = getLineBreak(retrieved_rules);
strStrm.clear();