How to create a download box for < Rs 2700

I have recently been involved headfirst into a project to create a download box for myself. Ever since I was in college I wanted my own server to run my own IRC bot, queue up downloads and forget about it, and do programming from say a mobile phone. Some kids dream about bikes, cars, new clothes etc when they get a job. I dreamed about a server. The past few months I have been working on that and finally I have completed it. It works as a download box for now and I will continue to irk out the flaws in it in the coming months. So, how have I achieved this, you ask? First off I bought a TP – LINK MR 3220. I wanted a computer with a processor, USB port and Ethernet port/ Wifi card with low power consumption. Unfortunately, everything I looked at, cost a lot more than Rs 10000. I think this is because since these computers are not bought by many people the companies that make them are trying to recoup their research costs by charging people more for their devices. Finally I realized that a router with USB port would do my job. Hence I arrived at the TP – Link router.The router cost me Rs Rs 2290 and I bought an 8GB pen drive for Rs 370. Now I am going to explain how I set up my router from my point of view. But if you have and idea about the fundamental stuff you can also build one yourself. This time, I am not going to explain the very basics of everything.

  • Install openWRT on your router

First, you need to flash the router’s firmware with the latest version of openWRT

  • Now install support for USB devices.

You need to enable support for USB. I also had to install iso and cp437 modules to make it work. I used FAT filesystem.

  • Now mount it and add the directories

mkdir -p  /media/usb
mount /dev/sda1 /media/usb
mkdir -p /media/usb/router/packages

  • Edit package manager to add USB as a destination

See the Configuration  : Adjust Repositories section of this link
Add the following line to /etc/opkg.conf

dest usb /media/usb/router/packages

  • Now install lighttpd, PHP-CGI, ctorrent to USB and configure symbolic links

For example to intstall lighttpd to usb use the following command

opkg update
opkg -dest usb install lighttpd

When you install the binaries and try to run them it will complain that it failed to load shared libraries. Just find them one by one at /media/usb/router/packages/usr/lib and create a symbolic link to them at /usr/lib.

  • Configure lighttpd, PHP-CGI and ctorrent [lighttpd webroot must be /www_1]

Instructions can be found here.

  • Now extract rapidleech stuff onto /media/usb/router/rapid and fix the bug

Since we have no X11 on our router we need to automate clicking through forms, verifying captchas etc through another mechanism. Rapidleech is a leech script for downloading from a variety of downloaders like Rapidshare, Hotfile, Fileserve etc. It can be found here. Extract it to a folder named /media/usb/router/rapid. Now there is a bug in the script at /media/usb/router/rapid/templates/plugmod/header.php

<?php // You can do some initialization for the template here
@date_default_timezone_set(date_default_timezone_get()); ?>

These geniuses realized that this is a function that can throw an error and decided to suppress that error message. Which means after configuring the rapidleech for the first time, you will get a blank page the first time you visit the page. Just comment the line which sets the default time zone and the site will start working normally.

Now create a symbolic link to this folder on lighttpd webroot

ln -s /media/usb/router/rapid /www_1/rapid

  • Now copy the ssh generated key file to /media/usb/router/ folder

My ISP does not provide me with a public IP address. It gives me an IP address 192.168.x.x and forces me behind their router. At work I am obviously behind some router of the company. This gives rise to an interesting problem where both the machines have to initiate the connection since they are behind routers. Neither system can directly connect to the other. The solution I have found is to tunnel the connection through an Amazon EC2 instance. For this you may need to enable incoming connections on port 2500 besides the default 22. Since the default key provided by Amazon is not accepted by dropbear and you need a new key. Copy the id_rsa key to the folder : /media/usb/router/scripts

  • Now compile and copy spectranet binary to /media/usb/router/packages/usr/bin

My ISP also has the annoying habbit to log me out every 30 minutes or so. I had to understand how the log in mechanism works and write a program to automatically log me in. If anyone else is trying this they might need to do a different set of steps to log in to their ISPs. I also added the startup stuff for lighttpd and to open ssh tunnels to this program so that I dont have to manage different things. The code I am publishing here:

main.c
Makefile
spectranet.c
spectranet.h
tcp.c
tcp.h

You need to build openWRT to obatain the toolchain to cross compile to MIPS. After compilation the tool chain will be available at openwrt/trunk/build_dir/target-mips_r2_uClibc-0.9.32/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.5-linaro_uClibc-0.9.32/toolchain-mips_r2_gcc-4.5-linaro_uClibc-0.9.32

After compiling the binary you need to copy it to /usr/bin/ directory of the router.

  • Now write a startup script for running the /media/usb/router/packages/usr/bin/spectranet if it exists on startup and enable it.

Instructions can be found here.

File : /etc/init.d/download


#!/bin/sh /etc/rc.common
# Copyright (c) 2012 Joji Antony
# All rights reserved
# Licence Affero GPL V3
START=15
STOP=15
start() {
mount /dev/sda1 /media/usb
if [ -d /media/usb/router/packages ]
then
export HOME=/root
/usr/bin/spectranet &
fi
}
stop() {
umount /media/usb
}

Enable it:
root@OpenWrt:~# /etc/init.d/download enable

  • Set secret key in /media/usb/router/rapid/configs/accounts.php and create /root/.profile

This is needed for rapidleech to work properly and setting PATH variables.

Add the following line to /root/.profile
export PATH=$PATH:/media/usb/router/packages/usr/bin:/media/usb/router/packages/usr/sbin
Now you are ready. Just switch on the router and it automatically becomes your download box.

simula67@prometheus:~$ ssh -i /home/simula67/Temp/AMAZON\ KEYS/aws_key.pem ec2-user@ec2-12-110-209-183.compute-1.amazonaws.com
Last login: Fri Jan 13 17:51:57 2012 from 180.151.42.251
__|  __|_  )
_|  (     /   Amazon Linux AMI
___|\___|___|
See /usr/share/doc/system-release/ for latest release notes.
27 package(s) needed for security, out of 44 available
[ec2-user@ip-41-196-83-37 ~]$ ssh root@localhost -p 10000
root@localhost's password:
BusyBox v1.19.3 (2011-12-31 21:23:18 MST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
_______                     ________        __
|       |.-----.-----.-----.|  |  |  |.----.|  |_
|   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
|_______||   __|_____|__|__||________||__|  |____|
|__| W I R E L E S S   F R E E D O M
ATTITUDE ADJUSTMENT (bleeding edge, r29631) ----------
* 1/4 oz Vodka      Pour all ingredients into mixing
* 1/4 oz Gin        tin with ice, strain into glass.
* 1/4 oz Amaretto
* 1/4 oz Triple sec
* 1/4 oz Peach schnapps
* 1/4 oz Sour mix
* 1 splash Cranberry juice
-----------------------------------------------------
root@OpenWrt:~# cd /media/usb
root@OpenWrt:~# ctorrent -e 1 -C 20 -dd KunfuPanda.torrent

Accessing rapidleech
Screenshot of Rapidleech running off download box
NOTE1 : Some terminal output shown here are to illustrate the concepts only.
NOTE2: Some trackers refuse connection from ctorrent.  Use -A option to change user agent string and/or use different trackers ( use ctorrent -x the_torrent_file.torrent to find different trackers and use ctorrent -u “tracker url” to change the tracker)
NOTE3: Files downloaded via Rapidleech will be available at router/rapid/files folder on your pen drive.
Advertisements

11 thoughts on “How to create a download box for < Rs 2700

  1. @tester
    I did consider it. But it is not available yet. Besides it has no wifi support, which will cost more should I plan to use it. Also the cost difference is not way too much. Anyway, this seemed to be a solution that would wok for me. But I would like to see people use Raspberry Pi for this too.
    @oceandrugs
    Thanks

  2. thanks for this article , with this and some help from openwrt website i managed to create a torrent download box which i can command from my web browser. thanks

  3. @Joe

    You can try to plug in an external drive. About read/write speed; with my new pen drive:
    root@OpenWrt:/media/usb# hdparm -tT /dev/sda1

    /dev/sda1:
    Timing cached reads: 140 MB in 2.00 seconds = 69.95 MB/sec
    Timing buffered disk reads: 30 MB in 3.13 seconds = 9.59 MB/sec

    root@OpenWrt:/media/usb# time dd count=1k bs=1M if=/dev/zero of=/dev/sda1
    1024+0 records in
    1024+0 records out
    real 3m 45.42s
    user 0m 0.02s
    sys 0m 29.97s

    That’s 1GB of data in 3min 45 seconds = 4.17 MB/s

    You cannot buy a hub and extend number of ports. Also for this model, the processor is pretty slow, it may not be able to take much load. Good luck!

  4. Hi Antony, does Rapidleech speed depend on router’s cpu ? Mine is a 200Mhz Asus router and it does 200KB/s while I can download the same file at 1.8MB/s on my PC (single connection). What is throttling the speed and how is your router’s performance on rapidleech ?

  5. Hello sir Joji,great tutorial.
    I’m using a TP-Link MR 3220 to download torrents, with rtorrent, serve some webapps, got my router @ 1300/- from snapdeal.

    Another good alternative is Pogoplug series 4, around 1400/- @ amazon.in, 800MHz ARMv5 SoC, 128M RAM, with Gigabit ethernet. Raspberry Pi is too expensive for this purpose.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s