2
0
Fork 0

update: add more checks and decrease NAT lease lifetime to equal default sleep time

This commit is contained in:
soxfor 2023-03-17 00:11:22 +00:00
parent 9f543c92d5
commit 7742454fea
2 changed files with 22 additions and 8 deletions

View File

@ -6,7 +6,7 @@ LABEL description="Map NAT-PMP/UPnP port and update qBittorrent configuration"
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install --no-install-suggests --no-install-recommends -y natpmpc curl
RUN apt install --no-install-suggests --no-install-recommends -y natpmpc curl bc
RUN rm -rf /var/lib/apt/lists/* /var/cache/apt/*
RUN apt clean
@ -16,7 +16,7 @@ ENV QBITTORRENT_USER='admin'
ENV QBITTORRENT_PASS='adminadmin'
ENV VPN_GATEWAY=''
ENV CHECK_INTERVAL='300'
ENV NAT_LEASE_LIFETIME='3600'
ENV NAT_LEASE_LIFETIME='300'
COPY data/start.sh /start.sh
RUN chmod 750 /start.sh

View File

@ -25,14 +25,20 @@ qbt_changeport(){
return $?
}
public_ip=''
qbt_sid=''
configured_port=''
public_ip=$(getpublicip)
qbt_sid=$(qbt_login)
configured_port=$(findconfiguredport ${qbt_sid})
active_port=''
check() {
get_portmap() {
res=0
public_ip=$(getpublicip)
qbt_sid=$(qbt_login)
if echo $(curl -s --header "Referer: http://${QBITTORRENT_SERVER}:${QBITTORRENT_PORT}" --cookie "${qbt_sid}" http://${QBITTORRENT_SERVER}:${QBITTORRENT_PORT}/api/v2/app/version) | grep -qi forbidden; then
echo "$(timestamp) | qBittorrent Cookie invalid, getting new SessionID"
qbt_sid=$(qbt_login)
fi
configured_port=$(findconfiguredport ${qbt_sid})
active_port=$(findactiveport)
@ -46,15 +52,23 @@ check() {
echo "$(timestamp) | Port Changed to: $(findconfiguredport ${qbt_sid})"
else
echo "$(timestamp) | Port Change failed."
res=1
fi
else
echo "$(timestamp) | Port OK (Act: ${active_port} Cfg: ${configured_port})"
fi
return $res
}
while true;
do
check
if get_portmap; then
echo "$(timestamp) | NAT-PMP/UPnP Ok!"
else
echo "$(timestamp) | NAT-PMP/UPnP Failed"
fi
echo "$(timestamp) | Sleeping for $(echo ${CHECK_INTERVAL}/60 | bc) minutes"
sleep ${CHECK_INTERVAL}
done