Skip to content

Commit

Permalink
Merge branch 'unstable'
Browse files Browse the repository at this point in the history
Мультитрекер с ручным обновлением и поддержкой UDP
и другие исправления в т.ч оптимизация заливки и download.php для больших торрент-файлов.
  • Loading branch information
yunasc committed Mar 4, 2014
2 parents 779acee + 79bdfa2 commit 01e80bf
Show file tree
Hide file tree
Showing 29 changed files with 967 additions and 130 deletions.
4 changes: 2 additions & 2 deletions admin/modules/faq.php
Expand Up @@ -54,8 +54,8 @@ function FaqAdmin() {
print("<option value=\"$n\"". $sel .">". $n ."</option>");
}
if ($faq_categ[$id]["items"][$id2][flag] == "0") $status = "<font color=\"#FF0000\">Ñêðûòî</font>";
elseif ($faq_categ[$id]["items"][$id2][flag] == "2") $status = "<font color=\"#0000FF\"><img src=\"".$rootpath.$pic_base_url."updated.png\" alt=\"Updated\" align=\"absbottom\"></font>";
elseif ($faq_categ[$id]["items"][$id2][flag] == "3") $status = "<font color=\"#008000\"><img src=\"".$rootpath.$pic_base_url."new.png\" alt=\"Íîâîå\" align=\"absbottom\"></font>";
elseif ($faq_categ[$id]["items"][$id2][flag] == "2") $status = "<font color=\"#0000FF\"><img src=\"".$rootpath.$pic_base_url."/updated.png\" alt=\"Updated\" align=\"absbottom\"></font>";
elseif ($faq_categ[$id]["items"][$id2][flag] == "3") $status = "<font color=\"#008000\"><img src=\"".$rootpath.$pic_base_url."/new.png\" alt=\"Íîâîå\" align=\"absbottom\"></font>";
else $status = "Îáû÷íûé";
print("</select></td><td>". $faq_categ[$id]["items"][$id2]["question"] ."</td><td align=\"center\" width=\"60px\">". $status ."</td><td align=\"center\" width=\"60px\"><a href=\"$admin_file.php?op=FaqAction&action=edit&id=". $id2 ."\">E</a> / <a href=\"$admin_file.php?op=FaqAction&action=delete&id=". $id2 ."\">D</a></td></tr>\n");
}
Expand Down
4 changes: 4 additions & 0 deletions blocks/block-stats.php
Expand Up @@ -14,6 +14,7 @@
$dead = number_format(get_row_count("torrents", "WHERE visible='no'"));
$seeders = get_row_count("peers", "WHERE seeder='yes'");
$leechers = get_row_count("peers", "WHERE seeder='no'");
list($external_seeders, $external_leechers) = array_map('number_format', mysql_fetch_row(sql_query('SELECT SUM(seeders), SUM(leechers) FROM torrents_scrape')));
$warned_users = number_format(get_row_count("users", "WHERE warned = 'yes'"));
$disabled = number_format(get_row_count("users", "WHERE enabled = 'no'"));
$uploaders = number_format(get_row_count("users", "WHERE class = ".UC_UPLOADER));
Expand Down Expand Up @@ -51,6 +52,9 @@
<tr><td class=\"rowhead\">".$tracker_lang['tracker_seed_peer']."</td><td align=right>$ratio</td></tr>";
}

$content .= "<tr><td class=\"rowhead\">".$tracker_lang['external_seeders']."&nbsp;&nbsp;<img src=\"./themes/$ss_uri/images/arrowup.gif\" border=0 align=absbottom></td><td align=right>$external_seeders</td></tr>
<tr><td class=\"rowhead\">".$tracker_lang['external_leechers']."&nbsp;&nbsp;<img src=\"./themes/$ss_uri/images/arrowdown.gif\" border=0 align=absbottom></td><td align=right>$external_leechers</td></tr>";

$content .= "</table></td>
</table>
Expand Down
2 changes: 1 addition & 1 deletion browse.php
Expand Up @@ -242,7 +242,7 @@
$addparam = $pagerlink;
}
list($pagertop, $pagerbottom, $limit) = pager($torrentsperpage, $count, "browse.php?" . $addparam);
$query = "SELECT t.id, t.moderated, t.moderatedby, t.category, t.leechers, t.seeders, t.free, t.name, t.times_completed, t.size, t.added, t.comments, t.numfiles, t.filename, t.not_sticky, t.owner," . "IF(t.numratings < $minvotes, NULL, ROUND(t.ratingsum / t.numratings, 1)) AS rating, c.name AS cat_name, c.image AS cat_pic, u.username, u.class" . ($CURUSER ? ", EXISTS(SELECT * FROM readtorrents WHERE readtorrents.userid = " . sqlesc($CURUSER["id"]) . " AND readtorrents.torrentid = t.id) AS readtorrent" : ", 1 AS readtorrent") . " FROM torrents AS t LEFT JOIN categories AS c ON t.category = c.id LEFT JOIN users AS u ON t.owner = u.id $where $orderby $limit";
$query = "SELECT t.id, t.moderated, t.moderatedby, t.category, (t.leechers + t.remote_leechers) AS leechers, (t.seeders + t.remote_seeders) AS seeders, t.multitracker, t.free, t.name, t.times_completed, t.size, t.added, t.comments, t.numfiles, t.filename, t.not_sticky, t.owner," . "IF(t.numratings < $minvotes, NULL, ROUND(t.ratingsum / t.numratings, 1)) AS rating, c.name AS cat_name, c.image AS cat_pic, u.username, u.class" . ($CURUSER ? ", EXISTS(SELECT * FROM readtorrents WHERE readtorrents.userid = " . sqlesc($CURUSER["id"]) . " AND readtorrents.torrentid = t.id) AS readtorrent" : ", 1 AS readtorrent") . " FROM torrents AS t LEFT JOIN categories AS c ON t.category = c.id LEFT JOIN users AS u ON t.owner = u.id $where $orderby $limit";
$res = sql_query($query) or die(mysql_error());
} else
unset($res);
Expand Down
17 changes: 15 additions & 2 deletions details.php
Expand Up @@ -190,7 +190,7 @@ function dltable($name, $arr, $torrent)
if (!isset($id) || !$id)
die();

$res = sql_query("SELECT t.keywords, t.description, t.free, t.seeders, t.banned, t.leechers, t.info_hash, t.filename, UNIX_TIMESTAMP() - UNIX_TIMESTAMP(t.last_action) AS lastseed, t.numratings, t.name, IF(t.numratings < $minvotes, NULL, ROUND(t.ratingsum / t.numratings, 1)) AS rating, t.owner, t.save_as, t.descr, t.visible, t.size, t.added, t.views, t.hits, t.times_completed, t.id, t.type, t.numfiles, t.image1, t.image2, t.image3, t.image4, t.image5, c.name AS cat_name, u.username FROM torrents AS t LEFT JOIN categories AS c ON t.category = c.id LEFT JOIN users AS u ON t.owner = u.id WHERE t.id = $id")
$res = sql_query("SELECT t.multitracker, t.last_mt_update, t.keywords, t.description, t.free, t.seeders, t.banned, t.leechers, t.info_hash, t.filename, UNIX_TIMESTAMP() - UNIX_TIMESTAMP(t.last_action) AS lastseed, t.numratings, t.name, IF(t.numratings < $minvotes, NULL, ROUND(t.ratingsum / t.numratings, 1)) AS rating, t.owner, t.save_as, t.descr, t.visible, t.size, t.added, t.views, t.hits, t.times_completed, t.id, t.type, t.numfiles, t.image1, t.image2, t.image3, t.image4, t.image5, c.name AS cat_name, u.username FROM torrents AS t LEFT JOIN categories AS c ON t.category = c.id LEFT JOIN users AS u ON t.owner = u.id WHERE t.id = $id")
or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_array($res);

Expand Down Expand Up @@ -439,6 +439,19 @@ function seed_sort($a,$b) {
tr("<a name=\"leechers\">".$tracker_lang['details_leeching']."</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[".$tracker_lang['close_list']."]</a>", dltable($tracker_lang['details_leeching'], $downloaders, $row), 1);
}

if ($row["multitracker"] == 'yes') {
$announces_r = sql_query('SELECT url, seeders, leechers, last_update, state, error FROM torrents_scrape WHERE tid = '.$id);
while ($announce = mysql_fetch_array($announces_r)) {
if ($announce['state'] == 'ok')
$anns[] = '<li><b>'.$announce['url'].'</b> - ðàçäàþùèå: <b>'.$announce['seeders'].'</b>, êà÷àþùèå: <b>'.$announce['leechers'].'</b>';
else
$anns[] = '<li><font color="red"><b>'.$announce['url'].'</b></font> - íå ðàáîòàåò, îøèáêà: '.$announce['error'].'</b>';
}
if (strtotime($row['last_mt_update']) < (TIMENOW - 3600))
$update_link = '<br />Äàííûå ìîãëè óñòàðåòü. <a href="update_multi.php?id='.$id.'">Îáíîâèòü ìóëüòèòðåêåð</a>';
tr("Ìóëüòèòðåêåð", '<ul style="margin: 0;">'.implode($anns).'</ul>'.$update_link, 1);
}

if ($row["times_completed"] > 0) {
$res = sql_query("SELECT users.id, users.username, users.title, users.uploaded, users.downloaded, users.donor, users.enabled, users.warned, users.last_access, users.class, snatched.startdat, snatched.last_action, snatched.completedat, snatched.seeder, snatched.userid, snatched.uploaded AS sn_up, snatched.downloaded AS sn_dn FROM snatched INNER JOIN users ON snatched.userid = users.id WHERE snatched.finished='yes' AND snatched.torrent =" . sqlesc($id) . " ORDER BY users.class DESC $limit") or sqlerr(__FILE__,__LINE__);
$snatched_full = "<table width=100% class=main border=1 cellspacing=0 cellpadding=5>\n";
Expand Down Expand Up @@ -472,7 +485,7 @@ function seed_sort($a,$b) {
//$highlight = $CURUSER["id"] == $arr["id"] ? " bgcolor=#00A527" : "";;
$snatched_small[] = "<a href=userdetails.php?id=$arr[userid]>".get_user_class_color($arr["class"], $arr["username"])." (<font color=" . get_ratio_color($ratio) . ">$ratio</font>)</a>";
$snatched_full .= "<tr$highlight><td><a href=userdetails.php?id=$arr[userid]>".get_user_class_color($arr["class"], $arr["username"])."</a>".get_user_icons($arr)."</td><td><nobr>$uploaded&nbsp;Îáùåãî<br>$uploaded2&nbsp;Òîððåíò</nobr></td><td><nobr>$downloaded&nbsp;Îáùåãî<br>$downloaded2&nbsp;Òîððåíò</nobr></td><td><nobr>$ratio&nbsp;Îáùåãî<br>$ratio2&nbsp;Òîððåíò</nobr></td><td align=center><nobr>" . $arr["startdat"] . "<br />" . $arr["completedat"] . "</nobr></td><td align=center><nobr>" . $arr["last_action"] . "</nobr></td><td align=center>" . ($arr["seeder"] == "yes" ? "<b><font color=\"green\">Äà</font>" : "<font color=\"red\">Íåò</font></b>") .
"</td><td align=center><a href=message.php?action=sendmessage&amp;receiver=$arr[userid]><img src=$pic_base_url/button_pm.gif border=\"0\"></a></td></tr>\n";
"</td><td align=center><a href=message.php?action=sendmessage&amp;receiver=$arr[userid]><img src=\"$pic_base_url/button_pm.gif\" border=\"0\"></a></td></tr>\n";
}
$snatched_full .= "</table>\n";
?><script language="javascript" type="text/javascript" src="js/show_hide.js"></script><?
Expand Down
16 changes: 10 additions & 6 deletions download.php
Expand Up @@ -68,18 +68,22 @@

$name = str_replace(array(',', ';'), '', $name);

require_once "include/benc.php";
require_once "include/BDecode.php";
require_once "include/BEncode.php";

if (strlen($CURUSER['passkey']) != 32) {
$CURUSER['passkey'] = md5($CURUSER['username'].get_date_time().$CURUSER['passhash']);
sql_query("UPDATE users SET passkey=".sqlesc($CURUSER[passkey])." WHERE id=".sqlesc($CURUSER[id]));
}

$dict = bdec_file($fn, $max_torrent_size);
$dict = bdecode(file_get_contents($fn));

$dict['value']['announce']['value'] = $announce_urls[0]."?passkey=$CURUSER[passkey]";//"$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";
$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']).":".$dict['value']['announce']['value'];
$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
//$dict['announce'] = $announce_urls[0]."?passkey=$CURUSER[passkey]";//"$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";

if (!empty($dict['announce-list'])) {
$dict['announce-list'][][0] = $announce_urls[0]."?passkey=$CURUSER[passkey]"; // Just add one tracker for multitrackers, we are the last
} else
$dict['announce'] = $announce_urls[0]."?passkey=$CURUSER[passkey]";//"$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";

header ("Expires: Tue, 1 Jan 1980 00:00:00 GMT");
header ("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
Expand All @@ -94,6 +98,6 @@
header ("Content-Type: application/x-bittorrent");
ob_implicit_flush(true);

print(benc($dict));
print(BEncode($dict));

?>
7 changes: 2 additions & 5 deletions edit.php
Expand Up @@ -55,7 +55,8 @@
print("<input type=\"hidden\" name=\"returnto\" value=\"" . htmlspecialchars_uni($_GET["returnto"]) . "\" />\n");
print("<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n");
print("<tr><td class=\"colhead\" colspan=\"2\">Ðåäàêòèðîâàòü òîððåíò</td></tr>");
tr($tracker_lang['torrent_file'], "<input type=file name=tfile size=80>\n", 1);
if ($row['multitracker'] == 'no')
tr($tracker_lang['torrent_file'], "<input type=file name=tfile size=80>\n", 1); // disable torrent update for multitracked ones
tr($tracker_lang['torrent_name'], "<input type=\"text\" name=\"name\" value=\"" . $row["name"] . "\" size=\"80\" />", 1);
tr($tracker_lang['img_poster'], "<input type=radio name=img1action value='keep' checked>Îñòàâèòü ïîñòåð&nbsp&nbsp"."<input type=radio name=img1action value='delete'>Óäàëèòü ïîñòåð&nbsp&nbsp"."<input type=radio name=img1action value='update'>Îáíîâèòü ïîñòåð<br /><b>Ïîñòåð:</b>&nbsp&nbsp<input type=file name=image0 size=80>", 1);
tr($tracker_lang['images'],
Expand Down Expand Up @@ -84,10 +85,6 @@

$s .= "</select>\n";
tr("Òèï", $s, 1);

tr('Keywords', '<input type="text" name="keywords" value="' . $row['keywords'] . '" size="80" />', 1);
tr('Description', '<input type="text" name="description" value="' . $row['description'] . '" size="80" />', 1);

tr("Âèäèìûé", "<input type=\"checkbox\" name=\"visible\"" . (($row["visible"] == "yes") ? " checked=\"checked\"" : "" ) . " value=\"1\" />
Âèäèìûé â òîððåíòàõ<br /><table border=0 cellspacing=0 cellpadding=0 width=420><tr><td class=embedded>Îáðàòèòå âíèìàíèå, ÷òî òîððåíò àâòîìàòè÷åñêè ñòàíåò âèäèìûì êîãäà ïîÿâèòüñÿ ðàçäàþùèé è àâòîìàòè÷åñêè ïåðåñòàíåò áûòü âèäèìûì (ñòàíåò ìåðòâÿêîì) êîãäà íå áóäåò ðàçäàþùåãî íåêîòîðîå âðåìÿ.
Èñïîëüçóéòå ýòîò ïåðåêëþ÷àòåëü äëÿ óñêîðåíèÿ ïðîöåñà. Òàêæå ó÷òèòå ÷òî íåâèäèìûå òîððåíòû (ìåðòâÿêè) âñå-ðàâíî ìîãóò áûòü ïðîñìîòðåíû è íàéäåíû, ýòî ïðîñòî íå ïî-óìîë÷àíèþ.</td></tr></table>", 1);
Expand Down
4 changes: 2 additions & 2 deletions faq.php
Expand Up @@ -88,9 +88,9 @@
if ($faq_categ[$id][items][$id2][flag] == "1")
print("<li><a href=\"#". $id2 ."\" class=\"altlink\">". $faq_categ[$id][items][$id2][question] ."</a></li>\n");
elseif ($faq_categ[$id][items][$id2][flag] == "2")
print("<li><a href=\"#". $id2 ."\" class=\"altlink\">". $faq_categ[$id][items][$id2][question] ."</a> <img src=\"".$pic_base_url."updated.png\" alt=\"Îáíîâëåíî\" title=\"Îáíîâëåíî\" align=\"absbottom\"></li>\n");
print("<li><a href=\"#". $id2 ."\" class=\"altlink\">". $faq_categ[$id][items][$id2][question] ."</a> <img src=\"".$pic_base_url."/updated.png\" alt=\"Îáíîâëåíî\" title=\"Îáíîâëåíî\" align=\"absbottom\"></li>\n");
elseif ($faq_categ[$id][items][$id2][flag] == "3")
print("<li><a href=\"#". $id2 ."\" class=\"altlink\">". $faq_categ[$id][items][$id2][question] ."</a> <img src=\"".$pic_base_url."new.png\" alt=\"Íîâîå\" title=\"Íîâîå\" align=\"absbottom\"></li>\n");
print("<li><a href=\"#". $id2 ."\" class=\"altlink\">". $faq_categ[$id][items][$id2][question] ."</a> <img src=\"".$pic_base_url."/new.png\" alt=\"Íîâîå\" title=\"Íîâîå\" align=\"absbottom\"></li>\n");
}
}
print("</ul>\n</li>\n</ul>\n<br />\n");
Expand Down
212 changes: 212 additions & 0 deletions include/BDecode.php
@@ -0,0 +1,212 @@
<?php

/*
Programming info
All functions output a small array, which we'll call $return for now.
$return[0] is the data expected of the function
$return[1] is the offset over the whole bencoded data of the next
piece of data.
numberdecode returns [0] as the integer read, and [1]-1 points to the
symbol that was interprented as the end of the interger (either "e" or
":").
numberdecode is used for integer decodes both for i11e and 11:hello there
so it is tolerant of the ending symbol.
decodelist returns $return[0] as an integer indexed array like you would use in C
for all the entries. $return[1]-1 is the "e" that ends the list, so [1] is the next
useful byte.
decodeDict returns $return[0] as an array of text-indexed entries. For example,
$return[0]["announce"] = "http://www.whatever.com:6969/announce";
$return[1]-1 again points to the "e" that ends the dictionary.
decodeEntry returns [0] as an integer in the case $offset points to
i12345e or a string if $offset points to 11:hello there style strings.
It also calls decodeDict or decodeList if it encounters a d or an l.
Known bugs:
- The program doesn't pay attention to the string it's working on.
A zero-sized or truncated data block will cause string offset errors
before they get rejected by the decoder. This is worked around by
suppressing errors.
*/

// Protect our namespace using a class
class BDecode
{

function numberdecode($wholefile, $start)
{
$ret[0] = 0;
$offset = $start;

// Funky handling of negative numbers and zero
$negative = false;
if ($wholefile[$offset] == '-')
{
$negative = true;
$offset++;
}
if ($wholefile[$offset] == '0')
{
$offset++;
if ($negative)
return array(false);
if ($wholefile[$offset] == ':' || $wholefile[$offset] == 'e')
{
$offset++;
$ret[0] = 0;
$ret[1] = $offset;
return $ret;
}
return array(false);
}
while (true)
{

if ($wholefile[$offset] >= '0' && $wholefile[$offset] <= '9')
{

$ret[0] *= 10;
$ret[0] += ord($wholefile[$offset]) - ord("0");
$offset++;
}
// Tolerate : or e because this is a multiuse function
else if ($wholefile[$offset] == 'e' || $wholefile[$offset] == ':')
{
$ret[1] = $offset+1;
if ($negative)
{
if ($ret[0] == 0)
return array(false);
$ret[0] = - $ret[0];
}
return $ret;
}
else
return array(false);
}

}

function decodeEntry($wholefile, $offset=0)
{
if ($wholefile[$offset] == 'd')
return $this->decodeDict($wholefile, $offset);
if ($wholefile[$offset] == 'l')
return $this->decodelist($wholefile, $offset);
if ($wholefile[$offset] == "i")
{
$offset++;
return $this->numberdecode($wholefile, $offset);
}
// String value: decode number, then grab substring
$info = $this->numberdecode($wholefile, $offset);
if ($info[0] === false)
return array(false);
$ret[0] = substr($wholefile, $info[1], $info[0]);
$ret[1] = $info[1]+strlen($ret[0]);
return $ret;
}

function decodeList($wholefile, $start)
{
$offset = $start+1;
$i = 0;
if ($wholefile[$start] != 'l')
return array(false);
$ret = array();
while (true)
{
if ($wholefile[$offset] == 'e')
break;
$value = $this->decodeEntry($wholefile, $offset);
if ($value[0] === false)
return array(false);
$ret[$i] = $value[0];
$offset = $value[1];
$i ++;
}

// The empy list is an empty array. Seems fine.
$final[0] = $ret;
$final[1] = $offset+1;
return $final;

}

// Tries to construct an array
function decodeDict($wholefile, $start=0)
{
$offset = $start;
if ($wholefile[$offset] == 'l')
return $this->decodeList($wholefile, $start);
if ($wholefile[$offset] != 'd')
return false;
$ret = array();
$offset++;
while (true)
{
if ($wholefile[$offset] == 'e')
{
$offset++;
break;
}
$left = $this->decodeEntry($wholefile, $offset);
if (!$left[0])
return false;
$offset = $left[1];
if ($wholefile[$offset] == 'd')
{
// Recurse
$value = $this->decodedict($wholefile, $offset);
if (!$value[0])
return false;
$ret[addslashes($left[0])] = $value[0];
$offset= $value[1];
continue;
}
else if ($wholefile[$offset] == 'l')
{
$value = $this->decodeList($wholefile, $offset);
if (!$value[0] && is_bool($value[0]))
return false;
$ret[addslashes($left[0])] = $value[0];
$offset = $value[1];
}
else
{
$value = $this->decodeEntry($wholefile, $offset);
if ($value[0] === false)
return false;
$ret[addslashes($left[0])] = $value[0];
$offset = $value[1];
}
}
if (empty($ret))
$final[0] = true;
else
$final[0] = $ret;
$final[1] = $offset;
return $final;


}

} // End of class declaration.

// Use this function. eg: BDecode("d8:announce44:http://www. ... e");
function BDecode($wholefile)
{
$decoder = new BDecode;
$return = $decoder->decodeEntry($wholefile);
return $return[0];
}

?>

0 comments on commit 01e80bf

Please sign in to comment.