diff --git a/luci-app-openclash/root/etc/openclash/custom/openclash_custom_overwrite.sh b/luci-app-openclash/root/etc/openclash/custom/openclash_custom_overwrite.sh index 9293e3b2b2..1e4f001efc 100644 --- a/luci-app-openclash/root/etc/openclash/custom/openclash_custom_overwrite.sh +++ b/luci-app-openclash/root/etc/openclash/custom/openclash_custom_overwrite.sh @@ -9,9 +9,10 @@ LOG_OUT "Tip: Start Running Custom Overwrite Scripts..." LOGTIME=$(echo $(date "+%Y-%m-%d %H:%M:%S")) LOG_FILE="/tmp/openclash.log" -CONFIG_FILE="$1" #config path +#Config Path +CONFIG_FILE="$1" -#Simple Demo: + #Simple Demo: #Key Overwrite Demo #1--config path #2--key name @@ -28,6 +29,13 @@ CONFIG_FILE="$1" #config path #ruby_edit "$CONFIG_FILE" "['dns']['nameserver-policy']" "{'+.msftconnecttest.com'=>'114.114.114.114', '+.msftncsi.com'=>'114.114.114.114', 'geosite:gfw'=>['https://dns.cloudflare.com/dns-query', 'https://dns.google/dns-query#ecs=1.1.1.1/24&ecs-override=true'], 'geosite:cn'=>['114.114.114.114'], 'geosite:geolocation-!cn'=>['https://dns.cloudflare.com/dns-query', 'https://dns.google/dns-query#ecs=1.1.1.1/24&ecs-override=true']}" #ruby_edit "$CONFIG_FILE" "['sniffer']" "{'enable'=>true, 'parse-pure-ip'=>true, 'force-domain'=>['+.netflix.com', '+.nflxvideo.net', '+.amazonaws.com', '+.media.dssott.com'], 'skip-domain'=>['+.apple.com', 'Mijia Cloud', 'dlg.io.mi.com', '+.oray.com', '+.sunlogin.net'], 'sniff'=>{'TLS'=>nil, 'HTTP'=>{'ports'=>[80, '8080-8880'], 'override-destination'=>true}}}" + #Hash Merge Demo + #1--config path + #2--key name + #3--hash + #ruby_merge_hash "$CONFIG_FILE" "['proxy-providers']" "'TW'=>{'type'=>'http', 'path'=>'./proxy_provider/TW.yaml', 'url'=>'https://gist.githubusercontent.com/raw/tw_clash', 'interval'=>3600, 'health-check'=>{'enable'=>true, 'url'=>'http://cp.cloudflare.com/generate_204', 'interval'=>300}}" + #ruby_merge_hash "$CONFIG_FILE" "['rule-providers']" "'Reject'=>{'type'=>'http', 'behavior'=>'classical', 'url'=>'https://testingcf.jsdelivr.net/gh/dler-io/Rules@main/Clash/Provider/Reject.yaml', 'path'=>'./rule_provider/Reject', 'interval'=>86400}" + #Array Insert Value Demo: #1--config path #2--key name @@ -35,6 +43,15 @@ CONFIG_FILE="$1" #config path #4--value #ruby_arr_insert "$CONFIG_FILE" "['dns']['nameserver']" "0" "114.114.114.114" + #Array Insert Hash Demo: + #1--config path + #2--key name + #3--position(start from 0, end with -1) + #4--hash + #ruby_arr_insert_hash "$CONFIG_FILE" "['proxy-groups']" "0" "{'name'=>'Disney', 'type'=>'select', 'disable-udp'=>false, 'use'=>['TW', 'SG', 'HK']}" + #ruby_arr_insert_hash "$CONFIG_FILE" "['proxies']" "0" "{'name'=>'HKG 01', 'type'=>'ss', 'server'=>'cc.hd.abc', 'port'=>'12345', 'cipher'=>'aes-128-gcm', 'password'=>'123456', 'udp'=>true, 'plugin'=>'obfs', 'plugin-opts'=>{'mode'=>'http', 'host'=>'microsoft.com'}}" + #ruby_arr_insert_hash "$CONFIG_FILE" "['listeners']" "0" "{'name'=>'name', 'type'=>'shadowsocks', 'port'=>'12345', 'listen'=>'0.0.0.0', 'rule'=>'sub-rule-1', 'proxy'=>'proxy'}" + #Array Insert Other Array Demo: #1--config path #2--key name diff --git a/luci-app-openclash/root/usr/share/openclash/ruby.sh b/luci-app-openclash/root/usr/share/openclash/ruby.sh index 46037f987b..b21b3d14d4 100644 --- a/luci-app-openclash/root/usr/share/openclash/ruby.sh +++ b/luci-app-openclash/root/usr/share/openclash/ruby.sh @@ -67,6 +67,17 @@ RUBY_YAML_PARSE="Thread.new{Value = YAML.load_file('$1'); Value$2=Value$2.uniq; ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "$RUBY_YAML_PARSE" 2>/dev/null } +#hash覆盖 +ruby_merge_hash() +{ +local Value Value_1 RUBY_YAML_PARSE +if [ -z "$1" ] || [ -z "$2" ]; then + return +fi +RUBY_YAML_PARSE="Thread.new{Value = YAML.load_file('$1'); Value$2.merge!($3); File.open('$1','w') {|f| YAML.dump(Value, f)}}.join" +ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "$RUBY_YAML_PARSE" 2>/dev/null +} + #数组指定位置前添加一组值(不要key) ruby_arr_add_file() { @@ -100,6 +111,17 @@ RUBY_YAML_PARSE="Thread.new{Value = YAML.load_file('$1'); if not Value.key?($2) ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "$RUBY_YAML_PARSE" 2>/dev/null } +#数组指定位置前增加Hash +ruby_arr_insert_hash() +{ +local Value RUBY_YAML_PARSE +if [ -z "$1" ] || [ -z "$2" ]; then + return +fi +RUBY_YAML_PARSE="Thread.new{Value = YAML.load_file('$1'); if not Value.key?($2) or Value$2.nil? then Value$2 = []; end; Value$2=Value$2.insert($3,$4).uniq; File.open('$1','w') {|f| YAML.dump(Value, f)}}.join" +ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "$RUBY_YAML_PARSE" 2>/dev/null +} + #数组指定位置前增加数组 ruby_arr_insert_arr() {