mirror of
https://github.com/kenzok8/small-package
synced 2025-01-05 11:36:47 +08:00
update 2024-09-05 20:36:23
This commit is contained in:
parent
3336fac4af
commit
8cc08d0dd3
@ -24,7 +24,6 @@ PKG_CONFIG_DEPENDS:= CONFIG_PACKAGE_$(PKG_NAME)_INCLUDE_binary
|
||||
define Package/luci-app-adguardhome/conffiles
|
||||
/usr/share/AdGuardHome/links.txt
|
||||
/etc/config/AdGuardHome
|
||||
/etc/AdGuardHome.yaml
|
||||
endef
|
||||
|
||||
define Package/luci-app-adguardhome/postinst
|
||||
|
@ -3,7 +3,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-natmap
|
||||
PKG_VERSION:=1.5.1
|
||||
PKG_VERSION:=1.5.2
|
||||
PKG_RELEASE:=1
|
||||
|
||||
LUCI_TITLE:=LuCI Support for natmap
|
||||
|
@ -291,6 +291,7 @@ return view.extend({
|
||||
o.datatype = "uinteger";
|
||||
o.default = 10;
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.depends("forward_advanced_enable", "1");
|
||||
|
||||
o = s.taboption(
|
||||
@ -303,6 +304,7 @@ return view.extend({
|
||||
o.datatype = "uinteger";
|
||||
o.default = 3;
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.depends("forward_advanced_enable", "1");
|
||||
|
||||
// **********************************************************************
|
||||
@ -485,6 +487,7 @@ return view.extend({
|
||||
o.datatype = "uinteger";
|
||||
o.default = 10;
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.depends("notify_advanced_enable", "1");
|
||||
|
||||
o = s.taboption(
|
||||
@ -497,6 +500,7 @@ return view.extend({
|
||||
o.datatype = "uinteger";
|
||||
o.default = 3;
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.depends("notify_advanced_enable", "1");
|
||||
|
||||
// **********************************************************************
|
||||
@ -815,6 +819,7 @@ return view.extend({
|
||||
o.datatype = "uinteger";
|
||||
o.default = 10;
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.depends("link_advanced_enable", "1");
|
||||
|
||||
o = s.taboption(
|
||||
@ -827,6 +832,7 @@ return view.extend({
|
||||
o.datatype = "uinteger";
|
||||
o.default = 3;
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.depends("link_advanced_enable", "1");
|
||||
|
||||
// **********************************************************************
|
||||
|
@ -11,6 +11,20 @@ if [ -z "$FORWARD_TARGET_PORT" ] || [ -z "$FORWARD_TARGET_IP" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 设置重试次数和时间间隔
|
||||
max_retries=1
|
||||
sleep_time=1
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "${FORWARD_ADVANCED_ENABLE}" == 1 ]; then
|
||||
max_retries=$FORWARD_ADVANCED_MAX_RETRIES
|
||||
sleep_time=$FORWARD_ADVANCED_SLEEP_TIME
|
||||
else
|
||||
# 默认重试次数为1,休眠时间为1s
|
||||
max_retries=1
|
||||
sleep_time=1
|
||||
fi
|
||||
|
||||
forward_script=""
|
||||
case $FORWARD_MODE in
|
||||
"firewall")
|
||||
@ -24,13 +38,8 @@ case $FORWARD_MODE in
|
||||
;;
|
||||
esac
|
||||
|
||||
# # 如果$FORWARD_MODE非空则执行对应的脚本
|
||||
# if [ -n "${FORWARD_MODE}" ]; then
|
||||
# forward_script="/usr/share/natmap/plugin-forward/${FORWARD_MODE}-forward.sh"
|
||||
# fi
|
||||
|
||||
if [ -n "${forward_script}" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME execute forward script" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME execute forward script"
|
||||
bash "$forward_script" "$@"
|
||||
bash "$forward_script" "$outter_ip" "$outter_port" "$ip4p" "$inner_port" "$protocol" "$max_retries" "$sleep_time"
|
||||
fi
|
||||
|
@ -9,13 +9,51 @@ protocol=$5
|
||||
link_script=""
|
||||
# echo "LINK_MODE: $LINK_MODE"
|
||||
|
||||
# 如果$LINK_MODE非空则执行对应的脚本
|
||||
if [ -n "${LINK_MODE}" ]; then
|
||||
link_script="/usr/share/natmap/plugin-link/${LINK_MODE}.sh"
|
||||
# 设置重试次数和时间间隔
|
||||
max_retries=1
|
||||
sleep_time=1
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "${LINK_ADVANCED_ENABLE}" == 1 ]; then
|
||||
max_retries=$LINK_ADVANCED_MAX_RETRIES
|
||||
sleep_time=$LINK_ADVANCED_SLEEP_TIME
|
||||
else
|
||||
# 默认重试次数为1,休眠时间为1s
|
||||
max_retries=1
|
||||
sleep_time=1
|
||||
fi
|
||||
|
||||
# 如果$LINK_MODE非空则执行对应的脚本
|
||||
case "${LINK_MODE}" in
|
||||
"cloudflare_ddns")
|
||||
link_script="/usr/share/natmap/plugin-link/cloudflare_ddns.sh"
|
||||
;;
|
||||
"cloudflare_origin_rule")
|
||||
link_script="/usr/share/natmap/plugin-link/cloudflare_origin_rule.sh"
|
||||
;;
|
||||
"cloudflare_redirect_rule")
|
||||
link_script="/usr/share/natmap/plugin-link/cloudflare_redirect_rule.sh"
|
||||
;;
|
||||
"emby")
|
||||
link_script="/usr/share/natmap/plugin-link/emby.sh"
|
||||
;;
|
||||
"qbittorrent")
|
||||
link_script="/usr/share/natmap/plugin-link/qbittorrent.sh"
|
||||
;;
|
||||
"transmission")
|
||||
link_script="/usr/share/natmap/plugin-link/transmission.sh"
|
||||
;;
|
||||
*)
|
||||
link_script=""
|
||||
;;
|
||||
esac
|
||||
|
||||
# if [ -n "${LINK_MODE}" ]; then
|
||||
# link_script="/usr/share/natmap/plugin-link/${LINK_MODE}.sh"
|
||||
# fi
|
||||
|
||||
if [ -n "${link_script}" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME execute link script" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME execute link script"
|
||||
bash "${link_script}" "$@"
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME execute link script" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME execute link script"
|
||||
bash "${link_script}" "$outter_ip" "$outter_port" "$ip4p" "$inner_port" "$protocol" "$max_retries" "$sleep_time"
|
||||
fi
|
||||
|
@ -6,6 +6,7 @@ ip4p=$3
|
||||
inner_port=$4
|
||||
protocol=$(echo $5 | tr 'a-z' 'A-Z')
|
||||
|
||||
# 构建消息内容
|
||||
msg="${GENERAL_NAT_NAME}
|
||||
New ${protocol} port mapping: ${inner_port} -> ${outter_ip}:${outter_port}
|
||||
IP4P: ${ip4p}"
|
||||
@ -13,33 +14,47 @@ if [ ! -z "$MSG_OVERRIDE" ]; then
|
||||
msg="$MSG_OVERRIDE"
|
||||
fi
|
||||
|
||||
# 设置重试次数和时间间隔
|
||||
max_retries=1
|
||||
sleep_time=1
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "${NOTIFY_ADVANCED_ENABLE}" == 1 ]; then
|
||||
max_retries=$NOTIFY_ADVANCED_MAX_RETRIES
|
||||
sleep_time=$NOTIFY_ADVANCED_SLEEP_TIME
|
||||
else
|
||||
# 默认重试次数为1,休眠时间为1s
|
||||
max_retries=1
|
||||
sleep_time=1
|
||||
fi
|
||||
|
||||
# notify_mode 判断
|
||||
notify_script=""
|
||||
# case $NOTIFY_MODE in
|
||||
# "telegram_bot")
|
||||
# notify_script="/usr/share/natmap/plugin-notify/telegram_bot.sh"
|
||||
# ;;
|
||||
# "pushplus")
|
||||
# notify_script="/usr/share/natmap/plugin-notify/pushplus.sh"
|
||||
# ;;
|
||||
# "serverchan")
|
||||
# notify_script="/usr/share/natmap/plugin-notify/serverchan.sh"
|
||||
# ;;
|
||||
# "gotify")
|
||||
# notify_script="/usr/share/natmap/plugin-notify/gotify.sh"
|
||||
# ;;
|
||||
# *)
|
||||
# notify_script=""
|
||||
# ;;
|
||||
# esac
|
||||
case $NOTIFY_MODE in
|
||||
"telegram_bot")
|
||||
notify_script="/usr/share/natmap/plugin-notify/telegram_bot.sh"
|
||||
;;
|
||||
"pushplus")
|
||||
notify_script="/usr/share/natmap/plugin-notify/pushplus.sh"
|
||||
;;
|
||||
"serverchan")
|
||||
notify_script="/usr/share/natmap/plugin-notify/serverchan.sh"
|
||||
;;
|
||||
"gotify")
|
||||
notify_script="/usr/share/natmap/plugin-notify/gotify.sh"
|
||||
;;
|
||||
*)
|
||||
notify_script=""
|
||||
;;
|
||||
esac
|
||||
|
||||
# 如果$NOTIFY_MODE非空则执行对应的脚本
|
||||
if [ -n "${NOTIFY_MODE}" ]; then
|
||||
notify_script="/usr/share/natmap/plugin-notify/$NOTIFY_MODE.sh"
|
||||
fi
|
||||
# # 如果$NOTIFY_MODE非空则执行对应的脚本
|
||||
# if [ -n "${NOTIFY_MODE}" ]; then
|
||||
# notify_script="/usr/share/natmap/plugin-notify/$NOTIFY_MODE.sh"
|
||||
# fi
|
||||
|
||||
if [ -n "${notify_script}" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME execute notify script" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME execute notify script"
|
||||
bash "$notify_script" "$msg"
|
||||
bash "$notify_script" "$msg" "$max_retries" "$sleep_time"
|
||||
fi
|
||||
|
@ -7,20 +7,10 @@ outter_port=$2
|
||||
ip4p=$3
|
||||
inner_port=$4
|
||||
protocol=$5
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
max_retries=$6
|
||||
sleep_time=$7
|
||||
retry_count=0
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "${FORWARD_ADVANCED_ENABLE}" == 1 ] && [ -n "$FORWARD_ADVANCED_MAX_RETRIES" ] && [ -n "$FORWARD_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((FORWARD_ADVANCED_MAX_RETRIES == "0" ? 1 : FORWARD_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((FORWARD_ADVANCED_SLEEP_TIME == "0" ? 3 : FORWARD_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
|
||||
# lan_port
|
||||
mapping_lan_port=""
|
||||
# 如果$FORWARD_TARGET_PORT为空或者$FORWARD_TARGET_PORT为0则退出
|
||||
@ -140,7 +130,7 @@ function call_action() {
|
||||
# ------------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------
|
||||
# 端口映射处理开始
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
while (true); do
|
||||
#
|
||||
# 登录
|
||||
login_payload="$(create_payload "login")"
|
||||
@ -155,68 +145,73 @@ for (( ; retry_count < max_retries; retry_count++)); do
|
||||
show_response="$(call_action "$cookie" "$show_payload")"
|
||||
# 获取dnat_id
|
||||
mapping_record_ids=()
|
||||
[ "$(echo "$show_response" | jq -r '.ErrMsg')" = "Success" ] && mapping_record_ids=($(echo "$show_response" | jq -r '.Data.data[].id'))
|
||||
# echo "mapping_record_ids: ${mapping_record_ids[@]}"
|
||||
if [ "$(echo "$show_response" | jq -r '.ErrMsg')" = "Success" ]; then
|
||||
mapping_record_ids=($(echo "$show_response" | jq -r '.Data.data[].id'))
|
||||
|
||||
#
|
||||
# 如果存在record_id,则删除所有端口映射
|
||||
[ ${#mapping_record_ids[@]} -gt 0 ] &&
|
||||
for id in "${mapping_record_ids[@]}"; do
|
||||
# echo "mapping_record_id: $id"
|
||||
del_payload="$(create_payload "del" "$id")"
|
||||
del_response="$(call_action "$cookie" "$del_payload")"
|
||||
if [ "$(echo "$del_response" | jq -r '.ErrMsg')" = "Success" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Port mapping deleted successfully" >>/var/log/natmap/natmap.log
|
||||
# echo "delete successfully"
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Failed to delete the port mapping" >>/var/log/natmap/natmap.log
|
||||
# echo "delete failed"
|
||||
fi
|
||||
done
|
||||
# echo "mapping_record_ids: ${mapping_record_ids[@]}"
|
||||
|
||||
#
|
||||
# 再次查询端口映射id
|
||||
show_response="$(call_action "$cookie" "$show_payload")"
|
||||
# 预设值mapping_record_ids数组变量,用于后续判断
|
||||
mapping_record_ids=(1 2)
|
||||
# echo "mapping_record_ids: ${mapping_record_ids[@]}"
|
||||
[ "$(echo "$show_response" | jq -r '.ErrMsg')" = "Success" ] && mapping_record_ids=($(echo "$show_response" | jq -r '.Data.data[].id'))
|
||||
# 验证对应端口映射是否存在
|
||||
if [ ${#mapping_record_ids[@]} -eq 0 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE all Port mapping deleted successfully" >>/var/log/natmap/natmap.log
|
||||
#
|
||||
# 添加端口映射
|
||||
# echo "adding mapping record..."
|
||||
add_payload="$(create_payload "add")"
|
||||
# echo "add_payload: $add_payload"
|
||||
add_response="$(call_action "$cookie" "$add_payload")"
|
||||
# echo "add_response: $add_response"
|
||||
#
|
||||
# Check if the modification was successful
|
||||
if [ "$(echo "$add_response" | jq -r '.ErrMsg')" = "Success" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Port mapping add successfully" >>/var/log/natmap/natmap.log
|
||||
# echo "add successfully"
|
||||
break
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Failed to add" >>/var/log/natmap/natmap.log
|
||||
# echo "add failed"
|
||||
# 如果存在record_id,则删除所有端口映射
|
||||
if [ ${#mapping_record_ids[@]} -gt 0 ]; then
|
||||
for id in "${mapping_record_ids[@]}"; do
|
||||
# echo "mapping_record_id: $id"
|
||||
del_payload="$(create_payload "del" "$id")"
|
||||
del_response="$(call_action "$cookie" "$del_payload")"
|
||||
if [ "$(echo "$del_response" | jq -r '.ErrMsg')" = "Success" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Port mapping deleted successfully" >>/var/log/natmap/natmap.log
|
||||
# echo "delete successfully"
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Failed to delete the port mapping" >>/var/log/natmap/natmap.log
|
||||
# echo "delete failed"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# 再次查询端口映射id
|
||||
show_response="$(call_action "$cookie" "$show_payload")"
|
||||
# 预设值mapping_record_ids数组变量,用于后续判断
|
||||
mapping_record_ids=(1 2)
|
||||
# echo "mapping_record_ids: ${mapping_record_ids[@]}"
|
||||
[ "$(echo "$show_response" | jq -r '.ErrMsg')" = "Success" ] && mapping_record_ids=($(echo "$show_response" | jq -r '.Data.data[].id'))
|
||||
|
||||
# 验证对应端口映射是否存在
|
||||
if [ ${#mapping_record_ids[@]} -eq 0 ]; then
|
||||
|
||||
# 旧端口映射记录已经全部删除,开始创建新纪录
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE all Port mapping deleted successfully" >>/var/log/natmap/natmap.log
|
||||
#
|
||||
# 添加端口映射
|
||||
# echo "adding mapping record..."
|
||||
add_payload="$(create_payload "add")"
|
||||
# echo "add_payload: $add_payload"
|
||||
add_response="$(call_action "$cookie" "$add_payload")"
|
||||
# echo "add_response: $add_response"
|
||||
#
|
||||
# Check if the modification was successful
|
||||
if [ "$(echo "$add_response" | jq -r '.ErrMsg')" = "Success" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Port mapping add successfully" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 修改成功"
|
||||
# echo "add successfully"
|
||||
break
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Failed to add" >>/var/log/natmap/natmap.log
|
||||
# echo "add failed"
|
||||
fi
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Failed to delete all of old record" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE Failed to delete all of old record" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
else
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 达到最大重试次数,无法修改,请检测是否设置正确" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 达到最大重试次数,无法修改,请检测是否设置正确"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 达到最大重试次数,无法修改,请检测是否设置正确" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 达到最大重试次数,无法修改,请检测是否设置正确"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $FORWARD_MODE 修改成功"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
@ -6,19 +6,11 @@ outter_port=$2
|
||||
ip4p=$3
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "$LINK_ADVANCED_ENABLE" == 1 ] && [ -n "$LINK_ADVANCED_MAX_RETRIES" ] && [ -n "$LINK_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((LINK_ADVANCED_MAX_RETRIES == "0" ? 1 : LINK_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((LINK_ADVANCED_SLEEP_TIME == "0" ? 3 : LINK_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
max_retries=$6
|
||||
sleep_time=$7
|
||||
retry_count=0
|
||||
|
||||
# 初始化参数
|
||||
retry_count=0
|
||||
dns_type=$LINK_CLOUDFLARE_DDNS_TYPE
|
||||
dns_record_id=""
|
||||
|
||||
@ -29,26 +21,20 @@ dns_record_id=""
|
||||
function get_dns_record_id() {
|
||||
local local_ddns_domain="$1"
|
||||
local local_dns_types="$2"
|
||||
local local_dns_record_id=""
|
||||
|
||||
# 获取cloudflare dns记录的dns_record
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
# 发送GET请求
|
||||
local local_dns_record=$(curl --request GET \
|
||||
--url "https://api.cloudflare.com/client/v4/zones/$LINK_CLOUDFLARE_ZONE_ID/dns_records?name=$local_ddns_domain&type=$local_dns_types" \
|
||||
--header "Authorization: Bearer $LINK_CLOUDFLARE_TOKEN" \
|
||||
--header "Content-Type: application/json")
|
||||
local local_dns_record=$(curl --request GET \
|
||||
--url "https://api.cloudflare.com/client/v4/zones/$LINK_CLOUDFLARE_ZONE_ID/dns_records?name=$local_ddns_domain&type=$local_dns_types" \
|
||||
--header "Authorization: Bearer $LINK_CLOUDFLARE_TOKEN" \
|
||||
--header "Content-Type: application/json")
|
||||
|
||||
# 判断是否成功获取响应
|
||||
if [ "$(echo "$local_dns_record" | jq '.success' | sed 's/"//g')" == "true" ]; then
|
||||
# 获取与dns_type匹配的dns_record_id
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录成功" >>/var/log/natmap/natmap.log
|
||||
local local_dns_record_id=$(echo "$local_dns_record" | jq ".result[0].id" | sed 's/"//g')
|
||||
break
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
fi
|
||||
done
|
||||
# 判断是否成功获取响应
|
||||
if [ "$(echo "$local_dns_record" | jq '.success' | sed 's/"//g')" == "true" ]; then
|
||||
# 获取与dns_type匹配的dns_record_id
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录成功" >>/var/log/natmap/natmap.log
|
||||
local_dns_record_id=$(echo "$local_dns_record" | jq ".result[0].id" | sed 's/"//g')
|
||||
fi
|
||||
|
||||
# 返回dns记录的id
|
||||
echo "$local_dns_record_id"
|
||||
@ -57,7 +43,7 @@ function get_dns_record_id() {
|
||||
# 创建请求数据
|
||||
# @param {string} local_dns_type - dns记录类型
|
||||
# @return {string} - 请求数据
|
||||
function create_request_data() {
|
||||
function generate_request_data() {
|
||||
local local_dns_type="$1"
|
||||
|
||||
# 构建请求数据
|
||||
@ -124,27 +110,15 @@ function create_request_data() {
|
||||
function update_dns_record() {
|
||||
local local_dns_record_id="$1"
|
||||
local local_request_data="$2"
|
||||
local local_result=""
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
local_result=$(
|
||||
curl --request PUT \
|
||||
--url "https://api.cloudflare.com/client/v4/zones/$LINK_CLOUDFLARE_ZONE_ID/dns_records/$local_dns_record_id" \
|
||||
--header "Authorization: Bearer $LINK_CLOUDFLARE_TOKEN" \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "$local_request_data"
|
||||
)
|
||||
local local_result==$(
|
||||
curl --request PUT \
|
||||
--url "https://api.cloudflare.com/client/v4/zones/$LINK_CLOUDFLARE_ZONE_ID/dns_records/$local_dns_record_id" \
|
||||
--header "Authorization: Bearer $LINK_CLOUDFLARE_TOKEN" \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "$local_request_data"
|
||||
)
|
||||
|
||||
# 判断api是否调用成功,返回参数success是否为true
|
||||
if [ "$(echo "$local_result" | jq '.success' | sed 's/"//g')" == "true" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 更新成功" >>/var/log/natmap/natmap.log
|
||||
break
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
fi
|
||||
done
|
||||
|
||||
# 返回值
|
||||
# 判断api是否调用成功,返回参数success是否为true
|
||||
if [ "$(echo "$local_result" | jq '.success' | sed 's/"//g')" == "true" ]; then
|
||||
echo "true"
|
||||
else
|
||||
@ -153,42 +127,78 @@ function update_dns_record() {
|
||||
}
|
||||
|
||||
# 开始运行
|
||||
# 初始化输出参数
|
||||
result="false"
|
||||
# 更新cloudflare的dns记录
|
||||
case $dns_type in
|
||||
"AAAA")
|
||||
# 更新 AAAA 记录
|
||||
dns_record_id=$(get_dns_record_id "$LINK_CLOUDFLARE_DDNS_DOMAIN" "$dns_type")
|
||||
request_data="$(create_request_data "$dns_type")"
|
||||
result=$(update_dns_record "$dns_record_id" "$request_data")
|
||||
;;
|
||||
"HTTPS")
|
||||
dns_record_id=$(get_dns_record_id "$LINK_CLOUDFLARE_DDNS_DOMAIN" "$dns_type")
|
||||
request_data="$(create_request_data "$dns_type")"
|
||||
result=$(update_dns_record "$dns_record_id" "$request_data")
|
||||
;;
|
||||
"SRV")
|
||||
# 更新target_domain的A记录
|
||||
dns_type="A"
|
||||
dns_record_id=$(get_dns_record_id "$LINK_CLOUDFLARE_DDNS_SRV_TARGET_DOMAIN" "$dns_type")
|
||||
request_data="$(create_request_data "$dns_type")"
|
||||
result=$(update_dns_record "$dns_record_id" "$request_data")
|
||||
while (true); do
|
||||
case $dns_type in
|
||||
"AAAA")
|
||||
# 更新 AAAA 记录
|
||||
request_data="$(generate_request_data "$dns_type")"
|
||||
dns_record_id="$(get_dns_record_id "$LINK_CLOUDFLARE_DDNS_DOMAIN" "$dns_type")"
|
||||
result="$(update_dns_record "$dns_record_id" "$request_data")"
|
||||
|
||||
# 更新SRV记录
|
||||
dns_type="SRV"
|
||||
dns_record_id=$(get_dns_record_id "$LINK_CLOUDFLARE_DDNS_DOMAIN" "$dns_type")
|
||||
request_data="$(create_request_data "$dns_type")"
|
||||
result=$(update_dns_record "$dns_record_id" "$request_data")
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
# 判断api是否调用成功
|
||||
if [ "$result" == "true" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
break
|
||||
else
|
||||
echo "$LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
;;
|
||||
"HTTPS")
|
||||
# 更新 HTTPS 记录
|
||||
request_data="$(generate_request_data "$dns_type")"
|
||||
dns_record_id="$(get_dns_record_id "$LINK_CLOUDFLARE_DDNS_DOMAIN" "$dns_type")"
|
||||
result="$(update_dns_record "$dns_record_id" "$request_data")"
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -ge $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 更新成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 更新成功"
|
||||
exit 0
|
||||
fi
|
||||
# 判断api是否调用成功
|
||||
if [ "$result" == "true" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
break
|
||||
else
|
||||
echo "$LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
;;
|
||||
"SRV")
|
||||
# 更新target_domain的A记录
|
||||
dns_type="A"
|
||||
request_data="$(generate_request_data "$dns_type")"
|
||||
dns_record_id="$(get_dns_record_id "$LINK_CLOUDFLARE_DDNS_SRV_TARGET_DOMAIN" "$dns_type")"
|
||||
result="$(update_dns_record "$dns_record_id" "$request_data")"
|
||||
|
||||
# 判断api是否调用成功,成功则继续下一步,更新SRV记录
|
||||
if [ "$result" == "true" ]; then
|
||||
# 更新SRV记录
|
||||
dns_type="SRV"
|
||||
request_data="$(generate_request_data "$dns_type")"
|
||||
dns_record_id="$(get_dns_record_id "$LINK_CLOUDFLARE_DDNS_DOMAIN" "$dns_type")"
|
||||
result="$(update_dns_record "$dns_record_id" "$request_data")"
|
||||
|
||||
# 判断api是否调用成功
|
||||
if [ "$result" == "true" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
break
|
||||
else
|
||||
echo "$LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
else
|
||||
echo "$LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -16,60 +16,56 @@ function get_current_rule() {
|
||||
}
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "$LINK_ADVANCED_ENABLE" == 1 ] && [ -n "$LINK_ADVANCED_MAX_RETRIES" ] && [ -n "$LINK_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((LINK_ADVANCED_MAX_RETRIES == "0" ? 1 : LINK_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((LINK_ADVANCED_SLEEP_TIME == "0" ? 3 : LINK_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
max_retries=$6
|
||||
sleep_time=$7
|
||||
retry_count=0
|
||||
|
||||
# 初始化参数
|
||||
|
||||
retry_count=0
|
||||
currrent_rule=""
|
||||
cloudflare_ruleset_id=""
|
||||
|
||||
# 获取cloudflare origin rule id
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
while (true); do
|
||||
currrent_rule=$(get_current_rule)
|
||||
cloudflare_ruleset_id=$(echo "$currrent_rule" | jq '.result.id' | sed 's/"//g')
|
||||
|
||||
if [ -z "$cloudflare_ruleset_id" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
if [ -n "$cloudflare_ruleset_id" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录成功" >>/var/log/natmap/natmap.log
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 修改 origin rule
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
# 修改 origin rule
|
||||
origin_rule_name="\"$LINK_CLOUDFLARE_ORIGIN_RULE_NAME\""
|
||||
new_rule=$(echo "$currrent_rule" | jq '.result.rules| to_entries | map(select(.value.description == '"$origin_rule_name"')) | .[].key')
|
||||
new_rule=$(echo "$currrent_rule" | jq '.result.rules['"$new_rule"'].action_parameters.origin.port = '"$outter_port"'')
|
||||
|
||||
origin_rule_name="\"$LINK_CLOUDFLARE_ORIGIN_RULE_NAME\""
|
||||
new_rule=$(echo "$currrent_rule" | jq '.result.rules| to_entries | map(select(.value.description == '"$origin_rule_name"')) | .[].key')
|
||||
new_rule=$(echo "$currrent_rule" | jq '.result.rules['"$new_rule"'].action_parameters.origin.port = '"$outter_port"'')
|
||||
# delete last_updated
|
||||
request_data=$(echo "$new_rule" | jq '.result | del(.last_updated)')
|
||||
result=$(curl --request PUT \
|
||||
--url "https://api.cloudflare.com/client/v4/zones/$LINK_CLOUDFLARE_ZONE_ID/rulesets/$cloudflare_ruleset_id" \
|
||||
--header "Authorization: Bearer $LINK_CLOUDFLARE_TOKEN" \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "$request_data")
|
||||
|
||||
# delete last_updated
|
||||
request_data=$(echo "$new_rule" | jq '.result | del(.last_updated)')
|
||||
result=$(curl --request PUT \
|
||||
--url "https://api.cloudflare.com/client/v4/zones/$LINK_CLOUDFLARE_ZONE_ID/rulesets/$cloudflare_ruleset_id" \
|
||||
--header "Authorization: Bearer $LINK_CLOUDFLARE_TOKEN" \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "$request_data")
|
||||
|
||||
if [ "$(echo "$result" | jq '.success' | sed 's/"//g')" == "true" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 更新成功" >>/var/log/natmap/natmap.log
|
||||
break
|
||||
if [ "$(echo "$result" | jq '.success' | sed 's/"//g')" == "true" ]; then
|
||||
# echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 更新成功" >>/var/log/natmap/natmap.log4
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
break
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
|
@ -12,72 +12,59 @@ function get_current_rule() {
|
||||
}
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "$LINK_ADVANCED_ENABLE" == 1 ] && [ -n "$LINK_ADVANCED_MAX_RETRIES" ] && [ -n "$LINK_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((LINK_ADVANCED_MAX_RETRIES == "0" ? 1 : LINK_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((LINK_ADVANCED_SLEEP_TIME == "0" ? 3 : LINK_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
max_retries=$6
|
||||
sleep_time=$7
|
||||
retry_count=0
|
||||
|
||||
# 初始化参数
|
||||
|
||||
retry_count=0
|
||||
currrent_rule=""
|
||||
cloudflare_ruleset_id=""
|
||||
|
||||
# 获取cloudflare redirect rule id
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
while (true); do
|
||||
currrent_rule=$(get_current_rule)
|
||||
cloudflare_ruleset_id=$(echo "$currrent_rule" | jq '.result.id' | sed 's/"//g')
|
||||
|
||||
if [ -z "$cloudflare_ruleset_id" ]; then
|
||||
echo "$LINK_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
if [ -n "$cloudflare_ruleset_id" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录成功" >>/var/log/natmap/natmap.log
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# update cloudflare redirect rule
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
cloudflare_redirect_rule_name="\"$LINK_CLOUDFLARE_REDIRECT_RULE_NAME\""
|
||||
# replace NEW_PORT with outter_port
|
||||
redirect_rule_target_url=$(echo $LINK_CLOUDFLARE_REDIRECT_RULE_TARGET_URL | sed 's/NEW_PORT/'"$outter_port"'/g')
|
||||
new_rule=$(echo "$currrent_rule" | jq '.result.rules| to_entries | map(select(.value.description == '"$cloudflare_redirect_rule_name"')) | .[].key')
|
||||
new_rule=$(echo "$currrent_rule" | jq '.result.rules['"$new_rule"'].action_parameters.from_value.target_url.value = "'"$redirect_rule_target_url"'"')
|
||||
# update cloudflare redirect rule
|
||||
cloudflare_redirect_rule_name="\"$LINK_CLOUDFLARE_REDIRECT_RULE_NAME\""
|
||||
|
||||
request_data=$(echo "$new_rule" | jq '.result')
|
||||
# replace NEW_PORT with outter_port
|
||||
redirect_rule_target_url=$(echo $LINK_CLOUDFLARE_REDIRECT_RULE_TARGET_URL | sed 's/NEW_PORT/'"$outter_port"'/g')
|
||||
new_rule=$(echo "$currrent_rule" | jq '.result.rules| to_entries | map(select(.value.description == '"$cloudflare_redirect_rule_name"')) | .[].key')
|
||||
new_rule=$(echo "$currrent_rule" | jq '.result.rules['"$new_rule"'].action_parameters.from_value.target_url.value = "'"$redirect_rule_target_url"'"')
|
||||
|
||||
# delete last_updated
|
||||
request_data=$(echo "$request_data" | jq 'del(.last_updated)')
|
||||
result=$(curl --request PUT \
|
||||
--url "https://api.cloudflare.com/client/v4/zones/$LINK_CLOUDFLARE_ZONE_ID/rulesets/$cloudflare_ruleset_id" \
|
||||
--header "Authorization: Bearer $LINK_CLOUDFLARE_TOKEN" \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "$request_data")
|
||||
request_data=$(echo "$new_rule" | jq '.result')
|
||||
|
||||
if [ "$(echo "$result" | jq '.success' | sed 's/"//g')" == "true" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 更新成功" >>/var/log/natmap/natmap.log
|
||||
# delete last_updated
|
||||
request_data=$(echo "$request_data" | jq 'del(.last_updated)')
|
||||
result=$(curl --request PUT \
|
||||
--url "https://api.cloudflare.com/client/v4/zones/$LINK_CLOUDFLARE_ZONE_ID/rulesets/$cloudflare_ruleset_id" \
|
||||
--header "Authorization: Bearer $LINK_CLOUDFLARE_TOKEN" \
|
||||
--header "Content-Type: application/json" \
|
||||
--data "$request_data")
|
||||
|
||||
break
|
||||
if [ "$(echo "$result" | jq '.success' | sed 's/"//g')" == "true" ]; then
|
||||
# echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 更新成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
break
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
exit 0
|
||||
fi
|
||||
|
@ -6,28 +6,17 @@ outter_port=$2
|
||||
LINK_EMBY_URL=$(echo $LINK_EMBY_URL | sed 's/\/$//')
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "$LINK_ADVANCED_ENABLE" == 1 ] && [ -n "$LINK_ADVANCED_MAX_RETRIES" ] && [ -n "$LINK_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((LINK_ADVANCED_MAX_RETRIES == "0" ? 1 : LINK_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((LINK_ADVANCED_SLEEP_TIME == "0" ? 3 : LINK_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
max_retries=$6
|
||||
sleep_time=$7
|
||||
retry_count=0
|
||||
|
||||
# 初始化参数
|
||||
current_cfg=""
|
||||
retry_count=0
|
||||
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
while (true); do
|
||||
current_cfg=$(curl -v $LINK_EMBY_URL/emby/System/Configuration?api_key=$LINK_EMBY_API_KEY)
|
||||
|
||||
if [ -z "$current_cfg" ]; then
|
||||
echo "$LINK_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
if [ -n "$current_cfg" ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录成功" >>/var/log/natmap/natmap.log
|
||||
new_cfg=$current_cfg
|
||||
if [ ! -z $LINK_EMBY_USE_HTTPS ] && [ $LINK_EMBY_USE_HTTPS = '1' ]; then
|
||||
@ -40,18 +29,26 @@ for (( ; retry_count < max_retries; retry_count++)); do
|
||||
new_cfg=$(echo $new_cfg | jq ".WanDdns = \"$outter_ip\"")
|
||||
fi
|
||||
|
||||
curl -X POST "$LINK_EMBY_URL/emby/System/Configuration?api_key=$LINK_EMBY_API_KEY" -H "accept: */*" -H "Content-Type: application/json" -d "$new_cfg"
|
||||
response=$(curl -X POST "$LINK_EMBY_URL/emby/System/Configuration?api_key=$LINK_EMBY_API_KEY" -H "accept: */*" -H "Content-Type: application/json" -d "$new_cfg" -w "%{http_code}")
|
||||
|
||||
if [ "$response" -eq 200 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
break
|
||||
else
|
||||
echo "$LINK_MODE 修改失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
else
|
||||
echo "$LINK_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
exit 0
|
||||
fi
|
||||
|
@ -10,23 +10,15 @@ ip4p=$3
|
||||
LINK_QB_WEB_URL=$(echo $LINK_QB_WEB_URL | sed 's/\/$//')
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "$LINK_ADVANCED_ENABLE" == 1 ] && [ -n "$LINK_ADVANCED_MAX_RETRIES" ] && [ -n "$LINK_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((LINK_ADVANCED_MAX_RETRIES == "0" ? 1 : LINK_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((LINK_ADVANCED_SLEEP_TIME == "0" ? 3 : LINK_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
max_retries=$6
|
||||
sleep_time=$7
|
||||
retry_count=0
|
||||
|
||||
# 初始化参数
|
||||
# 获取qbcookie,直至重试次数用尽
|
||||
qbcookie=""
|
||||
retry_count=0
|
||||
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
while (true); do
|
||||
# 获取qbcookie
|
||||
qbcookie=$(
|
||||
curl -Ssi -X POST \
|
||||
@ -36,27 +28,28 @@ for (( ; retry_count < max_retries; retry_count++)); do
|
||||
)
|
||||
|
||||
# 如果qbcookie为空,则重试
|
||||
if [ -z "$qbcookie" ]; then
|
||||
if [ -n "$qbcookie" ]; then
|
||||
# 修改端口
|
||||
response=$(curl -s -X POST \
|
||||
-b "$qbcookie" \
|
||||
-d 'json={"listen_port":"'$outter_port'"}' \
|
||||
"$LINK_QB_WEB_URL/api/v2/app/setPreferences" -w "%{http_code}")
|
||||
|
||||
if [ "$response" -eq 200 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录失败,正在重试..." >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录成功" >>/var/log/natmap/natmap.log
|
||||
# 修改端口
|
||||
curl -s -X POST \
|
||||
-b "$qbcookie" \
|
||||
-d 'json={"listen_port":"'$outter_port'"}' \
|
||||
"$LINK_QB_WEB_URL/api/v2/app/setPreferences"
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
exit 0
|
||||
fi
|
||||
|
@ -12,23 +12,15 @@ url="$LINK_TR_RPC_URL/transmission/rpc"
|
||||
trauth="-u $LINK_TR_USERNAME:$LINK_TR_PASSWORD"
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "$LINK_ADVANCED_ENABLE" == 1 ] && [ -n "$LINK_ADVANCED_MAX_RETRIES" ] && [ -n "$LINK_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((LINK_ADVANCED_MAX_RETRIES == "0" ? 1 : LINK_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((LINK_ADVANCED_SLEEP_TIME == "0" ? 3 : LINK_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
max_retries=$6
|
||||
sleep_time=$7
|
||||
retry_count=0
|
||||
|
||||
# 初始化参数
|
||||
# # 获取trsid,直至重试次数用尽
|
||||
trsid=""
|
||||
retry_count=0
|
||||
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
while (true); do
|
||||
trsid=$(curl -s $trauth $url | sed 's/.*<code>//g;s/<\/code>.*//g')
|
||||
|
||||
# Check if the provided session ID contains the header "X-Transmission-Session-Id"
|
||||
@ -43,28 +35,23 @@ for (( ; retry_count < max_retries; retry_count++)); do
|
||||
|
||||
# Check if the port modification was successful
|
||||
if [[ $(echo "$tr_result" | jq -r '.result') == "success" ]]; then
|
||||
echo "transmission port modified successfully" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
break
|
||||
else
|
||||
echo "transmission Failed to modify the port" >>/var/log/natmap/natmap.log
|
||||
# Sleep for a specified amount of time
|
||||
sleep $sleep_time
|
||||
fi
|
||||
else
|
||||
# Sleep for a specified amount of time
|
||||
sleep $sleep_time
|
||||
fi
|
||||
|
||||
# Sleep for a specified amount of time
|
||||
sleep $sleep_time
|
||||
done
|
||||
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 修改成功"
|
||||
exit 0
|
||||
fi
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 登录失败,正在重试..." >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $LINK_MODE 达到最大重试次数,无法修改"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -7,40 +7,58 @@ gotify_url="${NOTIFY_GOTIFY_URL}"
|
||||
priority="${NOTIFY_GOTIFY_PRIORITY:-5}"
|
||||
token="${NOTIFY_GOTIFY_TOKEN}"
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
# 获取最大重试次数和间隔时间
|
||||
# 默认重试次数为1,休眠时间为1s
|
||||
max_retries=$2
|
||||
sleep_time=$3
|
||||
retry_count=0
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "${NOTIFY_ADVANCED_ENABLE}" == 1 ] && [ -n "$NOTIFY_ADVANCED_MAX_RETRIES" ] && [ -n "$NOTIFY_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((NOTIFY_ADVANCED_MAX_RETRIES == "0" ? 1 : NOTIFY_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((NOTIFY_ADVANCED_SLEEP_TIME == "0" ? 3 : NOTIFY_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
# # # 判断是否开启高级功能
|
||||
# # if [ "${NOTIFY_ADVANCED_ENABLE}" == 1 ] && [ -n "$NOTIFY_ADVANCED_MAX_RETRIES" ] && [ -n "$NOTIFY_ADVANCED_SLEEP_TIME" ]; then
|
||||
# # # 获取最大重试次数
|
||||
# # max_retries=$((NOTIFY_ADVANCED_MAX_RETRIES == "0" ? 1 : NOTIFY_ADVANCED_MAX_RETRIES))
|
||||
# # # 获取休眠时间
|
||||
# # sleep_time=$((NOTIFY_ADVANCED_SLEEP_TIME == "0" ? 1 : NOTIFY_ADVANCED_SLEEP_TIME))
|
||||
# # fi
|
||||
|
||||
# # 判断是否开启高级功能
|
||||
# if [ "${NOTIFY_ADVANCED_ENABLE}" == 1 ]; then
|
||||
# # 获取最大重试次数
|
||||
# max_retries=$NOTIFY_ADVANCED_MAX_RETRIES
|
||||
# # 获取休眠时间
|
||||
# sleep_time=$NOTIFY_ADVANCED_SLEEP_TIME
|
||||
# fi
|
||||
|
||||
while (true); do
|
||||
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
# Send the message using curl
|
||||
curl -s -X POST -H "Content-Type: multipart/form-data" -F "token=$token" -F "title=$title" -F "message=$message" -F "priority=$priority" "$gotify_url/message"
|
||||
status=$?
|
||||
if [ $status -eq 0 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功"
|
||||
break
|
||||
else
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
echo "$NOTIFY_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功"
|
||||
exit 0
|
||||
fi
|
||||
# # Check if maximum retries reached
|
||||
# if [ $retry_count -eq $max_retries ]; then
|
||||
# echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
# echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
# exit 1
|
||||
# else
|
||||
# echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功" >>/var/log/natmap/natmap.log
|
||||
# echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功"
|
||||
# exit 0
|
||||
# fi
|
||||
|
@ -4,20 +4,13 @@ text="$1"
|
||||
title="natmap - ${GENERAL_NAT_NAME} 更新"
|
||||
token="${NOTIFY_PUSHPLUS_TOKEN}"
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
# 获取最大重试次数和间隔时间
|
||||
max_retries=$2
|
||||
sleep_time=$3
|
||||
retry_count=0
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "${NOTIFY_ADVANCED_ENABLE}" == 1 ] && [ -n "$NOTIFY_ADVANCED_MAX_RETRIES" ] && [ -n "$NOTIFY_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((NOTIFY_ADVANCED_MAX_RETRIES == "0" ? 1 : NOTIFY_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((NOTIFY_ADVANCED_SLEEP_TIME == "0" ? 3 : NOTIFY_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
while (true); do
|
||||
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
curl -4 -Ss -X POST \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"token": "'"${token}"'", "content": "'"${text}"'", "title": "'"${title}"'"}' \
|
||||
@ -25,20 +18,18 @@ for (( ; retry_count < max_retries; retry_count++)); do
|
||||
status=$?
|
||||
if [ $status -eq 0 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功"
|
||||
break
|
||||
else
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
echo "$NOTIFY_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功"
|
||||
exit 0
|
||||
fi
|
||||
|
@ -17,37 +17,29 @@ if [ "${NOTIFY_SERVERCHAN_ADVANCED_ENABLE}" == 1 ] && [ -n "$NOTIFY_SERVERCHAN_A
|
||||
else
|
||||
url="https://sctapi.ftqq.com/${NOTIFY_SERVERCHAN_SENDKEY}.send"
|
||||
fi
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
|
||||
# 获取最大重试次数和间隔时间
|
||||
max_retries=$2
|
||||
sleep_time=$3
|
||||
retry_count=0
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "${NOTIFY_ADVANCED_ENABLE}" == 1 ] && [ -n "$NOTIFY_ADVANCED_MAX_RETRIES" ] && [ -n "$NOTIFY_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((NOTIFY_ADVANCED_MAX_RETRIES == "0" ? 1 : NOTIFY_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((NOTIFY_ADVANCED_SLEEP_TIME == "0" ? 3 : NOTIFY_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
while (true); do
|
||||
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
result=$(curl -X POST -s -o /dev/null -w "%{http_code}" "$url" "${message[@]}")
|
||||
if [ $result -eq 200 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功"
|
||||
break
|
||||
else
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
echo "$NOTIFY_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 通知成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 通知成功"
|
||||
exit 0
|
||||
fi
|
||||
|
@ -13,28 +13,13 @@ function curl_proxy() {
|
||||
fi
|
||||
}
|
||||
|
||||
# 默认重试次数为1,休眠时间为3s
|
||||
max_retries=1
|
||||
sleep_time=3
|
||||
# 获取最大重试次数和间隔时间
|
||||
max_retries=$2
|
||||
sleep_time=$3
|
||||
retry_count=0
|
||||
|
||||
# 判断是否开启高级功能
|
||||
if [ "${NOTIFY_ADVANCED_ENABLE}" == 1 ] && [ -n "$NOTIFY_ADVANCED_MAX_RETRIES" ] && [ -n "$NOTIFY_ADVANCED_SLEEP_TIME" ]; then
|
||||
# 获取最大重试次数
|
||||
max_retries=$((NOTIFY_ADVANCED_MAX_RETRIES == "0" ? 1 : NOTIFY_ADVANCED_MAX_RETRIES))
|
||||
# 获取休眠时间
|
||||
sleep_time=$((NOTIFY_ADVANCED_SLEEP_TIME == "0" ? 3 : NOTIFY_ADVANCED_SLEEP_TIME))
|
||||
fi
|
||||
while (true); do
|
||||
|
||||
# # 判断是否开启高级功能
|
||||
# if [ "$NOTIFY_ADVANCED_ENABLE" == 1 ]; then
|
||||
# # 获取最大重试次数
|
||||
# max_retries="${NOTIFY_ADVANCED_MAX_RETRIES%/:-$max_retries}"
|
||||
# # 获取休眠时间
|
||||
# sleep_time="${NOTIFY_ADVANCED_SLEEP_TIME%/:-$sleep_time}"
|
||||
# fi
|
||||
|
||||
for (( ; retry_count < max_retries; retry_count++)); do
|
||||
curl_proxy -4 -Ss -o /dev/null -X POST \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"chat_id": "'"${chat_id}"'", "text": "'"${title}\n\n${text}"'", "parse_mode": "HTML", "disable_notification": "false"}' \
|
||||
@ -42,20 +27,18 @@ for (( ; retry_count < max_retries; retry_count++)); do
|
||||
status=$?
|
||||
if [ $status -eq 0 ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 发送成功"
|
||||
break
|
||||
else
|
||||
fi
|
||||
|
||||
# 检测剩余重试次数
|
||||
let retry_count++
|
||||
if [ $retry_count -lt $max_retries ] || [ $max_retries -eq 0 ]; then
|
||||
echo "$NOTIFY_MODE 登录失败,休眠$sleep_time秒" >>/var/log/natmap/natmap.log
|
||||
sleep $sleep_time
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if maximum retries reached
|
||||
if [ $retry_count -eq $max_retries ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 达到最大重试次数,无法通知"
|
||||
exit 1
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 通知成功" >>/var/log/natmap/natmap.log
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') : $GENERAL_NAT_NAME - $NOTIFY_MODE 通知成功"
|
||||
exit 0
|
||||
fi
|
||||
|
@ -796,7 +796,7 @@ add_firewall_rule() {
|
||||
|
||||
# 过滤所有节点IP
|
||||
filter_vpsip > /dev/null 2>&1 &
|
||||
filter_haproxy > /dev/null 2>&1 &
|
||||
# filter_haproxy > /dev/null 2>&1 &
|
||||
|
||||
accept_icmp=$(config_t_get global_forwarding accept_icmp 0)
|
||||
accept_icmpv6=$(config_t_get global_forwarding accept_icmpv6 0)
|
||||
|
@ -858,7 +858,7 @@ add_firewall_rule() {
|
||||
|
||||
# 过滤所有节点IP
|
||||
filter_vpsip > /dev/null 2>&1 &
|
||||
filter_haproxy > /dev/null 2>&1 &
|
||||
# filter_haproxy > /dev/null 2>&1 &
|
||||
# Prevent some conditions
|
||||
filter_vps_addr $(config_n_get $TCP_NODE address) $(config_n_get $UDP_NODE address) > /dev/null 2>&1 &
|
||||
|
||||
|
@ -21,13 +21,13 @@ define Download/geoip
|
||||
HASH:=944465ad5f3a3cccebf2930624f528cae3ca054f69295979cf4c4e002a575e90
|
||||
endef
|
||||
|
||||
GEOSITE_VER:=20240903080831
|
||||
GEOSITE_VER:=20240905081929
|
||||
GEOSITE_FILE:=dlc.dat.$(GEOSITE_VER)
|
||||
define Download/geosite
|
||||
URL:=https://github.com/v2fly/domain-list-community/releases/download/$(GEOSITE_VER)/
|
||||
URL_FILE:=dlc.dat
|
||||
FILE:=$(GEOSITE_FILE)
|
||||
HASH:=6a6a39a121a59efaf6bb7a3dd304266df0b4f8b470a84fc9614299f228ff4c2a
|
||||
HASH:=a5bcc1c67fade6d63a6b8f23b8ad952e9dae80ad208d8522f0b6d719cce24262
|
||||
endef
|
||||
|
||||
GEOSITE_IRAN_VER:=202409020032
|
||||
|
Loading…
Reference in New Issue
Block a user