09 New And Improved Snatchlist

Started by Mindless, July 20, 2012, 08:49:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tcboxa

thanks for this.

I was wondering does anyone else get high server loads with this mod?
Centos 7.4.1708 x86
Apache 2.4.29
PHP 7.0.14
MariaDB 10.1.29

DragonCoder

just what i was looking for many thax


Makee72

#3
thanks :)

denede


Mindless

Code (sql) Select
CREATE TABLE `snatched` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `userid` int(10) unsigned NOT NULL default '0',
  `torrentid` int(10) unsigned NOT NULL default '0',
  `ip` varchar(15) NOT NULL default '',
  `port` smallint(5) unsigned NOT NULL default '0',
  `connectable` enum('yes','no') NOT NULL default 'no',
  `agent` varchar(60) NOT NULL default '',
  `peer_id` varchar(20) NOT NULL default '',
  `uploaded` bigint(20) unsigned NOT NULL default '0',
  `upspeed` bigint(20) NOT NULL default '0',
  `downloaded` bigint(20) unsigned NOT NULL default '0',
  `downspeed` bigint(20) NOT NULL default '0',
  `to_go` bigint(20) unsigned NOT NULL default '0',
  `seeder` enum('yes','no') NOT NULL default 'no',
  `seedtime` int(10) unsigned NOT NULL default '0',
  `leechtime` int(10) unsigned NOT NULL default '0',
  `start_date` int(10) NOT NULL,
  `last_action` int(10) NOT NULL,
  `complete_date` int(10) NOT NULL,
  `timesann` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `tr_usr` (`torrentid`,`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


snatches.php ;

Code (php) Select
<?php
require_once("include/bittorrent.php");
require_once 
ROOT_PATH.'/include/user_functions.php';
require_once 
ROOT_PATH.'/include/pager_functions.php';
dbconn();
loggedinorreturn();

$lang array_mergeload_language('global'), load_language('snatches') );

$HTMLOUT="";

$id $_GET["id"];

if (!
is_valid_id($id))
  
stderr("Error""It appears that you have entered an invalid id.");

$res mysql_query("SELECT id, name FROM torrents WHERE id = ".sqlesc($id)."") or sqlerr();
$arr mysql_fetch_assoc($res);

if (!
$arr)
  
stderr("Error""It appears that there is no torrent with that id.");

$res mysql_query("SELECT COUNT(*) FROM snatched WHERE torrentid =".sqlesc$id ) ."") or sqlerr();
$row mysql_fetch_row($res);
$count $row[0];
$perpage 100;

if (!
$count)
  
stderr("No snatches""It appears that there are currently no snatches for the torrent <a href=details.php?id=$arr[id]>$arr[name]</a>.");

$pager pager($perpage$count"?id=$id&amp");

$HTMLOUT .= "<h1>Snatches for torrent <a href=details.php?id=$arr[id]>$arr[name]</a></h1>\n";
$HTMLOUT .= "<h2>Currently $row[0] snatch".($row[0] == "" "es")."</h2>\n";
if (
$count $perpage)
$HTMLOUT .= $pager['pagertop'];
$HTMLOUT .= "<table border=0 cellspacing=0 cellpadding=5>
<tr>
<td class='colhead' align='left'>
{$lang['snatches_username']}</td>
<td class='colhead' align='center'>
{$lang['snatches_connectable']}</td>
<td class='colhead' align='right'>
{$lang['snatches_uploaded']}</td>
<td class='colhead' align='right'>
{$lang['snatches_upspeed']}</td>
<td class='colhead' align='right'>
{$lang['snatches_downloaded']}</td>
<td class='colhead' align='right'>
{$lang['snatches_downspeed']}</td>
<td class='colhead' align='right'>
{$lang['snatches_ratio']}</td>
<td class='colhead' align='right'>
{$lang['snatches_completed']}</td>
<td class='colhead' align='right'>
{$lang['snatches_seedtime']}</td>
<td class='colhead' align='right'>
{$lang['snatches_leechtime']}</td>
<td class='colhead' align='center'>
{$lang['snatches_lastaction']}</td>
<td class='colhead' align='center'>
{$lang['snatches_completedat']}</td>
<td class='colhead' align='center'>
{$lang['snatches_client']}</td>
<td class='colhead' align='center'>
{$lang['snatches_port']}</td>
<td class='colhead' align='center'>
{$lang['snatches_announced']}</td>
</tr>\n"
;

$res mysql_query("SELECT s.*, size, username, warned, enabled, timesann, donor FROM snatched AS s INNER JOIN users ON s.userid = users.id INNER JOIN torrents ON s.torrentid = torrents.id WHERE torrentid = ".sqlesc($id)." ORDER BY complete_date DESC") or sqlerr();
while (
$arr mysql_fetch_assoc($res)) {

  
$upspeed = ($arr["upspeed"] > mksize($arr["upspeed"]) : ($arr["seedtime"] > mksize($arr["uploaded"] / ($arr["seedtime"] + $arr["leechtime"])) : mksize(0)));
  
$downspeed = ($arr["downspeed"] > mksize($arr["downspeed"]) : ($arr["leechtime"] > mksize($arr["downloaded"] / $arr["leechtime"]) : mksize(0)));
  
$ratio = ($arr["downloaded"] > number_format($arr["uploaded"] / $arr["downloaded"], 3) : ($arr["uploaded"] > "Inf." "---"));
  
$completed sprintf("%.2f%%"100 * (- ($arr["to_go"] / $arr["size"])));

  
$HTMLOUT .= "<tr>
  <td align='left'><a href=
{$TBDEV['baseurl']}/userdetails.php?id=$arr[userid]>$arr[username]</a>".get_user_icons($arr)."</td>
  <td align='center'>"
.($arr["connectable"] == "yes" "<font color=green>Yes</font>" "<font color=red>No</font>")."</td>
  <td align='right'>"
.mksize($arr["uploaded"])."</td>
  <td align='right'>
$upspeed/s</td>
  <td align='right'>"
.mksize($arr["downloaded"])."</td>
  <td align='right'>
$downspeed/s</td>
  <td align='right'>
$ratio</td>
  <td align='right'>
$completed</td>
  <td align='right'>"
.mkprettytime($arr["seedtime"])."</td>
  <td align='right'>"
.mkprettytime($arr["leechtime"])."</td>
  <td align='center'>"
.get_date($arr["last_action"], '',0,1)."</td>
  <td align='center'>"
.get_date($arr["complete_date"], '',0,1)."</td>
  <td align='center'>"
.$arr["agent"]."</td>
  <td align='center'>"
.$arr["port"]."</td>
  <td align='center'>"
.$arr["timesann"]."</td>
  </tr>\n"
;
}
$HTMLOUT .= "</table>\n";
if (
$count $perpage)
$HTMLOUT .= $pager['pagerbottom'];

print 
stdhead('Snatches') . $HTMLOUT stdfoot();
die;
?>


userdetails.php under

   
Code (php) Select
if (isset($leeching))
       $HTMLOUT .= "<tr valign=top><td class=rowhead>{$lang['userdetails_cur_leech']}</td><td align=left>".maketable($leeching)."</td></tr>\n";


add this :

   
Code (php) Select
//=== start snatched
    $count_snatched='';
    if ($CURUSER['class'] >= UC_MODERATOR){
    if (isset($_GET["snatched_table"])){
    $HTMLOUT .="<tr><td class='clearalt6' align='right' valign='top'><b>Snatched stuff:</b><br />[ <a class=altlink href=\"userdetails.php?id=$id\" class=\"sublink\">Hide list</a> ]</td><td class='clearalt6'>";
   
    $res = mysql_query(
    "SELECT sn.start_date AS s, sn.complete_date AS c, sn.last_action AS l_a, sn.seedtime AS s_t, sn.seedtime, sn.leechtime AS l_t, sn.leechtime, sn.downspeed, sn.upspeed, sn.uploaded, sn.downloaded, sn.torrentid, sn.start_date, sn.complete_date, sn.seeder, sn.last_action, sn.connectable, sn.agent, sn.seedtime, sn.port, cat.name, cat.image, t.size, t.seeders, t.leechers, t.owner, t.name AS torrent_name ".
    "FROM snatched AS sn ".
    "LEFT JOIN torrents AS t ON t.id = sn.torrentid ".
    "LEFT JOIN categories AS cat ON cat.id = t.category ".
    "WHERE sn.userid=$id ORDER BY sn.start_date DESC") or die(mysql_error());

    $HTMLOUT .= "<table border='1' cellspacing='0' cellpadding='5' align='center'><tr><td class='colhead' align='center'>Category</td><td class='colhead' align='left'>Torrent</td>".
    "<td class='colhead' align='center'>S / L</td><td class='colhead' align='center'>Up / Down</td><td class='colhead' align='center'>Torrent Size</td>".
    "<td class='colhead' align='center'>Ratio</td><td class='colhead' align='center'>Client</td></tr>";
    while ($arr = mysql_fetch_assoc($res)){
    //=======change colors
    $count2='';
    $count2= (++$count2)%2;
    $class = 'clearalt'.($count2==0?'6':'7');
    //=== speed color red fast green slow ;)
    if ($arr["upspeed"] > 0)
    $ul_speed = ($arr["upspeed"] > 0 ? mksize($arr["upspeed"]) : ($arr["seedtime"] > 0 ? mksize($arr["uploaded"] / ($arr["seedtime"] + $arr["leechtime"])) : mksize(0)));
    else
    $ul_speed = mksize(($arr["uploaded"] / ( $arr['l_a'] - $arr['s'] + 1 )));
    if ($arr["downspeed"] > 0)
    $dl_speed = ($arr["downspeed"] > 0 ? mksize($arr["downspeed"]) : ($arr["leechtime"] > 0 ? mksize($arr["downloaded"] / $arr["leechtime"]) : mksize(0)));
    else
    $dl_speed = mksize(($arr["downloaded"] / ( $arr['c'] - $arr['s'] + 1 )));
   
    $dlc="";
    switch (true){
    case ($dl_speed > 600):
    $dlc = 'red';
    break;
    case ($dl_speed > 300 ):
    $dlc = 'orange';
    break;
    case ($dl_speed > 200 ):
    $dlc = 'yellow';
    break;
    case ($dl_speed < 100 ):
    $dlc = 'Chartreuse';
    break;
    }

    if ($arr["downloaded"] > 0){
    $ratio = number_format($arr["uploaded"] / $arr["downloaded"], 3);
    $ratio = "<font color=" . get_ratio_color($ratio) . "><b>Ratio:</b><br />$ratio</font>";
    }
    else
    if ($arr["uploaded"] > 0)
    $ratio = "Inf.";
    else
    $ratio = "N/A";

    $HTMLOUT .= "<tr><td class='$class' align='center'>".($arr['owner'] == $id ? "<b><font color='orange'>Torrent owner</font></b><br />" : "".($arr['complete_date'] != '0'  ? "<b><font color='lightgreen'>Finished</font></b><br />" : "<b><font color='red'>Not Finished</font><br />")."")."<img src={$TBDEV['pic_base_url']}caticons/$arr[image] alt=$arr[name]></td>"."
    <td class='$class'><a class='altlink' href={$TBDEV['baseurl']}/details.php?id=$arr[torrentid]><b>$arr[torrent_name]</b></a>".($arr['complete_date'] != '0'  ?"<br />"."
    <font color='yellow'>started: ".get_date($arr['start_date'], 0,1) ."</font><br /><font color='pink'>finished:" : ""."
    <br /></font><font color='yellow'>started:".get_date($arr['start_date'], 0,1) ."</font><br /><font color='orange'>Last Action:".get_date($arr['last_action'], 0,1) ."</font>"."
    ".get_date($arr['complete_date'], 0,1) ." ".($arr['complete_date'] == '0'  ? "".($arr['owner'] == $id ? "" : "[ ".mksize($arr["size"] - $arr["downloaded"])." still to go ]")."" : "")."")." ".get_date($arr['complete_date'], 0,1) ." ".($arr['complete_date'] != '0'  ? "<br />"."
    <font color='silver'>time to download: ".($arr['leechtime'] != '0' ? mkprettytime($arr['leechtime']) : mkprettytime($arr['c'] - $arr['s'])."")."</font> <font color='$dlc'>[ DLed at: $dl_speed ]<font>"."
    <br />" : "<br />")."<font color='lightblue'>".($arr['seedtime'] != '0' ? "total seeding time: ".mkprettytime($arr['seedtime'])." <font color='$dlc'> " : "total seeding time: N/A").""."
    </font><font color='lightgreen'> [ up speed: ".$ul_speed." ] </font>".get_date($arr['complete_date'], 0,1) ."".($arr['complete_date'] == '0'  ? "<br /><font color='$dlc'>Download speed: $dl_speed</font>" : "")."</td>"."
    <td align='center' class='$class'>Seeds: ".$arr['seeders']."<br />Leech: ".$arr['leechers']."</td><td align='center' class='$class'><font color='lightgreen'>Uploaded:<br />"."
    <b>".$uploaded =mksize($arr["uploaded"])."</b></font><br /><font color='orange'>Downloaded:<br /><b>".$downloaded = mksize($arr["downloaded"])."</b></font></td>"."
    <td align='center' class='$class'>".mksize($arr["size"])."<br />difference of:<br /><font color='orange'><b>".mksize($arr['size'] - $arr["downloaded"])."</b></font></td>"."
    <td align='center' class='$class'>$ratio<br />".($arr['seeder'] == 'yes' ? "<font color='lightgreen'><b>seeding</b></font>" : "<font color='red'><b>not seeding</b></font>").""."
    </td><td align='center' class='$class'>".$arr["agent"]."<br />port: ".$arr["port"]."<br />".($arr["connectable"] == 'yes' ? "<b>connectable: <font color='lightgreen'>yes</font>"."
    </b>" : "<b>connectable: <font color='red'><b>no</b></font>")."</td></tr>\n";
    }
    $HTMLOUT .= "</table></td></tr>\n";
    }
    else
    $HTMLOUT .= tr("Snatched stuff:<br />","[ <a class=altlink href=\"userdetails.php?id=$id&snatched_table=1\" class=\"sublink\">Show</a> ]  - $count_snatched <font color='red'><b>staff only!!!</font></b>", 1);
    }
    //=== end snatched


details.php find :

Code (php) Select
$HTMLOUT .= tr("{$lang['details_snatched']}", $row["times_completed"] . "{$lang['details_times']}");

replace with :

Code (php) Select
$HTMLOUT .= tr("{$lang['details_snatched']}", ($row["times_completed"] > 0 ? "<a href=snatches.php?id=$id>$row[times_completed] {$lang['details_times']}</a>" : "0 {$lang['details_times']}"), 1);

include/torrenttable_functions.php - find :

   
Code (php) Select
if ($row["times_completed"] != 1)
          $_s = "".$lang["torrenttable_time_plural"]."";
        else
          $_s = "".$lang["torrenttable_time_singular"]."";
        $htmlout .= "<td align='center'>" . number_format($row["times_completed"]) . "<br />$_s</td>\n";


change to :

   
Code (php) Select

        if ($row["times_completed"] != 1)
          $_s = "".$lang["torrenttable_time_plural"]."";
        else
          $_s = "".$lang["torrenttable_time_singular"]."";
        $htmlout .= "<td align='center'><a href=snatches.php?id=$id>" . number_format($row["times_completed"]) . "<br />$_s</td>\n";


lastly announce.php - find :

Code (php) Select
$fields = "seeder, peer_id, ip, port, uploaded, downloaded, userid";

Change to :

Code (php) Select
$fields = 'seeder, peer_id, ip, port, uploaded, downloaded, userid, ('.time().' - last_action) AS announcetime';

under this :

Code (php) Select
$upthis = max(0, $uploaded - $self["uploaded"]);
$downthis = max(0, $downloaded - $self["downloaded"]);


add this :

Code (php) Select
$upspeed = ($upthis > 0 ? $upthis / $self["announcetime"] : 0);
$downspeed = ($downthis > 0 ? $downthis / $self["announcetime"] : 0);
$announcetime = ($self["seeder"] == "yes" ? "seedtime = seedtime + $self[announcetime]" : "leechtime = leechtime + $self[announcetime]");


find this :

Code (php) Select
if (portblacklisted($port))
err("Port $port is blacklisted.");
else
{
$sockres = @fsockopen($ip, $port, $errno, $errstr, 5);
if (!$sockres)
$connectable = "no";
else
{
$connectable = "yes";
@fclose($sockres);
}
}

      
copy it to above this :

Code (php) Select
$updateset = array();

Finally find the large update section

Code (php) Select
if ($event == "stopped")
{
if (isset($self))
{
mysql_query("DELETE FROM peers WHERE $selfwhere");
if (mysql_affected_rows())
{
if ($self["seeder"] == "yes")
$updateset[] = "seeders = seeders - 1";
else
$updateset[] = "leechers = leechers - 1";
}
}
}
else
{
if ($event == "completed")
$updateset[] = "times_completed = times_completed + 1";

if (isset($self))
{
mysql_query("UPDATE peers SET uploaded = $uploaded, downloaded = $downloaded, to_go = $left, last_action = ".time().", seeder = '$seeder'"
. ($seeder == "yes" && $self["seeder"] != $seeder ? ", finishedat = " . time() : "") . " WHERE $selfwhere");
if (mysql_affected_rows() && $self["seeder"] != $seeder)
{
if ($seeder == "yes")
{
$updateset[] = "seeders = seeders + 1";
$updateset[] = "leechers = leechers - 1";
}
else
{
$updateset[] = "seeders = seeders - 1";
$updateset[] = "leechers = leechers + 1";
}
}
}
else
{
if ($event != "started")
err("Peer not found. ".$passkey." Restart the torrent.");

if (portblacklisted($port))
err("Port $port is blacklisted.");
else
{
$sockres = @fsockopen($ip, $port, $errno, $errstr, 5);
if (!$sockres)
$connectable = "no";
else
{
$connectable = "yes";
@fclose($sockres);
}
}

$ret = mysql_query("INSERT INTO peers (connectable, torrent, peer_id, ip, port, uploaded, downloaded, to_go, started, last_action, seeder, userid, agent, passkey) VALUES ('$connectable', $torrentid, " . sqlesc($peer_id) . ", " . sqlesc($ip) . ", $port, $uploaded, $downloaded, $left, ".time().", ".time().", '$seeder', {$user['id']}, " . sqlesc($agent) . "," . sqlesc($passkey) . ")");

if ($ret)
{
if ($seeder == "yes")
$updateset[] = "seeders = seeders + 1";
else
$updateset[] = "leechers = leechers + 1";
}
}
}


replace it with this :

Code (php) Select
if (isset($self) && $event == "stopped") {
mysql_query("DELETE FROM peers WHERE $selfwhere") or err("D Err");

if (mysql_affected_rows()) {
$updateset[] = ($self["seeder"] == "yes" ? "seeders = seeders - 1" : "leechers = leechers - 1");
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', uploaded = uploaded + $upthis, downloaded = downloaded + $downthis, to_go = $left, upspeed = $upspeed, downspeed = $downspeed, $announcetime, last_action = ".time().", seeder = '$seeder', agent = ".sqlesc($agent)." WHERE torrentid = $torrentid AND userid = {$user['id']}") or err("SL Err 1");
}
} elseif (isset($self)) {

if ($event == "completed") {
$updateset[] = "times_completed = times_completed + 1";
$finished = ", finishedat = ".time()."";
$finished1 = ", complete_date = ".time()."";
}

mysql_query("UPDATE peers SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', uploaded = $uploaded, downloaded = $downloaded, to_go = $left, last_action = " . time() . ", seeder = '$seeder', agent = ".sqlesc($agent)." $finished WHERE $selfwhere") or err("PL Err 1");

if (mysql_affected_rows()) {
if ($seeder <> $self["seeder"])
$updateset[] = ($seeder == "yes" ? "seeders = seeders + 1, leechers = leechers - 1" : "seeders = seeders - 1, leechers = leechers + 1");
$anntime = "timesann = timesann + 1";
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', uploaded = uploaded + $upthis, downloaded = downloaded + $downthis, to_go = $left, upspeed = $upspeed, downspeed = $downspeed, $announcetime, last_action = ".time().", seeder = '$seeder', agent = ".sqlesc($agent)." $finished1, $anntime WHERE torrentid = $torrentid AND userid = {$user['id']}") or err("SL Err 2");
}
} else {
//if ($az["parked"] == "yes") //== uncommet if you use parked
//err("Your account is parked! (Read the FAQ)"); //== uncommet if you use parked
//elseif ($az["downloadpos"] == "no") //== uncommet if you use downloapos
//err("Your downloading priviledges have been disabled! (Read the rules)"); //== uncommet if you use downloapos

mysql_query("INSERT INTO peers (torrent, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, started, last_action, seeder, agent, downloadoffset, uploadoffset, passkey) VALUES ($torrentid, {$user['id']}, ".sqlesc($peer_id).", ".sqlesc($ip).", $port, '$connectable', $uploaded, $downloaded, $left, ".time().", ".time().", '$seeder', ".sqlesc($agent).", $downloaded, $uploaded, ".sqlesc($passkey).")") or err("PL Err 2");

if (mysql_affected_rows()) {
$updateset[] = ($seeder == "yes" ? "seeders = seeders + 1" : "leechers = leechers + 1");
$anntime = "timesann = timesann + 1";
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', to_go = $left, last_action = ".time().", seeder = '$seeder', agent = ".sqlesc($agent).", $anntime WHERE torrentid = $torrentid AND userid = {$user['id']}") or err("SL Err 3");

if (!mysql_affected_rows() && $seeder == "no")
mysql_query("INSERT INTO snatched (torrentid, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, start_date, last_action, seeder, agent) VALUES ($torrentid, {$user['id']}, ".sqlesc($peer_id).", ".sqlesc($ip).", $port, '$connectable', $uploaded, $downloaded, $left, ".time().", ".time().", '$seeder', ".sqlesc($agent).")") or err("SL Err 4");
}
}


finally upload this to lang/en :

lang_snatches.php :

Code (php) Select
<?php

$lang 
= array(

#snatchtable
'snatches_username' => "Username",
'snatches_connectable' => "Connectable",
'snatches_uploaded' => "Uploaded",
'snatches_upspeed' => "Upspeed",
'snatches_downloaded' => "Downloaded",
'snatches_downspeed' => "Downspeed",
'snatches_ratio' => "Ratio",
'snatches_completed' => "Completed",
'snatches_seedtime' => "Seed time",
'snatches_leechtime' => "Leech time",
'snatches_lastaction' => "Last action",
'snatches_completedat' => "Completed at",
'snatches_client' => "Client",
'snatches_port' => "Port",
'snatches_announced' => "Announced"
);

?>


And that should be it :)