From c92577b6124478aee50530864d5704a75ba0bf80 Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Fri, 10 Apr 2020 01:05:44 +0800 Subject: [PATCH] luci-app-openclash: sync with upstream source --- .../files/etc/init.d/openclash | 7 ++-- .../usr/share/openclash/openclash_core.sh | 2 +- .../share/openclash/openclash_history_set.sh | 42 +++++++++++-------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/package/ctcgfw/luci-app-openclash/files/etc/init.d/openclash b/package/ctcgfw/luci-app-openclash/files/etc/init.d/openclash index a6ba8c93a7..01d8757c26 100755 --- a/package/ctcgfw/luci-app-openclash/files/etc/init.d/openclash +++ b/package/ctcgfw/luci-app-openclash/files/etc/init.d/openclash @@ -748,7 +748,7 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then sleep 10 echo "" >$START_LOG else - echo "第五步: 启动 Clash 主程序..." >$START_LOG + echo "第五步: 启动主程序..." >$START_LOG nohup "$CLASH" -d "$CLASH_CONFIG" -f "$CONFIG_FILE" >> $LOG_FILE 2>&1 & #检测proxy_provider配置文件状态 @@ -758,7 +758,7 @@ if [ "$enable" -eq 1 ] && [ -f "$CONFIG_FILE" ]; then echo "第七步: 设置控制面板..." >$START_LOG ln -s /usr/share/openclash/yacd /www/luci-static/openclash 2>/dev/null - echo "第八步: 设置 OpenClash 防火墙规则..." >$START_LOG + echo "第八步: 设置防火墙规则..." >$START_LOG if [ "$(iptables -t nat -nL PREROUTING --line-number |grep "udp dpt:53" |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 '/udp dpt:53/=' 2>/dev/null |sort -rn) @@ -938,8 +938,9 @@ EOF fake_block "$en_mode" "$direct_dns" /etc/init.d/dnsmasq restart >/dev/null 2>&1 if pidof clash >/dev/null; then - echo "第十步: 添加 OpenClash 计划任务,启动进程守护程序..." >$START_LOG + echo "第十步: 还原策略组节点状态..." >$START_LOG /usr/share/openclash/openclash_history_set.sh + echo "第十一步: 添加计划任务,启动进程守护程序..." >$START_LOG add_cron if [ -z "$(uci get dhcp.lan.dhcpv6 2>/dev/null)" ]; then echo "OpenClash 启动成功,请等待服务器上线!" >$START_LOG diff --git a/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_core.sh b/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_core.sh index f4e7e14150..210d466de5 100755 --- a/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_core.sh +++ b/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_core.sh @@ -15,7 +15,7 @@ fi if [ "$(/etc/openclash/clash -v 2>/dev/null |awk -F ' ' '{print $2}')" != "$(sed -n 1p /tmp/clash_last_version 2>/dev/null)" ] || [ -z "$(/etc/openclash/clash -v 2>/dev/null |awk -F ' ' '{print $2}')" ] || [ ! -f /etc/openclash/clash ]; then if [ "$CPU_MODEL" != 0 ]; then - echo "开始下载 OpenClash 内核..." >$START_LOG + echo "开始下载 OpenClash 内核,如等待时间过长请尝试手动下载并上传..." >$START_LOG if pidof clash >/dev/null; then curl -sL --connect-timeout 10 --retry 2 -x http://$PROXY_ADDR:$HTTP_PORT -U "$PROXY_AUTH" https://github.com/vernesong/OpenClash/releases/download/Clash/clash-"$CPU_MODEL".tar.gz -o /tmp/clash.tar.gz >/dev/null 2>&1 else diff --git a/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_history_set.sh b/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_history_set.sh index 9048b6d185..23c8284414 100755 --- a/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_history_set.sh +++ b/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_history_set.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash HISTORY_PATH="/etc/openclash/history" SECRET=$(uci get openclash.config.dashboard_password 2>/dev/null) @@ -7,23 +7,29 @@ PORT=$(uci get openclash.config.cn_port 2>/dev/null) urlencode() { local data - if [ "$#" != 1 ]; then - return 1 + if [ "$#" -eq "1" ]; then + data=$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$1" "") + if [ ! -z "$data" ]; then + echo "${data##/?}" + fi fi - data=$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$1" "") - if [ ! -z "$data" ]; then - echo "${data##/?}" - fi - return 0 } -cat $HISTORY_PATH |while read line -do - if [ -z "$(echo $line |grep "#*#")" ]; then - continue - else - GROUP_NAME=$(urlencode "$(echo $line |awk -F '#*#' '{print $1}')") - NOW_NAME=$(echo $line |awk -F '#*#' '{print $3}') - curl -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 +if [ -s "$HISTORY_PATH" ]; then + for ((i=1;i<=3;i++)) + do + cat $HISTORY_PATH |while read line + do + if [ -z "$(echo $line |grep "#*#")" ]; then + continue + else + GROUP_NAME=$(urlencode "$(echo $line |awk -F '#*#' '{print $1}')") + NOW_NAME=$(echo $line |awk -F '#*#' '{print $3}') + [ ! -z "$GROUP_NAME" ] && { + curl -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 + sleep 1 + done >/dev/null 2>&1 +fi \ No newline at end of file