From ca50a20d6cdc632f57135cb3c0187805b58d53bd Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Thu, 12 Mar 2020 02:06:58 +0800 Subject: [PATCH] luci-app-openclash: sync with upstream source --- .../usr/lib/lua/luci/controller/openclash.lua | 2 +- .../model/cbi/openclash/config-subscribe.lua | 5 ++ .../usr/share/openclash/openclash_version.sh | 6 +- .../usr/share/openclash/yml_proxys_get.sh | 55 ++++++++++++++++++- .../i18n/zh_Hans/openclash.zh-cn.po | 3 + 5 files changed, 64 insertions(+), 7 deletions(-) diff --git a/package/ctcgfw/luci-app-openclash/files/usr/lib/lua/luci/controller/openclash.lua b/package/ctcgfw/luci-app-openclash/files/usr/lib/lua/luci/controller/openclash.lua index 434ef92954..85dd27ac57 100644 --- a/package/ctcgfw/luci-app-openclash/files/usr/lib/lua/luci/controller/openclash.lua +++ b/package/ctcgfw/luci-app-openclash/files/usr/lib/lua/luci/controller/openclash.lua @@ -42,7 +42,7 @@ local function is_web() end local function is_watchdog() - return luci.sys.exec("ps |grep openclash_watchdog.sh |grep -v grep 2>/dev/null |sed -n 1p") + return luci.sys.call("ps |grep openclash_watchdog.sh |grep -v grep >/dev/null") == 0 end local function cn_port() diff --git a/package/ctcgfw/luci-app-openclash/files/usr/lib/lua/luci/model/cbi/openclash/config-subscribe.lua b/package/ctcgfw/luci-app-openclash/files/usr/lib/lua/luci/model/cbi/openclash/config-subscribe.lua index 3736ae2771..c4b8d60fea 100644 --- a/package/ctcgfw/luci-app-openclash/files/usr/lib/lua/luci/model/cbi/openclash/config-subscribe.lua +++ b/package/ctcgfw/luci-app-openclash/files/usr/lib/lua/luci/model/cbi/openclash/config-subscribe.lua @@ -103,6 +103,11 @@ o = s:option(DynamicList, "keyword", font_red..bold_on..translate("Keyword Match o.description = font_red..bold_on..translate("(eg: hk or tw&bgp)")..bold_off..font_off o.rmempty = true +---- exkey +o = s:option(DynamicList, "ex_keyword", font_red..bold_on..translate("Exclude Keyword Match")..bold_off..font_off) +o.description = font_red..bold_on..translate("(eg: hk or tw&bgp)")..bold_off..font_off +o.rmempty = true + local t = { {Commit, Apply} } diff --git a/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_version.sh b/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_version.sh index 005990924c..91302f7d2c 100755 --- a/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_version.sh +++ b/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/openclash_version.sh @@ -10,8 +10,8 @@ if [ "$CKTIME" != "$(grep "CheckTime" $LAST_OPVER 2>/dev/null |awk -F ':' '{prin else curl -sL --connect-timeout 10 --retry 2 "$VERSION_URL" -o $LAST_OPVER >/dev/null 2>&1 fi - if [ "$?" -eq "0" ] && [ "$(ls -l $LAST_OPVER 2>/dev/null |awk '{print int($5)}')" -gt 0 ]; then - if [ "$(sed -n 1p /etc/openclash/openclash_version 2>/dev/null)" = "$(sed -n 1p $LAST_OPVER 2>/dev/null)" ]; then + if [ "$?" -eq "0" ] && [ -s "$LAST_OPVER" ]; then + if [ "$(sed -n 1p /etc/openclash/openclash_version 2>/dev/null |awk -F '-' '{print $1}' |awk -F '.' '{print $2$3}')" -ge "$(sed -n 1p $LAST_OPVER 2>/dev/null |awk -F '-' '{print $1}' |awk -F '.' '{print $2$3}')" ]; then sed -i "/^https:/i\CheckTime:${CKTIME}" "$LAST_OPVER" 2>/dev/null sed -i '/^https:/,$d' $LAST_OPVER else @@ -20,7 +20,7 @@ if [ "$CKTIME" != "$(grep "CheckTime" $LAST_OPVER 2>/dev/null |awk -F ':' '{prin else rm -rf "$LAST_OPVER" fi -elif [ "$(sed -n 1p /etc/openclash/openclash_version 2>/dev/null)" = "$(sed -n 1p $LAST_OPVER 2>/dev/null)" ]; then +elif [ "$(sed -n 1p /etc/openclash/openclash_version 2>/dev/null |awk -F '-' '{print $1}' |awk -F '.' '{print $2$3}')" -ge "$(sed -n 1p $LAST_OPVER 2>/dev/null |awk -F '-' '{print $1}' |awk -F '.' '{print $2$3}')" ]; then sed -i '/^CheckTime:/,$d' $LAST_OPVER echo "CheckTime:$CKTIME" >>$LAST_OPVER fi \ No newline at end of file diff --git a/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/yml_proxys_get.sh b/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/yml_proxys_get.sh index 410a121283..fef001d72d 100755 --- a/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/yml_proxys_get.sh +++ b/package/ctcgfw/luci-app-openclash/files/usr/share/openclash/yml_proxys_get.sh @@ -277,6 +277,7 @@ server_key_get() config_get "name" "$section" "name" "" config_get "keyword" "$section" "keyword" "" + config_get "ex_keyword" "$section" "ex_keyword" "" if [ -z "$name" ]; then name="config" @@ -286,6 +287,11 @@ server_key_get() config_keyword="$keyword" key_section="$1" fi + + if [ ! -z "$ex_keyword" ] && [ "$name.yaml" == "$CONFIG_NAME" ]; then + config_ex_keyword="$ex_keyword" + key_section="$1" + fi } @@ -323,6 +329,40 @@ server_key_match() fi } +server_key_exmatch() +{ + + if [ "$match" = "false" ] || [ ! -z "$(echo "$1" |grep "^ \{0,\}$")" ] || [ ! -z "$(echo "$1" |grep "^\t\{0,\}$")" ]; then + return + fi + + if [ ! -z "$(echo "$1" |grep "&")" ]; then + key_word=$(echo "$1" |sed 's/&/ /g') + match=0 + matchs=0 + for k in $key_word + do + if [ -z "$k" ]; then + continue + fi + + if [ ! -z "$(echo "$2" |grep -i "$k")" ]; then + match=$(( $match + 1 )) + fi + matchs=$(( $matchs + 1 )) + done + if [ "$match" = "$matchs" ]; then + match="false" + else + match="true" + fi + else + if [ ! -z "$(echo "$2" |grep -i "$1")" ]; then + match="false" + fi + fi +} + cfg_new_servers_groups_get() { if [ -z "$1" ]; then @@ -371,9 +411,18 @@ do fi #匹配关键字订阅节点 if [ "$servers_if_update" = "1" ]; then - if [ ! -z "$config_keyword" ]; then - match="false" - config_list_foreach "$key_section" "keyword" server_key_match "$server_name" + if [ ! -z "$config_keyword" ] || [ ! -z "$config_ex_keyword" ]; then + if [ ! -z "$config_keyword" ] && [ -z "$config_ex_keyword" ]; then + match="false" + config_list_foreach "$key_section" "keyword" server_key_match "$server_name" + elif [ -z "$config_keyword" ] && [ ! -z "$config_ex_keyword" ]; then + match="true" + config_list_foreach "$key_section" "ex_keyword" server_key_exmatch "$server_name" + elif [ ! -z "$config_keyword" ] && [ ! -z "$config_ex_keyword" ]; then + match="false" + config_list_foreach "$key_section" "keyword" server_key_match "$server_name" + config_list_foreach "$key_section" "ex_keyword" server_key_exmatch "$server_name" + fi if [ "$match" = "false" ]; then echo "跳过【$server_name】服务器节点..." >$START_LOG diff --git a/package/ctcgfw/luci-app-openclash/i18n/zh_Hans/openclash.zh-cn.po b/package/ctcgfw/luci-app-openclash/i18n/zh_Hans/openclash.zh-cn.po index e2e51c97f0..9fdf5d0756 100644 --- a/package/ctcgfw/luci-app-openclash/i18n/zh_Hans/openclash.zh-cn.po +++ b/package/ctcgfw/luci-app-openclash/i18n/zh_Hans/openclash.zh-cn.po @@ -705,6 +705,9 @@ msgstr "(空值无效)" msgid "Keyword Match" msgstr "筛选节点" +msgid "Exclude Keyword Match" +msgstr "排除节点" + msgid "(eg: hk or tw&bgp)" msgstr "(格式示例:香港、台湾&bgp)"