feat: 任意门解锁、nginx管理

完善任意门解锁,nginx管理修改为systemctl
pull/534/merge
mack-a 2021-12-16 16:55:28 +08:00
parent 659882b964
commit a323ded532
1 changed files with 125 additions and 125 deletions

View File

@ -793,9 +793,9 @@ EOF
# 修改nginx重定向配置 # 修改nginx重定向配置
updateRedirectNginxConf() { updateRedirectNginxConf() {
if [[ ${BTPanelStatus} = "true" ]];then if [[ ${BTPanelStatus} = "true" ]]; then
cat <<EOF >${nginxConfigPath}alone.conf cat <<EOF >${nginxConfigPath}alone.conf
server { server {
listen 127.0.0.1:31300; listen 127.0.0.1:31300;
server_name _; server_name _;
@ -804,7 +804,7 @@ cat <<EOF >${nginxConfigPath}alone.conf
EOF EOF
else else
cat <<EOF >${nginxConfigPath}alone.conf cat <<EOF >${nginxConfigPath}alone.conf
server { server {
listen 80; listen 80;
listen [::]:80; listen [::]:80;
@ -1096,7 +1096,7 @@ nginxBlog() {
handleNginx() { handleNginx() {
if [[ -z $(pgrep -f "nginx") ]] && [[ "$1" == "start" ]]; then if [[ -z $(pgrep -f "nginx") ]] && [[ "$1" == "start" ]]; then
nginx systemctl start nginx
sleep 0.5 sleep 0.5
if [[ -z $(pgrep -f nginx) ]]; then if [[ -z $(pgrep -f nginx) ]]; then
@ -1105,7 +1105,7 @@ handleNginx() {
exit 0 exit 0
fi fi
elif [[ -n $(pgrep -f "nginx") ]] && [[ "$1" == "stop" ]]; then elif [[ -n $(pgrep -f "nginx") ]] && [[ "$1" == "stop" ]]; then
nginx -s stop >/dev/null 2>&1 systemctl stop nginx
sleep 0.5 sleep 0.5
if [[ -n $(pgrep -f "nginx") ]]; then if [[ -n $(pgrep -f "nginx") ]]; then
pgrep -f "nginx" | xargs kill -9 pgrep -f "nginx" | xargs kill -9
@ -1131,7 +1131,7 @@ renewalTLS() {
echoContent skyBlue "\n进度 $1/1 : 更新证书" echoContent skyBlue "\n进度 $1/1 : 更新证书"
fi fi
local domain=${currentHost} local domain=${currentHost}
if [[ -z "${currentHost}" && -n "${tlsDomain}" ]];then if [[ -z "${currentHost}" && -n "${tlsDomain}" ]]; then
domain=${tlsDomain} domain=${tlsDomain}
fi fi
@ -3458,7 +3458,7 @@ EOF
unInstallSniffing unInstallSniffing
unInstallRouting blackhole-out unInstallRouting blackhole-out outboundTag
unInstallOutbounds blackhole-out unInstallOutbounds blackhole-out
@ -3474,16 +3474,26 @@ EOF
# 根据tag卸载Routing # 根据tag卸载Routing
unInstallRouting() { unInstallRouting() {
local tag=$1 local tag=$1
local type=$2
if [[ -f "${configPath}09_routing.json" ]]; then if [[ -f "${configPath}09_routing.json" ]]; then
local routing local routing
if grep -q "${tag}" ${configPath}09_routing.json; then if grep -q "${tag}" ${configPath}09_routing.json && grep -q "${type}" ${configPath}09_routing.json; then
local index
index=$(jq .routing.rules[].outboundTag ${configPath}09_routing.json | awk '{print ""NR""":"$0}' | grep "${tag}" | awk -F "[:]" '{print $1}' | head -1) jq -c .routing.rules[] ${configPath}09_routing.json | while read -r line; do
if [[ ${index} -gt 0 ]]; then local index=$((index + 1))
routing=$(jq -r 'del(.routing.rules['"$(("${index}" - 1))"'])' ${configPath}09_routing.json) local delStatus=0
echo "${routing}" | jq . >${configPath}09_routing.json if [[ "${type}" == "outboundTag" ]] && echo "${line}" | jq .outboundTag | grep -q "${tag}"; then
fi delStatus=1
elif [[ "${type}" == "inboundTag" ]] && echo "${line}" | jq .inboundTag | grep -q "${tag}"; then
delStatus=1
fi
if [[ ${delStatus} == 1 ]]; then
routing=$(jq -r 'del(.routing.rules['"$(("${index}" - 1))"'])' ${configPath}09_routing.json)
echo "${routing}" | jq . >${configPath}09_routing.json
fi
done
fi fi
fi fi
} }
@ -3560,7 +3570,7 @@ warpRouting() {
read -r -p "请按照上面示例录入域名:" domainList read -r -p "请按照上面示例录入域名:" domainList
if [[ -f "${configPath}09_routing.json" ]]; then if [[ -f "${configPath}09_routing.json" ]]; then
unInstallRouting warp-socks-out unInstallRouting warp-socks-out outboundTag
routing=$(jq -r ".routing.rules += [{\"type\":\"field\",\"domain\":[\"geosite:${domainList//,/\",\"geosite:}\"],\"outboundTag\":\"warp-socks-out\"}]" ${configPath}09_routing.json) routing=$(jq -r ".routing.rules += [{\"type\":\"field\",\"domain\":[\"geosite:${domainList//,/\",\"geosite:}\"],\"outboundTag\":\"warp-socks-out\"}]" ${configPath}09_routing.json)
@ -3597,7 +3607,7 @@ EOF
${removeType} cloudflare-warp >/dev/null 2>&1 ${removeType} cloudflare-warp >/dev/null 2>&1
unInstallRouting warp-socks-out unInstallRouting warp-socks-out outboundTag
unInstallOutbounds warp-socks-out unInstallOutbounds warp-socks-out
@ -3613,16 +3623,13 @@ streamingToolbox() {
echoContent skyBlue "\n功能 1/${totalProgress} : 流媒体工具箱" echoContent skyBlue "\n功能 1/${totalProgress} : 流媒体工具箱"
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
# echoContent yellow "1.Netflix检测" # echoContent yellow "1.Netflix检测"
echoContent yellow "1.任意门落地机解锁Netflix" echoContent yellow "1.任意门落地机解锁流媒体"
echoContent yellow "2.DNS解锁流媒体" echoContent yellow "2.DNS解锁流媒体"
read -r -p "请选择:" selectType read -r -p "请选择:" selectType
case ${selectType} in case ${selectType} in
# 1)
# checkNetflix
# ;;
1) 1)
dokodemoDoorUnblockNetflix dokodemoDoorUnblockStreamingMedia
;; ;;
2) 2)
dnsUnlockNetflix dnsUnlockNetflix
@ -3631,9 +3638,9 @@ streamingToolbox() {
} }
# 任意门解锁netflix # 任意门解锁流媒体
dokodemoDoorUnblockNetflix() { dokodemoDoorUnblockStreamingMedia() {
echoContent skyBlue "\n功能 1/${totalProgress} : 任意门落地机解锁Netflix" echoContent skyBlue "\n功能 1/${totalProgress} : 任意门落地机解锁流媒体"
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent yellow "# 注意事项" echoContent yellow "# 注意事项"
echoContent yellow "任意门解锁详解,请查看此文章[https://github.com/mack-a/v2ray-agent/blob/master/documents/netflix/dokodemo-unblock_netflix.md]\n" echoContent yellow "任意门解锁详解,请查看此文章[https://github.com/mack-a/v2ray-agent/blob/master/documents/netflix/dokodemo-unblock_netflix.md]\n"
@ -3645,35 +3652,47 @@ dokodemoDoorUnblockNetflix() {
case ${selectType} in case ${selectType} in
1) 1)
setDokodemoDoorUnblockNetflixOutbounds setDokodemoDoorUnblockStreamingMediaOutbounds
;; ;;
2) 2)
setDokodemoDoorUnblockNetflixInbounds setDokodemoDoorUnblockStreamingMediaInbounds
;; ;;
3) 3)
removeDokodemoDoorUnblockNetflix removeDokodemoDoorUnblockStreamingMedia
;; ;;
esac esac
} }
# 设置任意门解锁Netflix【出站】 # 设置任意门解锁Netflix【出站】
setDokodemoDoorUnblockNetflixOutbounds() { setDokodemoDoorUnblockStreamingMediaOutbounds() {
read -r -p "请输入解锁Netflix vps的IP:" setIP read -r -p "请输入解锁流媒体 vps的IP:" setIP
echoContent red "=============================================================="
echoContent yellow "# 注意事项\n"
echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "3.如内核启动失败请检查域名后重新添加域名"
echoContent yellow "4.不允许有特殊字符,注意逗号的格式"
echoContent yellow "5.每次添加都是重新添加,不会保留上次域名"
echoContent yellow "6.录入示例:netflix,disney,hulu\n"
read -r -p "请按照上面示例录入域名:" domainList
if [[ -n "${setIP}" ]]; then if [[ -n "${setIP}" ]]; then
unInstallOutbounds netflix-80 unInstallOutbounds streamingMedia-80
unInstallOutbounds netflix-443 unInstallOutbounds streamingMedia-443
outbounds=$(jq -r ".outbounds += [{\"tag\":\"netflix-80\",\"protocol\":\"freedom\",\"settings\":{\"domainStrategy\":\"AsIs\",\"redirect\":\"${setIP}:22387\"}},{\"tag\":\"netflix-443\",\"protocol\":\"freedom\",\"settings\":{\"domainStrategy\":\"AsIs\",\"redirect\":\"${setIP}:22388\"}}]" ${configPath}10_ipv4_outbounds.json) outbounds=$(jq -r ".outbounds += [{\"tag\":\"streamingMedia-80\",\"protocol\":\"freedom\",\"settings\":{\"domainStrategy\":\"AsIs\",\"redirect\":\"${setIP}:22387\"}},{\"tag\":\"streamingMedia-443\",\"protocol\":\"freedom\",\"settings\":{\"domainStrategy\":\"AsIs\",\"redirect\":\"${setIP}:22388\"}}]" ${configPath}10_ipv4_outbounds.json)
echo "${outbounds}" | jq . >${configPath}10_ipv4_outbounds.json echo "${outbounds}" | jq . >${configPath}10_ipv4_outbounds.json
if [[ -f "${configPath}09_routing.json" ]]; then if [[ -f "${configPath}09_routing.json" ]]; then
unInstallRouting netflix-80 unInstallRouting streamingMedia-80 outboundTag
unInstallRouting netflix-443 unInstallRouting streamingMedia-443 outboundTag
local routing local routing
routing=$(jq -r '.routing.rules += [{"type":"field","port":80,"domain":["ip.sb","geosite:netflix"],"outboundTag":"netflix-80"},{"type":"field","port":443,"domain":["ip.sb","geosite:netflix"],"outboundTag":"netflix-443"}]' ${configPath}09_routing.json)
routing=$(jq -r ".routing.rules += [{\"type\":\"field\",\"port\":80,\"domain\":[\"ip.sb\",\"geosite:${domainList//,/\",\"geosite:}\"],\"outboundTag\":\"streamingMedia-80\"},{\"type\":\"field\",\"port\":443,\"domain\":[\"ip.sb\",\"geosite:${domainList//,/\",\"geosite:}\"],\"outboundTag\":\"streamingMedia-443\"}]" ${configPath}09_routing.json)
echo "${routing}" | jq . >${configPath}09_routing.json echo "${routing}" | jq . >${configPath}09_routing.json
else else
cat <<EOF >${configPath}09_routing.json cat <<EOF >${configPath}09_routing.json
@ -3686,18 +3705,18 @@ setDokodemoDoorUnblockNetflixOutbounds() {
"port": 80, "port": 80,
"domain": [ "domain": [
"ip.sb", "ip.sb",
"geosite:netflix" "geosite:${domainList//,/\",\"geosite:}"
], ],
"outboundTag": "netflix-80" "outboundTag": "streamingMedia-80"
}, },
{ {
"type": "field", "type": "field",
"port": 443, "port": 443,
"domain": [ "domain": [
"ip.sb", "ip.sb",
"geosite:netflix" "geosite:${domainList//,/\",\"geosite:}"
], ],
"outboundTag": "netflix-443" "outboundTag": "streamingMedia-443"
} }
] ]
} }
@ -3705,24 +3724,30 @@ setDokodemoDoorUnblockNetflixOutbounds() {
EOF EOF
fi fi
reloadCore reloadCore
echoContent green " ---> 添加Netflix出站解锁成功" echoContent green " ---> 添加出站解锁成功"
# echoContent yellow " ---> 不支持trojan的相关节点"
exit 0 exit 0
fi fi
echoContent red " ---> ip不可为空" echoContent red " ---> ip不可为空"
} }
# 设置任意门解锁Netflix【入站】 # 设置任意门解锁Netflix【入站】
setDokodemoDoorUnblockNetflixInbounds() { setDokodemoDoorUnblockStreamingMediaInbounds() {
echoContent skyBlue "\n功能 1/${totalProgress} : 任意门添加入站" echoContent skyBlue "\n功能 1/${totalProgress} : 任意门添加入站"
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent yellow "# 注意事项\n" echoContent yellow "# 注意事项\n"
echoContent yellow "支持批量添加" echoContent yellow "1.规则仅支持预定义域名列表[https://github.com/v2fly/domain-list-community]"
echoContent yellow "不允许有特殊字符,注意逗号的格式" echoContent yellow "2.详细文档[https://www.v2fly.org/config/routing.html]"
echoContent yellow "录入示例:1.1.1.1,1.1.1.2\n" echoContent yellow "3.如内核启动失败请检查域名后重新添加域名"
read -r -p "请输入允许访问该解锁Netflix vps的IP:" setIPs echoContent yellow "4.不允许有特殊字符,注意逗号的格式"
echoContent yellow "5.每次添加都是重新添加,不会保留上次域名"
echoContent yellow "6.ip录入示例:1.1.1.1,1.1.1.2"
echoContent yellow "7.下面的域名一定要和出站的vps一致"
echoContent yellow "8.域名录入示例:netflix,disney,hulu\n"
read -r -p "请输入允许访问该解锁 vps的IP:" setIPs
if [[ -n "${setIPs}" ]]; then if [[ -n "${setIPs}" ]]; then
read -r -p "请按照上面示例录入域名:" domainList
cat <<EOF >${configPath}01_netflix_inbounds.json cat <<EOF >${configPath}01_netflix_inbounds.json
{ {
"inbounds": [ "inbounds": [
@ -3742,7 +3767,7 @@ setDokodemoDoorUnblockNetflixInbounds() {
"http" "http"
] ]
}, },
"tag": "unblock-80" "tag": "streamingMedia-80"
}, },
{ {
"listen": "0.0.0.0", "listen": "0.0.0.0",
@ -3760,7 +3785,7 @@ setDokodemoDoorUnblockNetflixInbounds() {
"tls" "tls"
] ]
}, },
"tag": "unblock-443" "tag": "streamingMedia-443"
} }
] ]
} }
@ -3791,62 +3816,66 @@ EOF
} }
EOF EOF
cat <<EOF >${configPath}09_routing.json if [[ -f "${configPath}09_routing.json" ]]; then
{ unInstallRouting streamingMedia-80 inboundTag
"routing": { unInstallRouting streamingMedia-443 inboundTag
"rules": [
{ local routing
"source": [], routing=$(jq -r ".routing.rules += [{\"source\":[\"${setIPs//,/\",\"}\"],\"type\":\"field\",\"inboundTag\":[\"streamingMedia-80\",\"streamingMedia-443\"],\"outboundTag\":\"direct\"},{\"domains\":[\"geosite:${domainList//,/\",\"geosite:}\"],\"type\":\"field\",\"inboundTag\":[\"streamingMedia-80\",\"streamingMedia-443\"],\"outboundTag\":\"blackhole-out\"}]" ${configPath}09_routing.json)
"type": "field", echo "${routing}" | jq . >${configPath}09_routing.json
"inboundTag": [ else
"unblock-80", cat <<EOF >${configPath}09_routing.json
"unblock-443" {
], "routing": {
"outboundTag": "direct" "rules": [
}, {
{ "source": [
"domains": [ "${setIPs//,/\",\"}"
"geosite:netflix" ],
], "type": "field",
"type": "field", "inboundTag": [
"inboundTag": [ "streamingMedia-80",
"unblock-80", "streamingMedia-443"
"unblock-443" ],
], "outboundTag": "direct"
"outboundTag": "blackhole-out" },
} {
] "domains": [
} "geosite:${domainList//,/\",\"geosite:}"
} ],
"type": "field",
"inboundTag": [
"streamingMedia-80",
"streamingMedia-443"
],
"outboundTag": "blackhole-out"
}
]
}
}
EOF EOF
oldIFS="${IFS}" fi
IFS=","
# shellcheck disable=SC2206
sourceIPs=(${setIPs})
IFS="${oldIFS}"
local routing
for value in "${sourceIPs[@]}"; do
routing=$(jq -r ".routing.rules[0].source += [\"${value}\"]" ${configPath}09_routing.json)
echo "${routing}" | jq . >${configPath}09_routing.json
done
reloadCore reloadCore
echoContent green " ---> 添加落地机入站解锁Netflix成功" echoContent green " ---> 添加落地机入站解锁成功"
exit 0 exit 0
fi fi
echoContent red " ---> ip不可为空" echoContent red " ---> ip不可为空"
} }
# 移除任意门解锁Netflix # 移除任意门解锁Netflix
removeDokodemoDoorUnblockNetflix() { removeDokodemoDoorUnblockStreamingMedia() {
unInstallOutbounds streamingMedia-80
unInstallOutbounds streamingMedia-443
unInstallRouting streamingMedia-80 inboundTag
unInstallRouting streamingMedia-443 inboundTag
unInstallRouting streamingMedia-80 outboundTag
unInstallRouting streamingMedia-443 outboundTag
unInstallOutbounds netflix-80
unInstallOutbounds netflix-443
unInstallRouting netflix-80
unInstallRouting netflix-443
rm -rf ${configPath}01_netflix_inbounds.json rm -rf ${configPath}01_netflix_inbounds.json
reloadCore reloadCore
@ -3864,35 +3893,6 @@ reloadCore() {
fi fi
} }
# 检查 vps是否支持Netflix
checkNetflix() {
echoContent red "\n注意事项"
echoContent yellow " 1.只可检测vps是否支持Netflix"
echoContent yellow " 2.无法检测代理配置dns解锁后是否支持Netflix"
echoContent yellow " 3.可检测vps配置dns解锁后是否支持Netflix\n"
echoContent skyBlue " ---> 检测中"
netflixResult=$(curl -s -m 2 https://www.netflix.com | grep "Not Available")
if [[ -n ${netflixResult} ]]; then
echoContent red " ---> Netflix不可用"
exit 0
fi
netflixResult=$(curl -s -m 2 https://www.netflix.com | grep "NSEZ-403")
if [[ -n ${netflixResult} ]]; then
echoContent red " ---> Netflix不可用"
exit 0
fi
echoContent skyBlue " ---> 检测绝命毒师是否可以播放"
result=$(curl -s -m 2 https://www.netflix.com/title/70143836 | grep "page-404")
if [[ -n ${result} ]]; then
echoContent green " ---> 仅可看自制剧"
exit 0
fi
echoContent green " ---> Netflix解锁"
exit 0
}
# dns解锁Netflix # dns解锁Netflix
dnsUnlockNetflix() { dnsUnlockNetflix() {
if [[ -z "${configPath}" ]]; then if [[ -z "${configPath}" ]]; then
@ -3931,7 +3931,7 @@ setUnlockDNS() {
echoContent yellow "7.默认方案请输入1默认方案包括以下内容" echoContent yellow "7.默认方案请输入1默认方案包括以下内容"
echoContent yellow "netflix,bahamut,hulu,hbo,disney,bbc,4chan,fox,abema,dmm,niconico,pixiv,bilibili,viu" echoContent yellow "netflix,bahamut,hulu,hbo,disney,bbc,4chan,fox,abema,dmm,niconico,pixiv,bilibili,viu"
read -r -p "请按照上面示例录入域名:" domainList read -r -p "请按照上面示例录入域名:" domainList
if [[ "${domainList}" = "1" ]];then if [[ "${domainList}" = "1" ]]; then
cat <<EOF >${configPath}11_dns.json cat <<EOF >${configPath}11_dns.json
{ {
"dns": { "dns": {
@ -3961,7 +3961,7 @@ setUnlockDNS() {
} }
} }
EOF EOF
elif [[ -n "${domainList}" ]];then elif [[ -n "${domainList}" ]]; then
cat <<EOF >${configPath}11_dns.json cat <<EOF >${configPath}11_dns.json
{ {
"dns": { "dns": {
@ -4341,7 +4341,7 @@ menu() {
cd "$HOME" || exit cd "$HOME" || exit
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者mack-a" echoContent green "作者mack-a"
echoContent green "当前版本v2.5.42" echoContent green "当前版本v2.5.43"
echoContent green "Githubhttps://github.com/mack-a/v2ray-agent" echoContent green "Githubhttps://github.com/mack-a/v2ray-agent"
echoContent green "描述:八合一共存脚本\c" echoContent green "描述:八合一共存脚本\c"
showInstallStatus showInstallStatus