Skip to content

Instantly share code, notes, and snippets.

@davericher
Last active September 28, 2015 03:52
Show Gist options
  • Save davericher/f82fbf0198369bbbd41a to your computer and use it in GitHub Desktop.
Save davericher/f82fbf0198369bbbd41a to your computer and use it in GitHub Desktop.
A node script to get forwarded private internet access port, write it to your transmission settings, and restart transmission
#!/usr/bin/env node
var os = require('os');
var fs = require('fs');
var curl = require('curlrequest'); // Required via npm
var shelljs = require('shelljs'); // Required via npm
var jsonfile = require('jsonfile'); // Required via npm
// Transmission-daemon settings.json file
var transFile = '/etc/transmission-daemon/settings.json';
// Private internet access username
var username = 'username';
// Private internet access password
var password = 'password';
// Location of cliend id file, see pia docs for generating one
var clientId = "location of client id file"
var options = {
url: 'https://www.privateinternetaccess.com/vpninfo/port_forward_assignment',
data: {
local_ip: os.networkInterfaces()['tun0'][0].address,
client_id: fs.readFileSync(clientId, 'utf8'),
user: username,
pass: password
}
};
curl.request(options, function(err, response) {
var json = JSON.parse(response);
jsonfile.readFile(transFile, function(err, transConfig) {
transConfig['peer-port'] = json.port;
shelljs.exec('systemctl stop transmission-daemon', function(code, output) {
jsonfile.writeFileSync(transFile, transConfig,{spaces:5});
shelljs.exec('systemctl start transmission-daemon');
});
});
console.log('Updated to port', json.port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment