├── version ├── Dockerfile ├── Makefile ├── docker-compose.yml ├── start.sh ├── README.md └── LICENSE /version: -------------------------------------------------------------------------------- 1 | 1.3 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | RUN apk update 4 | RUN apk add --no-cache curl inotify-tools bash 5 | 6 | ENV QBITTORRENT_SERVER=localhost 7 | ENV QBITTORRENT_PORT=8080 8 | ENV QBITTORRENT_USER=admin 9 | ENV QBITTORRENT_PASS=adminadmin 10 | ENV PORT_FORWARDED=tmp/gluetun/forwarded_port 11 | ENV HTTP_S=http 12 | 13 | COPY ./start.sh ./start.sh 14 | RUN chmod 770 ./start.sh 15 | 16 | CMD ["./start.sh"] 17 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME = snoringdragon/luetun-qbittorrent-port-manager 2 | VERSION = `cat version` 3 | 4 | build: Dockerfile start.sh 5 | docker buildx build --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le -t $(NAME):$(VERSION) -t $(NAME):latest --label "version=$(VERSION)" --load . 6 | 7 | push: Dockerfile start.sh version .secret 8 | cat .secret | docker login -u snoringdragon --password-stdin 9 | docker buildx build --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le -t $(NAME):$(VERSION) -t $(NAME):latest --label "version=$(VERSION)" --push . 10 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | gluetun-qbittorrent-port-manager: 2 | image: snoringdragon/gluetun-qbittorrent-port-manager:latest 3 | restart: unless-stopped 4 | volumes: 5 | - /yourfolder:/tmp/gluetun #Set "yourfolder" to the same directory you used for Gluetun 6 | network_mode: "service: gluetun" 7 | environment: 8 | QBITTORRENT_SERVER: localhost # IP Address of qbittorrent 9 | QBITTORRENT_PORT: 8080 10 | QBITTORRENT_USER: admin # username 11 | QBITTORRENT_PASS: adminadmin # password 12 | PORT_FORWARDED: /tmp/gluetun/forwarded_port 13 | HTTP_S: http # Select 'http' or 'https' depending on if you use certificates. 14 | -------------------------------------------------------------------------------- /start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | COOKIES="/tmp/cookies.txt" 4 | 5 | update_port () { 6 | PORT=$(cat $PORT_FORWARDED) 7 | rm -f $COOKIES 8 | curl -s -c $COOKIES --data "username=$QBITTORRENT_USER&password=$QBITTORRENT_PASS" ${HTTP_S}://${QBITTORRENT_SERVER}:${QBITTORRENT_PORT}/api/v2/auth/login > /dev/null 9 | curl -s -b $COOKIES --data 'json={"listen_port": "'"$PORT"'"}' ${HTTP_S}://${QBITTORRENT_SERVER}:${QBITTORRENT_PORT}/api/v2/app/setPreferences > /dev/null 10 | rm -f $COOKIES 11 | echo "Successfully updated qbittorrent to port $PORT" 12 | } 13 | 14 | while true; do 15 | if [ -f $PORT_FORWARDED ]; then 16 | update_port 17 | inotifywait -mq -e close_write $PORT_FORWARDED | while read change; do 18 | update_port 19 | done 20 | else 21 | echo "Couldn't find file $PORT_FORWARDED" 22 | echo "Trying again in 10 seconds" 23 | sleep 10 24 | fi 25 | done 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gluetun-qbittorrent Port Manager 2 | Automatically updates the listening port for qbittorrent to the port forwarded by [Gluetun](https://github.com/qdm12/gluetun/). 3 | 4 | ## Description 5 | [Gluetun](https://github.com/qdm12/gluetun/) has the ability to forward ports for supported VPN providers, 6 | but qbittorrent does not have the ability to update its listening port dynamically. 7 | Because of this, I wrote this short script available as a docker container which automatically detects changes to the 8 | forwarded_port file created by [Gluetun](https://github.com/qdm12/gluetun/) and updates the qbittorrent's listening port. 9 | 10 | ## Setup 11 | First, ensure you are able to successfully connect qbittorrent to the forwarded port manually (can be seen by a green globe at the bottom of the WebUI). 12 | 13 | Then add a mounted volume to [Gluetun](https://github.com/qdm12/gluetun/) (e.g. /yourfolder:/tmp/gluetun). 14 | 15 | Finally, insert the template in `docker-compose.yml` into your docker-compose containing gluetun, substituting the default values for your own. 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 SnoringDragon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------