@mysql_connect(__DB_SERVER, __DB_USERNAME, __DB_PASSWORD) or die(track('Database connection failed')); //Select the database @mysql_select_db(__DB_DATABASE) or die(track('Unable to select database')); //Inputs that are needed, do not continue without these valdata('peer_id', true); valdata('port'); valdata('info_hash', true); //Make sure we have something to use as a key if (!isset($_GET['key'])) { $_GET['key'] = ''; } $downloaded = isset($_GET['uploaded']) ? intval($_GET['uploaded']) : 0; $uploaded = isset($_GET['uploaded']) ? intval($_GET['uploaded']) : 0; $left = isset($_GET['left']) ? intval($_GET['left']) : 0; //Validate key as well valdata('key'); //Do we have a valid client port? if (!ctype_digit($_GET['port']) || $_GET['port'] < 1 || $_GET['port'] > 65535) { die(track('Invalid client port')); } //Hack to get comatibility with trackon if ($_GET['port'] == 999 && substr($_GET['peer_id'], 0, 10) == '-TO0001-XX') { die("d8:completei0e10:incompletei0e8:intervali600e12:min intervali60e5:peersld2:ip12:72.14.194.184:port3:999ed2:ip11:72.14.194.14:port3:999ed2:ip12:72.14.194.654:port3:999eee"); } mysql_query('INSERT INTO `peer` (`hash`, `user_agent`, `ip_address`, `key`, `port`) ' . "VALUES ('" . mysql_real_escape_string(bin2hex($_GET['peer_id'])) . "', '" . mysql_real_escape_string(substr($_SERVER['HTTP_USER_AGENT'], 0, 80)) . "', INET_ATON('" . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . "'), '" . mysql_real_escape_string(sha1($_GET['key'])) . "', " . intval($_GET['port']) . ") " . 'ON DUPLICATE KEY UPDATE `user_agent` = VALUES(`user_agent`), `ip_address` = VALUES(`ip_address`), `port` = VALUES(`port`), `id` = LAST_INSERT_ID(`peer`.`id`)') or die(track('Cannot update peer: ' . mysql_error())); $pk_peer = mysql_insert_id(); mysql_query("INSERT INTO `torrent` (`hash`) VALUES ('" . mysql_real_escape_string(bin2hex($_GET['info_hash'])) . "') " . "ON DUPLICATE KEY UPDATE `id` = LAST_INSERT_ID(`id`)") or die(track('Cannot update torrent' . mysql_error())); // ON DUPLICATE KEY UPDATE is just to make mysql_insert_id work $pk_torrent = mysql_insert_id(); //User agent is required if (!isset($_SERVER['HTTP_USER_AGENT'])) {
if (!is_string($_GET[$g])) { die(track('Invalid types on one or more arguments')); } if ($must_be_20_chars && strlen($_GET[$g]) != 20) { die(track('Invalid length on ' . $g . ' argument')); } if (strlen($_GET[$g]) > 128) { //128 chars should really be enough die(track('Argument ' . $g . ' is too large to handle')); } return $_GET[$g]; } //Inputs that are needed, do not continue without these $peer_id = valdata('peer_id', true); $info_hash = valdata('info_hash', true); $port = valdata('port'); //Do we have a valid client port? if (!ctype_digit($_GET['port']) || $_GET['port'] < 1 || $_GET['port'] > 65535) { die(track('Invalid client port')); } //Number of peers that the client would like to receive from the tracker. $numwant = 50; if (isset($_GET['numwant'])) { $numwant = 0 + $_GET['numwant']; } //Find out if we are seeding or not. Assume not if unknown. $is_seed = isset($_GET['left']) && $_GET['left'] == 0 ? true : false; //Get IP $ip = $_SERVER['REMOTE_ADDR']; if (ip2long($ip)) { $ip4 = $ip;