Пример #1
0
function caching_output($enabled, $mode, $cache_var_name, $ttl = 300)
{
    if (!$enabled || !CACHE('bb_cache')->used) {
        return;
    }
    if ($mode == 'send') {
        if ($cached_contents = CACHE('bb_cache')->get($cache_var_name)) {
            bb_exit($cached_contents);
        }
    } else {
        if ($mode == 'store') {
            if ($output = ob_get_contents()) {
                CACHE('bb_cache')->set($cache_var_name, $output, $ttl);
            }
        }
    }
}
Пример #2
0
}
ob_start('commify_ob');
echo '<html><body><head></head>';
echo '
<br /><br />
<table border="1" cellspacing="0" cellpadding="6" align="center">
<col width="40%">
<col width="60%">
';
echo "\n<tr><td align=center> users: bb-all / bt-all / bt-active </td><td align=center> {$stat['u_bb_all']} / {$stat['u_bt_all']} / <b>{$stat['u_bt_active']}</b> </td></tr>\n";
echo "\n\n\t<tr><td align=center> torrents:  all / active / with seeder </td>\n\t<td align=center>\n\t\t{$stat['tor_all']} / <b>{$stat['tor_active']}</b> / {$stat['tor_with_seeder']}\n\t\t&nbsp;\n\t\t[ " . humn_size($stat['torrents_size']) . " ]\n\t</td></tr>\n\n";
echo "\n\n\t<tr><td align=center> peers: all ({$stat['max_peer_time']} s) / in ann interval ({$announce_interval} s) </td>\n\t<td align=center>\n\t\t{$stat['p_all']} / <b>{$stat['p_within_ann']}</b>\n\t\t&nbsp;\n\t\t[ up:   " . humn_size($stat['speed_up']) . "/s,\n\t\t  down: " . humn_size($stat['speed_down']) . "/s ]\n\t</td></tr>\n\n";
echo "\n<tr><td align=center> peers: in last " . join(' / ', $peers_in_last_minutes) . " min</td>\n";
echo "\n<td align=center>" . join(' / ', $peers_in_last_min) . "</td></tr>\n";
echo "\n<tr><td align=center> peers in last {$peers_in_last_sec_limit} sec <br /> [ per second, DESC order --> ] <br /> last peer: {$stat['last_peer_time']} seconds ago <br /> " . date("j M H:i:s [T O]") . " </td>\n";
echo '<td align=center style="font-size: 13px; font-family: \'Courier New\',Courier,monospace;"><pre> ' . join(' ', $peers_in_last_sec) . "</pre></td></tr>\n";
echo '</table>';
echo '<div align="center"><pre>';
if ($l = sys('la')) {
    $l = explode(' ', $l);
    for ($i = 0; $i < 3; $i++) {
        $l[$i] = round($l[$i], 1);
    }
    echo "\n\n<b>loadavg: </b>{$l['0']} {$l['1']} {$l['2']}\n\n";
}
echo 'gen time: <b>' . sprintf('%.3f', array_sum(explode(' ', microtime())) - TIMESTART) . "</b> sec\n";
echo '</pre></div>';
echo '</body></html>';
DB()->query("DROP TEMPORARY TABLE " . TMP_TRACKER_TABLE);
bb_exit();
Пример #3
0
function send_torrent_with_passkey($filename)
{
    global $attachment, $auth_pages, $userdata, $bb_cfg, $tr_cfg, $lang;
    if (!$bb_cfg['bt_add_auth_key'] || $attachment['extension'] !== TORRENT_EXT || !($size = @filesize($filename))) {
        return;
    }
    $post_id = $poster_id = $passkey_val = '';
    $user_id = $userdata['user_id'];
    $attach_id = $attachment['attach_id'];
    if (!($passkey_key = $bb_cfg['passkey_key'])) {
        bb_die('Could not add passkey (wrong config $bb_cfg[\'passkey_key\'])');
    }
    // Get $post_id & $poster_id
    foreach ($auth_pages as $rid => $row) {
        if ($row['attach_id'] == $attach_id) {
            $post_id = $row['post_id'];
            $poster_id = $row['user_id_1'];
            break;
        }
    }
    // Get $topic_id
    $topic_id_sql = 'SELECT topic_id FROM ' . BB_POSTS . ' WHERE post_id = ' . (int) $post_id;
    if (!($topic_id_result = DB()->sql_query($topic_id_sql))) {
        bb_die('Could not query post information');
    }
    $topic_id_row = DB()->sql_fetchrow($topic_id_result);
    $topic_id = $topic_id_row['topic_id'];
    if (!$attachment['tracker_status']) {
        bb_die($lang['PASSKEY_ERR_TOR_NOT_REG']);
    }
    if (bf($userdata['user_opt'], 'user_opt', 'dis_passkey') && !IS_GUEST) {
        bb_die('Could not add passkey');
    }
    if ($bt_userdata = get_bt_userdata($user_id)) {
        $passkey_val = $bt_userdata['auth_key'];
    }
    if (!$passkey_val) {
        if (!($passkey_val = generate_passkey($user_id))) {
            bb_simple_die('Could not generate passkey');
        } elseif ($bb_cfg['ocelot']['enabled']) {
            ocelot_update_tracker('add_user', array('id' => $user_id, 'passkey' => $passkey_val));
        }
    }
    // Ratio limits
    $min_ratio = $bb_cfg['bt_min_ratio_allow_dl_tor'];
    if ($min_ratio && $user_id != $poster_id && ($user_ratio = get_bt_ratio($bt_userdata)) !== null) {
        if ($user_ratio < $min_ratio && $post_id) {
            $dl = DB()->fetch_row("\n\t\t\t\tSELECT dl.user_status\n\t\t\t\tFROM " . BB_POSTS . " p\n\t\t\t\tLEFT JOIN " . BB_BT_DLSTATUS . " dl ON dl.topic_id = p.topic_id AND dl.user_id = {$user_id}\n\t\t\t\tWHERE p.post_id = {$post_id}\n\t\t\t\tLIMIT 1\n\t\t\t");
            if (!isset($dl['user_status']) || $dl['user_status'] != DL_STATUS_COMPLETE) {
                bb_die(sprintf($lang['BT_LOW_RATIO_FOR_DL'], round($user_ratio, 2), "search.php?dlu={$user_id}&amp;dlc=1"));
            }
        }
    }
    // Announce URL
    $ann_url = $bb_cfg['bt_announce_url'];
    if (!($tor = bdecode_file($filename))) {
        bb_die('This is not a bencoded file');
    }
    $announce = $bb_cfg['ocelot']['enabled'] ? strval($bb_cfg['ocelot']['url'] . $passkey_val . "/announce") : strval($ann_url . "?{$passkey_key}={$passkey_val}");
    // Replace original announce url with tracker default
    if ($bb_cfg['bt_replace_ann_url'] || !isset($tor['announce'])) {
        $tor['announce'] = $announce;
    }
    // Delete all additional urls
    if ($bb_cfg['bt_del_addit_ann_urls'] || $bb_cfg['bt_disable_dht']) {
        unset($tor['announce-list']);
    } elseif (isset($tor['announce-list'])) {
        $tor['announce-list'] = array_merge($tor['announce-list'], array(array($announce)));
    }
    // Add retracker
    if (isset($tr_cfg['retracker']) && $tr_cfg['retracker']) {
        if (bf($userdata['user_opt'], 'user_opt', 'user_retracker') || IS_GUEST) {
            if (!isset($tor['announce-list'])) {
                $tor['announce-list'] = array(array($announce), array($tr_cfg['retracker_host']));
            } else {
                $tor['announce-list'] = array_merge($tor['announce-list'], array(array($tr_cfg['retracker_host'])));
            }
        }
    }
    // Add publisher & topic url
    $publisher_name = $bb_cfg['server_name'];
    $publisher_url = make_url(TOPIC_URL . $topic_id);
    $tor['publisher'] = strval($publisher_name);
    unset($tor['publisher.utf-8']);
    $tor['publisher-url'] = strval($publisher_url);
    unset($tor['publisher-url.utf-8']);
    $tor['comment'] = strval($publisher_url);
    unset($tor['comment.utf-8']);
    // Send torrent
    $output = bencode($tor);
    $dl_fname = $bb_cfg['torrent_name_style'] ? '[' . $bb_cfg['server_name'] . '].t' . $topic_id . '.torrent' : clean_filename(basename($attachment['real_filename']));
    if (!empty($_COOKIE['explain'])) {
        $out = "attach path: {$filename}<br /><br />";
        $tor['info']['pieces'] = '[...] ' . strlen($tor['info']['pieces']) . ' bytes';
        $out .= print_r($tor, true);
        bb_die("<pre>{$out}</pre>");
    }
    header("Content-Type: application/x-bittorrent; name=\"{$dl_fname}\"");
    header("Content-Disposition: attachment; filename=\"{$dl_fname}\"");
    bb_exit($output);
}