Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions base/config/example_external_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
;custom_proxy_group=UnblockNeteaseMusic`select`云音乐解锁`[]DIRECT
;custom_proxy_group=Telegram`select`新加坡`[]Proxy
custom_proxy_group=!!import:snippets/groups_forcerule.txt
; Examples of using use and rule in custom_proxy_group
; custom_proxy_group=Hong Kong`select`.*`.*
; custom_proxy_group=Hong Kong`select`!!FILTER:(?i)港|hk|hongkong|hong kong`.*
; custom_proxy_group=Japan`select`!!PROVIDER:provider1`(?i)日本|jp|japan`[]Japan Auto
; custom_proxy_group=US`url-test`!!PROVIDER:provider2`(?i)美国|us|united states`http://www.gstatic.com/generate_204`300

;Options for custom rulesets
enable_rule_generator=false
Expand Down
18 changes: 18 additions & 0 deletions base/config/example_external_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ clash_rule_base = "base/forcerule.yml"
[[custom_groups]]
import = "snippets/groups_forcerule.toml"

# Example of using filter in custom_groups
[[custom_groups]]
name = "Hong Kong"
type = "select"
use = ["Subscription 1"]
filter = "(?i)港|hk|hongkong|hong kong"
rule = ["[]Hong Kong Auto"]

[[custom_groups]]
name = "Japan"
type = "url-test"
use = ["Subscription 1"]
filter = "(?i)日本|jp|japan"
rule = ["[]Japan Auto"]
url = "http://www.gstatic.com/generate_204"
interval = 300


#[[rulesets]]
#import = ""

Expand Down
19 changes: 19 additions & 0 deletions base/config/example_external_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ custom:
proxy_groups:
- {import: snippets/groups_forcerule.txt}

# Example of using filter in proxy_groups
- name: "Hong Kong"
type: "select"
use:
- "Subscription 1"
filter: "(?i)港|hk|hongkong|hong kong"
rule:
- "[]Hong Kong Auto"

- name: "Japan"
type: "url-test"
use:
- "Subscription 1"
filter: "(?i)日本|jp|japan"
rule:
- "[]Japan Auto"
url: "http://www.gstatic.com/generate_204"
interval: 300

# rulesets:
# - {import: snippets/ruleset_remote.txt}

Expand Down
5 changes: 5 additions & 0 deletions src/config/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace toml
conf.Timeout = find_or(v, "timeout", 5);
conf.Proxies = find_or<StrArray>(v, "rule", {});
conf.UsingProvider = find_or<StrArray>(v, "use", {});
conf.Filter = find_or<String>(v, "filter", "");
if(conf.Proxies.empty() && conf.UsingProvider.empty())
throw serialization_error(format_error("Proxy Group must contains at least one of proxy match rule or provider!", v.location(), "here"), v.location());
if(v.contains("disable-udp"))
Expand Down Expand Up @@ -254,6 +255,10 @@ namespace INIBinding
conf.UsingProvider.reserve(conf.UsingProvider.size() + list.size());
std::move(list.begin(), list.end(), std::back_inserter(conf.UsingProvider));
}
else if(startsWith(vArray[i], "!!FILTER:"))
{
conf.Filter = vArray[i].substr(9); // Remove "!!FILTER:" prefix
}
else
conf.Proxies.emplace_back(std::move(vArray[i]));
}
Expand Down
1 change: 1 addition & 0 deletions src/config/proxygroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct ProxyGroupConfig
Boolean DisableUdp;
Boolean Persistent;
Boolean EvaluateBeforeUse;
String Filter;

String TypeStr() const
{
Expand Down
3 changes: 3 additions & 0 deletions src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,9 @@ void proxyToClash(std::vector<Proxy> &nodes, YAML::Node &yamlnode, const ProxyGr
}
if(!filtered_nodelist.empty())
singlegroup["proxies"] = filtered_nodelist;

if(!x.Filter.empty())
singlegroup["filter"] = x.Filter;
if(group_block)
singlegroup.SetStyle(YAML::EmitterStyle::Block);
else
Expand Down
9 changes: 8 additions & 1 deletion src/handler/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void readGroup(YAML::Node node, string_array &dest, bool scope_limit = true)
dest.emplace_back("!!import:" + name);
continue;
}
std::string url = "http://www.gstatic.com/generate_204", interval = "300", tolerance, timeout;
std::string url = "http://www.gstatic.com/generate_204", interval = "300", tolerance, timeout, filter;
object["name"] >>= name;
object["type"] >>= type;
tempArray.emplace_back(name);
Expand All @@ -190,6 +190,7 @@ void readGroup(YAML::Node node, string_array &dest, bool scope_limit = true)
object["interval"] >>= interval;
object["tolerance"] >>= tolerance;
object["timeout"] >>= timeout;
object["filter"] >>= filter;
for(std::size_t j = 0; j < object["rule"].size(); j++)
tempArray.emplace_back(safe_as<std::string>(object["rule"][j]));
switch(hash_(type))
Expand All @@ -208,6 +209,12 @@ void readGroup(YAML::Node node, string_array &dest, bool scope_limit = true)
tempArray.emplace_back(url);
tempArray.emplace_back(interval + "," + timeout + "," + tolerance);
}

if(!filter.empty())
{
// Add filter as a special rule with !!FILTER: prefix
tempArray.emplace_back("!!FILTER:" + filter);
}

std::string strLine = join(tempArray, "`");
dest.emplace_back(std::move(strLine));
Expand Down