🐶 Sync 2025-11-02 14:26:26

This commit is contained in:
actions-user
2025-11-02 14:26:26 +08:00
parent 64bcc56c2a
commit ac011db799
1557 changed files with 746465 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
config unblockneteasemusic 'config'
option enable '0'
option disable_upgrade_check '1'
option auto_update '1'
option update_time '3'

View File

@@ -0,0 +1,332 @@
#!/bin/sh /etc/rc.common
# SPDX-License-Identifier: GPL-3.0-only
#
# Copyright (C) 2019-2023 Tianling Shen <cnsztl@immortalwrt.org>
USE_PROCD=1
START=99
STOP=10
NAME="unblockneteasemusic"
UNM_DIR="/usr/share/$NAME"
RUN_DIR="/var/run/$NAME"
IPT_N="iptables -t nat"
IPT_INPUT_RULE="unm_input_rule"
FW4="$(command -v fw4)"
# we don't know which is the default server, just take the first one
DNSMASQ_UCI_CONFIG="$(uci -q show "dhcp.@dnsmasq[0]" | awk 'NR==1 {split($0, conf, /[.=]/); print conf[2]}')"
if [ -f "/tmp/etc/dnsmasq.conf.$DNSMASQ_UCI_CONFIG" ]; then
DNSMASQ_DIR="$(awk -F '=' '/^conf-dir=/ {print $2}' "/tmp/etc/dnsmasq.conf.$DNSMASQ_UCI_CONFIG")"
else
DNSMASQ_DIR="/tmp/dnsmasq.d"
fi
is_enabled() {
local enabled
config_get_bool enabled "$1" "$2" "${3:-0}"
if [ "$enabled" -eq "1" ]; then
return 0
else
return 1
fi
}
append_param() {
procd_append_param command "$1" $2
}
append_param_arg() {
local value
config_get value "$1" "$2" "$4"
[ -n "$value" ] && append_param "$3" "$value"
}
append_param_env() {
local value
config_get value "$1" "$2" $4
[ -n "$value" ] && procd_append_param env "$3"="$value"
}
append_param_boolenv() {
is_enabled "$1" "$2" "$4" && procd_append_param env "$3"="true"
}
append_filter_client() {
local cfg="$1"
is_enabled "$cfg" "enable" || return 1
local mac_addr filter_mode
config_get mac_addr "$cfg" "mac_addr"
config_get filter_mode "$cfg" "filter_mode"
[ -n "$mac_addr" -a -n "$filter_mode" ] || return 1
case "${filter_mode}" in
"disable_http")
if [ -n "$FW4" ]; then
acl_http_addr="${acl_http_addr:+$acl_http_addr\n}${mac_addr}"
else
ipset -! add "acl_neteasemusic_http" "${mac_addr}"
fi
;;
"disable_https")
if [ -n "$FW4" ]; then
acl_https_addr="${acl_https_addr:+$acl_https_addr\n}${mac_addr}"
else
ipset -! add "acl_neteasemusic_https" "${mac_addr}"
fi
;;
"disable_all")
if [ -n "$FW4" ]; then
acl_http_addr="${acl_http_addr:+$acl_http_addr\n}${mac_addr}"
acl_https_addr="${acl_https_addr:+$acl_https_addr\n}${mac_addr}"
else
ipset -! add "acl_neteasemusic_http" "${mac_addr}"
ipset -! add "acl_neteasemusic_https" "${mac_addr}"
fi
;;
esac
}
start_service() {
config_load "$NAME"
is_enabled "config" "enable" || return 1
local update_time
config_get update_time "config" "update_time" "3"
sed -i "/$NAME/d" /etc/crontabs/root
! is_enabled "config" "auto_update" || echo -e "0 ${update_time} * * * $UNM_DIR/update.sh update_core" >> "/etc/crontabs/root"
/etc/init.d/cron restart
mkdir -p "$RUN_DIR"
[ -s "$UNM_DIR/core/app.js" ] || { rm -f "$UNM_DIR/local_ver"; sh "$UNM_DIR/update.sh" "update_core_non_restart"; }
[ -s "$UNM_DIR/core/app.js" ] || { echo "Core Not Found, please download it before starting." >> "$RUN_DIR/run.log"; return 1; }
procd_open_instance "$NAME"
procd_set_param command node "$UNM_DIR/core/app.js"
append_param "-a" "::"
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}"
if [ -n "$FW4" ]; then
json_init
json_add_int http_port "${http_port}"
json_add_int https_port "${https_port}"
json_add_string hijack_ways "${hijack_ways}"
else
if is_enabled "config" "pub_access"; then
iptables -N "$IPT_INPUT_RULE"
iptables -t filter -I INPUT -j "$IPT_INPUT_RULE"
iptables -t filter -A "$IPT_INPUT_RULE" -p tcp --dport "${http_port}" -j ACCEPT
iptables -t filter -A "$IPT_INPUT_RULE" -p tcp --dport "${https_port}" -j ACCEPT
echo "/etc/init.d/$NAME restart" > "$RUN_DIR/fw3.include"
fi
fi
append_param_arg "config" "music_source" "-o" "kugou kuwo migu pyncmd"
append_param_arg "config" "cnrelay" "-c"
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"
local log_level
config_get log_level "config" "log_level" "info"
procd_set_param env LOG_FILE="$RUN_DIR/run.log"
procd_append_param env LOG_LEVEL="$log_level"
append_param_env "config" "joox_cookie" "JOOX_COOKIE"
append_param_env "config" "migu_cookie" "MIGU_COOKIE"
append_param_env "config" "qq_cookie" "QQ_COOKIE"
append_param_env "config" "youtube_key" "YOUTUBE_KEY"
append_param_env "config" "self_issue_cert_crt" "SIGN_CERT" "$UNM_DIR/core/server.crt"
append_param_env "config" "self_issue_cert_key" "SIGN_KEY" "$UNM_DIR/core/server.key"
append_param_env "config" "local_vip" "ENABLE_LOCAL_VIP"
append_param_boolenv "config" "follow_source_order" "FOLLOW_SOURCE_ORDER"
append_param_boolenv "config" "search_album" "SEARCH_ALBUM"
append_param_boolenv "config" "enable_flac" "ENABLE_FLAC"
append_param_boolenv "config" "select_max_br" "SELECT_MAX_BR"
append_param_boolenv "config" "disable_upgrade_check" "DISABLE_UPGRADE_CHECK"
append_param_boolenv "config" "block_ads" "BLOCK_ADS"
case "$(config_get "config" "replace_music_source")" in
"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
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn
local lan_addr="$(uci -q get network.lan.ipaddr)"
if [ "${hijack_ways}" = "use_ipset" ]; then
local settype setname
if [ -n "$FW4" ]; then
settype="nftset"
setname="inet#fw4#neteasemusic,6#inet#fw4#neteasemusic6"
else
settype="ipset"
setname="neteasemusic"
fi
mkdir -p "$DNSMASQ_DIR"
rm -f "$DNSMASQ_DIR/dnsmasq-$NAME.conf"
cat <<-EOF > "$DNSMASQ_DIR/dnsmasq-$NAME.conf"
dhcp-option=252,http://${lan_addr}:${http_port}/proxy.pac
${settype}=/.music.163.com/${setname}
${settype}=/interface.music.163.com/${setname}
${settype}=/interface3.music.163.com/${setname}
${settype}=/apm.music.163.com/${setname}
${settype}=/apm3.music.163.com/${setname}
${settype}=/clientlog.music.163.com/${setname}
${settype}=/clientlog3.music.163.com/${setname}
EOF
/etc/init.d/dnsmasq restart 2>"/dev/null"
if [ -z "$FW4" ]; then
ipset create "acl_neteasemusic_http" hash:mac
ipset create "acl_neteasemusic_https" hash:mac
ipset create "neteasemusic" hash:ip timeout 7200
fi
config_foreach append_filter_client "acl_rule"
local netease_music_ips="$(wget -T10 -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")"
if [ -n "$FW4" ]; then
json_add_string acl_http_addr "$(echo -e "${acl_http_addr}" | sort -u)"
json_add_string acl_https_addr "$(echo -e "${acl_https_addr}" | sort -u)"
json_add_string neteasemusic_addr "$(echo -e "${netease_music_ips}" | jsonfilter -e '@.data.*.ip.*' | sort -u)"
json_add_string neteasemusic_addr6 "$(echo -e "${netease_music_ips}" | jsonfilter -e '@.data.*.ipv6.*' | sort -u)"
json_dump > "$RUN_DIR/fw4.info"
json_cleanup
utpl -F "$RUN_DIR/fw4.info" -S "$UNM_DIR/nftables.ut" > "$RUN_DIR/fw4.nft"
if is_enabled "config" "pub_access"; then
procd_open_data
json_add_array firewall
json_add_object ""
json_add_string type rule
json_add_string name "Allow-access-UNM-http-$http_port"
json_add_string src "*"
json_add_string dest_port "$http_port"
json_add_string proto tcp
json_add_string target ACCEPT
json_close_object
json_add_object ""
json_add_string type rule
json_add_string name "Allow-access-UNM-https-$https_port"
json_add_string src "*"
json_add_string dest_port "$https_port"
json_add_string proto tcp
json_add_string target ACCEPT
json_close_object
json_close_array
procd_close_data
fi
else
echo -e "${netease_music_ips}" | jsonfilter -e '@.data.*.ip.*' | 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"
done
$IPT_N -A "netease_cloud_music" -p "tcp" -m "set" ! --match-set "acl_neteasemusic_http" "src" --dport "80" -j "REDIRECT" --to-ports "${http_port}"
$IPT_N -A "netease_cloud_music" -p "tcp" -m "set" ! --match-set "acl_neteasemusic_https" "src" --dport "443" -j "REDIRECT" --to-ports "${https_port}"
$IPT_N -I "PREROUTING" -p "tcp" -m "set" --match-set "neteasemusic" "dst" -j "netease_cloud_music"
echo "/etc/init.d/$NAME restart" > "$RUN_DIR/fw3.include"
fi
elif [ "${hijack_ways}" = "use_hosts" ]; then
mkdir -p "$DNSMASQ_DIR"
rm -f "$DNSMASQ_DIR/dnsmasq-$NAME.conf"
cat <<-EOF > "$DNSMASQ_DIR/dnsmasq-$NAME.conf"
dhcp-option=252,http://${lan_addr}:${http_port}/proxy.pac
address=/music.163.com/${lan_addr}
address=/interface.music.163.com/${lan_addr}
address=/interface3.music.163.com/${lan_addr}
address=/apm.music.163.com/${lan_addr}
address=/apm3.music.163.com/${lan_addr}
address=/clientlog.music.163.com/${lan_addr}
address=/clientlog3.music.163.com/${lan_addr}
address=/music.httpdns.c.163.com/0.0.0.0
EOF
/etc/init.d/dnsmasq restart 2>"/dev/null"
fi
procd_close_instance
procd_open_instance "log-check"
procd_set_param command "$UNM_DIR/log_check.sh"
procd_set_param respawn
procd_close_instance
}
service_started() {
[ -z "$FW4" ] || procd_set_config_changed firewall
}
stop_service() {
config_load "$NAME"
sed -i "/$NAME/d" "/etc/crontabs/root"
/etc/init.d/cron restart
local chain settable
if [ -n "$FW4" ]; then
for chain in "netease_cloud_music_redir" "netease_cloud_music"; do
nft flush chain inet fw4 "$chain" 2>"/dev/null"
nft delete chain inet fw4 "$chain" 2>"/dev/null"
done
for settable in "acl_neteasemusic_http" "acl_neteasemusic_https" "neteasemusic" "neteasemusic6"; do
nft flush set inet fw4 "$settable" 2>"/dev/null"
nft delete set inet fw4 "$settable" 2>"/dev/null"
done
rm -f "$RUN_DIR/fw4.info"
echo > "$RUN_DIR/fw4.nft"
else
iptables -t filter -D INPUT -j "$IPT_INPUT_RULE" 2>"/dev/null"
iptables -F "$IPT_INPUT_RULE" 2>"/dev/null"
iptables -X "$IPT_INPUT_RULE" 2>"/dev/null"
$IPT_N -D "PREROUTING" -p "tcp" -m set --match-set "neteasemusic" "dst" -j "netease_cloud_music" 2>"/dev/null"
$IPT_N -F "netease_cloud_music" 2>"/dev/null"
$IPT_N -X "netease_cloud_music" 2>"/dev/null"
for settable in "acl_neteasemusic_http" "acl_neteasemusic_https" "neteasemusic"; do
ipset destroy "$settable" 2>"/dev/null"
done
echo > "$RUN_DIR/fw3.include"
fi
rm -f "$DNSMASQ_DIR/dnsmasq-$NAME.conf"
/etc/init.d/dnsmasq restart 2>"/dev/null"
rm -f "$RUN_DIR/run.log"
}
service_stopped() {
[ -z "$FW4" ] || procd_set_config_changed firewall
}
reload_service() {
stop
start
}
service_triggers() {
procd_add_reload_trigger "$NAME"
}

View File

@@ -0,0 +1,34 @@
#!/bin/sh
sed -e "s,local_vip '1',local_vip 'cvip',g" \
-e "/local_vip '0'/d" \
-e "/music_source 'default'/d" \
-i "/etc/config/unblockneteasemusic"
uci -q batch <<-EOF >"/dev/null"
delete ucitrack.@unblockneteasemusic[-1]
commit ucitrack
EOF
if [ -e "$(command -v fw4)" ]; then
uci -q batch <<-EOF >"/dev/null"
delete firewall.unblockneteasemusic
set firewall.unblockneteasemusic=include
set firewall.unblockneteasemusic.type=nftables
set firewall.unblockneteasemusic.path=/var/run/unblockneteasemusic/fw4.nft
set firewall.unblockneteasemusic.position=table-post
commit firewall
EOF
else
uci -q batch <<-EOF >"/dev/null"
delete firewall.unblockneteasemusic
set firewall.unblockneteasemusic=include
set firewall.unblockneteasemusic.type=script
set firewall.unblockneteasemusic.path=/var/run/unblockneteasemusic/fw3.include
set firewall.unblockneteasemusic.reload=1
commit firewall
EOF
fi
rm -f /tmp/luci-indexcache
exit 0

View File

@@ -0,0 +1,17 @@
#!/bin/sh
# Copyright (C) 2021-2022 Tianling Shen <cnsztl@immortalwrt.org>
command -v "curl" >"/dev/null" || { echo -e "curl is not found."; exit 1; }
RUN_DIR="/var/run/unblockneteasemusic"
mkdir -p "$RUN_DIR"
/usr/share/unblockneteasemusic/debugging.sh 2>&1 | tee "$RUN_DIR/unm-debugging-output.txt"
catbox_link="$(curl -fsS -F "reqtype=fileupload" -F "time=72h" -F "fileToUpload=@$RUN_DIR/unm-debugging-output.txt" "https://litterbox.catbox.moe/resources/internals/api.php")"
transfer_link="$(curl -fsS --upload-file "$RUN_DIR/unm-debugging-output.txt" "https://transfer.sh/unm-debugging-output.txt")"
echo -e "\n"
echo -e "Log is available at:"
echo -e "$catbox_link"
echo -e "$transfer_link"
rm -f "$RUN_DIR/unm-debugging-output.txt"

View File

@@ -0,0 +1,29 @@
{
"admin/services/unblockneteasemusic": {
"title": "网易云音乐解锁",
"order": 50,
"action": {
"type": "firstchild"
},
"depends": {
"acl": [ "luci-app-unblockneteasemusic" ],
"uci": { "unblockneteasemusic": true }
}
},
"admin/services/unblockneteasemusic/config": {
"title": "基本设定",
"order": 10,
"action": {
"type": "view",
"path": "unblockneteasemusic/config"
}
},
"admin/services/unblockneteasemusic/status": {
"title": "状态信息",
"order": 20,
"action": {
"type": "view",
"path": "unblockneteasemusic/status"
}
}
}

View File

@@ -0,0 +1,25 @@
{
"luci-app-unblockneteasemusic": {
"description": "Grant access to UnblockNeteaseMusic configuration",
"read": {
"file": {
"/etc/init.d/unblockneteasemusic": [ "exec" ],
"/usr/bin/unm-debug": [ "exec" ],
"/usr/share/unblockneteasemusic/update.sh": [ "exec" ],
"/usr/share/unblockneteasemusic/core/ca.crt": [ "read" ],
"/var/run/unblockneteasemusic/run.log": [ "read" ]
},
"ubus": {
"service": [ "list" ]
},
"uci": [ "unblockneteasemusic" ]
},
"write": {
"file": {
"/usr/share/unblockneteasemusic/server.crt": [ "write" ],
"/usr/share/unblockneteasemusic/server.key": [ "write" ]
},
"uci": [ "unblockneteasemusic" ]
}
}
}

View File

@@ -0,0 +1,117 @@
#!/bin/sh
# 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:"
ubus call system board || cat "/etc/openwrt_release"
echo -e "\n"
echo -e "uclient-fetch info:"
opkg info uclient-fetch
opkg info libustream-*
opkg info wget-ssl
wget -T10 -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."
echo -e "\n"
echo -e "Node.js info:"
opkg info node
echo -e "Node.js is placed at $(command -v node || echo "Not Found")"
echo -e "Node.js version: $(node -v 2>"/dev/null" || echo "Not Found")"
echo -e "\n"
echo -e "luci-app-unblockneteasmusic info:"
opkg info "luci-app-unblockneteasemusic"
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,migu_cookie .*,migu_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/$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 "$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"
echo -e "Port status:"
config_get unm_port "config" "http_port" "5200"
config_get unm_ports "config" "https_port" "5201"
[ "$(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 "PROCD running info:"
running_stat="$(ubus call service list '{"name": "unblockneteasemusic", "verbose": true}' | \
sed -e 's,"JOOX_COOKIE".*","JOOX_COOKIE": "set",g' \
-e 's,"MIGU_COOKIE".*","MIGU_COOKIE": "set",g' \
-e 's,"QQ_COOKIE".*","QQ_COOKIE": "set",g' \
-e 's,"YOUTUBE_KEY".*","YOUTUBE_KEY": "set",g')"
[ "$(echo -e "$running_stat" | jsonfilter -e "@.$NAME.instances.$NAME.running")" == "true" ] || is_stopped=1
echo -e "$running_stat"
echo -e "\n"
[ -n "$is_stopped" ] || {
echo -e "Firewall info:"
if [ -e "$(command -v fw4)" ]; then
[ -e "/var/run/$NAME/fw4.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 ""
nft list set inet fw4 "acl_neteasemusic_https" 2>&1
echo -e ""
nft list set inet fw4 "neteasemusic" 2>&1
echo -e ""
nft list set inet fw4 "neteasemusic6" 2>&1
echo -e ""
nft list chain inet fw4 "netease_cloud_music" 2>&1
echo -e ""
nft list chain inet fw4 "netease_cloud_music_redir" 2>&1
else
iptables -t "nat" -L "netease_cloud_music" 2>"/dev/null" || echo -e 'Chain "netease_cloud_music" not found.'
echo -e ""
ipset list "neteasemusic" 2>"/dev/null" || echo -e 'Table "neteasemusic" not found.'
echo -e ""
ipset list "acl_neteasemusic_http" 2>"/dev/null" || echo -e 'Table "acl_neteasemusic_http" not found.'
echo -e ""
ipset list "acl_neteasemusic_https" 2>"/dev/null" || echo -e 'Table "acl_neteasemusic_https" not found.'
fi
echo -e ""
dnsmasq_uci_config="$(uci -q show "dhcp.@dnsmasq[0]" | awk 'NR==1 {split($0, conf, /[.=]/); print conf[2]}')"
if [ -f "/tmp/etc/dnsmasq.conf.$dnsmasq_uci_config" ]; then
dnsmasq_dir="$(awk -F '=' '/^conf-dir=/ {print $2}' "/tmp/etc/dnsmasq.conf.$dnsmasq_uci_config")"
else
dnsmasq_dir="/tmp/dnsmasq.d"
fi
cat "$dnsmasq_dir/dnsmasq-$NAME.conf"
echo -e "\n"
echo -e "Testing source replacing..."
lan_ip="$(uci -q get "network.lan.ipaddr" || echo "127.0.0.1")"
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"
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 "/var/run/$NAME/run.log" 2>"/dev/null" || echo -e "Log is not avaiable."

View File

@@ -0,0 +1,14 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (C) 2019-2023 Tianling Shen <cnsztl@immortalwrt.org>
NAME="unblockneteasemusic"
log_max_size="10" #使用KB计算
log_file="/var/run/$NAME/run.log"
while true; do
sleep 300
[ -s "$log_file" ] || continue
[ "$(( $(ls -l "$log_file" | awk -F ' ' '{print $5}') / 1024 >= log_max_size))" -eq "0" ] || echo "" > "$log_file"
done

View File

@@ -0,0 +1,68 @@
#!/usr/bin/utpl -S
set acl_neteasemusic_http {
type ether_addr;
flags interval;
auto-merge;
{% if (acl_http_addr): %}
elements = { {{ join(', ', split(trim(acl_http_addr), '\n')) }} }
{% endif %}
}
set acl_neteasemusic_https {
type ether_addr;
flags interval;
auto-merge;
{% if (acl_https_addr): %}
elements = { {{ join(', ', split(trim(acl_https_addr), '\n')) }} }
{% endif %}
}
set neteasemusic {
type ipv4_addr;
flags interval, timeout;
timeout 2h;
auto-merge;
{% if (neteasemusic_addr): %}
elements = { {{ join(', ', split(trim(neteasemusic_addr), '\n')) }} }
{% endif %}
}
set neteasemusic6 {
type ipv6_addr;
flags interval, timeout;
timeout 2h;
auto-merge;
{% if (neteasemusic_addr6): %}
elements = { {{ join(', ', split(trim(neteasemusic_addr6), '\n')) }} }
{% endif %}
}
chain netease_cloud_music {
type nat hook prerouting priority -1; policy accept;
meta l4proto tcp ip daddr @neteasemusic counter jump netease_cloud_music_redir;
meta l4proto tcp ip6 daddr @neteasemusic6 counter jump netease_cloud_music_redir;
}
chain netease_cloud_music_redir {
ip daddr { 0.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 127.0.0.0/8,
169.254.0.0/16, 172.16.0.0/12, 192.0.0.0/24,
192.0.2.0/24, 192.31.196.0/24, 192.52.193.0/24,
192.88.99.0/24, 192.168.0.0/16, 192.175.48.0/24,
198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24,
224.0.0.0/4, 240.0.0.0/4 } counter return;
ip6 daddr { ::/128, ::1/128, ::ffff:0:0/96, 100::/64, 64:ff9b::/96,
2001::/32, 2001:10::/28, 2001:20::/28, 2001:db8::/28, 2002::/16,
fc00::/7, fe80::/10, ff00::/8 } counter return;
ether saddr @acl_neteasemusic_http tcp dport 80 counter return;
ether saddr @acl_neteasemusic_https tcp dport 443 counter return;
tcp dport 80 counter redirect to :{{ http_port }};
tcp dport 443 counter redirect to :{{ https_port }};
}

View File

@@ -0,0 +1,100 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (C) 2019-2023 Tianling Shen <cnsztl@immortalwrt.org>
NAME="unblockneteasemusic"
UNM_DIR="/usr/share/$NAME"
RUN_DIR="/var/run/$NAME"
mkdir -p "$RUN_DIR"
LOCK="$RUN_DIR/update_core.lock"
LOG="$RUN_DIR/run.log"
clean_log(){
echo "" > "$LOG"
}
check_core_latest_version() {
exec 200>"$LOCK"
if ! flock -n 200 &> /dev/null; then
echo -e "\nA task is already running." >> "$LOG"
exit 2
fi
core_latest_ver="$(wget -T10 -qO- 'https://api.github.com/repos/UnblockNeteaseMusic/server/commits?sha=enhanced&path=precompiled' | jsonfilter -e '@[0].sha')"
[ -n "$core_latest_ver" ] || { echo -e "\nFailed to check latest core version, please try again later." >> "$LOG"; exit 1; }
if [ ! -e "$UNM_DIR/core_local_ver" ]; then
clean_log
echo -e "Local version: NOT FOUND, latest version: $core_latest_ver." >> "$LOG"
update_core
else
if [ "$(cat $UNM_DIR/core_local_ver)" != "$core_latest_ver" ]; then
clean_log
echo -e "Local version: $(cat $UNM_DIR/core_local_ver 2>"/dev/null"), latest version: $core_latest_ver." >> "$LOG"
update_core
else
echo -e "\nLocal version: $(cat $UNM_DIR/core_local_ver 2>"/dev/null"), latest version: $core_latest_ver." >> "$LOG"
echo -e "You're already using the latest version." >> "$LOG"
exit 3
fi
fi
}
update_core() {
echo -e "Updating core..." >> "$LOG"
mkdir -p "$UNM_DIR/core"
rm -rf "$UNM_DIR/core"/*
for file in $(wget -T10 -qO- "https://api.github.com/repos/UnblockNeteaseMusic/server/contents/precompiled" | jsonfilter -e '@[*].path')
do
wget -T10 "https://fastly.jsdelivr.net/gh/UnblockNeteaseMusic/server@$core_latest_ver/$file" -qO "$UNM_DIR/core/${file##*/}"
[ -s "$UNM_DIR/core/${file##*/}" ] || {
echo -e "Failed to download ${file##*/}." >> "$LOG"
exit 1
}
done
for cert in "ca.crt" "server.crt" "server.key"
do
wget -T10 "https://fastly.jsdelivr.net/gh/UnblockNeteaseMusic/server@$core_latest_ver/$cert" -qO "$UNM_DIR/core/$cert"
[ -s "$UNM_DIR/core/${cert}" ] || {
echo -e "Failed to download ${cert}." >> "$LOG"
exit 1
}
done
echo -e "$core_latest_ver" > "$UNM_DIR/core_local_ver"
[ -n "$non_restart" ] || /etc/init.d/"$NAME" restart
echo -e "Succeeded in updating core." > "$LOG"
echo -e "Current core version: $core_latest_ver.\n" >> "$LOG"
}
case "$1" in
"check_version")
if [ ! -e "$UNM_DIR/core_local_ver" ] || [ ! -e "$UNM_DIR/core/app.js" ]; then
echo -e "Not installed."
exit 2
else
version="$(node "$UNM_DIR/core/app.js" -v)"
commit="$(cat "$UNM_DIR/core_local_ver" | head -c7)"
echo "$version ($commit)"
exit 0
fi
;;
"update_core")
check_core_latest_version
;;
"update_core_non_restart")
non_restart=1
check_core_latest_version
;;
"remove_core")
"/etc/init.d/$NAME" stop
rm -rf "$UNM_DIR/core" "$UNM_DIR/core_local_ver" "$LOCK"
;;
*)
echo -e "Usage: $0 check_version | update_core | remove_core"
;;
esac