Enhancements

Fix not processing quotes in ws-headers in Surge VMess configurations.
Fix when default_url is set and insert_url is not set in YAML configuration and access /sub without url argument, the nodes in default_url will be added twice.
Add /version interface to compatible with some front-end.
This commit is contained in:
Tindy X committed 2020-03-11 23:54:08 +08:00
1 parent 550670006d
commit 5594070657
6 files changed
+39 -16

No files matched your search

+14 -8
View File
@@ -387,21 +387,27 @@ void readYAMLConf(YAML::Node &node)
{
section["default_url"] >> tempArray;
if(tempArray.size())
strLine = std::accumulate(std::next(tempArray.begin()), tempArray.end(), tempArray[0], [](std::string a, std::string b)
{
return std::move(a) + "|" + std::move(b);
});
default_url = strLine;
strLine = std::accumulate(std::next(tempArray.begin()), tempArray.end(), tempArray[0], [](std::string a, std::string b)
{
return std::move(a) + "|" + std::move(b);
});
default_url = strLine;
eraseElements(tempArray);
}
}
if(section["insert_url"].IsSequence())
{
section["insert_url"] >> tempArray;
if(tempArray.size())
strLine = std::accumulate(std::next(tempArray.begin()), tempArray.end(), tempArray[0], [](std::string a, std::string b)
{
return std::move(a) + "|" + std::move(b);
});
insert_url = strLine;
strLine = std::accumulate(std::next(tempArray.begin()), tempArray.end(), tempArray[0], [](std::string a, std::string b)
{
return std::move(a) + "|" + std::move(b);
});
insert_url = strLine;
eraseElements(tempArray);
}
}
if(section["exclude_remarks"].IsSequence())
section["exclude_remarks"] >> def_exclude_remarks;
+6 -1
View File
@@ -130,7 +130,12 @@ int main(int argc, char *argv[])
append_response("GET", "/", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
return std::string("subconverter " VERSION " backend\n");
return "subconverter " VERSION " backend\n";
});
append_response("GET", "/version", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
{
return "subconverter " VERSION " backend\n";
});
append_response("GET", "/refreshrules", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
+13 -3
View File
@@ -438,14 +438,14 @@ std::string getSystemProxy()
#endif // _WIN32
}
std::string trim(const std::string& str)
std::string trim_of(const std::string& str, char target)
{
std::string::size_type pos = str.find_first_not_of(' ');
std::string::size_type pos = str.find_first_not_of(target);
if (pos == std::string::npos)
{
return str;
}
std::string::size_type pos2 = str.find_last_not_of(' ');
std::string::size_type pos2 = str.find_last_not_of(target);
if (pos2 != std::string::npos)
{
return str.substr(pos, pos2 - pos + 1);
@@ -453,6 +453,16 @@ std::string trim(const std::string& str)
return str.substr(pos);
}
std::string trim(const std::string& str)
{
return trim_of(str, ' ');
}
std::string trim_quote(const std::string &str)
{
return trim_of(str, '\"');
}
std::string getUrlArg(const std::string &url, const std::string &request)
{
//std::smatch result;
+2
View File
@@ -39,7 +39,9 @@ std::string urlsafe_base64_decode(const std::string &encoded_string);
std::string urlsafe_base64_encode(const std::string &string_to_encode);
std::string UTF8ToACP(const std::string &str_src);
std::string ACPToUTF8(const std::string &str_src);
std::string trim_of(const std::string& str, char target);
std::string trim(const std::string& str);
std::string trim_quote(const std::string &str);
std::string getSystemProxy();
std::string rand_str(const int len);
bool is_str_utf8(const std::string &data);
+2 -2
View File
@@ -1204,9 +1204,9 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
{
header = split(trim(y), ":");
if(regMatch(header[0], "(?i)host"))
host = header[1];
host = trim_quote(header[1]);
else if(regMatch(header[0], "(?i)edge"))
edge = header[1];
edge = trim_quote(header[1]);
}
}
}
+2 -2
View File
@@ -1021,9 +1021,9 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
proxy = "vmess, " + hostname + ", " + port + ", username=" + id + ", tls=" + (tlssecure ? "true" : "false");
if(transproto == "ws")
{
proxy += ", ws=true, ws-path=" + path + ", ws-headers=Host:" + host;
proxy += ", ws=true, ws-path=" + path + ", ws-headers=Host:\"" + host + "\"";
if(edge.size())
proxy += "|Edge:" + edge;
proxy += "|Edge:\"" + edge + "\"";
}
if(ext.skip_cert_verify)
proxy += ", skip-cert-verify=1";