Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vpn-port-forwarding): add qbittorrent port update example #121

Merged
merged 8 commits into from
Jan 25, 2025

Conversation

Splinter7914
Copy link
Contributor

Adding a sample script that shows how to update listening port for qbittorrent. Script uses curl which its installing at run time. If it's possible to add curl to the base image that would be ideal. I can send a PR but was not sure if we are trying to minimize the size of the base image.

Also removed some verbiage around how filtering for proton vpn wireguard servers was not ideal. I saw conflicting statements in the readme where one section mentioned private key's were different and another said they were the same. From my usage I did not need to do a custom provider setup and just had to set the private key and the p2p filtering option. I could get it working with the following options.

VPN_SERVICE_PROVIDER=protonvpn
WIREGUARD_PRIVATE_KEY=xxxxx
SERVER_COUNTRIES=Netherlands,Switzerland
VPN_PORT_FORWARDING=on
PORT_FORWARD_ONLY=on
VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c "/tmp/qbit-port-updater.sh {{PORTS}}"

So i assumed those statements were no longer accurate?

@markleaf131313
Copy link

There's an example from the pull request that added the feature that uses wget so it doesn't need to be installed and can be done in one line from the environment without a script.

qdm12/gluetun#2399 (comment)

VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c '/usr/bin/wget -O- --retry-connrefused --post-data "json={\"listen_port\":{{PORTS}}}" http://127.0.0.1:${QBITTORRENT_UI_PORT}/api/v2/app/setPreferences 2>&1'

@Splinter7914
Copy link
Contributor Author

@markleaf131313 thanks for the heads up. I wish I had found that comment sooner :). I think adding this to readme will make it easier for consumers. Would you mind if I used this in my PR or would you like to submit one with this?

@markleaf131313
Copy link

You can use it, I was going to make a pull request until saw there already was one lol.

@Splinter7914
Copy link
Contributor Author

@markleaf131313 PR is updated and credited :).

@markleaf131313
Copy link

Oh you don't have to credit me, I just found the other thread. A couple of people posted variations of it addressing the problems, the one used was by @Marsu31 which addressed gluetun logging all output as errors.

@Splinter7914
Copy link
Contributor Author

ah fixed and credited @Marsu31 :).

@stephen304
Copy link

stephen304 commented Jan 15, 2025

This was really helpful in getting port forwarding to work with transmission, I ended up creating a small script since for transmission's RPC you need to get a session ID first. Hopefully this helps other people:

./set-transmission-port

#!/bin/sh

# Check if a port argument is provided
if [ -z "$1" ]; then
  echo "Usage: $0 <port>"
  exit 1
fi

# The port to set
PORT=$1

# Get the session ID
SESSION_ID=$(wget -S --spider http://127.0.0.1:9091/transmission/rpc 2>&1 | grep "X-Transmission-Session-Id:" | awk '{print $NF}')

if [ -z "$SESSION_ID" ]; then
  echo "Error: Could not retrieve session ID"
  exit 1
fi

# Set the peer-port using the session ID
wget -O- --retry-connrefused \
    --header="X-Transmission-Session-Id: $SESSION_ID" \
    --header="Content-Type: application/json" \
    --post-data='{"method":"session-set","arguments":{"peer-port":'$PORT'}}' \
     http://127.0.0.1:9091/transmission/rpc

echo "Port set to $PORT"

(Don't forget to chmod +x the script)

    volumes:
      - ./set-transmission-port:/usr/bin/set-transmission-port
    environment:
      - VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c "set-transmission-port {{PORTS}}"

It needs some changes if you want to have the transmission host as a parameter and if you use a username/password for RPC, but hopefully it's a good starting point. It might also help to increase retries or script in a delay between retries in case gluetun comes up before transmission has fully started, but in my tests it seemed reliable enough for me.

qdm12
qdm12 previously approved these changes Jan 25, 2025
Copy link
Owner

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 💯 !!

@qdm12
Copy link
Owner

qdm12 commented Jan 25, 2025

@stephen304 see qdm12/gluetun#2611 (feel free to comment on that PR if you feel there is something missing). Scripts are welcomed (built-in the docker image), although small single line commands like this one is better if possible 😉

@qdm12 qdm12 changed the title add example for proton vpn port forwarding setup feat(vpn-port-forwarding): add qbittorrent port update example Jan 25, 2025
@qdm12 qdm12 merged commit e853508 into qdm12:main Jan 25, 2025
1 check passed
@ashleyconnor
Copy link

Thanks @stephen304, the transmission equivalent is very tedious. Why they require a CSRF token for a JSON API call I'll never know...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants