function start($info_hash, $ip, $port, $peer_id, $left, $downloaded = 0, $uploaded = 0, $upid = '') { global $BASEURL, $db; MCached::connect(); if (isset($_GET["ip"]) && $GLOBALS["ip_override"]) { // compact check: valid IP address: if ($_GET["ip"] != long2ip(ip2long($_GET["ip"]))) { showError("Invalid IP address. Must be standard dotted decimal (hostnames not allowed)"); } $ip = $db->real_escape_string($_GET["ip"]); } else { $ip = vars::$ip; } $ip = $db->real_escape_string($ip); $agent = $db->real_escape_string($agent); $remotedns = gethostbyaddr($ip); if (isset($_GET["ip"])) { $nuIP = $db->real_escape_string($_GET["ip"]); } else { $nuIP = ''; } if ($remotedns == $nuIP) { $remotedns = "AA"; } else { $remotedns = strtoupper($remotedns); preg_match('/^(.+)\\.([A-Z]{2,3})$/', $remotedns, $tldm); if (!empty($tldm[2])) { $remotedns = $db->real_escape_string($tldm[2]); } else { $remotedns = "AA"; } } if ($left == 0) { $status = "seeder"; } else { $status = "leecher"; } if (@isFireWalled($info_hash, $peer_id, $ip, $port)) { $nat = "Y"; } else { $nat = "N"; } $compact = $db->real_escape_string(pack('Nn', ip2long($ip), $port)); $peerid = $db->real_escape_string('2:ip' . strlen($ip) . ':' . $ip . '7:peer id20:' . hex2bin($peer_id) . "4:porti{$port}e"); $no_peerid = $db->real_escape_string('2:ip' . strlen($ip) . ':' . $ip . "4:porti{$port}e"); $results = @$db->query("INSERT INTO peers SET infohash = '" . $info_hash . "', peer_id = '" . $peer_id . "', port = '" . $port . "', ip = '" . $ip . "', lastupdate = UNIX_TIMESTAMP(), bytes = '" . $left . "', status = '" . $status . "', natuser = '******', client = '" . $agent . "', dns = '" . $remotedns . "', downloaded = " . $downloaded . ", uploaded = " . $uploaded . ", pid = '" . $upid . "'"); // Special case: duplicated peer_id. if (!$results) { if ($db->connect_errno == 1062) { // Duplicate peer_id! Check IP address $peer = getPeerInfo($peer_id, $info_hash); if ($ip == $peer["ip"]) { // Same IP address. Tolerate this error. return "WHERE natuser = '******'"; } // Different IP address. Assume they were disconnected, and alter the IP address. quickQuery("UPDATE peers SET ip = '" . $ip . "', compact = '" . $compact . "', with_peerid = '" . $peerid . "', without_peerid = '" . $no_peerid . "' WHERE peer_id = '" . $peer_id . "' AND infohash = '" . $info_hash . "'"); return "WHERE natuser = '******'"; } error_log("BtiTracker: start: " . $db->error); show_error("Tracker/database error. The details are in the error log."); } $GLOBALS["trackerid"] = $db->insert_id; @$db->query("UPDATE peers SET sequence = '" . $GLOBALS['trackerid'] . "', compact = '" . $compact . "', with_peerid = '" . $peerid . "', without_peerid = '" . $no_peerid . "' WHERE peer_id = '" . $peer_id . "' AND infohash = '" . $info_hash . "'"); if ($left == 0) { summaryAdd("seeds", 1); MCached::del('peers::count::' . $info_hash); return "WHERE status = 'leecher' AND natuser = '******'"; } else { summaryAdd("leechers", 1); MCached::del('peers::count::' . $info_hash); return "WHERE natuser = '******'"; } }
function start($info_hash, $ip, $port, $peer_id, $left, $uploaded, $clientVer) { if ($left == 0) { $status = "seeder"; } else { $status = "leecher"; } if (@isFireWalled($info_hash, $peer_id, $ip, $port)) { $nat = "'Y'"; } else { $nat = "'N'"; } $results = @mysql_query("INSERT INTO x{$info_hash} SET peer_id=\"{$peer_id}\", port=\"{$port}\", ip=\"{$ip}\", lastupdate=UNIX_TIMESTAMP(), bytes=\"{$left}\", status=\"{$status}\", natuser={$nat}, uploaded={$uploaded}, clientversion=\"{$clientVer}\""); // Special case: duplicated peer_id. if (!$results) { $error = mysql_error(); if (stristr($error, "key")) { // Duplicate peer_id! Check IP address $peer = getPeerInfo($peer_id, $info_hash); if ($ip == $peer["ip"]) { // Same IP address. Tolerate this error. updatePeer($peer_id, $info_hash); return "WHERE natuser='******'"; } //showError("Duplicated peer_id or changed IP address. Please restart BitTorrent."); // Different IP address. Assume they were disconnected, and alter the IP address. quickQuery("UPDATE x{$info_hash} SET ip=\"{$ip}\", uploaded={$uploaded}, clientversion=\"{$clientVer}\" WHERE peer_id=\"{$peer_id}\""); return "WHERE natuser='******'"; } error_log("PHPBTTracker: start: " . $error); showError("Tracker/database error. The details are in the error log."); } $GLOBALS["trackerid"] = mysql_insert_id(); if ($GLOBALS["peercaching"]) { $compact = mysql_real_escape_string(pack('Nn', ip2long($ip), $port)); $peerid = mysql_real_escape_string('2:ip' . strlen($ip) . ':' . $ip . '7:peer id20:' . hex2bin($peer_id) . "4:porti{$port}e"); $no_peerid = mysql_real_escape_string('2:ip' . strlen($ip) . ':' . $ip . "4:porti{$port}e"); mysql_query("INSERT INTO y{$info_hash} SET sequence=\"{$GLOBALS["trackerid"]}\", compact=\"{$compact}\", with_peerid=\"{$peerid}\", without_peerid=\"{$no_peerid}\""); // Let's just assume success... :/ } if ($left == 0) { summaryAdd("seeds", 1); return "WHERE status=\"leecher\" AND natuser='******'"; } else { summaryAdd("leechers", 1); return "WHERE natuser='******'"; } }
function start($info_hash, $ip, $port, $peer_id, $left) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { foreach (explode(",", $_SERVER["HTTP_X_FORWARDED_FOR"]) as $address) { $addr = ip2long(trim($address)); if ($addr != -1) { if ($addr >= -1062731776 && $addr <= -1062666241) { // 192.168.x.x } else { if ($addr >= -1442971648 && $addr <= -1442906113) { // 169.254.x.x } else { if ($addr >= 167772160 && $addr <= 184549375) { // 10.x.x.x } else { if ($addr >= 2130706432 && $addr <= 2147483647) { // 127.0.0.1 } else { if ($addr >= -1408237568 && $addr <= -1407188993) { // 172.[16-31].x.x } else { // Finally, we can accept it as a "real" ip address. $ip = mysql_escape_string(trim($address)); break; } } } } } } } } if (isset($_GET["ip"]) && $GLOBALS["ip_override"]) { // compact check: valid IP address: if (ip2long($_GET["ip"]) == -1) { showError("Invalid IP address. Must be standard dotted decimal (hostnames not allowed)"); } $ip = mysql_escape_string($_GET["ip"]); } if ($left == 0) { $status = "seeder"; } else { $status = "leecher"; } if (@isFireWalled($info_hash, $peer_id, $ip, $port)) { $nat = "'Y'"; } else { $nat = "'N'"; } $results = @mysql_query("INSERT INTO x{$info_hash} SET peer_id=\"{$peer_id}\", port=\"{$port}\", ip=\"{$ip}\", lastupdate=UNIX_TIMESTAMP(), bytes=\"{$left}\", status=\"{$status}\", natuser={$nat}"); // Special case: duplicated peer_id. if (!$results) { $error = mysql_error(); if (stristr($error, "key")) { // Duplicate peer_id! Check IP address $peer = getPeerInfo($peer_id, $info_hash); if ($ip == $peer["ip"]) { // Same IP address. Tolerate this error. updatePeer($peer_id, $info_hash); return "WHERE natuser='******'"; } //showError("Duplicated peer_id or changed IP address. Please restart BitTorrent."); // Different IP address. Assume they were disconnected, and alter the IP address. quickQuery("UPDATE x{$info_hash} SET ip=\"{$ip}\" WHERE peer_id=\"{$peer_id}\""); return "WHERE natuser='******'"; } error_log("PHPBTTracker: start: " . $error); showError("Tracker/database error. The details are in the error log."); } $GLOBALS["trackerid"] = mysql_insert_id(); if ($GLOBALS["peercaching"]) { $compact = mysql_escape_string(pack('Nn', ip2long($ip), $port)); $peerid = mysql_escape_string('2:ip' . strlen($ip) . ':' . $ip . '7:peer id20:' . hex2bin($peer_id) . "4:porti{$port}e"); $no_peerid = mysql_escape_string('2:ip' . strlen($ip) . ':' . $ip . "4:porti{$port}e"); mysql_query("INSERT INTO y{$info_hash} SET sequence=\"{$GLOBALS["trackerid"]}\", compact=\"{$compact}\", with_peerid=\"{$peerid}\", without_peerid=\"{$no_peerid}\""); // Let's just assume success... :/ } if ($left == 0) { summaryAdd("seeds", 1); return "WHERE status=\"leecher\" AND natuser='******'"; } else { summaryAdd("leechers", 1); return "WHERE natuser='******'"; } }
function start($info_hash, $ip, $port, $peer_id, $left, $downloaded = 0, $uploaded = 0, $upid = "") { global $BASEURL, $TABLE_PREFIX; if (isset($_GET["ip"]) && $GLOBALS["ip_override"]) { // compact check: valid IP address: if ($_GET["ip"] != long2ip(ip2long($_GET["ip"]))) { show_error("Invalid IP address. Must be standard dotted decimal (hostnames not allowed)"); } $ip = mysql_real_escape_string($_GET["ip"]); } else { $ip = getip(); } $ip = mysql_real_escape_string($ip); $agent = mysql_real_escape_string($_SERVER["HTTP_USER_AGENT"]); $remotedns = gethostbyaddr($ip); if (isset($_GET["ip"])) { $nuIP = $_GET["ip"]; } else { $nuIP = ""; } if ($remotedns == $nuIP) { $remotedns = "AA"; } else { $remotedns = strtoupper($remotedns); preg_match('/^(.+)\\.([A-Z]{2,3})$/', $remotedns, $tldm); if (!empty($tldm[2])) { $remotedns = mysql_real_escape_string($tldm[2]); } else { $remotedns = "AA"; } } if ($left == 0) { $status = "seeder"; } else { $status = "leecher"; } if (@isFireWalled($info_hash, $peer_id, $ip, $port)) { $nat = "Y"; } else { $nat = "N"; } $compact = mysql_real_escape_string(str_pad(pack('Nn', ip2long($ip), $port), 6)); $peerid = mysql_real_escape_string('2:ip' . strlen($ip) . ':' . $ip . '7:peer id20:' . hex2bin($peer_id) . "4:porti{$port}e"); $no_peerid = mysql_real_escape_string('2:ip' . strlen($ip) . ':' . $ip . "4:porti{$port}e"); $results = @mysql_query("INSERT INTO {$TABLE_PREFIX}peers SET infohash=\"{$info_hash}\", peer_id=\"{$peer_id}\", port=\"{$port}\", ip=\"{$ip}\", lastupdate=UNIX_TIMESTAMP(), bytes=\"{$left}\", status=\"{$status}\", natuser=\"{$nat}\", client=\"{$agent}\", dns=\"{$remotedns}\", downloaded={$downloaded}, uploaded={$uploaded}, pid=\"{$upid}\""); // Special case: duplicated peer_id. if (!$results) { if (mysql_errno() == 1062) { // Duplicate peer_id! Check IP address $peer = getPeerInfo($peer_id, $info_hash); if ($ip == $peer["ip"]) { // Same IP address. Tolerate this error. return "WHERE natuser='******'"; } // Different IP address. Assume they were disconnected, and alter the IP address. quickQuery("UPDATE {$TABLE_PREFIX}peers SET ip=\"{$ip}\", compact=\"{$compact}\", with_peerid=\"{$peerid}\", without_peerid=\"{$no_peerid}\" WHERE peer_id=\"{$peer_id}\" AND infohash=\"{$info_hash}\""); return "WHERE natuser='******'"; } error_log("BtiTracker: start: " . mysql_error()); show_error("Tracker/database error. The details are in the error log."); } $GLOBALS["trackerid"] = mysql_insert_id(); @mysql_query("UPDATE {$TABLE_PREFIX}peers SET sequence=\"" . $GLOBALS["trackerid"] . "\", compact=\"{$compact}\", with_peerid=\"{$peerid}\", without_peerid=\"{$no_peerid}\" WHERE peer_id=\"{$peer_id}\" AND infohash=\"{$info_hash}\""); if ($left == 0) { summaryAdd("seeds", 1); return "WHERE status=\"leecher\" AND natuser='******'"; } else { summaryAdd("leechers", 1); return "WHERE natuser='******'"; } }
function start($info_hash, $ip, $port, $peer_id, $left, $downloaded = 0, $uploaded = 0, $upid = "") { global $BASEURL, $TABLE_PREFIX, $DBDT; if (isset($_GET["ip"]) && $GLOBALS["ip_override"]) { // compact check: valid IP address: if ($_GET["ip"] != long2ip(ip2long($_GET["ip"]))) { show_error("Invalid IP address. Must be standard dotted decimal (hostnames not allowed)"); } $ip = mysqli_real_escape_string($DBDT, $_GET["ip"]); } else { $ip = getip(); } $ip = mysqli_real_escape_string($DBDT, $ip); $agent = mysqli_real_escape_string($DBDT, $_SERVER["HTTP_USER_AGENT"]); $remotedns = gethostbyaddr($ip); if (isset($_GET["ip"])) { $nuIP = $_GET["ip"]; } else { $nuIP = ""; } if ($remotedns == $nuIP) { $remotedns = "AA"; } else { $remotedns = strtoupper($remotedns); preg_match('/^(.+)\\.([A-Z]{2,3})$/', $remotedns, $tldm); if (!empty($tldm[2])) { $remotedns = mysqli_real_escape_string($DBDT, $tldm[2]); } else { $remotedns = "AA"; } } if ($left == 0) { $status = "seeder"; } else { $status = "leecher"; } if (@isFireWalled($info_hash, $peer_id, $ip, $port)) { $nat = "Y"; } else { $nat = "N"; } $compact = mysqli_real_escape_string($DBDT, str_pad(pack('Nn', ip2long($ip), $port), 6)); $peerid = mysqli_real_escape_string($DBDT, '2:ip' . strlen($ip) . ':' . $ip . '7:peer id20:' . hex2bin($peer_id) . "4:porti{$port}e"); $no_peerid = mysqli_real_escape_string($DBDT, '2:ip' . strlen($ip) . ':' . $ip . "4:porti{$port}e"); $results = @mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO {$TABLE_PREFIX}peers SET infohash=\"{$info_hash}\", peer_id=\"{$peer_id}\", port=\"{$port}\", ip=\"{$ip}\", lastupdate=UNIX_TIMESTAMP(), bytes=\"{$left}\", status=\"{$status}\", natuser=\"{$nat}\", client=\"{$agent}\", dns=\"{$remotedns}\", downloaded={$downloaded}, uploaded={$uploaded}, pid=\"{$upid}\""); // max torrents per usergroup $getlevel = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id_level,id,username FROM {$TABLE_PREFIX}users WHERE pid='{$upid}' AND id > 1 LIMIT 1"); $level = mysqli_fetch_row($getlevel); $getmax = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT maxtorrents FROM {$TABLE_PREFIX}users_level WHERE id='{$level['0']}'"); $az = mysqli_fetch_row($getmax); $allowedtorrents = $az[0]; $res = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT COUNT(*) FROM {$TABLE_PREFIX}peers WHERE pid='{$upid}'") or show_error("Tracker error 051"); $row = mysqli_fetch_row($res); $activetorrents = $row[0]; if ($activetorrents > $allowedtorrents) { show_error("Sorry, " . $allowedtorrents . " active torrents are all that you get !"); } // vip torrent global $btit_settings; $resvp = do_sqlquery("SELECT vip_torrent FROM {$TABLE_PREFIX}files WHERE info_hash='{$info_hash}'"); $rowvp = mysqli_fetch_assoc($resvp); $getlevelvp = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id_level FROM {$TABLE_PREFIX}users WHERE pid='{$upid}'"); $levelvp = mysqli_fetch_assoc($getlevelvp); if ($btit_settings["vip_one"] == false) { if ($rowvp["vip_torrent"] == 1 and $levelvp["id_level"] < $btit_settings["vip_get"]) { show_error("VIP only torrent"); die; } } if ($btit_settings["vip_one"] == true) { if ($rowvp["vip_torrent"] == 1 and $levelvp["id_level"] != $btit_settings["vip_get_one"]) { show_error("VIP only torrent"); die; } } // vip torrent end // Special case: duplicated peer_id. if (!$results) { if ((is_object($GLOBALS["___mysqli_ston"]) ? mysqli_errno($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_errno()) ? $___mysqli_res : false)) == 1062) { // Duplicate peer_id! Check IP address $peer = getPeerInfo($peer_id, $info_hash); if ($ip == $peer["ip"]) { // Same IP address. Tolerate this error. return "WHERE natuser='******'"; } // Different IP address. Assume they were disconnected, and alter the IP address. quickQuery("UPDATE {$TABLE_PREFIX}peers SET ip=\"{$ip}\", compact=\"{$compact}\", with_peerid=\"{$peerid}\", without_peerid=\"{$no_peerid}\" WHERE peer_id=\"{$peer_id}\" AND infohash=\"{$info_hash}\""); return "WHERE natuser='******'"; } error_log("BtiTracker: start: " . (is_object($GLOBALS["___mysqli_ston"]) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))); show_error("Tracker/database error. The details are in the error log."); } $GLOBALS["trackerid"] = is_null($___mysqli_res = mysqli_insert_id($GLOBALS["___mysqli_ston"])) ? false : $___mysqli_res; if ($GLOBALS["NAT"]) { $res = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT `id` FROM `{$TABLE_PREFIX}users` WHERE " . ($PRIVATE_ANNOUNCE ? "`pid`='{$upid}'" : "`cip`='{$ip}'")); $row = mysqli_fetch_assoc($res); @mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `{$TABLE_PREFIX}users` SET `connectable`='" . ($nat == "Y" ? "no" : "yes") . "' WHERE `id`=" . $row["id"]); } @mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}peers SET sequence=\"" . $GLOBALS["trackerid"] . "\", compact=\"{$compact}\", with_peerid=\"{$peerid}\", without_peerid=\"{$no_peerid}\" WHERE peer_id=\"{$peer_id}\" AND infohash=\"{$info_hash}\""); if ($left == 0) { summaryAdd("seeds", 1); return "WHERE status=\"leecher\" AND natuser='******'"; } else { summaryAdd("leechers", 1); return "WHERE natuser='******'"; } }