PageRenderTime 62ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/dead/details.php

https://bitbucket.org/nexea/x00n
PHP | 389 lines | 278 code | 39 blank | 72 comment | 33 complexity | ba9484340b224dffccb7b4ffab7ca532 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?
  2. ob_start("ob_gzhandler");
  3. require_once("include/bittorrent.php");
  4. function getagent($httpagent)
  5. {
  6. if (preg_match("/^Azureus ([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)/", $httpagent, $matches))
  7. return "Azureus/$matches[1]";
  8. elseif (preg_match("/BitTorrent\\/S-([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches))
  9. return "Shadow's/$matches[1]";
  10. elseif (preg_match("/BitTorrent\\/U-([0-9]+\\.[0-9]+\\.[0-9]+)/", $httpagent, $matches))
  11. return "UPnP/$matches[1]";
  12. elseif (preg_match("/^BitTorrent\\/T-(.+)$/", $httpagent, $matches))
  13. return "BitTornado/$matches[1]";
  14. elseif (preg_match("/^BitTorrent\\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches))
  15. return "BitTorrent/$matches[1]";
  16. elseif (preg_match("/^Python-urllib\\/.+?, BitTorrent\\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches))
  17. return "BitTorrent/$matches[1]";
  18. elseif (ereg("^BitTorrent\\/BitSpirit$", $httpagent))
  19. return "BitSpirit";
  20. elseif (preg_match("/^BitTorrent\\/brst(.+)/", $httpagent, $matches))
  21. return "Burst/$matches[1]";
  22. elseif (preg_match("/^RAZA (.+)$/", $httpagent, $matches))
  23. return "Shareaza/$matches[1]";
  24. else
  25. return "---";
  26. }
  27. function dltable($name, $arr, $torrent)
  28. {
  29. global $CURUSER;
  30. $s = "<b>" . count($arr) . " $name</b>\n";
  31. if (!count($arr))
  32. return $s;
  33. $s .= "\n";
  34. $s .= "<table width=100% class=main border=1 cellspacing=0 cellpadding=5>\n";
  35. $s .= "<tr><td class=colhead>User/IP</td>" .
  36. "<td class=colhead align=center>Connectable</td>".
  37. "<td class=colhead align=right>Uploaded</td>".
  38. "<td class=colhead align=right>Rate</td>".
  39. "<td class=colhead align=right>Downloaded</td>" .
  40. "<td class=colhead align=right>Rate</td>" .
  41. "<td class=colhead align=right>Ratio</td>" .
  42. "<td class=colhead align=right>Complete</td>" .
  43. "<td class=colhead align=right>Connected</td>" .
  44. "<td class=colhead align=right>Idle</td>" .
  45. "<td class=colhead align=left>Client</td></tr>\n";
  46. $now = time();
  47. $moderator = (isset($CURUSER) && get_user_class() >= UC_MODERATOR);
  48. $mod = get_user_class() >= UC_MODERATOR;
  49. foreach ($arr as $e) {
  50. // user/ip/port
  51. // check if anyone has this ip
  52. ($unr = mysql_query("SELECT username, privacy FROM users WHERE id=$e[userid] ORDER BY last_access DESC LIMIT 1")) or die;
  53. $una = mysql_fetch_array($unr);
  54. if ($una["privacy"] == "strong") continue;
  55. $s .= "<tr>\n";
  56. if ($una["username"])
  57. $s .= "<td><a href=userdetails.php?id=$e[userid]><b>$una[username]</b></a></td>\n";
  58. else
  59. $s .= "<td>" . ($mod ? $e["ip"] : preg_replace('/\.\d+$/', ".xxx", $e["ip"])) . "</td>\n";
  60. $secs = max(1, ($now - $e["st"]) - ($now - $e["la"]));
  61. $revived = $e["revived"] == "yes";
  62. $s .= "<td align=center>" . ($e[connectable] == "yes" ? "Yes" : "<font color=red>No</font>") . "</td>\n";
  63. $s .= "<td align=right>" . mksize($e["uploaded"]) . "</td>\n";
  64. $s .= "<td align=right><nobr>" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</nobr></td>\n";
  65. $s .= "<td align=right>" . mksize($e["downloaded"]) . "</td>\n";
  66. if ($e["seeder"] == "no")
  67. $s .= "<td align=right><nobr>" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</nobr></td>\n";
  68. else
  69. $s .= "<td align=right><nobr>" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e[st])) . "/s</nobr></td>\n";
  70. if ($e["downloaded"])
  71. {
  72. $ratio = floor(($e["uploaded"] / $e["downloaded"]) * 1000) / 1000;
  73. $s .= "<td align=\"right\"><font color=" . get_ratio_color($ratio) . ">" . number_format($ratio, 3) . "</font></td>\n";
  74. }
  75. else
  76. if ($e["uploaded"])
  77. $s .= "<td align=right>Inf.</td>\n";
  78. else
  79. $s .= "<td align=right>---</td>\n";
  80. $s .= "<td align=right>" . sprintf("%.2f%%", 100 * (1 - ($e["to_go"] / $torrent["size"]))) . "</td>\n";
  81. $s .= "<td align=right>" . mkprettytime($now - $e["st"]) . "</td>\n";
  82. $s .= "<td align=right>" . mkprettytime($now - $e["la"]) . "</td>\n";
  83. $s .= "<td align=left>" . htmlspecialchars(getagent($e["agent"])) . "</td>\n";
  84. $s .= "</tr>\n";
  85. }
  86. $s .= "</table>\n";
  87. return $s;
  88. }
  89. dbconn(false);
  90. loggedinorreturn();
  91. $id = $_GET["id"];
  92. $id = 0 + $id;
  93. if (!isset($id) || !$id)
  94. die();
  95. $res = mysql_query("SELECT torrents.seeders, torrents.banned, torrents.leechers, torrents.info_hash, torrents.filename, UNIX_TIMESTAMP() - UNIX_TIMESTAMP(torrents.last_action) AS lastseed, torrents.numratings, torrents.name, IF(torrents.numratings < $minvotes, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.owner, torrents.save_as, torrents.descr, torrents.visible, torrents.size, torrents.added, torrents.views, torrents.hits, torrents.times_completed, torrents.id, torrents.type, torrents.numfiles, categories.name AS cat_name, users.username FROM torrents LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE torrents.id = $id")
  96. or sqlerr();
  97. $row = mysql_fetch_array($res);
  98. $owned = $moderator = 0;
  99. if (get_user_class() >= UC_MODERATOR)
  100. $owned = $moderator = 1;
  101. elseif ($CURUSER["id"] == $row["owner"])
  102. $owned = 1;
  103. //}
  104. if (!$row || ($row["banned"] == "yes" && !$moderator))
  105. stderr("Error", "No torrent with ID $id.");
  106. else {
  107. if ($_GET["hit"]) {
  108. mysql_query("UPDATE torrents SET views = views + 1 WHERE id = $id");
  109. if ($_GET["tocomm"])
  110. header("Location: $DEFAULTBASEURL/details.php?id=$id&page=0#startcomments");
  111. elseif ($_GET["filelist"])
  112. header("Location: $DEFAULTBASEURL/details.php?id=$id&filelist=1#filelist");
  113. elseif ($_GET["toseeders"])
  114. header("Location: $DEFAULTBASEURL/details.php?id=$id&dllist=1#seeders");
  115. elseif ($_GET["todlers"])
  116. header("Location: $DEFAULTBASEURL/details.php?id=$id&dllist=1#leechers");
  117. else
  118. header("Location: $DEFAULTBASEURL/details.php?id=$id");
  119. exit();
  120. }
  121. if (!isset($_GET["page"])) {
  122. stdhead("Details for torrent \"" . $row["name"] . "\"");
  123. if ($CURUSER["id"] == $row["owner"] || get_user_class() >= UC_MODERATOR)
  124. $owned = 1;
  125. else
  126. $owned = 0;
  127. $spacer = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  128. if ($_GET["uploaded"]) {
  129. print("<h2>Successfully uploaded!</h2>\n");
  130. print("<p>You can start seeding now. <b>Note</b> that the torrent won't be visible until you do that!</p>\n");
  131. }
  132. elseif ($_GET["edited"]) {
  133. print("<h2>Successfully edited!</h2>\n");
  134. if (isset($_GET["returnto"]))
  135. print("<p><b>Go back to <a href=\"" . htmlspecialchars($_GET["returnto"]) . "\">whence you came</a>.</b></p>\n");
  136. }
  137. elseif (isset($_GET["searched"])) {
  138. print("<h2>Your search for \"" . htmlspecialchars($_GET["searched"]) . "\" gave a single result:</h2>\n");
  139. }
  140. elseif ($_GET["rated"])
  141. print("<h2>Rating added!</h2>\n");
  142. $s=$row["name"];
  143. print("<h1>$s</h1>\n");
  144. print("<table width=750 border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n");
  145. $url = "edit.php?id=" . $row["id"];
  146. if (isset($_GET["returnto"])) {
  147. $addthis = "&amp;returnto=" . urlencode($_GET["returnto"]);
  148. $url .= $addthis;
  149. $keepget .= $addthis;
  150. }
  151. $editlink = "a href=\"$url\" class=\"sublink\"";
  152. // $s = "<b>" . htmlspecialchars($row["name"]) . "</b>";
  153. // if ($owned)
  154. // $s .= " $spacer<$editlink>[Edit torrent]</a>";
  155. // tr("Name", $s, 1);
  156. print("<tr><td class=rowhead width=1%>Download</td><td width=99% align=left><a class=\"index\" href=\"download.php/$id/" . rawurlencode($row["filename"]) . "\">" . htmlspecialchars($row["filename"]) . "</a></td></tr>");
  157. // tr("Downloads&nbsp;as", $row["save_as"]);
  158. function hex_esc($matches) {
  159. return sprintf("%02x", ord($matches[0]));
  160. }
  161. tr("Info hash", preg_replace_callback('/./s', "hex_esc", hash_pad($row["info_hash"])));
  162. if (!empty($row["descr"]))
  163. tr("Description", str_replace(array("\n", " "), array("<br>\n", "&nbsp; "), format_urls(htmlspecialchars($row["descr"]))), 1);
  164. if ($row["visible"] == "no")
  165. tr("Visible", "<b>no</b> (dead)", 1);
  166. if ($moderator)
  167. tr("Banned", $row["banned"]);
  168. if (isset($row["cat_name"]))
  169. tr("Type", $row["cat_name"]);
  170. else
  171. tr("Type", "(none selected)");
  172. tr("Last&nbsp;seeder", "Last activity " . mkprettytime($row["lastseed"]) . " ago");
  173. tr("Size",mksize($row["size"]) . " (" . number_format($row["size"]) . " bytes)");
  174. /*
  175. $s = "";
  176. $s .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" class=embedded>";
  177. if (!isset($row["rating"])) {
  178. if ($minvotes > 1) {
  179. $s .= "none yet (needs at least $minvotes votes and has got ";
  180. if ($row["numratings"])
  181. $s .= "only " . $row["numratings"];
  182. else
  183. $s .= "none";
  184. $s .= ")";
  185. }
  186. else
  187. $s .= "No votes yet";
  188. }
  189. else {
  190. $rpic = ratingpic($row["rating"]);
  191. if (!isset($rpic))
  192. $s .= "invalid?";
  193. else
  194. $s .= "$rpic (" . $row["rating"] . " out of 5 with " . $row["numratings"] . " vote(s) total)";
  195. }
  196. $s .= "\n";
  197. $s .= "</td><td class=embedded>$spacer</td><td valign=\"top\" class=embedded>";
  198. if (!isset($CURUSER))
  199. $s .= "(<a href=\"login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;nowarn=1\">Log in</a> to rate it)";
  200. else {
  201. $ratings = array(
  202. 5 => "Kewl!",
  203. 4 => "Pretty good",
  204. 3 => "Decent",
  205. 2 => "Pretty bad",
  206. 1 => "Sucks!",
  207. );
  208. if (!$owned || $moderator) {
  209. $xres = mysql_query("SELECT rating, added FROM ratings WHERE torrent = $id AND user = " . $CURUSER["id"]);
  210. $xrow = mysql_fetch_array($xres);
  211. if ($xrow)
  212. $s .= "(you rated this torrent as \"" . $xrow["rating"] . " - " . $ratings[$xrow["rating"]] . "\")";
  213. else {
  214. $s .= "<form method=\"post\" action=\"takerate.php\"><input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
  215. $s .= "<select name=\"rating\">\n";
  216. $s .= "<option value=\"0\">(add rating)</option>\n";
  217. foreach ($ratings as $k => $v) {
  218. $s .= "<option value=\"$k\">$k - $v</option>\n";
  219. }
  220. $s .= "</select>\n";
  221. $s .= "<input type=\"submit\" value=\"Vote!\" />";
  222. $s .= "</form>\n";
  223. }
  224. }
  225. }
  226. $s .= "</td></tr></table>";
  227. tr("Rating", $s, 1);
  228. */
  229. tr("Added", $row["added"]);
  230. tr("Views", $row["views"]);
  231. tr("Hits", $row["hits"]);
  232. tr("Snatched", $row["times_completed"] . " time(s)");
  233. $keepget = "";
  234. $uprow = (isset($row["username"]) ? ("<a href=userdetails.php?id=" . $row["owner"] . "><b>" . htmlspecialchars($row["username"]) . "</b></a>") : "<i>unknown</i>");
  235. if ($owned)
  236. $uprow .= " $spacer<$editlink><b>[Edit this torrent]</b></a>";
  237. tr("Upped by", $uprow, 1);
  238. if ($row["type"] == "multi") {
  239. if (!$_GET["filelist"])
  240. tr("Num files<br /><a href=\"details.php?id=$id&amp;filelist=1$keepget#filelist\" class=\"sublink\">[See full list]</a>", $row["numfiles"] . " files", 1);
  241. else {
  242. tr("Num files", $row["numfiles"] . " files", 1);
  243. $s = "<table class=main border=\"1\" cellspacing=0 cellpadding=\"5\">\n";
  244. $subres = mysql_query("SELECT * FROM files WHERE torrent = $id ORDER BY id");
  245. $s.="<tr><td class=colhead>Path</td><td class=colhead align=right>Size</td></tr>\n";
  246. while ($subrow = mysql_fetch_array($subres)) {
  247. $s .= "<tr><td>" . $subrow["filename"] .
  248. "</td><td align=\"right\">" . mksize($subrow["size"]) . "</td></tr>\n";
  249. }
  250. $s .= "</table>\n";
  251. tr("<a name=\"filelist\">File list</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Hide list]</a>", $s, 1);
  252. }
  253. }
  254. if (!$_GET["dllist"]) {
  255. /*
  256. $subres = mysql_query("SELECT seeder, COUNT(*) FROM peers WHERE torrent = $id GROUP BY seeder");
  257. $resarr = array(yes => 0, no => 0);
  258. $sum = 0;
  259. while ($subrow = mysql_fetch_array($subres)) {
  260. $resarr[$subrow[0]] = $subrow[1];
  261. $sum += $subrow[1];
  262. }
  263. tr("Peers<br /><a href=\"details.php?id=$id&amp;dllist=1$keepget#seeders\" class=\"sublink\">[See full list]</a>", $resarr["yes"] . " seeder(s), " . $resarr["no"] . " leecher(s) = $sum peer(s) total", 1);
  264. */
  265. tr("Peers<br /><a href=\"details.php?id=$id&amp;dllist=1$keepget#seeders\" class=\"sublink\">[See full list]</a>", $row["seeders"] . " seeder(s), " . $row["leechers"] . " leecher(s) = " . ($row["seeders"] + $row["leechers"]) . " peer(s) total", 1);
  266. }
  267. else {
  268. $downloaders = array();
  269. $seeders = array();
  270. $subres = mysql_query("SELECT seeder, finishedat, downloadoffset, uploadoffset, ip, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id") or sqlerr();
  271. while ($subrow = mysql_fetch_array($subres)) {
  272. if ($subrow["seeder"] == "yes")
  273. $seeders[] = $subrow;
  274. else
  275. $downloaders[] = $subrow;
  276. }
  277. function leech_sort($a,$b) {
  278. if ( isset( $_GET["usort"] ) ) return seed_sort($a,$b);
  279. $x = $a["to_go"];
  280. $y = $b["to_go"];
  281. if ($x == $y)
  282. return 0;
  283. if ($x < $y)
  284. return -1;
  285. return 1;
  286. }
  287. function seed_sort($a,$b) {
  288. $x = $a["uploaded"];
  289. $y = $b["uploaded"];
  290. if ($x == $y)
  291. return 0;
  292. if ($x < $y)
  293. return 1;
  294. return -1;
  295. }
  296. usort($seeders, "seed_sort");
  297. usort($downloaders, "leech_sort");
  298. tr("<a name=\"seeders\">Seeders</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Hide list]</a>", dltable("Seeder(s)", $seeders, $row), 1);
  299. tr("<a name=\"leechers\">Leechers</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Hide list]</a>", dltable("Leecher(s)", $downloaders, $row), 1);
  300. }
  301. print("</table></p>\n");
  302. }
  303. else {
  304. stdhead("Comments for torrent \"" . $row["name"] . "\"");
  305. print("<h1>Comments for <a href=details.php?id=$id>" . $row["name"] . "</a></h1>\n");
  306. // print("<p><a href=\"details.php?id=$id\">Back to full details</a></p>\n");
  307. }
  308. print("<p><a name=\"startcomments\"></a></p>\n");
  309. $commentbar = "<p align=center><a class=index href=comment.php?action=add&amp;tid=$id>Add a comment</a></p>\n";
  310. $subres = mysql_query("SELECT COUNT(*) FROM comments WHERE torrent = $id");
  311. $subrow = mysql_fetch_array($subres);
  312. $count = $subrow[0];
  313. if (!$count) {
  314. print("<h2>No comments yet</h2>\n");
  315. }
  316. else {
  317. list($pagertop, $pagerbottom, $limit) = pager(20, $count, "details.php?id=$id&", array(lastpagedefault => 1));
  318. $subres = mysql_query("SELECT comments.id, text, user, comments.added, editedby, editedat, avatar, warned, ".
  319. "username, title, class, donor FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = " .
  320. "$id ORDER BY comments.id $limit") or sqlerr(__FILE__, __LINE__);
  321. $allrows = array();
  322. while ($subrow = mysql_fetch_array($subres))
  323. $allrows[] = $subrow;
  324. print($commentbar);
  325. print($pagertop);
  326. commenttable($allrows);
  327. print($pagerbottom);
  328. }
  329. print($commentbar);
  330. }
  331. stdfoot();
  332. ?>