Skip to content

Commit

Permalink
chore: refine
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Dec 8, 2024
1 parent d30d285 commit 72847cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 40 deletions.
3 changes: 0 additions & 3 deletions luci-app-openclash/po/zh-cn/openclash.zh-cn.po
Original file line number Diff line number Diff line change
Expand Up @@ -2298,9 +2298,6 @@ msgstr "错误:设置自定义规则失败,"
msgid "Error: Set BT/P2P DIRECT Rules Failed,"
msgstr "错误:设置仅代理命中规则流量(BT/P2P直连)失败,"

msgid "Error: Set Loop Protect Rules Failed,"
msgstr "错误:设置防回环规则失败,"

msgid "Error: Set lhie1 Rules Failed,"
msgstr "错误:设置第三方规则(lhie1)失败,"

Expand Down
2 changes: 1 addition & 1 deletion luci-app-openclash/root/etc/init.d/openclash
Original file line number Diff line number Diff line change
Expand Up @@ -2946,7 +2946,7 @@ start()
LOG_OUT "Step 3: Modify The Config File..."
config_check
/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" "$enable_respect_rules" "$custom_fakeip_filter_mode" "$iptables_compat"
/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"
/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" "$enable_redirect_dns" "$en_mode"
#Custom overwrite
if [ -f "/etc/openclash/custom/openclash_custom_overwrite.sh" ]; then
chmod +x /etc/openclash/custom/openclash_custom_overwrite.sh >/dev/null 2>&1
Expand Down
43 changes: 7 additions & 36 deletions luci-app-openclash/root/usr/share/openclash/yml_rules_change.sh
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ yml_other_set()
config_foreach yml_rule_group_get "rule_provider_config" "$3"
config_foreach yml_rule_group_get "rule_providers" "$3"
config_foreach yml_rule_group_get "game_config" "$3"
local fake_ip="$(echo "${11}" |awk -F '/' '{print $1}')"
ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
begin
Value = YAML.load_file('$3');
Expand Down Expand Up @@ -402,19 +401,15 @@ yml_other_set()
#Router Self Proxy Rule
begin
if $6 == 0 and ${10} != 2 and '${12}' == 'fake-ip' then
if $6 == 0 and $8 != 2 and '$9' == 'fake-ip' then
if Value.has_key?('rules') and not Value['rules'].to_a.empty? then
if Value['rules'].to_a.grep(/(?=.*SRC-IP-CIDR,'${fake_ip}')/).empty? then
Value['rules']=Value['rules'].to_a.insert(0,'SRC-IP-CIDR,${11},DIRECT');
end
if Value['rules'].to_a.grep(/(?=.*SRC-IP-CIDR,'$7')/).empty? and not '$7'.empty? then
Value['rules']=Value['rules'].to_a.insert(0,'SRC-IP-CIDR,$7/32,DIRECT');
end;
else
Value['rules']=['SRC-IP-CIDR,${11},DIRECT','SRC-IP-CIDR,$7/32,DIRECT'];
Value['rules']=['SRC-IP-CIDR,$7/32,DIRECT'];
end;
elsif Value.has_key?('rules') and not Value['rules'].to_a.empty? then
Value['rules'].delete('SRC-IP-CIDR,${11},DIRECT');
Value['rules'].delete('SRC-IP-CIDR,$7/32,DIRECT');
end;
rescue Exception => e
Expand Down Expand Up @@ -445,12 +440,7 @@ yml_other_set()
end;
if File::exist?('/tmp/yaml_rule_set_top_custom.yaml') then
Value_1 = YAML.load_file('/tmp/yaml_rule_set_top_custom.yaml');
if Value['rules'].to_a.grep(/(?=.*'${fake_ip}')(?=.*REJECT)/).empty? then
Value_1['rules'].uniq.reverse.each{|x| Value['rules'].insert(0,x)};
else
ruby_add_index = Value['rules'].index(Value['rules'].grep(/(?=.*'${fake_ip}')(?=.*REJECT)/).first);
Value_1['rules'].uniq.reverse.each{|x| Value['rules'].insert(ruby_add_index + 1,x)};
end;
Value_1['rules'].uniq.reverse.each{|x| Value['rules'].insert(0,x)};
end;
else
if File::exist?('/tmp/yaml_rule_set_top_custom.yaml') then
Expand Down Expand Up @@ -624,25 +614,6 @@ yml_other_set()
rescue Exception => e
YAML.LOG('Error: Set Custom Rules Failed,【' + e.message + '】');
end;
#loop prevent
begin
if Value.has_key?('rules') and not Value['rules'].to_a.empty? then
if Value['rules'].to_a.grep(/(?=.*'${fake_ip}')(?=.*REJECT)/).empty? then
Value['rules']=Value['rules'].to_a.insert(0,'IP-CIDR,${11},REJECT,no-resolve');
end;
if Value['rules'].to_a.grep(/(?=.*DST-PORT,'$8',REJECT)/).empty? then
Value['rules']=Value['rules'].to_a.insert(0,'DST-PORT,$8,REJECT');
end;
if Value['rules'].to_a.grep(/(?=.*DST-PORT,'$9',REJECT)/).empty? then
Value['rules']=Value['rules'].to_a.insert(0,'DST-PORT,$9,REJECT');
end;
else
Value['rules']=['IP-CIDR,${11},REJECT,no-resolve','DST-PORT,$8,REJECT','DST-PORT,$9,REJECT'];
end;
rescue Exception => e
YAML.LOG('Error: Set Loop Protect Rules Failed,【' + e.message + '】');
end;
};
t2=Thread.new{
Expand Down Expand Up @@ -875,7 +846,7 @@ if [ "$1" != "0" ]; then
config_foreach yml_other_rules_get "other_rules" "$5"
if [ -z "$rule_name" ]; then
SKIP_CUSTOM_OTHER_RULES=1
yml_other_set "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "${10}" "${11}" "${12}"
yml_other_set "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
exit 0
#判断策略组是否存在
elif [ "$rule_name" = "lhie1" ]; then
Expand Down Expand Up @@ -912,16 +883,16 @@ if [ "$1" != "0" ]; then
|| [ -z "$(grep -F "$Domestic" /tmp/Proxy_Group)" ]; then
LOG_OUT "Warning: Because of The Different Porxy-Group's Name, Stop Setting The Other Rules!"
SKIP_CUSTOM_OTHER_RULES=1
yml_other_set "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "${10}" "${11}" "${12}"
yml_other_set "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
exit 0
fi
fi
if [ -z "$Proxy" ]; then
LOG_OUT "Error: Missing Porxy-Group's Name, Stop Setting The Other Rules!"
SKIP_CUSTOM_OTHER_RULES=1
yml_other_set "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "${10}" "${11}" "${12}"
yml_other_set "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
exit 0
fi
fi

yml_other_set "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "${10}" "${11}" "${12}"
yml_other_set "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"

0 comments on commit 72847cc

Please sign in to comment.