_|_   __   __   __   ___   __  _|_  |__  o _|_    __
|_, (__) | ' | ' (__/_ | ) |_, |__) | |_, __)

__ __ __ __ ___ __ __ __| ___
__) (__) (__(_ | ' (___ (__/_ (___ (__) (__| (__/_

_|_ _|_ __ __ o __ |
|_, (__(_ |_, (__) | ' | (__( |_,

Author: MrMister
Date: May 23, 2004
Version: 0.13h
Source: tbsource-0405211709.tar.bz2
Greets:
RedBeard: Owner of TorrentBits.org, for his helpful assistance in teaching me what I was doing wrong.
Without his help, this could never have been created.
KittyBitch: for alerting me to the existance of the great TorrentBits.org
SKORPiUS: for teaching me the Dynamic staff page, and offering other help.

Disclaimer
This document is for you to install your own version of the torrenbits tracker. The TB tracker is advanced in that only members of the site may download, and for its delays to leechers who do not upload as much. Please do not use this to run any Warez type site, only for legitimate reasons.

I would reccomend things such as CounterStrike or other large game mods, or linux downloads. Also good for amateur videographers who want to share their work with others and not having to pay high bandwidth fees for their large movie files being transfered.

I cannot be held responsible for what anyone does for this public document, mainly because I cannot track who sees it and what they will do with it.
WARNING
This isn't too easy, I tried to make it as easy and broad as possible. Of course, I don't know every situation, so I cannot explain it. Please ask in a public channel, preferably in the official TorrentBits channel, about the part you're having problems with. Remember they will want information about your setup and why theres a problem, so make sure you can tell them.
Why did you do this? I really liked the tracker, it was highly advanced for a tracker and good at being private, as you can require people to sign up and limit the number of signups. The status is also a nice touch.

The only thing was, there was no documentation on installing it, and they state not to ask them for help (obviously to save them from the headache of dealing with a billion newb questions). I decided it would be nice for everybody who would be asking these newb questions, and even the more advanced questions, to be able to read a simple tutorial and get it working quickly.

Plus, it was fun to learn how the source worked in the process.
Table Of Contents
  I. Introduction To TorrentBits
II. Requirements
III. Installation
A. Extraction
1. .tar.bz2
2. .tar.gz
B. SQL
1. DB Creation
2. Code Insertion
C. Editing Config
1. Setting secrets.php
2. Setting up bittorrent.php
3. Static Edits
a. URL on HomePage
b. FAQ
c. Staff Page
1. Dynamic Staff Page
2. Static Staff Page
D. Making Yourself Staff
E. Filling in the Blanks
1. Adding the Poll
2. Creating Forums
3. Deleting the Call of Duty section
4. Adding Other Staff
F. Finalization
1. Allowing Uploads
2. Updating PeerGuardian
IV. Bugfixing
V. Upgrading
1. From 0405120511 to 0405211709 (added in v0.13
I.
Introduction to TorrentBits
TorrentBits.org is a site sharing all sorts of files.
They share their source for aspiring torrent sites who want to stay a closed tracker, and such.
Nothing really to say except it's quite nice.
II.
Requirements
  • Apache HTTPD
  • PHP4 - 4.3 and above ( I think )
  • MySQL
  • A way to edit your MySQL databases, preferably PHPMyAdmin
III.
Installation
Be prepared for a long and boring installation process.  Grab a Vanilla Pepsi.
A.
Extraction
If the source code obtained from
ftp://torrentbits.org/snapshots/
is in .tar.bz2 form, use this command.
tar -jxvf tbsource [TAB] (meaning hit the tab key)
Else, if in .tar.gz form, use this command.
tar -zxvf tbsource [TAB]
The source code will extract itself to its own folder with the name of the tar, if it were tbsource-200109110846.tar.bz2 or .gz, it would be tbsource-200109110846. If you do not want it to go in its own folder, but instead the current folder, do not include the f in the -jxvf or -zxvf command.

Note: The number is in this format.
  2001 | 09 | 11 | 08 | 46
Year | Month | Date | Hour | Minute (time is in 24 hour format)
B.
SQL
This is divided into two parts. Making the DB (1) and inserting the SQL Queries (2).

Note: This is LOTS easier when you have phpmyadmin installed.
If you want to get it, go to http://www.phpmyadmin.net/ , but I will not assist you in setting it up.
1.
DB Creation
Note: I'm expecting you to know how to make a DB, if you don't, look around on the internet, or read the doc.
http://dev.mysql.com/doc/mysql/en/CREATE_DATABASE.html

If you have phpmyadmin, you can create a db there.

If you have cPanel, go to the SQL page and create a new database.  I'd reccomend the name 'tb'. After it's made it, it will be username_tb (replace username with whatever your username is).

Then create a user (tbusr is a good choice) and pass. It will turn into username_tbusr (again, username = your username). The pass will not be altered, though.

Now that you have created the database and the user (in cpanel), select the username_tbusr and username_tb in the dropdown boxes right under the list of databases. Then click "Add User to DB".

Congrats, the DB has been made. Please note what database, username, and pass you used, you will need this information later. If you didn't use cpanel, you shouldn't have even needed this section, as you're a pro.
2.
Insertion
Note: This is LOTS easier when you have phpmyadmin installed.  If you want to get it, go to http://www.phpmyadmin.net/ , but I will not assist you in setting it up.

When you have extracted the file, there will be several .sql files included, and they are ALL important. Open them up one by one and insert them into your database. Make sure you insert database.sql first.
C. Editing Config
There are quite a few parts to the configuration, some confusing.  You were warned when you started reading this.
1.
Setting up secrets.php
This is one of the easiest parts of the installation, apart from extracting the php.

Go to the directory/folder you extracted the TBSource into.
Open the 'includes' directory.
Edit " secrets.php ". It is easy to understand, it should come out like so.
<?

$mysql_host = "localhost";
$mysql_user = "username_tbusr";
$mysql_pass = "password";
$mysql_db = "username_tb";

?>

Where the 'mysql_user' is the username you used earlier, the mysql_pass is the pass you set earlier, and the mysql_db is the database you made earlier.
2.
Setting up bittorrent.php

You'll be editing mostly the top part of this, not the large sections of confusing code near the bottom.

Ignore most of the stuff at the top except the parts I mention. You can play with the other options if you like, although its not a good idea.

First, $maxusers sets how many users can join your site. Set this to whatever number you like, when your user count hits that number, no more signups will be allowed until the automatic pruning opens a slot.

Next, $torrent_dir is where the .torrent files will be stored. This does NOT have to be in a public folder. However, since it's unlikely you'll be running the server this is on, please set it to /home/username/tb/torrents (something else will work, but I'll be telling how to set this up). PLEASE NOTE the directory you set, you will NEED to know this later.

Then you will have the $announce_urls array. Please change the first one to your domain with the location of the tb source, and append announce.php:80 to it. (such as
http://www.linuxtorrents.com/tb/announce.php:80 ). I doubt you'll be using other ports, but if you ever do, you can easily add to or edit this area.

After that, the $DEFAULTBASEURL will be your url, as said before, like so.
http://www.linuxtorrents.com/tb (NO TRAILING SLASH)

Following, you can choose to make $MEMBERSONLY true or false. True means they must sign up to use it, false means anyone can use it.

The $PEERLIMIT option will not actually stop people from downloading, it will delete older torrents when the total amount of peers exceeds the limit, in order to make room. I reccomend you leave this as a high number, the default (as of this writing) is 50000.

The $SITEEMAIL is the email address people will see as the 'sender' to their sign up emails. As well, the $SITENAME is the name people will see on the front page and in the email as well.

That's all for bittorrent.php.

Please Note: I have been hearing of problems using subdirectories.  Please do not use /tb type subdirectories.  If possible, use a subdomain (tb.linuxtorrents.com).  There is no working workaround as of this writing.
3.
Static Edits
These edits will take place only on the page you edit them, unlike the dynamic edits in bittorrent.php which affect the whole site.
a.
URL on HomePage
This one's so easy.
Edit index.php
Scroll down to the bottom and find the Disclaimer. Replace the
(www.torrentbits.org)
with your own site, or this code (to make it depend on bittorrent.php, doesnt make ANY extra load on your server, so this is a good idea) provided here.
(<?PHP echo $DEFAULTBASEURL ?>)
Save the file, you're done.
b.
FAQ
You can edit the faq if you like, it's faq.php, but that's really up to you, I'm just here to tell you that you have to edit the php, it's not in the DB, and there is no tool to do this.

This section was such a ripoff.
c.
Staff Page
You can have a static (current, but blank) page, which decreases load on the mysql server, but doesnt show if the users are online, and isn't as easy to make.

If your site isn't going to be used too stressfully, or it can handle the load, use the dynamic version. I'll cover both.
1.
Dynamic Staff Page
Warning! This uses the MySQL db and puts load on the server. Fortunately it's not much of a load.

Thanks to SKORPiUS of TorrentBits, I have code which will get the staff from the Database automatically.

It's a large piece of code, here's what it'll be replacing.

<? begin_frame("Staff"); ?>
<? end_frame(); ?>

<? begin_frame("Current uploaders"); ?>
<? end_frame(); ?>

<? begin_frame("Moderators"); ?>
<? end_frame(); ?>

That's the old code. The NEW code (by SKORPiUS) follows.

<?
// Get current datetime
$dt = gmtime() - 180;
$dt = sqlesc(get_date_time($dt));
// Search User Database for Moderators and above and display in alphabetical order
$res = mysql_query("SELECT * FROM users WHERE class>=".UC_MODERATOR.
" AND status='confirmed' ORDER BY username" ) or sqlerr();
while ($arr = mysql_fetch_assoc($res))
{
$staff_table[$arr['class']]=$staff_table[$arr['class']].
"<td class=embedded><a class=altlink href=userdetails.php?id=".$arr['id'].">".
$arr['username']."</a><sup><font color=#".
("'".$arr['last_access']."'">$dt?"000066>On":"999999>Off" )."line</font></sup></td>".
"<td class=embedded><a href=sendmessage.php?receiver=".$arr['id'].">".
"<img src=".$pic_base_url."button_pm.gif border=0></a></td>".
"<td class=embedded><a href=mailto:".$arr['email'].">".
"<img src=".$pic_base_url."button_mail.gif border=0 alt=".$arr['email']."></a></td>";
// Show 3 staff per row, separated by an empty column
++ $col[$arr['class']];
if ($col[$arr['class']]<=3)
$staff_table[$arr['class']]=$staff_table[$arr['class']]."<td class=embedded>&nbsp;</td>";
else
{
$staff_table[$arr['class']]=$staff_table[$arr['class']]."</tr><tr height=15>";
$col[$arr['class']]=1;
}
}
?>

<table width=725 cellspacing=0>
<tr>
<!-- Define table column widths -->
<td class=embedded width="125"><b>SysOp</b></td>
<td class=embedded width="25">&nbsp;</td>
<td class=embedded width="35">&nbsp;</td>
<td class=embedded width="85">&nbsp;</td>
<td class=embedded width="125">&nbsp;</td>
<td class=embedded width="25">&nbsp;</td>
<td class=embedded width="35">&nbsp;</td>
<td class=embedded width="85">&nbsp;</td>
<td class=embedded width="125">&nbsp;</td>
<td class=embedded width="25">&nbsp;</td>
<td class=embedded width="35">&nbsp;</td>
</tr>
<tr>
<td class=embedded colspan=11><hr color="#4040c0" size=1></td>
</tr>
<tr height=15>
<?=$staff_table[UC_SYSOP]?>
</tr>
<tr><td class=embedded colspan=11>&nbsp;</td></tr>
<tr><td class=embedded colspan=11><b>Administrators</b></td></tr>
<tr><td class=embedded colspan=11><hr color="#4040c0" size=1></td></tr>
<tr height=15>
<?=$staff_table[UC_ADMINISTRATOR]?>
</tr>
<tr><td class=embedded colspan=11>&nbsp;</td></tr>
<tr><td class=embedded colspan=11><b>Moderators</b></td></tr>
<tr><td class=embedded colspan=11><hr color="#4040c0" size=1></td></tr>
<tr height=15>
<?=$staff_table[UC_MODERATOR]?>
</tr>
</table>


It includes the online status and such. I would reccomend it, but please back up your original staff.php which you will use if you find this dynamic version too demanding.
2.
Static Staff Page
If you do not want the page to call the database each time, then edit the staff page accordingly. It's quite simple and I do not feel it needs much explanation. In fact, I'd reccomend you use the dynnamic code just once, copy the source code from that for the admins, paste it in the static, and repeat for all the groups. This will result in a very nice layout with a minimal amount of work.
D.
Making Yourself Staff
Ah, Isn't it nice to get most of that crap out of the way? Now we're going to actually sign up and use tb, since it's mostly done! Just sign up as normal, use a real email, and then follow these instructions.

Open your tb database (preferably in phpmyadmin, if you use cpanel there is a link to phpmyadmin at the bottom of the MySQL Databases page, titled phpMyAdmin.
Go to username_tb database.
Select the 'users' table.
Click the "Browse" tab.
Click the Icon next to your name (the one thats not the trash bin).
Find the Field titled "class", and make yourself a 6.

There, you're now the sysop, congrats.
E.
Filling in the Blanks
Damn, there's a large error on the front page! Oh, that's right, there's no poll. Lets fix that.
1.
Adding the Poll
In your torrentbits clone site (http://www.linuxtorrents.com/tb is our example) open makepoll.php (http://www.linuxtorrents.com/tb/makepoll.php). Make a poll.

Yay, no more weird bug.
2.
Creating Forums
Sadly, there is no EASY way to create forums. You must do this in the phpmyadmin.Fortunately, phpmyadmin makes everything easy. You should still be in phpmyadmin since you edited yourself to be admin. If not, go back to III. D. (3d omg) and get to that section. However, instead of choosing the Users table, you'll choose the Forums table.

After loading the forums table, hit the Insert tab.
Fill in the ID (1 is fine, then the next one is 2, and so on)
Fill in the Name (Like "General Chat")
Fill in the Description ("Talk here you bitches")

The next two areas, minclassread and minclasswrite, can be left at 0 if these are public forums. If you want a forum for uploaders and above, make it 3 in both areas.

The list matches the user classes list (forget about the donators and other class).

  • User = 0
  • Power User = 1
  • VIP = 2
  • Uploader = 3
  • Moderator = 4
  • Admin = 5
  • SysOp = 6
I don't think you'd make a minclassread/write forum for 6, as you're the only one.
But there are some weirdos out there who talk to themselves. Moving on...
3.
Deleting the Call of Duty Section
Gah! I don't run a CoD server, why do I need this? Answer: You don't!

Open index.php and remove the bit starting at

function sortusers($a, $b)
{
$score_a = trim(substr($a, 4, 5));
$score_b = trim(substr($b, 4, 5));


and ending at

print("<p>Please install <a href=http://www.callofduty.com/patch/><b>this
patch</b></a> and <a href=ftp://torrentbits.org/games/callofduty/maps/><b>these
maps</b></a> before joing!</p>");


, as that whole section is just for call of duty. I'd also reccomend you back up index.php before you do so, in case you delete something else too by accident.
4.
Simple, have them sign up, go to Profile, at the bottom click search for user, put in their name, and make them another staff/uploader/vip/whatever.
F.
Finalization - Lets get this over with
1.
Allowing Uploads
Remember that directory you made earlier to store your torrents in? I reccomended you to use /home/username/tb/torrents didn't I? Now heres setting it up.

If you have shell (ssh) access, login and type
chmod 0777 -R tb
or if you don't, but have FTP, login and right click the tb folder, check all the boxes OR put in 0777 as the chmod code (if only 3 chars, 777). Check "recursive" if it is an option. You should now be able to upload torrents.
2.
PeerGuardian Blocklist
I don't know WHY you'd want to do this, but hey, that's your thing.

Open importpg.php (example: http://www.linuxtorrents.com/tb/importpg.php ) and the script will download the list and ban all those ips.
IV.
BugFixing
Lets see, what bugs? Oh yeah, the inherent ones.

If when someone clicks to download a torrent and it gives a 404 error, something like "/download/1/Knoppix.3.4-20040517.torrent could not be found", then you have two options. One is easy, one is only available if you run the server and know things.

The easy way:

Edit details.php
Go to Line 166 (or around it) to find this code

print("<tr><td class=rowhead width=1%>Download</td><td width=99% align=left>
<a class=\"index\" href=\"download/$id/" . rawurlencode($row["filename"]) .
"\">" . htmlspecialchars($row["filename"]) . "</a></td></tr>");


Replace the part
href=\"download/$id/"
with
href=\"download.php/$id/"

The HARD way:

Edit access.conf for apache httpd
Add MultiViews (Google it up)
Restart apache.
V. Upgrading
Please save your old copy and use it as a guide to copy over important parts.  The file secrets.php should copy over fine without need for any editing, but other things might have upgrades. Feel free to use this guide to find out what to remove, what to add, and all that.
1.
From 0405120511 to 0405211709
Everything in the config phps are pretty much the same.  The main thing are these SQL Queries, which must be pasted in.  These will make the necessary changes, and were checked realtime in database comparison.  If there are subsequent upgrades and you have the same version this starts with (0405120511) then you must do each upgrade in order.  If you have the newer version, you do not need to use this part.

CREATE TABLE blocks (
  id int(10) unsigned NOT NULL auto_increment,
  userid int(10) unsigned NOT NULL default '0',
  blockid int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (id),
  UNIQUE KEY userfriend (userid,blockid)
) TYPE=MyISAM;

CREATE TABLE friends (
  id int(10) unsigned NOT NULL auto_increment,
  userid int(10) unsigned NOT NULL default '0',
  friendid int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (id),
  UNIQUE KEY userfriend (userid,friendid)
) TYPE=MyISAM;

ALTER TABLE `peers` ADD `agent` VARCHAR( 60 ) NOT NULL ,
ADD `finishedat` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ;

ALTER TABLE `users` CHANGE `password` `old_password` VARCHAR( 40 ) NOT NULL,
DROP `warnedat` ,
ADD `passhash` VARCHAR( 32 ) NOT NULL ,
ADD `warneduntil` DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL ;

That will upgrade the tables and will allow you to login again (it does break login if you do not add these tables).

Notice: This upgrade removes the cleartext passwords from the database, apparently because I made a big issue by putting it in my userinfo at TB, plus they were h4xed once.  The password is moved to old_password and after you login once, it is removed and moved to passhash as an encrypted md5 hash.  Yay team!  (Everyone, beg for TimmyTurner's warn to be removed, he was new and trying to be funny, but not in a smart way).

Note: I will not provide direct support, but if I hear of a problem in the forums related to this and it's a common problem, I'll do something.

I give the torrentbits.org team full permission to host this on their site, link to it from their FAQ, and all that. Because them hosting it just gives it a lot more crediblity.

I guess this isn't good enough for VIP.
Time to commit seppuku.