OpenClash: sync with upstream source

This commit is contained in:
CN_SZTL 2020-04-30 20:22:10 +08:00
parent 1b0285c07e
commit c5f7f484e7
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
28 changed files with 836 additions and 494 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-openclash
PKG_VERSION:=0.37.4
PKG_VERSION:=0.37.5
PKG_RELEASE:=beta
PKG_MAINTAINER:=vernesong <https://github.com/vernesong/OpenClash>

View File

@ -23,7 +23,7 @@ config openclash 'config'
option log_level 'silent'
option proxy_mode 'Rule'
option intranet_allowed '0'
option enable_udp_proxy '0'
option enable_udp_proxy '1'
option lan_ac_mode '0'
option operation_mode 'redir-host'
option enable_rule_proxy '0'

View File

@ -4,6 +4,7 @@
START=99
STOP=15
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
CLASH="/etc/openclash/clash"
CLASH_CONFIG="/etc/openclash"
CRON_FILE="/etc/crontabs/root"
@ -110,8 +111,8 @@ yml_check()
sed -i "s/- \{2,\}/- /g" "$3" 2>/dev/null
#检查关键字避免后续操作出错
/usr/share/openclash/yml_field_name_ch.sh "$3"
/usr/share/openclash/yml_field_name_ch.sh "$3" 2>/dev/null
#dns
[ -z "$(grep "^dns:" "$3")" ] && {
sed -i "s/^ \{1,\}dns:/dns:/g" "$3" 2>/dev/null
@ -131,7 +132,7 @@ yml_check()
group_len=$(sed -n '/^Proxy Group:/=' "$3" 2>/dev/null)
dns_len=$(sed -n '/^dns:/=' "$3" 2>/dev/null)
rule_len=$(sed -n '/^Rule:/=' "$3" 2>/dev/null)
if [ "$dns_len" -ge "$proxy_len" ] || [ "$dns_len" -ge "$rule_len" ] || [ "$dns_len" -ge "$group_len" ]; then
echo "错误: 不支持的配置文件, General 设置部分应位于开头,请根据模板修改后重试!" > $START_LOG
echo "${LOGTIME} Unsupported Config, Please Check The General Setting's location And Try-again!" >> $LOG_FILE
@ -192,7 +193,6 @@ yml_check()
fi 2>/dev/null
fi
if [ ! -z "$provider_len" ]; then
proxy_provider_mode=1
fi
@ -208,10 +208,10 @@ yml_check()
sed -i '/^ \{0,\}nameserver:/,/^Custom DNS End$/d' "$3" 2>/dev/null
sed -i '/##Custom DNS##/r/tmp/bakdns.config' "$3" 2>/dev/null
rm -rf /tmp/backdns.config 2>/dev/null
fi
fi 2>/dev/null
yml_dns_check
if [ ! -z "$(grep "^ \{1,\}port:" "$3")" ] || [ ! -z "$(grep "^ \{1,\}mode:" "$3")" ] || [ ! -z "$(grep "^ \{1,\}log-level:" "$3")" ]; then
cp "$3" /tmp/config.check 2>/dev/null
sed -i '/^dns:/,$d' /tmp/config.check 2>/dev/null
@ -240,7 +240,7 @@ yml_dns_check()
sed -i '/^Proxy:/i\dns:' "$CONFIG_FILE" 2>/dev/null
fi
fi
if [ -z "$(grep '^ \{0,\}nameserver:' "$CONFIG_FILE")" ]; then
if [ "$proxy_provider_mode" -eq 1 ]; then
sed -i '/^proxy-provider:/i\ nameserver:' "$CONFIG_FILE" 2>/dev/null
@ -256,21 +256,21 @@ yml_dns_check()
if [ -z "$dns_port" ] || [ "$dns_port" -eq 53 ]; then
dns_port=7874
fi
if [ ! -z "$(grep "^ \{0,\}listen:" "$CONFIG_FILE")" ]; then
if [ "$ipv6_enable" -ne 1 ]; then
if [ "$ipv6_enable" != "1" ]; then
sed -i "/^ \{0,\}listen:/c\ listen: 127.0.0.1:${dns_port}" "$CONFIG_FILE" 2>/dev/null
else
sed -i "/^ \{0,\}listen:/c\ listen: 0.0.0.0:${dns_port}" "$CONFIG_FILE" 2>/dev/null
fi
else
if [ "$ipv6_enable" -ne 1 ]; then
if [ "$ipv6_enable" != "1" ]; then
sed -i "/^dns:/a\ listen: 127.0.0.1:${dns_port}" "$CONFIG_FILE" 2>/dev/null
else
sed -i "/^dns:/a\ listen: 0.0.0.0:${dns_port}" "$CONFIG_FILE" 2>/dev/null
fi
fi
fi 2>/dev/null
uci set openclash.config.dns_port="$dns_port" && uci commit openclash
}
@ -290,7 +290,7 @@ yml_provider_path()
sed -i "s#${provider_path}#./proxy_provider/${provider_name}#" "$1" 2>/dev/null
fi
done
fi
fi 2>/dev/null
}
#检查代理集文件防止启动失败
@ -630,11 +630,11 @@ fi
lan_ac()
{
if [ -z "$1" ]; then
if [ -z "$1" ]; then
return
fi
fi
ipset add "$2" "$1" 2>/dev/null
ipset add "$2" "$1" 2>/dev/null
}
@ -662,7 +662,7 @@ else
if [ ! -f "$CONFIG_FILE" ] && [ -f "$BACKUP_FILE" ]; then
cp "$BACKUP_FILE" "$CONFIG_FILE"
fi
fi
fi 2>/dev/null
CONFIG_NAME=$(echo "$CONFIG_FILE" |awk -F '/' '{print $5}' 2>/dev/null)
}
@ -715,6 +715,272 @@ do_run_mode()
[ ! -x "/etc/openclash/core/clash" ] && chmod 4755 /etc/openclash/core/clash 2>/dev/null
}
set_firewall()
{
if [ "$(iptables -t nat -nL PREROUTING --line-number |grep "udp dpt:53" |grep "0.0.0.0/0 \{0,\}0.0.0.0/0" |wc -l)" -gt 1 ] && [ "$enable_redirect_dns" -eq "1" ]; then
echo "发现53端口被劫持清理防火墙规则..." >$START_LOG
pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/0.0.0.0\/0 \{0,\}0.0.0.0\/0 \{0,\}udp dpt:53/=' 2>/dev/null |sort -rn)
for pre_line in $pre_lines; do
iptables -t nat -D PREROUTING "$pre_line" >/dev/null 2>&1
done
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53 >/dev/null 2>&1
sleep 2
fi
if [ -z "$(uci get firewall.openclash 2>/dev/null)" ] || [ -z "$(uci get ucitrack.@openclash[-1].init 2>/dev/null)" ]; then
uci delete ucitrack.@openclash[-1] >/dev/null 2>&1
uci add ucitrack openclash >/dev/null 2>&1
uci set ucitrack.@openclash[-1].init=openclash >/dev/null 2>&1
uci commit ucitrack >/dev/null 2>&1
uci delete firewall.openclash >/dev/null 2>&1
uci set firewall.openclash=include >/dev/null 2>&1
uci set firewall.openclash.type=script >/dev/null 2>&1
uci set firewall.openclash.path=/var/etc/openclash.include >/dev/null 2>&1
uci set firewall.openclash.reload=1 >/dev/null 2>&1
fi
if [ "$(uci get firewall.@defaults[0].forward)" != "ACCEPT" ]; then
uci set firewall.@defaults[0].forward=ACCEPT >/dev/null 2>&1
uci commit firewall >/dev/null 2>&1
/etc/init.d/firewall reload >/dev/null 2>&1
fi
mkdir -p /var/etc
cat > "/var/etc/openclash.include" <<-EOF
/etc/init.d/openclash reload >/dev/null 2>&1
EOF
#lan_ac
if [ "$operation_mode" = "redir-host" ] && [ "$en_mode" = "redir-host" ]; then
if [ "$lan_ac_mode" = "0" ] && [ ! -z "$(uci get openclash.config.lan_ac_black_ips 2>/dev/null)" ]; then
ipset create lan_ac_black_ips hash:net
config_load "openclash"
config_list_foreach "config" "lan_ac_black_ips" lan_ac "lan_ac_black_ips"
elif [ "$lan_ac_mode" = "1" ] && [ ! -z "$(uci get openclash.config.lan_ac_white_ips 2>/dev/null)" ]; then
ipset create lan_ac_white_ips hash:net
config_load "openclash"
config_list_foreach "config" "lan_ac_white_ips" lan_ac "lan_ac_white_ips"
fi
fi
if [ -z "$en_mode_tun" ]; then
#tcp
iptables -t nat -N openclash
iptables -t nat -A openclash -m set --match-set lan_ac_black_ips src -j RETURN >/dev/null 2>&1
iptables -t nat -A openclash -m set ! --match-set lan_ac_white_ips src -j RETURN >/dev/null 2>&1
iptables -t nat -A openclash -d 0.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 10.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 127.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 169.254.0.0/16 -j RETURN
iptables -t nat -A openclash -d 172.16.0.0/12 -j RETURN
iptables -t nat -A openclash -d 192.168.0.0/16 -j RETURN
iptables -t nat -A openclash -d 224.0.0.0/4 -j RETURN
iptables -t nat -A openclash -d 240.0.0.0/4 -j RETURN
if [ ! -z "$wan_ip4" ]; then
for wan_ip4s in $wan_ip4; do
iptables -t nat -A openclash -d "$wan_ip4s" -j RETURN 2>/dev/null
done
fi
iptables -t nat -A openclash -p tcp -j REDIRECT --to-ports "$proxy_port"
#iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j REDIRECT --to-ports "$proxy_port"
#iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j REDIRECT --to-ports "$proxy_port"
iptables -t nat -A PREROUTING -p tcp -j openclash
#udp
if [ "$enable_udp_proxy" -eq 1 ]; then
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 789
ip route add local default dev lo table "$PROXY_ROUTE_TABLE"
iptables -t mangle -N openclash
iptables -t mangle -A openclash -m set --match-set lan_ac_black_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -A openclash -m set ! --match-set lan_ac_white_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -A openclash -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A openclash -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A openclash -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A openclash -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A openclash -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A openclash -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A openclash -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A openclash -d 240.0.0.0/4 -j RETURN
if [ ! -z "$wan_ip4" ]; then
for wan_ip4s in $wan_ip4; do
iptables -t mangle -A openclash -d "$wan_ip4s" -j RETURN 2>/dev/null
done
fi
iptables -t mangle -A openclash -p udp -j TPROXY --on-port "$proxy_port" --tproxy-mark "$PROXY_FWMARK"
iptables -t mangle -A PREROUTING -p udp -j openclash
fi
if [ "$en_mode" = "fake-ip" ]; then
iptables -t nat -A OUTPUT -p tcp -d 198.18.0.0/16 -j REDIRECT --to-ports "$proxy_port"
if [ "$enable_udp_proxy" -eq 1 ]; then
iptables -t mangle -A OUTPUT -p udp -d 198.18.0.0/16 -j MARK --set-mark "$PROXY_FWMARK"
fi
fi
if [ "$ipv6_enable" -eq 1 ]; then
#tcp
ip6tables -t nat -N openclash
if [ ! -z "$lan_ip6" ]; then
for lan_ip6s in $lan_ip6; do
ip6tables -t nat -A openclash -d "$lan_ip6s" -j RETURN 2>/dev/null
done
fi
ip6tables -t nat -A openclash -p tcp -j REDIRECT --to-ports "$proxy_port"
ip6tables -t nat -A PREROUTING -p tcp -j openclash
#udp
if [ "$enable_udp_proxy" -eq 1 ]; then
ip6tables -t mangle -N openclash
if [ ! -z "$lan_ip6" ]; then
for lan_ip6s in $lan_ip6; do
if [ "$enable_udp_proxy" -eq 1 ]; then
ip6tables -t mangle -A openclash -d "$lan_ip6s" -j RETURN 2>/dev/null
fi
done
fi
ip6tables -t mangle -A openclash -p udp -j TPROXY --on-port "$proxy_port" --tproxy-mark "$PROXY_FWMARK"
ip6tables -t mangle -A PREROUTING -p udp -j openclash
fi
fi
else
#TUN模式
ipset create localnetwork hash:net
ipset add localnetwork 127.0.0.0/8
ipset add localnetwork 10.0.0.0/8
ipset add localnetwork 169.254.0.0/16
ipset add localnetwork 192.168.0.0/16
ipset add localnetwork 224.0.0.0/4
ipset add localnetwork 240.0.0.0/4
ipset add localnetwork 172.16.0.0/12
if [ ! -z "$wan_ip4" ]; then
for wan_ip4s in $wan_ip4; do
ipset add localnetwork "$wan_ip4s" 2>/dev/null
done
fi
#启动TUN
if [ "$en_mode_tun" = "2" ]; then
ip tuntap add user root mode tun clash0
ip link set clash0 up
ip route replace default dev clash0 table "$PROXY_ROUTE_TABLE"
elif [ "$en_mode_tun" = "1" ]; then
TUN_WAIT=0
while ( [ ! -z "$(pidof clash)" ] && [ -z "$(ip route list |grep utun)" ] && [ "$TUN_WAIT" -le 3 ] )
do
TUN_WAIT=$(expr "$TUN_WAIT" + 1)
sleep 2
done
ip route replace default dev utun table "$PROXY_ROUTE_TABLE"
fi
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 789
#设置防火墙
iptables -t mangle -N openclash
iptables -t mangle -F openclash
iptables -t mangle -A openclash -m set --match-set localnetwork dst -j RETURN
if [ "$en_mode" = "fake-ip" ]; then
iptables -t mangle -A openclash -d 198.18.0.0/16 -j MARK --set-mark "$PROXY_FWMARK"
fi
iptables -t mangle -I OUTPUT -j openclash
iptables -t mangle -I PREROUTING -m set --match-set lan_ac_black_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -I PREROUTING -m set ! --match-set lan_ac_white_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -I PREROUTING -m set ! --match-set localnetwork dst -j MARK --set-mark "$PROXY_FWMARK"
iptables -t nat -I PREROUTING -p tcp --dport 53 -j ACCEPT
#ipv6
# if [ "$ipv6_enable" -eq 1 ]; then
# ip6tables -t mangle -I PREROUTING -j MARK --set-mark "$PROXY_FWMARK"
# fi
fi
}
revert_firewall()
{
rm -rf /var/etc/openclash.include 2>/dev/null
#ipv4
ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 789 >/dev/null 2>&1
ip route del local default dev lo table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
iptables -t nat -D PREROUTING -p tcp --dport 53 -j ACCEPT >/dev/null 2>&1
iptables -t mangle -F openclash >/dev/null 2>&1
iptables -t mangle -D PREROUTING -p udp -j openclash >/dev/null 2>&1
iptables -t mangle -X openclash >/dev/null 2>&1
iptables -t nat -F openclash >/dev/null 2>&1
iptables -t nat -D PREROUTING -p tcp -j openclash >/dev/null 2>&1
iptables -t nat -X openclash >/dev/null 2>&1
out_lines=$(iptables -nvL OUTPUT -t mangle |sed 1,2d |sed -n '/198.18.0.0\/16/=' 2>/dev/null |sort -rn)
for out_line in $out_lines; do
iptables -t mangle -D OUTPUT "$out_line" >/dev/null 2>&1
done
out_lines=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.0\/16/=' 2>/dev/null |sort -rn)
for out_line in $out_lines; do
iptables -t nat -D OUTPUT "$out_line" >/dev/null 2>&1
done
#pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/8\.8\./=' 2>/dev/null |sort -rn)
#for pre_line in $pre_lines; do
# iptables -t nat -D PREROUTING "$pre_line" >/dev/null 2>&1
#done
#ipv6
ip6tables -t mangle -F openclash >/dev/null 2>&1
ip6tables -t mangle -D PREROUTING -p udp -j openclash >/dev/null 2>&1
ip6tables -t mangle -X openclash >/dev/null 2>&1
ip6tables -t nat -F openclash >/dev/null 2>&1
ip6tables -t nat -D PREROUTING -p tcp -j openclash >/dev/null 2>&1
ip6tables -t nat -X openclash >/dev/null 2>&1
#TUN
ip route del default dev clash0 table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip route del default dev utun table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 789 >/dev/null 2>&1
ip link set dev clash0 down >/dev/null 2>&1
ip tuntap del clash0 mode tun >/dev/null 2>&1
iptables -t mangle -D OUTPUT -j openclash >/dev/null 2>&1
iptables -t mangle -D PREROUTING -m set --match-set lan_ac_black_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -D PREROUTING -m set ! --match-set lan_ac_white_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -D PREROUTING -m set ! --match-set localnetwork dst -j MARK --set-mark "$PROXY_FWMARK" >/dev/null 2>&1
ip6tables -t mangle -D PREROUTING -j MARK --set-mark "$PROXY_FWMARK" >/dev/null 2>&1
iptables -t mangle -F openclash >/dev/null 2>&1
iptables -t mangle -X openclash >/dev/null 2>&1
ipset destroy localnetwork >/dev/null 2>&1
ipset destroy lan_ac_white_ips >/dev/null 2>&1
ipset destroy lan_ac_black_ips >/dev/null 2>&1
}
get_config()
{
enable_custom_dns=$(uci get openclash.config.enable_custom_dns 2>/dev/null)
rule_source=$(uci get openclash.config.rule_source 2>/dev/null)
enable_custom_clash_rules=$(uci get openclash.config.enable_custom_clash_rules 2>/dev/null)
da_password=$(uci get openclash.config.dashboard_password 2>/dev/null)
cn_port=$(uci get openclash.config.cn_port 2>/dev/null)
proxy_port=$(uci get openclash.config.proxy_port 2>/dev/null)
ipv6_enable=$(uci get openclash.config.ipv6_enable 2>/dev/null)
http_port=$(uci get openclash.config.http_port 2>/dev/null)
socks_port=$(uci get openclash.config.socks_port 2>/dev/null)
enable_redirect_dns=$(uci get openclash.config.enable_redirect_dns 2>/dev/null)
lan_ip=$(uci get network.lan.ipaddr 2>/dev/null |awk -F '/' '{print $1}' 2>/dev/null)
wan_ip4=$(ifconfig | grep 'inet addr' | awk '{print $2}' | cut -d: -f2 2>/dev/null)
lan_ip6=$(ifconfig | grep 'inet6 addr' | awk '{print $3}' 2>/dev/null)
direct_dns=$(uci get openclash.config.direct_dns 2>/dev/null)
disable_masq_cache=$(uci get openclash.config.disable_masq_cache 2>/dev/null)
log_level=$(uci get openclash.config.log_level 2>/dev/null)
proxy_mode=$(uci get openclash.config.proxy_mode 2>/dev/null)
intranet_allowed=$(uci get openclash.config.intranet_allowed 2>/dev/null)
enable_udp_proxy=$(uci get openclash.config.enable_udp_proxy 2>/dev/null)
operation_mode=$(uci get openclash.config.operation_mode 2>/dev/null)
lan_ac_mode=$(uci get openclash.config.lan_ac_mode 2>/dev/null)
enable_rule_proxy=$(uci get openclash.config.enable_rule_proxy 2>/dev/null)
}
start()
{
#禁止多个实例
@ -724,7 +990,7 @@ status=$(ps|grep -c /etc/init.d/openclash)
config_choose
enable=$(uci get openclash.config.enable 2>/dev/null)
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
#检查是否存在核心文件
do_run_mode
@ -735,29 +1001,7 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
}
echo "OpenClash 开始启动..." >$START_LOG
echo "第一步: 获取配置..." >$START_LOG
enable_custom_dns=$(uci get openclash.config.enable_custom_dns 2>/dev/null)
rule_source=$(uci get openclash.config.rule_source 2>/dev/null)
enable_custom_clash_rules=$(uci get openclash.config.enable_custom_clash_rules 2>/dev/null)
da_password=$(uci get openclash.config.dashboard_password 2>/dev/null)
cn_port=$(uci get openclash.config.cn_port 2>/dev/null)
proxy_port=$(uci get openclash.config.proxy_port 2>/dev/null)
ipv6_enable=$(uci get openclash.config.ipv6_enable 2>/dev/null)
http_port=$(uci get openclash.config.http_port 2>/dev/null)
socks_port=$(uci get openclash.config.socks_port 2>/dev/null)
enable_redirect_dns=$(uci get openclash.config.enable_redirect_dns 2>/dev/null)
lan_ip=$(uci get network.lan.ipaddr 2>/dev/null |awk -F '/' '{print $1}' 2>/dev/null)
wan_ip4=$(ifconfig | grep 'inet addr' | awk '{print $2}' | cut -d: -f2 2>/dev/null)
lan_ip6=$(ifconfig | grep 'inet6 addr' | awk '{print $3}' 2>/dev/null)
direct_dns=$(uci get openclash.config.direct_dns 2>/dev/null)
disable_masq_cache=$(uci get openclash.config.disable_masq_cache 2>/dev/null)
log_level=$(uci get openclash.config.log_level 2>/dev/null)
proxy_mode=$(uci get openclash.config.proxy_mode 2>/dev/null)
intranet_allowed=$(uci get openclash.config.intranet_allowed 2>/dev/null)
enable_udp_proxy=$(uci get openclash.config.enable_udp_proxy 2>/dev/null)
operation_mode=$(uci get openclash.config.operation_mode 2>/dev/null)
lan_ac_mode=$(uci get openclash.config.lan_ac_mode 2>/dev/null)
enable_rule_proxy=$(uci get openclash.config.enable_rule_proxy 2>/dev/null)
get_config
echo "第二步: 配置文件检查..." >$START_LOG
yml_check "$en_mode" "$enable_custom_dns" "$CONFIG_FILE" "$BACKUP_FILE" "$START_BACKUP"
grep "^ \{0,\}Proxy Group:" "$CONFIG_FILE" >/dev/null 2>&1 && grep "^ \{0,\}Rule:" "$CONFIG_FILE" >/dev/null 2>&1
@ -791,7 +1035,15 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
echo "" >$START_LOG
else
echo "第五步: 启动主程序..." >$START_LOG
nohup "$CLASH" -d "$CLASH_CONFIG" -f "$CONFIG_FILE" >> $LOG_FILE 2>&1 &
config_reload=$(uci get openclash.config.config_reload 2>/dev/null)
if [ -n "$(pidof clash)" ] && [ "$en_mode_tun" != "1" ] && [ "$config_reload" != "0" ]; then
curl -s --connect-timeout 5 -m 5 -H 'Content-Type: application/json' -H "Authorization: Bearer ${da_password}" -XPUT http://"$lan_ip":"$cn_port"/configs -d "{\"path\": \"$CONFIG_FILE\"}" 2>/dev/null
else
kill -9 "$(pidof clash|sed 's/$//g')" 2>/dev/null
nohup "$CLASH" -d "$CLASH_CONFIG" -f "$CONFIG_FILE" >> $LOG_FILE 2>&1 &
fi
uci set openclash.config.config_reload=1
uci commit openclash
#检测proxy_provider配置文件状态
echo "第六步: 等待主程序下载代理集..." >$START_LOG
@ -801,179 +1053,7 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then
ln -s /usr/share/openclash/yacd /www/luci-static/openclash 2>/dev/null
echo "第八步: 设置防火墙规则..." >$START_LOG
if [ "$(iptables -t nat -nL PREROUTING --line-number |grep "udp dpt:53" |grep "0.0.0.0/0 \{0,\}0.0.0.0/0" |wc -l)" -gt 1 ] && [ "$enable_redirect_dns" -eq "1" ]; then
echo "发现53端口被劫持清理防火墙规则..." >$START_LOG
pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/0.0.0.0\/0 \{0,\}0.0.0.0\/0 \{0,\}udp dpt:53/=' 2>/dev/null |sort -rn)
for pre_line in $pre_lines; do
iptables -t nat -D PREROUTING "$pre_line" >/dev/null 2>&1
done
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53 >/dev/null 2>&1
sleep 2
fi
if [ -z "$(uci get firewall.openclash 2>/dev/null)" ] || [ -z "$(uci get ucitrack.@openclash[-1].init 2>/dev/null)" ]; then
uci delete ucitrack.@openclash[-1] >/dev/null 2>&1
uci add ucitrack openclash >/dev/null 2>&1
uci set ucitrack.@openclash[-1].init=openclash >/dev/null 2>&1
uci commit ucitrack >/dev/null 2>&1
uci delete firewall.openclash >/dev/null 2>&1
uci set firewall.openclash=include >/dev/null 2>&1
uci set firewall.openclash.type=script >/dev/null 2>&1
uci set firewall.openclash.path=/var/etc/openclash.include >/dev/null 2>&1
uci set firewall.openclash.reload=1 >/dev/null 2>&1
fi
if [ "$(uci get firewall.@defaults[0].forward)" != "ACCEPT" ]; then
uci set firewall.@defaults[0].forward=ACCEPT >/dev/null 2>&1
uci commit firewall >/dev/null 2>&1
/etc/init.d/firewall reload >/dev/null 2>&1
fi
mkdir -p /var/etc
cat > "/var/etc/openclash.include" <<-EOF
/etc/init.d/openclash restart
EOF
#lan_ac
if [ "$operation_mode" = "redir-host" ] && [ "$en_mode" = "redir-host" ]; then
if [ "$lan_ac_mode" = "0" ] && [ ! -z "$(uci get openclash.config.lan_ac_black_ips 2>/dev/null)" ]; then
ipset create lan_ac_black_ips hash:net
config_load "openclash"
config_list_foreach "config" "lan_ac_black_ips" lan_ac "lan_ac_black_ips"
elif [ "$lan_ac_mode" = "1" ] && [ ! -z "$(uci get openclash.config.lan_ac_white_ips 2>/dev/null)" ]; then
ipset create lan_ac_white_ips hash:net
config_load "openclash"
config_list_foreach "config" "lan_ac_white_ips" lan_ac "lan_ac_white_ips"
fi
fi
if [ -z "$en_mode_tun" ]; then
#tcp
iptables -t nat -N openclash
iptables -t nat -A openclash -m set --match-set lan_ac_black_ips src -j RETURN >/dev/null 2>&1
iptables -t nat -A openclash -m set ! --match-set lan_ac_white_ips src -j RETURN >/dev/null 2>&1
iptables -t nat -A openclash -d 0.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 10.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 127.0.0.0/8 -j RETURN
iptables -t nat -A openclash -d 169.254.0.0/16 -j RETURN
iptables -t nat -A openclash -d 172.16.0.0/12 -j RETURN
iptables -t nat -A openclash -d 192.168.0.0/16 -j RETURN
iptables -t nat -A openclash -d 224.0.0.0/4 -j RETURN
iptables -t nat -A openclash -d 240.0.0.0/4 -j RETURN
if [ ! -z "$wan_ip4" ]; then
for wan_ip4s in $wan_ip4; do
iptables -t nat -A openclash -d "$wan_ip4s" -j RETURN 2>/dev/null
done
fi
iptables -t nat -A openclash -p tcp -j REDIRECT --to-ports "$proxy_port"
iptables -t nat -I PREROUTING -p tcp -d 8.8.8.8 -j REDIRECT --to-ports "$proxy_port"
iptables -t nat -I PREROUTING -p tcp -d 8.8.4.4 -j REDIRECT --to-ports "$proxy_port"
iptables -t nat -A PREROUTING -p tcp -j openclash
#udp
if [ "$enable_udp_proxy" -eq 1 ]; then
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 789
ip route add local default dev lo table "$PROXY_ROUTE_TABLE"
iptables -t mangle -N openclash
iptables -t mangle -A openclash -m set --match-set lan_ac_black_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -A openclash -m set ! --match-set lan_ac_white_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -A openclash -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A openclash -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A openclash -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A openclash -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A openclash -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A openclash -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A openclash -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A openclash -d 240.0.0.0/4 -j RETURN
if [ ! -z "$wan_ip4" ]; then
for wan_ip4s in $wan_ip4; do
iptables -t mangle -A openclash -d "$wan_ip4s" -j RETURN 2>/dev/null
done
fi
iptables -t mangle -A openclash -p udp -j TPROXY --on-port "$proxy_port" --tproxy-mark "$PROXY_FWMARK"
iptables -t mangle -A PREROUTING -p udp -j openclash
fi
if [ "$en_mode" = "fake-ip" ]; then
iptables -t nat -A OUTPUT -p tcp -d 198.18.0.0/16 -j REDIRECT --to-ports "$proxy_port"
if [ "$enable_udp_proxy" -eq 1 ]; then
iptables -t mangle -A OUTPUT -p udp -d 198.18.0.0/16 -j MARK --set-mark "$PROXY_FWMARK"
fi
fi
if [ "$ipv6_enable" -eq 1 ]; then
#tcp
ip6tables -t nat -N openclash
if [ ! -z "$lan_ip6" ]; then
for lan_ip6s in $lan_ip6; do
ip6tables -t nat -A openclash -d "$lan_ip6s" -j RETURN 2>/dev/null
done
fi
ip6tables -t nat -A openclash -p tcp -j REDIRECT --to-ports "$proxy_port"
ip6tables -t nat -A PREROUTING -p tcp -j openclash
#udp
if [ "$enable_udp_proxy" -eq 1 ]; then
ip6tables -t mangle -N openclash
if [ ! -z "$lan_ip6" ]; then
for lan_ip6s in $lan_ip6; do
if [ "$enable_udp_proxy" -eq 1 ]; then
ip6tables -t mangle -A openclash -d "$lan_ip6s" -j RETURN 2>/dev/null
fi
done
fi
ip6tables -t mangle -A openclash -p udp -j TPROXY --on-port "$proxy_port" --tproxy-mark "$PROXY_FWMARK"
ip6tables -t mangle -A PREROUTING -p udp -j openclash
fi
fi
else
#TUN模式
ipset create localnetwork hash:net
ipset add localnetwork 127.0.0.0/8
ipset add localnetwork 10.0.0.0/8
ipset add localnetwork 169.254.0.0/16
ipset add localnetwork 192.168.0.0/16
ipset add localnetwork 224.0.0.0/4
ipset add localnetwork 240.0.0.0/4
ipset add localnetwork 172.16.0.0/12
if [ ! -z "$wan_ip4" ]; then
for wan_ip4s in $wan_ip4; do
ipset add localnetwork "$wan_ip4s" 2>/dev/null
done
fi
#启动TUN
if [ "$en_mode_tun" = "2" ]; then
ip tuntap add user root mode tun clash0
ip link set clash0 up
ip route replace default dev clash0 table "$PROXY_ROUTE_TABLE"
elif [ "$en_mode_tun" = "1" ]; then
TUN_WAIT=0
while ( [ ! -z "$(pidof clash)" ] && [ -z "$(ip route list |grep utun)" ] && [ "$TUN_WAIT" -le 3 ] )
do
TUN_WAIT=$(expr "$TUN_WAIT" + 1)
sleep 2
done
ip route replace default dev utun table "$PROXY_ROUTE_TABLE"
fi
ip rule add fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 789
#设置防火墙
iptables -t mangle -N openclash
iptables -t mangle -F openclash
iptables -t mangle -A openclash -m set --match-set localnetwork dst -j RETURN
if [ "$en_mode" = "fake-ip" ]; then
iptables -t mangle -A openclash -d 198.18.0.0/16 -j MARK --set-mark "$PROXY_FWMARK"
fi
iptables -t mangle -I OUTPUT -j openclash
iptables -t mangle -I PREROUTING -m set --match-set lan_ac_black_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -I PREROUTING -m set ! --match-set lan_ac_white_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -I PREROUTING -m set ! --match-set localnetwork dst -j MARK --set-mark "$PROXY_FWMARK"
iptables -t nat -I PREROUTING -p tcp --dport 53 -j ACCEPT
#ipv6
# if [ "$ipv6_enable" -eq 1 ]; then
# ip6tables -t mangle -I PREROUTING -j MARK --set-mark "$PROXY_FWMARK"
# fi
fi
set_firewall
echo "第九步: 重启 Dnsmasq 程序..." >$START_LOG
change_dns "$enable_redirect_dns" "$disable_masq_cache"
@ -1067,108 +1147,70 @@ fi
stop()
{
echo "OpenClash 开始关闭..." >$START_LOG
echo "第一步: 备份当前节点状态..." >$START_LOG
/usr/share/openclash/openclash_history_get.sh &
wait
echo "第二步: 删除 OpenClash 防火墙规则..." >$START_LOG
rm -rf /var/etc/openclash.include 2>/dev/null
#ipv4
#禁止多个实例
status=$(ps|grep -c /etc/init.d/openclash)
[ "$status" -gt "3" ] && exit 0
enable=$(uci get openclash.config.enable 2>/dev/null)
ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 789 >/dev/null 2>&1
ip route del local default dev lo table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
echo "OpenClash 开始关闭..." >$START_LOG
echo "第一步: 备份当前节点状态..." >$START_LOG
/usr/share/openclash/openclash_history_get.sh &
wait
iptables -t nat -D PREROUTING -p tcp --dport 53 -j ACCEPT >/dev/null 2>&1
echo "第二步: 删除 OpenClash 防火墙规则..." >$START_LOG
revert_firewall
iptables -t mangle -F openclash >/dev/null 2>&1
iptables -t mangle -D PREROUTING -p udp -j openclash >/dev/null 2>&1
iptables -t mangle -X openclash >/dev/null 2>&1
iptables -t nat -F openclash >/dev/null 2>&1
iptables -t nat -D PREROUTING -p tcp -j openclash >/dev/null 2>&1
iptables -t nat -X openclash >/dev/null 2>&1
ipset destroy lan_ac_white_ips >/dev/null 2>&1
ipset destroy lan_ac_black_ips >/dev/null 2>&1
out_lines=$(iptables -nvL OUTPUT -t mangle |sed 1,2d |sed -n '/198.18.0.0\/16/=' 2>/dev/null |sort -rn)
for out_line in $out_lines; do
iptables -t mangle -D OUTPUT "$out_line" >/dev/null 2>&1
done
out_lines=$(iptables -nvL OUTPUT -t nat |sed 1,2d |sed -n '/198.18.0.0\/16/=' 2>/dev/null |sort -rn)
for out_line in $out_lines; do
iptables -t nat -D OUTPUT "$out_line" >/dev/null 2>&1
done
pre_lines=$(iptables -nvL PREROUTING -t nat |sed 1,2d |sed -n '/8.8./=' 2>/dev/null |sort -rn)
for pre_line in $pre_lines; do
iptables -t nat -D PREROUTING "$pre_line" >/dev/null 2>&1
done
#ipv6
ip6tables -t mangle -F openclash >/dev/null 2>&1
ip6tables -t mangle -D PREROUTING -p udp -j openclash >/dev/null 2>&1
ip6tables -t mangle -X openclash >/dev/null 2>&1
ip6tables -t nat -F openclash >/dev/null 2>&1
ip6tables -t nat -D PREROUTING -p tcp -j openclash >/dev/null 2>&1
ip6tables -t nat -X openclash >/dev/null 2>&1
#TUN
ip link set dev clash0 down >/dev/null 2>&1
ip tuntap del clash0 mode tun >/dev/null 2>&1
ip route del default dev clash0 table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip route del default dev utun table "$PROXY_ROUTE_TABLE" >/dev/null 2>&1
ip rule del fwmark "$PROXY_FWMARK" table "$PROXY_ROUTE_TABLE" pref 789 >/dev/null 2>&1
echo "第三步: 关闭 OpenClash 守护程序..." >$START_LOG
watchdog_pids=$(ps |grep openclash_watchdog.sh |grep -v grep |awk '{print $1}' 2>/dev/null)
for watchdog_pid in $watchdog_pids; do
kill -9 "$watchdog_pid" >/dev/null 2>&1
done
iptables -t mangle -D OUTPUT -j openclash >/dev/null 2>&1
iptables -t mangle -D PREROUTING -m set --match-set lan_ac_black_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -D PREROUTING -m set ! --match-set lan_ac_white_ips src -j RETURN >/dev/null 2>&1
iptables -t mangle -D PREROUTING -m set ! --match-set localnetwork dst -j MARK --set-mark "$PROXY_FWMARK" >/dev/null 2>&1
ip6tables -t mangle -D PREROUTING -j MARK --set-mark "$PROXY_FWMARK" >/dev/null 2>&1
iptables -t mangle -F openclash >/dev/null 2>&1
iptables -t mangle -X openclash >/dev/null 2>&1
ipset destroy localnetwork >/dev/null 2>&1
echo "第四步: 关闭 Clash 主程序..." >$START_LOG
if [ "$enable" -eq 0 ]; then
kill -9 "$(pidof clash|sed 's/$//g')" 2>/dev/null
fi
echo "第三步: 关闭 OpenClash 守护程序..." >$START_LOG
watchdog_pids=$(ps |grep openclash_watchdog.sh |grep -v grep |awk '{print $1}' 2>/dev/null)
for watchdog_pid in $watchdog_pids; do
kill -9 "$watchdog_pid" >/dev/null 2>&1
done
echo "第五步: 重启 Dnsmasq 程序..." >$START_LOG
dns_port=$(uci get openclash.config.dns_port 2>/dev/null)
redirect_dns=$(uci get openclash.config.redirect_dns 2>/dev/null)
masq_cache=$(uci get openclash.config.masq_cache 2>/dev/null)
revert_dns "$redirect_dns" "$masq_cache" "$dns_port"
/etc/init.d/dnsmasq restart >/dev/null 2>&1
echo "第四步: 关闭 Clash 主程序..." >$START_LOG
kill -9 "$(pidof clash|sed 's/$//g')" 2>/dev/null
echo "第六步:删除 OpenClash 残留文件..." >$START_LOG
if [ "$enable" -eq 0 ]; then
rm -rf $LOG_FILE 2>/dev/null
rm -rf /tmp/openclash_debug.log 2>/dev/null
rm -rf /www/luci-static/openclash 2>/dev/null
rm -rf /tmp/openclash_last_version 2>/dev/null
rm -rf /tmp/clash_last_version 2>/dev/null
rm -rf /tmp/Proxy_Group 2>/dev/null
rm -rf /tmp/rules_name 2>/dev/null
echo "OpenClash 关闭成功!" >$START_LOG
sleep 5
fi
echo "第五步: 重启 Dnsmasq 程序..." >$START_LOG
dns_port=$(uci get openclash.config.dns_port 2>/dev/null)
redirect_dns=$(uci get openclash.config.redirect_dns 2>/dev/null)
masq_cache=$(uci get openclash.config.masq_cache 2>/dev/null)
revert_dns "$redirect_dns" "$masq_cache" "$dns_port"
/etc/init.d/dnsmasq restart >/dev/null 2>&1
echo "第六步:删除 OpenClash 残留文件..." >$START_LOG
enable=$(uci get openclash.config.enable 2>/dev/null)
if [ "$enable" -eq 0 ]; then
rm -rf $LOG_FILE 2>/dev/null
rm -rf /www/luci-static/openclash 2>/dev/null
rm -rf /tmp/openclash_last_version 2>/dev/null
rm -rf /tmp/clash_last_version 2>/dev/null
rm -rf /tmp/Proxy_Group 2>/dev/null
rm -rf /tmp/rules_name 2>/dev/null
echo "OpenClash 关闭成功!" >$START_LOG
sleep 5
fi
rm -rf $START_LOG 2>/dev/null
del_cron
echo "OpenClash Already Stop"
rm -rf $START_LOG 2>/dev/null
del_cron
echo "OpenClash Already Stop"
}
restart()
{
stop
start
stop
start
}
reload()
{
revert_firewall 2>/dev/null
config_choose 2>/dev/null
do_run_mode 2>/dev/null
get_config 2>/dev/null
set_firewall 2>/dev/null
/usr/share/openclash/openclash_history_set.sh
echo "${LOGTIME} OpenClash Reload After Firewall Restart" >> $LOG_FILE
}

View File

@ -17,6 +17,10 @@ ina.ntp.org.cn
1.openwrt.pool.ntp.org
2.openwrt.pool.ntp.org
3.openwrt.pool.ntp.org
time1.cloud.tencent.com
time.ustc.edu.cn
pool.ntp.org
ntp.ubuntu.com
ntp.aliyun.com
ntp1.aliyun.com
ntp2.aliyun.com

View File

@ -4052,7 +4052,6 @@ Rule:
- DOMAIN-SUFFIX,iflyad.bj.openstorage.cn,AdBlock
- DOMAIN-SUFFIX,iframe.travel.yahoo.com,AdBlock
- DOMAIN-SUFFIX,ig.nukefans.net,AdBlock
- DOMAIN-SUFFIX,igexin.com,AdBlock
- DOMAIN-SUFFIX,igj5y.yongchanghengyuan.com,AdBlock
- DOMAIN-SUFFIX,ih.adscale.de,AdBlock
- DOMAIN-SUFFIX,ihualun.com,AdBlock
@ -6143,7 +6142,6 @@ Rule:
- DOMAIN-SUFFIX,pv.focus.cn,AdBlock
- DOMAIN-SUFFIX,pv.ra.icast.cn,AdBlock
- DOMAIN-SUFFIX,pv.sogou.com,AdBlock
- DOMAIN-SUFFIX,pv.sohu.com,AdBlock
- DOMAIN-SUFFIX,pv.xcar.com.cn,AdBlock
- DOMAIN-SUFFIX,pv.zdnet.com.cn,AdBlock
- DOMAIN-SUFFIX,pv.zol.com.cn,AdBlock
@ -8507,15 +8505,16 @@ Rule:
# > BBC iPlayer
# - USER-AGENT,BBCiPlayer*,GlobalTV
- DOMAIN-KEYWORD,bbcfmt,GlobalTV
- DOMAIN-SUFFIX,bbc.com,GlobalTV
- DOMAIN-SUFFIX,bbc.co,GlobalTV
- DOMAIN-SUFFIX,bbc.co.uk,GlobalTV
- DOMAIN-SUFFIX,bbci.co,GlobalTV
- DOMAIN-SUFFIX,bbci.co.uk,GlobalTV
- DOMAIN,aod-dash-uk-live.akamaized.net,GlobalTV
- DOMAIN,aod-hls-uk-live.akamaized.net,GlobalTV
- DOMAIN,vod-dash-uk-live.akamaized.net,GlobalTV
- DOMAIN,vod-thumb-uk-live.akamaized.net,GlobalTV
- DOMAIN,vod-dash-uk-live.bbcfmt.hs.llnwd.net,GlobalTV
- DOMAIN,vod-thumb-uk-live.bbcfmt.hs.llnwd.net,GlobalTV
- DOMAIN-SUFFIX,bbc.co,GlobalTV
- DOMAIN-SUFFIX,bbc.co.uk,GlobalTV
- DOMAIN-SUFFIX,bbc.com,GlobalTV
- DOMAIN-SUFFIX,bbcfmt.hs.llnwd.net,GlobalTV
- DOMAIN-SUFFIX,bbci.co,GlobalTV
- DOMAIN-SUFFIX,bbci.co.uk,GlobalTV
# > DAZN
- DOMAIN-SUFFIX,d151l6v8er5bdm.cloudfront.net,GlobalTV
@ -9590,16 +9589,51 @@ Rule:
- DOMAIN-SUFFIX,telegra.ph,Telegram
- DOMAIN-SUFFIX,telegram.me,Telegram
- DOMAIN-SUFFIX,telegram.org,Telegram
- IP-CIDR,91.108.4.0/22,Telegram
- IP-CIDR,91.108.56.0/22,Telegram
- IP-CIDR,109.239.140.0/24,Telegram
- IP-CIDR,149.154.167.99/32,Telegram
- IP-CIDR,149.154.175.10/32,Telegram
- IP-CIDR,149.154.167.40/32,Telegram
- IP-CIDR,149.154.167.42/32,Telegram
- IP-CIDR,149.154.175.117/32,Telegram
- IP-CIDR,149.154.175.50/32,Telegram
- IP-CIDR,149.154.167.50/32,Telegram
- IP-CIDR,149.154.167.51/32,Telegram
- IP-CIDR,149.154.175.100/32,Telegram
- IP-CIDR,149.154.167.91/32,Telegram
- IP-CIDR,149.154.167.90/32,Telegram
- IP-CIDR,149.154.165.120/32,Telegram
- IP-CIDR,149.154.166.120/32,Telegram
- IP-CIDR,149.154.164.250/32,Telegram
- IP-CIDR,149.154.167.117/32,Telegram
- IP-CIDR,149.154.167.118/32,Telegram
- IP-CIDR,149.154.167.192/27,Telegram
- IP-CIDR,149.154.164.8/29 ,Telegram
- IP-CIDR,91.108.8.0/27,Telegram
- IP-CIDR,91.108.12.0/27,Telegram
- IP-CIDR,91.108.16.0/27,Telegram
- IP-CIDR,91.108.56.0/24,Telegram
- IP-CIDR,91.108.4.0/24,Telegram
- IP-CIDR,149.154.160.0/22,Telegram
- IP-CIDR,149.154.164.0/22,Telegram
- IP-CIDR,149.154.168.0/22,Telegram
- IP-CIDR,149.154.172.0/22,Telegram
- IP-CIDR6,2001:67c:4e8::/48,Telegram
- IP-CIDR,91.108.56.0/22,Telegram
- IP-CIDR,91.108.4.0/22,Telegram
- IP-CIDR,91.108.8.0/22,Telegram
- IP-CIDR,91.108.16.0/22,Telegram
- IP-CIDR,91.108.12.0/22,Telegram
- IP-CIDR,149.154.160.0/20,Telegram
- IP-CIDR6,2001:b28:f23d:f001::e/128,Telegram
- IP-CIDR6,2001:67c:4e8:f002::e/128,Telegram
- IP-CIDR6,2001:b28:f23d:f003::e/128,Telegram
- IP-CIDR6,2001:b28:f23d:f001::a/128,Telegram
- IP-CIDR6,2001:67c:4e8:f002::a/128,Telegram
- IP-CIDR6,2001:b28:f23d:f003::a/128,Telegram
- IP-CIDR6,2001:67c:4e8:f004::a/128,Telegram
- IP-CIDR6,2001:b28:f23f:f005::a/128,Telegram
- IP-CIDR6,2001:67c:4e8:fa60::/64,Telegram
- IP-CIDR6,2001:b28:f23d::/48,Telegram
- IP-CIDR6,2001:b28:f23f::/48,Telegram
- IP-CIDR6,2001:67c:4e8::/48,Telegram

File diff suppressed because one or more lines are too long

View File

@ -32,7 +32,7 @@ function index()
entry({"admin", "services", "openclash", "groups-config"},cbi("openclash/groups-config"), nil).leaf = true
entry({"admin", "services", "openclash", "proxy-provider-config"},cbi("openclash/proxy-provider-config"), nil).leaf = true
entry({"admin", "services", "openclash", "config"},form("openclash/config"),_("Config Manage"), 70).leaf = true
entry({"admin", "services", "openclash", "log"},form("openclash/log"),_("Logs"), 80).leaf = true
entry({"admin", "services", "openclash", "log"},form("openclash/log"),_("Server Logs"), 80).leaf = true
end
local fs = require "luci.openclash"
@ -81,6 +81,13 @@ local function daip()
return daip
end
local function uh_port()
local uh_port = luci.sys.exec("uci get uhttpd.main.listen_http |awk -F ':' '{print $NF}'")
if uh_port ~= "80" then
return ":" .. uh_port
end
end
local function dase()
return luci.sys.exec("uci get openclash.config.dashboard_password 2>/dev/null")
end
@ -99,7 +106,7 @@ local function startlog()
end
local function coremodel()
local coremodel = luci.sys.exec("cat /proc/cpuinfo |grep 'cpu model' 2>/dev/null |awk -F ': ' '{print $2}' 2>/dev/null")
local coremodel = luci.sys.exec("cat /usr/lib/os-release 2>/dev/null |grep OPENWRT_ARCH 2>/dev/null |awk -F '\"' '{print $2}' 2>/dev/null")
local coremodel2 = luci.sys.exec("opkg status libc 2>/dev/null |grep 'Architecture' |awk -F ': ' '{print $2}' 2>/dev/null")
if not coremodel or coremodel == "" then
return coremodel2 .. "," .. coremodel2
@ -212,6 +219,7 @@ function action_status()
watchdog = is_watchdog(),
daip = daip(),
dase = dase(),
uh_port = uh_port(),
web = is_web(),
cn_port = cn_port(),
mode = mode();

View File

@ -2,11 +2,8 @@
local NXFS = require "nixio.fs"
local SYS = require "luci.sys"
local HTTP = require "luci.http"
local DISP = require "luci.dispatcher"
local UTIL = require "luci.util"
m = Map("openclash", translate("Server logs"))
m = Map("openclash", translate("Server Logs"))
s = m:section(TypedSection, "openclash")
m.pageaction = false
s.anonymous = true

View File

@ -34,6 +34,7 @@ s:tab("dashboard", translate("Dashboard Settings"))
s:tab("rules_update", translate("Rules Update"))
s:tab("geo_update", translate("GEOIP Update"))
s:tab("version_update", translate("Version Update"))
s:tab("debug", translate("Debug Logs"))
---- Operation Mode
o = s:taboption("op_mode", ListValue, "operation_mode", font_red..bold_on..translate("Select Operation Mode")..bold_off..font_off)
@ -62,7 +63,7 @@ o:depends("en_mode", "redir-host")
o:depends("en_mode", "fake-ip")
o:value("0", translate("Disable"))
o:value("1", translate("Enable"))
o.default = "0"
o.default = "1"
o = s:taboption("op_mode", ListValue, "proxy_mode", font_red..bold_on..translate("Proxy Mode")..bold_off..font_off)
o.description = translate("Select Proxy Mode")
@ -450,6 +451,24 @@ o.description = translate("Set Dashboard Secret")
core_update = s:taboption("version_update", DummyValue, "", nil)
core_update.template = "openclash/update"
---- debug
debug_log = s:taboption("debug", Value, "debug_log")
debug_log.template = "cbi/tvalue"
debug_log.readonly=true
debug_log.rows = 30
debug_log.wrap = "off"
function debug_log.cfgvalue(self, section)
return NXFS.readfile("/tmp/openclash_debug.log") or ""
end
o = s:taboption("debug", Button, translate("Generate Logs"))
o.title = translate("Generate Logs")
o.inputtitle = translate("Click to Generate")
o.inputstyle = "reload"
o.write = function()
SYS.call("/usr/share/openclash/openclash_debug.sh")
end
-- [[ Edit Server ]] --
s = m:section(TypedSection, "dns_servers", translate("Add Custom DNS Servers")..translate("(Take Effect After Choose Above)"))
s.anonymous = true

View File

@ -44,41 +44,7 @@
var dase = document.getElementById('_dase');
var dapo = document.getElementById('_dapo');
var clashversion = document.getElementById('_clashversion');
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "status")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
clash.innerHTML = status.clash ? '<b><font color=green><%:RUNNING%></font></b>' : '<b><font color=red><%:NOT RUNNING%></font></b>';
if ( status.mode == "fake-ip\n" )
{
mode.innerHTML = status.clash ? "<b><font color=green><%: Fake-IP增强模式 %></font></b>" : '<b><font color=red><%:NOT RUNNING%></font></b>';
}
else if ( status.mode == "redir-host\n" )
{
mode.innerHTML = status.clash ? "<b><font color=green><%: Redir-Host兼容模式 %></font></b>" : '<b><font color=red><%:NOT RUNNING%></font></b>';
}
else if ( status.mode == "redir-host-tun\n" )
{
mode.innerHTML = status.clash ? "<b><font color=green><%: Redir-HostTUN模式 %></font></b>" : '<b><font color=red><%:NOT RUNNING%></font></b>';
}
else if ( status.mode == "fake-ip-tun\n" )
{
mode.innerHTML = status.clash ? "<b><font color=green><%: Fake-IPTUN模式 %></font></b>" : '<b><font color=red><%:NOT RUNNING%></font></b>';
}
else if ( status.mode == "redir-host-vpn\n" )
{
mode.innerHTML = status.clash ? "<b><font color=green><%: Redir-Host游戏模式 %></font></b>" : '<b><font color=red><%:NOT RUNNING%></font></b>';
}
else if ( status.mode == "fake-ip-vpn\n" )
{
mode.innerHTML = status.clash ? "<b><font color=green><%: Fake-IP游戏模式 %></font></b>" : '<b><font color=red><%:NOT RUNNING%></font></b>';
}
watchdog.innerHTML = status.watchdog ? '<b><font color=green><%:RUNNING%></font> </b>' : '<b><font color=red><%:NOT RUNNING%></font></b>';
daip.innerHTML = status.daip ? "<b><font color=green>"+status.daip+"</font></b>" : "<b><font color=red>"+"<%:Not Set%>"+"</font></b>";
dase.innerHTML = status.dase ? "<b><font color=green>"+status.dase+"</font></b>" : "<b><font color=red>"+"<%:Not Set%>"+"</font></b>";
dapo.innerHTML = status.cn_port ? "<b><font color=green>"+status.cn_port+"</font></b>" : "<b><font color=red>"+"<%:Not Set%>"+"</font></b>";
web.innerHTML = status.web ? '<input type="button" class="cbi-button cbi-button-reload" value="<%:打开控制面板%>" onclick="return ycad_dashboard(this)"/>' : '<b><font color=red><%:NOT RUNNING%></font></b>';
webo.innerHTML = status.web ? '<input type="button" class="cbi-button cbi-button-reload" value="<%:打开控制面板%>" onclick="return net_dashboard(this)"/>' : '<b><font color=red><%:NOT RUNNING%></font></b>';
}
});
XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "services", "openclash", "status")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
clash.innerHTML = status.clash ? '<b><font color=green><%:RUNNING%></font></b>' : '<b><font color=red><%:NOT RUNNING%></font></b>';
@ -115,13 +81,21 @@
}
});
function winOpen(url)
{
var winOpen = window.open(url);
if(winOpen == null || typeof(winOpen) == 'undefined'){
window.location.href=url;
}
}
function ycad_dashboard(btn)
{
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "status")%>', status.cn_port, function(x, status) {
btn.disabled = true;
btn.value = '<%:打开控制面板%>';
url1='<%="http://'+window.location.hostname+'/luci-static/openclash?hostname='+ status.daip + '&port=' + status.cn_port + '&secret=' + status.dase +'"%>';
window.open(url1);
url1='<%="http://'+window.location.hostname+status.uh_port+'/luci-static/openclash?hostname='+ status.daip + '&port=' + status.cn_port + '&secret=' + status.dase +'"%>';
winOpen(url1);
return false;
});
}
@ -131,7 +105,7 @@
btn.disabled = true;
btn.value = '<%:打开控制面板%>';
url2='http://'+window.location.hostname+':'+status.cn_port+'/ui';
window.open(url2);
winOpen(url2);
return false;
});
}
@ -139,25 +113,25 @@
function homepage()
{
url3='https://github.com/vernesong/OpenClash';
window.open(url3);
winOpen(url3);
}
function wikipage()
{
url5='https://github.com/vernesong/OpenClash/wiki';
window.open(url5);
winOpen(url5);
}
function telegrampage()
{
url6='https://t.me/joinchat/D4mVX0n-n5mOK6YO_W3_Og';
window.open(url6);
winOpen(url6);
}
function sponsorpage()
{
url7='https://ko-fi.com/vernesong';
window.open(url7);
winOpen(url7);
}
@ -197,7 +171,7 @@
function go_update()
{
url4='https://github.com/vernesong/OpenClash/releases';
window.open(url4);
winOpen(url4);
}
var startlog = document.getElementById('_clashstart');

View File

@ -7,7 +7,7 @@
</p>
</td></tr>
<tr><td width="25%"> 已选择编译版本 </td><td width="25%" align="left" id="CORE_VERSION"><%:Collecting data...%></td><td width="25%"> 上次检查更新时间 </td><td width="25%" align="left" id="CHECKTIME"><%:Collecting data...%></td></tr>
<tr><td width="25%"> 处理器架构(PROC </td><td width="25%" align="left" id="CPU_MODEL"><%:Collecting data...%></td><td width="25%"> 处理器架构OPKG </td><td width="25%" align="left" id="CPU_MODEL2"><%:Collecting data...%></td></tr>
<tr><td width="25%"> 处理器架构(OS </td><td width="25%" align="left" id="CPU_MODEL"><%:Collecting data...%></td><td width="25%"> 处理器架构OPKG </td><td width="25%" align="left" id="CPU_MODEL2"><%:Collecting data...%></td></tr>
<tr><td width="100%" colspan="4">
<p align="center">
<b> 内核路径:/etc/openclash/core/clash </b>
@ -43,7 +43,7 @@
</table>
</fieldset>
<fieldset class="cbi-section">
<table>
<table width="100%">
<tr><td width="100%" colspan="4" align="center" id="restore"><%:Collecting data...%></td></tr>
</table>
</fieldset>
@ -71,99 +71,6 @@
var ma_core_game_up = document.getElementById('ma_core_game_up');
var ma_op_up = document.getElementById('ma_op_up');
var restore = document.getElementById('restore');
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "update")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
var cpu_models = status.coremodel;
var arr_model = cpu_models.split(",");
var cpu_model1 = arr_model[0];
var cpu_model22 = arr_model[1];
cpu_model.innerHTML = cpu_model1 ? "<b><font color=green>"+cpu_model1+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
cpu_model2.innerHTML = cpu_model22 ? "<b><font color=green>"+cpu_model22+"</font></b>" : "<b><font color=red><%:Model Not Found%></font></b>";
if ( status.corever != "0\n" && status.corever != "" ) {
core_version.innerHTML = "<b><font color=green>"+status.corever+"</font></b>";
}
else {
core_version.innerHTML = "<b><font color=red><%:未选择编译版本,请到常规设置标签中配置%></font></b>";
}
if ( status.upchecktime != "1" ) {
checktime.innerHTML = "<b><font color=green>"+status.upchecktime+"</font></b>";
}
else {
checktime.innerHTML = "<b><font color=red><%:查询更新失败%></font></b>";
}
if ( status.corecv == "0" ) {
core_cv.innerHTML = "<b><font color=red><%:File Not Exist%></font></b>";
}
else if (status.corecv != "") {
core_cv.innerHTML = "<b><font color=green>"+status.corecv+"</font></b>";
}
else {
core_cv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
}
if ( status.coretuncv == "0" ) {
core_tun_cv.innerHTML = "<b><font color=red><%:File Not Exist%></font></b>";
}
else if (status.coretuncv != "") {
core_tun_cv.innerHTML = "<b><font color=green>"+status.coretuncv+"</font></b>";
}
else {
core_tun_cv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
}
if ( status.coregamecv == "0" ) {
core_game_cv.innerHTML = "<b><font color=red><%:File Not Exist%></font></b>";
}
else if (status.coregamecv != "") {
core_game_cv.innerHTML = "<b><font color=green>"+status.coregamecv+"</font></b>";
}
else {
core_game_cv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
}
var corelv = status.corelv;
var arr_core = corelv.split(",");
var corelvis = arr_core[0];
var coretunlvis = arr_core[1];
var coregamelvis = arr_core[2];
var new_ch = arr_core[3];
if ( new_ch == "2" || new_ch == "4" ) {
core_lv.innerHTML = "<b><font color=green>"+corelvis+"<%:<New>%></font></b>";
}
else if (corelvis != "" && corelvis != "\n" ) {
core_lv.innerHTML = "<b><font color=green>"+corelvis+"</font></b>";
}
else {
core_lv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
}
if ( new_ch == "3" || new_ch == "4" ) {
core_tun_lv.innerHTML = "<b><font color=green>"+coretunlvis+"<%:<New>%></font></b>";
}
else if (coretunlvis != "" && coretunlvis != "\n" ) {
core_tun_lv.innerHTML = "<b><font color=green>"+coretunlvis+"</font></b>";
}
else {
core_tun_lv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
}
if (coregamelvis != "" && coregamelvis != "\n" ) {
core_game_lv.innerHTML = "<b><font color=green>"+coregamelvis+"</font></b>";
}
else {
core_game_lv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
}
var oplv = status.oplv;
var arr_op = oplv.split(",");
var oplvis = arr_op[0];
var new_op = arr_op[1];
op_cv.innerHTML = status.opcv ? "<b><font color=green>"+status.opcv+"</font></b>" : "<b><font color=red><%:Unknown%></font></b>";
if ( new_op == "2" ) {
op_lv.innerHTML = "<b><font color=green>"+oplvis+"<%:<New>%></font></b>";
}
else if (oplvis != "" && oplvis != "\n") {
op_lv.innerHTML = "<b><font color=green>"+oplvis+"</font></b>";
}
else {
op_lv.innerHTML = "<b><font color=red><%:Unknown%></font></b>";
}
}
});
XHR.poll(6, '<%=luci.dispatcher.build_url("admin", "services", "openclash", "update")%>', null, function(x, status) {
if ( x && x.status == 200 ) {
@ -269,6 +176,14 @@
ma_op_up.innerHTML = '<input type="button" class="cbi-button cbi-button-reload" value="<%:下载到本地%>" onclick="return ma_op_update(this)"/>';
restore.innerHTML = '<input type="button" class="cbi-button cbi-button-reset" value="<%:还原默认配置%>" onclick="return restore_config(this)"/>';
function winOpen(url)
{
var winOpen = window.open(url);
if(winOpen == null || typeof(winOpen) == 'undefined'){
window.location.href=url;
}
}
function core_update(btn)
{
@ -320,7 +235,7 @@
if ( x && x.status == 200 ) {
if ( status.corever != "0\n" ) {
url1='https://github.com/vernesong/OpenClash/releases/download/Clash/clash-'+status.corever+'.tar.gz';
window.open(url1);
winOpen(url1);
}
else {
alert('未选择编译版本,请到常规设置标签中配置!')
@ -341,7 +256,7 @@
var coretunlvis = arr_core[1];
if ( status.corever != "0\n" && coretunlvis != "\n" && coretunlvis != "" ) {
url3='https://github.com/Dreamacro/clash/releases/download/TUN/clash-'+status.corever+'-'+coretunlvis+'.gz';
window.open(url3);
winOpen(url3);
}
else if ( status.corever == "0\n" ) {
alert('未选择编译版本,请到常规设置标签中配置!')
@ -362,7 +277,7 @@
if ( x && x.status == 200 ) {
if ( status.corever != "0\n" ) {
url4='https://github.com/vernesong/OpenClash/releases/download/TUN/clash-'+status.corever+'.tar.gz';
window.open(url4);
winOpen(url4);
}
else {
alert('未选择编译版本,请到常规设置标签中配置!')
@ -382,7 +297,7 @@
var oplvis = oplv.substring(oplv.indexOf("v") + 1,oplv.indexOf(","));
if ( oplvis != "" && oplvis != "\n" ) {
url2='https://github.com/vernesong/OpenClash/releases/download/v'+oplvis+'/luci-app-openclash_'+oplvis+'_all.ipk';
window.open(url2);
winOpen(url2);
}
else {
alert('最新版本获取失败,请稍后再试!')

View File

@ -1 +1 @@
<!doctype html><html lang="en" dir="ltr"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/Dreamacro/clash/docs/logo.png"/><title>Clash</title><link href="main.587bc7edc5f3d06c94f4.css" rel="stylesheet"></head><body><div id="root"></div><script src="js/1.bundle.587bc7edc5f3d06c94f4.min.js"></script><script src="js/bundle.587bc7edc5f3d06c94f4.min.js"></script></body></html>
<!doctype html><html lang="en" dir="ltr"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/Dreamacro/clash/docs/logo.png"/><title>Clash</title><link href="main.ccbf66abd21c384a0bf9.css" rel="stylesheet"></head><body><div id="root"></div><script src="js/1.bundle.ccbf66abd21c384a0bf9.min.js"></script><script src="js/bundle.ccbf66abd21c384a0bf9.min.js"></script></body></html>

View File

@ -199,9 +199,9 @@ sub_info_get()
if [ "$?" -eq "0" ] && [ -s "$CFG_FILE" ]; then
config_encode
grep "^ \{0,\}Proxy Group:" "$CFG_FILE" >/dev/null 2>&1 && grep "^ \{0,\}Rule:" "$CFG_FILE" >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
if [ "$?" -eq 0 ]; then
grep "^ \{0,\}Proxy:" "$CFG_FILE" >/dev/null 2>&1 || grep "^ \{0,\}proxy-provider:" "$CFG_FILE" >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
if [ "$?" -eq 0 ]; then
config_su_check
else
config_download_direct

View File

@ -98,7 +98,7 @@ if [ "$CORE_CV" != "$CORE_LV" ] || [ -z "$CORE_CV" ]; then
rm -rf /tmp/clash.tar.gz >/dev/null 2>&1
rm -rf /tmp/clash.gz >/dev/null 2>&1
mkdir -p /etc/openclash/core
[ "$if_restart" -eq 1 ] && /etc/init.d/openclash stop
[ "$if_restart" -eq 1 ] && kill -9 "$(pidof clash|sed 's/$//g')" 2>/dev/null && /etc/init.d/openclash stop
echo "【"$CORE_TYPE"】版本内核下载成功,开始更新..." >$START_LOG
case $CORE_TYPE in
"Tun")

View File

@ -0,0 +1,315 @@
#!/bin/bash
. /lib/functions.sh
status=$(ps|grep -c /usr/share/openclash/openclash_debug.sh)
[ "$status" -gt "3" ] && exit 0
DEBUG_LOG="/tmp/openclash_debug.log"
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
enable_custom_dns=$(uci get openclash.config.enable_custom_dns 2>/dev/null)
rule_source=$(uci get openclash.config.rule_source 2>/dev/null)
enable_custom_clash_rules=$(uci get openclash.config.enable_custom_clash_rules 2>/dev/null)
ipv6_enable=$(uci get openclash.config.ipv6_enable 2>/dev/null)
enable_redirect_dns=$(uci get openclash.config.enable_redirect_dns 2>/dev/null)
direct_dns=$(uci get openclash.config.direct_dns 2>/dev/null)
disable_masq_cache=$(uci get openclash.config.disable_masq_cache 2>/dev/null)
proxy_mode=$(uci get openclash.config.proxy_mode 2>/dev/null)
intranet_allowed=$(uci get openclash.config.intranet_allowed 2>/dev/null)
enable_udp_proxy=$(uci get openclash.config.enable_udp_proxy 2>/dev/null)
enable_rule_proxy=$(uci get openclash.config.enable_rule_proxy 2>/dev/null)
en_mode=$(uci get openclash.config.en_mode 2>/dev/null)
CONFIG_FILE=$(uci get openclash.config.config_path 2>/dev/null)
core_type=$(uci get openclash.config.core_version 2>/dev/null)
cpu_model=$(opkg status libc 2>/dev/null |grep 'Architecture' |awk -F ': ' '{print $2}' 2>/dev/null)
core_version=$(/etc/openclash/core/clash -v 2>/dev/null |awk -F ' ' '{print $2}' 2>/dev/null)
core_tun_version=$(/etc/openclash/core/clash_tun -v 2>/dev/null |awk -F ' ' '{print $2}' 2>/dev/null)
core_game_version=$(/etc/openclash/core/clash_game -v 2>/dev/null |awk -F ' ' '{print $2}' 2>/dev/null)
servers_update=$(uci get openclash.config.servers_update 2>/dev/null)
op_version=$(sed -n 1p /etc/openclash/openclash_version 2>/dev/null)
if [ -z "$CONFIG_FILE" ] || [ ! -f "$CONFIG_FILE" ]; then
CONFIG_NAME=$(ls -lt /etc/openclash/config/ | grep -E '.yaml|.yml' | head -n 1 |awk '{print $9}')
if [ ! -z "$CONFIG_NAME" ]; then
CONFIG_FILE="/etc/openclash/config/$CONFIG_NAME"
fi
fi
ts_cf()
{
if [ "$1" != 1 ]; then
echo "停用"
else
echo "启用"
fi
}
ts_re()
{
if [ -z "$1" ]; then
echo "未安装"
else
echo "已安装"
fi
}
echo "OpenClash 调试日志" > "$DEBUG_LOG"
cat >> "$DEBUG_LOG" <<-EOF
生成时间: $LOGTIME
插件版本: $op_version
EOF
cat >> "$DEBUG_LOG" <<-EOF
#===================== 系统信息 =====================#
主机型号: $(cat /tmp/sysinfo/model 2>/dev/null)
固件版本: $(cat /usr/lib/os-release 2>/dev/null |grep OPENWRT_RELEASE 2>/dev/null |awk -F '"' '{print $2}' 2>/dev/null)
LuCI版本: $(opkg status luci 2>/dev/null |grep 'Version' |awk -F ': ' '{print $2}' 2>/dev/null)
内核版本: $(uname -r 2>/dev/null)
处理器架构: $cpu_model
#此项在使用Tun模式时应为ACCEPT
防火墙转发: $(uci get firewall.@defaults[0].forward 2>/dev/null)
#此项有值时建议到网络-接口-lan的设置中禁用IPV6的DHCP
IPV6-DHCP: $(uci get dhcp.lan.dhcpv6 2>/dev/null)
#此项结果应仅有配置文件的DNS监听地址
Dnsmasq转发设置: $(uci get dhcp.@dnsmasq[0].server 2>/dev/null)
EOF
cat >> "$DEBUG_LOG" <<-EOF
#===================== 依赖检查 =====================#
dnsmasq-full: $(ts_re "$(opkg status dnsmasq-full 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
coreutils: $(ts_re "$(opkg status coreutils 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
coreutils-nohup: $(ts_re "$(opkg status coreutils-nohup 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
bash: $(ts_re "$(opkg status bash 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
curl: $(ts_re "$(opkg status curl 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
jsonfilter: $(ts_re "$(opkg status jsonfilter 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
ca-certificates: $(ts_re "$(opkg status ca-certificates 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
ipset: $(ts_re "$(opkg status ipset 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
ip-full: $(ts_re "$(opkg status ip-full 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
iptables-mod-tproxy: $(ts_re "$(opkg status iptables-mod-tproxy 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
kmod-tun(TUN模式): $(ts_re "$(opkg status kmod-tun 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
luci-compat(Luci-19.07): $(ts_re "$(opkg status luci-compat 2>/dev/null |grep 'Status' |awk -F ': ' '{print $2}' 2>/dev/null)")
EOF
#core
cat >> "$DEBUG_LOG" <<-EOF
#===================== 内核检查 =====================#
EOF
if pidof clash >/dev/null; then
cat >> "$DEBUG_LOG" <<-EOF
运行状态: 运行中
EOF
else
cat >> "$DEBUG_LOG" <<-EOF
运行状态: 未运行
EOF
fi
cat >> "$DEBUG_LOG" <<-EOF
已选择的架构: $core_type
#下方无法显示内核版本号时请确认您的内核版本是否正确或者有无权限
EOF
cat >> "$DEBUG_LOG" <<-EOF
Tun内核版本: $core_tun_version
EOF
if [ ! -f "/etc/openclash/core/clash_tun" ]; then
cat >> "$DEBUG_LOG" <<-EOF
Tun内核文件: 不存在
EOF
else
cat >> "$DEBUG_LOG" <<-EOF
Tun内核文件: 存在
EOF
fi
if [ ! -x "/etc/openclash/core/clash_tun" ]; then
cat >> "$DEBUG_LOG" <<-EOF
Tun内核运行权限: 否
EOF
else
cat >> "$DEBUG_LOG" <<-EOF
Tun内核运行权限: 正常
EOF
fi
cat >> "$DEBUG_LOG" <<-EOF
Game内核版本: $core_game_version
EOF
if [ ! -f "/etc/openclash/core/clash_game" ]; then
cat >> "$DEBUG_LOG" <<-EOF
Game内核文件: 不存在
EOF
else
cat >> "$DEBUG_LOG" <<-EOF
Game内核文件: 存在
EOF
fi
if [ ! -x "/etc/openclash/core/clash_game" ]; then
cat >> "$DEBUG_LOG" <<-EOF
Game内核运行权限: 否
EOF
else
cat >> "$DEBUG_LOG" <<-EOF
Game内核运行权限: 正常
EOF
fi
cat >> "$DEBUG_LOG" <<-EOF
Dev内核版本: $core_version
EOF
if [ ! -f "/etc/openclash/core/clash" ]; then
cat >> "$DEBUG_LOG" <<-EOF
Dev内核文件: 不存在
EOF
else
cat >> "$DEBUG_LOG" <<-EOF
Dev内核文件: 存在
EOF
fi
if [ ! -x "/etc/openclash/core/clash" ]; then
cat >> "$DEBUG_LOG" <<-EOF
Dev内核运行权限: 否
EOF
else
cat >> "$DEBUG_LOG" <<-EOF
Dev内核运行权限: 正常
EOF
fi
cat >> "$DEBUG_LOG" <<-EOF
#===================== 插件设置 =====================#
当前配置文件: $CONFIG_FILE
运行模式: $en_mode
默认代理模式: $proxy_mode
UDP流量转发: $(ts_cf "$enable_udp_proxy")
DNS劫持: $(ts_cf "$enable_redirect_dns")
自定义DNS: $(ts_cf "$enable_custom_dns")
IPV6-DNS解析: $(ts_cf "$ipv6_enable")
Real-IP-DNS地址: $direct_dns
禁用Dnsmasq缓存: $(ts_cf "$disable_masq_cache")
自定义规则: $(ts_cf "$enable_custom_clash_rules")
仅允许内网: $(ts_cf "$intranet_allowed")
仅代理命中规则流量: $(ts_cf "$enable_rule_proxy")
#启动异常时建议关闭此项后重试
保留配置: $(ts_cf "$servers_update")
EOF
if [ "$rule_source" != "0" ]; then
cat >> "$DEBUG_LOG" <<-EOF
#启动异常时建议关闭此项后重试
第三方规则: $rule_source
EOF
else
cat >> "$DEBUG_LOG" <<-EOF
第三方规则: 停用
EOF
fi
cat >> "$DEBUG_LOG" <<-EOF
#===================== 配置文件 =====================#
EOF
if [ -n "$(grep OpenClash-General-Settings "$CONFIG_FILE")" ]; then
sed '/OpenClash-General-Settings/,$d' "$CONFIG_FILE" >> "$DEBUG_LOG" 2>/dev/null
else
/usr/share/openclash/yml_field_name_ch.sh "$CONFIG_FILE" 2>/dev/null
proxy_len=$(sed -n '/^Proxy:/=' "$CONFIG_FILE" 2>/dev/null)
provider_len=$(sed -n '/^proxy-provider:/=' "$CONFIG_FILE" 2>/dev/null)
group_len=$(sed -n '/^Proxy Group:/=' "$CONFIG_FILE" 2>/dev/null)
dns_len=$(sed -n '/^dns:/=' "$CONFIG_FILE" 2>/dev/null)
rule_len=$(sed -n '/^Rule:/=' "$CONFIG_FILE" 2>/dev/null)
if [ "$dns_len" -ge "$proxy_len" ] || [ "$dns_len" -ge "$rule_len" ] || [ "$dns_len" -ge "$group_len" ]; then
echo "错误: 不支持的配置文件, General 设置部分应位于开头,请根据模板修改后重试!" >> "$DEBUG_LOG"
fi 2>/dev/null
if [ "$proxy_len" -ge "$rule_len" ] || [ "$provider_len" -ge "$rule_len" ]; then
echo "错误: 不支持的配置文件,服务器节点设置部分应位于规则之前,请根据模板修改后重试!" >> "$DEBUG_LOG"
fi 2>/dev/null
if [ "$group_len" -ge "$rule_len" ] || [ "$proxy_len" -ge "$group_len" ]; then
echo "错误: 不支持的配置文件,策略组设置部分应位于规则之前、节点之后,请根据模板修改后重试!" >> "$DEBUG_LOG"
fi 2>/dev/null
if [ "$proxy_len" -le "$provider_len" ]; then
sed '/^ \{0,\}Proxy:/,$d' "$CONFIG_FILE" >> "$DEBUG_LOG" 2>/dev/null
elif [ "$proxy_len" -ge "$provider_len" ]; then
sed '/^ \{0,\}proxy-provider:/,$d' "$CONFIG_FILE" >> "$DEBUG_LOG" 2>/dev/null
elif [ -n "$proxy_len" ] && [ -z "$provider_len" ]; then
sed '/^ \{0,\}Proxy:/,$d' "$CONFIG_FILE" >> "$DEBUG_LOG" 2>/dev/null
elif [ -z "$proxy_len" ] && [ -n "$provider_len" ]; then
sed '/^ \{0,\}proxy-provider:/,$d' "$CONFIG_FILE" >> "$DEBUG_LOG" 2>/dev/null
fi 2>/dev/null
fi
#firewall
cat >> "$DEBUG_LOG" <<-EOF
#===================== 防火墙设置 =====================#
#NAT chain
EOF
iptables -t nat -nL PREROUTING --line-number >> "$DEBUG_LOG"
iptables -t nat -nL OUTPUT --line-number >> "$DEBUG_LOG"
cat >> "$DEBUG_LOG" <<-EOF
#Mangle chain
EOF
iptables -t mangle -nL PREROUTING --line-number >> "$DEBUG_LOG"
iptables -t mangle -nL OUTPUT --line-number >> "$DEBUG_LOG"
cat >> "$DEBUG_LOG" <<-EOF
#===================== 路由表状态 =====================#
EOF
echo "#route -n" >> "$DEBUG_LOG"
route -n >> "$DEBUG_LOG" 2>/dev/null
echo "#ip route list" >> "$DEBUG_LOG"
ip route list >> "$DEBUG_LOG" 2>/dev/null
echo "#ip rule show" >> "$DEBUG_LOG"
ip rule show >> "$DEBUG_LOG" 2>/dev/null
if [ "$en_mode" != "fake-ip" ] && [ "$en_mode" != "redir-host" ]; then
cat >> "$DEBUG_LOG" <<-EOF
#===================== Tun设备状态 =====================#
EOF
ip tuntap list >> "$DEBUG_LOG" 2>/dev/null
fi
cat >> "$DEBUG_LOG" <<-EOF
#===================== 端口监听状态 =====================#
EOF
netstat -nlp |grep clash >> "$DEBUG_LOG" 2>/dev/null
cat >> "$DEBUG_LOG" <<-EOF
#===================== 测试本机网络连接 =====================#
EOF
curl -I -m 5 www.baidu.com >> "$DEBUG_LOG" 2>/dev/null
cat >> "$DEBUG_LOG" <<-EOF
#===================== 测试本机DNS查询 =====================#
EOF
nslookup www.baidu.com >> "$DEBUG_LOG" 2>/dev/null
cat >> "$DEBUG_LOG" <<-EOF
#===================== 最近运行日志 =====================#
EOF
tail -n 20 "/tmp/openclash.log" >> "$DEBUG_LOG" 2>/dev/null

View File

@ -8,8 +8,8 @@ SECRET=$(uci get openclash.config.dashboard_password 2>/dev/null)
LAN_IP=$(uci get network.lan.ipaddr 2>/dev/null |awk -F '/' '{print $1}' 2>/dev/null)
PORT=$(uci get openclash.config.cn_port 2>/dev/null)
curl --connect-timeout 5 --retry 2 -w %{http_code}"\n" -H "Authorization: Bearer ${SECRET}" -H "Content-Type:application/json" -X GET http://"$LAN_IP":"$PORT"/proxies > "$CURL_CACHE" 2>/dev/null
if [ "$(sed -n '$p' "$CURL_CACHE")" -eq "200" ]; then
curl -m 5 --retry 2 -w %{http_code}"\n" -H "Authorization: Bearer ${SECRET}" -H "Content-Type:application/json" -X GET http://"$LAN_IP":"$PORT"/proxies > "$CURL_CACHE" 2>/dev/null
if [ "$(sed -n '$p' "$CURL_CACHE" 2>/dev/null)" = "200" ]; then
cat "$CURL_CACHE" |jsonfilter -e '@["proxies"][@.type="Selector"]["name"]' > "$CURL_GROUP_CACHE" 2>/dev/null
cat "$CURL_CACHE" |jsonfilter -e '@["proxies"][@.type="Selector"]["now"]' > "$CURL_NOW_CACHE" 2>/dev/null
awk 'NR==FNR{a[i]=$0;i++}NR>FNR{print a[j]"#*#"$0;j++}' "$CURL_GROUP_CACHE" "$CURL_NOW_CACHE" > "$HISTORY_PATH" 2>/dev/null

View File

@ -15,17 +15,28 @@ urlencode() {
fi
}
GROUP_STATE() {
echo "$(curl -m 5 -w %{http_code}"\n" -H "Authorization: Bearer ${SECRET}" -H "Content-Type:application/json" -X GET http://"$LAN_IP":"$PORT"/proxies/"$1" 2>/dev/null |sed -n '$p' 2>/dev/null)"
}
if [ -s "$HISTORY_PATH" ]; then
cat $HISTORY_PATH |while read line
do
if [ -z "$(echo $line |grep "#*#")" ]; then
GROUP_NAME=$(echo $line |awk -F '#*#' '{print $1}')
if [ -z "$(echo $line |grep "#*#")" ] || [ -z "$(grep "^$GROUP_NAME$" /tmp/Proxy_Group)" ]; then
continue
else
GROUP_NAME=$(urlencode "$(echo $line |awk -F '#*#' '{print $1}')")
GROUP_NAME=$(urlencode "$GROUP_NAME")
NOW_NAME=$(echo $line |awk -F '#*#' '{print $3}')
[ ! -z "$GROUP_NAME" ] && {
curl -m 5 --retry 2 -H "Authorization: Bearer ${SECRET}" -H "Content-Type:application/json" -X PUT -d '{"name":"'"$NOW_NAME"'"}' http://"$LAN_IP":"$PORT"/proxies/"$GROUP_NAME" >/dev/null 2>&1
}
GROUP_STATE=$(GROUP_STATE "$GROUP_NAME")
GROUP_STATE_NUM=0
while ( [ ! -z "$(pidof clash)" ] && [ "$GROUP_STATE" != "200" ] && [ "$GROUP_STATE_NUM" -le 1 ] )
do
sleep 3
GROUP_STATE_NUM=$(expr "$GROUP_STATE_NUM" + 1)
GROUP_STATE=$(GROUP_STATE "$GROUP_NAME")
done
curl -m 5 --retry 2 -H "Authorization: Bearer ${SECRET}" -H "Content-Type:application/json" -X PUT -d '{"name":"'"$NOW_NAME"'"}' http://"$LAN_IP":"$PORT"/proxies/"$GROUP_NAME" >/dev/null 2>&1
fi
done >/dev/null 2>&1
fi

View File

@ -43,7 +43,7 @@
mv /tmp/rules.yaml /etc/openclash/"$RUlE_SOURCE".yaml >/dev/null 2>&1
sed -i '/^Rule:/a\##updated' /etc/openclash/"$RUlE_SOURCE".yaml >/dev/null 2>&1
echo "替换成功,重新加载 OpenClash 应用新规则..." >$START_LOG
/etc/init.d/openclash reload 2>/dev/null
/etc/init.d/openclash restart 2>/dev/null
echo "${LOGTIME} Other Rules 【$RUlE_SOURCE】 Update Successful" >>$LOG_FILE
else
echo "检测到下载的规则文件没有更新,停止继续操作..." >$START_LOG

View File

@ -31,6 +31,8 @@ LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
START_LOG="/tmp/openclash_start.log"
LOG_FILE="/tmp/openclash.log"
echo "正在卸载旧版本,更新过程请不要刷新页面和进行其他操作 ..." >$START_LOG
uci set openclash.config.enable=0
uci commit openclash
opkg remove luci-app-openclash
echo "正在安装新版本,更新过程请不要刷新页面和进行其他操作 ..." >$START_LOG
opkg install /tmp/openclash.ipk

View File

@ -64,7 +64,7 @@ fi
## 端口转发重启
last_line=$(iptables -t nat -nL PREROUTING --line-number |awk '{print $1}' 2>/dev/null |awk 'END {print}' |sed -n '$p')
op_line=$(iptables -t nat -nL PREROUTING --line-number |grep "openclash" 2>/dev/null |awk '{print $1}' 2>/dev/null |head -1)
if [ "$last_line" -ne "$op_line" ]; then
if [ "$last_line" != "$op_line" ] && [ -z "$core_type" ]; then
iptables -t nat -D PREROUTING -p tcp -j openclash
iptables -t nat -A PREROUTING -p tcp -j openclash
echo "$LOGTIME Watchdog: Reset Firewall For Enabling Redirect." >>$LOG_FILE

View File

@ -90,16 +90,29 @@
else
sed -i "/^dns:/i\external-controller: ${controller_address}:${5}" "$7"
fi
uci set openclash.config.config_reload=0
fi
if [ -z "$(grep '^secret: $4' "$7")" ]; then
if [ -z "$(grep '^secret: \"$4\"' "$7")" ]; then
if [ ! -z "$(grep "^ \{0,\}secret:" "$7")" ]; then
sed -i "/^ \{0,\}secret:/c\secret: \"${4}\"" "$7"
else
sed -i "/^dns:/i\secret: \"${4}\"" "$7"
fi
uci set openclash.config.config_reload=0
fi
if [ -z "$(grep "^ \{0,\}device-url:" "$7")" ] && [ "$15" -eq 2 ]; then
uci set openclash.config.config_reload=0
elif [ -z "$(grep "^ \{0,\}tun:" "$7")" ] && [ -n "$15" ]; then
uci set openclash.config.config_reload=0
elif [ -n "$(grep "^ \{0,\}tun:" "$7")" ] && [ -z "$15" ]; then
uci set openclash.config.config_reload=0
elif [ -n "$(grep "^ \{0,\}device-url:" "$7")" ] && [ "$15" -eq 1 ]; then
uci set openclash.config.config_reload=0
fi
uci commit openclash
sed -i '/^ \{0,\}tun:/,/^ \{0,\}enable:/d' "$7" 2>/dev/null
sed -i '/^ \{0,\}device-url:/d' "$7" 2>/dev/null
sed -i '/^ \{0,\}dns-listen:/d' "$7" 2>/dev/null

View File

@ -191,12 +191,14 @@ yml_servers_set()
echo "正在写入【$type】-【$name】节点到配置文件【$CONFIG_NAME】..." >$START_LOG
if [ "$obfs" != "none" ]; then
if [ "$obfs" != "none" ] && [ -n "$obfs" ]; then
if [ "$obfs" = "websocket" ]; then
obfss="plugin: v2ray-plugin"
else
obfss="plugin: obfs"
fi
else
obfss=""
fi
if [ "$obfs_vmess" = "websocket" ]; then

View File

@ -65,11 +65,17 @@ msgstr "文件不存在"
msgid "Not Set"
msgstr "未设置"
msgid "Server logs"
msgid "Server Logs"
msgstr "运行日志"
msgid "Logs"
msgstr "运行日志"
msgid "Debug Logs"
msgstr "调试日志"
msgid "Generate Logs"
msgstr "生成日志"
msgid "Click to Generate"
msgstr "点击生成"
msgid "Enable Clash"
msgstr "启动 OpenClash"