W T O R R E N T
D
T
V
Yes, I’ve finally gotten around to part 3 of 3 in my rtorrent with wtorrent tutorial. Wtorrent is an excellent webui for rtorrent and after this tutorial you’ll be able to manage rtorrent from the web…forward a port and you can even connect to your wdtv from the internet to queue up torrents!
In order to take advantage of this tutorial you must either be running WDLXTV or Zoranders ext3-boot. You must also have my Optware for WDTV package installed, that stuff is covered elsewhere. I’ll be including every necessary step here, so you might be able to skip around if you already have some of this done.
This writeup presumes that you have already executed the steps from part 1 and part 2. If you haven’t done them yet, then get over and complete them first!
First ssh/telnet into your WDTV, then update your Optware feed and download the latest wtorrent.
$ ssh root@wdtv-01
BusyBox v1.10.0 (2009-02-15 05:09:42 CST) built-in shell (msh)
Enter 'help' for a list of built-in commands.
# ipkg update
Downloading http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//Packages.gz
Inflating http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//Packages.gz
Updated list of available packages in /opt/lib/ipkg/lists/wdtv
Successfully terminated.
#
# cd /tmp
#
# wget 'http://www.wtorrent-project.org/trac/changeset/latest/trunk/?old_path=%2F&format=zip' -O wtorrent-current.zip
--2009-04-08 07:11:41-- http://www.wtorrent-project.org/trac/changeset/latest/trunk/?old_path=%2F&format=zip
Resolving www.wtorrent-project.org... 38.103.173.70
Connecting to www.wtorrent-project.org|38.103.173.70|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 453058 (442K) [application/zip]
Saving to: `wtorrent-current.zip'100%[======================================>] 453,058 771K/s in 0.6s
2009-04-08 07:11:43 (371 KB/s) - `wtorrent-current.zip' saved [453058/453058]
Now that we have the latest version, lets unzip it to our web server location and do a bit of file maintenance to get things in working order.
# unzip wtorrent-current.zip -d /opt/share/www/
inflating: trunk/wtorrent/torrents/.htaccess
inflating: trunk/wtorrent/cls/torrent.cls.php
inflating: trunk/wtorrent/cls/rtorrent.cls.php
...
...
...
inflating: trunk/wtorrent/wt/js/ajax.js
inflating: trunk/wtorrent/install.php
inflating: trunk/wtorrent/index.php
#
#
# cd /opt/share/www
# mv trunk/wtorrent/ .
# ls
index.php trunk wtorrent
# rmdir trunk/
# ls
index.php wtorrent
#
# mkdir wtorrent/tpl_c
#
# touch wtorrent/db/database.db
#
# cp wtorrent/conf/sample.user.conf.php wtorrent/conf/user.conf.php
#
# chmod -R 777 wtorrent
#
Whew, now that bit of (undocumented) house cleaning is taken care of we need to modify the configuration for rtorrent to enable the xmlrpc server.
# echo '# xmlrpc support for wtorrent
scgi_port = 127.0.0.1:5000' >> /opt/etc/rtorrent.conf
You’ll have to restart rtorrent after the line above. If you’re successfull your rtorrent should have a message like so:
# /opt/etc/init.d/S99rtorrent restart
NOTE:
I still haven't gotten around to patching S99rtorrent in Optware. For a temporary solution there is an S99rtorrent that will work for now, check the comment section of part 1of3 of this series.
*** rTorrent 0.8.2/0.12.4 - wdtv-01:1282 ***
[View: main]( 7:25:43) Using 'select' based polling.
( 7:25:43) Ignoring ~/.rtorrent.rc.
( 7:25:43) XMLRPC initialized with 444 functions.
( 7:25:43) The SCGI socket is bound to a specific network device yet may still p
[Throttle 40/300 KB] [Rate 0.0/ 0.0 KB] [Port: 51780] [U 0/18] [D 0/70] [H
Note: I’ve done the minimal patching required to get rtorrents init.d script syntax error free, will patch Optware tomorrow if I have time
Ok, we’re gettin closer. Now we just need to install one package I accidentally left off (sqlite2) the lighttpd tutorial and then enable the modules in php.ini.
# ipkg install sqlite2
Installing sqlite2 (2.8.17-2) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//sqlite2_2.8.17-2_mipsel.ipk
Configuring sqlite2
Successfully terminated.#
# echo 'extension=pdo.so
extension=pdo_sqlite.so' >> /opt/etc/php.ini
Now its time to enable and configure the SCGI server module in lighttpd. For good style I’ll place the config file in /opt/etc/lighttpd/conf.d/. All .conf files located in this directory are parsed each time lighttpd starts. This makes things a bit more modular.
To edit:
# nano /opt/etc/lighttpd/conf.d/11-mod_scgi.conf
inside 11-mod_scgi.conf add:
server.modules += ( "mod_scgi" )
scgi.server = (
"/RPC2" => # RT_DIR
( "127.0.0.1" =>
(
"host" => "127.0.0.1", # Ip where rtorrent is listening
"port" => 5000, # Port specified in .rtorrent.rc
"check-local" => "disable"
)
)
)
The next step is optional. If your wdtv is not accessible from the public internet, then you can skip this step. If you are forwarding an external port to your wdtv so you can manage wtorrent remotely, then yes you definitely want to do this.
To edit:
# nano /opt/etc/lighttpd/conf.d/12-mod_auth.conf
inside 12-mod_auth.conf add:
server.modules += ( "mod_auth" )
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/opt/etc/lighttpd/.passwd"auth.require = ( "/wtorrent" =>
(
"method" => "basic",
"realm" => "wtorrent.on.wdtv",
"require" => "valid-user"
)
)
Now when you attempt to access wtorrent you’ll be prompted for a username/password, without disclosing whats behind the auth. One last thing we need to do before SCGI is finished, we need to create the directory and set its permissions.
# mkdir /opt/share/www/RPC2
# chmod 777 /opt/share/www/RPC2
We have authorization set up, but one problem…What users are authorized to connect? Inside of 12-mod_auth.conf you should notice these two lines:
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/opt/etc/lighttpd/.passwd"
Valid user/password combinations are stored in /opt/etc/lighttpd/.passwd. We’ll need to create a little script to add user/password combo’s to this file.
to edit:
# nano /opt/bin/htpasswd && chmod a+x /opt/bin/htpasswd
inside /opt/bin/htpasswd add:
#!/bin/sh
user=$1
realm=$2
pass=$3hash=`echo -n "$user:$realm:$pass" | md5sum | cut -b -32`
echo "$user:$realm:$hash"
Now I’ll generate a user so I can connect, when things are finished.
# htpasswd b-rad.cc wtorrent.on.wdtv testing >> \
/opt/etc/lighttpd/.passwd
You can change wtorrent.on.wdtv to anything you desire (maybe something less obvious), just be sure there are no spaces in the string.
Are we there yet? Almost. We first need to restart lighttpd to reflect our config changes and kill php-fcgi so it loads the sqlite modules.
# killall php-fcgi
#
# /opt/etc/init.d/S80lighttpd restart
Stopping web server: lighttpd
Starting web server: lighttpd
#
Now we're finally ready to run wtorrents web installer and get things underway.
Open your favourite web browser and enter:
http://<your wdtv's ip>:8081/wtorrent/install.php
You should be welcomed by the install screen. Heres what my config looks like...notice that it asks you for rtorrents scgi port, but I've entered the webserver port instead. I imagine that is a typo on wtorrents part, you must enter your lighttpd port there. When SCGI was enabled earlier we set it to only be exposed to the loopback, so no need to have a username/password there.

Note: don't copy my config information verbatim unless your directories are exactly like mine
Once you've filled the information out correctly, click on try configuration. You should see this:

If you don't then you haven't been following very well
If it says you're good, then click save configuration. It should report success like so:

Bingo!
Now there are two things that we need to do before starting, delete install.php like wtorrents asks and protect the wtorrent db from being downloaded.
# rm /opt/share/www/wtorrent/install.php
That takes care of the install script, in order to protect the database we have to modify /opt/etc/lighttpd/lighttpd.conf
# nano /opt/etc/lighttpd/lighttpd.conf
You need to find this line:
url.access-deny = ( "~", ".inc" )
and replace it with this line:
url.access-deny = ("~", ".inc", ".db", ".tpl.php", ".cls.php",)
Restart lighttpd now to reflect that change, then how bout we take wtorrent for a testdrive?
# /opt/etc/init.d/S80lighttpd restart
Ok, navigate to http://<your wdtv's ip>:8081/wtorrent. You're greeted by wtorrents internal log in page, if you enabled mod_auth earlier you'll have to enter a user/password before you access wtorrent.

After logging in you're dropped in to the torrent listings. If your rtorrent has torrents currently running you'll see them here, I don't have anything downloading at the moment.

I'll click on add torrent to see about adding something.

I've selected something and checked private, since this is a private torrent, now I'll click to upload.

Lets go back to the main view to see if the torrent is running.

Awesome! You now have the ability to add torrents to your wdtv from anywhere in the world...and you don't have to go to the console at all!!!
Some things to note:
- the wdtv is not a powerful web server, give rtorrent/wtorrent time to respond and don't be impatient.
- extracting archives can be painful
I spend a tremendous amount of time hacking the WDTV firmware and writing up stuff like this, so if you appreciate my efforts please donate a little something using the link below : ) Thanks & enjoy.