From 7742454fea4690b8ed58863df9c20c6e21d59fa8 Mon Sep 17 00:00:00 2001 From: soxfor <7237915+soxfor@users.noreply.github.com> Date: Fri, 17 Mar 2023 00:11:22 +0000 Subject: [PATCH] update: add more checks and decrease NAT lease lifetime to equal default sleep time --- Dockerfile | 4 ++-- data/start.sh | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index c89d881..07b47b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/data/start.sh b/data/start.sh index 502373d..261829d 100755 --- a/data/start.sh +++ b/data/start.sh @@ -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