if (!IS_ADMIN) {
            $this->ajax_die($lang['NOT_ADMIN']);
        }
        $table = BB_BT_USERS;
        $value = (double) str_replace(',', '.', $this->request['value']);
        foreach (array('KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4) as $s => $m) {
            if (strpos($this->request['value'], $s) !== false) {
                $value *= pow(1024, $m);
                break;
            }
        }
        $value = sprintf('%.0f', $value);
        $this->response['new_value'] = humn_size($value, null, null, ' ');
        if (!($btu = get_bt_userdata($user_id))) {
            require INC_DIR . 'functions_torrent.php';
            generate_passkey($user_id, true);
            $btu = get_bt_userdata($user_id);
        }
        $btu[$field] = $value;
        $this->response['update_ids']['u_ratio'] = (string) get_bt_ratio($btu);
        break;
    case 'user_points':
        $value = htmlCHR($value);
        $value = (double) str_replace(',', '.', $this->request['value']);
        $value = sprintf('%.2f', $value);
        $this->response['new_value'] = $value;
        break;
    default:
        $this->ajax_die("invalid profile field: {$field}");
}
$value_sql = DB()->escape($value, true);
Exemple #2
0
<?php

if (!defined('IN_AJAX')) {
    die(basename(__FILE__));
}
global $userdata, $lang;
$req_uid = (int) $this->request['user_id'];
if ($req_uid == $userdata['user_id'] || IS_ADMIN) {
    if (empty($this->request['confirmed'])) {
        $this->prompt_for_confirm($lang['BT_GEN_PASSKEY_NEW']);
    }
    if (!($passkey = generate_passkey($req_uid, IS_ADMIN))) {
        $this->ajax_die('Could not insert passkey');
    }
    tracker_rm_user($req_uid);
    $this->response['passkey'] = $passkey;
} else {
    $this->ajax_die($lang['NOT_AUTHORISED']);
}
function send_torrent_with_passkey($filename)
{
    global $attachment, $auth_pages, $userdata, $ft_cfg, $lang;
    if (!$ft_cfg['bt_add_auth_key'] || $attachment['extension'] !== TORRENT_EXT || !($size = @filesize($filename))) {
        return;
    }
    $post_id = '';
    $user_id = $userdata['user_id'];
    $attach_id = $attachment['attach_id'];
    // Get tracker config
    $sql = 'SELECT *
		FROM ' . BT_CONFIG_TABLE . "\r\n\t\tWHERE config_name = 'auth_key_name'\r\n\t\t\tOR  config_name = 'allow_guest_dl'";
    if (!($rowset = @DB()->sql_fetchrowset(DB()->sql_query($sql)))) {
        message_die(GENERAL_ERROR, 'Could not query tracker config', '', __LINE__, __FILE__, $sql);
    }
    foreach ($rowset as $rid => $row) {
        $tr_cfg[$row['config_name']] = $row['config_value'];
    }
    if (!($auth_key_name = $tr_cfg['auth_key_name'])) {
        message_die(GENERAL_ERROR, 'Could not add passkey (wrong config auth_key_name)');
    }
    // Get post_id
    foreach ($auth_pages as $rid => $row) {
        if ($row['attach_id'] == $attach_id) {
            $post_id = $row['post_id'];
            break;
        }
    }
    // Redirect guests to login page
    if (!$userdata['session_logged_in'] && (!$tr_cfg['allow_guest_dl'] || $ft_cfg['bt_force_passkey'])) {
        if ($post_id) {
            redirect(append_sid("login.php?redirect=viewtopic.php&" . POST_POST_URL . "={$post_id}", TRUE));
        } else {
            redirect(append_sid("login.php?redirect=index.php", TRUE));
        }
    }
    // Get torrent tracker status
    $sql = 'SELECT d.tracker_status, u.user_allow_passkey
		FROM ' . ATTACHMENTS_DESC_TABLE . ' d, ' . USERS_TABLE . " u\r\n\t\tWHERE d.attach_id = {$attach_id}\r\n\t\t\tAND u.user_id = {$user_id}\r\n\t\tLIMIT 1";
    if (!($result = DB()->sql_query($sql))) {
        message_die(GENERAL_ERROR, 'Could not query information for this torrent', '', __LINE__, __FILE__, $sql);
    }
    $row = DB()->sql_fetchrow($result);
    if (!$row['tracker_status']) {
        message_die(GENERAL_ERROR, $lang['Passkey_err_tor_not_reg']);
    }
    if (!$row['user_allow_passkey']) {
        message_die(GENERAL_ERROR, 'Could not add passkey<br /><br />You are not authorized to use passkey');
    }
    $auth_key = get_user_passkey($user_id);
    if (!$auth_key && $userdata['session_logged_in']) {
        if ($ft_cfg['bt_gen_passkey_on_reg']) {
            $auth_key = generate_passkey($user_id, TRUE);
            if (!defined('AUTH_KEY_INSERT_OK')) {
                message_die(GENERAL_ERROR, 'Could not insert passkey', '', __LINE__, __FILE__, $sql);
            }
        } else {
            $mess = sprintf($lang['Passkey_err_empty'], append_sid("profile.php?mode=editprofile#bittorrent"));
            message_die(GENERAL_ERROR, $mess);
        }
    }
    $ann_url = $ft_cfg['bt_announce_url'];
    if (!($tor = bdecode_file($filename))) {
        message_die(GENERAL_ERROR, 'This is not a bencoded file');
    }
    $passkey = !$userdata['session_logged_in'] || isset($_GET['no_passkey']) ? '' : "?{$auth_key_name}={$auth_key}&";
    // replace original announce url with tracker default
    if ($ft_cfg['bt_replace_ann_url'] || !@$tor['announce']) {
        $tor['announce'] = strval($ann_url . $passkey);
    }
    // delete all additional urls
    if ($ft_cfg['bt_del_addit_ann_urls']) {
        unset($tor['announce-list']);
    }
    // add publisher & topic url
    $publisher = $ft_cfg['bt_add_publisher'];
    $publisher_url = $post_id ? make_url("viewtopic.php?" . POST_POST_URL . "={$post_id}") : '';
    if ($publisher) {
        $tor['publisher'] = strval($publisher);
        unset($tor['publisher.utf-8']);
        if ($publisher_url) {
            $tor['publisher-url'] = strval($publisher_url);
            unset($tor['publisher-url.utf-8']);
        }
    }
    // add comment
    $comment = '';
    $orig_com = @$tor['comment'] ? $tor['comment'] : '';
    if ($ft_cfg['bt_add_comment']) {
        $comment = $ft_cfg['bt_add_comment'];
    } else {
        $comment = $publisher_url ? $publisher_url : '';
    }
    if ($comment = trim($comment)) {
        $tor['comment'] = strval($comment);
        unset($tor['comment.utf-8']);
    }
    // DHT
    $ft_cfg['bt_disable_dht'] = 1;
    if ($ft_cfg['bt_disable_dht']) {
        $tor['private'] = intval(1);
        unset($tor['nodes']);
        $tor['azureus_properties'] = array('dht_backup_enable' => intval(0));
    }
    // Send torrent
    $output = bencode($tor);
    $output_size = strlen($output);
    header("Content-length: {$output_size}");
    header('Content-Type: application/x-bittorrent');
    header('Content-Disposition: attachment; filename="' . clean_filename($attachment['real_filename']) . '"');
    echo $output;
    exit;
}
Exemple #4
0
}
// Unregister torrent from tracker
if ($mode == 'unreg') {
    tracker_unregister($attach_id, 'request');
    exit;
}
// Delete torrent
if ($mode == 'del' && $confirm) {
    delete_torrent($attach_id, 'request');
    $redirect_url = append_sid("viewtopic.php?" . POST_TOPIC_URL . "={$topic_id}");
    redirect($redirect_url);
}
// Delete torrent and move topic
if ($mode == 'del_move' && $confirm) {
    delete_torrent($attach_id, 'request');
    $redirect_url = "modcp.php?" . POST_TOPIC_URL . "={$topic_id}&mode=move&sid=" . $userdata['session_id'];
    redirect($redirect_url);
}
// Generate passkey
if ($mode == 'gen_passkey') {
    if ($req_uid == $user_id || $userdata['user_level'] == ADMIN) {
        generate_passkey($req_uid, FALSE);
        if (!defined('AUTH_KEY_INSERT_OK')) {
            message_die(GENERAL_ERROR, 'Could not insert passkey', '', __LINE__, __FILE__, $sql);
        }
        message_die(GENERAL_MESSAGE, $lang['Bt_Gen_Passkey_OK']);
    } else {
        message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
    }
}
message_die(GENERAL_ERROR, 'Not confirmed or invalid mode');
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);
}