Skip to content

Commit dd71849

Browse files
zxlhhycccvernesong
andauthored
add 'fake-ip-filter-mode' in 'dns' (#4011)
* add fake-ip-filter-mode in dns * chore: refine code --------- Co-authored-by: vernesong <[email protected]>
1 parent dbd2bbc commit dd71849

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

luci-app-openclash/luasrc/model/cbi/openclash/config-overwrite.lua

+7
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ if op_mode == "fake-ip" then
226226
o = s:taboption("dns", Flag, "custom_fakeip_filter", translate("Fake-IP-Filter"))
227227
o.default = 0
228228

229+
o = s:taboption("dns", ListValue, "custom_fakeip_filter_mode", translate("Fake-IP-Filter-Mode"))
230+
o.description = translate("Fake-IP is not returned if the matching succeeds when blacklist mode or Fake-IP is returned if the matching succeeds when whitelist mode")
231+
o.default = "blacklist"
232+
o:value("blacklist", translate("Blacklist Mode"))
233+
o:value("whitelist", translate("Whitelist Mode"))
234+
o:depends("custom_fakeip_filter", "1")
235+
229236
custom_fake_black = s:taboption("dns", Value, "custom_fake_filter")
230237
custom_fake_black.template = "cbi/tvalue"
231238
custom_fake_black.description = translate("Domain Names In The List Do Not Return Fake-IP, One rule per line")

luci-app-openclash/po/zh-cn/openclash.zh-cn.po

+15
Original file line numberDiff line numberDiff line change
@@ -3356,3 +3356,18 @@ msgstr "指定正确的 LAN 接口名称"
33563356

33573357
msgid "For More Useful Meta Core Functions Go Wiki"
33583358
msgstr "如需要了解更多关于 Meta 内核的功能,请前往 Wiki"
3359+
3360+
msgid "Tip: Because Need Ensure Bypassing IP Option Work, Deleted The Fake-IP-Filter Rule"
3361+
msgstr "提示:为保证绕过 IP 正常工作,已在 Fake-IP-Filter 中删除规则"
3362+
3363+
msgid "Tip: Because Need Ensure Bypassing IP Option Work, Added The Fake-IP-Filter Rule"
3364+
msgstr "提示:为保证绕过 IP 正常工作,已在 Fake-IP-Filter 中添加规则"
3365+
3366+
msgid "Fake-IP is not returned if the matching succeeds when blacklist mode or Fake-IP is returned if the matching succeeds when whitelist mode"
3367+
msgstr "黑名单模式表示如果匹配成功则不返回 Fake-IP, 白名单模式时只有匹配成功才返回 Fake-IP"
3368+
3369+
msgid "Blacklist Mode"
3370+
msgstr "黑名单模式"
3371+
3372+
msgid "Whitelist Mode"
3373+
msgstr "白名单模式"

luci-app-openclash/root/etc/init.d/openclash

+2-1
Original file line numberDiff line numberDiff line change
@@ -2880,6 +2880,7 @@ get_config()
28802880
keep_alive_interval=$(uci -q get openclash.config.keep_alive_interval || echo "0")
28812881
proxy_dns_group=$(uci -q get openclash.config.proxy_dns_group || echo "Disable")
28822882
intranet_allowed_wan_name=$(uci -q get openclash.config.intranet_allowed_wan_name || echo "0")
2883+
custom_fakeip_filter_mode=$(uci -q get openclash.config.custom_fakeip_filter_mode || echo "blacklist")
28832884
[ -z "$dns_port" ] && dns_port=7874 && uci -q set openclash.config.dns_port=7874
28842885
uci -q commit openclash
28852886
}
@@ -2907,7 +2908,7 @@ start()
29072908
if ! $quick_start; then
29082909
LOG_OUT "Step 3: Modify The Config File..."
29092910
config_check
2910-
/usr/share/openclash/yml_change.sh 2>/dev/null "$en_mode" "$da_password" "$cn_port" "$proxy_port" "$TMP_CONFIG_FILE" "$ipv6_enable" "$http_port" "$socks_port" "$log_level" "$proxy_mode" "$en_mode_tun" "$stack_type" "$dns_port" "$mixed_port" "$tproxy_port" "$ipv6_dns" "$store_fakeip" "$enable_meta_sniffer" "$enable_geoip_dat" "$geodata_loader" "$enable_meta_sniffer_custom" "$interface_name" "$enable_tcp_concurrent" "$core_type" "$append_default_dns" "$enable_meta_sniffer_pure_ip" "$find_process_mode" "$fakeip_range" "$global_client_fingerprint" "$ipv6_mode" "$stack_type_v6" "$enable_unified_delay" "$keep_alive_interval" "$proxy_dns_group"
2911+
/usr/share/openclash/yml_change.sh 2>/dev/null "$en_mode" "$da_password" "$cn_port" "$proxy_port" "$TMP_CONFIG_FILE" "$ipv6_enable" "$http_port" "$socks_port" "$log_level" "$proxy_mode" "$en_mode_tun" "$stack_type" "$dns_port" "$mixed_port" "$tproxy_port" "$ipv6_dns" "$store_fakeip" "$enable_meta_sniffer" "$enable_geoip_dat" "$geodata_loader" "$enable_meta_sniffer_custom" "$interface_name" "$enable_tcp_concurrent" "$core_type" "$append_default_dns" "$enable_meta_sniffer_pure_ip" "$find_process_mode" "$fakeip_range" "$global_client_fingerprint" "$ipv6_mode" "$stack_type_v6" "$enable_unified_delay" "$keep_alive_interval" "$proxy_dns_group" "$custom_fakeip_filter_mode"
29112912
/usr/share/openclash/yml_rules_change.sh 2>/dev/null "$rule_source" "$enable_custom_clash_rules" "$TMP_CONFIG_FILE" "$enable_rule_proxy" "$CONFIG_NAME" "$router_self_proxy" "$lan_ip" "$proxy_port" "$tproxy_port" "$enable_redirect_dns" "$fakeip_range" "$en_mode"
29122913
/usr/share/openclash/openclash_custom_domain_dns.sh >/dev/null 2>&1
29132914
#Custom overwrite

luci-app-openclash/root/usr/share/openclash/res/default.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ dns:
106106
# fake-ip-filter:
107107
# - '*.lan'
108108
# - localhost.ptlogin2.qq.com
109+
110+
# The matching mode of fake-ip-filter is set to a blacklist by default.
111+
# That is, fake-ip is not returned if the matching succeeds
112+
# It can be set to whitelist, that is, fake-ip is returned only after the match is successful
113+
fake-ip-filter-mode: blacklist
109114

110115
# Supports UDP, TCP, DoT, DoH. You can specify the port to connect to.
111116
# All DNS questions are sent directly to the nameserver, without proxies
@@ -469,4 +474,4 @@ rules:
469474
- DST-PORT,80,DIRECT
470475
- SRC-PORT,7777,DIRECT
471476
- RULE-SET,apple,REJECT # Premium only
472-
- MATCH,auto
477+
- MATCH,auto

luci-app-openclash/root/usr/share/openclash/yml_change.sh

+22-5
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ end;
675675
begin
676676
Thread.new{
677677
if '$custom_fakeip_filter' == '1' then
678+
if '${35}' == 'whitelist' then
679+
Value['dns']['fake-ip-filter-mode']='whitelist';
680+
else
681+
Value['dns']['fake-ip-filter-mode']='blacklist';
682+
end;
678683
if '$1' == 'fake-ip' then
679684
if File::exist?('/etc/openclash/custom/openclash_custom_fake_filter.list') then
680685
Value_4 = IO.readlines('/etc/openclash/custom/openclash_custom_fake_filter.list');
@@ -702,12 +707,24 @@ Thread.new{
702707
end;
703708
if '$1' == 'fake-ip' then
704709
if '$china_ip_route' != '0' then
705-
if Value['dns'].has_key?('fake-ip-filter') and not Value['dns']['fake-ip-filter'].to_a.empty? then
706-
Value['dns']['fake-ip-filter'].insert(-1,'geosite:category-games@cn');
707-
Value['dns']['fake-ip-filter'].insert(-1,'geosite:cn');
708-
Value['dns']['fake-ip-filter']=Value['dns']['fake-ip-filter'].uniq;
710+
if Value['dns']['fake-ip-filter-mode'] == 'blacklist' or not Value['dns'].has_key?('fake-ip-filter-mode') then
711+
if Value['dns'].has_key?('fake-ip-filter') and not Value['dns']['fake-ip-filter'].to_a.empty? then
712+
Value['dns']['fake-ip-filter'].insert(-1,'geosite:category-games@cn');
713+
Value['dns']['fake-ip-filter'].insert(-1,'geosite:cn');
714+
Value['dns']['fake-ip-filter']=Value['dns']['fake-ip-filter'].uniq;
715+
else
716+
Value['dns'].merge!({'fake-ip-filter'=>['geosite:category-games@cn,geosite:cn']});
717+
end;
718+
puts '${LOGTIME} Tip: Because Need Ensure Bypassing IP Option Work, Added The Fake-IP-Filter Rule【 geosite:category-games@cn,geosite:cn 】';
709719
else
710-
Value['dns'].merge!({'fake-ip-filter'=>['geosite:category-games@cn,geosite:cn']});
720+
if Value['dns'].has_key?('fake-ip-filter') and not Value['dns']['fake-ip-filter'].to_a.empty? then
721+
Value['dns']['fake-ip-filter'].each{|x|
722+
if x =~ /(geosite:?).*(@cn|:cn)/ then
723+
Value['dns']['fake-ip-filter'].delete(x);
724+
puts '${LOGTIME} Tip: Because Need Ensure Bypassing IP Option Work, Deleted The Fake-IP-Filter Rule【' + x + '】';
725+
end;
726+
};
727+
end;
711728
end;
712729
end;
713730
end;

0 commit comments

Comments
 (0)