OSDN Git Service

luci-app-unblockneteasemusic: bump to 2.11-2
authorTianling Shen <cnsztl@immortalwrt.org>
Fri, 17 Sep 2021 17:18:49 +0000 (01:18 +0800)
committerTianling Shen <cnsztl@immortalwrt.org>
Fri, 17 Sep 2021 17:18:49 +0000 (01:18 +0800)
Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
applications/luci-app-unblockneteasemusic/Makefile
applications/luci-app-unblockneteasemusic/luasrc/model/cbi/unblockneteasemusic/unblockneteasemusic.lua
applications/luci-app-unblockneteasemusic/root/etc/config/unblockneteasemusic
applications/luci-app-unblockneteasemusic/root/etc/init.d/unblockneteasemusic
applications/luci-app-unblockneteasemusic/root/usr/share/unblockneteasemusic/log_check.sh

index 6faab96..bccde14 100644 (file)
@@ -9,11 +9,11 @@ LUCI_DEPENDS:=+busybox +dnsmasq-full +ipset +jsonfilter +libustream-openssl +nod
 LUCI_PKGARCH:=all
 
 PKG_NAME:=luci-app-unblockneteasemusic
-PKG_VERSION:=2.10
-PKG_RELEASE:=4
+PKG_VERSION:=2.11
+PKG_RELEASE:=2
 
 PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
 
-include ../../luci.mk
+include $(TOPDIR)/feeds/luci/luci.mk
 
 # call BuildPackage - OpenWrt buildroot signature
index 05b1bbb..6a5d183 100644 (file)
@@ -14,15 +14,15 @@ enable.rmempty = false
 
 music_source = s:option(Value, "music_source", translate("音源接口"))
 music_source:value("default", translate("默认"))
-music_source:value("netease", translate("网易云音乐"))
-music_source:value("qq", translate("QQ音乐"))
+music_source:value("bilibili", translate("Bilibili音乐"))
+music_source:value("joox", translate("JOOX音乐"))
+music_source:value("kugou", translate("酷狗音乐"))
 music_source:value("kuwo", translate("酷我音乐"))
 music_source:value("migu", translate("咪咕音乐"))
-music_source:value("kugou", translate("酷狗音乐"))
-music_source:value("baidu", translate("百度音乐"))
-music_source:value("joox", translate("JOOX音乐"))
+music_source:value("pyncmd", translate("网易云音乐(pyncmd)"))
+music_source:value("qq", translate("QQ音乐"))
 music_source:value("youtube", translate("Youtube音乐"))
-music_source:value("bilibili", translate("Bilibili音乐"))
+music_source:value("ytdownload", translate("Youtube音乐(ytdownload)"))
 music_source.description = translate("自定义模式下,多个音源请用空格隔开")
 music_source.default = "default"
 music_source.rmempty = false
@@ -82,11 +82,6 @@ update_time.default = "3"
 update_time.description = translate("设定每天自动检查更新时间")
 update_time:depends("auto_update", 1)
 
-daemon_enable = s:option(Flag, "daemon_enable", translate("启用进程守护"))
-daemon_enable.description = translate("开启后,附属程序会自动检测主程序运行状态,在主程序退出时自动重启")
-daemon_enable.default = 0
-daemon_enable.rmempty = false
-
 download_cert = s:option(Button,"certificate", translate("HTTPS 证书"))
 download_cert.inputtitle = translate("下载 CA 根证书")
 download_cert.description = translate("Linux/iOS/MacOSX在信任根证书后方可正常使用")
index e341d28..2125000 100644 (file)
@@ -7,5 +7,4 @@ config unblockneteasemusic 'config'
        option use_custom_cookie '0'
        option auto_update '1'
        option update_time '3'
-       option daemon_enable '1'
        option advanced_mode '0'
index 2c6fa2c..363a582 100755 (executable)
@@ -2,6 +2,8 @@
 # SPDX-License-Identifier: GPL-3.0-only
 # Copyright (C) 2019-2021 Tianling Shen <cnsztl@immortalwrt.org>
 
+USE_PROCD=1
+
 START=99
 STOP=10
 
@@ -20,32 +22,30 @@ is_enabled() {
        fi
 }
 
-config_padding_arg() {
+append_param() {
+       procd_append_param command "$1" $2
+}
+
+append_param_arg() {
        local value
        config_get value "$1" "$2" $4
-       [ -n "$value" ] && export "$2"="$3 $value"
+       [ -n "$value" ] && append_param "$3" "$value"
 }
 
 append_param_env() {
        local value
        config_get value "$1" "$2"
-       [ -n "$value" ] && export "$3"="$value"
+       [ -n "$value" ] && procd_append_param env "$3"="$value"
 }
 
 uci_get_by_name() {
-       local "index"
-       index=0
-       if [ -n "$4" ]; then
-               index="$4"
-       fi
-       ret="$(uci get "$NAME".@"$1"["${index}"]."$2" 2>/dev/null)"
-       echo "${ret:=$3}"
+       local ret
+       ret="$(uci -q get "$NAME".@"$1"["${4:-0}"]."$2")"
+       echo "${ret:-$3}"
 }
 
-start()
+start_service()
 {
-       stop
-
        config_load "$NAME"
        is_enabled "config" "enable" || exit 1
 
@@ -54,21 +54,25 @@ start()
        sed -i "/$NAME/d" /etc/crontabs/root
        is_enabled "config" "auto_update" && echo "0 ${update_time} * * * /usr/share/$NAME/update.sh update_core" >> "/etc/crontabs/root"
        echo "*/5 * * * * /usr/share/$NAME/log_check.sh" >> "/etc/crontabs/root"
-       /etc/init.d/cron restart > "/dev/null" 2>&1
+       /etc/init.d/cron restart
 
        [ ! -e "/usr/share/$NAME/core/app.js" ] && { rm -f "/usr/share/$NAME/local_ver"; sh "/usr/share/$NAME/update.sh" "update_core_non_restart"; }
        [ ! -e "/usr/share/$NAME/core/app.js" ] && { echo "Core Not Found, please download it before starting." >> "/tmp/$NAME.log"; exit 1; }
 
+       procd_open_instance "$NAME"
+       procd_set_param command node "/usr/share/$NAME/core/app.js"
+
        local http_port https_port hijack_ways
        config_get http_port "config" "http_port" "5200"
        config_get https_port "config" "https_port" "5201"
        config_get hijack_ways "config" "hijack_ways" "use_ipset"
        [ "${hijack_ways}" = "use_hosts" ] && { http_port="80"; https_port="443"; }
+       append_param "-p" "${http_port}":"${https_port}"
 
        local lan_addr
        lan_addr="$(uci get network.lan.ipaddr)"
        if is_enabled "config" "pub_access"; then
-               listen_addr="0.0.0.0"
+               append_param "-a" "0.0.0.0"
 
                iptables -I "INPUT" -p "tcp" --dport "${http_port}" -j "ACCEPT"
                iptables -I "INPUT" -p "tcp" --dport "${https_port}" -j "ACCEPT"
@@ -77,21 +81,19 @@ start()
                mkdir -p "/var/etc/"
                echo "/etc/init.d/$NAME restart" > "/var/etc/$NAME.include"
        else
-               listen_addr="${lan_addr}"
+               append_param "-a" "${lan_addr}"
        fi
 
        local music_source
        config_get music_source "config" "music_source" "default"
-       if [ "${music_source}" = "default" ]; then
-              unset music_source
-       else
-              music_source="-o ${music_source}"
-       fi
+       [ "${music_source}" != "default" ] && append_param -o "${music_source}"
 
-       is_enabled "config" "strict_mode" && strict_mode="-s"
-       config_padding_arg "config" "endpoint_url" "-e" "https://music.163.com"
-       config_padding_arg "config" "netease_server_ip" "-f"
-       config_padding_arg "config" "proxy_server_ip" "-u"
+       append_param_arg "config" "endpoint_url" "-e" "https://music.163.com"
+       append_param_arg "config" "netease_server_ip" "-f"
+       append_param_arg "config" "proxy_server_ip" "-u"
+       is_enabled "config" "strict_mode" && append_param "-s"
+
+       procd_set_param env LOG_FILE="/tmp/$NAME.log"
 
        append_param_env "config" "joox_cookie" "JOOX_COOKIE"
        append_param_env "config" "migu_cookie" "MIGU_COOKIE"
@@ -100,15 +102,17 @@ start()
        append_param_env "config" "self_issue_cert_crt" "SIGN_CERT"
        append_param_env "config" "self_issue_cert_key" "SIGN_KEY"
 
-       is_enabled "config" "enable_flac" && export ENABLE_FLAC="true"
+       is_enabled "config" "enable_flac" && procd_append_param env ENABLE_FLAC="true"
        case "$(config_get "config" "replace_music_source")" in
-               "lower_than_192kbps") export MIN_BR="192000" ;;
-               "lower_than_320kbps") export MIN_BR="320000" ;;
-               "lower_than_999kbps") export MIN_BR="999000" ;;
-               "replace_all") export MIN_BR="999999" ;;
+               "lower_than_192kbps") procd_append_param env MIN_BR="192000" ;;
+               "lower_than_320kbps") procd_append_param env MIN_BR="320000" ;;
+               "lower_than_999kbps") procd_append_param env MIN_BR="600000" ;;
+               "replace_all") procd_append_param env MIN_BR="9999999" ;;
        esac
 
-       node "/usr/share/$NAME/core/app.js" -a "${listen_addr}" -p "${http_port}":"${https_port}" ${music_source} ${endpoint_url} ${netease_server_ip} ${proxy_server_ip} ${strict_mode} >"/tmp/$NAME.log" 2>&1 &
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+       procd_set_param respawn
 
        if [ "${hijack_ways}" = "use_ipset" ]; then
                mkdir -p "/tmp/dnsmasq.d"
@@ -123,10 +127,10 @@ start()
                        ipset=/clientlog.music.163.com/neteasemusic
                        ipset=/clientlog3.music.163.com/neteasemusic
                EOF
-               /etc/init.d/dnsmasq reload >"/dev/null" 2>&1
+               /etc/init.d/dnsmasq reload
 
-               if ! ipset list "acl_neteasemusic_http" > "/dev/null"; then ipset create "acl_neteasemusic_http" hash:ip; fi
-               if ! ipset list "acl_neteasemusic_https" > "/dev/null"; then ipset create "acl_neteasemusic_https" hash:ip; fi
+               ipset list "acl_neteasemusic_http" > "/dev/null" || ipset create "acl_neteasemusic_http" hash:ip
+               ipset list "acl_neteasemusic_https" > "/dev/null" || ipset create "acl_neteasemusic_https" hash:ip
                ip_addr_num="$(uci show "$NAME" | grep -c "filter_mode")"
                let ip_addr_num="ip_addr_num-1"
                [ "${ip_addr_num}" -ge "0" ] && for i in $(seq 0 "${ip_addr_num}")
@@ -148,7 +152,9 @@ start()
                done
 
                ipset list "neteasemusic" > "/dev/null" || ipset create "neteasemusic" hash:ip
-               uclient-fetch -q -O- "http://httpdns.n.netease.com/httpdns/v2/d?domain=music.163.com,interface.music.163.com,interface3.music.163.com,apm.music.163.com,apm3.music.163.com,clientlog.music.163.com,clientlog3.music.163.com" |jsonfilter -e '@.data.*.ip.*' |sort -u |awk '{print "ipset add neteasemusic "$1}' |sh > "/dev/null" 2>&1
+               netease_music_ips="$(uclient-fetch -qO- "http://httpdns.n.netease.com/httpdns/v2/d?domain=music.163.com,interface.music.163.com,interface3.music.163.com,apm.music.163.com,apm3.music.163.com,clientlog.music.163.com,clientlog3.music.163.com" |jsonfilter -e '@.data.*.ip.*')"
+               netease_music_ips2="$(uclient-fetch -qO- "https://music.httpdns.c.163.com/d" --post-data="music.163.com,interface.music.163.com,interface3.music.163.com,apm.music.163.com,apm3.music.163.com,clientlog.music.163.com,clientlog3.music.163.com" |jsonfilter -e '@.dns.*["ips"].*')"
+               echo -e "${netease_music_ips}\n${netease_music_ips2}" |sort -u |awk '{print "ipset add neteasemusic "$1}' |sh
                $IPT_N -N "netease_cloud_music"
                for local_addr in "0.0.0.0/8" "10.0.0.0/8" "127.0.0.0/8" "169.254.0.0/16" "172.16.0.0/12" "192.168.0.0/16" "224.0.0.0/4" "240.0.0.0/4"; do
                        $IPT_N -A "netease_cloud_music" -d "${local_addr}" -j "RETURN"
@@ -174,39 +180,39 @@ start()
                        address=/clientlog3.music.163.com/${lan_addr}
                        address=/music.httpdns.c.163.com/0.0.0.0
                EOF
-               /etc/init.d/dnsmasq reload >"/dev/null" 2>&1
+               /etc/init.d/dnsmasq reload
 
                ip route add "223.252.199.10" dev lo
        fi
+
+       procd_close_instance
 } >"/dev/null" 2>&1
 
-stop()
+stop_service()
 {
-       { ps |grep "$NAME" |grep "app.js" |grep -v "grep" |awk '{print $1}' |xargs kill -9; } > "/dev/null" 2>&1
-
        config_load "$NAME"
 
        sed -i "/$NAME/d" "/etc/crontabs/root"
-       /etc/init.d/cron restart > "/dev/null" 2>&1
-
-       [ -f "${UPGRADE_CONF}" ] && sed -i "/$NAME\/core/d;/$NAME\/local_ver/d" "${UPGRADE_CONF}"
-       is_enabled "config" "keep_core_when_upgrade" && { echo "/usr/share/$NAME/core/" >> "${UPGRADE_CONF}"; echo "/usr/share/$NAME/local_ver" >> "${UPGRADE_CONF}"; }
+       /etc/init.d/cron restart
 
+       rm -f "${UPGRADE_CONF}"
+       is_enabled "config" "keep_core_when_upgrade" && {
+               echo "/usr/share/$NAME/core/" >> "${UPGRADE_CONF}"
+               echo "/usr/share/$NAME/local_ver" >> "${UPGRADE_CONF}"
+       }
        local self_issue_cert_crt self_issue_cert_key
        config_get "self_issue_cert_crt" "config" "self_issue_cert_crt"
        config_get "self_issue_cert_key" "config" "self_issue_cert_key"
        { [ -f "${self_issue_cert_crt}" ] && [ -f "${self_issue_cert_key}" ]; } && {
-               sed -i "/${self_issue_cert_crt//\//\\/}/d" "${UPGRADE_CONF}"
-               sed -i "/${self_issue_cert_key//\//\\/}/d" "${UPGRADE_CONF}"
-
                echo "${self_issue_cert_crt}" >> "${UPGRADE_CONF}"
                echo "${self_issue_cert_key}" >> "${UPGRADE_CONF}"
        }
 
-       http_port="$(cat "/tmp/$NAME.ports" | awk -F ':' 'print $1')"
-       https_port="$(cat "/tmp/$NAME.ports" | awk -F ':' 'print $2')"
-       iptables -D "INPUT" -p "tcp" --dport "${http_port}" -j "ACCEPT"
-       iptables -D "INPUT" -p "tcp" --dport "${https_port}" -j "ACCEPT"
+       [ -f "/tmp/$NAME.ports" ] && {
+               iptables -D "INPUT" -p "tcp" --dport "$(awk -F ':' 'print $1' "/tmp/$NAME.ports")" -j "ACCEPT"
+               iptables -D "INPUT" -p "tcp" --dport "$(awk -F ':' 'print $2' "/tmp/$NAME.ports")" -j "ACCEPT"
+               rm -f "/tmp/$NAME.ports"
+       }
 
        $IPT_N -D "PREROUTING" -p "tcp" -m set --match-set "neteasemusic" "dst" -j "netease_cloud_music"
        $IPT_N -D "KOOLPROXY" -m "set" --match-set "neteasemusic" "dst" -j "RETURN" -m "comment" --comment "KP for UnblockMusic"
@@ -218,8 +224,17 @@ stop()
        echo "" > "/var/etc/$NAME.include"
 
        rm -f "/tmp/dnsmasq.d/dnsmasq-$NAME.conf"
-       /etc/init.d/dnsmasq reload >"/dev/null" 2>&1
+       /etc/init.d/dnsmasq reload
        ip route del "223.252.199.10"
 
        rm -f "/tmp/$NAME.log"
 } >"/dev/null" 2>&1
+
+reload_service() {
+       stop
+       start
+}
+
+service_triggers() {
+       procd_add_reload_trigger "$NAME"
+}
index 2269a83..40e921c 100755 (executable)
@@ -9,5 +9,3 @@ log_file="/tmp/$NAME.log"
 
 log_size="$(expr $(ls -l "${log_file}" | awk -F ' ' '{print $5}') / "1024")"
 [ "${log_size}" -lt "${log_max_size}" ] || echo "" > "${log_file}"
-
-[ "*$(uci get $NAME.@$NAME[0].daemon_enable 2>/dev/null)*" != "*1*" ] || { [ -n "$(ps |grep "$NAME" |grep "app.js" |grep -v "grep")" ] || /etc/init.d/$NAME restart; }