Example #1
0
<?php

require_once "include/bittorrent.php";
dbconn();
maxcoder();
logoutcookie();
Header("Location: {$DEFAULTBASEURL}/");
Example #2
0
function userlogin()
{
    global $SITE_ONLINE;
    unset($GLOBALS["CURUSER"]);
    $dt = get_date_time();
    $ip = getip();
    $ipf = $_SERVER['REMOTE_ADDR'];
    $nip = ip2long($ip);
    $nip2 = ip2long($ipf);
    require_once ROOT_PATH . "cache/bans_cache.php";
    if (count($bans) > 0) {
        foreach ($bans as $k) {
            if ($nip >= $k['first'] && $nip <= $k['last'] || $nip2 >= $k['first'] && $nip2 <= $k['last']) {
                header("HTTP/1.0 403 Forbidden");
                echo "<html><body><h1>403 Forbidden</h1>Unauthorized IP address.</body></html>\n";
                exit;
            }
        }
        unset($bans);
    }
    if (!$SITE_ONLINE || empty($_COOKIE["uid"]) || empty($_COOKIE["pass"]) || empty($_COOKIE["hashv"])) {
        return;
    }
    $id = 0 + $_COOKIE["uid"];
    if (!$id or strlen($_COOKIE["pass"]) != 32 or $_COOKIE["hashv"] != hashit($id, $_COOKIE["pass"])) {
        return;
    }
    // //////////////announcement mod by Retro/////////////////////////
    $res = sql_query("SELECT u.*, ann_main.subject AS curr_ann_subject, ann_main.body AS curr_ann_body " . "FROM users AS u " . "LEFT JOIN announcement_main AS ann_main " . "ON ann_main.main_id = u.curr_ann_id " . "WHERE u.id = {$id} AND u.enabled='yes' AND u.status = 'confirmed'") or sqlerr(__FILE__, __LINE__);
    $row = mysql_fetch_assoc($res);
    if (!$row) {
        return;
    }
    $sec = hash_pad($row["secret"]);
    if ($_COOKIE["pass"] !== md5($row["passhash"] . $_SERVER["REMOTE_ADDR"])) {
        return;
    }
    if ($row['logout'] == 'yes' && $row['last_access'] > $row['last_login'] && $row['last_access'] < time() - 900) {
        logoutcookie();
        return;
    }
    if ($row['last_access'] != '0000-00-00 00:00:00' and strtotime($row['last_access']) < strtotime($dt) - 300 || $row['ip'] !== $ip || $row['ipf'] !== '' && $row['ipf'] !== $ipf) {
        $add_set = isset($add_set) ? $add_set : '';
        sql_query("UPDATE users SET last_access=" . sqlesc($dt) . ", ip=" . sqlesc($ip) . $add_set . ", uptime=uptime+300 WHERE id=" . $row['id']);
        // or die(mysql_error());
    }
    if ($row['ip'] !== $ip || $row['ipf'] !== '' && $row['ipf'] !== $ipf) {
        sql_query('INSERT INTO iplog (ip, userid, access) VALUES (' . sqlesc($ip) . ', ' . $row['id'] . ', \'' . $row['last_access'] . '\') on DUPLICATE KEY update access=values(access)');
    }
    // If curr_ann_id > 0 but curr_ann_body IS NULL, then force a refresh
    if ($row['curr_ann_id'] > 0 and $row['curr_ann_body'] == null) {
        $row['curr_ann_id'] = 0;
        $row['curr_ann_last_check'] = '0000-00-00 00:00:00';
    }
    // If elapsed > 10 minutes, force a announcement refresh.
    if ($row['curr_ann_last_check'] != '0000-00-00 00:00:00' and strtotime($row['curr_ann_last_check']) < strtotime($dt) - 300) {
        $row['curr_ann_last_check'] = '0000-00-00 00:00:00';
    }
    if ($row['curr_ann_id'] == 0 and $row['curr_ann_last_check'] == '0000-00-00 00:00:00') {
        // Force an immediate check...
        $query = sprintf('SELECT m.*,p.process_id FROM announcement_main AS m ' . 'LEFT JOIN announcement_process AS p ON m.main_id = p.main_id ' . 'AND p.user_id = %s ' . 'WHERE p.process_id IS NULL ' . 'OR p.status = 0 ' . 'ORDER BY m.main_id ASC ' . 'LIMIT 1', sqlesc($row['id']));
        $result = mysql_query($query);
        if (mysql_num_rows($result)) {
            // Main Result set exists
            $ann_row = mysql_fetch_array($result);
            $query = $ann_row['sql_query'];
            // Ensure it only selects...
            if (!preg_match('/\\ASELECT.+?FROM.+?WHERE.+?\\z/', $query)) {
                die;
            }
            // The following line modifies the query to only return the current user
            // row if the existing query matches any attributes.
            $query .= ' AND u.id = ' . sqlesc($row['id']) . ' LIMIT 1';
            $result = mysql_query($query);
            if (mysql_num_rows($result)) {
                // Announcement valid for member
                $row['curr_ann_id'] = $ann_row['main_id'];
                // Create two row elements to hold announcement subject and body.
                $row['curr_ann_subject'] = $ann_row['subject'];
                $row['curr_ann_body'] = $ann_row['body'];
                // Create additional set for main UPDATE query.
                $add_set = ', curr_ann_id = ' . sqlesc($ann_row['main_id']);
                $status = 2;
            } else {
                // Announcement not valid for member...
                $add_set = ', curr_ann_last_check = ' . sqlesc($dt);
                $status = 1;
            }
            // Create or set status of process
            if ($ann_row['process_id'] === null) {
                // Insert Process result set status = 1 (Ignore)
                $query = sprintf('INSERT INTO announcement_process (main_id, ' . 'user_id, status) VALUES (%s, %s, %s)', sqlesc($ann_row['main_id']), sqlesc($row['id']), sqlesc($status));
            } else {
                // Update Process result set status = 2 (Read)
                $query = sprintf('UPDATE announcement_process SET status = %s ' . 'WHERE process_id = %s', sqlesc($status), sqlesc($ann_row['process_id']));
            }
            mysql_query($query);
        } else {
            // No Main Result Set. Set last update to now...
            $add_set = ', curr_ann_last_check = ' . sqlesc($dt);
            //$add_set = ', curr_ann_last_check = '.sqlesc($dt).', curr_ann_id = curr_ann_id';
        }
        unset($result);
        unset($ann_row);
    }
    session_cache_limiter('private');
    session_start();
    if (!isset($_SESSION['browsetime']) || $row['ip'] !== $ip) {
        $_SESSION['browsetime'] = strtotime($row['last_access']);
    }
    $row['ip'] = $ip;
    $GLOBALS["CURUSER"] = $row;
    if ($row['override_class'] < $row['class']) {
        $row['class'] = $row['override_class'];
    }
    // Override class and save in GLOBAL array below.
    $GLOBALS["CURUSER"] = $row;
}
Example #3
0
function userlogin()
{
    global $INSTALLER09, $mc1, $CURBLOCK;
    unset($GLOBALS["CURUSER"]);
    $dt = time();
    $ip = getip();
    $nip = ip2long($ip);
    if (isset($CURUSER)) {
        return;
    }
    require_once INCL_DIR . 'user_functions.php';
    require_once CACHE_DIR . 'bans_cache.php';
    if (count($bans) > 0) {
        foreach ($bans as $k) {
            if ($nip >= $k['first'] && $nip <= $k['last']) {
                header("HTTP/1.0 403 Forbidden");
                print "<html><body><h1>403 Forbidden</h1>Unauthorized IP address.</body></html>\n";
                exit;
            }
        }
        unset($bans);
    }
    if (!$INSTALLER09['site_online'] || !get_mycookie('uid') || !get_mycookie('pass') || !get_mycookie('hashv')) {
        return;
    }
    $id = 0 + get_mycookie('uid');
    if (!$id or strlen(get_mycookie('pass')) != 32 or get_mycookie('hashv') != hashit($id, get_mycookie('pass'))) {
        return;
    }
    // ==Retro's Announcement mod
    $prefix = '09skan';
    /** let's cache $CURUSER - pdq **/
    $row = $mc1->get_value('MyUser_' . $id);
    if ($row === false) {
        // $row not found
        $res = sql_query("SELECT " . $prefix . ".*, ann_main.subject AS curr_ann_subject, ann_main.body AS curr_ann_body, s.last_status, s.last_update, s.archive FROM users AS " . $prefix . " LEFT JOIN announcement_main AS ann_main " . "ON ann_main.main_id = " . $prefix . ".curr_ann_id LEFT JOIN ustatus as s ON s.userid = " . $prefix . ".id WHERE " . $prefix . ".id = {$id} AND " . $prefix . ".enabled='yes' AND " . $prefix . ".status = 'confirmed'") or sqlerr(__FILE__, __LINE__);
        if (mysql_num_rows($res) == 0) {
            logoutcookie();
            return;
        }
        $row = mysql_fetch_assoc($res);
        //== Do all ints and floats
        $row['id'] = (int) $row['id'];
        $row['added'] = (int) $row['added'];
        $row['last_login'] = (int) $row['last_login'];
        $row['last_access'] = (int) $row['last_access'];
        $row['curr_ann_last_check'] = (int) $row['curr_ann_last_check'];
        $row['curr_ann_id'] = (int) $row['curr_ann_id'];
        $row['stylesheet'] = (int) $row['stylesheet'];
        $row['class'] = (int) $row['class'];
        $row['override_class'] = (int) $row['override_class'];
        $row['av_w'] = (int) $row['av_w'];
        $row['av_h'] = (int) $row['av_h'];
        $row['uploaded'] = (double) $row['uploaded'];
        $row['downloaded'] = (double) $row['downloaded'];
        $row['country'] = (int) $row['country'];
        $row['warned'] = (int) $row['warned'];
        $row['torrentsperpage'] = (int) $row['torrentsperpage'];
        $row['topicsperpage'] = (int) $row['topicsperpage'];
        $row['postsperpage'] = (int) $row['postsperpage'];
        $row['reputation'] = (int) $row['reputation'];
        $row['time_offset'] = (double) $row['time_offset'];
        $row['dst_in_use'] = (int) $row['dst_in_use'];
        $row['auto_correct_dst'] = (int) $row['auto_correct_dst'];
        $row['chatpost'] = (int) $row['chatpost'];
        $row['smile_until'] = (int) $row['smile_until'];
        $row['seedbonus'] = (double) $row['seedbonus'];
        $row['vip_until'] = (int) $row['vip_until'];
        $row['freeslots'] = (int) $row['freeslots'];
        $row['free_switch'] = (int) $row['free_switch'];
        $row['invites'] = (int) $row['invites'];
        $row['invitedby'] = (int) $row['invitedby'];
        $row['anonymous'] = $row['anonymous'];
        $row['uploadpos'] = (int) $row['uploadpos'];
        $row['forumpost'] = (int) $row['forumpost'];
        $row['downloadpos'] = (int) $row['downloadpos'];
        $row['immunity'] = (int) $row['immunity'];
        $row['leechwarn'] = (int) $row['leechwarn'];
        $row['last_browse'] = (int) $row['last_browse'];
        $row['sig_w'] = (int) $row['sig_w'];
        $row['sig_h'] = (int) $row['sig_h'];
        $row['forum_access'] = (int) $row['forum_access'];
        $row['hit_and_run_total'] = (int) $row['hit_and_run_total'];
        $row['donoruntil'] = (int) $row['donoruntil'];
        $row['donated'] = (int) $row['donated'];
        $row['total_donated'] = (double) $row['total_donated'];
        $row['vipclass_before'] = (int) $row['vipclass_before'];
        $row['passhint'] = (int) $row['passhint'];
        $row['avatarpos'] = (int) $row['avatarpos'];
        $row['sendpmpos'] = (int) $row['sendpmpos'];
        $row['invitedate'] = (int) $row['invitedate'];
        $row['anonymous_until'] = (int) $row['anonymous_until'];
        $row['pirate'] = (int) $row['pirate'];
        $row['king'] = (int) $row['king'];
        $row['ssluse'] = (int) $row['ssluse'];
        $row['paranoia'] = (int) $row['paranoia'];
        $row['parked_until'] = (int) $row['parked_until'];
        $row['bjwins'] = (int) $row['bjwins'];
        $row['bjlosses'] = (int) $row['bjlosses'];
        $row['irctotal'] = (int) $row['irctotal'];
        $row['last_access_numb'] = (int) $row['last_access_numb'];
        $row['onlinetime'] = (int) $row['onlinetime'];
        $ratio = $row['downloaded'] > 0 ? $row['uploaded'] / $row['downloaded'] : 0;
        $row['ratio'] = number_format($ratio, 2);
        $row['rep'] = get_reputation($row);
        $mc1->cache_value('MyUser_' . $id, $row, $INSTALLER09['expires']['curuser']);
        // set $Cache
        unset($res);
    }
    if (get_mycookie('pass') !== md5($row["passhash"] . $_SERVER["REMOTE_ADDR"])) {
        return;
    }
    //==Allowed staff
    if ($row["class"] >= UC_STAFF) {
        $allowed_ID = $INSTALLER09['allowed_staff']['id'];
        if (!in_array((int) $row["id"], $allowed_ID, true)) {
            $msg = "Fake Account Detected: Username: "******"username"] . " - UserID: " . $row["id"] . " - UserIP : " . getip();
            /** Demote and disable **/
            sql_query("UPDATE users SET enabled = 'no', class = 0 WHERE id =" . sqlesc($row["id"]) . "") or sqlerr(__FILE__, __LINE__);
            write_log($msg);
            autoshout($msg);
            logoutcookie();
        }
    }
    // If curr_ann_id > 0 but curr_ann_body IS NULL, then force a refresh
    if ($row['curr_ann_id'] > 0 and $row['curr_ann_body'] == NULL) {
        $row['curr_ann_id'] = 0;
        $row['curr_ann_last_check'] = '0';
    }
    // If elapsed > 10 minutes, force a announcement refresh.
    if ($row['curr_ann_last_check'] != '0' and $row['curr_ann_last_check'] < time($dt) - 600) {
        $row['curr_ann_last_check'] = '0';
    }
    if ($row['curr_ann_id'] == 0 and $row['curr_ann_last_check'] == '0') {
        // Force an immediate check...
        $query = sprintf('SELECT m.*,p.process_id FROM announcement_main AS m ' . 'LEFT JOIN announcement_process AS p ON m.main_id = p.main_id ' . 'AND p.user_id = %s ' . 'WHERE p.process_id IS NULL ' . 'OR p.status = 0 ' . 'ORDER BY m.main_id ASC ' . 'LIMIT 1', sqlesc($row['id']));
        $result = sql_query($query);
        if (mysql_num_rows($result)) {
            // Main Result set exists
            $ann_row = mysql_fetch_assoc($result);
            $query = $ann_row['sql_query'];
            // Ensure it only selects...
            if (!preg_match('/\\ASELECT.+?FROM.+?WHERE.+?\\z/', $query)) {
                die;
            }
            // The following line modifies the query to only return the current user
            // row if the existing query matches any attributes.
            $query .= ' AND u.id = ' . sqlesc($row['id']) . ' LIMIT 1';
            $result = sql_query($query);
            if (mysql_num_rows($result)) {
                // Announcement valid for member
                $row['curr_ann_id'] = $ann_row['main_id'];
                // Create two row elements to hold announcement subject and body.
                $row['curr_ann_subject'] = $ann_row['subject'];
                $row['curr_ann_body'] = $ann_row['body'];
                // Create additional set for main UPDATE query.
                $add_set = ', curr_ann_id = ' . sqlesc($ann_row['main_id']);
                $status = 2;
            } else {
                // Announcement not valid for member...
                $add_set = ', curr_ann_last_check = ' . sqlesc($dt);
                $status = 1;
            }
            // Create or set status of process
            if ($ann_row['process_id'] === NULL) {
                // Insert Process result set status = 1 (Ignore)
                $query = sprintf('INSERT INTO announcement_process (main_id, ' . 'user_id, status) VALUES (%s, %s, %s)', sqlesc($ann_row['main_id']), sqlesc($row['id']), sqlesc($status));
            } else {
                // Update Process result set status = 2 (Read)
                $query = sprintf('UPDATE announcement_process SET status = %s ' . 'WHERE process_id = %s', sqlesc($status), sqlesc($ann_row['process_id']));
            }
            sql_query($query);
        } else {
            // No Main Result Set. Set last update to now...
            $add_set = ', curr_ann_last_check = ' . sqlesc($dt);
        }
        unset($result);
        unset($ann_row);
    }
    if ($row['ssluse'] > 1 && !isset($_SERVER['HTTPS']) && !defined('NO_FORCE_SSL')) {
        $INSTALLER09['baseurl'] = str_replace('http', 'https', $INSTALLER09['baseurl']);
        header('Location: ' . $INSTALLER09['baseurl'] . $_SERVER['REQUEST_URI']);
        exit;
    }
    //== bitwise curuser bloks by pdq
    $blocks_key = 'blocks::' . $row['id'];
    $CURBLOCK = $mc1->get_value($blocks_key);
    if ($CURBLOCK === false) {
        $c_sql = sql_query('SELECT * FROM user_blocks WHERE userid = ' . $row['id']) or sqlerr(__FILE__, __LINE__);
        if (mysql_num_rows($c_sql) == 0) {
            sql_query('INSERT INTO user_blocks(userid) VALUES(' . $row['id'] . ')');
            header('Location: index.php');
            die;
        }
        $CURBLOCK = mysql_fetch_assoc($c_sql);
        $CURBLOCK['index_page'] = (int) $CURBLOCK['index_page'];
        $CURBLOCK['global_stdhead'] = (int) $CURBLOCK['global_stdhead'];
        $mc1->cache_value($blocks_key, $CURBLOCK, 0);
    }
    //== online time pdq
    $userupdate0 = 'onlinetime = onlinetime + 0';
    $new_time = TIME_NOW - $row['last_access_numb'];
    if ($new_time < 300) {
        $userupdate0 = "onlinetime = onlinetime + " . $new_time;
    }
    $userupdate1 = "last_access_numb = " . TIME_NOW;
    //end online-time
    $add_set = isset($add_set) ? $add_set : '';
    if ($row['ip'] !== $ip) {
        sql_query("UPDATE users SET last_access=" . TIME_NOW . ", {$userupdate0}, {$userupdate1}, ip=" . sqlesc($ip) . $add_set . " WHERE id=" . $row['id']);
        // or die(mysql_error());
        $mc1->delete_value('MyUser_' . $row['id']);
    } elseif ($row['last_access'] != '0' and $row['last_access'] < time($dt) - 180) {
        sql_query("UPDATE users SET last_access=" . TIME_NOW . ", {$userupdate0}, {$userupdate1}, ip=" . sqlesc($ip) . $add_set . " WHERE id=" . $row['id']);
        // or die(mysql_error());
        $mc1->delete_value('MyUser_' . $row['id']);
    }
    //==
    if ($row['override_class'] < $row['class']) {
        $row['class'] = $row['override_class'];
    }
    // Override class and save in GLOBAL array below.
    $GLOBALS["CURUSER"] = $row;
    get_template();
}
Example #4
0
function userlogin()
{
    $ip = getip();
    // If there's no IP a script is being ran from CLI. Any checks here will fail, skip all.
    if ($ip == "") {
        return;
    }
    global $CURUSER;
    unset($GLOBALS["CURUSER"]);
    //Check IP bans
    if (is_ipv6($ip)) {
        $nip = ip2long6($ip);
    } else {
        $nip = ip2long($ip);
    }
    $res = SQL_Query_exec("SELECT * FROM bans");
    while ($row = mysql_fetch_assoc($res)) {
        $banned = false;
        if (is_ipv6($row["first"]) && is_ipv6($row["last"]) && is_ipv6($ip)) {
            $row["first"] = ip2long6($row["first"]);
            $row["last"] = ip2long6($row["last"]);
            $banned = bccomp($row["first"], $nip) != -1 && bccomp($row["last"], $nip) != -1;
        } else {
            $row["first"] = ip2long($row["first"]);
            $row["last"] = ip2long($row["last"]);
            $banned = $nip >= $row["first"] && $nip <= $row["last"];
        }
        if ($banned) {
            header("HTTP/1.0 403 Forbidden");
            echo "<html><head><title>Forbidden</title></head><body><h1>Forbidden</h1>Unauthorized IP address.<br />" . "Reason for banning: {$row['comment']}</body></html>";
            die;
        }
    }
    //Check The Cookie and get CURUSER details
    if (strlen($_COOKIE["pass"]) != 40 || !is_numeric($_COOKIE["uid"])) {
        logoutcookie();
        return;
    }
    //Get User Details And Permissions
    $res = SQL_Query_exec("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE id={$_COOKIE['uid']} AND users.enabled='yes' AND users.status = 'confirmed'");
    $row = mysql_fetch_assoc($res);
    if (!$row || sha1($row["id"] . $row["secret"] . $row["password"] . $ip . $row["secret"]) != $_COOKIE["pass"]) {
        logoutcookie();
        return;
    }
    $where = where($_SERVER["SCRIPT_FILENAME"], $row["id"], 0);
    SQL_Query_exec("UPDATE users SET last_access='" . get_date_time() . "', ip=" . sqlesc($ip) . ", page=" . sqlesc($where) . " WHERE id=" . $row["id"]);
    $GLOBALS["CURUSER"] = $row;
    unset($row);
}
Example #5
0
function userlogin()
{
    global $INSTALLER09, $mc1, $CURBLOCK, $mood, $whereis;
    unset($GLOBALS["CURUSER"]);
    $dt = TIME_NOW;
    $ip = getip();
    $nip = ip2long($ip);
    $ipf = $_SERVER['REMOTE_ADDR'];
    if (isset($CURUSER)) {
        return;
    }
    if (!$INSTALLER09['site_online'] || !get_mycookie('uid') || !get_mycookie('pass') || !get_mycookie('hashv')) {
        return;
    }
    $id = 0 + get_mycookie('uid');
    if (!$id or strlen(get_mycookie('pass')) != 32 or get_mycookie('hashv') != hashit($id, get_mycookie('pass'))) {
        return;
    }
    // let's cache $CURUSER - pdq
    if (($row = $mc1->get_value('MyUser_' . $id)) === false) {
        // $row not found
        $user_fields = 'id, username, passhash, secret, passkey, email, status, added, ' . 'last_login, last_access, curr_ann_last_check, curr_ann_id, editsecret, privacy, stylesheet, ' . 'info, acceptpms, ip, class, override_class, language, avatar, av_w, av_h, ' . 'title, country, notifs, enabled, donor, warned, torrentsperpage, topicsperpage, ' . 'postsperpage, deletepms, savepms, reputation, time_offset, dst_in_use, auto_correct_dst, ' . 'show_shout, show_staffshout, shoutboxbg, chatpost, smile_until, vip_added, vip_until, ' . 'freeslots, free_switch, invites, invitedby, invite_rights, anonymous, uploadpos, forumpost, ' . 'downloadpos, immunity, leechwarn, disable_reason, clear_new_tag_manually, last_browse, sig_w, ' . 'sig_h, signatures, signature, forum_access, highspeed, hnrwarn, hit_and_run_total, donoruntil, ' . 'donated, total_donated, vipclass_before, parked, passhint, hintanswer, avatarpos, support, ' . 'supportfor, sendpmpos, invitedate, invitees, invite_on, subscription_pm, gender, anonymous_until, ' . 'viewscloud, tenpercent, avatars, offavatar, pirate, king, hidecur, ssluse, signature_post, forum_post, ' . 'avatar_rights, offensive_avatar, view_offensive_avatar, paranoia, google_talk, msn, aim, yahoo, website, ' . 'icq, show_email, parked_until, gotgift, hash1, suspended, bjwins, bjlosses, warn_reason, onirc, irctotal, ' . 'birthday, got_blocks, last_access_numb, onlinetime, pm_on_delete, commentpm, split, browser, hits, ' . 'comments, categorie_icon, reputation, perms, mood, got_moods, pms_per_page, show_pm_avatar, watched_user, game_access, browse_icons';
        $res = sql_query("SELECT " . $user_fields . " " . "FROM users " . "WHERE id = " . sqlesc($id) . " " . "AND enabled='yes' " . "AND status = 'confirmed'") or sqlerr(__FILE__, __LINE__);
        if (mysqli_num_rows($res) == 0) {
            logoutcookie();
            return;
        }
        $row = mysqli_fetch_assoc($res);
        // Do all ints and floats
        $row['id'] = (int) $row['id'];
        $row['added'] = (int) $row['added'];
        $row['last_login'] = (int) $row['last_login'];
        $row['last_access'] = (int) $row['last_access'];
        $row['curr_ann_last_check'] = (int) $row['curr_ann_last_check'];
        $row['curr_ann_id'] = (int) $row['curr_ann_id'];
        $row['stylesheet'] = (int) $row['stylesheet'];
        $row['class'] = (int) $row['class'];
        $row['override_class'] = (int) $row['override_class'];
        $row['av_w'] = (int) $row['av_w'];
        $row['av_h'] = (int) $row['av_h'];
        $row['country'] = (int) $row['country'];
        $row['warned'] = (int) $row['warned'];
        $row['torrentsperpage'] = (int) $row['torrentsperpage'];
        $row['topicsperpage'] = (int) $row['topicsperpage'];
        $row['postsperpage'] = (int) $row['postsperpage'];
        $row['reputation'] = (int) $row['reputation'];
        $row['time_offset'] = (double) $row['time_offset'];
        $row['dst_in_use'] = (int) $row['dst_in_use'];
        $row['auto_correct_dst'] = (int) $row['auto_correct_dst'];
        $row['chatpost'] = (int) $row['chatpost'];
        $row['smile_until'] = (int) $row['smile_until'];
        $row['vip_until'] = (int) $row['vip_until'];
        $row['freeslots'] = (int) $row['freeslots'];
        $row['free_switch'] = (int) $row['free_switch'];
        $row['invites'] = (int) $row['invites'];
        $row['invitedby'] = (int) $row['invitedby'];
        $row['anonymous'] = $row['anonymous'];
        $row['uploadpos'] = (int) $row['uploadpos'];
        $row['forumpost'] = (int) $row['forumpost'];
        $row['downloadpos'] = (int) $row['downloadpos'];
        $row['immunity'] = (int) $row['immunity'];
        $row['leechwarn'] = (int) $row['leechwarn'];
        $row['last_browse'] = (int) $row['last_browse'];
        $row['sig_w'] = (int) $row['sig_w'];
        $row['sig_h'] = (int) $row['sig_h'];
        $row['forum_access'] = (int) $row['forum_access'];
        $row['hit_and_run_total'] = (int) $row['hit_and_run_total'];
        $row['donoruntil'] = (int) $row['donoruntil'];
        $row['donated'] = (int) $row['donated'];
        $row['total_donated'] = (double) $row['total_donated'];
        $row['vipclass_before'] = (int) $row['vipclass_before'];
        $row['passhint'] = (int) $row['passhint'];
        $row['avatarpos'] = (int) $row['avatarpos'];
        $row['language'] = (int) $row['language'];
        $row['sendpmpos'] = (int) $row['sendpmpos'];
        $row['invitedate'] = (int) $row['invitedate'];
        $row['anonymous_until'] = (int) $row['anonymous_until'];
        $row['pirate'] = (int) $row['pirate'];
        $row['king'] = (int) $row['king'];
        $row['ssluse'] = (int) $row['ssluse'];
        $row['paranoia'] = (int) $row['paranoia'];
        $row['parked_until'] = (int) $row['parked_until'];
        $row['bjwins'] = (int) $row['bjwins'];
        $row['bjlosses'] = (int) $row['bjlosses'];
        $row['irctotal'] = (int) $row['irctotal'];
        $row['last_access_numb'] = (int) $row['last_access_numb'];
        $row['onlinetime'] = (int) $row['onlinetime'];
        $row['categorie_icon'] = (int) $row['categorie_icon'];
        $row['perms'] = (int) $row['perms'];
        $row['mood'] = (int) $row['mood'];
        $row['watched_user'] = (int) $row['watched_user'];
        $row['pms_per_page'] = (int) $row['pms_per_page'];
        $row['game_access'] = (int) $row['game_access'];
        $row['rep'] = get_reputation($row);
        $mc1->cache_value('MyUser_' . $id, $row, $INSTALLER09['expires']['curuser']);
        unset($res);
    }
    //==
    if (get_mycookie('pass') !== md5($row["passhash"] . $_SERVER["REMOTE_ADDR"])) {
        logoutcookie();
        return;
    }
    // bans by djGrrr <3 pdq
    if (!isset($row['perms']) || !($row['perms'] & bt_options::PERMS_BYPASS_BAN)) {
        $banned = false;
        if (check_bans($ip, $reason)) {
            $banned = true;
        } else {
            if ($ip != $ipf) {
                if (check_bans($ipf, $reason)) {
                    $banned = true;
                }
            }
        }
        if ($banned) {
            header('Content-Type: text/html; charset=utf-8');
            echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
      <title>Forbidden</title>
      </head><body>
      <h1>403 Forbidden</h1>Unauthorized IP address!
      <p>Reason: <strong>' . htmlsafechars($reason) . '</strong></p>
      </body></html>';
            die;
        }
    }
    // Allowed staff
    if ($row["class"] >= UC_STAFF) {
        $allowed_ID = $INSTALLER09['allowed_staff']['id'];
        if (!in_array((int) $row["id"], $allowed_ID, true)) {
            $msg = "Fake Account Detected: Username: "******"username"]) . " - UserID: " . (int) $row["id"] . " - UserIP : " . getip();
            // Demote and disable
            sql_query("UPDATE users SET enabled = 'no', class = 0 WHERE id =" . sqlesc($row["id"])) or sqlerr(__FILE__, __LINE__);
            $mc1->begin_transaction('MyUser_' . $row['id']);
            $mc1->update_row(false, array('enabled' => 'no', 'class' => 0));
            $mc1->commit_transaction($INSTALLER09['expires']['curuser']);
            $mc1->begin_transaction('user' . $row['id']);
            $mc1->update_row(false, array('enabled' => 'no', 'class' => 0));
            $mc1->commit_transaction($INSTALLER09['expires']['user_cache']);
            write_log($msg);
            logoutcookie();
        }
    }
    // user stats
    if (($stats = $mc1->get_value('userstats_' . $id)) === false) {
        $sql = sql_query('SELECT uploaded, downloaded, seedbonus FROM users WHERE id = ' . sqlesc($id)) or sqlerr(__FILE__, __LINE__);
        $stats = mysqli_fetch_assoc($sql);
        $stats['seedbonus'] = (double) $stats['seedbonus'];
        $stats['uploaded'] = (double) $stats['uploaded'];
        $stats['downloaded'] = (double) $stats['downloaded'];
        $ratio = $stats['downloaded'] > 0 ? $stats['uploaded'] / $stats['downloaded'] : 0;
        $stats['ratio'] = number_format($ratio, 2);
        $mc1->cache_value('userstats_' . $id, $stats, $INSTALLER09['expires']['u_stats']);
        // 5 mins
    }
    $row['seedbonus'] = $stats['seedbonus'];
    $row['uploaded'] = $stats['uploaded'];
    $row['downloaded'] = $stats['downloaded'];
    $row['ratio'] = $stats['ratio'];
    //==
    if (($ustatus = $mc1->get_value('userstatus_' . $id)) === false) {
        $sql2 = sql_query('SELECT * FROM ustatus WHERE userid = ' . sqlesc($id));
        if (mysqli_num_rows($sql2)) {
            $ustatus = mysqli_fetch_assoc($sql2);
        } else {
            $ustatus = array('last_status' => '', 'last_update' => 0, 'archive' => '');
        }
        $mc1->add_value('userstatus_' . $id, $ustatus, $INSTALLER09['expires']['u_status']);
        // 30 days
    }
    $row['last_status'] = $ustatus['last_status'];
    $row['last_update'] = $ustatus['last_update'];
    $row['archive'] = $ustatus['archive'];
    //==
    if ($row['ssluse'] > 1 && !isset($_SERVER['HTTPS']) && !defined('NO_FORCE_SSL')) {
        $INSTALLER09['baseurl'] = str_replace('http', 'https', $INSTALLER09['baseurl']);
        header('Location: ' . $INSTALLER09['baseurl'] . $_SERVER['REQUEST_URI']);
        exit;
    }
    // bitwise curuser bloks by pdq
    $blocks_key = 'blocks::' . $row['id'];
    if (($CURBLOCK = $mc1->get_value($blocks_key)) === false) {
        $c_sql = sql_query('SELECT * FROM user_blocks WHERE userid = ' . sqlesc($row['id'])) or sqlerr(__FILE__, __LINE__);
        if (mysqli_num_rows($c_sql) == 0) {
            sql_query('INSERT INTO user_blocks(userid) VALUES(' . sqlesc($row['id']) . ')');
            header('Location: index.php');
            die;
        }
        $CURBLOCK = mysqli_fetch_assoc($c_sql);
        $CURBLOCK['index_page'] = (int) $CURBLOCK['index_page'];
        $CURBLOCK['global_stdhead'] = (int) $CURBLOCK['global_stdhead'];
        $CURBLOCK['userdetails_page'] = (int) $CURBLOCK['userdetails_page'];
        $mc1->cache_value($blocks_key, $CURBLOCK, 0);
    }
    //== online time pdq, original code by superman
    $userupdate0 = 'onlinetime = onlinetime + 0';
    $new_time = TIME_NOW - $row['last_access_numb'];
    $update_time = 0;
    if ($new_time < 300) {
        $userupdate0 = "onlinetime = onlinetime + " . $new_time;
        $update_time = $new_time;
    }
    $userupdate1 = "last_access_numb = " . TIME_NOW;
    //end online-time
    $update_time = $row['onlinetime'] + $update_time;
    if ($row['last_access'] != '0' and $row['last_access'] < TIME_NOW - 180) {
        sql_query("UPDATE users SET last_access=" . TIME_NOW . ", {$userupdate0}, {$userupdate1} WHERE id=" . sqlesc($row['id']));
        $mc1->begin_transaction('MyUser_' . $row['id']);
        $mc1->update_row(false, array('last_access' => TIME_NOW, 'onlinetime' => $update_time, 'last_access_numb' => TIME_NOW));
        $mc1->commit_transaction($INSTALLER09['expires']['curuser']);
        $mc1->begin_transaction('user' . $row['id']);
        $mc1->update_row(false, array('last_access' => TIME_NOW, 'onlinetime' => $update_time, 'last_access_numb' => TIME_NOW));
        $mc1->commit_transaction($INSTALLER09['expires']['user_cache']);
    }
    //==
    if ($row['override_class'] < $row['class']) {
        $row['class'] = $row['override_class'];
    }
    // Override class and save in GLOBAL array below.
    $GLOBALS["CURUSER"] = $row;
    get_template();
    $mood = create_moods();
}