Skip to content

Commit

Permalink
0.46.037
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Oct 3, 2024
1 parent 15c5ec9 commit 3893791
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 109 deletions.
2 changes: 1 addition & 1 deletion luci-app-openclash/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-openclash
PKG_VERSION:=0.46.036
PKG_VERSION:=0.46.037
PKG_RELEASE:=beta
PKG_MAINTAINER:=vernesong <https://github.com/vernesong/OpenClash>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ o.rempty = false

---- interface
o = s:option(Value, "interface", translate("Specific Interface"))
o.description = translate("DNS Lookup Only Through The Specific Interface")..translate("(Only TUN Core)")
o.description = translate("DNS Lookup Only Through The Specific Interface")
local interfaces = SYS.exec("ls -l /sys/class/net/ 2>/dev/null |awk '{print $9}' 2>/dev/null")
for interface in string.gmatch(interfaces, "%S+") do
o:value(interface)
Expand All @@ -79,6 +79,12 @@ o:depends("type", "https")
o.rmempty = false
o.default = o.disbled

---- Skip-cert-verify
o = s:option(Flag, "skip_cert_verify", translate("skip-cert-verify"), translate("skip-cert-verify")..translate("(Only Meta Core)"))
o:depends("type", "https")
o.rmempty = false
o.default = o.disbled

---- ECS Subnet
o = s:option(Value, "ecs_subnet", translate("ECS Subnet"),translate("Specify the ECS Subnet Address")..translate("(Only Meta Core)"))
o:depends("type", "https")
Expand Down
6 changes: 3 additions & 3 deletions luci-app-openclash/luasrc/view/openclash/status.htm
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
</span></td><td width="25%"><%:Control Panel Login Port%></td><td width="25%" align="left" id="_dapo"><%:Collecting data...%></td></tr>
<tr><td width="25%"><%:Proxy Mode%></td><td width="25%" align="left"><span id="radio-de"><%:Collecting data...%></span><span id="radio-mode" class="radio-button">
<input type="radio" id="rule" name="radios" value="rule" checked onclick="return switch_rule_mode(this.value)"/>
<label for="rule">Rule</label>
<label for="rule"><%:Rule%></label>
<input type="radio" id="global" name="radios" value="global" onclick="return switch_rule_mode(this.value)"/>
<label for="global">Global</label>
<label for="global"><%:Global%></label>
<input type="radio" id="direct" name="radios" value="direct" onclick="return switch_rule_mode(this.value)"/>
<label for="direct">Direct</label>
<label for="direct"><%:Direct%></label>
</span></td><td width="25%"><%:Control Panel Login Secret%></td><td width="25%" align="left" id="_dase"><%:Collecting data...%></td></tr>
<tr><td colspan="4"><div style="margin: 10px 0; text-align: center"><span id="_web" style="width: 33%; display: inline-block;"></span><span id="_webm" style="width: 33%; display: inline-block;"><%:Collecting data...%></span><span id="_webo" style="width: 33%; display: inline-block;"></span></div></td></tr>
<tr id="tool_label2"><td colspan="4">
Expand Down
9 changes: 9 additions & 0 deletions luci-app-openclash/po/zh-cn/openclash.zh-cn.po
Original file line number Diff line number Diff line change
Expand Up @@ -3419,3 +3419,12 @@ msgstr "错误:设置 proxy-server-nameserver 错误,"

msgid "Error: Set fallback-filter Failed,"
msgstr "错误:设置 fallback-filter 错误,"

msgid "Rule"
msgstr "规则"

msgid "Global"
msgstr "全局"

msgid "Direct"
msgstr "直连"
51 changes: 50 additions & 1 deletion luci-app-openclash/root/etc/init.d/openclash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh /etc/rc.common
# Copyright (c) 2019 vernesong
# Copyright (c) 2019-2024 vernesong

START=99
STOP=15
Expand Down Expand Up @@ -704,6 +704,51 @@ upnp_exclude()
fi
}

check_core_status()
{
TUN_WAIT=0
TUN_RESTART=1
if [ -n "$en_mode_tun" ] || [ "$ipv6_mode" -eq 2 ]; then
if [ -n "$en_mode_tun" ]; then
ip_="ip"
else
ip_="ip -6"
fi

while ( [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_WAIT" -le 60 ] )
do
$ip_ link set utun up
let TUN_WAIT++
sleep 1
done >/dev/null 2>&1

if [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_WAIT" -gt 60 ]; then
while ( [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_RESTART" -le 3 ] )
do
LOG_OUT "Warning: TUN Interface Start Failed, Try to Restart Again..."
kill_clash
start_run_core
sleep 15
let TUN_RESTART++
done >/dev/null 2>&1
if [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_RESTART" -gt 3 ]; then
LOG_OUT "Warning: TUN Interface Start Failed, Please Check The Dependence or Try to Restart Again!"
start_fail
fi
fi
else
while ( [ -n "$(pidof clash)" ] && [ "$TUN_WAIT" -le 5 ] )
do
let TUN_WAIT++
sleep 5
done >/dev/null 2>&1
fi

if [ -z "$(pidof clash)" ]; then
start_fail
fi
}

firewall_rule_exclude()
{
local section="$1"
Expand Down Expand Up @@ -1453,6 +1498,7 @@ if [ -n "$FW4" ]; then
#TUN模式
#启动TUN
set_tun_tap
check_core_status &

#设置防火墙
if [ "$router_self_proxy" = "1" ] || ([ "$enable_redirect_dns" != "2" ] && [ "$en_mode" = "fake-ip" ]); then
Expand Down Expand Up @@ -1851,6 +1897,7 @@ if [ -n "$FW4" ]; then
fi
else
set_tun_tap "v6"
check_core_status &
fi

#TUN FORWORD
Expand Down Expand Up @@ -2246,6 +2293,7 @@ if [ -z "$FW4" ]; then
#TUN模式
#启动TUN
set_tun_tap
check_core_status &
#设置防火墙
if [ "$router_self_proxy" = "1" ] || ([ "$enable_redirect_dns" != "2" ] && [ "$en_mode" = "fake-ip" ]); then
if [ "$en_mode" = "fake-ip" ]; then
Expand Down Expand Up @@ -2634,6 +2682,7 @@ if [ -z "$FW4" ]; then
fi
else
set_tun_tap "v6"
check_core_status &
fi

#TUN FORWORD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,45 @@ LOG_FILE="/tmp/openclash.log"
CONFIG_FILE="$1" #config path

#Simple Demo:
#General Demo
#Key Overwrite Demo
#1--config path
#2--key name
#3--value
#ruby_edit "$CONFIG_FILE" "['redir-port']" "7892"
#ruby_edit "$CONFIG_FILE" "['secret']" "123456"
#ruby_edit "$CONFIG_FILE" "['dns']['enable']" "true"
#ruby_edit "$CONFIG_FILE" "['dns']['proxy-server-nameserver']" "['https://doh.pub/dns-query','https://223.5.5.5:443/dns-query']"

#Hash Demo
#Hash Overwrite Demo
#1--config path
#2--key name
#3--hash type value
#ruby_edit "$CONFIG_FILE" "['experimental']" "{'sniff-tls-sni'=>true}"
#ruby_edit "$CONFIG_FILE" "['sniffer']" "{'sniffing'=>['tls','http']}"
#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}}}"

#Array Demo:
#Array Insert Value Demo:
#1--config path
#2--key name
#3--position(start from 0, end with -1)
#4--value
#ruby_arr_insert "$CONFIG_FILE" "['dns']['nameserver']" "0" "114.114.114.114"

#Array Add From Yaml File Demo:
#Array Insert Other Array Demo:
#1--config path
#2--key name
#3--position(start from 0, end with -1)
#4--array
#ruby_arr_insert_arr "$CONFIG_FILE" "['dns']['proxy-server-nameserver']" "0" "['https://doh.pub/dns-query','https://223.5.5.5:443/dns-query']"

#Array Insert From Yaml File Demo:
#1--config path
#2--key name
#3--position(start from 0, end with -1)
#4--value file path
#5--value key name in #4 file
#ruby_arr_add_file "$CONFIG_FILE" "['dns']['fallback-filter']['ipcidr']" "0" "/etc/openclash/custom/openclash_custom_fallback_filter.yaml" "['fallback-filter']['ipcidr']"

#Ruby Script Demo:
#Ruby Script Demo:
#ruby -ryaml -rYAML -I "/usr/share/openclash" -E UTF-8 -e "
# begin
# Value = YAML.load_file('$CONFIG_FILE');
Expand Down
101 changes: 18 additions & 83 deletions luci-app-openclash/root/usr/share/openclash/openclash_watchdog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dns_port=$(uci -q get openclash.config.dns_port)
disable_masq_cache=$(uci -q get openclash.config.disable_masq_cache)
cfg_update_interval=$(uci -q get openclash.config.config_update_interval || echo 60)
log_size=$(uci -q get openclash.config.log_size || echo 1024)
core_type=$(uci -q get openclash.config.core_type)
router_self_proxy=$(uci -q get openclash.config.router_self_proxy || echo 1)
stream_auto_select_interval=$(uci -q get openclash.config.stream_auto_select_interval || echo 30)
ipv6_mode=$(uci -q get openclash.config.ipv6_mode || echo 0)
Expand All @@ -28,87 +27,6 @@ SKIP_PROXY_ADDRESS_INTERVAL=30
STREAM_AUTO_SELECT=1
FW4=$(command -v fw4)

kill_clash()
{
check_time=1
while ( [ "$check_time" -le 10 ] && [ -n "$(pidof clash)" ] )
do
clash_pids=$(pidof clash |sed 's/$//g')
for clash_pid in $clash_pids; do
kill -9 "$clash_pid" 2>/dev/null
done
sleep 1
let check_time++
done >/dev/null 2>&1
}

start_fail()
{
kill_clash
/etc/init.d/openclash stop
exit 0
}

start_run_core()
{
ulimit -SHn 65535 2>/dev/null
ulimit -v unlimited 2>/dev/null
ulimit -u unlimited 2>/dev/null
chown root:root /etc/openclash/core/* 2>/dev/null
capabilties="cap_sys_resource,cap_dac_override,cap_net_raw,cap_net_bind_service,cap_net_admin,cap_sys_ptrace,cap_sys_admin"
capsh --caps="${capabilties}+eip" -- -c "capsh --user=nobody --addamb='${capabilties}' -- -c 'nohup $CLASH -d $CLASH_CONFIG -f \"$CONFIG_FILE\" >> $LOG_FILE 2>&1 &'" >> $LOG_FILE 2>&1
sleep 3
if [ "$core_type" == "Meta" ]; then
ip route replace default dev utun table "$PROXY_ROUTE_TABLE" 2>/dev/null
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" 2>/dev/null
if [ "$ipv6_mode" -eq 2 ] && [ "$ipv6_enable" -eq 1 ]; then
ip -6 rule del oif utun table 2022 >/dev/null 2>&1
ip -6 route del default dev utun table 2022 >/dev/null 2>&1
ip -6 addr add fdfe:dcba:9876::1/126 dev utun >/dev/null 2>&1
ip -6 route add fdfe:dcba:9876::/126 dev utun proto kernel metric 256 pref medium >/dev/null 2>&1
ip -6 route add fe80::/64 dev utun proto kernel metric 256 pref medium >/dev/null 2>&1
ip -6 route replace default dev utun table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip -6 rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
fi
fi
}

check_tun_status()
{
TUN_WAIT=0
TUN_RESTART=1
if [ -n "$(echo $en_mode |grep -E '\-mix|\-tun')" ] || [ "$ipv6_mode" -eq 2 ]; then
if [ "$ipv6_enable" = "0" ]; then
ip_="ip"
else
ip_="ip -6"
fi

while ( [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_WAIT" -le 30 ] )
do
$ip_ link set utun up
let TUN_WAIT++
sleep 1
done >/dev/null 2>&1

if [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_WAIT" -gt 30 ]; then
while ( [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_RESTART" -le 3 ] )
do
LOG_OUT "Warning: TUN Interface Start Failed, Try to Restart Again..."
kill_clash
start_run_core
sleep 5
let TUN_RESTART++
done >/dev/null 2>&1
if [ -n "$(pidof clash)" ] && [ -z "$($ip_ route list |grep utun)" ] && [ "$TUN_RESTART" -gt 3 ]; then
LOG_OUT "Warning: TUN Interface Start Failed, Please Check The Dependence or Try to Restart Again!"
start_fail
fi
fi
fi
}

check_tun_status
sleep 15

while :;
Expand Down Expand Up @@ -149,7 +67,24 @@ if [ "$enable" -eq 1 ]; then
CRASH_NUM=$(expr "$CRASH_NUM" + 1)
if [ "$CRASH_NUM" -le 3 ]; then
LOG_OUT "Watchdog: Clash Core Problem, Restart..."
start_run_core
ulimit -SHn 65535 2>/dev/null
ulimit -v unlimited 2>/dev/null
ulimit -u unlimited 2>/dev/null
chown root:root /etc/openclash/core/* 2>/dev/null
capabilties="cap_sys_resource,cap_dac_override,cap_net_raw,cap_net_bind_service,cap_net_admin,cap_sys_ptrace,cap_sys_admin"
capsh --caps="${capabilties}+eip" -- -c "capsh --user=nobody --addamb='${capabilties}' -- -c 'nohup $CLASH -d $CLASH_CONFIG -f \"$CONFIG_FILE\" >> $LOG_FILE 2>&1 &'" >> $LOG_FILE 2>&1
sleep 3
ip route replace default dev utun table "$PROXY_ROUTE_TABLE" 2>/dev/null
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" 2>/dev/null
if [ "$ipv6_mode" -eq 2 ] && [ "$ipv6_enable" -eq 1 ]; then
ip -6 rule del oif utun table 2022 >/dev/null 2>&1
ip -6 route del default dev utun table 2022 >/dev/null 2>&1
ip -6 addr add fdfe:dcba:9876::1/126 dev utun >/dev/null 2>&1
ip -6 route add fdfe:dcba:9876::/126 dev utun proto kernel metric 256 pref medium >/dev/null 2>&1
ip -6 route add fe80::/64 dev utun proto kernel metric 256 pref medium >/dev/null 2>&1
ip -6 route replace default dev utun table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip -6 rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
fi
sleep 60
continue
else
Expand Down
13 changes: 12 additions & 1 deletion luci-app-openclash/root/usr/share/openclash/ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ local Value RUBY_YAML_PARSE
if [ -z "$1" ] || [ -z "$2" ]; then
return
fi
RUBY_YAML_PARSE="Thread.new{Value = YAML.load_file('$1'); Value$2=Value$2.insert($3,'$4').uniq; File.open('$1','w') {|f| YAML.dump(Value, f)}}.join"
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()
{
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; ${4}.reverse.each{|x| Value$2=Value$2.insert($3,x).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
}

Expand Down
Loading

0 comments on commit 3893791

Please sign in to comment.