If you need help setting up the VPN on Synoloy, see Setting up the VPN
This is designed to grab the port and set the port in transmission. This could easily be adapted to work as a shell script as well.
This script does the following things:
- Fetch an auth token
- Acquire Port from PIA
- Renews port
- Updates transmission with the new port (and verifies the port is open)
It will honor the following TTLs:
- Auth tokens are used for 24hrs
- Ports last for 2 months (set at 58 days)
- The port should be renewed every 16 minutes (so it can be used on a task running every 15m)
- You must have python3 installed. There should be no extra modules required.
- You must already be connected to a PIA VPN Server that supports Port Forwarding
- Sometimes it might take a little after being connected for these calls to work.
- Setup your config file.
- Copy
cp config.json.sample config.json
- Update username and password in
config.json
- configure a Port Change Consumer (see below)
- Copy
- Run it
./ng-seed-port.py config.json
- Everything in the
config
variable will be written to thejson
file dynamically. You can add or remove params to this if you want to store them. - If you want more verbose output, change the log level in the script
The only necessary fields to generate the seed port are your PIA username and password. You also need to configure a Port Change Consumer if you want to do anything with the port after it's setup.
The script will populate evrything else it needs in the config file after the first run, so make sure the file is writeable.
{
"user": "pia_username",
"password": "pia_password"
}
All configured Port Change Consumers will get called when the port changes. They have their own sections in the json config used to enable them.
This will update transmission with the new port and verify it is open
{
"user": "pia_username",
"password": "pia_password",
"transmission": {
"remote": "/usr/local/transmission/bin/transmission-remote",
"username": "",
"password": "",
"port_test_delay": 5
}
}
remote
: The path to thetransmission-remote
command. The default shown is the path to it when installed via the synology package manager for meport_test_delay
: The delay (seconds) after updating the port before testing it. This is necessary to make sure transmission has had enough time to register the port
- Create a new class extending
PortChangeConsumer
with aconsume
function. - Update
def get_consumers() -> list:
with your config key
PIA - FOSS - Sample code of how to automate connecting via OpenVPN and Wireguard. This code was referenced heavily in this solution
PIA Server List - This is a JSON dump of al the regions with a server from each region. You can use this to find port forwarding servers.
PIA Connection Issues - If you are having issues, this might help