feat(脚本): 添加新端口时会同步添加hysteria相应端口

pull/534/merge
mack-a 2022-12-29 10:47:52 +08:00
parent abc480ed5a
commit e9f4d0d6dd
1 changed files with 3525 additions and 3497 deletions

View File

@ -353,12 +353,16 @@ readInstallAlpn() {
# 检查防火墙 # 检查防火墙
allowPort() { allowPort() {
local type=$2
if [[ -z ${type} ]]; then
type=tcp
fi
# 如果防火墙启动状态则添加相应的开放端口 # 如果防火墙启动状态则添加相应的开放端口
if systemctl status netfilter-persistent 2>/dev/null | grep -q "active (exited)"; then if systemctl status netfilter-persistent 2>/dev/null | grep -q "active (exited)"; then
local updateFirewalldStatus= local updateFirewalldStatus=
if ! iptables -L | grep -q "$1(mack-a)"; then if ! iptables -L | grep -q "$1(mack-a)"; then
updateFirewalldStatus=true updateFirewalldStatus=true
iptables -I INPUT -p tcp --dport "$1" -m comment --comment "allow $1(mack-a)" -j ACCEPT iptables -I INPUT -p ${type} --dport "$1" -m comment --comment "allow $1(mack-a)" -j ACCEPT
fi fi
if echo "${updateFirewalldStatus}" | grep -q "true"; then if echo "${updateFirewalldStatus}" | grep -q "true"; then
@ -367,18 +371,16 @@ allowPort() {
elif systemctl status ufw 2>/dev/null | grep -q "active (exited)"; then elif systemctl status ufw 2>/dev/null | grep -q "active (exited)"; then
if ufw status | grep -q "Status: active"; then if ufw status | grep -q "Status: active"; then
if ! ufw status | grep -q "$1"; then if ! ufw status | grep -q "$1"; then
sudo ufw allow "$1" sudo ufw allow "$1/${type}"
checkUFWAllowPort "$1" checkUFWAllowPort "$1"
fi fi
fi fi
elif elif systemctl status firewalld 2>/dev/null | grep -q "active (running)"; then
systemctl status firewalld 2>/dev/null | grep -q "active (running)"
then
local updateFirewalldStatus= local updateFirewalldStatus=
if ! firewall-cmd --list-ports --permanent | grep -qw "$1/tcp"; then if ! firewall-cmd --list-ports --permanent | grep -qw "$1/${type}"; then
updateFirewalldStatus=true updateFirewalldStatus=true
firewall-cmd --zone=public --add-port="$1/tcp" --permanent firewall-cmd --zone=public --add-port="$1/${type}" --permanent
checkFirewalldAllowPort "$1" checkFirewalldAllowPort "$1"
fi fi
@ -3543,6 +3545,7 @@ updateNginxBlog() {
# 添加新端口 # 添加新端口
addCorePort() { addCorePort() {
readHysteriaConfig
echoContent skyBlue "\n功能 1/${totalProgress} : 添加新端口" echoContent skyBlue "\n功能 1/${totalProgress} : 添加新端口"
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent yellow "# 注意事项\n" echoContent yellow "# 注意事项\n"
@ -3550,6 +3553,7 @@ addCorePort() {
echoContent yellow "不影响默认端口的使用" echoContent yellow "不影响默认端口的使用"
echoContent yellow "查看账号时,只会展示默认端口的账号" echoContent yellow "查看账号时,只会展示默认端口的账号"
echoContent yellow "不允许有特殊字符,注意逗号的格式" echoContent yellow "不允许有特殊字符,注意逗号的格式"
echoContent yellow "会同时安装hysteria新端口"
echoContent yellow "录入示例:2053,2083,2087\n" echoContent yellow "录入示例:2053,2083,2087\n"
echoContent yellow "1.添加端口" echoContent yellow "1.添加端口"
@ -3570,20 +3574,46 @@ addCorePort() {
rm -rf "$(find ${configPath}* | grep "${port}")" rm -rf "$(find ${configPath}* | grep "${port}")"
local fileName= local fileName=
local hysteriaFileName=
if [[ -n "${defaultPort}" && "${port}" == "${defaultPort}" ]]; then if [[ -n "${defaultPort}" && "${port}" == "${defaultPort}" ]]; then
fileName="${configPath}02_dokodemodoor_inbounds_${port}_default.json" fileName="${configPath}02_dokodemodoor_inbounds_${port}_default.json"
else else
fileName="${configPath}02_dokodemodoor_inbounds_${port}.json" fileName="${configPath}02_dokodemodoor_inbounds_${port}.json"
fi fi
if [[ -n ${hysteriaPort} ]]; then
hysteriaFileName="${configPath}02_dokodemodoor_inbounds_hysteria_${port}.json"
fi
# 开放端口 # 开放端口
allowPort "${port}" allowPort "${port}"
allowPort "${port}" "udp"
local settingsPort=443 local settingsPort=443
if [[ -n "${customPort}" ]]; then if [[ -n "${customPort}" ]]; then
settingsPort=${customPort} settingsPort=${customPort}
fi fi
if [[ -n ${hysteriaFileName} ]]; then
cat <<EOF >"${hysteriaFileName}"
{
"inbounds": [
{
"listen": "0.0.0.0",
"port": ${port},
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1",
"port": ${hysteriaPort},
"network": "udp",
"followRedirect": false
},
"tag": "dokodemo-door-newPort-hysteria-${port}"
}
]
}
EOF
fi
cat <<EOF >"${fileName}" cat <<EOF >"${fileName}"
{ {
"inbounds": [ "inbounds": [
@ -5432,15 +5462,13 @@ menu() {
cd "$HOME" || exit cd "$HOME" || exit
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者:mack-a" echoContent green "作者:mack-a"
echoContent green "当前版本:v2.6.13" echoContent green "当前版本:v2.6.14"
echoContent green "Github:https://github.com/mack-a/v2ray-agent" echoContent green "Github:https://github.com/mack-a/v2ray-agent"
echoContent green "描述:八合一共存脚本\c" echoContent green "描述:八合一共存脚本\c"
showInstallStatus showInstallStatus
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent red " 推广区 " echoContent red " 推广区 "
echoContent green "AFF捐赠https://github.com/mack-a/v2ray-agent/blob/master/documents/donation_aff.md\n" echoContent green "AFF捐赠https://github.com/mack-a/v2ray-agent/blob/master/documents/donation_aff.md\n"
echoContent green "虚拟币捐赠0xB08b731653515b083deE362fefFc45d5eb96c35d\n"
echoContent green "推广可联系TGhttps://t.me/mackaff"
echoContent red "==============================================================" echoContent red "=============================================================="
if [[ -n "${coreInstallType}" ]]; then if [[ -n "${coreInstallType}" ]]; then
echoContent yellow "1.重新安装" echoContent yellow "1.重新安装"