Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
User Posts

Go to Profile

Sql inject — 2023-06-16 18:47:31 in v3 Support
Also all GET/POST variables that expect a integer from user-input (url or form submission), should always be wrapped with intval(). This is because it filters out potentially malicious code, and delivers a real integer.

somesite.com/torrents-details.php?id=5guys

Intval filters and returns:

somesite.com/torrents-details.php?id=5

Additionally, anyone can run a for loop on a torrent index and collect all of the IDS and store them in a array and then mass-download them all from any account. This produces abuse. Encrypted links are the way to deal with this.

The problem ?id=5, 6, 7, 8, 9, etc
donate_block.php — 2023-06-02 15:10:33 in v3 Support
Thanks Spirit 😀
donate_block.php — 2023-06-01 14:55:23 in v3 Support
Do you have success with donations? Is paypal risky?
Server Load help — 2023-05-28 17:47:15 in General Chat
You should do this in a viewport or else your smaller font size will be chicken scratch on a iPhone for example.

Once you have a viewport assigned in your .css file, you can set sizes based on the clients resolution.

This steps up suitable rendering that is both compatible and normalized.
Ajax Shoutbox V3 — 2023-05-27 18:58:49 in v3 Mods in Progress
The JS is really old.

It uses document.getElementById(...) which is legacy supported in most browser engines for a long time to come, but this is most likely the problem on a new browser like Chrome/Edge/Opera. I would replace with document.querySelector(...)

Try on Firefox first before editing the JS, as they have their own browser engine that has nothing to do with Chromium project. That will rule that out before updating anything.
Ajax Shoutbox V3 — 2023-05-27 04:21:19 in v3 Mods in Progress
Just point $row to the fetch method.

if ($row = mysqli_fetch_assoc($query)) { ... }

PHP automatically checks if result set is available, otherwise it returns false. Thats all you need to do. By wrapping $row, your assigning it so you can read it in the scope { ... }

---

Now if you want to check if query result(s) are empty first, you do this

if (!($row = mysqli_fetch_assoc($query))) {
  // $row not available - INSERT, DELETE FROM, etc
} else {
   // $row available - UPDATE, DELETE FROM, continue, etc
}


So you dont need to use this

$mysqli->mysqli_num_rows()
$pdo->getRowCount()


These methods above are good for counters, database related tracking (eg. inserting to column "Imported row 1/27 successful" or presenting a count on front-end webpage. I personally use a $i++ counter at all times. I dont see the need for these and the overhead associated. Raw PHP as much as possible (performance).


$query = SQL_Query_exec("SELECT id FROM users WHERE username = " . sqlesc($Data));
if ($row = mysqli_fetch_assoc($query)) {
  $Userid = $row['id'];
  SQL_Query_exec("DELETE FROM ajshoutbox WHERE uid = " . sqlesc($Userid)) or sqlerr(__FILE__, 293));
  execcommand_message();
}
Server Load help — 2023-05-23 03:07:22 in General Chat

if (extension_loaded('com_dotnet')) {
   // The com_dotnet extension is loaded
   $wmi = new COM('WinMgmts:\\\\.');
   // Rest of your code here
} else {
   // The com_dotnet extension is not loaded or supported
   // Handle the situation accordingly
   echo "The com_dotnet extension is not available.";
}
New getip function — 2023-05-21 23:29:19 in v3 Support
Most welcome!
New getip function — 2023-05-21 18:40:07 in v3 Support
Been having invalid IPV6 addresses on and off for a little while, so this seems to resolve that and updates the IPs correctly, and some filtering on the IPV4 compatible prefix. Takes care of proxies as the original, and lets you convert the IPV4 address to a compatible IPV6 address.


function getip($convertToIPv6 = false)
{
   $trustedHeaders = [
       'HTTP_CLIENT_IP',
       'HTTP_X_FORWARDED_FOR',
       'HTTP_X_FORWARDED',
       'HTTP_X_CLUSTER_CLIENT_IP',
       'HTTP_FORWARDED_FOR',
       'HTTP_FORWARDED',
       'HTTP_CF_CONNECTING_IP',
       'REMOTE_ADDR'
   ];

   $ip = '';
   foreach ($trustedHeaders as $header) {
       if (!empty($_SERVER[$header])) {
           $ip = $_SERVER[$header];
           break;
       }
   }

   if (empty($ip)) {
       $ip = $_SERVER['REMOTE_ADDR'];
   }

   if (strpos($ip, ',') !== false) {
       $ip = explode(',', $ip)[0];
   }

   if (strpos($ip, '::ffff:') === 0) {
       $ip = substr($ip, 7);
   }

   $ip = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);

   if ($convertToIPv6 && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
       $ip = '::ffff:' . $ip;
   }

   return $ip;
}
Server Load help — 2023-05-21 15:54:38 in General Chat
It wont work if the OS doesn't support the system calls to pull these stats. It's not uncommon.
Seed Time — 2023-05-19 07:13:57 in v2.08 Support
No problem. I can tell you know a thing or two. So naturally I feed what I know. I run my own codebase, but its a early migration away from V3 and its 95% in-house. We all start somewhere. I agree, the peer time to take into effect is faulty and I personally should consult that myself on my copy of cleanup.

Get into PECL Parallel processing (PHP 8.1+), it uses all your CPU cores to run all the jobs simultaneously, way faster on a larger tables like torrent table (LONGBLOB, no physical meta files).  

Here is a sample of just that, with locks so if the job its too heavy, it pushes it to the end of the queue so the rest of the jobs are fired first (ratiowarn is always locked for later, huge table).

run_jobs.php

<?
// Cleanup V2 - PECL Parallel support
$tasks = [
   'cleancache' => [1],
   'seedbonus' => [],
   'comments' => [],
   'checkexpiredwarns' => [],
   'cleanlogs' => [1],
'cleannotifs' => [1],
'cleanshoutbox' => [1],
   'autopromote' => [],
   'autofreeleech' => [],
   'autodemote' => [],
   'pendingusers' => [],
   'privseeders' => [],
'checkdead' => [],
   'startsync' => [],
'ratiowarn' => [] // Heavy
];

$classFiles = [
   'Extensions',
   'Cleanup'
];

$results = [];
$runtime = new \parallel\Runtime;

foreach ($tasks as $taskName => $taskParams) {
   $future = $runtime->run(function () use ($taskName, $taskParams, $classFiles) {
       spl_autoload_register(function ($className) use ($classFiles) {
           if (!empty($classFiles) && in_array($className, $classFiles)) {
               include_once "classes/$className.php";
           }
       });
       $cleanup = new \Cleanup;
       $lockName = "cleanup_$taskName";
       if ($cleanup->acquireLock($lockName)) {
           if (method_exists($cleanup, $taskName)) {
               call_user_func_array([$cleanup, $taskName], $taskParams);
               echo "Task '$taskName' completed.\n";
           }
           $cleanup->query_params('DELETE FROM locks WHERE name = :name', array(
'name' => $lockName
));
       } else {
           echo "Task '$taskName' skipped due to a lock.\n";
       }
   });
}

echo "All tasks completed.\n";


Cleanup.php

interface Tasks
{
   public function seedbonus();
   public function comments();
   public function checkexpiredwarns();
   public function ratiowarn();
   public function cleanlogs();
   public function autopromote();
   public function autofreeleech();
   public function autodemote();
   public function checkdead();
   public function pendingusers();
   public function privseeders();
   public function startsync();
   public function cleanshoutbox();
public function cleancache();
public function cleannotifs();
public function acquireLock($name);
}

class Cleanup extends Extensions implements Tasks
{
public function acquireLock($name) {
       $lock = $this->query_params('INSERT INTO locks (name, created_at, updated_at) VALUES (:name, NOW(), NOW()) ON DUPLICATE KEY UPDATE updated_at = NOW()', array(
'name' => $name
));
       return $lock;
   }


The code formatting sucks on here but you get the idea.
Seed Time — 2023-05-18 22:19:09 in v2.08 Support
Also you want to make sure you have the cleanup.php script and have it triggered to run every 30mins or so (or 6 hours on thousands of torrents). Bump it up over time as the database grows.

The cleanup script will take care of all of this, peers, ratio warnings, comments, etc. Its best to run this on a cronjob and store it back a directory ../ before root, for security.
Seed Time — 2023-05-18 22:15:37 in v2.08 Support
Its bad design.

Peers seeding torrents should be counted by reference in the peers table (user id, passkey, etc) as a total seed count, as they currently exist. That is the way. Row removed, one less seed for that peer.

And announce should automatically delete peer when client stops. Not completed, only stopped. Paused should retain table row, but deny inbound connections - eg. fsockopen()

event=completed assumes seed state, and it is seed state as clients rush the event state to seeding status by design automatically, so that gives you a large window of determining that state or not. Otherwise, the row should be removed for that torrent when event=stopped is detected in announce.

That is a lot of overhead math and there is much faster methods to that even if I deemed it relevant to good design.

You have to remember, this is old code from 2007-2012, and basically left frozen in time. Your best using the MVC version or rolling your own codebase yourself. Its sorts all this crap out and runs on any version of PHP, not exactly the case for V3 as-is.
I rebooted because I wanted a fresh take at the adjustment. You do not have to reboot. Changes should be immediate. Just make sure your torrents are still downloading, and let me know if anything comes up of error.

Working on this end 100%. Automatically reducing some peers to 1-2 connections according to my logs. Server is faster.
You are most welcome!

This code will go into announce.php

My server has been handling 1300 peers and peak load, while still slow its a big improvement compared to how the server was before I wrote this code. I gave it 12 hours (overnight), and it works great!

Thank you for the credit, for that I will do you a favor. Give me a little bit.

---

Open announce.php and find


$userid = 0;
if ($MEMBERSONLY){
//check passkey is valid, and get users details
$res = SQL_Query_exec("SELECT $userfields FROM users u INNER JOIN groups g ON u.class = g.group_id WHERE u.passkey=".sqlesc($passkey)." AND u.enabled = 'yes' AND u.status = 'confirmed' LIMIT 1") or err("Cannot Get User Details");
$user = mysqli_fetch_assoc($res);
if (!$user)
err("Cannot locate a user with that passkey!");
   if ($user["can_download"] == "no")
       err("You do not have permission to download.");
$userid = $user["id"]; //etc
}


and replace with


if ($MEMBERSONLY){
//check passkey is valid, and get users details
$res = SQL_Query_exec("SELECT $userfields FROM users u INNER JOIN groups g ON u.class = g.group_id WHERE u.passkey=".sqlesc($passkey)." AND u.enabled = 'yes' AND u.status = 'confirmed' LIMIT 1") or err("Cannot Get User Details");
$user = mysqli_fetch_assoc($res);
if (!$user)
err("Cannot locate a user with that passkey!");
   if ($user["can_download"] == "no")
       err("You do not have permission to download.");
$userid = $user["id"]; //etc

$torrent_id = 0;
$res2 = SQL_Query_exec("SELECT id FROM torrents WHERE info_hash = ".sqlesc($GLOBALS['info_hash'])) or err("Cannot Get Torrent Details");
$torrent = mysqli_fetch_assoc($res2);
$torrent_id = $torrent['id'];
}


Now the code is ready


if (array_key_exists('key', $data)) {
$max_connections = $site_config['max_conn_allowed']; // default: 5
$torrent_max_connections = 50;
$reduced_connections = min(5, $torrent_max_connections);

$user_id = sqlesc($userid);
$torrent_id = sqlesc($torrent_id);

$checkdata = mysqli_query($GLOBALS['DBconnector'], "SELECT clientkey FROM peers WHERE id = $user_id AND torrent_id = $torrent_id AND seeder = 'no' AND completed = 0");
$num_connections = mysqli_num_rows($checkdata);
$unique_clientkeys = array();
while ($row = mysqli_fetch_assoc($checkdata)) {
$unique_clientkeys[] = $row['clientkey'];
}
$num_unique_clientkeys = count(array_unique($unique_clientkeys));
if ($site_config['max_conn_increased'] === 0) {
if ($num_unique_clientkeys > $max_connections) {
mysqli_query($GLOBALS['DBconnector'], "DELETE p FROM peers p LEFT JOIN (SELECT clientkey FROM peers WHERE id = $user_id ORDER BY RAND() LIMIT $user_id) excluded ON p.clientkey = excluded.clientkey WHERE p.user_id = $user_id AND p.torrent = $torrent_id AND p.seeder = 'no' AND p.completed = 0 AND excluded.clientkey IS NOT NULL");
$num_connections = $reduced_connections;
}
if ($num_unique_clientkeys > 0) {
header('X-Connection-Limit: ' . $num_unique_clientkeys);
}
} else {
header('X-Connection-Limit: ' . $max_connections);
}
mysqli_close($GLOBALS['DBconnector']);
}


Add to site config file


'max_conn_allowed' = 5;
'max_conn_increased' = 0; // 0: manage connections, 1: no control (open)



This is my last forum post. So just wanted to share the last task I was assigned with.
I'm too far ahead to be any use here. I love to help but I like to see activity and feedback too. Both of those are lacking unfortunately. Time is also not on my side going forward, which effects my own site in the process. I've managed a good balance.

Now, this code checks the number of connections a user has established on the tracker for the torrent their starting/resuming, and if the number of connections exceeds a certain limit, it takes actions to adjust or reduce the number of connections, notifies user and logs the event.

Its up to you to port it for your tracker. I dont do old-school conversions anymore, code is as-is.


if (array_key_exists('key', $data)) {
$max_connections = $user_row['max_conn_allowed'];
$torrent_max_connections = 50;
$reduced_connections = min(5, $torrent_max_connections);
$checkdata = $db->query_params("SELECT clientkey FROM peers WHERE user_id = :user_id AND torrent_id = :torrent_id AND seeder = 'no' AND completed = 0", array(
'user_id' => $user_id,
'torrent_id' => $torrent_id
));
$num_connections = count(array_unique(array_column($checkdata->fetchAll(), 'clientkey')));
if ($user_row['max_conn_increased'] === 0) {
if ($num_connections > $max_connections) {
$db->query_params("DELETE p FROM peers p LEFT JOIN (SELECT clientkey FROM peers WHERE user_id = :user_id ORDER BY RAND() LIMIT :limit) excluded ON p.clientkey = excluded.clientkey WHERE p.user_id = :user_id AND p.torrent_id = :torrent_id AND p.seeder = 'no' AND p.completed = 0 AND excluded.clientkey IS NOT NULL", array(
'user_id' => $user_id,
'torrent_id' => $torrent_id,
'limit' => $reduced_connections
));
$num_connections = $reduced_connections;
}
if ($num_connections > 0) {
header('X-Connection-Limit: ' . $num_connections);
$account->sendNotif($user_row['user_id'], 'Connections reduced (' . $num_connections . ')', 'Tracker');
$logevent = $db->query_params('INSERT INTO announce_log (message, added) VALUES (:message, NOW())', array(
'message' => 'Connections reduced (' . $num_connections . ')'
));
}
} else {
header('X-Connection-Limit: ' . $max_connections);
}
}



ALTER TABLE users ADD COLUMN max_conn_increased TINYINT DEFAULT 0 NULL;
ALTER TABLE users ADD COLUMN max_conn_allowed TINYINT DEFAULT 5 NULL;


This is a good idea for most, who dont want their server flooded with so many connections. This manages the clients connection pool and makes decisions based on unique client keys (connections). uTorrent generates a new client key per each connection. So we compare keys and deny or accept the connection while providing the appropriate headers to maintain limitation state.

This is at user-level, so insert code after passkey authentication logic. I'm aware people can find other ways to flood, but that is outside of the scope of this mod.
Pssstt..

Users wont like being restricted to basic privilege's like removing their potentially incorrect update / wrong / corrected .torrent file, as per the screenshot. These are things that should be addressed. This could impact the tracker with a high rate of dead torrents and limited action to replace them.

I would never restrict my users from being to manage their uploads, it just doesnt make sense. I would have many incorrect uploads just sitting there. Dont look good lol
I think this can be done another way as well, at least on my end. One can also calculate torrent size against completed sized, and deduct the difference and add that value to a table to tracking partials/H&Rs.

Personally this makes sense.

Using a table or whatever, you can list the partials, links etc and allow the user to have insight into how much they "downloaded and left".

This can be applied to movies, games, appz, etc
This code defines two functions. The first function, crc32c(), computes the CRC32C hash of a string. The second function, calculate_node_id(), calculates a valid node ID given an IP address and the number of octets to consider.

To use this code, you can call the calculate_node_id() function with an IP address (represented as an array of four or eight integers) and the number of octets to consider (4 for IPv4, 8 for IPv6). The function returns an array of 20 integers representing the node ID. You can convert this array to a string representation using the sprintf() function, as shown in the example usage code.


function crc32c($crc, $data) {
   static $table = null;

   if ($table === null) {
       $table = array();
       for ($i = 0; $i < 256; ++$i) {
           $crc = $i;
           for ($j = 0; $j < 8; ++$j) {
               $crc = ($crc & 1) ? (0x82f63b78 ^ ($crc >> 1)) : ($crc >> 1);
           }
           $table[$i] = $crc;
       }
   }

   $crc = ~$crc;
   foreach (str_split($data) as $byte) {
       $crc = $table[($crc ^ ord($byte)) & 0xff] ^ ($crc >> 8);
   }
   return ~$crc;
}

function calculate_node_id($ip, $num_octets) {
   $v4_mask = array(0x03, 0x0f, 0x3f, 0xff);
   $v6_mask = array(0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff);
   $mask = ($num_octets == 4) ? $v4_mask : $v6_mask;

   for ($i = 0; $i < $num_octets; ++$i) {
       $ip[$i] &= $mask[$i];
   }

   $rand = mt_rand(0, 0xff);
   $r = $rand & 0x7;
   $ip[0] |= $r << 5;

   $crc = crc32c(0, pack('C*', ...$ip));

   $node_id = array();
   $node_id[] = ($crc >> 24) & 0xff;
   $node_id[] = ($crc >> 16) & 0xff;
   $node_id[] = (($crc >> 8) & 0xf8) | (mt_rand(0, 0x7));
   for ($i = 3; $i < 19; ++$i) {
       $node_id[] = mt_rand(0, 0xff);
   }
   $node_id[] = $rand;

   return $node_id;
}

// example usage
$ip = array(124, 31, 75, 21);
$num_octets = 4;
$node_id = calculate_node_id($ip, $num_octets);
print implode('', array_map('sprintf', array_fill(0, count($node_id), '%02x'), $node_id)) . "\n";
Abstract
This BEP specifies an extension to the BitTorrent DHT (BEP 5) to support scrapes via distributed counting based on bloom filters.

Rationale
Scrapes are an important part of the BitTorrent ecosystem as they allow users to assess the state of a torrent and clients to determine which swarm to select next in their seeding queue, without having to participate in the swarm first.

These options are currently not available in the absence of a tracker, this BEP aims to rectify this.


function estimateCount(array $bloom): float
{
   $m = 256 * 8;
   $k = 2;
   $c = $m - 1;
   for ($i = 0; $i < count($bloom); $i++) {
       $c -= ($bloom[$i] === 0) ? 8 : substr_count(decbin($bloom[$i]), '0');
   }
   $c = max(1, $c);
   $size = log($c / $m) / ($k * log(1 - 1 / $m));
   return $size;
}
function insertIP(array $ip, array &$bloom): void
{
   $hash = sha1(implode('.', $ip), true);
   $index1 = unpack('v', substr($hash, 0, 2))[1];
   $index2 = unpack('v', substr($hash, 2, 2))[1];
   $m = 256 * 8;
   $index1 %= $m;
   $index2 %= $m;
   $bloom[$index1 >> 3] |= (1 << ($index1 & 7));
   $bloom[$index2 >> 3] |= (1 << ($index2 & 7));
}


The insertIP function takes the bloom filter as an input and returns the estimated count of items in the bloom filter. The function first initializes the parameters m and k. It then calculates the number of zero bits in the bloom filter and uses it to estimate the count using the provided equation.

The estimateCount function takes the bloom filter as an input and returns the estimated count of items in the bloom filter. The function first initializes the parameters m and k. It then calculates the number of zero bits in the bloom filter and uses it to estimate the count using the provided equation.
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 1
  • Members: 0
  • Guests online: 1
  • Comments: 3
  • Messages: 1,728