Skip to content

Commit

Permalink
fix #4334
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Feb 18, 2025
1 parent ebab3ae commit 4333c67
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions luci-app-openclash/root/usr/share/openclash/yml_rules_change.sh
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ yml_other_set()
CUSTOM_RULE = YAML.load_file('/etc/openclash/custom/openclash_custom_rules.list')
CUSTOM_RULE_2 = YAML.load_file('/etc/openclash/custom/openclash_custom_rules_2.list')
CONFIG_GROUP = (Value['proxy-groups'].map { |x| x['name'] }\
+ ['DIRECT', 'REJECT']\
+ ['DIRECT', 'REJECT', 'GLOBAL']\
+ (if Value['proxies'] != nil and not Value['proxies'].empty? then Value['proxies'].map { |x| x['name'] } else [] end)\
+ (if Value['sub-rules'] != nil and not Value['sub-rules'].empty? then Value['sub-rules'].keys else [] end)\
+ (if CUSTOM_RULE['sub-rules'] != nil and not CUSTOM_RULE['sub-rules'].empty? then CUSTOM_RULE['sub-rules'].keys else [] end)\
Expand All @@ -486,7 +486,7 @@ yml_other_set()
Value_1 = YAML.load_file('/tmp/yaml_rule_set_bottom_custom.yaml');
if ruby_add_index != -1 then
Value_1['rules'].uniq.reverse.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if CONFIG_GROUP.include?(RULE_GROUP) then
Value['rules'].insert(ruby_add_index,x);
else
Expand All @@ -495,7 +495,7 @@ yml_other_set()
};
else
Value_1['rules'].uniq.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if CONFIG_GROUP.include?(RULE_GROUP) then
Value['rules'].insert(ruby_add_index,x);
else
Expand All @@ -507,7 +507,7 @@ yml_other_set()
if File::exist?('/tmp/yaml_rule_set_top_custom.yaml') then
Value_1 = YAML.load_file('/tmp/yaml_rule_set_top_custom.yaml');
Value_1['rules'].uniq.reverse.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if CONFIG_GROUP.include?(RULE_GROUP) then
Value['rules'].insert(0,x);
else
Expand All @@ -519,7 +519,7 @@ yml_other_set()
if File::exist?('/tmp/yaml_rule_set_top_custom.yaml') then
Value_1 = YAML.load_file('/tmp/yaml_rule_set_top_custom.yaml')['rules'].uniq;
Value_1.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if not CONFIG_GROUP.include?(RULE_GROUP) then
Value_1.delete(x);
YAML.LOG('Warning: Skiped The Custom Rule Because Group & Proxy Not Found:【' + x + '】');
Expand All @@ -530,7 +530,7 @@ yml_other_set()
if File::exist?('/tmp/yaml_rule_set_bottom_custom.yaml') then
Value_1 = YAML.load_file('/tmp/yaml_rule_set_bottom_custom.yaml')['rules'].uniq;
Value_1.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if not CONFIG_GROUP.include?(RULE_GROUP) then
Value_1.delete(x);
YAML.LOG('Warning: Skiped The Custom Rule Because Group & Proxy Not Found:【' + x + '】');
Expand Down Expand Up @@ -564,7 +564,7 @@ yml_other_set()
end;
if defined? Value_2 then
Value_2.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if CONFIG_GROUP.include?(RULE_GROUP) then
Value['rules'].insert(0,x);
else
Expand Down Expand Up @@ -597,7 +597,7 @@ yml_other_set()
Value_4 = Value_4.reverse!;
end;
Value_4.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if CONFIG_GROUP.include?(RULE_GROUP) then
Value['rules'].insert(ruby_add_index,x);
else
Expand All @@ -615,7 +615,7 @@ yml_other_set()
if Value_1.class.to_s == 'Hash' then
if not Value_1['rules'].to_a.empty? and Value_1['rules'].class.to_s == 'Array' then
Value_1['rules'].to_a.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if not CONFIG_GROUP.include?(RULE_GROUP) then
Value_1['rules'].delete(x);
YAML.LOG('Warning: Skiped The Custom Rule Because Group & Proxy Not Found:【' + x + '】');
Expand All @@ -626,7 +626,7 @@ yml_other_set()
end;
elsif Value_1.class.to_s == 'Array' then
Value_1.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if not CONFIG_GROUP.include?(RULE_GROUP) then
Value_1.delete(x);
YAML.LOG('Warning: Skiped The Custom Rule Because Group & Proxy Not Found:【' + x + '】');
Expand All @@ -644,7 +644,7 @@ yml_other_set()
if Value_2.class.to_s == 'Hash' then
if not Value_2['rules'].to_a.empty? and Value_2['rules'].class.to_s == 'Array' then
Value_2['rules'].to_a.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if not CONFIG_GROUP.include?(RULE_GROUP) then
Value_2['rules'].delete(x);
YAML.LOG('Warning: Skiped The Custom Rule Because Group & Proxy Not Found:【' + x + '】');
Expand All @@ -655,7 +655,7 @@ yml_other_set()
end;
elsif Value_2.class.to_s == 'Array' then
Value_2.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if not CONFIG_GROUP.include?(RULE_GROUP) then
Value_2.delete(x);
YAML.LOG('Warning: Skiped The Custom Rule Because Group & Proxy Not Found:【' + x + '】');
Expand Down Expand Up @@ -684,7 +684,7 @@ yml_other_set()
Value_3 = Value_3.reverse!;
end
Value_3.each{|x|
RULE_GROUP = (x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1];
RULE_GROUP = ((x.split(',')[-1] =~ /^no-resolve$|^src$/) ? x.split(',')[-2] : x.split(',')[-1]).strip;
if CONFIG_GROUP.include?(RULE_GROUP) then
Value['rules'].insert(ruby_add_index,x);
else
Expand Down

0 comments on commit 4333c67

Please sign in to comment.