mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-01 17:25:02 +00:00
Enhancements
Add support for exporting Surfboard subscription. Improve compatibility for subscriptions that contain duplicate node names.
This commit is contained in:
5 files changed
+65
-62
No files matched your search
@@ -20,7 +20,7 @@ string_array def_exclude_remarks, def_include_remarks, rulesets;
|
||||
std::vector<ruleset_content> ruleset_content_array;
|
||||
std::string listen_address = "127.0.0.1", default_url, managed_config_prefix;
|
||||
int listen_port = 25500, max_pending_connections = 10, max_concurrent_threads = 4;
|
||||
bool api_mode = true, write_managed_config = true, update_ruleset_on_request = false, overwrite_original_rules = true;
|
||||
bool api_mode = true, write_managed_config = false, update_ruleset_on_request = false, overwrite_original_rules = true;
|
||||
extern std::string custom_group;
|
||||
|
||||
//safety lock for multi-thread
|
||||
@@ -36,28 +36,28 @@ std::string clash_rule_base;
|
||||
string_array clash_extra_group;
|
||||
|
||||
//surge custom
|
||||
std::string surge_rule_base;
|
||||
std::string surge_rule_base, surfboard_rule_base;
|
||||
|
||||
void setcd(char *argv[])
|
||||
{
|
||||
#ifndef _WIN32
|
||||
std::string path, prgpath;
|
||||
std::string path;
|
||||
char szTmp[1024];
|
||||
prgpath.assign(argv[0]);
|
||||
if(prgpath[0] == '/')
|
||||
{
|
||||
path = prgpath.substr(0, prgpath.rfind("/") + 1);
|
||||
}
|
||||
else
|
||||
#ifndef _WIN32
|
||||
path.assign(argv[0]);
|
||||
if(path[0] != '/')
|
||||
{
|
||||
getcwd(szTmp, 1023);
|
||||
path.append(szTmp);
|
||||
path.assign(szTmp);
|
||||
path.append("/");
|
||||
path.append(argv[0]);
|
||||
path = path.substr(0, path.rfind("/") + 1);
|
||||
}
|
||||
chdir(path.data());
|
||||
path = path.substr(0, path.rfind("/") + 1);
|
||||
#else
|
||||
GetModuleFileName(NULL, szTmp, 1023);
|
||||
strrchr(szTmp, '\\')[1] = '\0';
|
||||
path.assign(szTmp);
|
||||
#endif // _WIN32
|
||||
chdir(path.data());
|
||||
}
|
||||
|
||||
std::string refreshRulesets()
|
||||
@@ -135,6 +135,8 @@ void readConf()
|
||||
clash_rule_base = ini.Get("clash_rule_base");
|
||||
if(ini.ItemExist("surge_rule_base"))
|
||||
surge_rule_base = ini.Get("surge_rule_base");
|
||||
if(ini.ItemExist("surfboard_rule_base"))
|
||||
surfboard_rule_base = ini.Get("surfboard_rule_base");
|
||||
if(ini.ItemPrefixExist("rename_node"))
|
||||
ini.GetAll("rename_node", renames);
|
||||
|
||||
@@ -249,6 +251,22 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
output_content = "#!MANAGED-CONFIG " + managed_config_prefix + "/sub?" + argument + "\n\n" + output_content;
|
||||
return output_content;
|
||||
}
|
||||
else if(target == "surfboard")
|
||||
{
|
||||
std::cerr<<"Surfboard"<<std::endl;
|
||||
if(fileExist(surfboard_rule_base))
|
||||
base_content = fileGet(surfboard_rule_base, false);
|
||||
else
|
||||
base_content = webGet(surfboard_rule_base, getSystemProxy());
|
||||
|
||||
output_content = netchToSurge(nodes, base_content, rulesets, clash_extra_group, 2);
|
||||
if(upload == "true")
|
||||
uploadGist("surfboard", output_content, true);
|
||||
|
||||
if(write_managed_config && managed_config_prefix.size())
|
||||
output_content = "#!MANAGED-CONFIG " + managed_config_prefix + "/sub?" + argument + "\n\n" + output_content;
|
||||
return output_content;
|
||||
}
|
||||
else if(target == "ss")
|
||||
{
|
||||
std::cerr<<"SS"<<std::endl;
|
||||
@@ -316,7 +334,9 @@ int main(int argc, char *argv[])
|
||||
SetConsoleOutputCP(65001);
|
||||
#endif // _WIN32
|
||||
|
||||
#ifndef _DEBUG
|
||||
setcd(argv);
|
||||
#endif // _DEBUG
|
||||
readConf();
|
||||
if(!update_ruleset_on_request)
|
||||
refreshRulesets();
|
||||
@@ -349,6 +369,11 @@ int main(int argc, char *argv[])
|
||||
return subconverter(argument + "&target=surge", postdata);
|
||||
});
|
||||
|
||||
append_response("GET", "/surfboard", "text/plain;charset=utf-8", [](RESPONSE_CALLBACK_ARGS) -> std::string
|
||||
{
|
||||
return subconverter(argument + "&target=surfboard", postdata);
|
||||
});
|
||||
|
||||
append_response("GET", "/ss", "text/plain", [](RESPONSE_CALLBACK_ARGS) -> std::string
|
||||
{
|
||||
return subconverter(argument + "&target=ss", postdata);
|
||||
|
||||
@@ -18,6 +18,9 @@ clash_rule_base=simple_base.yml
|
||||
;Surge config base used by the generator, supports local files/URL
|
||||
surge_rule_base=surge.conf
|
||||
|
||||
;Surfboard config base used by the generator, supports local files/URL
|
||||
surfboard_rule_base=surfboard.conf
|
||||
|
||||
;Rename remarks with the following patterns. Supports regular expression.
|
||||
;Format: Search_Pattern@Replace_Pattern
|
||||
;rename_node=IPLC@专线
|
||||
|
||||
@@ -1581,12 +1581,3 @@ void remarksInit(string_array &exclude, string_array &include)
|
||||
exclude_remarks = exclude;
|
||||
include_remarks = include;
|
||||
}
|
||||
|
||||
int appendClashRules(YAML::Node &base, YAML::Node &rules)
|
||||
{
|
||||
if(rules["Proxy Group"].IsDefined())
|
||||
base["Proxy Group"].reset(rules["Proxy Group"]);
|
||||
if(rules["Rule"].IsDefined())
|
||||
base["Rule"].reset(rules["Rule"]);
|
||||
return 0;
|
||||
}
|
||||
+16
-40
@@ -343,7 +343,7 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &baseConf, st
|
||||
std::vector<nodeInfo> nodelist;
|
||||
std::string group;
|
||||
bool tlssecure, replace_flag;
|
||||
string_array vArray, filtered_nodelist;
|
||||
string_array vArray, remarks_list, filtered_nodelist;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -359,7 +359,9 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &baseConf, st
|
||||
singleproxy.reset();
|
||||
json.Parse(x.proxyStr.data());
|
||||
type = GetMember(json, "Type");
|
||||
remark = x.remarks = addEmoji(trim(removeEmoji(nodeRename(x.remarks))));
|
||||
remark = x.remarks = addEmoji("[" + type + "]" + trim(removeEmoji(nodeRename(x.remarks))));
|
||||
while(std::count(remarks_list.begin(), remarks_list.end(), remark) > 0)
|
||||
remark = x.remarks = x.remarks + "$";
|
||||
hostname = GetMember(json, "Hostname");
|
||||
port = GetMember(json, "Port");
|
||||
username = GetMember(json, "Username");
|
||||
@@ -431,35 +433,14 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &baseConf, st
|
||||
singleproxy["name"] = remark;
|
||||
singleproxy["server"] = hostname;
|
||||
singleproxy["port"] = (unsigned short)stoi(port);
|
||||
singleproxy.SetStyle(YAML::EmitterStyle::Flow);
|
||||
proxies.push_back(singleproxy);
|
||||
remarks_list.emplace_back(remark);
|
||||
nodelist.emplace_back(x);
|
||||
}
|
||||
|
||||
yamlnode["Proxy"] = proxies;
|
||||
std::string groupname;
|
||||
/*
|
||||
if(!overwrite_original_groups)
|
||||
{
|
||||
original_groups = yamlnode["Proxy Group"];
|
||||
for(unsigned int i = 0; i < original_groups.size(); i++)
|
||||
{
|
||||
groupname = original_groups[i]["name"].as<std::string>();
|
||||
if(groupname == "Proxy" || groupname == "PROXY")
|
||||
{
|
||||
original_groups[i]["name"] = "Proxy";
|
||||
original_groups[i]["proxies"] = vectorToNode(nodelist);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
singlegroup["name"] = "Proxy";
|
||||
singlegroup["type"] = "select";
|
||||
singlegroup["proxies"] = vectorToNode(nodelist);
|
||||
original_groups.push_back(singlegroup);
|
||||
}
|
||||
*/
|
||||
|
||||
for(std::string &x : extra_proxy_group)
|
||||
{
|
||||
@@ -559,7 +540,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
std::string url, group;
|
||||
std::vector<nodeInfo> nodelist;
|
||||
bool tlssecure;
|
||||
string_array vArray, filtered_nodelist;
|
||||
string_array vArray, remarks_list, filtered_nodelist;
|
||||
|
||||
ini.store_any_line = true;
|
||||
if(ini.Parse(base_conf) != 0)
|
||||
@@ -572,7 +553,9 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
{
|
||||
json.Parse(x.proxyStr.data());
|
||||
type = GetMember(json, "Type");
|
||||
remark = x.remarks = addEmoji(trim(removeEmoji(nodeRename(x.remarks))));
|
||||
remark = x.remarks = addEmoji("[" + type + "]" + trim(removeEmoji(nodeRename(x.remarks))));
|
||||
while(std::count(remarks_list.begin(), remarks_list.end(), remark) > 0)
|
||||
remark = x.remarks = x.remarks + "$";
|
||||
hostname = GetMember(json, "Hostname");
|
||||
port = std::__cxx11::to_string((unsigned short)stoi(GetMember(json, "Port")));
|
||||
username = GetMember(json, "Username");
|
||||
@@ -582,26 +565,18 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
|
||||
if(type == "SS")
|
||||
{
|
||||
plugin = GetMember(json, "Plugin");
|
||||
pluginopts = GetMember(json, "PluginOption");
|
||||
if(surge_ver >= 3)
|
||||
{
|
||||
plugin = GetMember(json, "Plugin");
|
||||
pluginopts = GetMember(json, "PluginOption");
|
||||
proxy = "ss," + hostname + "," + port + ",encrypt-method=" + method + ",password=" + password;
|
||||
if(plugin.size() && pluginopts.size())
|
||||
{
|
||||
proxy += "," + replace_all_distinct(pluginopts, ";", ",");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(GetMember(json, "Plugin") == "")
|
||||
{
|
||||
proxy = "custom," + hostname + "," + port + "," + method + "," + password + ",https://github.com/ConnersHua/SSEncrypt/raw/master/SSEncrypt.module";
|
||||
}
|
||||
else
|
||||
continue;
|
||||
proxy = "custom," + hostname + "," + port + "," + method + "," + password + ",https://github.com/ConnersHua/SSEncrypt/raw/master/SSEncrypt.module";
|
||||
}
|
||||
|
||||
if(plugin.size() && pluginopts.size())
|
||||
proxy += "," + replace_all_distinct(pluginopts, ";", ",");
|
||||
}
|
||||
else if(type == "VMess")
|
||||
{
|
||||
@@ -638,6 +613,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
continue;
|
||||
ini.Set(remark, proxy);
|
||||
nodelist.emplace_back(x);
|
||||
remarks_list.emplace_back(remark);
|
||||
}
|
||||
|
||||
ini.SetCurrentSection("Proxy Group");
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[General]
|
||||
loglevel = notify
|
||||
interface = 127.0.0.1
|
||||
skip-proxy = 127.0.0.1, 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 100.64.0.0/10, localhost, *.local
|
||||
ipv6 = false
|
||||
dns-server = system, 223.5.5.5
|
||||
exclude-simple-hostnames = true
|
||||
enhanced-mode-by-rule = true
|
||||
Reference in new issue
Block a user