diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 2d9ac16..6e45ca1 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -1664,7 +1664,7 @@ std::string surgeConfToClash(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"); - if(token != access_token) + if(token.empty() || name.empty()) { *status_code = 403; return "Forbidden"; @@ -1695,6 +1695,24 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS) *status_code = 500; 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("expand", expand); std::string query; diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index 2626f72..ac78a4a 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -326,8 +326,6 @@ void explodeSSAndroid(std::string ss, bool libev, std::string custom_port, int l { Document json; nodeInfo node; - std::string ps, password, method, server, port, group = SS_DEFAULT_GROUP; - std::string plugin, pluginopts; int index = nodes.size(); //first add some extra data before parsing 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++) { + std::string ps, password, method, server, port, group = SS_DEFAULT_GROUP; + std::string plugin, pluginopts; + server = GetMember(json["nodes"][i], "server"); if(server.empty()) continue; @@ -744,14 +745,15 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v nodeInfo node; Node singleproxy; unsigned int index = nodes.size(); - 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 plugin, pluginopts, pluginopts_mode, pluginopts_host, pluginopts_mux; //ss - std::string protocol, protoparam, obfs, obfsparam; //ssr - std::string user; //socks 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 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 protocol, protoparam, obfs, obfsparam; //ssr + std::string user; //socks + singleproxy = yamlnode[section][i]; singleproxy["type"] >> proxytype; 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 &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 configs, vArray, headers, header; std::multimap proxies; nodeInfo node; 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) { + 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 configs, vArray, headers, header; + remarks = x.first; configs = split(x.second, ","); 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; method = trim(configs[3]); password = trim(configs[4]); - plugin.clear(); 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") pluginopts_host = itemVal; } - if(plugin != "") + if(plugin.size()) { pluginopts = "obfs=" + pluginopts_mode; 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]); port = custom_port.empty() ? trim(configs[2]) : custom_port; - plugin.clear(); 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") pluginopts_host = itemVal; } - if(plugin != "") + if(plugin.size()) { pluginopts = "obfs=" + pluginopts_mode; 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) { header = split(trim(y), ":"); - if(header[0] == "Host") + if(regMatch(header[0], "(?i)host")) host = header[1]; - else if(header[0] == "Edge") + else if(regMatch(header[0], "(?i)edge")) 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(":"))); port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port; - plugin = protocol = remarks = ""; 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()) remarks = server + ":" + port; - if(plugin != "") + if(plugin.size()) { pluginopts = "obfs=" + pluginopts_mode; - pluginopts += pluginopts_host.empty() ? "" : ";obfs-host=" + pluginopts_host; + if(pluginopts_host.size()) + pluginopts += ";obfs-host=" + pluginopts_host; } 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(":"))); port = custom_port.empty() ? trim(configs[0].substr(configs[0].rfind(":") + 1)) : custom_port; - plugin = protocol = remarks = ""; net = "tcp"; 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; 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(); json.Parse(sstap.data()); 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++) { + 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]["remarks"] >> remarks; json["configs"][i]["server"] >> server;