function update_config_table($table_name, $default_cfg, $cfg, $type)
{
    foreach ($default_cfg as $config_name => $config_value) {
        if (isset($_POST[$config_name]) && $_POST[$config_name] != $cfg[$config_name]) {
            if ($type == 'str') {
                $config_value = "'" . bt_sql_esc(unesc($_POST[$config_name])) . "'";
            } else {
                if ($type == 'bool') {
                    $config_value = $_POST[$config_name] ? 1 : 0;
                } else {
                    if ($type == 'num') {
                        $config_value = round(abs(intval($_POST[$config_name])));
                    } else {
                        return;
                    }
                }
            }
            $sql = "UPDATE {$table_name} SET\n\t\t\t\tconfig_value = {$config_value}\n\t\t\t\tWHERE config_name = '{$config_name}'";
            if (!DB()->sql_query($sql)) {
                message_die(GENERAL_ERROR, "Failed to update configuration for {$config_name}", '', __LINE__, __FILE__, $sql);
            }
        }
    }
    return;
}
Example #2
0
        if ($tmp = substr(unesc(trim($_REQUEST[$title_match_key])), 0, $title_match_max_len)) {
            $title_match_val = htmlspecialchars($tmp);
            $title_match_sql = bt_sql_esc($tmp);
        }
    }
}
if ($forum_val && $allowed_forums_sql) {
    if ($s_not_seen_val != $search_all) {
        $seed_exist_val = 0;
    }
    if ($seed_exist_val) {
        $active_val = 1;
    }
    // Current search settings array (will stored in DB)
    $curr_set = array($sid_key => $sid_val, $new_key => $new_val, $seed_exist_key => $seed_exist_val, $active_key => $active_val, $my_key => $my_val, $forum_key => $forum_val, $poster_id_key => $poster_id_val, $poster_name_key => $poster_name_val, $s_not_seen_key => $s_not_seen_val, $order_key => $order_val, $sort_key => $sort_val, $time_key => $time_val, $show_forum_key => $show_forum_val, $show_author_key => $show_author_val, $show_speed_key => $show_speed_val);
    $curr_set_sql = bt_sql_esc(serialize($curr_set));
    // Store search settings
    if (array_diff_assoc($curr_set, $prev_set) && !$guest) {
        $sql = 'UPDATE ' . USERS_TABLE . " SET\r\n\t\t\t\tbt_tor_browse_set = '{$curr_set_sql}'\r\n\t\t\tWHERE user_id = {$user_id}\r\n\t\t\tLIMIT 1";
        if (!($result = DB()->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not update torrent search settings', '', __LINE__, __FILE__, $sql);
        }
    }
    // Switches
    $only_new = $new_val && !$guest ? TRUE : FALSE;
    $seed_exist = $seed_exist_val ? TRUE : FALSE;
    $only_active = $active_val ? TRUE : FALSE;
    $only_my = $my_val && !$guest ? TRUE : FALSE;
    $prev_days = $time_val != $search_all ? TRUE : FALSE;
    $poster_id = $poster_id_val ? TRUE : FALSE;
    $title_match = $title_match_sql ? TRUE : FALSE;
Example #3
0
function insert_post($mode, $topic_id, $forum_id = '', $old_forum_id = '', $new_topic_id = '', $new_topic_title = '', $old_topic_id = '', $message = '', $poster_id = '')
{
    global $ft_cfg, $lang;
    global $userdata, $user_ip, $is_auth;
    if (!$topic_id) {
        return;
    }
    $post_username = $post_subject = $post_text = $poster_ip = $bbcode_uid = '';
    $enable_bbcode = $enable_smilies = 0;
    $enable_html = $enable_sig = 1;
    $post_time = $current_time = time();
    $username = $userdata['username'];
    $forum_name = array();
    if ($mode == 'after_move') {
        if (!$forum_id || !$old_forum_id) {
            return;
        }
        $sql = 'SELECT forum_id, forum_name
			FROM ' . FORUMS_TABLE . "\n\t\t\tWHERE forum_id IN({$forum_id}, {$old_forum_id})";
        if (!($result = DB()->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
        }
        while ($row = DB()->sql_fetchrow($result)) {
            $forum_name[$row['forum_id']] = $row['forum_name'];
        }
        $post_text = sprintf($lang['Bot_topic_moved_from_to'], "<a class=\"postLink\" href=\"viewforum.php?f={$old_forum_id}\">{$forum_name[$old_forum_id]}</a>", "<a class=\"postLink\" href=\"viewforum.php?f={$forum_id}\">{$forum_name[$forum_id]}</a></b>", $username);
        $poster_id = BOT_UID;
        $poster_ip = '7f000001';
    } else {
        if ($mode == 'after_split_to_old') {
            $post_text = sprintf($lang['Bot_mess_splits'], "<a class=\"postLink\" href=\"viewtopic.php?t={$new_topic_id}\">{$new_topic_title}</a>", $username);
            $poster_id = BOT_UID;
            $poster_ip = '7f000001';
        } else {
            if ($mode == 'after_split_to_new') {
                $sql = 'SELECT t.topic_title, p.post_time
			FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p\n\t\t\tWHERE t.topic_id = {$old_topic_id}\n\t\t\t\tAND p.post_id = t.topic_first_post_id";
                if (!($result = DB()->sql_query($sql))) {
                    message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
                }
                if ($row = DB()->sql_fetchrow($result)) {
                    $old_topic_title = bt_sql_esc($row['topic_title']);
                    $post_time = $row['post_time'] - 1;
                    $post_text = sprintf($lang['Bot_topic_splits'], "<a class=\"postLink\" href=\"viewtopic.php?t={$old_topic_id}\">{$old_topic_title}</a>", $username);
                    $poster_id = BOT_UID;
                    $poster_ip = '7f000001';
                } else {
                    return;
                }
            } else {
                return;
            }
        }
    }
    $post_columns = 'topic_id,  forum_id,  poster_id,   post_username,   post_time,   poster_ip,   enable_bbcode,  enable_html,  enable_smilies,  enable_sig';
    $post_values = "{$topic_id}, {$forum_id}, {$poster_id}, '{$post_username}', {$post_time}, '{$poster_ip}', {$enable_bbcode}, {$enable_html}, {$enable_smilies}, {$enable_sig}";
    $sql = 'INSERT INTO ' . POSTS_TABLE . " ({$post_columns}) VALUES ({$post_values})";
    if (!DB()->sql_query($sql, BEGIN_TRANSACTION)) {
        message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
    }
    $post_id = DB()->sql_nextid();
    $post_text_columns = 'post_id,   post_subject,    bbcode_uid,    post_text';
    $post_text_values = "{$post_id}, '{$post_subject}', '{$bbcode_uid}', '{$post_text}'";
    $sql = 'INSERT INTO ' . POSTS_TEXT_TABLE . " ({$post_text_columns}) VALUES ({$post_text_values})";
    if (!DB()->sql_query($sql)) {
        message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
    }
    $sql = 'UPDATE ' . FORUMS_TABLE . "\n\t\tSET forum_last_post_id = {$post_id},\n\t\t\t\tforum_posts = forum_posts + 1\n\t\tWHERE forum_id = {$forum_id}";
    if (!DB()->sql_query($sql)) {
        message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
    }
    $sql = 'UPDATE ' . TOPICS_TABLE . "\n\t\tSET topic_last_post_id = {$post_id},\n\t\t\t\ttopic_replies = topic_replies + 1\n\t\tWHERE topic_id = {$topic_id}";
    if (!DB()->sql_query($sql)) {
        message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
    }
    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\tSET user_posts = user_posts + 1\n\t\tWHERE user_id = {$poster_id}";
    if (!DB()->sql_query($sql, END_TRANSACTION)) {
        message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
    }
    $redirect_message = $lang['Stored'] . '<br /><br />' . sprintf($lang['Click_view_message'], '<a href="' . append_sid("viewtopic.php?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">', '</a>') . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.php?" . POST_FORUM_URL . "={$forum_id}") . '">', '</a>');
    $redirect_meta = '<meta http-equiv="refresh" content="1;url=' . append_sid("viewtopic.php?" . POST_POST_URL . "=" . $post_id) . '#' . $post_id . '">';
    return;
}
function tracker_register($attach_id, $mode = '')
{
    global $template, $attach_config, $ft_cfg, $lang, $return_message;
    global $reg_mode;
    $template->assign_vars(array('META' => ''));
    $attach_id = intval($attach_id);
    $reg_mode = $mode;
    if (!($torrent = get_torrent_info($attach_id))) {
        message_die(GENERAL_ERROR, 'Torrent not found');
    }
    $post_id = $torrent['post_id'];
    $topic_id = $torrent['topic_id'];
    $forum_id = $torrent['forum_id'];
    $poster_id = $torrent['poster_id'];
    if ($torrent['extension'] !== TORRENT_EXT) {
        torrent_error_exit($lang['Not_torrent']);
    }
    if ($torrent['privmsgs_id']) {
        torrent_error_exit('Not allowed in PM');
    }
    if (!$torrent['allow_reg_tracker']) {
        torrent_error_exit($lang['Reg_not_allowed_in_this_forum']);
    }
    if ($post_id != $torrent['topic_first_post_id']) {
        torrent_error_exit($lang['Allowed_only_1st_post_reg']);
    }
    if ($torrent['tracker_status']) {
        torrent_error_exit($lang['Already_reg']);
    }
    if ($this_topic_torrents = get_registered_torrents($topic_id, 'topic')) {
        torrent_error_exit($lang['Only_1_tor_per_topic']);
    }
    torrent_auth_check($forum_id, $torrent['poster_id']);
    $filename = FT_ROOT . $attach_config['upload_dir'] . '/' . $torrent['physical_filename'];
    if (!is_file($filename)) {
        torrent_error_exit('File name error');
    }
    if (!file_exists($filename)) {
        torrent_error_exit('File not exists');
    }
    if (!($tor = bdecode_file($filename))) {
        torrent_error_exit('This is not a bencoded file');
    }
    if ($ft_cfg['bt_check_announce_url']) {
        require_once FT_ROOT . 'includes/torrent_announce_urls.php';
        $ann = @$tor['announce'] ? $tor['announce'] : '';
        $announce_urls['main_url'] = $ft_cfg['bt_announce_url'];
        if (!$ann || !in_array($ann, $announce_urls)) {
            $mess = sprintf($lang['Invalid_ann_url'], htmlspecialchars($ann), $announce_urls['main_url']);
            torrent_error_exit($mess);
        }
    }
    $info = @$tor['info'] ? $tor['info'] : array();
    if (!@$info['name'] || !@$info['piece length'] || !@$info['pieces'] || strlen($info['pieces']) % 20 != 0) {
        torrent_error_exit('Invalid torrent file');
    }
    $totallen = floatval(0);
    if (@$info['length']) {
        $totallen += $info['length'];
    } else {
        if (@$info['files'] && is_array($info['files'])) {
            foreach ($info['files'] as $fn => $f) {
                $totallen += $f['length'];
            }
        } else {
            torrent_error_exit('Invalid torrent file');
        }
    }
    $size = sprintf('%.0f', $totallen);
    $piece_length = sprintf('%.0f', floatval($info['piece length']));
    $reg_time = time();
    $info_hash = pack("H*", sha1(bencode($info)));
    $info_hash_md5 = strtolower(md5($info_hash));
    $info_hash_sql = rtrim(bt_sql_esc($info_hash), ' ');
    $columns = ' info_hash,       post_id,  poster_id,  topic_id,  attach_id,   size,    piece_length,   reg_time';
    $values = "'{$info_hash_sql}', {$post_id}, {$poster_id}, {$topic_id}, {$attach_id}, '{$size}', '{$piece_length}', {$reg_time}";
    $sql = 'INSERT INTO ' . BT_TORRENTS_TABLE . " ({$columns}) VALUES ({$values})";
    if (!DB()->sql_query($sql)) {
        $sql_error = DB()->sql_error();
        if ($sql_error['code'] == 1062) {
            torrent_error_exit($lang['Bt_Reg_fail_same_hash']);
        }
        message_die(GENERAL_ERROR, 'Could not register torrent on tracker', '', __LINE__, __FILE__, $sql);
    }
    /*
    	// Insert empty up/down "statistic record" for guests
    	$torrent_id = DB()->sql_nextid();
    	$guest_uid  = GUEST_UID;
    
    	$columns = 'torrent_id,  user_id,    attach_id, t_up_total, t_down_total';
    	$values = "$torrent_id, $guest_uid, $attach_id, 0,          0";
    
    	$sql = 'INSERT INTO '. BT_TOR_DL_STAT_TABLE ." ($columns) VALUES ($values)";
    
    	if (!DB()->sql_query($sql))
    	{
    		message_die(GENERAL_ERROR, 'Could not insert empty statistic record for guests', '', __LINE__, __FILE__, $sql);
    	}
    */
    // update tracker status for this attachment
    $sql = 'UPDATE ' . ATTACHMENTS_DESC_TABLE . " SET\r\n\t\t\ttracker_status = 1\r\n\t\tWHERE attach_id = {$attach_id}\r\n\t\tLIMIT 1";
    if (!DB()->sql_query($sql)) {
        message_die(GENERAL_ERROR, 'Could not update torrent status', '', __LINE__, __FILE__, $sql);
    }
    // set DL-Type for topic
    if ($ft_cfg['bt_set_dltype_on_tor_reg']) {
        $sql = 'UPDATE ' . TOPICS_TABLE . ' SET
				topic_dl_type = ' . TOPIC_DL_TYPE_DL . "\r\n\t\t\tWHERE topic_id = {$topic_id}\r\n\t\t\tLIMIT 1";
        if (!($result = DB()->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
        }
    }
    if ($reg_mode == 'request' || $reg_mode == 'newtopic') {
        $mess = sprintf($lang['Bt_Registered'], append_sid("download.php?id={$attach_id}"));
        exit_redirect($mess, $post_id, $forum_id);
    }
    return;
}