Transmission + openVPN (with autosave password)

Status
Not open for further replies.

andyclimb

Contributor
Joined
Aug 17, 2012
Messages
101
Install tranmission plugin…

1st problem, get OPENvpn working with an auth file
Source : http://forums.freenas.org/index.php...-connects-to-the-vpn.18669/page-2#post-108802

1) Gain shell acess to you jail, ssh into your freenas instance and list the jail instances

# jls
This command then allows you to enter the jail, replace the $ with the number shown for your transmission jail.

# jexec $ /bin/tcsh
1) Remove existing OPENvpn

# pkg remove openvpn

2) Get source of openvpn and recompile, at the blue screen enable the save_passwords option

# portsnap fetch
# portsnap extract
# cd /usr/ports/security/openvpn
# make install clean

Get your open vpn script from you VPN service, I'm using ipvanish which are pretty good. And check that you can log in ok

# openvpn nameofyourconf.conf

If your VPN logs in ok, then you can add this line to the conf file at the bottom that runs it in the background.

daemon

and add the path to you auth.txt where the first line is your account username and the second is the vpn password. now try running openvpn nameofconf.conf and it should automatically log in for you. run ifconfig to check and then pkill openvpn will shut it down.

#ifconfig

This should give you an entry called tun0, which we will use to bind transmission to so that if the VPN fails then it does not fall over to your normal connection. This works quite nicely. I've tried to use the --up command from OPENvpn to run a little script, which works fine in debian, but not in freebsd / in a jail.. I just could not get it working. I made a post elsewhere about it
http://forums.freenas.org/index.php?threads/transmission-vpn-script-fail.19928/

1. Next the script that passes the tun0 IP.

Make a script called up.sh

# nano up.sh

And place this into it
-----------------------------------
#!/bin/bash

/usr/local/etc/rc.d/transmission stop
pkill openvpn
sleep 5
echo "Starting VPN"
# you will need to point this to the location of you conf script. The wait is to get it to load before obtaining the IP
openvpn /media/home/vpn.conf

echo "Waiting for vpn to start..."
sleep 10
# This line extracts the IP from ifconfig. If anyone knows a better way to do this, let me know. The two -v removes the localhost,
# and the LAN IP, which should leave one entry which is your tun0 interface. Cut and paste this to see if it works.

var=$(ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | grep -v '192.168.1.40' | awk '{ print $2}')
echo "VPN started IP: $var"

# This took some figuring out, but it essentially replaces the bind address in the settings.json with your vpn IP….
sed -i -e "s/\"bind-address-ipv4\".*/\"bind-address-ipv4\": \"$var\",/" /usr/pbi/transmission-amd64/etc/transmission/home/settings.json
echo "Transmission settings updated"
# start transmission again
/usr/local/etc/rc.d/transmission start

-------------------------------------

now when you run up.sh it should automatically start the VPN and bind transmission to it. I should say that there is an alternative method of using sed online but it takes a settings_template.json file and replaces some text. I did not like this approach as any settings you adjusted when the client was running were lost. this keeps the original settings.json file.

happy torrenting...
 

marian78

Patron
Joined
Jun 30, 2011
Messages
210
Hi,

im not expert (im noob :) ) , but i try your script.
you write: sed -i -e "s/\"bind-address-ipv4\".*/\"bind-address-ipv4\": \"$var\",/" /usr/pbi/transmission-amd64/etc/transmission/home/settings.json

But after this on every run up.sh, it add new ip to "settings.json": "bind-address-ipv4": "10.2.3.4", "10.2.3.4", ................................,"192.168.1.40",

i changet to this: sed -e "s/\"bind-address-ipv4\":*.*.*.*/\"bind-address-ipv4\": \"$var\",/" /usr/pbi/transmission-amd64/etc/transmission/settings.json

now my settings.json is always like: "bind-address-ipv4": "10.2.3.4",


If im wrong please ignore this message.


Edit: now i have another problem. Command "sed" dont update settings.json. Its not caused by permissions....
 

andyclimb

Contributor
Joined
Aug 17, 2012
Messages
101
Hi,

I'm very new to this as well. it took a lot of trial and error to get it working and basically it doesn't work for me unless both the -i and -e flag are there in that order. don't ask me why, I did try both separately... so who knows.. i think if i just used the -e flag, and specified the same output file as input then i got a blank document.
 
Joined
Mar 6, 2014
Messages
686
Why would you want transmission to stop? Would be easier to just make firewall rules that only allow traffic over the vpn connection (and to your local LAN perhaps), so if that connection is down, there will just be no traffic (except from your LAN if preferred)?
 

Lars Kluken

Dabbler
Joined
Jan 23, 2015
Messages
14
Hi,
I managed to get this working when runned manually, but it would be nice to have it run automatilly at startup.
So far I have tried making modifications to the script using the instructions found on: https://joekuan.wordpress.com/2010/...ow-to-create-a-freebsd-system-startup-script/
Then I placed the script in /usr/local/etc/rc.d/ and added myscript_enable="YES" to /etc/rc.conf.

The script creates the test folder on startup, but the VPN does not start.
Does anybody see what I'm doing wrong or maybe there is a simpler way to make this solution apply automatically?

myscript:
----------------------------------------------------------------
#!/bin/sh
# PROVIDE: myscript
. /etc/rc.subr
name=myscript
rcvar=myscript_enable
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
load_rc_config $name
exec >> /media/up_output.log

myscript_start()
{
if checkyesno ${rcvar}; then
/usr/local/etc/rc.d/transmission stop
pkill openvpn
sleep 5
echo "Starting VPN"
# you will need to point this to the location of you conf script. The wait is to get it to load before obtaining the IP
/usr/local/etc/rc.d/openvpn start
echo "Waiting for vpn to start..."
sleep 10

# This line extracts the IP from ifconfig. If anyone knows a better way to do this, let me know. The two -v removes the localhost,
# and the LAN IP, which should leave one entry which is your tun0 interface. Cut and paste this to see if it works.
var=$(ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | grep -v '192.168.1.4' | awk '{ print $2}')
echo "VPN started IP: $var"

# This took some figuring out, but it essentially replaces the bind address in the settings.json with your vpn IP...
sed -i -e "s/\"bind-address-ipv4\".*/\"bind-address-ipv4\": \"$var\",/" /var/db/transmission/settings.json
echo "Transmission settings updated"
# start transmission again
/usr/local/etc/rc.d/transmission start
mkdir /media/testdir
fi
}
run_rc_command "$1"
 

yourmate

Contributor
Joined
Apr 4, 2016
Messages
105
dead?
 
Status
Not open for further replies.
Top