Fix incorrect generation of Surge 4 VMess configurations.

This commit is contained in:
Tindy X committed 2019-11-25 23:01:30 +08:00
1 parent 81dfeac556
commit f31508c72c
1 file changed
+9 -13
+9 -13
View File
@@ -24,6 +24,8 @@ std::string vmessConstruct(std::string add, std::string port, std::string type,
port = "0";
if(!path.size())
path = "/";
if(!host.size())
host = add;
rapidjson::StringBuffer sb;
rapidjson::Writer<rapidjson::StringBuffer> writer(sb);
writer.StartObject();
@@ -336,6 +338,7 @@ void rulesetToSurge(INIReader &base_rule, std::vector<ruleset_content> &ruleset_
strLine = regReplace(strLine, "^(.*)(,no-resolve)(.*)$", "$1$3$2");
else if(strLine.find("DOMAIN-SUFFIX") == 0)
strLine = regReplace(strLine, "^(.*)(,force-remote-dns)(.*)$", "$1$3$2");
//strLine = regReplace(strLine, "^(.*?)(,.*?)(,.*)(,.*)$", "$1$2$4$3")
allRules.emplace_back(strLine);
}
}
@@ -599,7 +602,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
method = GetMember(json, "EncryptMethod");
proxy = "";
if(type == "SS")
if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSS)
{
plugin = GetMember(json, "Plugin");
pluginopts = GetMember(json, "PluginOption");
@@ -614,7 +617,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
if(plugin.size() && pluginopts.size())
proxy += "," + replace_all_distinct(pluginopts, ";", ",");
}
else if(type == "VMess")
else if(x.linkType == SPEEDTEST_MESSAGE_FOUNDVMESS)
{
if(surge_ver < 4)
continue;
@@ -624,18 +627,18 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
host = GetMember(json, "Host");
path = GetMember(json, "Path");
tlssecure = GetMember(json, "TLSSecure") == "true";
proxy = "vmess," + hostname + "," + port + "," + method + ",username=" + id + ",tls=" + (tlssecure ? "true" : "false");
proxy = "vmess, " + hostname + ", " + port + ", username=" + id + ", tls=" + (tlssecure ? "true" : "false");
if(transproto == "ws")
{
proxy += ",ws=true,ws-path=" + path;
proxy += ", ws=true, ws-path=" + path + ", ws-headers=Host:" + host;
}
else if(transproto == "kcp" || transproto == "h2" || transproto == "quic")
continue;
}
else if(type == "Socks5")
else if(x.linkType == SPEEDTEST_MESSAGE_FOUNDSOCKS)
{
proxy = "socks5, " + hostname + ", " + port;
if(username != "" && password != "")
if(username.size() && password.size())
proxy += ", " + username + ", " + password;
}
else if(type == "HTTP" || type == "HTTPS")
@@ -1282,13 +1285,6 @@ std::string netchToMellow(std::vector<nodeInfo> &nodes, std::string &base_conf,
rulesetToSurge(ini, ruleset_content_array, 2);
string_multimap rules;
ini.GetItems("Rules", rules);
ini.EraseSection("Rules");
ini.SetCurrentSection("RoutingRule");
for(auto &x : rules)
ini.Set("{NONAME}", x.second);
return ini.ToString();
}