[quote="jleiss"]
I'm assuming you have found what you needed otherwise you would have followed up by now, but I thought I would add what I got working here in case anyone else needed it. This is what I use on Ubuntu 16.04
Code: Select all
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
# Private Internet Access Advanced Port Forward Script for pfSense
# v1.0 (21st January 2014)
# Pre-requisites for this script:
# pfSense v2.1 (Port forward NAT return destination broken in earlier versions)
# curl - pkg_add -r curl
# xmlstarlet - pkg_add -r xmlstarlet
# Add your PIA username and password
USERNAME="user"
PASSWORD="password"
PIACLIENTID=/home/jleiss/.pia_client_id
# Check to see if we have a valid PIA Client ID file.
# If not, create one. Linux is included for illustration only.
if [ ! -e $PIACLIENTID ]; then
# OSX/FreeBSD (pfSense)
#head -n 100 /dev/urandom | md5 > $PIACLIENTID
# Linux
head -n 100 /dev/urandom | md5sum | tr -d " -" > $PIACLIENTID
logger "pia-port: Created new PIA Client ID."
fi
# Find out the tunnelling device for your VPN and get your IP address.
# There are several options presented here. Personally, I prefer to use
# the interface which I know relates to my VPN tunnel for forwarding.
DEVICE=`ifconfig | grep -o "tun[0-9]"`
LOCAL_IP=`ifconfig $DEVICE | grep -Po "(?<=addr.)[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"`
# Get the port number for the forwarded port
PORT=`curl -d "user=$USERNAME&pass=$PASSWORD&client_id=$(cat $PIACLIENTID)&local_ip=$LOCAL_IP" https://www.privateinternetaccess.com/vpninfo/port_forward_assignment`
PORTNUM=`echo $PORT | grep -oE "[0-9]+"`
logger "pia-port: Port number acquired: $PORTNUM"
echo $PORTNUM > /home/jleiss/VPNport.txt
logger "pia-port: Current port forward: $CURPORT"
#Update port in QBittorent
curl -i -X POST -d "json=%7B%22listen_port%22%3A${PORTNUM}%7D" http://localhost:8080/command/setPreferences
and then I setup an entry in crontab to run the script once an hour and dump that to a log file in case there is error's I need to review.
25 * * * * /home/jleiss/newport.sh > /home/jleiss/.cronlog 2>&1
Jeff
[/quote]
Hi Jeff,
Thanks for providing your solution. I found your solution just yesterday and the script seems to work fine. Although I'm getting a weird error which I, who lack any experience in working with web APIs, really can't figure out. I assume it's related to the script not being able to authenticate correctly to my qbt server, see below:
Code: Select all
HTTP/1.1 403 Forbidden
content-length: 0
content-security-policy: default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; script-src 'self' 'unsafe-inline'; object-src 'none';
date: Fri, 05 Jan 2018 11:22:15 GMT
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
I tired to add "--data "username=XXX&password=XXX"" to the string in the script, but also a cookie in my 2nd attempt with "--cookie "SID=XXX"" without any luck.
Also, when I run the initial curl string towards PIA I get another port number than the one that is being logged in the logger log file from the script, and the port provided in that logfile stops my current active torrents. Any idea why this might happen? I've made sure that all the commands actually works manually and gives me the right data.
Appreciate any insight you or anyone else might be able to give me,
Cheers,
Seb