Gazelle Article 3: Anonymous Links, Ticket System, and a Freeleech Tool

October 05, 2009 by MFSL

We’re back with Part 3 of our exclusive series on how to install Gazelle. In this article, we explain how to add a script to anonymize all outgoing links through anonym.to. Also up, we show how to incorporate a ticket system so that beta testers and members can report site bugs and provide feedback. Last - but not least - we explain how to add a global freeleech to the tracker with the ability to enable/disable it through the Gazelle Toolbox utility.

Hello readers. I’m MFSL - here with the third article on gazelle development. Sorry about the delay between article 2 and this third installment, I was having some trouble with mySQL and made a bit of a noob mistake. ‘ is NOT the same as `. Thank you ilias for pointing that out to me. The current beta members have requested many features and i am here to deliver a few of them. Lets get started!

Anonym.to added to external links

This was one of the many features requests by are beta members and not only is it very helpful in keeping our site secret but it is also fairly easy to implement. Login with your SFTP client and navigate to / open /site/classes/class_text.php. Replace the urls function with:

function urls($Str) {
$Str = preg_replace(”/(\A|[^=\]‘\”a-zA-Z0-9])((http|ftp|https|ftps|irc):\/\/[^<>\s()]+)/i”,
“\\1<a href=’http://www.anonym.to/?\\2′ target=’_blank’>\\2</a>”, $Str);

$Str = str_replace(”http://www.anonym.to/?http://” . NONSSL_SITE_URL, “http://” . NONSSL_SITE_URL, $Str);
$Str = str_replace(”http://www.anonym.to/?https://” . SSL_SITE_URL, “https://” . SSL_SITE_URL, $Str);

// VULNERABLE
// Local site links
$Replace[]=’/(<a href=[\'"]?)?http(s)?:\/\/www\.’.preg_quote(NONSSL_SITE_URL,’/').’\/?([^<>\s]*)([\'"]>)?/i’;
$Replace[]=’/(<a href=[\'"]?)?http(s)?:\/\/’.preg_quote(NONSSL_SITE_URL,’/').’\/?([^<>\s]*)([\'"]>)?/i’;
$Replace[]=’/(<a href=[\'"]?)?http(s)?:\/\/’.preg_quote(SSL_SITE_URL,’/').’\/?([^<>\s]*)([\'"]>)?/i’;
$Str=preg_replace_callback($Replace, array(’TEXT’,'fix_url’),$Str);
return $Str;
}

And it works :).

Using anonym.to for anonymous links

Leto’s Updated Ticket System

This may be one of the best suggestions we received. Leto did a great job with this. The current ticket system was… lacking, but Leto turned it into something that does its job perfectly. Here is my own mirror of Leto’s guide, it is far to long to post in with this article (letoticketsys.txt - or here). There are some things you should do however. Make sure you backup your site before you do this! One mistake and your in for a world of hurt. Also, don’t try and use PuTTY for file editing here, it’s far to tedious on this scale. Here are some pictures of the Ticket System in action!

Ticket System

Global Freeleech Staff Tool

Yet another feature that Raketa showed me. Lets get this started, everybody likes freeleeches!

First ssh in and login to mysql. Then execute the following code

USE <yourdatabase>
DROP TABLE IF EXISTS `mod_core`;
CREATE TABLE IF NOT EXISTS `mod_core` (
`mod_option` varchar(60) NOT NULL,
`mod_setting` int(12) NOT NULL default ‘0′,
PRIMARY KEY (`mod_option`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `mod_core` (`mod_option`, `mod_setting`) VALUES
(’global_freeleech’, 0);

ALTER TABLE `torrents` ADD `was_free` SET( ‘0′, ‘1′ ) NOT NULL DEFAULT ‘0′

Now that we got sql out of the say the rest is just Copy + Pasting

Open classes/script_start.php

Find:

function check_perms($PermissionName,$MinClass = 0) {
if ($_SESSION['logged_user']['Permissions'][$PermissionName] && $_SESSION['logged_user']['Class']>=$MinClass) { return true; } else { return false; }
}

Add this underneath of it:

function enable_freeleech($enable) {
global $DB;
$DB->query(”SELECT mod_setting FROM mod_core WHERE mod_option = ‘global_freeleech’”);
list ($mod_setting) = $DB->next_record();
if ($enable == ‘1′ && $mod_setting != ‘1′) {
$DB->query(”UPDATE torrents SET was_free=’1′, flags = ‘2′ WHERE FreeTorrent=’1′”);
$DB->query(”UPDATE torrents SET FreeTorrent=’1′, flags = ‘2′ WHERE FreeTorrent=’0′”);
$DB->query(”UPDATE mod_core SET mod_setting=’1′ WHERE mod_option=’global_freeleech’”);
} elseif($enable == ‘0′ && $mod_setting != ‘0′) {
$DB->query(”UPDATE torrents SET FreeTorrent=’0′, flags = ‘2′ WHERE FreeTorrent=’1′”);
$DB->query(”UPDATE torrents SET FreeTorrent=’1′, flags = ‘2′ was_free=’0′ WHERE was_free=’1′”);
$DB->query(”UPDATE mod_core SET mod_setting=’0′ WHERE mod_option=’global_freeleech’”);
}
}

Open classes/permissions_form.php

Find:

<? display_perm(’admin_login_watch’,'Can manage login watch.’); ?>

Add this underneath of it:

<? display_perm(’admin_enable_freeleech’,'Can enable site-wide Freeleech’); ?>

Open sections/tools/index.php

Find:

case ‘polls’:
if (!check_perms(’admin_manage_polls’)) { error(’403′); }

if ($_REQUEST['id']) {
$Val->SetFields(’question’,1,’string’,'You did not enter a valid question for this poll.’);

Add this above:

case ‘freeleech’:
include(’managers/freeleech.php’);
break;

case ‘enable_freeleech’:
enable_freeleech($_POST['go_freeleech']);
header(’Location: tools.php’);
break;

Open sections/tools/tools.php

Find:

<? } if (check_perms(’admin_manage_news’)) { ?>
<tr><td><a href=”tools.php?action=news”>News</a></td></tr>

Add this underneath:

<? } if (check_perms(’admin_enable_freeleech’)) { ?>
<tr><td><a href=”tools.php?action=freeleech”>Global Freeleech</a></td></tr>

Create a new php file (sections/tools/managers/freeleech.php)

Add this code to it:

<?
enforce_login();
if(!check_perms(’admin_enable_freeleech’)){ error(403); }

show_header(’Enable Freeleech’);
$DB->query(”SELECT mod_setting FROM mod_core WHERE mod_option = ‘global_freeleech’”);
list ($mod_setting) = $DB->next_record();
if ($mod_setting == ‘1′) {
$enabled = ‘CHECKED’;
} else {
$disabled = ‘CHECKED’;
}
?>
<div class=”thin”>
<h2>Enable Freeleech</h2>
<form action=”tools.php” method=”post”>
<div class=”box pad”>
<input type=”hidden” name=”action” value=”enable_freeleech” />
Enable Freeleech:
<input type=”radio” name=”go_freeleech” value=”1″ <?=$enabled?>>
<br />
Disable Freeleech:
<input type=”radio” name=”go_freeleech” value=”0″ <?=$disabled?>>
<br />
<div class=”center”>
<input type=”submit” value=”Do it” />
</div>
</div>
</form>
</div>

<?
show_footer();

?>

Open sections/upload/upload_handle.php

Find:

//if($T['Format'] == “‘MP3′”){
// $FreeTorrent=”‘1′”;
//} else {
// $FreeTorrent=”‘0′”;
//}

Add this underneath:

$DB->query(”SELECT mod_setting FROM mod_core WHERE mod_option = ‘global_freeleech’”);
list ($mod_setting) = $DB->next_record();
if ($mod_setting == ‘1′) {
$FreeTorrent=”‘1′”;
} else {
$FreeTorrent=”‘0′”;
}

And that’s all she wrote. Below is a picture of the Tools page and the Freeleech Tool itself.

Freeleech Tool