|
@@ -9,13 +9,11 @@ START=99
|
|
|
STOP=10
|
|
|
|
|
|
NAME="unblockneteasemusic"
|
|
|
-UPGRADE_CONF="/lib/upgrade/keep.d/$NAME"
|
|
|
+UNM_DIR="/usr/share/$NAME"
|
|
|
+RUN_DIR="/var/run/$NAME"
|
|
|
|
|
|
IPT_N="iptables -t nat"
|
|
|
-
|
|
|
-FW4="$(command -v fw4)"
|
|
|
-RULES_UC="/usr/share/$NAME/rules/default.uc"
|
|
|
-RULES_NFT="/etc/nftables.d/90-$NAME-rules.nft"
|
|
|
+IPT_INPUT_RULE="unblockneteasemusic_input_rule"
|
|
|
|
|
|
is_enabled() {
|
|
|
local enabled
|
|
@@ -50,6 +48,8 @@ append_param_boolenv() {
|
|
|
append_filter_client() {
|
|
|
local cfg="$1"
|
|
|
|
|
|
+ is_enabled "$cfg" "enable" || return 1
|
|
|
+
|
|
|
local ip_addr filter_mode
|
|
|
config_get ip_addr "$cfg" "ip_addr"
|
|
|
config_get filter_mode "$cfg" "filter_mode"
|
|
@@ -57,27 +57,14 @@ append_filter_client() {
|
|
|
|
|
|
case "${filter_mode}" in
|
|
|
"disable_http")
|
|
|
- if [ -n "$FW4" ]; then
|
|
|
- acl_http_addr="${acl_http_addr:+$acl_http_addr\n}${ip_addr}"
|
|
|
- else
|
|
|
- ipset -! add "acl_neteasemusic_http" "${ip_addr}"
|
|
|
- fi
|
|
|
+ ipset -! add "acl_neteasemusic_http" "${ip_addr}"
|
|
|
;;
|
|
|
"disable_https")
|
|
|
- if [ -n "$FW4" ]; then
|
|
|
- acl_https_addr="${acl_https_addr:+$acl_https_addr\n}${ip_addr}"
|
|
|
- else
|
|
|
- ipset -! add "acl_neteasemusic_https" "${ip_addr}"
|
|
|
- fi
|
|
|
+ ipset -! add "acl_neteasemusic_https" "${ip_addr}"
|
|
|
;;
|
|
|
"disable_all")
|
|
|
- if [ -n "$FW4" ]; then
|
|
|
- acl_http_addr="${acl_http_addr:+$acl_http_addr\n}${ip_addr}"
|
|
|
- acl_https_addr="${acl_https_addr:+$acl_https_addr\n}${ip_addr}"
|
|
|
- else
|
|
|
- ipset -! add "acl_neteasemusic_http" "${ip_addr}"
|
|
|
- ipset -! add "acl_neteasemusic_https" "${ip_addr}"
|
|
|
- fi
|
|
|
+ ipset -! add "acl_neteasemusic_http" "${ip_addr}"
|
|
|
+ ipset -! add "acl_neteasemusic_https" "${ip_addr}"
|
|
|
;;
|
|
|
esac
|
|
|
}
|
|
@@ -89,43 +76,31 @@ start_service() {
|
|
|
local update_time
|
|
|
config_get update_time "config" "update_time" "3"
|
|
|
sed -i "/$NAME/d" /etc/crontabs/root
|
|
|
- is_enabled "config" "auto_update" && echo "0 ${update_time} * * * /usr/share/$NAME/update.sh update_core" >> "/etc/crontabs/root"
|
|
|
- echo "*/5 * * * * /usr/share/$NAME/log_check.sh" >> "/etc/crontabs/root"
|
|
|
+ is_enabled "config" "auto_update" && echo "0 ${update_time} * * * $UNM_DIR/update.sh update_core" >> "/etc/crontabs/root"
|
|
|
/etc/init.d/cron restart
|
|
|
|
|
|
- [ ! -s "/usr/share/$NAME/core/app.js" ] && { rm -f "/usr/share/$NAME/local_ver"; sh "/usr/share/$NAME/update.sh" "update_core_non_restart"; }
|
|
|
- [ ! -s "/usr/share/$NAME/core/app.js" ] && { echo "Core Not Found, please download it before starting." >> "/tmp/$NAME.log"; exit 1; }
|
|
|
+ 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 "/usr/share/$NAME/core/app.js"
|
|
|
+ procd_set_param command node "$UNM_DIR/core/app.js"
|
|
|
append_param "-a" "0.0.0.0"
|
|
|
|
|
|
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"; }
|
|
|
+ [ "$hijack_ways" != "use_hosts" ] || { http_port="80"; https_port="443"; }
|
|
|
append_param "-p" "${http_port}":"${https_port}"
|
|
|
|
|
|
- if [ -n "$FW4" ]; then
|
|
|
- json_init
|
|
|
- if is_enabled "config" "pub_access"; then
|
|
|
- json_add_int o_pub_access "1"
|
|
|
- else
|
|
|
- json_add_int o_pub_access "0"
|
|
|
- fi
|
|
|
- json_add_int o_http_port "${http_port}"
|
|
|
- json_add_int o_https_port "${https_port}"
|
|
|
- json_add_string o_hijack_ways "${hijack_ways}"
|
|
|
- else
|
|
|
- if is_enabled "config" "pub_access"; then
|
|
|
- iptables -I "INPUT" -p "tcp" --dport "${http_port}" -j "ACCEPT"
|
|
|
- iptables -I "INPUT" -p "tcp" --dport "${https_port}" -j "ACCEPT"
|
|
|
- echo "${http_port}:${https_port}" > "/tmp/$NAME.ports"
|
|
|
-
|
|
|
- mkdir -p "/var/etc/"
|
|
|
- echo "/etc/init.d/$NAME restart" > "/var/etc/$NAME.include"
|
|
|
- fi
|
|
|
+ if is_enabled "config" "pub_access"; then
|
|
|
+ iptables -N "$IPT_RULE_NAME"
|
|
|
+ iptables -t filter -I INPUT -j "$IPT_RULE_NAME"
|
|
|
+ iptables -t filter -A "$IPT_RULE_NAME" -p tcp --dport "${http_port}" -j ACCEPT
|
|
|
+ iptables -t filter -A "$IPT_RULE_NAME" -p tcp --dport "${https_port}" -j ACCEPT
|
|
|
+
|
|
|
+ echo "/etc/init.d/$NAME restart" > "$RUN_DIR/fw3.include"
|
|
|
fi
|
|
|
|
|
|
local music_source
|
|
@@ -140,21 +115,23 @@ start_service() {
|
|
|
|
|
|
local log_level
|
|
|
config_get log_level "config" "log_level" "info"
|
|
|
- procd_set_param env LOG_FILE="/tmp/$NAME.log"
|
|
|
+ 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" "/usr/share/$NAME/core/server.crt"
|
|
|
- append_param_env "config" "self_issue_cert_key" "SIGN_KEY" "/usr/share/$NAME/core/server.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_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" "local_vip" "ENABLE_LOCAL_VIP"
|
|
|
+ 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"
|
|
|
+ append_param_boolenv "config" "local_vip" "ENABLE_LOCAL_VIP"
|
|
|
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" ;;
|
|
@@ -168,57 +145,39 @@ start_service() {
|
|
|
|
|
|
local lan_addr="$(uci -q get network.lan.ipaddr)"
|
|
|
if [ "${hijack_ways}" = "use_ipset" ]; then
|
|
|
- local settype nftflag
|
|
|
- if [ -n "$FW4" ]; then
|
|
|
- settype="nftset"
|
|
|
- nftflag="inet#fw4#"
|
|
|
- else
|
|
|
- settype="ipset"
|
|
|
- fi
|
|
|
mkdir -p "/tmp/dnsmasq.d"
|
|
|
rm -f "/tmp/dnsmasq.d/dnsmasq-$NAME.conf"
|
|
|
cat <<-EOF > "/tmp/dnsmasq.d/dnsmasq-$NAME.conf"
|
|
|
dhcp-option=252,http://${lan_addr}:${http_port}/proxy.pac
|
|
|
- ${settype}=/.music.163.com/${nftflag}neteasemusic
|
|
|
- ${settype}=/interface.music.163.com/${nftflag}neteasemusic
|
|
|
- ${settype}=/interface3.music.163.com/${nftflag}neteasemusic
|
|
|
- ${settype}=/apm.music.163.com/${nftflag}neteasemusic
|
|
|
- ${settype}=/apm3.music.163.com/${nftflag}neteasemusic
|
|
|
- ${settype}=/clientlog.music.163.com/${nftflag}neteasemusic
|
|
|
- ${settype}=/clientlog3.music.163.com/${nftflag}neteasemusic
|
|
|
+ ipset=/.music.163.com/neteasemusic
|
|
|
+ ipset=/interface.music.163.com/neteasemusic
|
|
|
+ ipset=/interface3.music.163.com/neteasemusic
|
|
|
+ ipset=/apm.music.163.com/neteasemusic
|
|
|
+ ipset=/apm3.music.163.com/neteasemusic
|
|
|
+ ipset=/clientlog.music.163.com/neteasemusic
|
|
|
+ ipset=/clientlog3.music.163.com/neteasemusic
|
|
|
EOF
|
|
|
- /etc/init.d/dnsmasq reload
|
|
|
+ /etc/init.d/dnsmasq reload 2>"/dev/null"
|
|
|
|
|
|
- [ -n "$FW4" ] || {
|
|
|
- ipset create "acl_neteasemusic_http" hash:ip
|
|
|
- ipset create "acl_neteasemusic_https" hash:ip
|
|
|
- ipset create "neteasemusic" hash:ip
|
|
|
- }
|
|
|
+ ipset create "acl_neteasemusic_http" hash:ip
|
|
|
+ ipset create "acl_neteasemusic_https" hash:ip
|
|
|
+ ipset create "neteasemusic" hash:ip
|
|
|
config_foreach append_filter_client "acl_rule"
|
|
|
|
|
|
local netease_music_ips="$(uclient-fetch -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" |jsonfilter -e '@.data.*.ip.*')"
|
|
|
local netease_music_ips2="$(uclient-fetch -qO- "https://music.httpdns.c.163.com/d" --post-data="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" |jsonfilter -e '@.dns.*["ips"].*')"
|
|
|
- if [ -n "$FW4" ]; then
|
|
|
- local neteasemusic_addr="$(echo -e "${netease_music_ips}\n${netease_music_ips2}" | sort -u | awk '{print $1}')"
|
|
|
-
|
|
|
- json_add_string o_acl_http_addr "$(echo -e "${acl_http_addr}" | sort -u | awk '{print $1}')"
|
|
|
- json_add_string o_acl_https_addr "$(echo -e "${acl_https_addr}" | sort -u | awk '{print $1}')"
|
|
|
- json_add_string o_neteasemusic_addr "$neteasemusic_addr"
|
|
|
- else
|
|
|
- echo -e "${netease_music_ips}\n${netease_music_ips2}" | 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"
|
|
|
-
|
|
|
- mkdir -p "/var/etc/"
|
|
|
- echo "/etc/init.d/$NAME restart" > "/var/etc/$NAME.include"
|
|
|
- fi
|
|
|
+ echo -e "${netease_music_ips}\n${netease_music_ips2}" | 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"
|
|
|
elif [ "${hijack_ways}" = "use_hosts" ]; then
|
|
|
mkdir -p "/tmp/dnsmasq.d"
|
|
|
rm -f "/tmp/dnsmasq.d/dnsmasq-$NAME.conf"
|
|
@@ -233,21 +192,16 @@ start_service() {
|
|
|
address=/clientlog3.music.163.com/${lan_addr}
|
|
|
address=/music.httpdns.c.163.com/0.0.0.0
|
|
|
EOF
|
|
|
- /etc/init.d/dnsmasq reload
|
|
|
+ /etc/init.d/dnsmasq reload 2>"/dev/null"
|
|
|
|
|
|
ip route add "223.252.199.10" dev lo
|
|
|
fi
|
|
|
|
|
|
- if [ -n "$FW4" ]; then
|
|
|
- local nft_tmp="/tmp/$NAME"
|
|
|
- json_dump -i > "$nft_tmp.json"
|
|
|
- if utpl -F "$nft_tmp.json" -S "$RULES_UC" > "$nft_tmp.nft" && ! cmp -s "$nft_tmp.nft" "$RULES_NFT"; then
|
|
|
- echo "table inet chk {include \"$nft_tmp.nft\";}" > "$nft_tmp.nft.chk"
|
|
|
- ! nft -f "$nft_tmp.nft.chk" -c || { mv -f "$nft_tmp.nft" "$RULES_NFT"; fw4 reload; }
|
|
|
- fi
|
|
|
- rm -f "$nft_tmp.json" "$nft_tmp.nft" "$nft_tmp.nft.chk"
|
|
|
- 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
|
|
|
}
|
|
|
|
|
@@ -257,54 +211,27 @@ stop_service() {
|
|
|
sed -i "/$NAME/d" "/etc/crontabs/root"
|
|
|
/etc/init.d/cron restart
|
|
|
|
|
|
- rm -f "${UPGRADE_CONF}"
|
|
|
- is_enabled "config" "keep_core_when_upgrade" && {
|
|
|
- echo "/usr/share/$NAME/core/" >> "${UPGRADE_CONF}"
|
|
|
- echo "/usr/share/$NAME/local_ver" >> "${UPGRADE_CONF}"
|
|
|
- }
|
|
|
-
|
|
|
- local self_issue_cert_crt self_issue_cert_key
|
|
|
- config_get "self_issue_cert_crt" "config" "self_issue_cert_crt"
|
|
|
- config_get "self_issue_cert_key" "config" "self_issue_cert_key"
|
|
|
- { [ -f "${self_issue_cert_crt}" ] && [ -f "${self_issue_cert_key}" ]; } && {
|
|
|
- echo "${self_issue_cert_crt}" >> "${UPGRADE_CONF}"
|
|
|
- echo "${self_issue_cert_key}" >> "${UPGRADE_CONF}"
|
|
|
- }
|
|
|
-
|
|
|
- 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"
|
|
|
- done
|
|
|
- for settable in "acl_neteasemusic_http" "acl_neteasemusic_https" "local_addr" "neteasemusic"; do
|
|
|
- nft flush set inet fw4 "$settable" 2>"/dev/null"
|
|
|
- done
|
|
|
+ local settable
|
|
|
+ iptables -t filter -D INPUT -j "$IPT_RULE_NAME" 2>"/dev/null"
|
|
|
+ iptables -F "$IPT_RULE_NAME" 2>"/dev/null"
|
|
|
+ iptables -X "$IPT_RULE_NAME" 2>"/dev/null"
|
|
|
|
|
|
- rm -f "$RULES_NFT"
|
|
|
- fw4 reload
|
|
|
- else
|
|
|
- [ ! -e "/tmp/$NAME.ports" ] || {
|
|
|
- iptables -D "INPUT" -p "tcp" --dport "$(awk -F ':' '{print $1}' "/tmp/$NAME.ports")" -j "ACCEPT"
|
|
|
- iptables -D "INPUT" -p "tcp" --dport "$(awk -F ':' '{print $2}' "/tmp/$NAME.ports")" -j "ACCEPT"
|
|
|
- rm -f "/tmp/$NAME.ports"
|
|
|
- }
|
|
|
- $IPT_N -D "PREROUTING" -p "tcp" -m set --match-set "neteasemusic" "dst" -j "netease_cloud_music"
|
|
|
- $IPT_N -F "netease_cloud_music"
|
|
|
- $IPT_N -X "netease_cloud_music"
|
|
|
-
|
|
|
- for settable in "acl_neteasemusic_http" "acl_neteasemusic_https" "local_addr" "neteasemusic"; do
|
|
|
- ipset destroy "$settable" 2>"/dev/null"
|
|
|
- done
|
|
|
+ $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"
|
|
|
|
|
|
- echo "" > "/var/etc/$NAME.include"
|
|
|
- fi
|
|
|
+ for settable in "acl_neteasemusic_http" "acl_neteasemusic_https" "neteasemusic"; do
|
|
|
+ ipset destroy "$settable" 2>"/dev/null"
|
|
|
+ done
|
|
|
+
|
|
|
+ echo > "$RUN_DIR/fw3.include"
|
|
|
|
|
|
rm -f "/tmp/dnsmasq.d/dnsmasq-$NAME.conf"
|
|
|
- /etc/init.d/dnsmasq reload
|
|
|
+ /etc/init.d/dnsmasq reload 2>"/dev/null"
|
|
|
|
|
|
ip route del "223.252.199.10" 2>"/dev/null"
|
|
|
|
|
|
- rm -f "/tmp/$NAME.log"
|
|
|
+ rm -f "$RUN_DIR/run.log"
|
|
|
}
|
|
|
|
|
|
reload_service() {
|