OSDN Git Service

luci-app-unblockneteasemusic: bump to 2.13
[immortalwrt/luci.git] / applications / luci-app-unblockneteasemusic / root / usr / share / unblockneteasemusic / debugging.sh
1 #!/bin/sh
2 # Copyright (C) 2021-2022 Tianling Shen <cnsztl@immortalwrt.org>
3
4 . /lib/functions.sh
5
6 NAME="unblockneteasemusic"
7
8 command -v "curl" >"/dev/null" || { echo -e "curl is not found."; exit 1; }
9
10 echo -e "Launching luci-app-unblockneteasmusic Debugging Tool..."
11 echo -e "\n"
12
13 echo -e "OpenWrt info:"
14 ubus call system board || cat "/etc/openwrt_release"
15 echo -e "\n"
16
17 echo -e "uclient-fetch info:"
18 opkg info uclient-fetch
19 opkg info libustream-*
20 uclient-fetch -O- 'https://api.github.com/repos/UnblockNeteaseMusic/server/commits?sha=enhanced&path=precompiled' | jsonfilter -e '@[0].sha' || echo -e "Failed to connect to GitHub with uclient-fetch."
21 echo -e "\n"
22
23 echo -e "Node.js info:"
24 opkg info node
25 echo -e "Node.js is placed at $(command -v node || echo "Not Found")"
26 echo -e "Node.js version: $(node -v 2>"/dev/null" || echo "Not Found")"
27 echo -e "\n"
28
29 echo -e "luci-app-unblockneteasmusic info:"
30 opkg info "luci-app-unblockneteasemusic"
31 ls -lh "/etc/config/$NAME" "/etc/init.d/$NAME" "/usr/share/$NAME"
32 cat "/etc/config/$NAME" | sed -e "s,joox_cookie .*,joox_cookie 'set',g" \
33         -e "s,qq_cookie .*,qq_cookie 'set',g" \
34         -e "s,youtube_key .*,youtube_key 'set',g" \
35         -e "s,proxy_server_ip .*,proxy_server_ip 'set',g"
36 echo -e "\n"
37
38 echo -e "UnblockNeteaseMusic Node.js info:"
39 echo -e "Git HEAD version: $(cat "/usr/share/$NAME/core_local_ver" 2>"/dev/null" || echo "Not Found")"
40 echo -e "Core version: $(node "/usr/share/$NAME/core/app.js" -v 2>"/dev/null" || echo "Not Found")"
41 ls -lh "/usr/share/$NAME/core" 2>"/dev/null"
42 echo -e "\n"
43
44 echo -e "Netease networking info:"
45 curl -fsv "http://music.163.com/song/media/outer/url?id=641644.mp3" 2>&1 | grep "Location" || echo -e "Cannot connect to NeteaseMusic."
46 curl -sSL "http://httpdns.n.netease.com/httpdns/v2/d?domain=music.163.com" || echo -e "Cannot connect to Netease HTTPDNS."
47 config_load "$NAME"
48 config_get custom_proxy "config" "proxy_server_ip"
49 [ -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."; }
50 echo -e "\n"
51
52 echo -e "Port status:"
53 config_get unm_port "config" "http_port" "5200"
54 config_get unm_ports "config" "https_port" "5201"
55 [ "$(config_get "config" "hijack_ways")" = "use_hosts" ] && { unm_port="80"; unm_ports="443"; }
56 netstat -tlpen | grep "$unm_port" || echo -e "No instance found on port $unm_port."
57 netstat -tlpen | grep "$unm_ports" || echo -e "No instance found on port $unm_ports."
58 echo -e "\n"
59
60 echo -e "PROCD running info:"
61 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')"
62 [ "$(echo -e "$running_stat" | jsonfilter -e "@.$NAME.instances.$NAME.running")" == "true" ] || is_stopped=1
63 echo -e "$running_stat"
64
65 echo -e "\n"
66
67 [ -n "$is_stopped" ] || {
68         echo -e "Firewall info:"
69
70         [ -e "/etc/nftables.d/90-$NAME-rules.nft" ] || echo -e 'netease_cloud_music nft rule file not found.'
71         echo -e ""
72         nft list set inet fw4 "acl_neteasemusic_http" 2>&1
73         echo -e ""
74         nft list set inet fw4 "acl_neteasemusic_https" 2>&1
75         echo -e ""
76         nft list set inet fw4 "local_addr" 2>&1
77         echo -e ""
78         nft list set inet fw4 "neteasemusic" 2>&1
79         echo -e ""
80         nft list chain inet fw4 "input_wan" | grep "unblockneteasemusic-http-" 2>"/dev/null" || echo -e 'Http Port pub access rule not found.'
81         echo -e ""
82         nft list chain inet fw4 "input_wan" | grep "unblockneteasemusic-https-" 2>"/dev/null" || echo -e 'Https Port pub access rule not found.'
83         echo -e ""
84         nft list chain inet fw4 "netease_cloud_music" 2>&1
85         echo -e ""
86         nft list chain inet fw4 "netease_cloud_music_redir" 2>&1
87         echo -e ""
88         cat "/tmp/dnsmasq.d/dnsmasq-$NAME.conf"
89         echo -e "\n"
90
91         echo -e "Testing source replacing..."
92         lan_ip="$(uci -q get "network.lan.ipaddr" || echo "127.0.0.1")"
93
94         echo -n "" > "/tmp/unblockneteasemusic.log"
95         curl -sSL -X "POST" "https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=" --data "params=bf3kf%2BOyalbxNS%2FeHAXquH8D2nt2YrhBzww4zy5rj2H%2BeAhdOIaGh4HHHzcoREFcu9Ve35LUgc%2BGE1YJD1HxrJ87ucm5zK%2FFn1lLvHFv1A8ZAuyU1afjG28s2Xja6zpfg00T0EcCeqkK61OpTfAaqw%3D%3D&encSecKey=6bab0dfa7ee3b292f9263a7af466636731cdbbd1d8747c9178c17477e70be899b7788c4a4e315c9fdb8c6e787603db6f9dff62c356f164d35b16b7f2d9ad5ede3cc7336130605521a8f916d308ce86b15c32b81c883ae2ba9c244444d91e1683be93fa0ea3e2a85207c9d693b86b5bb31adb002dd56c0bbcce9c73ec3bf5c105"
96         echo -e ""
97         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"
98         echo -e ""
99 }
100
101 cat "/tmp/$NAME.log" 2>"/dev/null" || echo -e "Log is not avaiable."