debugging.sh 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. 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."
  15. echo -e "\n"
  16. echo -e "Node.js info:"
  17. opkg info node
  18. echo -e "Node.js is placed at $(command -v node || echo "Not Found")"
  19. echo -e "Node.js version: $(node -v 2>"/dev/null" || echo "Not Found")"
  20. echo -e "\n"
  21. echo -e "luci-app-unblockneteasmusic info:"
  22. opkg info "luci-app-unblockneteasemusic"
  23. ls -lh "/etc/config/$NAME" "/etc/init.d/$NAME" "/usr/share/$NAME"
  24. cat "/etc/config/$NAME" | sed -e "s,joox_cookie .*,joox_cookie 'set',g" \
  25. -e "s,migu_cookie .*,migu_cookie 'set',g" \
  26. -e "s,qq_cookie .*,qq_cookie 'set',g" \
  27. -e "s,youtube_key .*,youtube_key 'set',g" \
  28. -e "s,proxy_server_ip .*,proxy_server_ip 'set',g"
  29. echo -e "\n"
  30. echo -e "UnblockNeteaseMusic Node.js info:"
  31. echo -e "Git HEAD version: $(cat "/usr/share/$NAME/core_local_ver" 2>"/dev/null" || echo "Not Found")"
  32. echo -e "Core version: $(node "/usr/share/$NAME/core/app.js" -v 2>"/dev/null" || echo "Not Found")"
  33. ls -lh "/usr/share/$NAME/core" 2>"/dev/null"
  34. echo -e "\n"
  35. echo -e "Netease networking info:"
  36. curl -fsv "http://music.163.com/song/media/outer/url?id=641644.mp3" 2>&1 | grep "Location" || echo -e "Cannot connect to NeteaseMusic."
  37. curl -sSL "http://httpdns.n.netease.com/httpdns/v2/d?domain=music.163.com" || echo -e "Cannot connect to Netease HTTPDNS."
  38. config_load "$NAME"
  39. config_get custom_proxy "config" "proxy_server_ip"
  40. [ -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."; }
  41. echo -e "\n"
  42. echo -e "Port status:"
  43. config_get unm_port "config" "http_port" "5200"
  44. config_get unm_ports "config" "https_port" "5201"
  45. [ "$(config_get "config" "hijack_ways")" = "use_hosts" ] && { unm_port="80"; unm_ports="443"; }
  46. netstat -tlpen | grep "$unm_port" || echo -e "No instance found on port $unm_port."
  47. netstat -tlpen | grep "$unm_ports" || echo -e "No instance found on port $unm_ports."
  48. echo -e "\n"
  49. echo -e "PROCD running info:"
  50. running_stat="$(ubus call service list '{"name": "unblockneteasemusic", "verbose": true}' | \
  51. sed -e 's,"JOOX_COOKIE".*","JOOX_COOKIE": "set",g' \
  52. -e 's,"MIGU_COOKIE".*","MIGU_COOKIE": "set",g' \
  53. -e 's,"QQ_COOKIE".*","QQ_COOKIE": "set",g' \
  54. -e 's,"YOUTUBE_KEY".*","YOUTUBE_KEY": "set",g')"
  55. [ "$(echo -e "$running_stat" | jsonfilter -e "@.$NAME.instances.$NAME.running")" == "true" ] || is_stopped=1
  56. echo -e "$running_stat"
  57. echo -e "\n"
  58. [ -n "$is_stopped" ] || {
  59. echo -e "Firewall info:"
  60. iptables -t "nat" -L "netease_cloud_music" 2>"/dev/null" || echo -e 'Chain "netease_cloud_music" not found.'
  61. echo -e ""
  62. ipset list "neteasemusic" 2>"/dev/null" || echo -e 'Table "neteasemusic" not found.'
  63. echo -e ""
  64. ipset list "acl_neteasemusic_http" 2>"/dev/null" || echo -e 'Table "acl_neteasemusic_http" not found.'
  65. echo -e ""
  66. ipset list "acl_neteasemusic_https" 2>"/dev/null" || echo -e 'Table "acl_neteasemusic_https" not found.'
  67. echo -e ""
  68. cat "/tmp/dnsmasq.d/dnsmasq-$NAME.conf"
  69. echo -e "\n"
  70. echo -e "Testing source replacing..."
  71. lan_ip="$(uci -q get "network.lan.ipaddr" || echo "127.0.0.1")"
  72. 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"
  73. echo -e ""
  74. 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"
  75. echo -e ""
  76. }
  77. cat "/var/run/$NAME/run.log" 2>"/dev/null" || echo -e "Log is not avaiable."