OSDN Git Service

luci-app-unblockneteasemusic: bump to 2.13
[immortalwrt/luci.git] / applications / luci-app-unblockneteasemusic / root / usr / share / unblockneteasemusic / debugging.sh
index e30d0a8..19457df 100755 (executable)
@@ -1,15 +1,17 @@
 #!/bin/sh
-# Copyright (C) 2021 Tianling Shen <cnsztl@immortalwrt.org>
+# Copyright (C) 2021-2022 Tianling Shen <cnsztl@immortalwrt.org>
 
 . /lib/functions.sh
 
+NAME="unblockneteasemusic"
+
 command -v "curl" >"/dev/null" || { echo -e "curl is not found."; exit 1; }
 
 echo -e "Launching luci-app-unblockneteasmusic Debugging Tool..."
 echo -e "\n"
 
 echo -e "OpenWrt info:"
-cat "/etc/openwrt_release"
+ubus call system board || cat "/etc/openwrt_release"
 echo -e "\n"
 
 echo -e "uclient-fetch info:"
@@ -26,23 +28,23 @@ echo -e "\n"
 
 echo -e "luci-app-unblockneteasmusic info:"
 opkg info "luci-app-unblockneteasemusic"
-ls -lh "/etc/config/unblockneteasemusic" "/etc/init.d/unblockneteasemusic" "/usr/share/unblockneteasemusic"
-cat "/etc/config/unblockneteasemusic" | sed -e "s,joox_cookie .*,joox_cookie 'set',g" \
+ls -lh "/etc/config/$NAME" "/etc/init.d/$NAME" "/usr/share/$NAME"
+cat "/etc/config/$NAME" | sed -e "s,joox_cookie .*,joox_cookie 'set',g" \
        -e "s,qq_cookie .*,qq_cookie 'set',g" \
        -e "s,youtube_key .*,youtube_key 'set',g" \
        -e "s,proxy_server_ip .*,proxy_server_ip 'set',g"
 echo -e "\n"
 
 echo -e "UnblockNeteaseMusic Node.js info:"
-echo -e "Git HEAD version: $(cat "/usr/share/unblockneteasemusic/core_local_ver" 2>"/dev/null" || echo "Not Found")"
-echo -e "Core version: $(node "/usr/share/unblockneteasemusic/core/app.js" -v 2>"/dev/null" || echo "Not Found")"
-ls -lh "/usr/share/unblockneteasemusic/core" 2>"/dev/null"
+echo -e "Git HEAD version: $(cat "/usr/share/$NAME/core_local_ver" 2>"/dev/null" || echo "Not Found")"
+echo -e "Core version: $(node "/usr/share/$NAME/core/app.js" -v 2>"/dev/null" || echo "Not Found")"
+ls -lh "/usr/share/$NAME/core" 2>"/dev/null"
 echo -e "\n"
 
 echo -e "Netease networking info:"
 curl -fsv "http://music.163.com/song/media/outer/url?id=641644.mp3" 2>&1 | grep "Location" || echo -e "Cannot connect to NeteaseMusic."
 curl -sSL "http://httpdns.n.netease.com/httpdns/v2/d?domain=music.163.com" || echo -e "Cannot connect to Netease HTTPDNS."
-config_load "unblockneteasemusic"
+config_load "$NAME"
 config_get custom_proxy "config" "proxy_server_ip"
 [ -n "$custom_proxy" ] && { curl -sL -x "$custom_proxy" "http://music.163.com/song/media/outer/url?id=641644.mp3" 2>&1 | grep "Location" || echo -e "Cannot connect to NeteaseMusic via proxy."; }
 echo -e "\n"
@@ -50,20 +52,22 @@ echo -e "\n"
 echo -e "Port status:"
 config_get unm_port "config" "http_port" "5200"
 config_get unm_ports "config" "https_port" "5201"
-[ "x$(config_get "config" "hijack_ways")" = "xuse_hosts" ] && { unm_port="80"; unm_ports="443"; }
+[ "$(config_get "config" "hijack_ways")" = "use_hosts" ] && { unm_port="80"; unm_ports="443"; }
 netstat -tlpen | grep "$unm_port" || echo -e "No instance found on port $unm_port."
 netstat -tlpen | grep "$unm_ports" || echo -e "No instance found on port $unm_ports."
 echo -e "\n"
 
-echo -e "Running info:"
-procd_running_status="$(/etc/init.d/unblockneteasemusic status)"
-echo -e "PROCD running status: $procd_running_status"
-[ "$procd_running_status" = "running" ] && { ps -w | grep "unblockneteasemusic" | grep "app\.js" || echo -e "Thread is not found."; }
+echo -e "PROCD running info:"
+running_stat="$(ubus call service list '{"name": "unblockneteasemusic", "verbose": true}' | sed -e 's,"YOUTUBE_KEY".*","YOUTUBE_KEY": "set",g' -e 's,"QQ_COOKIE".*","QQ_COOKIE": "set",g')"
+[ "$(echo -e "$running_stat" | jsonfilter -e "@.$NAME.instances.$NAME.running")" == "true" ] || is_stopped=1
+echo -e "$running_stat"
+
 echo -e "\n"
 
-[ "$procd_running_status" != "running" ] || {
+[ -n "$is_stopped" ] || {
        echo -e "Firewall info:"
-       [ -e "/etc/nftables.d/90-unblockneteasemusic-rules.nft" ] || echo -e 'netease_cloud_music nft rule file not found.'
+
+       [ -e "/etc/nftables.d/90-$NAME-rules.nft" ] || echo -e 'netease_cloud_music nft rule file not found.'
        echo -e ""
        nft list set inet fw4 "acl_neteasemusic_http" 2>&1
        echo -e ""
@@ -81,7 +85,7 @@ echo -e "\n"
        echo -e ""
        nft list chain inet fw4 "netease_cloud_music_redir" 2>&1
        echo -e ""
-       cat "/tmp/dnsmasq.d/dnsmasq-unblockneteasemusic.conf"
+       cat "/tmp/dnsmasq.d/dnsmasq-$NAME.conf"
        echo -e "\n"
 
        echo -e "Testing source replacing..."
@@ -92,5 +96,6 @@ echo -e "\n"
        echo -e ""
        curl -ksSL -X "POST" -x "http://$lan_ip:$unm_port" "https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=" --data "params=bf3kf%2BOyalbxNS%2FeHAXquH8D2nt2YrhBzww4zy5rj2H%2BeAhdOIaGh4HHHzcoREFcu9Ve35LUgc%2BGE1YJD1HxrJ87ucm5zK%2FFn1lLvHFv1A8ZAuyU1afjG28s2Xja6zpfg00T0EcCeqkK61OpTfAaqw%3D%3D&encSecKey=6bab0dfa7ee3b292f9263a7af466636731cdbbd1d8747c9178c17477e70be899b7788c4a4e315c9fdb8c6e787603db6f9dff62c356f164d35b16b7f2d9ad5ede3cc7336130605521a8f916d308ce86b15c32b81c883ae2ba9c244444d91e1683be93fa0ea3e2a85207c9d693b86b5bb31adb002dd56c0bbcce9c73ec3bf5c105"
        echo -e ""
-       cat "/tmp/unblockneteasemusic.log"
 }
+
+cat "/tmp/$NAME.log" 2>"/dev/null" || echo -e "Log is not avaiable."