debugging.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/sh
  2. # Copyright (C) 2021-2022 Tianling Shen <[email protected]>
  3. . /lib/functions.sh
  4. NAME="unblockneteasemusic"
  5. command -v "curl" >"/dev/null" || { echo -e "curl is not found."; exit 1; }
  6. echo -e "Launching luci-app-unblockneteasmusic Debugging Tool..."
  7. echo -e "\n"
  8. echo -e "OpenWrt info:"
  9. ubus call system board || cat "/etc/openwrt_release"
  10. echo -e "\n"
  11. echo -e "uclient-fetch info:"
  12. opkg info uclient-fetch
  13. opkg info libustream-*
  14. opkg info wget-ssl
  15. wget -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."
  16. echo -e "\n"
  17. echo -e "Node.js info:"
  18. opkg info node
  19. echo -e "Node.js is placed at $(command -v node || echo "Not Found")"
  20. echo -e "Node.js version: $(node -v 2>"/dev/null" || echo "Not Found")"
  21. echo -e "\n"
  22. echo -e "luci-app-unblockneteasmusic info:"
  23. opkg info "luci-app-unblockneteasemusic"
  24. ls -lh "/etc/config/$NAME" "/etc/init.d/$NAME" "/usr/share/$NAME"
  25. cat "/etc/config/$NAME" | sed -e "s,joox_cookie .*,joox_cookie 'set',g" \
  26. -e "s,migu_cookie .*,migu_cookie 'set',g" \
  27. -e "s,qq_cookie .*,qq_cookie 'set',g" \
  28. -e "s,youtube_key .*,youtube_key 'set',g" \
  29. -e "s,proxy_server_ip .*,proxy_server_ip 'set',g"
  30. echo -e "\n"
  31. echo -e "UnblockNeteaseMusic Node.js info:"
  32. echo -e "Git HEAD version: $(cat "/usr/share/$NAME/core_local_ver" 2>"/dev/null" || echo "Not Found")"
  33. echo -e "Core version: $(node "/usr/share/$NAME/core/app.js" -v 2>"/dev/null" || echo "Not Found")"
  34. ls -lh "/usr/share/$NAME/core" 2>"/dev/null"
  35. echo -e "\n"
  36. echo -e "Netease networking info:"
  37. curl -fsv "http://music.163.com/song/media/outer/url?id=641644.mp3" 2>&1 | grep "Location" || echo -e "Cannot connect to NeteaseMusic."
  38. curl -sSL "http://httpdns.n.netease.com/httpdns/v2/d?domain=music.163.com" || echo -e "Cannot connect to Netease HTTPDNS."
  39. config_load "$NAME"
  40. config_get custom_proxy "config" "proxy_server_ip"
  41. [ -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."; }
  42. echo -e "\n"
  43. echo -e "Port status:"
  44. config_get unm_port "config" "http_port" "5200"
  45. config_get unm_ports "config" "https_port" "5201"
  46. [ "$(config_get "config" "hijack_ways")" = "use_hosts" ] && { unm_port="80"; unm_ports="443"; }
  47. netstat -tlpen | grep "$unm_port" || echo -e "No instance found on port $unm_port."
  48. netstat -tlpen | grep "$unm_ports" || echo -e "No instance found on port $unm_ports."
  49. echo -e "\n"
  50. echo -e "PROCD running info:"
  51. running_stat="$(ubus call service list '{"name": "unblockneteasemusic", "verbose": true}' | \
  52. sed -e 's,"JOOX_COOKIE".*","JOOX_COOKIE": "set",g' \
  53. -e 's,"MIGU_COOKIE".*","MIGU_COOKIE": "set",g' \
  54. -e 's,"QQ_COOKIE".*","QQ_COOKIE": "set",g' \
  55. -e 's,"YOUTUBE_KEY".*","YOUTUBE_KEY": "set",g')"
  56. [ "$(echo -e "$running_stat" | jsonfilter -e "@.$NAME.instances.$NAME.running")" == "true" ] || is_stopped=1
  57. echo -e "$running_stat"
  58. echo -e "\n"
  59. [ -n "$is_stopped" ] || {
  60. echo -e "Firewall info:"
  61. if [ -e "$(command -v fw4)" ]; then
  62. [ -e "/var/run/$NAME/fw4.nft" ] || echo -e 'netease_cloud_music nft rule file not found.'
  63. echo -e ""
  64. nft list set inet fw4 "acl_neteasemusic_http" 2>&1
  65. echo -e ""
  66. nft list set inet fw4 "acl_neteasemusic_https" 2>&1
  67. echo -e ""
  68. nft list set inet fw4 "neteasemusic" 2>&1
  69. echo -e ""
  70. nft list set inet fw4 "neteasemusic6" 2>&1
  71. echo -e ""
  72. nft list chain inet fw4 "netease_cloud_music" 2>&1
  73. echo -e ""
  74. nft list chain inet fw4 "netease_cloud_music_redir" 2>&1
  75. else
  76. iptables -t "nat" -L "netease_cloud_music" 2>"/dev/null" || echo -e 'Chain "netease_cloud_music" not found.'
  77. echo -e ""
  78. ipset list "neteasemusic" 2>"/dev/null" || echo -e 'Table "neteasemusic" not found.'
  79. echo -e ""
  80. ipset list "acl_neteasemusic_http" 2>"/dev/null" || echo -e 'Table "acl_neteasemusic_http" not found.'
  81. echo -e ""
  82. ipset list "acl_neteasemusic_https" 2>"/dev/null" || echo -e 'Table "acl_neteasemusic_https" not found.'
  83. fi
  84. echo -e ""
  85. dnsmasq_uci_config="$(uci -q show "dhcp.@dnsmasq[0]" | awk 'NR==1 {split($0, conf, /[.=]/); print conf[2]}')"
  86. if [ -f "/tmp/etc/dnsmasq.conf.$dnsmasq_uci_config" ]; then
  87. dnsmasq_dir="$(awk -F '=' '/^conf-dir=/ {print $2}' "/tmp/etc/dnsmasq.conf.$dnsmasq_uci_config")"
  88. else
  89. dnsmasq_dir="/tmp/dnsmasq.d"
  90. fi
  91. cat "$dnsmasq_dir/dnsmasq-$NAME.conf"
  92. echo -e "\n"
  93. echo -e "Testing source replacing..."
  94. lan_ip="$(uci -q get "network.lan.ipaddr" || echo "127.0.0.1")"
  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. cat "/var/run/$NAME/run.log" 2>"/dev/null" || echo -e "Log is not avaiable."