From eec89ca1dcc3783d6f31db744fa800866e38e87c Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Sat, 29 Feb 2020 19:16:22 +0800 Subject: [PATCH] luci-app-clash: bump to 1.5.9d --- package/ntlf9t/luci-app-clash/Makefile | 2 +- .../luasrc/controller/clash.lua | 16 ++++++++++--- .../luasrc/model/cbi/clash/create.lua | 4 ++++ .../luasrc/model/cbi/clash/ip-rules.lua | 2 ++ .../luci-app-clash/luasrc/view/clash/list.htm | 24 ++++++++++++++++--- .../ntlf9t/luci-app-clash/po/zh-cn/clash.po | 8 ++++++- .../luci-app-clash/root/etc/init.d/clash | 12 ++++++---- .../clash/{kill.sh => clash-watchdog.sh} | 9 ++----- .../root/usr/share/clash/iprules.sh | 7 +++++- .../root/usr/share/clash/list.sh | 6 +++++ .../root/usr/share/clash/luci_version | 2 +- 11 files changed, 70 insertions(+), 22 deletions(-) rename package/ntlf9t/luci-app-clash/root/usr/share/clash/{kill.sh => clash-watchdog.sh} (76%) diff --git a/package/ntlf9t/luci-app-clash/Makefile b/package/ntlf9t/luci-app-clash/Makefile index 4e5b215577..e6f1900ff6 100644 --- a/package/ntlf9t/luci-app-clash/Makefile +++ b/package/ntlf9t/luci-app-clash/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-clash -PKG_VERSION:=1.5.8 +PKG_VERSION:=1.5.9 PKG_MAINTAINER:=frainzy1477 diff --git a/package/ntlf9t/luci-app-clash/luasrc/controller/clash.lua b/package/ntlf9t/luci-app-clash/luasrc/controller/clash.lua index 159994fafe..aeefe9fe18 100644 --- a/package/ntlf9t/luci-app-clash/luasrc/controller/clash.lua +++ b/package/ntlf9t/luci-app-clash/luasrc/controller/clash.lua @@ -56,6 +56,7 @@ function index() entry({"admin", "services", "clash", "conf"},call("action_conf")).leaf=true entry({"admin", "services", "clash", "update_config"},call("action_update")).leaf=true entry({"admin", "services", "clash", "game_rule"},call("action_update_rule")).leaf=true + entry({"admin", "services", "clash", "ping_check"},call("action_ping_status")).leaf=true end @@ -90,6 +91,11 @@ local function in_use() end +local function ping_enable() + return luci.sys.exec("uci get clash.config.ping_enable") +end + + local function conf_path() if nixio.fs.access(string.sub(luci.sys.exec("uci get clash.config.use_config"), 1, -2)) then return fss.basename(string.sub(luci.sys.exec("uci get clash.config.use_config"), 1, -2)) @@ -315,16 +321,20 @@ function action_status() in_use = in_use(), conf_path = conf_path(), typeconf = typeconf() + }) +end - - +function action_ping_status() + luci.http.prepare_content("application/json") + luci.http.write_json({ + ping_enable = ping_enable() }) end function act_ping() local e={} e.index=luci.http.formvalue("index") - e.ping=luci.sys.exec("ping -c 1 -W 1 %q 2>&1 | grep -o 'time=[0-9]*.[0-9]' | awk -F '=' '{print$2}'"%luci.http.formvalue("domain")) + e.ping=luci.sys.exec("ping -c 1 -W 1 -w 10 %q 2>&1 | grep -o 'time=[0-9]*.[0-9]' | awk -F '=' '{print$2}'"%luci.http.formvalue("domain")) luci.http.prepare_content("application/json") luci.http.write_json(e) end diff --git a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/create.lua b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/create.lua index 7824cf6c19..831a92acd7 100644 --- a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/create.lua +++ b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/create.lua @@ -62,6 +62,10 @@ cc = s:option(Flag, "create", translate("Enable Create")) cc.default = 1 cc.description = translate("Enable to create configuration") +cc = s:option(Flag, "ping_enable", translate("Enable Ping Servers")) +cc.default = 0 +cc.description = translate("Enable Ping Servers") + o = s:option(Value, "create_tag") o.title = translate("Config Name") o.rmempty = true diff --git a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/ip-rules.lua b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/ip-rules.lua index 3cc61692e4..eb1946383b 100644 --- a/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/ip-rules.lua +++ b/package/ntlf9t/luci-app-clash/luasrc/model/cbi/clash/ip-rules.lua @@ -48,5 +48,7 @@ o.description = translate("Select a policy group to add rule") o = s:option(Value, "ipaaddr", translate("IP/Domain/Address/Keyword/Port")) o.rmempty = false +o = s:option(Flag, "res", translate("No Resolve")) +o.default = 0 return m diff --git a/package/ntlf9t/luci-app-clash/luasrc/view/clash/list.htm b/package/ntlf9t/luci-app-clash/luasrc/view/clash/list.htm index 54275d8ae4..75631cde96 100644 --- a/package/ntlf9t/luci-app-clash/luasrc/view/clash/list.htm +++ b/package/ntlf9t/luci-app-clash/luasrc/view/clash/list.htm @@ -12,17 +12,35 @@ local dsp = require "luci.dispatcher" domain: pings[i].getAttribute("hint") }, function(x, result) { - pings[result.index].innerHTML = (result.ping ? ''+result.ping+' ms' : '<%:Error%>'); + + XHR.get('<%=luci.dispatcher.build_url("admin", "services", "clash", "ping_check")%>', null, function(x, status) { + if ( x && x.status == 200 ) { + if(status.ping_enable==1){ + pings[result.index].innerHTML = (result.ping ? ''+result.ping+' ms' : '<%:Error%>'); + }else{ + pings[result.index].innerHTML = result.ping ? '<%:DISABLED%>' : '<%:DISABLED%>'; + } + } + }) } ); - XHR.poll(10,'<%=luci.dispatcher.build_url("admin", "services", "clash", "ping")%>',{ + XHR.poll(15,'<%=luci.dispatcher.build_url("admin", "services", "clash", "ping")%>',{ index: i, domain: pings[i].getAttribute("hint") }, function(x, result) { - pings[result.index].innerHTML = (result.ping ? ''+result.ping+' ms' : '<%:Error%>'); + + XHR.poll(15,'<%=luci.dispatcher.build_url("admin", "services", "clash", "ping_check")%>', null, function(x, status) { + if ( x && x.status == 200 ) { + if(status.ping_enable==1){ + pings[result.index].innerHTML = (result.ping ? ''+result.ping+' ms' : '<%:Error%>'); + }else{ + pings[result.index].innerHTML = result.ping ? '<%:DISABLED%>' : '<%:DISABLED%>'; + } + } + }) } ); } diff --git a/package/ntlf9t/luci-app-clash/po/zh-cn/clash.po b/package/ntlf9t/luci-app-clash/po/zh-cn/clash.po index 75487142be..97ac893b52 100644 --- a/package/ntlf9t/luci-app-clash/po/zh-cn/clash.po +++ b/package/ntlf9t/luci-app-clash/po/zh-cn/clash.po @@ -1020,4 +1020,10 @@ msgid "Download Online" msgstr "在线下载" msgid "Yacd Dashboard" -msgstr "Yacd控制面板" \ No newline at end of file +msgstr "Yacd控制面板" + +msgid "Enable Ping Servers" +msgstr "启用Ping服务器" + +msgid "DISABLED" +msgstr "禁用" diff --git a/package/ntlf9t/luci-app-clash/root/etc/init.d/clash b/package/ntlf9t/luci-app-clash/root/etc/init.d/clash index b9249d73ce..006f3b9796 100644 --- a/package/ntlf9t/luci-app-clash/root/etc/init.d/clash +++ b/package/ntlf9t/luci-app-clash/root/etc/init.d/clash @@ -20,7 +20,7 @@ REAL_LOG="/usr/share/clash/clash_real.txt" revert_dns() { #=========================================================================================================================== - dns_port=$(grep "^ \{0,\}listen:" $CONFIG_YAML |awk -F ':' '{print $3}' 2>/dev/null) + dns_port=$(grep "^ \{0,\}listen:" $CONFIG_YAML |awk -F ':' '{print $3}' 2>/dev/null) uci del_list dhcp.@dnsmasq[0].server=127.0.0.1#$dns_port >/dev/null 2>&1 uci set dhcp.@dnsmasq[0].noresolv=0 uci delete dhcp.@dnsmasq[0].cachesize @@ -34,7 +34,9 @@ add_cron(){ config_type=$(uci get clash.config.config_type 2>/dev/null) #=========================================================================================================================== sed -i '/clash.txt/d' $CRON_FILE - + + [ -z "$(grep -w "/usr/share/clash/clash-watchdog.sh" $CRON_FILE)" ] && echo "*/1 * * * * /usr/share/clash/clash-watchdog.sh" >> $CRON_FILE + clear=$(uci get clash.config.auto_clear_log 2>/dev/null) if [ "${clear}" -eq 1 ]; then [ -z "$(grep -w "/usr/share/clash/clash.txt" $CRON_FILE)" ] && echo "0 */$(uci get clash.config.clear_time 2>/dev/null) * * * echo '' >/usr/share/clash/clash.txt" >> $CRON_FILE @@ -68,7 +70,7 @@ config_type=$(uci get clash.config.config_type 2>/dev/null) del_cron(){ #=========================================================================================================================== - sed -i '/clash/d' $CRON_FILE + sed -i '/update_all.sh/d' $CRON_FILE sed -i '/clash.txt/d' $CRON_FILE /etc/init.d/cron restart #=========================================================================================================================== @@ -521,7 +523,7 @@ if [ -f $CONFIG_YAML ] && [ "$(ls -l $CONFIG_YAML|awk '{print int($5/1024)}')" echo "Clash for OpenWRT" >$REAL_LOG fi - nohup /usr/share/clash/kill.sh >/dev/null 2>&1 + #nohup /usr/share/clash/clash-watchdog.sh >/dev/null 2>&1 else if [ "${lang}" == "en" ] || [ $lang == "auto" ];then echo " $(date "+%Y-%m-%d %H:%M:%S") - problem with config.yaml, config.yaml is either empty or not found " >> /usr/share/clash/clash.txt @@ -693,7 +695,7 @@ stop(){ echo "" >/usr/share/clash/clash.txt >/dev/null 2>&1 echo "0" > /usr/share/clash/logstatus_check >/dev/null 2>&1 - sh /usr/share/clash/kill.sh + if [ "${lang}" == "en" ] || [ $lang == "auto" ];then echo " $(date "+%Y-%m-%d %H:%M:%S") - CLIENT IS DISABLED " >> /usr/share/clash/clash.txt echo "Client is Disabled " >$REAL_LOG diff --git a/package/ntlf9t/luci-app-clash/root/usr/share/clash/kill.sh b/package/ntlf9t/luci-app-clash/root/usr/share/clash/clash-watchdog.sh similarity index 76% rename from package/ntlf9t/luci-app-clash/root/usr/share/clash/kill.sh rename to package/ntlf9t/luci-app-clash/root/usr/share/clash/clash-watchdog.sh index 85e41d442f..3ff0a098c3 100755 --- a/package/ntlf9t/luci-app-clash/root/usr/share/clash/kill.sh +++ b/package/ntlf9t/luci-app-clash/root/usr/share/clash/clash-watchdog.sh @@ -3,22 +3,17 @@ enable=$(uci get clash.config.enable 2>/dev/null) if [ "${enable}" -eq 1 ];then -while [ $enable -eq 1 ]; -do + if ! pidof clash>/dev/null; then /etc/init.d/clash restart 2>&1 & fi -sleep 60 -continue -done - elif [ "${enable}" -eq 0 ];then if [ -f /tmp/watchlist ];then rm -rf /tmp/watchlist fi -line=$(ps | grep -n '/usr/share/clash/kill.sh'|awk -F ':' '{print $2}' |awk -F ' ' '{print $1}'>/tmp/watchlist) +line=$(ps | grep -n 'clash-watchdog.sh'|awk -F ':' '{print $2}' |awk -F ' ' '{print $1}'>/tmp/watchlist) line_no=$(grep -n '' /tmp/watchlist|awk -F ':' '{print $1}') num=$(grep -c '' /tmp/watchlist| awk '{print $1}') nums=1 diff --git a/package/ntlf9t/luci-app-clash/root/usr/share/clash/iprules.sh b/package/ntlf9t/luci-app-clash/root/usr/share/clash/iprules.sh index 383baf0437..3eed7637a6 100755 --- a/package/ntlf9t/luci-app-clash/root/usr/share/clash/iprules.sh +++ b/package/ntlf9t/luci-app-clash/root/usr/share/clash/iprules.sh @@ -21,7 +21,12 @@ ipadd() config_get "pgroup" "$section" "pgroup" "" config_get "ipaaddr" "$section" "ipaaddr" "" config_get "type" "$section" "type" "" - echo "- $type,$ipaaddr,$pgroup">>/tmp/ipadd.conf + config_get "res" "$section" "res" "" + if [ "${res}" -eq 1 ] || [ ! -z "${res}" ];then + echo "- $type,$ipaaddr,$pgroup,no-resolve">>/tmp/ipadd.conf + else + echo "- $type,$ipaaddr,$pgroup">>/tmp/ipadd.conf + fi } diff --git a/package/ntlf9t/luci-app-clash/root/usr/share/clash/list.sh b/package/ntlf9t/luci-app-clash/root/usr/share/clash/list.sh index 0f2abdc2b2..131528de1a 100755 --- a/package/ntlf9t/luci-app-clash/root/usr/share/clash/list.sh +++ b/package/ntlf9t/luci-app-clash/root/usr/share/clash/list.sh @@ -1,6 +1,10 @@ #!/bin/bash /etc/rc.common . /lib/functions.sh + +#ping=$(uci get clash.config.ping_enable 2>/dev/null) + + enable_list=$(uci get clash.config.cus_list 2>/dev/null) if [ $enable_list -eq 1 ];then @@ -36,7 +40,9 @@ add_address(){ rm -rf /tmp/server.conf /usr/share/clashbackup/address.list >/dev/null 2>&1 } +#if [ $ping -eq 1 ];then add_address >/dev/null 2>&1 +#fi if [ -d /tmp/dnsmasq.clash ];then rm -rf /tmp/dnsmasq.clash diff --git a/package/ntlf9t/luci-app-clash/root/usr/share/clash/luci_version b/package/ntlf9t/luci-app-clash/root/usr/share/clash/luci_version index 1cc9c180e2..2b26b8d213 100644 --- a/package/ntlf9t/luci-app-clash/root/usr/share/clash/luci_version +++ b/package/ntlf9t/luci-app-clash/root/usr/share/clash/luci_version @@ -1 +1 @@ -1.5.8 +1.5.9