示例#1
0
 public static function benc_error($error)
 {
     global $forum_db;
     $forum_db->close();
     header('Content-Type: text/plain');
     exit(Fancy_Tracker::benc_encode(array('failure reason' => $error)));
 }
示例#2
0
}
$response = array();
$response['flags'] = $response['files'] = array();
foreach ($info_hashes as $hash) {
    // GET TORRENT INFO
    $query = array('SELECT' => 't.name, t.completed', 'FROM' => 'torrents AS t', 'WHERE' => 'UPPER(t.info_hash) = UPPER(\'' . $forum_db->escape($hash) . '\')');
    $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
    $torrent_info = $forum_db->fetch_assoc($result);
    if (!$torrent_info) {
        continue;
    }
    $torrent_info['seeds'] = $torrent_info['leechers'] = 0;
    // GET TORRENT PEERS INFO
    $peersQuery = array('SELECT' => 'p.*', 'FROM' => 'peers AS p', 'WHERE' => 'p.info_hash = \'' . $forum_db->escape($hash) . '\'');
    $peersResult = $forum_db->query_build($peersQuery) or error(__FILE__, __LINE__);
    while ($cur_peer = $forum_db->fetch_assoc($peersResult)) {
        if ($cur_peer['remaining'] == 0) {
            $torrent_info['seeds']++;
        } else {
            $torrent_info['leechers']++;
        }
    }
    $response['files'][Fancy_Tracker::hex2bin($hash)] = array('complete' => $torrent_info['seeds'], 'downloaded' => $torrent_info['completed'], 'incomplete' => $torrent_info['leechers'], 'name' => $torrent_info['name']);
}
// ADD FLAGS
$response['flags']['min_request_interval'] = intval($forum_config['o_fancy_tracker_announce_interval'], 10) * 2;
// End the transaction
$forum_db->end_transaction();
$forum_db->close();
exit(Fancy_Tracker::benc_encode($response));
示例#3
0
        message($lang_tracker['File not exists']);
    }
    $query = array('SELECT' => 't.name', 'FROM' => 'torrents AS t', 'WHERE' => 'UPPER(t.info_hash) = UPPER(\'' . $forum_db->escape($info_hash) . '\')');
    $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
    $name = $forum_db->result($result);
    if (is_null($name) || $name === false) {
        message($lang_common['Bad request']);
    }
    if (strlen($forum_user['passkey']) != 32) {
        $forum_user['passkey'] = md5($forum_user['salt'] . $forum_user['id'] . time() . $forum_user['username'] . $forum_user['password']);
        $query = array('UPDATE' => 'users', 'SET' => 'passkey=\'' . $forum_db->escape($forum_user['passkey']) . '\'', 'WHERE' => 'id=' . $forum_user['id']);
        $forum_db->query_build($query) or error(__FILE__, __LINE__);
    }
    $torrent = Fancy_Tracker::benc_decode(file_get_contents(FORUM_ROOT . 'extensions/fancy_tracker/torrents/' . $info_hash . '.torrent'));
    $torrent['announce'] = forum_link($forum_url['announce'], $forum_user['passkey']);
    // RETRACKER.LOCAL
    if ($forum_config['o_fancy_tracker_use_retracker'] == '1') {
        $torrent['announce-list'] = array(array(forum_link($forum_url['announce'], $forum_user['passkey']), 'http://retracker.local/announce'));
    }
    // End the transaction
    $forum_db->end_transaction();
    $forum_db->close();
    // SEND
    header('Content-Type: application/x-bittorrent');
    header("Pragma: public");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header('Content-Disposition: attachment; filename="' . htmlspecialchars($name, ENT_QUOTES) . '.torrent"');
    exit(Fancy_Tracker::benc_encode($torrent));
}
// If we end up here, the script was called with some wacky parameters
message($lang_common['Bad request']);
示例#4
0
    case 'mysql_innodb':
    case 'mysqli_innodb':
    case 'pgsql':
        $random_fn = 'RAND()';
        break;
    case 'sqlite':
    case 'sqlite3':
        $random_fn = 'random()';
        break;
    default:
        $random_fn = 'RAND()';
}
$query = array('SELECT' => 'p.peer_id, p.ip, p.port, p.remaining', 'FROM' => 'peers AS p', 'WHERE' => 'UPPER(p.info_hash) = UPPER(\'' . $forum_db->escape($fields['info_hash']) . '\') AND UPPER(p.peer_id) != UPPER(\'' . $forum_db->escape($fields['peer_id']) . '\')', 'ORDER BY' => $random_fn, 'LIMIT' => $fields['num_want']);
$result = $forum_db->query_build($query) or Fancy_Tracker::benc_error('Unable to fetch list of peers.');
$peers = array();
$seeders = $leechers = 0;
while ($cur_peer = $forum_db->fetch_assoc($result)) {
    $peers[] = array('ip' => $cur_peer['ip'], 'peer id' => str_pad(Fancy_Tracker::hex2bin($cur_peer['peer_id']), 20), 'port' => intval($cur_peer['port'], 10));
    // GET num SEED and LEECHERS
    if ($cur_peer['remaining'] == 0) {
        $seeders++;
    } else {
        $leechers++;
    }
}
// End the transaction
$forum_db->end_transaction();
// LAST QUERY
$forum_db->close();
$response = Fancy_Tracker::benc_encode(array('complete' => $seeders, 'incomplete' => $leechers, 'interval' => intval($forum_config['o_fancy_tracker_announce_interval'], 10), 'peers' => $peers));
exit($response);