Tuesday, April 8, 2008

Torrent Anywhere

How to safely use bittorrent away from home (on linux)

Many universities and companies block/prohibit bittorrent or limit your bandwidth. Petty restrictions need not limit your thirst for data. Using a properly configured linux server you can easily whisk files to your home computer from any machine with basic web access.

A. Install and configure AjaxTerm

1. Ajaxterm requires the apache webserver. Install it using your distribution's package manager.

2. How you install AjaxTerm itself depends upon your distribution. For example:

Ubuntu (from universe repo):

# sudo apt-get install ajaxterm

If ajaxterm is not in your distribution's repo it can be easily set up from source:

(from the offical site: http://antony.lesuisse.org/qweb/trac/wiki/AjaxTerm)

# wget http://antony.lesuisse.org/qweb/files/Ajaxterm-0.10.tar.gz
# tar zxvf Ajaxterm-0.10.tar.gz
# cd Ajaxterm-0.10
# ./ajaxterm.py

Right. Now that it's installed, run it from a shell:
#ajaxterm AjaxTerm at http://localhost:8022/

Point your browser to http://localhost:8022/ and make sure everything works.

3. We want ajaxterm to run on boot, so add the line ajaxterm -d to /etc/rc.local .
If you do not have ssl set up, then do the following as root:
# cd /etc/httpd/conf
# openssl req -new -x509 -newkey rsa:1024 -days 3650 -keyout server.key -out server.crt

4. To get rid of the passphrase:
# openssl rsa -in server.key -out server.key
5. Add an initial user:
# htpasswd2 -c /etc/apache2/htpasswd yourusernamehere
6. To make ajaxterm accessible from the outside world, add the following to your /etc/httpd/conf/httpd.conf
Listen 443
NameVirtualHost *:443
ServerName localhost
SSLEngine On
SSLCertificateKeyFile conf/server.key
SSLCertificateFile conf/server.crt
ProxyRequests Off
AuthType Basic
AuthName "remote Shell Access"
AuthUserFile /etc/httpd/conf/htpasswd
Require user YOURUSERNAME
Order deny,allow
Allow from all

ProxyPass /ajaxterm/ http://localhost:8022/
ProxyPassReverse /ajaxterm/ http://localhost:8022/

7. Next, you may need to forward port 443 to your computer. For linksys routers browse to http://192.168.1.1 .For 2WIREs try http://192.168.1.254 .There should be a login and some menus to navigate.
Now you should be able to access your remote login shell from https://123.45.68.90/ajaxterm/ where those numbers are your IP address. (http://www.whatismyip.com).

8. Cable and DSL IPs change from time to time so you need a way to always know the location of your home server. I will use this script to keep me updated:
#!/bin/bash
cd /tmp/
rm *.asp*
wget www.whatismyip.com/automation/n09230945.asp
mail -s "Automated IP Notification" burthawk101@gmail.com <>

If you need this to run automatically, add the following line to your crontab (# crontab -e) o run the script every day at 7 AM.
00 07 * * * /etc/ip/ip.sh

9. Gmail kept bouncing my emails as spam, so I used ssmtp to send emails from the gmail account to itself. Install ssmtp from your distribution's repo.

The Gentoo wiki has instructions for setting up ssmtp

In /etc/ssmtp/ssmtp.conf, set the following:

root=youraccount@gmail.com mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=smtp.gmail.com:587
UseSTARTTLS=YES
AuthUser=youraccount
AuthPass=yourpasword
FromLineOverride=YES # optional

In /etc/ssmtp/revaliases:

root:youraccount@gmail.com:smtp.gmail.com:587 mainuser:youraccount@gmail.com:smtp.gmail.com:587



B. Install a bittorrent command line client.
1. Download btpd, a bittorrent client that can run as a daemon at http://www.murmeldjur.se/btpd/ Install with the usual
# ./configure

# make
# sudo make install

2. Make sure btpd runs on boot by adding an entry "btpd" to /etc/rc.local

3. Download a torrent from your favorite site like so:

# wget http://torrentsite.com/path/to/linuxiso.torrent

4. Load the torrent with btpd

# btcli  add /media/downloads/linuxiso.torrent -d /media/downloads/linuxiso

If the torrent has multiple files in it, be sure to include a new directory in the specified -d path.

If bandwidth is a concern you will want to wait until you have physical access to your remote machine and get your files onto an external hard drive. If your only concern is avoiding attention for torrent activity, then you can transfer the files via scp. Note that this requires the ability to SSH from a local shell and won’t work with AjaxTerm