#!/bin/bash
#Author: Tran Dinh Duy
#generate the fake rapidshare packet for download with wget
#Use for download rapidshare with resuming using free download

#user agent field
USER_AGENT="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070417 Fedora/2.0.0.3-4.fc7 Firefox/2.0.0.3 MEGAUPLOAD 1.0"

#read access code from user
read -p "Enter access code of rapidshare:" ACCESS_CODE;

#making --post-string variable
TEXT_DATA="\"mirror=on&accesscode="${ACCESS_CODE}" &actionstring=Download+via+TeliSonera\""

#debug line
echo ${TEXT_DATA}

#reading rapid share download link
read -p "Enter rapidshare file link to download:" FILE_LINK;

#parse host field
HOST=`echo ${FILE_LINK} | cut -b8- | cut -d'/' -f1`

#debug line
echo ${HOST}

#header field

header1="\"Host: ${HOST}\""
header2="\"User-Agent: ${USER_AGENT}\""
header3="\"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\""
header4="\"Accept-Language: en-us,en;q=0.5\""
header5="\"Accept-Encoding: gzip,deflate\""
header6="\"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\""
header7="\"Keep-Alive: 300\""

wget --header=${header1} \
--header=${header2} \
--header=${header3} \
--header=${header4} \
--header=${header5} \
--header=${header6} \
--header=${header7} \
--post-data=${TEXT_DATA} ${FILE_LINK}