Enhancements

Fix compatibility problem with some non-standard subscriptions.
Add support for specifying token for each profile.
This commit is contained in:
Tindy X committed 2020-03-09 12:28:24 +08:00
1 parent 4eda0edb26
commit 7bbd9af989
2 files changed
+45 -26

No files matched your search

+19 -1
View File
@@ -1664,7 +1664,7 @@ std::string surgeConfToClash(RESPONSE_CALLBACK_ARGS)
std::string getProfile(RESPONSE_CALLBACK_ARGS) std::string getProfile(RESPONSE_CALLBACK_ARGS)
{ {
std::string name = UrlDecode(getUrlArg(argument, "name")), token = UrlDecode(getUrlArg(argument, "token")), expand = getUrlArg(argument, "expand"); std::string name = UrlDecode(getUrlArg(argument, "name")), token = UrlDecode(getUrlArg(argument, "token")), expand = getUrlArg(argument, "expand");
if(token != access_token) if(token.empty() || name.empty())
{ {
*status_code = 403; *status_code = 403;
return "Forbidden"; return "Forbidden";
@@ -1695,6 +1695,24 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
*status_code = 500; *status_code = 500;
return "Broken profile!"; return "Broken profile!";
} }
auto profile_token = contents.find("profile_token");
if(profile_token != contents.end())
{
if(token != profile_token->second)
{
*status_code = 403;
return "Forbidden";
}
token = access_token;
}
else
{
if(token != access_token)
{
*status_code = 403;
return "Forbidden";
}
}
contents.emplace("token", token); contents.emplace("token", token);
contents.emplace("expand", expand); contents.emplace("expand", expand);
std::string query; std::string query;
+26 -25
View File
@@ -326,8 +326,6 @@ void explodeSSAndroid(std::string ss, bool libev, std::string custom_port, int l
{ {
Document json; Document json;
nodeInfo node; nodeInfo node;
std::string ps, password, method, server, port, group = SS_DEFAULT_GROUP;
std::string plugin, pluginopts;
int index = nodes.size(); int index = nodes.size();
//first add some extra data before parsing //first add some extra data before parsing
ss = "{\"nodes\":" + ss + "}"; ss = "{\"nodes\":" + ss + "}";
@@ -337,6 +335,9 @@ void explodeSSAndroid(std::string ss, bool libev, std::string custom_port, int l
for(unsigned int i = 0; i < json["nodes"].Size(); i++) for(unsigned int i = 0; i < json["nodes"].Size(); i++)
{ {
std::string ps, password, method, server, port, group = SS_DEFAULT_GROUP;
std::string plugin, pluginopts;
server = GetMember(json["nodes"][i], "server"); server = GetMember(json["nodes"][i], "server");
if(server.empty()) if(server.empty())
continue; continue;
@@ -744,14 +745,15 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v
nodeInfo node; nodeInfo node;
Node singleproxy; Node singleproxy;
unsigned int index = nodes.size(); unsigned int index = nodes.size();
const std::string section = yamlnode["proxies"].IsDefined() ? "proxies" : "Proxy";
for(unsigned int i = 0; i < yamlnode[section].size(); i++)
{
std::string proxytype, ps, server, port, cipher, group, password; //common std::string proxytype, ps, server, port, cipher, group, password; //common
std::string type = "none", id, aid = "0", net = "tcp", path, host, edge, tls; //vmess std::string type = "none", id, aid = "0", net = "tcp", path, host, edge, tls; //vmess
std::string plugin, pluginopts, pluginopts_mode, pluginopts_host, pluginopts_mux; //ss std::string plugin, pluginopts, pluginopts_mode, pluginopts_host, pluginopts_mux; //ss
std::string protocol, protoparam, obfs, obfsparam; //ssr std::string protocol, protoparam, obfs, obfsparam; //ssr
std::string user; //socks std::string user; //socks
const std::string section = yamlnode["proxies"].IsDefined() ? "proxies" : "Proxy";
for(unsigned int i = 0; i < yamlnode[section].size(); i++)
{
singleproxy = yamlnode[section][i]; singleproxy = yamlnode[section][i];
singleproxy["type"] >> proxytype; singleproxy["type"] >> proxytype;
singleproxy["name"] >> ps; singleproxy["name"] >> ps;
@@ -1034,12 +1036,6 @@ void explodeKitsunebi(std::string kit, std::string custom_port, int local_port,
bool explodeSurge(std::string surge, std::string custom_port, int local_port, std::vector<nodeInfo> &nodes, bool libev) bool explodeSurge(std::string surge, std::string custom_port, int local_port, std::vector<nodeInfo> &nodes, bool libev)
{ {
std::string remarks, server, port, method, username, password; //common
std::string plugin, pluginopts, pluginopts_mode, pluginopts_host = "cloudfront.net", mod_url, mod_md5; //ss
std::string id, net, tls, host, edge, path; //v2
std::string protocol, protoparam; //ssr
std::string itemName, itemVal;
std::vector<std::string> configs, vArray, headers, header;
std::multimap<std::string, std::string> proxies; std::multimap<std::string, std::string> proxies;
nodeInfo node; nodeInfo node;
unsigned int i, index = nodes.size(); unsigned int i, index = nodes.size();
@@ -1063,6 +1059,13 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
for(auto &x : proxies) for(auto &x : proxies)
{ {
std::string remarks, server, port, method, username, password; //common
std::string plugin, pluginopts, pluginopts_mode, pluginopts_host = "cloudfront.net", mod_url, mod_md5; //ss
std::string id, net, tls, host, edge, path; //v2
std::string protocol, protoparam; //ssr
std::string itemName, itemVal;
std::vector<std::string> configs, vArray, headers, header;
remarks = x.first; remarks = x.first;
configs = split(x.second, ","); configs = split(x.second, ",");
if(configs.size() < 2 || configs[0] == "direct") if(configs.size() < 2 || configs[0] == "direct")
@@ -1089,7 +1092,6 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
port = custom_port.empty() ? trim(configs[2]) : custom_port; port = custom_port.empty() ? trim(configs[2]) : custom_port;
method = trim(configs[3]); method = trim(configs[3]);
password = trim(configs[4]); password = trim(configs[4]);
plugin.clear();
for(i = 6; i < configs.size(); i++) for(i = 6; i < configs.size(); i++)
{ {
@@ -1106,7 +1108,7 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
else if(itemName == "obfs-host") else if(itemName == "obfs-host")
pluginopts_host = itemVal; pluginopts_host = itemVal;
} }
if(plugin != "") if(plugin.size())
{ {
pluginopts = "obfs=" + pluginopts_mode; pluginopts = "obfs=" + pluginopts_mode;
pluginopts += pluginopts_host.empty() ? "" : ";obfs-host=" + pluginopts_host; pluginopts += pluginopts_host.empty() ? "" : ";obfs-host=" + pluginopts_host;
@@ -1123,7 +1125,6 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
{ {
server = trim(configs[1]); server = trim(configs[1]);
port = custom_port.empty() ? trim(configs[2]) : custom_port; port = custom_port.empty() ? trim(configs[2]) : custom_port;
plugin.clear();
for(i = 3; i < configs.size(); i++) for(i = 3; i < configs.size(); i++)
{ {
@@ -1144,7 +1145,7 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
else if(itemName == "obfs-host") else if(itemName == "obfs-host")
pluginopts_host = itemVal; pluginopts_host = itemVal;
} }
if(plugin != "") if(plugin.size())
{ {
pluginopts = "obfs=" + pluginopts_mode; pluginopts = "obfs=" + pluginopts_mode;
pluginopts += pluginopts_host.empty() ? "" : ";obfs-host=" + pluginopts_host; pluginopts += pluginopts_host.empty() ? "" : ";obfs-host=" + pluginopts_host;
@@ -1199,9 +1200,9 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
for(auto &y : headers) for(auto &y : headers)
{ {
header = split(trim(y), ":"); header = split(trim(y), ":");
if(header[0] == "Host") if(regMatch(header[0], "(?i)host"))
host = header[1]; host = header[1];
else if(header[0] == "Edge") else if(regMatch(header[0], "(?i)edge"))
edge = header[1]; edge = header[1];
} }
} }
@@ -1230,7 +1231,6 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
{ {
server = trim(configs[0].substr(0, configs[0].rfind(":"))); server = trim(configs[0].substr(0, configs[0].rfind(":")));
port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port; port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port;
plugin = protocol = remarks = "";
for(i = 1; i < configs.size(); i++) for(i = 1; i < configs.size(); i++)
{ {
@@ -1259,10 +1259,11 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
} }
if(remarks.empty()) if(remarks.empty())
remarks = server + ":" + port; remarks = server + ":" + port;
if(plugin != "") if(plugin.size())
{ {
pluginopts = "obfs=" + pluginopts_mode; pluginopts = "obfs=" + pluginopts_mode;
pluginopts += pluginopts_host.empty() ? "" : ";obfs-host=" + pluginopts_host; if(pluginopts_host.size())
pluginopts += ";obfs-host=" + pluginopts_host;
} }
if(protocol.size()) if(protocol.size())
@@ -1282,7 +1283,6 @@ bool explodeSurge(std::string surge, std::string custom_port, int local_port, st
{ {
server = trim(configs[0].substr(0, configs[0].rfind(":"))); server = trim(configs[0].substr(0, configs[0].rfind(":")));
port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port; port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port;
plugin = protocol = remarks = "";
net = "tcp"; net = "tcp";
for(i = 1; i < configs.size(); i++) for(i = 1; i < configs.size(); i++)
@@ -1339,10 +1339,6 @@ void explodeSSTap(std::string sstap, std::string custom_port, int local_port, st
{ {
Document json; Document json;
nodeInfo node; nodeInfo node;
std::string configType, group, remarks, server, port;
std::string cipher;
std::string user, pass;
std::string protocol, protoparam, obfs, obfsparam;
unsigned int index = nodes.size(); unsigned int index = nodes.size();
json.Parse(sstap.data()); json.Parse(sstap.data());
if(json.HasParseError()) if(json.HasParseError())
@@ -1350,6 +1346,11 @@ void explodeSSTap(std::string sstap, std::string custom_port, int local_port, st
for(unsigned int i = 0; i < json["configs"].Size(); i++) for(unsigned int i = 0; i < json["configs"].Size(); i++)
{ {
std::string configType, group, remarks, server, port;
std::string cipher;
std::string user, pass;
std::string protocol, protoparam, obfs, obfsparam;
json["configs"][i]["group"] >> group; json["configs"][i]["group"] >> group;
json["configs"][i]["remarks"] >> remarks; json["configs"][i]["remarks"] >> remarks;
json["configs"][i]["server"] >> server; json["configs"][i]["server"] >> server;