From 9b32b72f0e6fe73e45d8be999c3b3a2102c23016 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Thu, 25 Mar 2021 11:00:26 +0800 Subject: [PATCH] Bugs fix Fix server_port fields become 0 in SIP008 and ShadowsocksD subscriptions. Fix parsed target not being passed to template argument. --- src/generator/config/subexport.cpp | 18 +++++++++--------- src/generator/config/subexport.h | 2 +- src/handler/interfaces.cpp | 2 ++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/generator/config/subexport.cpp b/src/generator/config/subexport.cpp index 3b38c61..c7d3e08 100644 --- a/src/generator/config/subexport.cpp +++ b/src/generator/config/subexport.cpp @@ -984,7 +984,7 @@ std::string proxyToSingle(std::vector &nodes, int types, extra_settings & return base64Encode(allLinks); } -std::string proxyToSSSub(std::string &base_conf, std::vector &nodes, extra_settings &ext) +std::string proxyToSSSub(std::string base_conf, std::vector &nodes, extra_settings &ext) { rapidjson::Document json, base; std::string remark, hostname, password, method; @@ -1002,6 +1002,9 @@ std::string proxyToSSSub(std::string &base_conf, std::vector &nodes, extr json.AddMember("plugin", "", alloc); json.AddMember("plugin_opts", "", alloc); + base_conf = trimWhitespace(base_conf); + if(base_conf.empty()) + base_conf = "{}"; rapidjson::ParseResult result = base.Parse(base_conf.data()); if(result) { @@ -1019,7 +1022,6 @@ std::string proxyToSSSub(std::string &base_conf, std::vector &nodes, extr { remark = x.Remark; hostname = x.Hostname; - int port = (unsigned short)to_int(GetMember(json, "Port")); std::string &password = x.Password; std::string &method = x.EncryptMethod; std::string &plugin = x.Plugin; @@ -1034,7 +1036,7 @@ std::string proxyToSSSub(std::string &base_conf, std::vector &nodes, extr plugin = "obfs-local"; break; case ProxyType::ShadowsocksR: - if(std::count(ss_ciphers.begin(), ss_ciphers.end(), method) > 0 && protocol == "origin" && obfs == "plain") + if(std::find(ss_ciphers.begin(), ss_ciphers.end(), method) == ss_ciphers.end() || protocol != "origin" || obfs != "plain") continue; break; default: @@ -1042,7 +1044,7 @@ std::string proxyToSSSub(std::string &base_conf, std::vector &nodes, extr } jsondata["remarks"].SetString(rapidjson::StringRef(remark.c_str(), remark.size())); jsondata["server"].SetString(rapidjson::StringRef(hostname.c_str(), hostname.size())); - jsondata["server_port"] = port; + jsondata["server_port"] = x.Port; jsondata["password"].SetString(rapidjson::StringRef(password.c_str(), password.size())); jsondata["method"].SetString(rapidjson::StringRef(method.c_str(), method.size())); jsondata["plugin"].SetString(rapidjson::StringRef(plugin.c_str(), plugin.size())); @@ -1628,10 +1630,9 @@ void proxyToQuanX(std::vector &nodes, INIReader &ini, std::vector &nodes, std::string &group, std::string &userinfo, extra_settings &ext) { - rapidjson::Document json; rapidjson::StringBuffer sb; rapidjson::Writer writer(sb); - int port, index = 0; + size_t index = 0; if(!group.size()) group = "SSD"; @@ -1670,7 +1671,6 @@ std::string proxyToSSD(std::vector &nodes, std::string &group, std::strin for(Proxy &x : nodes) { std::string &hostname = x.Hostname, &password = x.Password, &method = x.EncryptMethod, &plugin = x.Plugin, &pluginopts = x.PluginOption, &protocol = x.Protocol, &obfs = x.OBFS; - port = (unsigned short)to_int(GetMember(json, "Port")); switch(x.Type) { @@ -1681,7 +1681,7 @@ std::string proxyToSSD(std::vector &nodes, std::string &group, std::strin writer.Key("server"); writer.String(hostname.data()); writer.Key("port"); - writer.Int(port); + writer.Int(x.Port); writer.Key("encryption"); writer.String(method.data()); writer.Key("password"); @@ -1703,7 +1703,7 @@ std::string proxyToSSD(std::vector &nodes, std::string &group, std::strin writer.Key("server"); writer.String(hostname.data()); writer.Key("port"); - writer.Int(port); + writer.Int(x.Port); writer.Key("encryption"); writer.String(method.data()); writer.Key("password"); diff --git a/src/generator/config/subexport.h b/src/generator/config/subexport.h index 0d04f84..6c95f9c 100644 --- a/src/generator/config/subexport.h +++ b/src/generator/config/subexport.h @@ -58,7 +58,7 @@ std::string proxyToSurge(std::vector &nodes, const std::string &base_conf std::string proxyToMellow(std::vector &nodes, const std::string &base_conf, std::vector &ruleset_content_array, const string_array &extra_proxy_group, extra_settings &ext); void proxyToMellow(std::vector &nodes, INIReader &ini, std::vector &ruleset_content_array, const string_array &extra_proxy_group, extra_settings &ext); std::string proxyToLoon(std::vector &nodes, const std::string &base_conf, std::vector &ruleset_content_array, const string_array &extra_proxy_group, extra_settings &ext); -std::string proxyToSSSub(std::string &base_conf, std::vector &nodes, extra_settings &ext); +std::string proxyToSSSub(std::string base_conf, std::vector &nodes, extra_settings &ext); std::string proxyToSingle(std::vector &nodes, int types, extra_settings &ext); std::string proxyToQuanX(std::vector &nodes, const std::string &base_conf, std::vector &ruleset_content_array, const string_array &extra_proxy_group, extra_settings &ext); void proxyToQuanX(std::vector &nodes, INIReader &ini, std::vector &ruleset_content_array, const string_array &extra_proxy_group, extra_settings &ext); diff --git a/src/handler/interfaces.cpp b/src/handler/interfaces.cpp index 6514465..102b242 100644 --- a/src/handler/interfaces.cpp +++ b/src/handler/interfaces.cpp @@ -1393,6 +1393,8 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) continue; req_arg_map[x.substr(0, pos)] = x.substr(pos + 1); } + req_arg_map["target"] = argTarget; + req_arg_map["ver"] = std::to_string(intSurgeVer); /// save template variables template_args tpl_args;