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
Torrent Test
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / M-BiTsy / M-BiTsy Support

2021-01-22 20:26:41
Hoping to update github at the end of this month, just need to skip through admincp a bit more first

So ive added a torrent (just a old movie) so members can see the torrent page i have added a copy of the normal home page as well for viewing before i open site at https://torrenttrader.uk/example

On the torrent i added imdb (for show), i have rewritten the announce.php from scratch which is a pain in the arse so members are welcome to download the torrent to help test

If you download would you please post here which client you used or any issues, if it does not start immediately please give it a few minutes

https://torrenttrader.uk/torrents/read?id=1

ps = if you right click  on screen you can inspect and see mobile view
Last edited by M-jay warn on 2021-01-22 20:28:43
2021-01-22 21:08:19
Downloading now just fine using qbittorrent
2021-01-23 02:36:45
"request Reseed"? I'll gladly replicate this. Can you tell me what this does exactly? I can assume, but would appreciate a detail on this. Thank you
2021-01-23 04:11:43
here is the controller method mate just sends pm to owner/completed to reseed

   public function reseed()
   {
       if ($_SESSION["view_torrents"] == "no") {
           Session::flash('info', Lang::T("NO_TORRENT_VIEW"), URLROOT."/home");
       }
       $id = (int) $_GET["id"];
       if (isset($_COOKIE["reseed$id"])) {
           Session::flash('info', Lang::T("RESEED_ALREADY_ASK"), URLROOT."/home");
       }
       $res = DB::run("SELECT `owner`, `banned`, `external` FROM `torrents` WHERE `id` = $id");
       $row = $res->fetch(PDO::FETCH_ASSOC);
       if (!$row || $row["banned"] == "yes" || $row["external"] == "yes") {
           Session::flash('info', Lang::T("TORRENT_NOT_FOUND"), URLROOT."/home");
       }
       $res2 = DB::run("SELECT users.id FROM completed LEFT JOIN users ON completed.userid = users.id WHERE users.enabled = 'yes' AND users.status = 'confirmed' AND completed.torrentid = $id");
       $message = sprintf(Lang::T('RESEED_MESSAGE'), $_SESSION['username'], URLROOT, $id);
       while ($row2 = $res2->fetch(PDO::FETCH_ASSOC)) {
           DB::run("INSERT INTO `messages` (`subject`, `sender`, `receiver`, `added`, `msg`) VALUES ('" . Lang::T("RESEED_MES_SUBJECT") . "', '" . $_SESSION['id'] . "', '" . $row2['id'] . "', '" . TimeDate::get_date_time() . "', " . $message . ")");
       }
       if ($row["owner"] && $row["owner"] != $_SESSION["id"]) {
           DB::run("INSERT INTO `messages` (`subject`, `sender`, `receiver`, `added`, `msg`) VALUES ('Torrent Reseed Request', '" . $_SESSION['id'] . "', '" . $row['owner'] . "', '" . TimeDate::get_date_time() . "', " . $message . ")");
       }
       setcookie("reseed$id", $id, time() + 86400, '/');
       Session::flash('info', Lang::T("RESEED_SENT"), URLROOT."/home");
   }


Message received
STorrents2020 has requested a re-seed on the torrent below because there are currently no or few seeds:

https://torrenttrader.uk/torrents/read?id=1
Thank You!
Last edited by M-jay warn on 2021-01-23 06:15:18
2021-01-23 05:05:44
looking through the announce log and the only thing i can see wrong is the start column gets reset every time thats fixed,
been working on announce for ages bit by bit im surprised the v3 one works lol theres so many errors
like the connectable code should return bool not sure if that will throw big error in php 8  i used your function for that  :thum

been testing on multiple trackers and the only headache was utorrent thats because on the peer_id having dots in u455.g45.454  had to use hex2bin to format and seems to work
in peer table its hex2bin (like hash) so on announce response to client it sends that not the proper peer_id but seems to work flawless - the client can read info_hash so i asume it can for peer_id

any suggestions on collation on the column im using ut8mb84blah general ci - i know changing db engine would fix this but looking for something is MyISAM

the announce (one bencode function cause we hate it  :rofl )
<?php
// Error Reporting
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(0);
ini_set('error_log', '../data/logs/errors_log.txt');
ignore_user_abort(true);
require '../app/config/config.php';
require '../app/libraries/Database.php';
require '../app/models/Logs.php';
require '../app/libraries/TimeDate.php';
// Register custom exception handler
include "../app/helpers/exception_helper.php";
set_exception_handler("handleUncaughtException");
// Used for testing
define('__INTERVAL', 60);
define('__TIMEOUT', 120);

//Do some input validation
function valdata($g, $fixed_size = false)
{
   if (!isset($_GET[$g])) {
       die(track('Invalid request, missing data'));
   }
   if (!is_string($_GET[$g])) {
       die(track('Invalid request, unknown data type'));
   }
   if ($fixed_size && strlen($_GET[$g]) != 20) {
       die(track('Invalid request, length on fixed argument not correct'));
   }
   if (strlen($_GET[$g]) > 80) { //128 chars should really be enough
       die(track('Request too long'));
   }
}

function isConnectable($ipadress, $port) {
   $fp = @fsockopen($ipadress, $port, $errno, $errstr, 0.1);
   if (!$fp) {
       return false;
   } else {
       fclose($fp);
       return true;
   }
}

function gmtime()
{
   return strtotime(get_date_time());
}

function get_date_time($timestamp = 0)
{
   if ($timestamp) {
       return date("Y-m-d H:i:s", $timestamp);
   } else {
       return gmdate("Y-m-d H:i:s");
   }
}


//Bencoding function, returns a bencoded dictionary (You may go ahead and enter custom keys in the dictionary)
function track($list, $c = 0, $i = 0)
{
   if (is_string($list)) { //Did we get a string? Return an error to the client
       return 'd14:failure reason' . strlen($list) . ':' . $list . 'e';
   }
   $p = ''; //Peer directory
   foreach ($list as $d) { //Runs for each client
       $pid = '';
       if (!isset($_GET['no_peer_id'])) { //Send out peer_ids in the reply
           $real_id = hex2bin($d[2]);
           $pid = '7:peer id' . strlen($real_id) . ':' . $real_id;
       }
       $p .= 'd2:ip' . strlen($d[0]) . ':' . $d[0] . $pid . '4:porti' . $d[1] . 'ee';
   }
   //Add some other paramters in the dictionary and merge with peer list
   $r = 'd8:intervali' . __INTERVAL . 'e12:min intervali' . __INTERVAL . 'e8:completei' . $c . 'e10:incompletei' . $i . 'e5:peersl' . $p . 'ee';
   return $r;
}


// Use the correct content-type
header("Content-type: Text/Plain");

// Make sure we have something to use as a passkey
$passkey = $_GET['passkey'] ?? '';
// Standard Information Fields
$info_hash = bin2hex($_GET['info_hash']);
$peerid = bin2hex($_GET['peer_id']);
$port = intval($_GET['port']);
$downloaded = isset($_GET['downloaded']) && is_numeric($_GET['downloaded']) ? intval($_GET['downloaded']) : 0;
$uploaded = isset($_GET['uploaded']) && is_numeric($_GET['uploaded']) ? intval($_GET['uploaded']) : 0;
$left = isset($_GET['left']) && is_numeric($_GET['uploaded']) ? intval($_GET['left']) : 0;
$seeder = ($left == 0) ? "yes" : "no";
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) && is_string($_SERVER['HTTP_USER_AGENT']) ? substr($_SERVER['HTTP_USER_AGENT'], 0, 80) : "N/A";
$ipadress = is_string($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : die("Weird ip adress");
$event = $_GET['event'] ?? '';
// Extra Information Fields
$no_peer_id = $_GET["no_peer_id"];
$compact = ($_GET["compact"] && $_GET["compact"] == 1) ? true : false;
$numwant = $_GET["numwant"] ? (int) $_GET["numwant"] : PEERLIMIT;

// Inputs that are needed, do not continue without these
valdata('peer_id', true);
valdata('port');
valdata('info_hash', true);
// Do we have a valid client port, support compact, is a browser?
if (!ctype_digit($_GET['port']) || $_GET['port'] < 1 || $_GET['port'] > 65535) {die(track('Invalid client port'));}
if (!$compact) {die(track("Your client doesn't support compact, please update your client"));}
//if (preg_match("/^Mozilla|^Opera|^Links|^Lynx/i", $user_agent)) { die("No");}
if (strlen($passkey) != 32) {die(track("Invalid passkey (" . strlen($passkey) . " - $passkey)"));}

// Get db connection
$dbh = new Database() or die(track('Database connection failed'));

// Client Ban
$stmt = $dbh->prepare("SELECT agent_name FROM agents");
$agentarray = $stmt->fetchAll(PDO::FETCH_COLUMN);
$useragent = substr($peerid, 0, 8);
foreach ($agentarray as $bannedclient) {
   if (@strpos($useragent, $bannedclient) !== false) {
       die(track('Client is banned'));
   }
}

// Get User (select user/group vars here)
$sql = "SELECT u.id, u.class, u.uploaded, u.downloaded, u.ip, u.passkey, g.can_download
   FROM users u
   INNER JOIN groups g
   ON u.class = g.group_id
   WHERE u.passkey=? AND u.enabled = ? AND u.status = ? LIMIT 1";
$stmt = $dbh->prepare($sql);
$stmt->execute([$passkey, 'yes', 'confirmed']);
$user = $stmt->fetch(PDO::FETCH_ASSOC);

// Get Torrent (select torrent vars here)  note = torrent['numpeers']
$sql = "SELECT id, info_hash, banned, freeleech, seeders + leechers
       AS numpeers, UNIX_TIMESTAMP(added)
   AS ts, seeders, leechers, times_completed
   FROM torrents WHERE info_hash=?";
$stmt = $dbh->prepare($sql);
$stmt->execute([$info_hash]);
$torrent = $stmt->fetch(PDO::FETCH_ASSOC);

// Do some more checks
if (!$user) {die(track("Cannot locate a user with that passkey!"));}
if ($user["can_download"] == "no") {die(track("You do not have permission to download."));}
if (!$torrent) {die(track("Torrent not found on this tracker - hash = " . $info_hash));}
if ($torrent["banned"] == 'yes') {die(track("Torrent has been banned - hash = " . $info_hash));}
$sql = $dbh->run("SELECT COUNT(*)
                 FROM peers
                 WHERE torrent=? AND passkey=?", [$torrent['id'], $passkey]);
$valid = $sql->rowCount();
if ($valid >= 1 && $seeder == 'no') {
   //die(track("Connection limit exceeded! You may only leech from one location at a time."));
}
$connect = isConnectable($ipadress, $port);
if ($connect) {
   $connectable = 'yes';
}else{
   $connectable = 'no';
}

// Prepare Peer Array
$peer_params = [
   'torrentid' => $torrent['id'],
   'peerid' => $peerid,
   'ipadress' => $ipadress,
   'port' => $port,
   'uploaded' => $uploaded,
   'downloaded' => $downloaded,
   'left' => $left,
   'seeder' => $seeder,
   'started' => TimeDate::get_date_time(),
   'lastaction' => TimeDate::get_date_time(),
   'connectable' => $connectable,
   'useragent' => $user_agent,
   'userid' => $user['id'],
   'passkey' => $passkey];

// Now Insert Peer Array or Update on Duplicate
$insert_peer = $dbh->prepare('INSERT INTO `peers` (`torrent`, `peer_id`, `ip`, `port`, `uploaded`, `downloaded`, `to_go`, `seeder`, `started`, `last_action`, `connectable`, `client`, `userid`, `passkey`) '
   . "VALUES (:torrentid, :peerid, :ipadress, :port, :uploaded, :downloaded, :left, :seeder, :started, :lastaction, :connectable, :useragent, :userid, :passkey) "
   . 'ON DUPLICATE KEY UPDATE `peer_id`=VALUES(`peer_id`), `ip` = VALUES(`ipadress`), `passkey`=VALUES(`passkey`), `port` = VALUES(`port`), `uploaded` = VALUES(`uploaded`), `downloaded` = VALUES(`downloaded`), `to_go` = VALUES(`to_go`), `seeder` = VALUES(`seeder`), `last_action` = VALUES(`last_action`), `connectable` = VALUES(`connectable`), `client` = VALUES(`client`), `userid` = VALUES(`userid`), `passkey` = VALUES(`passkey`),`id` = LAST_INSERT_ID(`peers`.`id`)');
$insert_peer->execute($peer_params);
$pk_peer = $dbh->lastInsertId();

// Select ip, port, peer_id to send back to client
$sql = "SELECT seeder, UNIX_TIMESTAMP(last_action) AS ez, peer_id, INET_NTOA(ip), port, uploaded, downloaded, userid, passkey FROM peers WHERE torrent=? AND passkey=? LIMIT $numwant";
$select_peer_torrent = $dbh->prepare($sql);
$select_peer_torrent->execute([$torrent['id'], $passkey]);
$reply = array(); //To be encoded and sent to the client
while ($r = $select_peer_torrent->fetch(PDO::FETCH_ASSOC)) { //Runs for every client with the same infohash
   $reply[] = array($r['ip'], $r['port'], $r['peer_id']);
   /*
   if ($r['peer_id'] === $peerid) {
       $currentpeer = $r; // the current connection = already in table(self)
   }
   */
}

// The Events
if ($event == 'started') { // when a connection is made or restarted after turn off
   if (($seeder == 'no' && $torrent['freeleech'] == 0)) {
       $dbh->run("INSERT INTO `snatched` (`uid`, `tid`, `stime`, `utime`) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE `utime` = ?", [$user['id'], $torrent['id'], gmtime(), gmtime(), gmtime()]);
   }
} elseif ($event == 'completed') { // when a download finishes in client
   // old updateset for completed
   $dbh->run("UPDATE torrents SET times_completed = $torrent[times_completed] + 1 WHERE id=$torrent[id]") or die(track("Tracker error: Unable to update torrent"));
   $dbh->run("INSERT INTO completed (userid, torrentid, date) VALUES (?,?,?)", [$user['id'], $torrent['id'], get_date_time()]);
   $dbh->run("UPDATE LOW_PRIORITY `snatched` SET `completed` = '1' WHERE `tid` = '$torrent[id]' AND `uid` = '$user[id]' AND `utime` = '" . gmtime() . "'");
} elseif ($event == 'stopped') { // when client is stopped correctly
   $dbh->run("DELETE FROM peers WHERE torrent = ? AND userid = ?", [$torrent['id'], $user['id']]);
}

// update user
$elapsed = ($seeder == 'yes') ? ANNOUNCEINTERVAL - floor(($self['ez'] - time()) / 60) : 0; //
if ($torrent["freeleech"] == 1) {
   $dbh->run("UPDATE users SET uploaded =? WHERE id=?", [$user['uploaded'] + $downloaded, $user['id']]) or die(track("Tracker error: Unable to update stats"));
} else {
   $dbh->run("UPDATE users SET uploaded =?, downloaded =? WHERE id=?", [$user['uploaded '] + $uploaded, $user['downloaded'] + $downloaded, $user['id']]) or die(track("Tracker error: Unable to update stats"));
   // snatch
   $dbh->run("UPDATE LOW_PRIORITY `snatched` SET `uload` = `uload` + '$uploaded', `dload` = `dload` + '$downloaded', `utime` = '" . gmtime() . "', `ltime` = `ltime` + '$elapsed' WHERE `tid` = '$torrent[id]' AND `uid` = '$user[id]'");
}


// Count the peers from to_go for seeders/leechers
$select_peers = $dbh->prepare('SELECT IFNULL(SUM(peers.to_go > 0), 0) AS leech, IFNULL(SUM(peers.to_go = 0), 0) AS seed '
   . 'FROM peers '
   . "WHERE peers.torrent = ? "
   . 'AND peers.last_action >= DATE_SUB(UTC_TIMESTAMP(), INTERVAL ' . (__INTERVAL + __INTERVAL) . ' SECOND) '
   . 'GROUP BY `peers`.`torrent`');
$select_peers->execute([$torrent['id']]);
$seeders = 0;
$leechers = 0;
if ($r = $select_peers->fetch(PDO::FETCH_NUM)) {
   $seeders = $r[1];
   $leechers = $r[0];
}

// Update Torrent -
if ($seeder == "yes") {
   if ($torrent["banned"] != "yes") { // DONT MAKE BANNED ONES VISIBLE {
       $dbh->run("UPDATE torrents SET seeders = ?, leechers = ?, last_action = ?, visible = ? WHERE id=?", [$seeders, $leechers, get_date_time(), 'yes', $torrent['id']]) or die(track("Tracker error: Unable to update torrent"));
   }
   $dbh->run("UPDATE torrents SET seeders = ?, leechers = ?, last_action = ? WHERE id=?", [$seeders, $leechers, get_date_time(), $torrent['id']]) or die(track("Tracker error: Unable to update torrent"));
}
/*
if (count($updateset)) {
   $dbh->run("UPDATE torrents SET " . join(",", $updateset) . " WHERE id=$torrent[id]") or die(track("Tracker error: Unable to update torrent"));
}
*/
Logs::write("$user[id] = user $event = event $downloaded = downloaded  $uploaded = uploaded $left = left $seeder = seeder $passkey = passkey $info_hash = info_hash $peerid = peer_id $port = port $user_agent = user agent $no_peer_id = no_peer_id $compact = cpmpact $numwant = numwant");
// Print out response
die(track($reply, $seeders[0], $leechers[0]));
2021-01-23 07:05:45
downloading just fine so far with qbittorrent
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
2021-01-23 23:15:16
Few issues with the announce script, but for now this is my result acting as a regular user with Bittorrent 7.4.3 installed.



Few things going on here. So a persistent connection to the database seems to be denied, therefor allowing a "direct connection", which is not swarm-friendly. And the passkey is easily bypassed, as lacking additional validation - token auth or peer ID validation. Also appears to be lacking min-intervel BEP as revealed by my client. This file needs a lot of work, do you have source available?
Last edited by STorrents2020 on 2021-01-23 23:15:45
2021-01-23 23:21:16
As for connectable, its always been of error. I had enough with my entire peers table column "connectable" = "no" for every single peer, so I did this to bind this to my query and deleted function.

'connectable' => fsockopen($data['ip'], $data['port']) ? 'yes' : 'no'

Works 100%

Delete that isConnectable() crap and use this inline with your query. Reduce overhead too.
Additionally, there is a lot of I/O overhead calling local files per X amount of requests, look to bind these in or reduce their function to a 1-liner for optimization sake.

"Downloaded" also has no reported INT value back to clients - looks like a TODO.
Last edited by STorrents2020 on 2021-01-23 23:28:38
2021-01-24 09:32:39
I would like a solution to adapt to TorrentTrader PDO / MVC Edition
2021-01-24 10:16:50
rtorrent can't handle metalink
Tracker: [Failure reason \"Invalid passkey (0 - )\"]
2021-01-24 13:07:29
Will the IMDB info be optional, meaning can turn of or on in the settings?
For our site it will not be of much use to show.
If It Ain't Dutch, It Ain't Much!!
2021-01-24 17:00:13
I guess you can turn it off in config.php
2021-01-24 19:25:09
My seedbox refuses to download this test torrent
2021-01-25 18:59:39
i dont use imdb mate so you can turn off in config. but in the example https://torrenttrader.uk/torrents/read?id=1
i just removed like from database which switches to normal view

Maksimum, did you use download or magnet - for first download must be download not magnet to add passkey

just seems to be rtorrent having issues, ill keep playing with it @storrents can you post a updated copy of yours
2021-01-25 19:21:43
seems to be encoding causing issues
Uncaught Exception: 2021-01-25 19:10:44 - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: '\xB3v&\xED\xB5u...' for column peer_id

i removed the peer_id hash and now i get errors on rutorrent just need to get colleration on database right now
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: 3
  • Members: 0
  • Guests online: 3
  • Comments: 3
  • Messages: 1,728