GithubHelp home page GithubHelp logo

pia-transmission-updater's Introduction

Private Internet Access Transmission Updater

This script will update the listening port for Transmission with the forwarding port for users of Private Internet Access.

How It Works

There are three steps to this script. First, it makes a remote procedure call to Transmision to see if the current listening port is still open. If it isn't, the script gathers the local ip address for the VPN device, and makes a request to PIA with your user name, password, and client id for the current forwarding port. Finally, another remote procedure call is made to Transmission to update the listening port with the forwarding port sent back by PIA.

Requirements

Tcl and Tcllib are the only two requirements. They come pre-installed on most *nix operating systems.

Configuring

Configurations are loaded via a config file. By default, the script looks for a file named .config residing in the same directory as the script. The config file location can also be passed as a command like argument:

./updater.tcl --config patch/to/config.file

Configs

pia_user       USERNAME
pia_pass       PASSWORD
id_file        CLIENT_ID_FILE
device         VPN_DEVICE
trans_rpc_url  TRANSMISSION_URL/transmission/rpc
rpc_auth       TRUE/FALSE
rpc_user       RPC_USERNAME
rpc_pass       RPC_PASSWORD
pia_url        https://www.privateinternetaccess.com/vpninfo/port_forward_assignment
check_port     1
USERNAME         ---PIA user name
PASSWORD         ---PIA password
CLIENT_ID_FILE   ---Path to file containing client id
VPN_DEVICE       ---Device name for VPN connection. Usually tun0. Run ifconfig to find out
TRANSMISSION_URL ---URL to transmission. If running on same box: http://localhost:9091
RPC_TRUE/FALSE   ---If rpc authenication is enabled for transmission. Set to true or false
RPC_USERNAME     ---Transmission rpc username
RPC_PASSWORD     ---Transmission rpc password
PIA_URL          ---Url for fetching port from PIA. Can normally be left as is.
CHECK_PORT       ---OPTIONAL. Can be used to disable Transmission port checking to just always update port

Running

First, we need a file with the unique, constant client id. This will be sent with every PIA request.

OS X: head -n 100 /dev/urandom | md5 > ~/.pia_client_id

Linux: head -n 100 /dev/urandom | md5sum | tr -d " -" > ~/.pia_client_id

Once the client id file is created and the configurations set, it is as easy as running: tclsh updater.tcl

or make it executable with chmod u+x updater.tcl and then run ./updater.tcl

Scheduling

It can even be setup to run as a cron job to completely automate this process. Something such as:

@hourly /usr/local/bin/tclsh /scripts/updater.tcl

Troubleshooting

If it doesn't work for some reason, the script can ran in a debugging mode by adding a flag when running:

./updater.tcl --debug true

The script communicates with Transmission via its RPC API. Specific Transmission RPC configs can be found here and the RPC specs here.

pia-transmission-updater's People

Watchers

 avatar  avatar

pia-transmission-updater's Issues

Trouble with latest release

Hi,

Having some problems with the new version..
Getting the following error:

key "port-is-open" not known in dictionary
while executing
"dict get [dict get $resp_data arguments] port-is-open"
(procedure "_isPortOpen" line 16)
invoked from within
"_isPortOpen"
(procedure "_checkPort" line 3)
invoked from within
"_checkPort"
(procedure "::upd::updTransmission::checkPort" line 3)
invoked from within
"::upd::updTransmission::checkPort"
(file "./updater.tcl" line 16)

Output from debug:
DEBUG: Connecting to transmission at: http://localhost:9091/transmission/rpc
DEBUG: Send request to Transmission
DEBUG: Query:
DEBUG: Headers: Authorization {Basic dHJhbnNtaXNzaW9uOnRyYW5zbWlzc2lvbg==}
DEBUG: Response:
DEBUG: Server Transmission X-Transmission-Session-Id Al2EGbHspdRMZDnItavovXHcDheRWbl4UXMd3UgqfAzrRuNY Date {Tue, 30 Aug 2016 17:47:24 GMT} Content-Length 580 Content-Type {text/html; charset=ISO-8859-1} Connection close
DEBUG: Retrieved CSRF token: Al2EGbHspdRMZDnItavovXHcDheRWbl4UXMd3UgqfAzrRuNY
DEBUG: Set headers: Authorization {Basic dHJhbnNtaXNzaW9uOnRyYW5zbWlzc2lvbg==} X-Transmission-Session-Id Al2EGbHspdRMZDnItavovXHcDheRWbl4UXMd3UgqfAzrRuNY
DEBUG: Send request to Transmission
DEBUG: Query: {"arguments": {},"method": "port-test"}
DEBUG: Headers: Authorization {Basic dHJhbnNtaXNzaW9uOnRyYW5zbWlzc2lvbg==} X-Transmission-Session-Id Al2EGbHspdRMZDnItavovXHcDheRWbl4UXMd3UgqfAzrRuNY
DEBUG: Response:
DEBUG: arguments {} result {portTested: http error 0: No Response}
DEBUG: Received: arguments {} result {portTested: http error 0: No Response}
key "port-is-open" not known in dictionary
while executing
"dict get [dict get $resp_data arguments] port-is-open"
(procedure "_isPortOpen" line 16)
invoked from within
"_isPortOpen"
(procedure "_checkPort" line 3)
invoked from within
"_checkPort"
(procedure "::upd::updTransmission::checkPort" line 3)
invoked from within
"::upd::updTransmission::checkPort"
(file "./updater.tcl" line 16)

Do you have any ideas?

Cron

Hei @mhum

The script work great, but I'am having trouble scheduling it..
I have not much experience with tcl.. So i may be doing something wrong..
I have set up this cron:
@hourly /usr/bin/tclsh /opt/scripts/updater.tcl

From logs i see this:
Date: Sat, 23 Apr 2016 22:58:01 +0200 (CEST)

Port is no longer open. Let's continue!
couldn't execute "ifconfig": no such file or directory
while executing
"exec ifconfig $device"
invoked from within
"regexp {inet .*?(10.[0-9]+.[0-9]+.[0-9]+)} [exec ifconfig $device] -> local_ip"
(file "/opt/scripts/updater.tcl" line 114)

Running /usr/bin/tclsh /opt/scripts/updater.tcl from command line works just fint.

How have you set up your cron?
Is there some tcl environment thing I have to change?

Externalize Configs

Move configurations out of the script itself and put into a separate file.

list must have an even number of elements

Having some issue running it.

Running: tclsh updater.tcl
list must have an even number of elements
while executing
"http::geturl $trans_url -query $query -headers $headers"
invoked from within
"set resp_token [http::geturl $trans_url -query $query -headers $headers]"
(file "updater.tcl" line 24)

Any idea what it could be?
I'am running on ubuntu 14.04.4 headless server.

Trouble with latest release

Do you have any suggestion regarding this error?

DEBUG: Received: arguments {port-is-open false} result success
DEBUG: Port open: false
Port is no longer open. Let's continue!
DEBUG: Read client id from: /home/user/.pia_client_id
DEBUG: Client id:

DEBUG: Run ifconfig for tun0:
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.133.1.6 P-t-P:10.133.1.5 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:47611175 errors:0 dropped:0 overruns:0 frame:0
TX packets:56266484 errors:0 dropped:140397 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:29744413819 (29.7 GB) TX bytes:63441025372 (63.4 GB)

DEBUG: Found IP: 10.133.1.6
DEBUG: Format query to fetch port:
DEBUG: Sending to: http://www.privateinternetaccess.com/vpninfo/port_forward_assignment
DEBUG: Response:
DEBUG: error {Invalid parameter: client_id}
key "port" not known in dictionary
while executing
"dict get $resp port"
(procedure "::upd::updPia::fetchPort" line 41)
invoked from within
"::upd::updPia::fetchPort"
invoked from within
"set port [::upd::updPia::fetchPort]"
(file "./updater.tcl" line 40)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.