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

Life saver! I lost my backup files.. whew!
referer mod — 2021-03-05 21:52:28 in v3 Support
If you removed isset() you would take note of the warnings, and what the problem is.

isset() is faster than array_key_exists, however returns/handles checks differently.

Both are good to use in this case:

if (isset($_SERVER['HTTP_REFERER']) || array_key_exists('HTTP_REFERER', $_SERVER))

Anyway, try this:


error_reporting(E_ALL);
if (isset($_SERVER['HTTP_REFERER'])) {
   $parse = parse_url($_SERVER['HTTP_REFERER']);
   if ($parse['host'] != $_SERVER['HTTP_HOST']) {
       echo 'No referer';
   } else {
       SQL_Query_exec("INSERT INTO 'referer' ('referer', 'added', 'count') VALUES ('" . $parse['scheme'] . '://' . $parse['host'] . "', '" . gmtime() . "', '1') ON DUPLICATE KEY UPDATE 'count' = 'count' + 1");
   }
}



Rewrite: Cleanup.php — 2021-03-04 01:21:45 in M-BiTsy Support
Class complete.
Rewrite: Cleanup.php — 2021-03-03 01:28:33 in M-BiTsy Support
I rewrote this as I wanted a fresh solution to a clean up class. I did some reading and figured out a way to minimize my declared methods and instead implement a interface, which holds every task to execute. It works perfectly, as long as you have PDO installed (PHP PDO).

This is 100% working. Use as you will. Works perfectly for us.

Add to /classes as class.cleanup.php
<?
// STorrents2020 Cleanup Class - Class rewrite & fancy syntax - Mar 3, 2021

class Database
{
   public $pdo;
   public $CONFIG;
   
   public function __construct($db = 'database', $username = 'username', $password = 'password', $host = 'localhost', $port = 3306, $options = [])
   {
       $dsn = "mysql:host=$host;dbname=$db;port=$port;charset=utf8mb4";
       try {
           $this->pdo = new PDO($dsn, $username, $password, $options);
       }
       catch (PDOException $e) {
           $this->log_exception($e->getMessage(), $e->getLine());
       }
   }
   
   private function log_exception($msg, $line)
   {
$query = "INSERT INTO sql_logging(exception, added) VALUES(?, NOW())";
$stt = $this->pdo->prepare($query);
$stt->bindValue(1, $msg . $line);
$stt->execute();
   }
   
   public 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');
   }
   
   public function preprocess($query, $get_id)
   {
       return $query;
   }
   
   public function write_log($text)
   {
       $this->query_params('INSERT INTO log (added, txt) VALUES(NOW(), :log)', array(
           'log' => $text
       ));
   }
   
   public function sql_timestamp_to_unix_timestamp($s)
   {
       return mktime(substr($s, 11, 2), substr($s, 14, 2), substr($s, 17, 2), substr($s, 5, 2), substr($s, 8, 2), substr($s, 0, 4));
   }
   
   public function gmtime()
   {
       return $this->sql_timestamp_to_unix_timestamp($this->get_date_time());
   }
   
   public function interval($s)
   {
       return sprintf("INTERVAL '%s'", $s);
   }
   
   public function query_params($query, $params = null, $get_id = null)
   {
       if (is_null($params)) {
           $params = array();
       }
       try {
           $query = $this->preprocess($query, $get_id);
           $stmt  = $this->pdo->prepare($query);
           foreach ($params as $key => $param) {
               if ($key == "data") {
                   $stmt->bindValue(':' . $key, $param, PDO::PARAM_LOB);
               } else if ($key == "limit") {
                   $stmt->bindValue(':' . $key, (int) trim($param), PDO::PARAM_INT);
               } else {
                   $stmt->bindValue(':' . $key, $param);
               }
           }
           $stmt->execute();
           $stmt->setFetchMode(PDO::FETCH_ASSOC);
           if (is_null($get_id)) {
               return $stmt;
           } else {
               return $this->get_last_id($stmt, $get_id);
           }
       }
       catch (PDOException $e) {
           $this->log_exception($e->getMessage(), $e->getLine());
       }
   }
}

interface Tasks
{
   
   public function seedbonus();
   
   public function comments();
   
   public function updatetorrents();
   
   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 cleanpeers();
   
}

class Cleanup extends Database implements Tasks
{
   
   public function cleanlogs()
   {
       $ts = $this->gmtime() - $this->CONFIG['log_clean'];
       $this->query_params('DELETE FROM log WHERE added < FROM_UNIXTIME(:ts)', array(
           'ts' => $ts
       ));
   }
   
   public function checkdead()
   {
   $deadtime = $this->gmtime() - $this->CONFIG['max_dead_torrent_time'];
   $founddead = $this->query_params('SELECT COUNT(torrent_id) AS dead FROM torrents WHERE seeders = 0 AND leechers = 0');
   $find = $founddead->fetch();
//$this->query_params("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME(:dead_time) AND seeders = '0' AND leechers = '0' AND external !='yes'", array('dead_time' => $deadtime));
   $event = "$find[dead] torrents found dead. Opening Graveyard ";
$this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array('receiver' => 'NerbBot', 'event' => $event));
   }
   
   public function seedbonus()
   {
       $res = $this->query_params("SELECT DISTINCT user_id as peer, (SELECT DISTINCT COUNT(torrent_id) FROM peers WHERE seeder = 'yes' AND user_id = peer) AS count FROM peers WHERE seeder = 'yes'");
       while ($row = $res->fetch()) {
           $this->query_params('UPDATE users SET seedbonus = seedbonus + :bonustime_rowcount WHERE user_id = :peer', array(
               'bonustime_rowcount' => ($this->CONFIG['bonuspertime'] * $row['count']),
               'peer' => $row['peer']
           ));
       }
   }

   public function autofreeleech()
   {
   $gigs  = 17179869184; // 16gb
$query = $this->query_params("SELECT torrent_id, name FROM torrents WHERE banned = 'no' AND freeleech = '0' AND size >= :gigs", array('gigs' => $gigs));
if ($query) {
while ($row = $query->fetch()) {
$event = "$row[name] has been cycled to Freeleech (16GB+)";
$this->query_params("UPDATE torrents SET freeleech = '1' WHERE torrent_id = :torrent_id", array('torrent_id' => $row['torrent_id']));
$this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array('receiver' => 'NerbBot', 'event' => $event));
$this->write_log("Freeleech added on <a href='/details/$row[torrent_id]'>$row[name]</a> because it is bigger than 8GB.");
    }                                                                                                                

}
   }
   
   public function pendingusers()
   {
   $deadtime = $this->gmtime() - $this->CONFIG['signup_timeout'];
$this->query_params("DELETE FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME(:dead_time)", array('dead_time' => $deadtime));
   }
   
   public function privseeders()
   {
   $res      = $this->query_params("SELECT t.torrent_id, (SELECT COUNT(torrent_id) FROM peers WHERE seeder = 'yes' AND completed = 1) AS seeders, COUNT(seeders) AS c FROM torrents t LEFT JOIN peers p ON p.torrent_id = t.torrent_id WHERE t.banned = 'no' AND t.external = 'no'");
   $getcount = $res->fetch();
$event    = "Found $getcount[c] Private Seeders connected (global) ";
$this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array('receiver' => 'NerbBot', 'event' => $event));
   }
   
   public function comments()
   {
       $getcount = $this->query_params("SELECT COUNT(torrent) as c FROM comments");
       $restotal = $getcount->fetch();
       $event    = "Currently there are $restotal[c] comments posted ";
       $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
           'receiver' => 'NerbBot',
           'event' => $event
       ));
   }
   
   public function cleanpeers()
   {
$cleantable = $this->query_params('DELETE FROM peers WHERE last_announce + ' . $this->interval('1 hour') . ' < CURRENT_TIMESTAMP');
$released   = $this->query_params('SELECT COUNT(user_id) AS c FROM peers WHERE last_announce + ' . $this->interval('1 hour') . ' < CURRENT_TIMESTAMP');
$row = $released->fetch();
if ($cleantable) {
$event    = "Cleaning $row[c][c] peers found idle or stale ";
$this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
            'receiver' => 'NerbBot',
'event' => $event
));
}
   }
   
   public function updatetorrents()
   {
       $fields        = explode(':', 'comments:leechers:seeders');
       $res           = $this->query_params("SELECT p.torrent_id, t.external, t.comments, (SELECT COUNT(torrent_id) FROM peers WHERE seeder = 'yes' AND torrent_id = p.torrent_id) AS seeders, (SELECT COUNT(torrent_id) FROM peers WHERE seeder = 'no' AND torrent_id = p.torrent_id) AS leechers FROM torrents t LEFT JOIN peers p ON p.torrent_id = t.torrent_id WHERE t.banned = 'no'");
       $torrents   = array();
       while ($row = $res->fetch()) {
           $id   = $row['torrent_id'];
           $torr = $torrents[$id];
           foreach ($fields as $field) {
               if (!isset($torr[$field]))
                   $torr[$field] = 0;
           }
           $update = array();
           foreach ($fields as $field) {
               if ($row['external'] == 'no' || $field == 'comments') {
                   if ($torr[$field] != $row[$field])
                       $update[] = "$field = " . $torr[$field];
               }
           }
           if (count($update))
               $this->query_params("UPDATE torrents SET " . implode(",", $update) . " WHERE torrent_id = :torrent_id", array(
                   'torrent_id' => $id
               ));
       }
   }
   
   public function autopromote()
   {
       $limit    = 25 * 1024 * 1024 * 1024;
       $minratio = 1.05;
       $maxdt    = $this->get_date_time(time() - 86400 * 28);
       $res      = $this->query_params('SELECT user_id, username FROM users WHERE class = 1 AND uploaded >= :limit AND uploaded / downloaded >= :minratio AND added < :maxdt', array(
           'limit' => $limit,
           'minratio' => $minratio,
           'maxdt' => $maxdt
       ));
       if ($res) {
           $dt  = $this->get_date_time();
           $msg = "Congratulations, you have been automatically promoted to Power User. You can now do more stuff.";
           while ($arr = $res->fetch()) {
               $this->query_params('UPDATE users SET class = 2 WHERE user_id = :user_id', array(
                   'user_id' => $arr['user_id']
               ));
               $txt   = "You have been promoted to Power User!";
               $event = "$arr[username] has been promoted Power User";
               $this->query_params('INSERT INTO messages (sender, receiver, added, msg, poster, subject) VALUES(0, :user_id, NOW(), :message, 0, :subject)', array(
                   'user_id' => $arr['user_id'],
                   'message' => $txt,
                   'subject' => 'Promoted!'
               ));
               $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
                   'receiver' => $arr['username'],
                   'event' => $event
               ));
               $this->write_log("The user <a href=\"/user/?id=$arr[user_id]\">$arr[username]</a> was automatically promoted to power user.");
           }
       }
   }
   
   public function autodemote()
   {
       $minratio = 0.95;
       $res      = $this->query_params('SELECT user_id, username FROM users WHERE class = 2 AND uploaded / downloaded < :minratio', array(
           'minratio' => $minratio
       ));
       if ($res) {
           $dt  = $this->get_date_time();
           $msg = "You were automatically demoted from Power User to Regular because your share ratio fell below $minratio.";
           while ($arr = $res->fetch()) {
               $this->query_params('UPDATE users SET class = 1 WHERE user_id = :user_id', array(
                   'user_id' => $arr['user_id']
               ));
               $txt   = "You have been demoted to Regular.";
               $event = "$arr[username] has been demoted to Regular";
               $this->query_params('INSERT INTO messages (sender, receiver, added, msg, poster, subject) VALUES(0, :user_id, NOW(), :message, 0, :subject)', array(
                   'user_id' => $arr['user_id'],
                   'message' => $txt,
                   'subject' => 'Demoted!'
               ));
               $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
                   'receiver' => $arr['username'],
                   'event' => $event
               ));
               $this->write_log("The user <a href=\"/user/?id=$arr[user_id]\">$arr[username]</a> was automatically promoted to power user.");
           }
       }
   }
   
   public function checkexpiredwarns()
   {
       $res = $this->query_params("SELECT users.user_id, users.username, warnings.expiry FROM users INNER JOIN warnings ON users.user_id=warnings.userid WHERE type != 'Poor Ratio' AND warned = 'yes' AND enabled='yes' AND warnings.active = 'yes' AND warnings.expiry < :date_time", array(
           'date_time' => $this->get_date_time()
       ));
       while ($arr1 = $res->fetch()) {
           $this->query_params("UPDATE users SET warned = 'no' WHERE user_id = :user_id", array(
               'user_id' => $arr1['user_id']
           ));
           $this->query_params("UPDATE warnings SET active = 'no' WHERE userid = :user_id AND expiry < :date_time", array(
               'user_id' => $arr1['user_id'],
               'date_time' => $this->get_date_time()
           ));
           $event = "Warning removed for $arr1[username]. Expiry: $arr1[expiry]";
           $this->write_log("Removed warning for $arr1[username]. Expiry: $arr1[expiry]");
       }
       $this->query_params("UPDATE users SET warned = 'yes' WHERE warned = 'no' AND user_id IN (SELECT userid FROM warnings WHERE active = 'yes')");
       while ($active = $res->fetch()) {
           $event = "Active warning renewed for $active[username]";
           $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
               'receiver' => 'NerbBot',
               'event' => $event
           ));
       }
   }
   
   public function ratiowarn()
   {
       if ($this->CONFIG['ratiowarn_enable']) {
       $minratio   = $this->CONFIG["ratiowarn_minratio"];
           $downloaded = $this->CONFIG["ratiowarn_mingigs"] * 1024 * 1024 * 1024;
           $length     = $this->CONFIG["ratiowarn_daystowarn"];
           $res = $this->query_params("SELECT user_id, username FROM users WHERE class = 1 AND warned = 'no' AND enabled='yes' AND uploaded / downloaded < :minratio AND downloaded >= :downloaded", array(
               'minratio' => $minratio,
               'downloaded' => $downloaded
           ));
           if ($res) {
               $timenow    = $this->get_date_time();
               $reason     = "You have been warned because of having low ratio. You need to get a " . $minratio . " before next " . $length . " days or your account may be banned.";
               $expiretime = gmdate('Y-m-d H:i:s', $this->gmtime() + (86400 * $length));
               while ($arr = $res->fetch()) {
                   
                   $warneduser = $arr['username'];
                   $event      = "Low ratio warning added for [url=https://www.switch-torrents.com/user/?id=$arr[user_id]]$arr[username][/url]";
                   $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
                       'receiver' => $warneduser,
                       'event' => $event
                   ));
                   $this->query_params('INSERT INTO warnings (userid, reason, added, expiry, warnedby, type) VALUES (:user_id, :reason, NOW(), :expiretime, 0, :type)', array(
                       'user_id' => $arr['user_id'],
                       'reason' => $reason,
                       'expiretime' => $expiretime,
                       'type' => 'Poor Ratio'
                   ));
                   $this->query_params("UPDATE users SET warned = 'yes' WHERE user_id = :user_id", array(
                       'user_id' => $arr['user_id']
                   ));
                   $this->query_params('INSERT INTO messages (sender, receiver, added, msg, poster, subject) VALUES (0, :user_id, NOW(), :reason, 0, :subject)', array(
                       'user_id' => $arr['user_id'],
                       'reason' => $reason,
                       'subject' => 'Warning: Poor Ratio'
                   ));
                   $this->write_log("Auto Leech warning has been <b>added</b> for <a href='/user/?id=" . $arr["user_id"] . "'>" . $arr["username"] . "</a>");
               }
           }
           $res1 = $this->query_params("SELECT users.user_id, users.username FROM users INNER JOIN warnings ON users.user_id=warnings.userid WHERE type='Poor Ratio' AND active = 'yes' AND warned = 'yes' AND enabled='yes' AND uploaded / downloaded >= :minratio AND downloaded >= :downloaded", array(
               'minratio' => $minratio,
               'downloaded' => $downloaded
           ));
           if ($res1) {
               $timenow = $this->get_date_time();
               $reason  = "Your warning of low ratio has been removed. We highly recommend you to keep a your ratio up to not be warned again.\n";
               while ($arr1 = $res1->fetch()) {
                   
                   $warnremoved = $arr1['username'];
                   $event       = "Low ratio warning removed for [url=https://www.switch-torrents.com/user/?id=$arr1[user_id]]$arr1[username][/url]";
                   $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
                       'receiver' => $warnremoved,
                       'event' => $event
                   ));
                   $this->query_params("UPDATE users SET warned = 'no' WHERE user_id = :user_id", array(
                       'user_id' => $arr1['user_id']
                   ));
                   $this->query_params("UPDATE warnings SET expiry = :time_now, active = 'no' WHERE userid = :user_id", array(
                       'time_now' => $timenow,
                       'user_id' => $arr1['user_id']
                   ));
                   $this->query_params('INSERT INTO messages (sender, receiver, added, msg, poster, subject) VALUES (0, :user_id, NOW(), :reason, 0, :subject)', array(
                       'user_id' => $arr1['user_id'],
                       'reason' => $reason,
                       'subject' => 'Ratio Warning Removed'
                   ));
                   $this->write_log("Auto Leech warning has been removed for: <a href='/user/?id=" . $arr1["user_id"] . "'>" . $arr1["username"] . "</a>");
               }
           }
           
           
           $res = $this->query_params("SELECT users.user_id, users.username, users.limited, UNIX_TIMESTAMP(warnings.expiry) AS expiry FROM users INNER JOIN warnings ON users.user_id=warnings.userid WHERE type='Poor Ratio' AND active = 'yes' AND class = 1 AND enabled='yes' AND warned = 'yes' AND uploaded / downloaded < :minratio AND downloaded >= :downloaded", array(
               'minratio' => $minratio,
               'downloaded' => $downloaded
           ));
           if ($res->fetch() > 0) {
               $timenow = $this->get_date_time();
               $expires = (86400 * $length);
               while ($arr = $res->fetch()) {
                   if ($this->gmtime() - $arr['expiry'] >= 0) {
                       $limiteduser = $arr['username'];
                       $event       = "[url=https://www.switch-torrents.com/user/?id=$arr[user_id]]$arr[username][/url] has been limited (Auto Leech warning)";
                       $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
                           'receiver' => $limiteduser,
                           'event' => $event
                       ));
                       $this->query_params("UPDATE users SET limited = 'yes', warned = 'no' WHERE user_id = :user_id", array(
                           'user_id' => $arr['user_id']
                       ));
                       $this->write_log("User <a href='/user/?id=" . $arr["user_id"] . "'>" . $arr["username"] . "</a> has been <b>limited</b> (Auto Leech warning)");
                   }
               }
           }
           
       }
       
       $res = $this->query_params("SELECT users.user_id, users.username, warnings.expiry FROM users INNER JOIN warnings ON users.user_id=warnings.userid WHERE type != 'Poor Ratio' AND warned = 'yes' AND enabled='yes' AND warnings.active = 'yes' AND warnings.expiry < :date_time", array(
           'date_time' => $this->get_date_time()
       ));
       while ($arr1 = $res->fetch()) {
           $this->query_params("UPDATE users SET warned = 'no' WHERE user_id = :user_id", array(
               'user_id' => $arr1['user_id']
           ));
           $this->query_params("UPDATE warnings SET active = 'no' WHERE userid = :user_id AND expiry < :date_time", array(
               'user_id' => $arr1['user_id'],
               'date_time' => $this->get_date_time()
           ));
           
           $event = "Warning removed for $arr1[username]. Expiry: $arr1[expiry]";
           $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
               'receiver' => 'NerbBot',
               'event' => $event
           ));
           $this->write_log("Removed warning for $arr1[username]. Expiry: $arr1[expiry]");
       }
       $this->query_params("UPDATE users SET warned = 'yes' WHERE warned = 'no' AND user_id IN (SELECT userid FROM warnings WHERE active = 'yes')");
       
       while ($active = $res->fetch()) {
           $event = "Active warning renewed for $active[username]";
           $this->query_params('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, :receiver, :event, NOW(), 0)', array(
               'receiver' => 'NerbBot',
               'event' => $event
           ));
       }
       
   }    
   
}


run_jobs.php and save to / (where index.php is)


<?
// Cleanup Runner - Mar 3, 2021
require_once('config.php');
require_once('classes/class.cleanup.php');

echo 'Running Jobs...';

$task = new Cleanup;
$task->seedbonus();
$task->comments();
$task->updatetorrents();
$task->checkexpiredwarns();
$task->ratiowarn();
$task->cleanlogs();
$task->autopromote();
$task->autofreeleech();
$task->autodemote();
$task->checkdead();
$task->pendingusers();
$task->privseeders();
$task->cleanpeers();


Our version uses nullable types, like ?string, ?int etc. I left this out as people seem to use PHP 5 still. Best to rule that out. Enjoy.

Required (for torrenttrader):

Search and Replace "torrent_id" => "id", "user_id" => "id"
Snatchlist [TTv3] — 2021-02-13 22:25:57 in v3 Mods Completed
It appears 23 weeks later I am "tackling this". Could someone explain whether or not there are current bugs, and if this mod is partially-complete?
TT 2.5 [moded 2.08] — 2021-02-11 20:21:49 in M-BiTsy Support
Their all INT values. Absense of declaring Type may produce warnings between newer PHP versions, and any error or notice corrupts announce output (thats why they forced errors off to avoid this, fixing the code is better solution). 
This is terrible and is also outdated as of current.  This caches too much and must contain handling for newly uploaded torrents (clear cache), etc.

It's much faster but leaves your content behind for a bit. Use with caution. 
I wrote this to aid our own database issues with our community, and most of it is caused by our heavy use of persistant AJAX calls, hammering the server to often high loads on local processes (like php-FPM), so I wrote a function without ever googling, and so far so good.

maybe this will help or at least provide some testing grounds.

[CODE=php]
function cached_query(string $query, string $fetchtype) : array
{
global $db;
$memtest = new Memcached();
$memtest->addServer('127.0.0.1', 11211);
$retval = $db->query_params($query);
$result = $retval->$fetchtype();
$querykey = 'KEY' . md5($query);
$memtest->set($querykey, $result);
return $memtest->get($querykey);

}
[/CODE]

Test:

[CODE=php]
cached_query('SELECT avatar, username, id FROM users WHERE user_id IN (1)', 'fetchAll');
[/CODE]

I am still working on return cases on the function, so we can call the function and return true or false, and also allow to read array keys from the get() in the function, not sure how to do that except pushing the array to the function param? maybe some advise on this. anyway try it out!
Torrent Test — 2021-01-24 19:25:09 in M-BiTsy Support
My seedbox refuses to download this test torrent
Torrent Test — 2021-01-23 23:21:16 in M-BiTsy Support
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.
Torrent Test — 2021-01-23 23:15:16 in M-BiTsy Support
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?
Turns out foreach() needs to be replaced with while() and i would get rid of that silly file caching, when FPM or opcache will handle it properly. Do you guys need a rewrite?
Torrent Test — 2021-01-23 02:36:45 in M-BiTsy Support
"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
Approaching BETA 9 its a huge milestone. Will have to weed out the database issues people have with it and go from there.

Many new things, such as Torrent Signing - RSA 2048 on the fly (download & upload), and handles non-encrypted torrents with auto-signing, its tied into the OS CLI on a compiled binary (ut signing tool), probably first tracker ever to do this or even release it! Big accomplishment.

We want to next support V2/hybrid torrents now that certificate signing (BEP 35) was so successful
Awesome thanks!! The query works great. This code i made, does fine and shows iterated result total with overall found total count. I had to use a sub-query in the query to pull off both counts without
breaking the results. I also made it so it takes the first keyword of the torrent name, and focues on that for relevant results, but it can be tuned to including more lookups on substr() or such.


<?
// Similar Torrents - Dec 20, 2020
$matched = $db->query_params("SELECT (SELECT COUNT(torrents.category) FROM torrents WHERE (torrents.name LIKE :param AND torrents.seeders > 0 AND torrents.torrent_id <> 5)) AS totalfound, torrents.torrent_id, torrents.name, torrents.cover1, torrents.size,  torrents.added, torrents.seeders, torrents.leechers, torrents.category, categories.image FROM torrents LEFT JOIN categories ON (categories.id = torrents.category) WHERE (torrents.name LIKE :param AND torrents.seeders > 0 AND torrents.torrent_id <> 5) ORDER BY torrents.seeders DESC", array('param' => '%'.explode(' ',trim($row['name']))[0].'%', 'param' => '%'.explode(' ',trim($row['name']))[0].'%'));
$total = 0;
foreach ($matched as $similar): $total++; ?>
   <a href="/details/<?=$similar['torrent_id']?>/"><img itemprop="image" class="responsive-img" src="/images/covers/<?=$similar['cover1']?>" alt="<?=html_escape($similar['name'])?>" style="width: 103px; height: 176px; margin-right: 10px" border="0" /></a>          
<? if($total==6) break; endforeach; ?>
   <div style="padding:10px;text-align:right"><b><?=$total?></b> matched <?=($total > 1 || $total == 0) ? 'results' : 'result'; ?> of <b><?=$similar['totalfound'] ? $similar['totalfound'] : 0; ?></b> found</div>

"m-jay, post: 69712, member: 20288":

To transfer data (sql) should be very easy just need to go to your host control panel
Go to database section where myphpadmin is and at the top there should be a option to export
You can click custom and only download structure, no data then a simple update list can be done  (y) if you send me a copy of the exported structure I'll take a quick look

The only issue updating tbdev or any other tracker including old TT is that the passwords are old using md5 this can be fixed pretty easy with a small snippet of code


Personally I load the sql file in a editer, "search and replace" one string for another across the entire file, and that does it fine, with respect to line-endings
Code Journel — 2020-12-16 03:38:05 in Support & Suggestions
3 Failed Login Attempts - Email notification & logging

So this became a random idea during the day today, gave it some thought for a few hours and got home and wrote it out in 1 shot. Works great as expected, 2 typos, no bugs lol pleased.
I always use PEAR Mail as its my favourite for a long time, so it stuck ever since.

If account gets failed login 3 times in a row, a email notification is sent to the account owner and count resets back to 0

Reference: $data['username'] is the same as $_POST['username']

// Failed login attempts (3) with Email Notification & Log - Dec 15, 2020
       $checkusers = $db->query_params('SELECT username, email, login_attempts, ip FROM users WHERE username = :username', array('username' => $data['username'])) or die('Unable to retrieve username');
       if (!($checkuser = $checkusers->fetch())) {
           // Query successful, username found
       }else{
           if ($checkuser['login_attempts'] >= 0) {
               $db->query_params('UPDATE users SET login_attempts = login_attempts + 1 WHERE username = :username', array('username' => $checkuser['username'])) or die('Unable to retrieve username');
           }
           if ($checkuser['login_attempts'] >= 3) {
               $db->query_params('UPDATE users SET login_attempts = 0 WHERE username = :username', array('username' => $checkuser['username'])) or die('Unable to retrieve username');

               include('Mail.php');
               $recipients = $checkuser['email'];
               $headers['From'] = $CONFIG['site_email'];
               $headers['To'] = $checkuser['email'];
               $headers['Subject'] = 'Failed Login Attempts';
               $headers['MIME-Version'] = 1;
               $headers['Content-type'] = 'text/html;charset=iso-8859-1';
               // Define SMTP Parameters
               $params['host'] = 'smtp.someservice.com';
               $params['port'] = '25';
               $params['auth'] = ''; // PLAIN for fields filled below, blank for false
               $params['username'] = '';
               $params['password'] = '';

               // SMTP debug - only helps with authentication issues
               $params['debug'] = false;
               // Create the mail object using the Mail::factory method
               $mail_object = Mail::factory('smtp', $params);

               // Send reset email
               $template = sprintf('<html><head>
               <style>body{font-family:arial,sans-serif,helvetica;background-color:rgba(236,236,236,1);margin:0;padding:0}.email-header{background:url("https://domain.com/header.png") left no-repeat rgba(237,35,36,1);width:1000px;height:56px;margin-bottom:20px}.email-body{box-shadow:0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12);background:rgba(255,255,255,1);padding:10 10px 50px 10px;font-size:17px;width:500px;margin:0 auto;text-align:center;overflow:auto}.welcome-msg{font-size:45px;text-align:center;padding:0 20px 20px 0}.welcome-msg2{font-size:17px;text-align:center;padding:0 20px 20 0}.email-body .welcome-msg{padding-top:15px}.email-body a{margin-left:-20px;margin-top:10px}.btn-signin{box-shadow:inset 0 1px 0 0 rgba(242,156,147,1);background:linear-gradient(to bottom,rgba(254,26,0,1) 5px,rgba(206,1,0,1) 1000px);background-color:rgba(254,26,0,1);border-radius:6px;border:1px solid rgba(216,53,38,1);display:inline-block;cursor:pointer;color:rgba(255,255,255,1);font-family:Arial;font-size:15px;font-weight:bold;padding:6px 24px;text-decoration:none;text-shadow:0 1px 0 rgba(178,62,53,1)}.btn-signin:hover{background:linear-gradient(to bottom,rgba(206,1,0,1) 5px,rgba(254,26,0,1) 1000px);background-color:rgba(206,1,0,1)}.btn-signin:active{position:relative;top:1px}</style>
               </head>
               <body>
               <div class="email-header">
               </div>
               <div class="welcome-msg">Failed Login Attempts</div>
               <div class="welcome-msg2">Tracker has detected <b> %1$s </b> failed login attempts from IP <b> %2$s </b> attempting to gain access to this account.</div>
               <div class="email-body">
               <div class="welcome-msg">Actions</div>
               <div class="email-content">
               <url here></div>
               </div>
               <div class="welcome-msg"><a href="https://domain.com/recover/" class="btn-signin">Reset Password</a></div>
               </div>
               </body>
               </html>', $checkuser['login_attempts'], $checkuser['ip']);
               $mail_object->send($recipients, $headers, $template);
               write_log("3 failed login attempts. Email sent to  $headers[To]");
           }
}


And email looks like (without logo)
[ATTACH type="full" alt="email-sample.png"]6001[/ATTACH]
"m-jay, post: 69700, member: 20288":

added note to first post  the code has changed a lot so github is far behind until next month ,
and a quick look at the admin side the admincp will preferably go everything will be split like the adduser section this will end up on profile controller inline

the controller methods (the query should be in the model)
    public function adduser()
   {
       if ($_SESSION["class"] < "7") {
           show_error_msg("Error", "Sorry you do not have the rights to view this page!", 1);
       }
       $data = [];
       $this->view('admin/adduser', $data);
   }

   public function addeduserok()
   {
       if ($_SERVER["REQUEST_METHOD"] == "POST") {
           if ($_POST["username"] == "" || $_POST["password"] == "" || $_POST["email"] == "") {
               show_error_msg("Error", "Missing form data.");
           }
           if ($_POST["password"] != $_POST["password2"]) {
               show_error_msg("Error", "Passwords mismatch.");
           }
           $username = $_POST["username"];
           $password = $_POST["password"];
           $email = $_POST["email"];
           $secret = mksecret();
           $passhash = md5($password);
           $secret = $secret;
           $count = get_row_count("users", "WHERE username=$username");
           if (!$count !=0) {
           show_error_msg("Error", "Unable to create the account. The user name is possibly already taken.");
           Redirect::to(URLROOT . "/admincp");
           die;
           }
           DB::run("INSERT INTO users (added, last_access, secret, username, password, status, email) VALUES (?,?,?,?,?,?,?)", [get_date_time(), get_date_time(), $secret, $username, $passhash, 'confirmed', $email]);
           Redirect::autolink(URLROOT . "/admincp", Lang::T("COMPLETE"));
       }
   }


the template (bootstrap)

<?php
Style::adminheader("Add User");
Admincp::adminnavmenu1();
Style::begin("Add User");
?>
   <center><b>Add user</b></center>
   <div class="form-group">
   <form method=get action=?>
   <input type=hidden name=action value=users>
   Search Users: <input type=text size=30 name=search>
   <input type=submit value='Search'>
   </form>
   <form method=post action='<?php echo URLROOT; ?>/admincp/addeduserok'>
   <div class="form-group">
       <label for="name">Username</label>
       <input id="name" type="text" class="form-control" name="username" minlength="3" maxlength="25" required autofocus>
   </div>
   <div class="form-group">
       <label for="name">Password</label>
       <input id="name" type="text" class="form-control" name="password" minlength="3" maxlength="25" required autofocus>
   </div>
   <div class="form-group">
       <label for="name">Re-type password</label>
       <input id="name" type="text" class="form-control" name="password2" minlength="3" maxlength="25" required autofocus>
   </div>
   <div class="form-group">
       <label for="name">E-mail</label>
       <input id="name" type="text" class="form-control" name="email" minlength="3" maxlength="25" required autofocus>
   </div>
   <div class="form-group">
   <div class="form-group no-margin">
       <button type="submit" class="btn btn-primary btn-block">Okay</button>
   </div>
   </form>
   </div>
   </div>
<?php
Style::end();
Style::adminfooter();



image is from mobile device


Request vars are wide open and unsanitized, is this performed elsewhere (models or views)? I recommend checking a key dictionary or making use of filter module and suppress warnings with isset, etc. Those and/or conditions can then just call $data[] only once, while checking all.
Ajax Shoutbox V3 — 2020-12-14 20:12:09 in v3 Mods in Progress
A function could take care of this, returning a colour code wrapping class_user(), based on the ID. More elegant than writing a bunch of code for 1 spot to get the desired colour array
Ajax Shoutbox V3 — 2020-12-14 04:15:22 in v3 Mods in Progress
I use js to feed tags and pull data out through json, i wish could be of more help, its become complex on my end for what it does now that its hardly php anymore
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: 1
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728