🌴 Sync 2026-03-05 23:51:42

This commit is contained in:
github-actions[bot] committed 2026-03-05 23:51:42 +08:00
1 parent 97c049ed0a
commit 0acff03804
14253 files changed
+3893239

No files matched your search

+1
View File
@@ -0,0 +1 @@
bin/
+57
View File
@@ -0,0 +1,57 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=natmap
PKG_VERSION:=20260214
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://github.com/heiher/natmap/releases/download/$(PKG_VERSION)
PKG_HASH:=skip
PKG_MAINTAINER:=Richard Yu <yurichard3839@gmail.com>
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=License
PKG_BUILD_FLAGS:=no-mips16
PKG_BUILD_PARALLEL:=1
include $(INCLUDE_DIR)/package.mk
define Package/natmap
SECTION:=net
CATEGORY:=Network
TITLE:=TCP/UDP port mapping tool for full cone NAT
URL:=https://github.com/heiher/natmap
DEPENDS:=+jq +curl
endef
MAKE_FLAGS += REV_ID="$(PKG_VERSION)"
define Package/natmap/conffiles
/etc/config/natmap
endef
define Package/natmap/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/natmap $(1)/usr/bin/
$(INSTALL_DIR) $(1)/usr/lib/natmap/
$(INSTALL_BIN) ./files/natmap-update.sh $(1)/usr/lib/natmap/update.sh
$(INSTALL_BIN) ./files/natmap-notify.sh $(1)/usr/lib/natmap/notify.sh
$(INSTALL_BIN) ./files/natmap-forward.sh $(1)/usr/lib/natmap/forward.sh
$(INSTALL_DIR) $(1)/usr/lib/natmap/plugin-notify
$(INSTALL_BIN) ./files/telegram_bot.sh $(1)/usr/lib/natmap/plugin-notify
$(INSTALL_BIN) ./files/pushplus.sh $(1)/usr/lib/natmap/plugin-notify
$(INSTALL_DIR) $(1)/usr/lib/natmap/plugin
$(INSTALL_BIN) ./files/qb.sh $(1)/usr/lib/natmap/plugin
$(INSTALL_BIN) ./files/tr.sh $(1)/usr/lib/natmap/plugin
$(INSTALL_BIN) ./files/emby.sh $(1)/usr/lib/natmap/plugin
$(INSTALL_BIN) ./files/cloudflare_origin_rule.sh $(1)/usr/lib/natmap/plugin
$(INSTALL_BIN) ./files/cloudflare_redirect_rule.sh $(1)/usr/lib/natmap/plugin
$(INSTALL_BIN) ./files/proxy_port.sh $(1)/usr/lib/natmap/plugin
$(INSTALL_DIR) $(1)/etc/config/
$(INSTALL_CONF) ./files/natmap.config $(1)/etc/config/natmap
$(INSTALL_DIR) $(1)/etc/init.d/
$(INSTALL_BIN) ./files/natmap.init $(1)/etc/init.d/natmap
endef
$(eval $(call BuildPackage,natmap))
+63
View File
@@ -0,0 +1,63 @@
### 新功能
1. 内置两种消息通知方式,Telegram Bot 和 PushPlus,可以为任何每一个打洞单独配置, PushPlus 支持推送到微信且不需要翻墙
2. 内置多种配置模式,常用功能无需写脚本就能使用,详见内置模式
### 内置模式
#### qBittorrent
打洞成功后,自动修改 qBittorrent 的端口号,并配置转发(可选)
需要配置 qBittorrent 地址、账号、密码用于修改端口
需要配置 qBittorrent 使用网卡的 IP 用于配置转发,端口填 0,会转发到修改后的端口
#### Transmission
打洞成功后,自动修改 Transmission 的端口号,并配置转发(可选)
需要配置 Transmission 地址、账号、密码用于修改端口
需要配置 Transmission 使用网卡的 IP 用于配置转发,端口填 0,会转发到修改后的端口
#### Emby
配合 Emby Connect 使用时,用户登录账号后,会从服务器获取最新的连接地址信息,此模式就是用于配置这些信息的
需要配置 Emby 地址和 API Key 用于修改连接地址信息
此模式必须配置转发
默认不更新「外部域」,如果有配置 DDNS,将 DDNS 域名填入外部域后将不需要再次修改
若没有域名,需要将 IP 填入外部域,可以勾选 「Update host with IP」
若对外提供的是 HTTPS 服务,需要勾选 「Update HTTPS Port」
#### Cloudflare Origin Rules
Cloudflare Origin Rules 可以设置回源端口,配合 DDNS 使用时,可以将 DDNS 域名指向 Cloudflare,然后将回源端口设置为打洞后的端口,这样就可以通过 Cloudflare 的 CDN 加速访问了
需要配置 Cloudflare 的 API Key,邮箱 和 Zone ID,Zone ID 可以在 Cloudflare 的域名首页找到
API Key 请访问 https://dash.cloudflare.com/profile/api-tokens 复制 Global API Key
需要先在 Cloudflare 后台的 Rules - Origin Rules 下添加一个 Origin Rules,然后将 Origin Rules 的 Name 填入配置中
Name 请保持唯一,否则会出现奇怪的问题
### 使用
添加软件源
```
sh -c "$(curl https://fastly.jsdelivr.net/gh/EkkoG/openwrt-dist@master/add-feed.sh)" -- packages
```
更新软件源并安装
```
opkg update
opkg install natmap
```
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
cp feeds.conf.default feeds.conf
echo "src-link local_build $(pwd)/local-build" >> ./feeds.conf
./scripts/feeds update -a
make defconfig
./scripts/feeds install -p local_build -f natmap
make package/natmap/compile V=s
+10
View File
@@ -0,0 +1,10 @@
services:
sdk:
image: openwrt/sdk:x86-64
volumes:
- .:/builder/local-build/natmap
- ./bin:/builder/bin
- ./build.sh:/builder/build.sh
- ./key-build:/builder/key-build
command: /builder/build.sh
+31
View File
@@ -0,0 +1,31 @@
#!/bin/sh
# NATMap
outter_ip=$1
outter_port=$2
get_current_rule() {
curl --retry 10 --request GET \
--url https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/rulesets/phases/http_request_origin/entrypoint \
--header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
--header 'Content-Type: application/json'
}
currrent_rule=$(get_current_rule)
CLOUDFLARE_RULE_NAME="\"$CLOUDFLARE_RULE_NAME\""
new_rule=$(echo "$currrent_rule" | jq '.result.rules| to_entries | map(select(.value.description == '"$CLOUDFLARE_RULE_NAME"')) | .[].key')
new_rule=$(echo "$currrent_rule" | jq '.result.rules['"$new_rule"'].action_parameters.origin.port = '"$outter_port"'')
CLOUDFLARE_RULESET_ID=$(echo "$currrent_rule" | jq '.result.id' | sed 's/"//g')
body=$(echo "$new_rule" | jq '.result')
# delete last_updated
body=$(echo "$body" | jq 'del(.last_updated)')
curl --retry 10 --request PUT \
--url https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/rulesets/$CLOUDFLARE_RULESET_ID \
--header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
--header 'Content-Type: application/json' \
--data "$body"
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
# NATMap
outter_ip=$1
outter_port=$2
get_current_rule() {
curl --retry 10 --request GET \
--url https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/rulesets/phases/http_request_dynamic_redirect/entrypoint \
--header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
--header 'Content-Type: application/json'
}
currrent_rule=$(get_current_rule)
CLOUDFLARE_RULE_NAME="\"$CLOUDFLARE_RULE_NAME\""
# replace NEW_PORT with outter_port
CLOUDFLARE_RULE_TARGET_URL=$(echo $CLOUDFLARE_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_RULE_NAME"')) | .[].key')
new_rule=$(echo "$currrent_rule" | jq '.result.rules['"$new_rule"'].action_parameters.from_value.target_url.value = "'"$CLOUDFLARE_RULE_TARGET_URL"'"')
CLOUDFLARE_RULESET_ID=$(echo "$currrent_rule" | jq '.result.id' | sed 's/"//g')
body=$(echo "$new_rule" | jq '.result')
# delete last_updated
body=$(echo "$body" | jq 'del(.last_updated)')
curl --retry 10 --request PUT \
--url https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/rulesets/$CLOUDFLARE_RULESET_ID \
--header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
--header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
--header 'Content-Type: application/json' \
--data "$body"
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
# NATMap
outter_ip=$1
outter_port=$2
current_cfg=$(curl --retry 10 -v $EMBY_URL/emby/System/Configuration?api_key=$EMBY_API_KEY)
new_cfg=$current_cfg
if [ ! -z $EMBY_USE_HTTPS ] && [ $EMBY_USE_HTTPS = '1' ]; then
new_cfg=$(echo $current_cfg | jq ".PublicHttpsPort = $outter_port")
else
new_cfg=$(echo $current_cfg | jq ".PublicPort = $outter_port")
fi
if [ ! -z $EMBY_UPDATE_HOST_WITH_IP ] && [ $EMBY_UPDATE_HOST_WITH_IP = '1' ]; then
new_cfg=$(echo $new_cfg | jq ".WanDdns = \"$outter_ip\"")
fi
curl --retry 10 -X POST "$EMBY_URL/emby/System/Configuration?api_key=$EMBY_API_KEY" -H "accept: */*" -H "Content-Type: application/json" -d "$new_cfg"
+38
View File
@@ -0,0 +1,38 @@
#!/bin/sh
# NATMap
outter_ip=$1
outter_port=$2
ip4p=$3
inner_port=$4
protocol=$5
if [ ! -z $FORWARD_USE_NATMAP ] && [ $FORWARD_USE_NATMAP = '1' ]; then
exit 0
fi
if [ -z "$FORWARD_PORT" ]; then
exit 0
fi
if [ -z "$FORWARD_TARGET" ]; then
exit 0
fi
rule_name=$(echo "${NAT_NAME}_v4" | sed 's/[^a-zA-Z0-9]/_/g' | awk '{print tolower($0)}')
final_forward_port=$FORWARD_PORT
if [ $final_forward_port = 0 ]; then
final_forward_port=$outter_port
fi
# ipv4 redirect
uci set firewall.$rule_name=redirect
uci set firewall.$rule_name.name="$NAT_NAME"
uci set firewall.$rule_name.proto=$protocol
uci set firewall.$rule_name.src='wan'
uci set firewall.$rule_name.dest='lan'
uci set firewall.$rule_name.target='DNAT'
uci set firewall.$rule_name.src_dport="${inner_port}"
uci set firewall.$rule_name.dest_ip="${FORWARD_TARGET}"
uci set firewall.$rule_name.dest_port="${final_forward_port}"
# reload
uci commit firewall
/etc/init.d/firewall reload
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
# NATMap
outter_ip=$1
outter_port=$2
ip4p=$3
inner_port=$4
protocol=$(echo $5 | tr 'a-z' 'A-Z')
if [ $IM_NOTIFY_ENABLE != 1 ]; then
exit 0
fi
msg="$NAT_NAME\nNew $protocol port mapping: $inner_port -> $outter_ip:$outter_port\nIP4P: $ip4p"
if [ ! -z "$MSG_OVERRIDE" ]; then
msg="$MSG_OVERRIDE"
fi
if [ -f "/usr/lib/natmap/plugin-notify/$IM_NOTIFY_CHANNEL.sh" ]; then
source "/usr/lib/natmap/plugin-notify/$IM_NOTIFY_CHANNEL.sh" "$msg"
fi
+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
(
json_init
json_add_string ip "$1"
json_add_int port "$2"
json_add_int inner_port "$4"
json_add_string protocol "$5"
json_add_string name "$NAT_NAME"
json_dump > /var/run/natmap/$PPID.json
)
[ -n "${NOTIFY_SCRIPT}" ] && {
export -n NOTIFY_SCRIPT
source "${NOTIFY_SCRIPT}" "$@"
}
if [ ! -z $INTERNAL_DEFINE_SCRIPT ]; then
echo "$NAT_NAME Excute internal define script: $INTERNAL_DEFINE_SCRIPT"
$INTERNAL_DEFINE_SCRIPT "$@"
fi
source /usr/lib/natmap/forward.sh "$@"
source /usr/lib/natmap/notify.sh "$@"
+48
View File
@@ -0,0 +1,48 @@
config natmap
option enable '0'
option family ''
option mode 'general'
option nat_name ''
option udp_mode '1'
option interface ''
option interval ''
option stun_server 'stunserver.stunprotocol.org'
option http_server 'example.com'
option port '8080'
option forward_target ''
option forward_port ''
option notify_script ''
option im_notify_enable '0'
option forward_use_natmap '0'
option im_notify_channel 'telegram_bot'
option im_notify_channel_telegram_bot_chat_id 'chat_id'
option im_notify_channel_telegram_bot_token 'token'
option im_notify_channel_pushplus_token 'token'
option emby_url ''
option emby_api_key ''
option emby_use_https '0'
option emby_update_host_with_ip '0'
option qb_web_ui_url ''
option qb_username ''
option qb_password ''
option qb_ipv6_address '::/-64'
option qb_allow_ipv6 '1'
option tr_rpc_url ''
option tr_username ''
option tr_password ''
option tr_ipv6_address '::/-64'
option tr_allow_ipv6 '1'
option cloudflare_email ''
option cloudflare_api_key ''
option cloudflare_zone_id ''
option cloudflare_rule_name ''
option proxy ''
option proxy_port_content_url
option proxy_port_gist_id
option proxy_port_gist_filename
option proxy_port_github_token
+166
View File
@@ -0,0 +1,166 @@
#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
NAME=natmap
PROG=/usr/bin/$NAME
STATUS_PATH=/var/run/natmap
load_interfaces() {
config_get interface "$1" interface
config_get enable "$1" enable 1
[ "${enable}" = "1" ] && interfaces=" ${interface} ${interfaces}"
}
validate_section_natmap() {
uci_load_validate "${NAME}" natmap "$1" "$2" \
'enable:bool:0' \
'family:string' \
'mode:string:general' \
'udp_mode:bool:0' \
'interface:string' \
'nat_name:string' \
'interval:uinteger' \
'stun_server:host' \
'http_server:host' \
'port:port' \
'forward_target:host' \
'forward_port:port' \
'notify_script:file' \
'forward_use_natmap:bool:0' \
'im_notify_enable:bool:0' \
'im_notify_channel:string' \
'im_notify_channel_telegram_bot_chat_id:string' \
'im_notify_channel_telegram_bot_token:string' \
'im_notify_channel_pushplus_token:string' \
'emby_url:string' \
'emby_api_key:string' \
'emby_use_https:bool:0' \
'emby_update_host_with_ip:bool:0' \
'qb_web_ui_url:string' \
'qb_username:string' \
'qb_password:string' \
'qb_ipv6_address:string' \
'qb_allow_ipv6:bool:0' \
'tr_rpc_url:string' \
'tr_username:string' \
'tr_password:string' \
'tr_allow_ipv6:bool:0' \
'tr_ipv6_address:string' \
'cloudflare_email:string' \
'cloudflare_api_key:string' \
'cloudflare_zone_id:string' \
'cloudflare_rule_target_url:string' \
'cloudflare_rule_name:string' \
'proxy_port_content_url:string' \
'proxy_port_gist_id:string' \
'proxy_port_gist_filename:string' \
'proxy_port_github_token:string' \
'proxy:string'
}
natmap_instance() {
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
[ "${enable}" = 0 ] && return 1
procd_open_instance "$1"
procd_set_param command "$PROG" \
${interval:+-k "$interval"} \
${stun_server:+-s "$stun_server"} \
${http_server:+-h "$http_server"} \
${port:+-b "$port"} \
[ "${family}" = ipv4 ] && procd_append_param command -4
[ "${family}" = ipv6 ] && procd_append_param command -6
[ "${udp_mode}" = 1 ] && procd_append_param command -u
[ -n "${interface}" ] && {
local ifname
network_get_device ifname "$interface" || ifname="$interface"
procd_append_param command -i "$ifname"
procd_append_param netdev "$ifname"
}
[ -n "${forward_target}" ] && [ $forward_use_natmap == "1" ] && procd_append_param command -t "$forward_target" -p "$forward_port"
for e in $EXTRA_ENV; do
eval value=\$${e}
option_name=$(echo "$e" | tr 'a-z' 'A-Z')
if [ -n "$value" ]; then
procd_append_param env $option_name="$value"
fi
done
[ $mode == 'qbittorrent' ] && procd_append_param env INTERNAL_DEFINE_SCRIPT=/usr/lib/natmap/plugin/qb.sh
[ $mode == 'transmission' ] && procd_append_param env INTERNAL_DEFINE_SCRIPT=/usr/lib/natmap/plugin/tr.sh
[ $mode == 'emby' ] && procd_append_param env INTERNAL_DEFINE_SCRIPT=/usr/lib/natmap/plugin/emby.sh
[ $mode == 'cloudflare_origin_rule' ] && procd_append_param env INTERNAL_DEFINE_SCRIPT=/usr/lib/natmap/plugin/cloudflare_origin_rule.sh
[ $mode == 'cloudflare_redirect_rule' ] && procd_append_param env INTERNAL_DEFINE_SCRIPT=/usr/lib/natmap/plugin/cloudflare_redirect_rule.sh
[ $mode == 'proxy_port' ] && procd_append_param env INTERNAL_DEFINE_SCRIPT=/usr/lib/natmap/plugin/proxy_port.sh
procd_append_param command -e /usr/lib/natmap/update.sh
procd_set_param respawn
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
clear_status_files() {
find "${STATUS_PATH}" -type f -print0 | xargs -0 rm -f --
}
service_triggers() {
local interfaces
procd_add_reload_trigger "${NAME}"
config_load "${NAME}"
config_foreach load_interfaces natmap
[ -n "${interfaces}" ] && {
for n in $interfaces ; do
procd_add_reload_interface_trigger $n
done
}
procd_add_validation validate_section_natmap
}
start_service() {
. /lib/functions/network.sh
config_cb() {
[ $# -eq 0 ] && return
option_cb() {
local option="$1"
EXTRA_ENV="$EXTRA_ENV $option"
}
list_cb() {
local name="$1"
EXTRA_ENV="$EXTRA_ENV $name"
}
}
mkdir -p "${STATUS_PATH}"
clear_status_files
config_load "${NAME}"
config_foreach validate_section_natmap natmap natmap_instance
}
reload_service() {
stop
start
}
service_stopped() {
clear_status_files
}
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
outter_port=$2
echo "PROXY_PORT_CONTENT_URL $PROXY_PORT_CONTENT_URL"
content=$(curl --retry 10 -s -L $PROXY_PORT_CONTENT_URL)
if [ -z "$content" ]; then
echo "Failed to get gist content"
exit 1
fi
# replace port, placeholder is OUTTER_PORT
content=$(echo "$content" | sed "s/OUTTER_PORT/$outter_port/g")
#replace newline to \n
content=$(echo "$content" | awk '{printf "%s\\n", $0}')
content=$(echo "$content" | sed 's/"/\\"/g')
body="{\"files\": {\"$PROXY_PORT_GIST_FILENAME\": {\"content\": \"$content\"}}}"
# update gist content
url="https://api.github.com/gists/$PROXY_PORT_GIST_ID"
curl --retry 10 -X PATCH \
-H "Authorization: token $PROXY_PORT_GITHUB_TOKEN" \
-d "$body" \
$url >/dev/null
if [ $? -eq 0 ]; then
echo "Update gist success"
else
echo "Update gist failed"
exit 1
fi
+16
View File
@@ -0,0 +1,16 @@
#!/bin/sh
text="$1"
token=$2
curl --retry 10 -4 -Ss -X POST \
-H 'Content-Type: application/json' \
-d '{"token": "'"${IM_NOTIFY_CHANNEL_PUSHPLUS_TOKEN}"'", "content": "'"${text}"'", "title": "NATMap"}' \
"http://www.pushplus.plus/send"
if [ $? -eq 0 ]; then
echo "Send pushplus success"
else
echo "Send pushplus failed"
exit 1
fi
+49
View File
@@ -0,0 +1,49 @@
#!/bin/sh
# NATMap
protocol=$5
inner_port=$4
outter_ip=$1
outter_port=$2
ip4p=$3
rule_name=$(echo "${NAT_NAME}_v6_allow" | sed 's/[^a-zA-Z0-9]/_/g' | awk '{print tolower($0)}')
QB_WEB_UI_URL=$(echo $QB_WEB_UI_URL | sed 's/\/$//')
# update port
qbcookie=$(\
curl --retry 10 -Ssi -X POST \
-d "username=${QB_USERNAME}&password=${QB_PASSWORD}" \
"$QB_WEB_UI_URL/api/v2/auth/login" | \
sed -n 's/.*\(SID=.\{32\}\);.*/\1/p' )
echo "qbcookie: $qbcookie"
echo "outter_port: $outter_port"
curl --retry 10 -X POST \
-b "${qbcookie}" \
-d 'json={"listen_port":"'${outter_port}'"}' \
"$QB_WEB_UI_URL/api/v2/app/setPreferences"
# qb_allow_ipv6
if [ $QB_ALLOW_IPV6 = 1 ]; then
echo "rule_name: $rule_name"
# ipv6 allow
uci set firewall.$rule_name=rule
uci set firewall.$rule_name.name='Allow-qBittorrent-IPv6'
uci set firewall.$rule_name.src='wan'
uci set firewall.$rule_name.dest='lan'
uci set firewall.$rule_name.target='ACCEPT'
uci set firewall.$rule_name.proto='tcp udp'
# uci get firewall.$rule_name.dest_ip
# check if dest_ip is already set with return code
if uci get firewall.$rule_name.dest_ip >/dev/null 2>&1; then
uci del firewall.$rule_name.dest_ip
fi
for ip in $QB_IPV6_ADDRESS; do
uci add_list firewall.$rule_name.dest_ip="${ip}"
done
uci set firewall.$rule_name.family='ipv6'
uci set firewall.$rule_name.dest_port="${outter_port}"
# reload
uci commit firewall
/etc/init.d/firewall reload
fi
+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
text="$1"
id=$2
chat_id=$3
token=$4
function curl_proxy() {
if [ -z "$PROXY" ]; then
curl --retry 10 "$@"
else
curl --retry 10 -x $PROXY "$@"
fi
}
curl_proxy -4 -Ss -o /dev/null -X POST \
-H 'Content-Type: application/json' \
-d '{"chat_id": "'"${IM_NOTIFY_CHANNEL_TELEGRAM_BOT_CHAT_ID}"'", "text": "'"${text}"'", "parse_mode": "HTML", "disable_notification": "false"}' \
"https://api.telegram.org/bot${IM_NOTIFY_CHANNEL_TELEGRAM_BOT_TOKEN}/sendMessage"
if [ $? -eq 0 ]; then
echo "Send telegram bot success"
else
echo "Send telegram bot failed"
exit 1
fi
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
# NATMap
outter_ip=$1
outter_port=$2
ip4p=$3
inner_port=$4
protocol=$5
env
TR_RPC_URL=$(echo $TR_RPC_URL | sed 's/\/$//')
# update port
trauth="-u $TR_USERNAME:$TR_PASSWORD"
trsid=$(curl --retry 10 -s $trauth $TR_RPC_URL/transmission/rpc | sed 's/.*<code>//g;s/<\/code>.*//g')
curl --retry 10 -X POST \
-H "${trsid}" $trauth \
-d '{"method":"session-set","arguments":{"peer-port":'${outter_port}'}}' \
"$TR_RPC_URL/transmission/rpc"
if [ $TR_ALLOW_IPV6 = 1 ]; then
rule_name=$(echo "${NAT_NAME}_v6_allow" | sed 's/[^a-zA-Z0-9]/_/g' | awk '{print tolower($0)}')
# ipv6 allow
uci set firewall.$rule_name=rule
uci set firewall.$rule_name.name='Allow-Transmission-IPv6'
uci set firewall.$rule_name.src='wan'
uci set firewall.$rule_name.dest='lan'
uci set firewall.$rule_name.target='ACCEPT'
uci set firewall.$rule_name.proto='tcp udp'
if uci get firewall.$rule_name.dest_ip >/dev/null 2>&1; then
uci del firewall.$rule_name.dest_ip
fi
for ip in $TR_IPV6_ADDRESS; do
uci add_list firewall.$rule_name.dest_ip="${ip}"
done
uci set firewall.$rule_name.family='ipv6'
uci set firewall.$rule_name.dest_port="${outter_port}"
# reload
uci commit firewall
/etc/init.d/firewall reload
fi
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
"$1" 2>&1 | grep "$2"