mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2025-10-26 10:52:21 +00:00
Add filter nodes by group or group ID
This commit is contained in:
16
main.cpp
16
main.cpp
@@ -188,6 +188,7 @@ int main()
|
||||
if(!url.size()) url = default_url;
|
||||
string_array urls = split(url, "|");
|
||||
std::vector<nodeInfo> nodes;
|
||||
int groupID = 0;
|
||||
if(include.size())
|
||||
{
|
||||
eraseElements(def_include_remarks);
|
||||
@@ -197,7 +198,8 @@ int main()
|
||||
for(std::string &x : urls)
|
||||
{
|
||||
std::cerr<<"Fetching node data from url '"<<x<<"'. Generate target: Clash"<<std::endl;
|
||||
addNodes(x, nodes);
|
||||
addNodes(x, nodes, groupID);
|
||||
groupID++;
|
||||
}
|
||||
if(fileExist(clash_rule_base))
|
||||
clash_base_content = fileGet(clash_rule_base, false);
|
||||
@@ -218,6 +220,7 @@ int main()
|
||||
if(!url.size()) url = default_url;
|
||||
string_array urls = split(url, "|");
|
||||
std::vector<nodeInfo> nodes;
|
||||
int groupID = 0;
|
||||
if(include.size())
|
||||
{
|
||||
eraseElements(def_include_remarks);
|
||||
@@ -227,7 +230,8 @@ int main()
|
||||
for(std::string &x : urls)
|
||||
{
|
||||
std::cerr<<"Fetching node data from url '"<<x<<"'. Generate target: ClashR"<<std::endl;
|
||||
addNodes(x, nodes);
|
||||
addNodes(x, nodes, groupID);
|
||||
groupID++;
|
||||
}
|
||||
if(fileExist(clash_rule_base))
|
||||
clash_base_content = fileGet(clash_rule_base, false);
|
||||
@@ -249,6 +253,7 @@ int main()
|
||||
if(!url.size()) url = default_url;
|
||||
string_array urls = split(url, "|");
|
||||
std::vector<nodeInfo> nodes;
|
||||
int groupID = 0;
|
||||
if(include.size())
|
||||
{
|
||||
eraseElements(def_include_remarks);
|
||||
@@ -258,12 +263,11 @@ int main()
|
||||
for(std::string &x : urls)
|
||||
{
|
||||
std::cerr<<"Fetching node data from url '"<<x<<"'. Generate target: Surge "<<surge_ver<<std::endl;
|
||||
addNodes(x, nodes);
|
||||
addNodes(x, nodes, groupID);
|
||||
groupID++;
|
||||
}
|
||||
if(fileExist(surge_rule_base))
|
||||
{
|
||||
surge_base_content = fileGet(surge_rule_base, false);
|
||||
}
|
||||
else
|
||||
surge_base_content = webGet(surge_rule_base, getSystemProxy());
|
||||
|
||||
@@ -286,7 +290,7 @@ int main()
|
||||
});
|
||||
}
|
||||
|
||||
listener_args args = {listen_address, listen_port, 10240, 4};
|
||||
listener_args args = {listen_address, listen_port, max_pending_connections, max_concurrent_threads};
|
||||
std::cout<<"Serving HTTP @ http://"<<listen_address<<":"<<listen_port<<std::endl;
|
||||
start_web_server_multi(&args);
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
struct nodeInfo
|
||||
{
|
||||
int linkType = -1;
|
||||
int id = 0;
|
||||
int id = -1;
|
||||
int groupID = -1;
|
||||
std::string group;
|
||||
std::string remarks;
|
||||
std::string server;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
std::string override_conf_port, custom_group;
|
||||
int socksport;
|
||||
bool ss_libev, ssr_libev;
|
||||
extern bool api_mode;
|
||||
|
||||
void copyNodes(std::vector<nodeInfo> *source, std::vector<nodeInfo> *dest)
|
||||
{
|
||||
@@ -20,7 +21,7 @@ void copyNodes(std::vector<nodeInfo> *source, std::vector<nodeInfo> *dest)
|
||||
}
|
||||
}
|
||||
|
||||
void addNodes(std::string link, std::vector<nodeInfo> &allNodes)
|
||||
void addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID)
|
||||
{
|
||||
int linkType = -1;
|
||||
std::vector<nodeInfo> nodes;
|
||||
@@ -67,6 +68,8 @@ void addNodes(std::string link, std::vector<nodeInfo> &allNodes)
|
||||
{
|
||||
writeLog(LOG_TYPE_INFO, "Parsing subscription data...");
|
||||
explodeConfContent(strSub, override_conf_port, socksport, ss_libev, ssr_libev, nodes);
|
||||
for(nodeInfo &x : nodes)
|
||||
x.groupID = groupID;
|
||||
copyNodes(&nodes, &allNodes);
|
||||
}
|
||||
else
|
||||
@@ -75,6 +78,8 @@ void addNodes(std::string link, std::vector<nodeInfo> &allNodes)
|
||||
}
|
||||
break;
|
||||
case SPEEDTEST_MESSAGE_FOUNDLOCAL:
|
||||
if(api_mode)
|
||||
break;
|
||||
writeLog(LOG_TYPE_INFO, "Parsing configuration file data...");
|
||||
if(explodeConf(link, override_conf_port, socksport, ss_libev, ssr_libev, nodes) == SPEEDTEST_ERROR_UNRECOGFILE)
|
||||
{
|
||||
@@ -82,6 +87,8 @@ void addNodes(std::string link, std::vector<nodeInfo> &allNodes)
|
||||
}
|
||||
else
|
||||
{
|
||||
for(nodeInfo &x : nodes)
|
||||
x.groupID = groupID;
|
||||
copyNodes(&nodes, &allNodes);
|
||||
}
|
||||
break;
|
||||
@@ -97,6 +104,7 @@ void addNodes(std::string link, std::vector<nodeInfo> &allNodes)
|
||||
}
|
||||
else
|
||||
{
|
||||
node.groupID = groupID;
|
||||
allNodes.push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
|
||||
#include "nodeinfo.h"
|
||||
|
||||
void addNodes(std::string link, std::vector<nodeInfo> &allNodes);
|
||||
void addNodes(std::string link, std::vector<nodeInfo> &allNodes, int groupID);
|
||||
|
||||
#endif // NODEMANIP_H_INCLUDED
|
||||
|
||||
6
pref.ini
6
pref.ini
@@ -103,6 +103,10 @@ surge_ruleset=💕 规则自选,[]MATCH
|
||||
;custom_proxy_group=FallBack`fallback`.*`http://www.gstatic.com/generate_204`300
|
||||
;custom_proxy_group=LoadBalance`load-balance`.*`http://www.gstatic.com/generate_204`300
|
||||
|
||||
;custom_proxy_group=g1`select`!!GROUPID=0
|
||||
;custom_proxy_group=g2`select`!!GROUPID=1
|
||||
;custom_proxy_group=v2ray`select`!!GROUP=V2RayProvider
|
||||
|
||||
;for forcerule.yml
|
||||
;custom_proxy_group=Proxy`select`.*[]AUTO`[]DIRECT`.*
|
||||
;custom_proxy_group=AUTO`url-test`.*`http://www.gstatic.com/generate_204`300
|
||||
@@ -142,5 +146,5 @@ listen=0.0.0.0
|
||||
port=25500
|
||||
|
||||
[advanced]
|
||||
max_pending_connections=10
|
||||
max_pending_connections=10240
|
||||
max_concurrent_threads=4
|
||||
|
||||
@@ -165,19 +165,19 @@ void explodeVmess(std::string vmess, std::string custom_port, int local_port, no
|
||||
version = "1"; //link without version will treat as version 1
|
||||
GetMember(jsondata, "v", version); //try to get version
|
||||
|
||||
jsondata["ps"] >> ps;
|
||||
jsondata["add"] >> add;
|
||||
jsondata["type"] >> type;
|
||||
jsondata["id"] >> id;
|
||||
jsondata["aid"] >> aid;
|
||||
jsondata["net"] >> net;
|
||||
jsondata["tls"] >> tls;
|
||||
GetMember(jsondata, "ps", ps);
|
||||
GetMember(jsondata, "add", add);
|
||||
GetMember(jsondata, "type", type);
|
||||
GetMember(jsondata, "id", id);
|
||||
GetMember(jsondata, "aid", aid);
|
||||
GetMember(jsondata, "net", net);
|
||||
GetMember(jsondata, "tls", tls);
|
||||
if(custom_port != "")
|
||||
port = custom_port;
|
||||
else
|
||||
jsondata["port"] >> port;
|
||||
GetMember(jsondata, "port", port);
|
||||
|
||||
jsondata["host"] >> host;
|
||||
GetMember(jsondata, "host", host);
|
||||
if(version == "1")
|
||||
{
|
||||
if(host != "")
|
||||
@@ -872,24 +872,12 @@ void explodeClash(Node yamlnode, std::string custom_port, int local_port, std::v
|
||||
yamlnode["Proxy"][i]["password"] >> password;
|
||||
if(yamlnode["Proxy"][i]["plugin"].IsDefined())
|
||||
{
|
||||
if(yamlnode["Proxy"][i]["plugin"].as<std::string>() == "obfs")
|
||||
yamlnode["Proxy"][i]["plugin"] >> plugin;
|
||||
if(yamlnode["Proxy"][i]["plugin-opts"].IsDefined())
|
||||
{
|
||||
plugin = "simple-obfs";
|
||||
if(yamlnode["Proxy"][i]["plugin-opts"].IsDefined())
|
||||
{
|
||||
yamlnode["Proxy"][i]["plugin-opts"]["mode"] >> pluginopts_mode;
|
||||
if(yamlnode["Proxy"][i]["plugin-opts"]["host"].IsDefined())
|
||||
yamlnode["Proxy"][i]["plugin-opts"]["host"] >> pluginopts_host;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(yamlnode["Proxy"][i]["obfs"].IsDefined())
|
||||
{
|
||||
plugin = "simple-obfs";
|
||||
yamlnode["Proxy"][i]["obfs"] >> pluginopts_mode;
|
||||
if(yamlnode["Proxy"][i]["obfs-host"].IsDefined())
|
||||
{
|
||||
yamlnode["Proxy"][i]["obfs-host"] >> pluginopts_host;
|
||||
yamlnode["Proxy"][i]["plugin-opts"]["mode"] >> pluginopts_mode;
|
||||
if(yamlnode["Proxy"][i]["plugin-opts"]["host"].IsDefined())
|
||||
yamlnode["Proxy"][i]["plugin-opts"]["host"] >> pluginopts_host;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -286,7 +286,8 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &baseConf, st
|
||||
std::string plugin, pluginopts;
|
||||
std::string protocol, protoparam, obfs, obfsparam;
|
||||
std::string id, aid, transproto, faketype, host, path, quicsecure, quicsecret;
|
||||
std::vector<std::string> nodelist;
|
||||
std::vector<nodeInfo> nodelist;
|
||||
std::string group;
|
||||
bool tlssecure, replace_flag;
|
||||
string_array vArray, filtered_nodelist;
|
||||
|
||||
@@ -305,7 +306,7 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &baseConf, st
|
||||
singleproxy.reset();
|
||||
json.Parse(x.proxyStr.data());
|
||||
type = GetMember(json, "Type");
|
||||
remark = addEmoji(trim(removeEmoji(nodeRename(x.remarks))));
|
||||
remark = x.remarks = addEmoji(trim(removeEmoji(nodeRename(x.remarks))));
|
||||
hostname = GetMember(json, "Hostname");
|
||||
port = GetMember(json, "Port");
|
||||
username = GetMember(json, "Username");
|
||||
@@ -378,7 +379,7 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &baseConf, st
|
||||
singleproxy["server"] = hostname;
|
||||
singleproxy["port"] = (unsigned short)stoi(port);
|
||||
proxies.push_back(singleproxy);
|
||||
nodelist.emplace_back(remark);
|
||||
nodelist.emplace_back(x);
|
||||
}
|
||||
|
||||
yamlnode["Proxy"] = proxies;
|
||||
@@ -439,12 +440,30 @@ std::string netchToClash(std::vector<nodeInfo> &nodes, std::string &baseConf, st
|
||||
{
|
||||
filtered_nodelist.emplace_back(vArray[i].substr(2));
|
||||
}
|
||||
else if(vArray[i].find("!!GROUP=") == 0)
|
||||
{
|
||||
group = vArray[i].substr(8);
|
||||
for(nodeInfo &y : nodelist)
|
||||
{
|
||||
if(regFind(y.group, group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y.remarks);
|
||||
}
|
||||
}
|
||||
else if(vArray[i].find("!!GROUPID=") == 0)
|
||||
{
|
||||
group = vArray[i].substr(10);
|
||||
for(nodeInfo &y : nodelist)
|
||||
{
|
||||
if(y.groupID == stoi(group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y.remarks);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(std::string &y : nodelist)
|
||||
for(nodeInfo &y : nodelist)
|
||||
{
|
||||
if(regFind(y, vArray[i]) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y);
|
||||
if(regFind(y.remarks, vArray[i]) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y.remarks);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,8 +503,8 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
std::string type, remark, hostname, port, username, password, method;
|
||||
std::string plugin, pluginopts;
|
||||
std::string id, aid, transproto, faketype, host, path, quicsecure, quicsecret;
|
||||
std::string url;
|
||||
std::vector<std::string> nodelist;
|
||||
std::string url, group;
|
||||
std::vector<nodeInfo> nodelist;
|
||||
bool tlssecure;
|
||||
string_array vArray, filtered_nodelist;
|
||||
|
||||
@@ -500,7 +519,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
{
|
||||
json.Parse(x.proxyStr.data());
|
||||
type = GetMember(json, "Type");
|
||||
remark = addEmoji(trim(removeEmoji(nodeRename(x.remarks))));
|
||||
remark = x.remarks = addEmoji(trim(removeEmoji(nodeRename(x.remarks))));
|
||||
hostname = GetMember(json, "Hostname");
|
||||
port = std::__cxx11::to_string((unsigned short)stoi(GetMember(json, "Port")));
|
||||
username = GetMember(json, "Username");
|
||||
@@ -565,7 +584,7 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
else
|
||||
continue;
|
||||
ini.Set(remark, proxy);
|
||||
nodelist.emplace_back(remark);
|
||||
nodelist.emplace_back(x);
|
||||
}
|
||||
|
||||
ini.SetCurrentSection("Proxy Group");
|
||||
@@ -600,12 +619,30 @@ std::string netchToSurge(std::vector<nodeInfo> &nodes, std::string &base_conf, s
|
||||
{
|
||||
filtered_nodelist.emplace_back(vArray[i].substr(2));
|
||||
}
|
||||
else if(vArray[i].find("!!GROUP=") == 0)
|
||||
{
|
||||
group = vArray[i].substr(8);
|
||||
for(nodeInfo &y : nodelist)
|
||||
{
|
||||
if(regFind(y.group, group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y.remarks);
|
||||
}
|
||||
}
|
||||
else if(vArray[i].find("!!GROUPID=") == 0)
|
||||
{
|
||||
group = vArray[i].substr(10);
|
||||
for(nodeInfo &y : nodelist)
|
||||
{
|
||||
if(y.groupID == stoi(group) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y.remarks);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(std::string &y : nodelist)
|
||||
for(nodeInfo &y : nodelist)
|
||||
{
|
||||
if(regFind(y, vArray[i]) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y);
|
||||
if(regFind(y.remarks, vArray[i]) && std::find(filtered_nodelist.begin(), filtered_nodelist.end(), y.remarks) == filtered_nodelist.end())
|
||||
filtered_nodelist.emplace_back(y.remarks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user