Advertisement
Guest User

Untitled

a guest
Apr 17th, 2012
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.77 KB | None | 0 0
  1. <?
  2.  
  3. /*
  4. // +--------------------------------------------------------------------------+
  5. // | Project: NVTracker - NetVision BitTorrent Tracker |
  6. // +--------------------------------------------------------------------------+
  7. // | This file is part of NVTracker. NVTracker is based on BTSource, |
  8. // | originally by RedBeard of TorrentBits, extensively modified by |
  9. // | Gartenzwerg. |
  10. // | |
  11. // | NVTracker is free software; you can redistribute it and/or modify |
  12. // | it under the terms of the GNU General Public License as published by |
  13. // | the Free Software Foundation; either version 2 of the License, or |
  14. // | (at your option) any later version. |
  15. // | |
  16. // | NVTracker is distributed in the hope that it will be useful, |
  17. // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  18. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  19. // | GNU General Public License for more details. |
  20. // | |
  21. // | You should have received a copy of the GNU General Public License |
  22. // | along with NVTracker; if not, write to the Free Software Foundation, |
  23. // | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  24. // +--------------------------------------------------------------------------+
  25. // | Obige Zeilen dürfen nicht entfernt werden! Do not remove above lines! |
  26. // +--------------------------------------------------------------------------+
  27. */
  28.  
  29. ob_start("ob_gzhandler");
  30.  
  31. require_once("include/bittorrent.php");
  32. require_once("include/benc.php");
  33.  
  34. hit_start();
  35.  
  36. function hex2bin($hexdata) {
  37.  
  38. for ($i=0;$i<strlen($hexdata);$i+=2) {
  39. $bindata.=chr(hexdec(substr($hexdata,$i,2)));
  40. }
  41.  
  42. return $bindata;
  43. }
  44.  
  45. function err($msg)
  46. {
  47. benc_resp(array("failure reason" => array(type => "string", value => $msg)));
  48. hit_end();
  49. exit();
  50. }
  51.  
  52. function benc_resp($d)
  53. {
  54. benc_resp_raw(benc(array(type => "dictionary", value => $d)));
  55. }
  56.  
  57. function benc_resp_raw($x)
  58. {
  59. header("Content-Type: text/plain");
  60. header("Pragma: no-cache");
  61. print($x);
  62. }
  63.  
  64. function check_ip_limit() {
  65. global $userid;
  66.  
  67. // Check IP limit
  68. $res = mysql_query("SELECT DISTINCT(ip) AS ip FROM peers WHERE userid=$userid");
  69. $count = 0;
  70. $found = FALSE;
  71. while ($row = mysql_fetch_assoc($res)) {
  72. $count++;
  73. if ($row["ip"] == $ip) {
  74. $found = TRUE;
  75. break;
  76. }
  77. }
  78.  
  79. if (!$found && $count >= $GLOBALS["MAX_PASSKEY_IPS"])
  80. err("Zu viele unterschiedliche IPs fuer diesen Benutzer (max ".$GLOBALS["MAX_PASSKEY_IPS"].")");
  81. }
  82.  
  83. include("include/dagent.class.php");
  84. dbconn(false);
  85. new UserAgent($_SERVER["HTTP_USER_AGENT"]);
  86.  
  87. $req = "info_hash:peer_id:!ip:port:uploaded:downloaded:left:!event";
  88. if ($GLOBALS["CLIENT_AUTH"] == CLIENT_AUTH_PASSKEY) {
  89. if ($GLOBALS["PASSKEY_SOURCE"] == PASSKEY_USE_PARAM) {
  90. $req .= ":passkey";
  91. // Using announce.php?passkey={KEY} will lead to an incorrect parameter list,
  92. // so the first parameter appended by the client gets appended to the passkey parameter.
  93. // This match will extract the parameter to $_GET
  94. if (preg_match("/^([a-f0-9]{16})\?(.*?)\=(.*)$/is", $_GET["passkey"], $m)) {
  95. $_GET["passkey"] = $m[1];
  96. $_GET[$m[2]] = $m[3];
  97. }
  98. }
  99. if ($GLOBALS["PASSKEY_SOURCE"] == PASSKEY_USE_SUBDOMAIN) {
  100. preg_match("/^([a-f0-9]{16})\./i", $_SERVER["HTTP_HOST"], $m);
  101. if (strlen($m[1])==16)
  102. $passkey = $m[1];
  103. else
  104. err("Fehlender Parameter fuer Announce: passkey");
  105. }
  106. }
  107.  
  108. foreach (explode(":", $req) as $x)
  109. {
  110. if ($x[0] == "!")
  111. {
  112. $x = substr($x, 1);
  113. $opt = 1;
  114. }
  115. else
  116. $opt = 0;
  117. if (!isset($_GET[$x]))
  118. {
  119. if (!$opt)
  120. err("Fehlender Parameter fuer Announce: $x");
  121. continue;
  122. }
  123. $GLOBALS[$x] = unesc($_GET[$x]);
  124. }
  125.  
  126. foreach (array("info_hash","peer_id") as $x)
  127. {
  128. if (strlen($GLOBALS[$x]) != 20)
  129. err("Ungueltiger Wert fuer $x (" . strlen($GLOBALS[$x]) . " - " . urlencode($GLOBALS[$x]) . ")");
  130. }
  131.  
  132. foreach ($GLOBALS["BAN_PEERIDS"] as $banned_id)
  133. {
  134. if (substr($GLOBALS["peer_id"],0,strlen($banned_id)) == $banned_id)
  135. err("Du benutzt einen gebannten Client. Bitte lies das FAQ!");
  136. }
  137.  
  138. $ip = getip();
  139. $origip = $ip;
  140. $port = 0 + $port;
  141. $origport = $port;
  142. $downloaded = 0 + $downloaded;
  143. $uploaded = 0 + $uploaded;
  144. $left = 0 + $left;
  145.  
  146. $supportcrypto = 0 + $_GET['supportcrypto'];
  147. $requirecrypto = 0 + $_GET['requirecrypto'];
  148. $cryptoport = 0 + $_GET['cryptoport'];
  149. $crypto = 0;
  150. // Welchen Cryptostatus speichern wir in der Datenbank?
  151. if ($supportcrypto == 1)
  152. $crypto = 1;
  153. if ($requirecrypto == 1)
  154. $crypto = 2;
  155.  
  156. $rsize = 50;
  157. foreach(array("num want", "numwant", "num_want") as $k)
  158. {
  159. if (isset($_GET[$k]))
  160. {
  161. $rsize = 0 + $_GET[$k];
  162. break;
  163. }
  164. }
  165.  
  166. // $agent = $_SERVER["HTTP_USER_AGENT"];
  167. //Fix
  168. $agent = htmlentities($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES);
  169.  
  170. // Deny access made with a browser...
  171. if (ereg("^Mozilla\/", $agent) || ereg("^Opera\/", $agent) || ereg("^Links ", $agent) || ereg("^Lynx\/", $agent))
  172. err("Dieser Torrent ist dem Tracker nicht bekannt");
  173.  
  174. if (!$port || $port > 0xffff)
  175. err("Ungueltiges TCP-Port");
  176.  
  177. if (!isset($event))
  178. $event = "";
  179.  
  180. $seeder = ($left == 0) ? "yes" : "no";
  181.  
  182. dbconn(false);
  183.  
  184. hit_count();
  185.  
  186. $res = mysql_query("SELECT id, name, category, banned, freeleech, free, activated, seeders + leechers AS numpeers, UNIX_TIMESTAMP(added) AS ts FROM torrents WHERE " . hash_where("info_hash", $info_hash));
  187.  
  188. $torrent = mysql_fetch_assoc($res);
  189. if (!$torrent)
  190. err("Dieser Torrent ist dem Tracker nicht bekannt");
  191.  
  192. if ($torrent["activated"] != "yes")
  193. err("Dieser Torrent ist dem Tracker nicht bekannt");
  194.  
  195. $torrentid = $torrent["id"];
  196.  
  197. $fields = "crypto, cryptoport, seeder, peer_id, ip, port, uploaded, downloaded, userid";
  198.  
  199. $numpeers = $torrent["numpeers"];
  200. $limit = "";
  201. if ($numpeers > $rsize)
  202. {
  203. // Versteht der Peer, der mich aufruft Verschluesselung?
  204. if ($supportcrypto == 1 || $requirecrypto == 1)
  205. {
  206. // Ja: Gib bevorzugt Peers zurueck, die auch verschluessen koennen
  207. $limit = "ORDER BY crypto DESC, uploaded DESC LIMIT $rsize";
  208. }
  209. else
  210. {
  211. // Radikale Moeglichkeit:
  212. //err("Klient unterstuetzt keine Verschluesselung.");
  213. // Nein: Gib zufaellige Peers zurueck (alte Standardeinstellung)
  214. $limit = "ORDER BY RAND() LIMIT $rsize";
  215. }
  216. }
  217. $res = mysql_query("SELECT $fields FROM peers WHERE torrent = $torrentid AND connectable = 'yes' $limit");
  218.  
  219. $resp = "d" . benc_str("interval") . "i" . $GLOBALS["ANNOUNCE_INTERVAL"] . "e" . benc_str("peers") . "l";
  220. unset($self);
  221. // Neue bencoding liste fuer crypto-array
  222. $crypto_array = "l";
  223. while ($row = mysql_fetch_assoc($res))
  224. {
  225. $row["peer_id"] = hash_pad($row["peer_id"]);
  226. if ($row["peer_id"] === $peer_id)
  227. {
  228. $userid = intval($row["userid"]);
  229. $self = $row;
  230. continue;
  231. }
  232. $resp .= "d" .
  233. benc_str("ip") . benc_str($row["ip"]) .
  234. benc_str("peer id") . benc_str($row["peer_id"]) .
  235. benc_str("port") . "i" . $row["port"] . "e";
  236.  
  237. // Jedem Peer den cryptoport mitgeben, falls unterstuetzt
  238. if(($row['crypto'] > 1) && ($row['cryptoport'] > 0))
  239. $resp.=benc_str("cryptoport"). "i" .$row['cryptoport'] . "e";
  240.  
  241. // Und das boolesche Cryptoarray vorbereiten
  242. if($row['crypto'] > 0)
  243. $crypto_array.="i1e";
  244. else
  245. $crypto_array .="i0e";
  246.  
  247. $resp .= "e";
  248. }
  249. $crypto_array .="e";
  250.  
  251. // bencoding per Hand. Magic!
  252. if (($supportcrypto == 1) || ($requirecrypto == 1))
  253. $resp .= "ee" . benc_str("crypto_flags"). "i" .$crypto_array;
  254. else
  255. $resp .= "ee";
  256.  
  257. $selfwhere = "torrent = $torrentid AND " . hash_where("peer_id", $peer_id);
  258.  
  259. if (!isset($self))
  260. {
  261. $res = mysql_query("SELECT $fields FROM peers WHERE $selfwhere");
  262. $row = mysql_fetch_assoc($res);
  263. if ($row)
  264. {
  265. $userid = $row["userid"];
  266.  
  267. $self = $row;
  268. }
  269. }
  270.  
  271.  
  272. //// Up/down stats ////////////////////////////////////////////////////////////
  273.  
  274. if (!isset($self))
  275. {
  276. if ($GLOBALS["CLIENT_AUTH"] == CLIENT_AUTH_PASSKEY) {
  277. $rz = mysql_query("SELECT id, uploaded, downloaded, class, tlimitseeds, tlimitleeches, tlimitall FROM users WHERE passkey=".sqlesc(hex2bin($passkey))." AND enabled = 'yes' ORDER BY last_access DESC LIMIT 1") or err("Tracker error 2");
  278. if ($MEMBERSONLY && mysql_num_rows($rz) == 0)
  279. err("Ungueltiger PassKey. Lies das FAQ!");
  280. } else {
  281. $rz = mysql_query("SELECT id, uploaded, downloaded, class, tlimitseeds, tlimitleeches, tlimitall FROM users WHERE ip=".sqlesc($ip)." AND enabled = 'yes' ORDER BY last_access DESC LIMIT 1") or err("Tracker error 2");
  282. if ($MEMBERSONLY && mysql_num_rows($rz) == 0)
  283. err("Unbekannte IP. Lies das FAQ!");
  284. }
  285.  
  286. $az = mysql_fetch_assoc($rz);
  287. $userid = $az["id"];
  288.  
  289. // Wartezeit prüfen
  290. $wait = get_wait_time($az["id"], $torrentid, FALSE, $left);
  291. if (($left > 0 || !$GLOBALS["ONLY_LEECHERS_WAIT"]) && $wait)
  292. err("Wartezeit (noch " . ($wait) . "h) - Bitte lies das FAQ!");
  293.  
  294. // Torrent-Limit prüfen
  295. // $az["tlimitall"] < 0 entspricht unlimitiert!
  296. if ($az["tlimitall"] >= 0) {
  297. $arr = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) AS cnt FROM peers WHERE userid=$userid"));
  298. $numtorrents = $arr["cnt"];
  299. $arr = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) AS cnt FROM peers WHERE userid=$userid AND seeder='yes'"));
  300. $seeds = $arr["cnt"];
  301. $leeches = $numtorrents - $seeds;
  302. $limit = get_torrent_limits($az);
  303.  
  304. if ( ($limit["total"] > 0)
  305. &&(($numtorrents >= $limit["total"])
  306. || ($left == 0 && $seeds >= $limit["seeds"])
  307. || ($left > 0 && $leeches >= $limit["leeches"])))
  308. err("Maximales Torrent-Limit erreicht ($limit[seeds] Seeds, $limit[leeches] Leeches, $limit[total] Gesamt)");
  309.  
  310. }
  311.  
  312. check_ip_limit();
  313.  
  314. // Create traffic log entry if not existent
  315. $res = mysql_query("SELECT * FROM `traffic` WHERE `userid`=$userid AND `torrentid`=$torrentid");
  316. if (@mysql_num_rows($res) == 0)
  317. mysql_query("INSERT INTO `traffic` (`userid`,`torrentid`) VALUES ($userid, $torrentid)");
  318. }
  319. else
  320. {
  321. // We won't check the IP again, since this would disrupt a user's download if he
  322. // uses another IP to continue browsing on the tracker.
  323. if ($GLOBALS["CLIENT_AUTH"] == CLIENT_AUTH_PASSKEY) {
  324. $res = mysql_query("SELECT passkey,id FROM users WHERE id=$userid AND enabled = 'yes'");
  325. $pkrow = mysql_fetch_assoc($res);
  326. $passkey = hex2bin($passkey);
  327. if ($passkey != $pkrow["passkey"])
  328. err("Ungueltiger PassKey. Lies das FAQ!");
  329.  
  330. check_ip_limit();
  331. }
  332. // Multiplikatortorrents by Underworld
  333. $multires = mysql_query("SELECT multi FROM torrents WHERE id =$torrentid ");
  334. $multiarr = mysql_fetch_assoc($multires);
  335. if ($multiarr["multi"] > 0)
  336. {
  337. // Anti Spam Anti DDoS @ Client´s by bliZZ
  338. $start = $self["ts"]; // Letzte Client Update (z.B Azureus Flood/PufferOverflow)
  339. $end = time(); //Zeit (JETZT)
  340. if ($end - $start < 30) //~30 sek. Wartezeit (Update Ban)
  341. err("Sorry, minimaler announce interval = 30 sek.");//Info Sendung an den Clienten
  342. $upthis = max(0, $uploaded - $self["uploaded"]);
  343. $upthis = $upthis * $multiarr["multi"];
  344. }
  345. else
  346. {
  347. $upthis = max(0, $uploaded - $self["uploaded"]);
  348. }
  349. $downthis = max(0, $downloaded - $self["downloaded"]);
  350. //Eof Multiplikatortorrents
  351. $downthis = max(0, $downloaded - $self["downloaded"]);
  352.  
  353. $arr = mysql_fetch_assoc(mysql_query("SELECT UNIX_TIMESTAMP(last_action) AS lastaction FROM peers WHERE $selfwhere"));
  354. $interval = time() - $arr["lastaction"];
  355.  
  356. if ($interval == 0) $interval = 1;
  357.  
  358. // If speed is higher than 4 MB/sec, the user is apparently cheating.
  359. // Frustrate him by adding his desired upload to his download ^^
  360. // ratiofaker bei multitorrent deaktivieren da es sowieso keinen sinn macht...
  361. if ($multiarr["multi"] == 0)
  362. {
  363. if (($upthis / $interval) > $GLOBALS["RATIOFAKER_THRESH"]) {
  364. // Write mod comment
  365. write_modcomment($userid, 0, "announce.php: Ratiofaker-Tool verwendet: ".mksize($upthis)." Upload, Fake Rate: ".mksize($upthis / $interval)."/sek");
  366. // Add upload as download and zero out upload.
  367. $downthis += $upthis;
  368. $upthis = 0;
  369. }
  370. }
  371. //Eof ratiofaker
  372.  
  373. $dynOnlyUp = false;
  374. $dynOnlyUpRes = mysql_query("SELECT COUNT(`id`) AS `count` FROM `dynonlyup` WHERE `userid` = ".$userid." AND `torrent` = ".$torrentid." LIMIT 1");
  375. $dynOnlyUpRow = mysql_fetch_array($dynOnlyUpRes);
  376. if($dynOnlyUpRow['count'] == 1)
  377. {
  378. $dynOnlyUp = true;
  379. }
  380. else
  381. {
  382. $dynOnlyUp = false;
  383. }
  384. $dynFree = false;
  385. $dynFreeRes = mysql_query("SELECT COUNT(`id`) AS count FROM `dynfree` WHERE `userid` = ".$userid." AND `torrent` = ".$torrentid." LIMIT 1");
  386. $dynFreeRow = mysql_fetch_array($dynFreeRes);
  387. if($dynFreeRow['count'] == 1)
  388. {
  389. $dynFree = true;
  390. }
  391. else
  392. {
  393. $dynFree = false;
  394. }
  395. if ($torrent['freeleech'] == 'no' && $dynFree === false)
  396. {
  397. if ($upthis > 0 || $downthis > 0)
  398. {
  399. $res_ufree = mysql_query("SELECT userfree FROM users WHERE id = $userid"); //Get userfreestate for user
  400. $arr_ufree = mysql_fetch_array($res_ufree);
  401.  
  402. $userfree = $arr_ufree["userfree"]; //Set $userfree to users state
  403.  
  404. if($userfree == 'yes'){
  405. mysql_query("UPDATE users SET uploaded = uploaded + $upthis WHERE id=$userid") or err("Tracker error 3");
  406. mysql_query("UPDATE `traffic` SET `downloaded`=`downloaded`+$downthis, `uploaded`=`uploaded`+$upthis, `downloadtime`=`downloadtime`+$interval,`uploadtime`=`uploadtime`+$interval WHERE `userid`=$userid AND `torrentid`=$torrentid");
  407. }
  408. else {
  409. mysql_query("UPDATE `traffic` SET `downloaded`=`downloaded`+$downthis, `uploaded`=`uploaded`+$upthis, `downloadtime`=`downloadtime`+$interval,`uploadtime`=`uploadtime`+$interval WHERE `userid`=$userid AND `torrentid`=$torrentid");
  410. mysql_query("UPDATE users SET uploaded = uploaded + $upthis". ($torrent['free']=='no'?", downloaded = downloaded + $downthis ":' '). "WHERE id=$userid") or err("Tracker error 3");
  411. }
  412. }
  413. }
  414. }
  415. // Delete old dynonlyup entries
  416. mysql_query("DELETE FROM `dynonlyup` WHERE `userid` NOT IN (SELECT `id` FROM `users`) OR `torrent` NOT IN (SELECT `id` FROM `torrents`)") OR sqlerr(__FILE__,__LINE__);
  417.  
  418. // Bad user? If yes, we'll provide him with an invalid peer list :)
  419. $acctdata = mysql_fetch_assoc(mysql_query("SELECT baduser FROM accounts WHERE userid=$userid"));
  420. if ($acctdata["baduser"]==1) {
  421. $resarr = bdec($resp);
  422. for ($I=0; $I<count($resarr["value"]["peers"]["value"]); $I++) {
  423. $tmpip = $resarr["value"]["peers"]["value"][$I]["value"]["ip"]["value"];
  424. $resarr["value"]["peers"]["value"][$I]["value"]["port"]["value"] += mt_rand(100,250);
  425.  
  426. $rndnum = mt_rand(1,254);
  427. $resarr["value"]["peers"]["value"][$I]["value"]["ip"]["value"] =
  428. preg_replace("/\.(\d{1,3})$/", ".$rndnum", $tmpip);
  429.  
  430. }
  431. $resp = benc($resarr);
  432.  
  433. $rndnum = mt_rand(1,254);
  434. $ip = preg_replace("/\.(\d{1,3})$/", ".$rndnum", $ip);
  435. $port += mt_rand(100,250);
  436.  
  437. }
  438.  
  439.  
  440. ///////////////////////////////////////////////////////////////////////////////
  441.  
  442. function portblacklisted($port)
  443. {
  444. // direct connect
  445. if ($port >= 411 && $port <= 413) return true;
  446.  
  447. // bittorrent
  448. if ($port >= 6881 && $port <= 6889) return true;
  449.  
  450. // kazaa
  451. if ($port == 1214) return true;
  452.  
  453. // gnutella
  454. if ($port >= 6346 && $port <= 6347) return true;
  455.  
  456. // emule
  457. if ($port == 4662) return true;
  458.  
  459. // winmx
  460. if ($port == 6699) return true;
  461.  
  462. return false;
  463. }
  464.  
  465. $updateset = array();
  466.  
  467. if ($event == "stopped")
  468. {
  469. if (isset($self))
  470. {
  471. mysql_query("DELETE FROM peers WHERE $selfwhere");
  472. if (mysql_affected_rows())
  473. {
  474. if ($self["seeder"] == "yes")
  475. $updateset[] = "seeders = seeders - 1";
  476. else
  477. $updateset[] = "leechers = leechers - 1";
  478. }
  479. $up = ($self["uploaded"]);
  480. $down = ($self["downloaded"]);
  481. mysql_query("UPDATE snatched SET seeder = 'no', last_action = NOW(), ruploaded = ruploaded + $up, rdownloaded = rdownloaded + $down where userid = '$userid' and torrentid = '$torrentid'");
  482. }
  483. mysql_query("INSERT INTO startstoplog (userid,event,`datetime`,torrent,ip,peerid,useragent) VALUES ($userid,'stop',NOW(),$torrentid,".sqlesc($_SERVER["REMOTE_ADDR"]).",".sqlesc($peer_id).",".sqlesc($agent).")");
  484.  
  485. $announcedelay = @mysql_fetch_assoc(@mysql_query("SELECT * FROM `announcedelay` WHERE `peer_id`=".sqlesc($peer_id)));
  486. if (is_array($announcedelay)) {
  487. if ($announcedelay["first"] && $announcedelay["second"] && $announcedelay["quantity"]) {
  488. $duration1 = $announcedelay["second"]-$announcedelay["first"];
  489. $duration2 = time() - $announcedelay["second"];
  490. if ($duration1 < 310 && $duration2 < 10 && $uploaded - $announcedelay["quantity"] == 0) {
  491. write_modcomment($userid, 0, "announce.php: Evtl. Ratiomaker 0.5+ benutzt: ".mksize($uploaded)." Upload / ".mksize($downloaded)." Download, Fake Rate: ".mksize($uploaded / $duration1)."/sek, Delays: {$duration1}s / {$duration2}s");
  492. }
  493. }
  494. }
  495.  
  496. $resp = benc_resp(array("failure reason" => array(type => "string", value => "Kein Fehler - Torrent gestoppt.")));
  497. }
  498. else
  499. {
  500. if ($event == "completed") {
  501. $updateset[] = "times_completed = times_completed + 1";
  502. mysql_query("INSERT INTO completed (user_id, torrent_id, torrent_name, torrent_category, complete_time) VALUES ($userid, $torrentid, ".sqlesc($torrent["name"]).", ".$torrent["category"].", NOW())");
  503. mysql_query("INSERT INTO snatched (torrentid,userid,ruploaded,rdownloaded,seeder,completedat,finished) VALUES ($torrentid,$userid,$uploaded,$downloaded,'yes',NOW(),'yes')");
  504. }
  505.  
  506. if (isset($self))
  507. {
  508. $announcedelay = @mysql_fetch_assoc(@mysql_query("SELECT * FROM `announcedelay` WHERE `peer_id`=".sqlesc($peer_id)));
  509. if (is_array($announcedelay)) {
  510. if ($announcedelay["second"] == 0)
  511. mysql_query("UPDATE `announcedelay` SET `second`=UNIX_TIMESTAMP(),`quantity`=$uploaded WHERE `peer_id`=".sqlesc($peer_id));
  512. }
  513.  
  514. mysql_query("UPDATE peers SET uploaded = $uploaded, downloaded = $downloaded, to_go = $left, last_action = NOW(), seeder = '$seeder'"
  515. . ($seeder == "yes" && $self["seeder"] != $seeder ? ", finishedat = " . time() : "") . " WHERE $selfwhere");
  516. if (mysql_affected_rows() && $self["seeder"] != $seeder)
  517. {
  518. if ($seeder == "yes")
  519. {
  520. $updateset[] = "seeders = seeders + 1";
  521. $updateset[] = "leechers = leechers - 1";
  522. }
  523. else
  524. {
  525. $updateset[] = "seeders = seeders - 1";
  526. $updateset[] = "leechers = leechers + 1";
  527. }
  528. }
  529. }
  530. else
  531. {
  532. if (portblacklisted($origport))
  533. err("Der TCP-Port $origport ist nicht erlaubt.");
  534. else
  535. {
  536. $sockres = @fsockopen($origip, $origport, $errno, $errstr, 5);
  537. if (!$sockres)
  538. $connectable = "no";
  539. else
  540. {
  541. $connectable = "yes";
  542. @fclose($sockres);
  543. }
  544. }
  545.  
  546. // Alte abfrage
  547. // $ret = mysql_query("INSERT INTO peers (connectable, torrent, peer_id, ip, port, uploaded, downloaded, to_go, started, last_action, seeder, userid, agent, uploadoffset, downloadoffset) VALUES ('$connectable', $torrentid, " . sqlesc($peer_id) . ", " . sqlesc($ip) . ", $port, $uploaded, $downloaded, $left, NOW(), NOW(), '$seeder', $userid, " . sqlesc($agent) . ", $uploaded, $downloaded)");
  548.  
  549. // Neue Abfrage
  550. $ret = mysql_query("INSERT INTO peers (connectable, torrent, peer_id, ip, port, uploaded, downloaded, to_go, started, last_action, seeder, userid, agent, uploadoffset, downloadoffset, crypto, cryptoport) VALUES ('$connectable', $torrentid, " . sqlesc($peer_id) . ", " . sqlesc($ip) . ", $port, $uploaded, $downloaded, $left, NOW(), NOW(), '$seeder', $userid, " . sqlesc ($agent) . ", $uploaded, $downloaded, $crypto, $cryptoport)");
  551.  
  552. if ($ret)
  553. {
  554. if ($seeder == "yes")
  555. $updateset[] = "seeders = seeders + 1";
  556. else
  557. $updateset[] = "leechers = leechers + 1";
  558. }
  559. mysql_query("INSERT INTO startstoplog (userid,event,`datetime`,torrent,ip,peerid,useragent) VALUES ($userid,'start',NOW(),$torrentid,".sqlesc($_SERVER["REMOTE_ADDR"]).",".sqlesc($peer_id).",".sqlesc($agent).")");
  560. mysql_query("INSERT INTO announcedelay (peer_id, first) VALUES (".sqlesc($peer_id).", UNIX_TIMESTAMP())");
  561. mysql_query("DELETE FROM announcedelay WHERE `first`<UNIX_TIMESTAMP()-900");
  562. }
  563. }
  564.  
  565. if ($seeder == "yes")
  566. {
  567. if ($torrent["banned"] != "yes")
  568. $updateset[] = "visible = 'yes'";
  569. $updateset[] = "last_action = NOW()";
  570. }
  571.  
  572. if (count($updateset))
  573. mysql_query("UPDATE torrents SET " . join(",", $updateset) . " WHERE id = $torrentid");
  574.  
  575. benc_resp_raw($resp);
  576.  
  577. hit_end();
  578.  
  579. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement