예제 #1
0
function dltable($name, $arr, $torrent)
{
    global $CURUSER, $lang;
    $htmlout = '';
    if (!count($arr)) {
        return $htmlout = "<div align='left'><b>{$lang['peerslist_no']} {$name} {$lang['peerslist_data_available']}</b></div>\n";
    }
    $htmlout = "\n";
    $htmlout .= "<table width='100%' class='main' border='1' cellspacing='0' cellpadding='5'>\n";
    $htmlout .= "<tr><td colspan='11' class='colhead'>" . count($arr) . " {$name}</td></tr>" . "<tr><td class='colhead'>{$lang['peerslist_user_ip']}</td>" . "<td class='colhead' align='center'>{$lang['peerslist_connectable']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_uploaded']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_downloaded']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_ratio']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_complete']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_connected']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_idle']}</td>" . "<td class='colhead' align='left'>{$lang['peerslist_client']}</td></tr>\n";
    $now = time();
    //$moderator = (isset($CURUSER) && get_user_class() >= UC_MODERATOR);
    //$mod = get_user_class() >= UC_MODERATOR;
    foreach ($arr as $e) {
        // user/ip/port
        // check if anyone has this ip
        //($unr = mysql_query("SELECT username, privacy FROM users WHERE id=$e[userid] ORDER BY last_access DESC LIMIT 1")) or die;
        //$una = mysql_fetch_assoc($unr);
        if ($e["privacy"] == "strong") {
            continue;
        }
        $htmlout .= "<tr>\n";
        if ($e["username"]) {
            $htmlout .= "<td><a href='userdetails.php?id={$e['userid']}'><b>{$e['username']}</b></a></td>\n";
        } else {
            $htmlout .= "<td>" . ($mod ? $e["ip"] : preg_replace('/\\.\\d+$/', ".xxx", $e["ip"])) . "</td>\n";
        }
        $secs = max(1, $now - $e["st"] - ($now - $e["la"]));
        //$revived = $e["revived"] == "yes";
        $htmlout .= "<td align='center'>" . ($e['connectable'] == "yes" ? "{$lang['peerslist_yes']}" : "<font color='red'>{$lang['peerslist_no']}</font>") . "</td>\n";
        $htmlout .= "<td align='right'>" . mksize($e["uploaded"]) . "</td>\n";
        $htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</span></td>\n";
        $htmlout .= "<td align='right'>" . mksize($e["downloaded"]) . "</td>\n";
        if ($e["seeder"] == "no") {
            $htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</span></td>\n";
        } else {
            $htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e['st'])) . "/s</span></td>\n";
        }
        if ($e["downloaded"]) {
            $ratio = floor($e["uploaded"] / $e["downloaded"] * 1000) / 1000;
            $htmlout .= "<td align=\"right\"><font color='" . get_ratio_color($ratio) . "'>" . number_format($ratio, 3) . "</font></td>\n";
        } else {
            if ($e["uploaded"]) {
                $htmlout .= "<td align='right'>{$lang['peerslist_inf']}</td>\n";
            } else {
                $htmlout .= "<td align='right'>---</td>\n";
            }
        }
        $htmlout .= "<td align='right'>" . sprintf("%.2f%%", 100 * (1 - $e["to_go"] / $torrent["size"])) . "</td>\n";
        $htmlout .= "<td align='right'>" . mkprettytime($now - $e["st"]) . "</td>\n";
        $htmlout .= "<td align='right'>" . mkprettytime($now - $e["la"]) . "</td>\n";
        $htmlout .= "<td align='left'>" . htmlspecialchars(getagent($e["agent"], $e['peer_id'])) . "</td>\n";
        $htmlout .= "</tr>\n";
    }
    $htmlout .= "</table>\n";
    return $htmlout;
}
예제 #2
0
function dltable($name, $arr, $torrent)
{
    global $CURUSER, $lang;
    $htmlout = '';
    if (!count($arr)) {
        return $htmlout = "<div align='left'><b>{$lang['peerslist_no']} {$name} {$lang['peerslist_data_available']}</b></div>\n";
    }
    $htmlout = "\n";
    $htmlout .= "<table width='100%' class='main' border='1' cellspacing='0' cellpadding='5'>\n";
    $htmlout .= "<tr><td colspan='11' class='colhead'>" . count($arr) . " {$name}</td></tr>" . "<tr><td class='colhead'>{$lang['peerslist_user_ip']}</td>" . "<td class='colhead' align='center'>{$lang['peerslist_connectable']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_uploaded']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_downloaded']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_ratio']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_complete']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_connected']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_idle']}</td>" . "<td class='colhead' align='left'>{$lang['peerslist_client']}</td></tr>\n";
    $now = time();
    $mod = $CURUSER['class'] >= UC_MODERATOR;
    foreach ($arr as $e) {
        if ($e["privacy"] == "strong") {
            continue;
        }
        $htmlout .= "<tr>\n";
        if ($e['username']) {
            if (($e['tanonymous'] == 'yes' && $e['owner'] == $e['userid'] || $e['anonymous'] == 'yes' && $CURUSER['id'] != $e['userid']) && $CURUSER['class'] < UC_MODERATOR) {
                $htmlout .= "<td><b>Anonymous</b></td>\n";
            } else {
                $htmlout .= "<td><a href='userdetails.php?id=" . $e['userid'] . "'><b>" . $e['username'] . "</b></a></td>\n";
            }
        } else {
            $htmlout .= "<td>" . ($mod ? $e["ip"] : preg_replace('/\\.\\d+$/', ".xxx", $e["ip"])) . "</td>\n";
        }
        $secs = max(1, $now - $e["st"] - ($now - $e["la"]));
        $htmlout .= "<td align='center'>" . ($e['connectable'] == "yes" ? "{$lang['peerslist_yes']}" : "<font color='red'>{$lang['peerslist_no']}</font>") . "</td>\n";
        $htmlout .= "<td align='right'>" . mksize($e["uploaded"]) . "</td>\n";
        $htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</span></td>\n";
        $htmlout .= "<td align='right'>" . mksize($e["downloaded"]) . "</td>\n";
        if ($e["seeder"] == "no") {
            $htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</span></td>\n";
        } else {
            $htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e['st'])) . "/s</span></td>\n";
        }
        if ($e["downloaded"]) {
            $ratio = floor($e["uploaded"] / $e["downloaded"] * 1000) / 1000;
            $htmlout .= "<td align=\"right\"><font color='" . get_ratio_color($ratio) . "'>" . number_format($ratio, 3) . "</font></td>\n";
        } else {
            if ($e["uploaded"]) {
                $htmlout .= "<td align='right'>{$lang['peerslist_inf']}</td>\n";
            } else {
                $htmlout .= "<td align='right'>---</td>\n";
            }
        }
        $htmlout .= "<td align='right'>" . sprintf("%.2f%%", 100 * (1 - $e["to_go"] / $torrent["size"])) . "</td>\n";
        $htmlout .= "<td align='right'>" . mkprettytime($now - $e["st"]) . "</td>\n";
        $htmlout .= "<td align='right'>" . mkprettytime($now - $e["la"]) . "</td>\n";
        $htmlout .= "<td align='left'>" . htmlspecialchars(getagent($e["agent"], $e['peer_id'])) . "</td>\n";
        $htmlout .= "</tr>\n";
    }
    $htmlout .= "</table>\n";
    return $htmlout;
}
예제 #3
0
function dltable($name, $arr, $torrent)
{
    global $CURUSER, $lang, $INSTALLER09;
    $htmlout = '';
    if (!count($arr)) {
        return $htmlout = "<div align='left'><b>{$lang['peerslist_no']} {$name} {$lang['peerslist_data_available']}</b></div>\n";
    }
    $htmlout = "\n";
    $htmlout .= "<table width='100%' class='main' border='1' cellspacing='0' cellpadding='5'>\n";
    $htmlout .= "<tr><td colspan='11' class='colhead'>" . count($arr) . " {$name}</td></tr>" . "<tr><td class='colhead'>{$lang['peerslist_user_ip']}</td>" . "<td class='colhead' align='center'>{$lang['peerslist_connectable']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_uploaded']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>" . "" . ($INSTALLER09['ratio_free'] ? "" : "<td class='colhead' align='right'>{$lang['peerslist_downloaded']}</td>") . "" . "" . ($INSTALLER09['ratio_free'] ? "" : "<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>") . "" . "<td class='colhead' align='right'>{$lang['peerslist_ratio']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_complete']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_connected']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_idle']}</td>" . "<td class='colhead' align='left'>{$lang['peerslist_client']}</td></tr>\n";
    $now = TIME_NOW;
    $mod = $CURUSER['class'] >= UC_STAFF;
    foreach ($arr as $e) {
        $htmlout .= "<tr>\n";
        if ($e['username']) {
            if (($e['tanonymous'] == 'yes' && $e['owner'] == $e['userid'] || $e['anonymous'] == 'yes' or $e['paranoia'] >= 2) && $CURUSER['id'] != $e['userid'] && $CURUSER['class'] < UC_STAFF) {
                $htmlout .= "<td><b>Kezer Soze</b></td>\n";
            } else {
                $htmlout .= "<td><a href='userdetails.php?id=" . (int) $e['userid'] . "'><b>" . htmlsafechars($e['username']) . "</b></a></td>\n";
            }
        } else {
            $htmlout .= "<td>" . ($mod ? $e["ip"] : preg_replace('/\\.\\d+$/', ".xxx", $e["ip"])) . "</td>\n";
        }
        $secs = max(1, $now - $e["st"] - ($now - $e["la"]));
        $htmlout .= "<td align='center'>" . ($e['connectable'] == "yes" ? "{$lang['peerslist_yes']}" : "<font color='red'>{$lang['peerslist_no']}</font>") . "</td>\n";
        $htmlout .= "<td align='right'>" . mksize($e["uploaded"]) . "</td>\n";
        $htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</span></td>\n";
        $htmlout .= "" . ($INSTALLER09['ratio_free'] ? "" : "<td align='right'>" . mksize($e["downloaded"]) . "</td>") . "\n";
        if ($e["seeder"] == "no") {
            $htmlout .= "" . ($INSTALLER09['ratio_free'] ? "" : "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</span></td>") . "\n";
        } else {
            $htmlout .= "" . ($INSTALLER09['ratio_free'] ? "" : "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e['st'])) . "/s</span></td>") . "\n";
        }
        $htmlout .= "<td align=\"right\">" . member_ratio($e['uploaded'], $INSTALLER09['ratio_free'] ? "0" : $e['downloaded']) . "</td>\n";
        $htmlout .= "<td align='right'>" . sprintf("%.2f%%", 100 * (1 - $e["to_go"] / $torrent["size"])) . "</td>\n";
        $htmlout .= "<td align='right'>" . mkprettytime($now - $e["st"]) . "</td>\n";
        $htmlout .= "<td align='right'>" . mkprettytime($now - $e["la"]) . "</td>\n";
        $htmlout .= "<td align='left'>" . htmlsafechars(getagent($e["agent"], $e['peer_id'])) . "</td>\n";
        $htmlout .= "</tr>\n";
    }
    $htmlout .= "</table>\n";
    return $htmlout;
}
예제 #4
0
function dltable($name, $arr, $torrent)
{
    global $CURUSER, $lang, $INSTALLER09;
    $htmlout = '';
    if (!count($arr)) {
        return $htmlout = "<div align='left'><b>{$lang['peerslist_no']} {$name} {$lang['peerslist_data_available']}</b></div>\n";
    }
    $htmlout = "\n";
    $htmlout .= "<table class='table table-bordered'>\n";
    $htmlout .= "<tr><td colspan='11' class='colhead'>" . count($arr) . " {$name}</td></tr>" . "<tr><td class='colhead'>{$lang['peerslist_user_ip']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_uploaded']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>" . "" . ($INSTALLER09['ratio_free'] ? "" : "<td class='colhead' align='right'>{$lang['peerslist_downloaded']}</td>") . "" . "" . ($INSTALLER09['ratio_free'] ? "" : "<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>") . "" . "<td class='colhead' align='right'>{$lang['peerslist_ratio']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_complete']}</td>" . "<td class='colhead' align='right'>{$lang['peerslist_idle']}</td>" . "<td class='colhead' align='left'>{$lang['peerslist_client']}</td></tr>\n";
    $now = TIME_NOW;
    $mod = $CURUSER['class'] >= UC_STAFF;
    foreach ($arr as $e) {
        $htmlout .= "<tr>\n";
        $upspeed = $e["upspeed"] > 0 ? mksize($e["upspeed"]) : ($e["seedtime"] > 0 ? mksize($e["uploaded"] / ($e["seedtime"] + $e["leechtime"])) : mksize(0));
        $downspeed = $e["downspeed"] > 0 ? mksize($e["downspeed"]) : ($e["leechtime"] > 0 ? mksize($e["downloaded"] / $e["leechtime"]) : mksize(0));
        if ($e['username']) {
            if (($e['tanonymous'] == 'yes' && $e['owner'] == $e['uid'] || $e['anonymous'] == 'yes' or $e['paranoia'] >= 2 && $CURUSER['id'] != $e['uid']) && $CURUSER['class'] < UC_STAFF) {
                $htmlout .= "<td><b>Kezer Soze</b></td>\n";
            } else {
                $htmlout .= "<td><a href='userdetails.php?id=" . (int) $e['uid'] . "'><b>" . htmlsafechars($e['username']) . "</b></a></td>\n";
            }
        } else {
            $htmlout .= "<td>" . ($mod ? XBT_IP_CONVERT($e["ipa"]) : preg_replace('/\\.\\d+$/', ".xxx", XBT_IP_CONVERT($e["ipa"]))) . "</td>\n";
        }
        $htmlout .= "<td align='right'>" . mksize($e["uploaded"]) . "</td>\n";
        $htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . htmlsafechars($upspeed) . "/s</span></td>\n";
        $htmlout .= "" . ($INSTALLER09['ratio_free'] ? "" : "<td align='right'>" . mksize($e["downloaded"]) . "</td>") . "\n";
        $htmlout .= "" . ($INSTALLER09['ratio_free'] ? "" : "<td align='right'><span style=\"white-space: nowrap;\">" . htmlsafechars($downspeed) . "/s</span></td>") . "\n";
        $htmlout .= "<td align=\"right\">" . member_ratio($e['uploaded'], $INSTALLER09['ratio_free'] ? "0" : $e['downloaded']) . "</td>\n";
        $htmlout .= "<td align='right'>" . sprintf("%.2f%%", 100 * (1 - $e["left"] / $torrent["size"])) . "</td>\n";
        $htmlout .= "<td align='right'>" . mkprettytime($now - $e["la"]) . "</td>\n";
        $htmlout .= "<td align='left'>" . htmlsafechars(getagent($e["peer_id"], $e['peer_id'])) . "</td>\n";
        $htmlout .= "</tr>\n";
    }
    $htmlout .= "</table>\n";
    return $htmlout;
}
예제 #5
0
if (!defined("IN_BTIT")) {
    die("non direct access!");
}
if (!defined("IN_ACP")) {
    die("non direct access!");
}
include load_language("lang_peers.php");
$admintpl->set('language', $language);
isset($_GET["agent"]) ? $agent = urldecode($_GET["agent"]) : ($agent = "");
isset($_GET["peer_id"]) ? $peer_id = urldecode($_GET["peer_id"]) : ($peer_id = "");
isset($_GET["returnto"]) ? $url = urldecode($_GET["returnto"]) : ($url = "index.php");
isset($_POST["confirm"]) ? $confirm = $_POST["confirm"] : ($confirm = "");
isset($_POST["reason"]) ? $reason = mysql_real_escape_string($_POST["reason"]) : ($reason = "");
isset($_POST["banall"]) ? $banall = "yes" : ($banall = "no");
$peer_id_ascii = hex2bin($peer_id);
$client = getagent($agent, $peer_id);
$admintpl->set('agent', $agent);
$admintpl->set('peer_id', $peer_id);
$admintpl->set('url', $url);
$admintpl->set('confirm', $confirm);
$admintpl->set('reason', $reason);
$admintpl->set('banall', $banall);
$admintpl->set('peer_id_ascii', $peer_id_ascii);
$admintpl->set('client', $client);
if ($_POST["confirm"]) {
    if ($confirm == $language["YES"] && $reason != "") {
        $sqlquery = "SELECT id ";
        $sqlquery .= "FROM {$TABLE_PREFIX}banned_client ";
        $sqlquery .= "WHERE peer_id=" . sqlesc($peer_id) . " ";
        $sqlquery .= "OR peer_id=" . sqlesc(substr($peer_id, 0, 6));
        $check = mysql_query($sqlquery) or die(mysql_error());
예제 #6
0
     collectBytes($peer_exists, $info_hash, $left, $downloaded, $uploaded, $pid);
     $peers = getRandomPeers($info_hash);
     sendPeerList($peers);
     // begin history
     if ($LOG_HISTORY) {
         $resu = $db->query("SELECT id FROM users WHERE " . ($PRIVATE_ANNOUNCE ? "pid = '" . $pid . "'" : "cip = '" . $ip . "'") . " ORDER BY lastconnect DESC LIMIT 1");
         // if found at least one user should be 1
         if ($resu && $resu->num_rows == 1) {
             $curuid = $resu->fetch_array(MYSQLI_BOTH);
             // if user has already completed this torrent, mysql will give error because of unique index (uid+infohash)
             // upload/download will be updated on stop event...
             // record should already exist (created on stated event)
             quickQuery("UPDATE history SET date = UNIX_TIMESTAMP(), active = 'yes', agent = '" . getagent($agent, $peer_id) . "' WHERE uid = " . (int) $curuid["id"] . " AND infohash = '" . $info_hash . "'");
             // record is not present, create it
             if ($db->affected_rows == 0) {
                 quickQuery("INSERT INTO history (uid, infohash, date, active, agent) VALUES (" . (int) $curuid["id"] . ", '" . $info_hash . "', UNIX_TIMESTAMP(), 'yes', '" . getagent($agent, $peer_id) . "')");
             }
         }
         $resu->free();
     }
     break;
     // client sent no event
 // client sent no event
 case '':
     verifyTorrent($info_hash) or show_error("Torrent is not authorized for use on this tracker.");
     $peer_exists = getPeerInfo($peer_id, $info_hash);
     $where = "WHERE natuser = '******'";
     if (!is_array($peer_exists)) {
         $where = start($info_hash, $ip, $port, $peer_id, $left, $downloaded, $uploaded, $pid);
     }
     if ($peer_exists["bytes"] != 0 && $left == 0) {
예제 #7
0
function get_svgmode()
{
    global $debug;
    $dummy = getagent();
    $ua_name = $dummy["name"];
    $ua_ver = $dummy["version"];
    #echo "more specifically: $ua_name, version $ua_ver<br>\n";
    if ($debug > 0) {
        debug_output("browser: {$ua_name}, version {$ua_ver}");
    }
    $svgmode = 0;
    // default: SVG not supported
    if ($ua_name === "MSIE" && $ua_ver >= 9) {
        $svgmode = 1;
    }
    if ($ua_name === "Firefox" && $ua_ver >= 4) {
        $svgmode = 1;
    }
    if ($ua_name === "Chrome" && $ua_ver >= 7) {
        $svgmode = 1;
    }
    if ($ua_name === "Opera" && $ua_ver >= 8) {
        $svgmode = 2;
    }
    // ?? inline SVG since 11.6
    if ($ua_name === "Opera" && $ua_ver >= 11.6) {
        $svgmode = 1;
    }
    // ?? inline SVG since 11.6
    if ($ua_name === "Safari" && $ua_ver >= 500) {
        $svgmode = 2;
    }
    // ?? inline SVG since 5.1
    if ($ua_name === "Safari" && $ua_ver >= 510) {
        $svgmode = 1;
    }
    // ?? inline SVG since 5.1
    // currently, display of _scaled_ external SVGs does not work properly, so disable mode 2
    if ($svgmode == 2) {
        $svgmode = 0;
    }
    return $svgmode;
}
예제 #8
0
    } elseif ($rowuser[2] != "" && !empty($rowuser[2])) {
        print "<td align='center' class='lista'><img src='images/flag/" . $rowuser[2] . "' alt='" . security::html_safe(unesc($rowuser[3])) . "' /></td>";
    } else {
        print "<td align='center' class='lista'><img src='images/flag/unknown.gif' alt='" . UNKNOWN . "' /></td>";
    }
    print "<td align='center' class='lista'>" . (int) $row["port"] . "</td>";
    if ($tsize != 0) {
        $stat = floor(($tsize - (int) $row['bytes']) / $tsize * 100);
    } else {
        $stat = floor(($tsize - (int) $row['bytes']) / 0 * 100);
    }
    $progress = "<table width='100' cellspacing='0' cellpadding='0'><tr><td class='progress' align='left'>";
    $progress .= "<img height='10' height='10' width='" . number_format($stat, 0) . "' src='" . $STYLEPATH . "/progress.jpg'></td></tr></table>";
    print "<td valign='top' align='center' class='lista'>" . $stat . "%<br />" . $progress . "</td>\n";
    print "<td align='center' class='lista'>" . $row["status"] . "</td>";
    print "<td align='center' class='lista'>" . security::html_safe(getagent(unesc($row["client"]), unesc($row["peer_id"]))) . "</td>";
    $dled = misc::makesize((int) $row["downloaded"]);
    $upld = misc::makesize((int) $row["uploaded"]);
    print "<td align='center' class='lista'>" . $dled . "</td>";
    print "<td align='center' class='lista'>" . $upld . "</td>";
    //Peer Ratio
    if (intval($row["downloaded"]) > 0) {
        $ratio = number_format((int) $row["uploaded"] / (int) $row["downloaded"], 2);
    } else {
        $ratio = "&infin;";
    }
    print "<td align='center' class='lista'>" . $ratio . "</td>";
    //End Peer Ratio
    print "<td align='center' class='lista'>" . get_elapsed_time($row["lastupdate"]) . " ago</td></tr>";
}
if ($res->num_rows == 0) {
예제 #9
0
function getclient($peerid, $agent = null)
{
    $azclients = array('AZ' => 'Azureus', 'BB' => 'BitBuddy', 'CT' => 'CTorrent', 'MT' => 'MoonlightTorrent', 'LT' => 'LibTorrent', 'BX' => 'Bittorrent X', 'TS' => 'TorrentStorm', 'TN' => 'TorrentDotNET', 'SS' => 'SwarmScope', 'XT' => 'XanTorrent', 'BS' => 'BitSlave');
    //azuranus style
    $sclients = array('S' => 'Shadow', 'U' => 'UPnP', 'T' => 'BitTornado', 'A' => 'ABC');
    //shadow style clients
    $bcclients = array('exbc' => 'BitComet');
    //bitcomet style
    if (preg_match("/^Azureus ([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]\\_B[0-9]+)/", $httpagent, $matches)) {
        return "Azureus/{$matches['1']}";
    } elseif (preg_match("/^Azureus ([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]\\_[a-zA-Z]+)/", $httpagent, $matches)) {
        return "Azureus/{$matches['1']}";
    } elseif (preg_match("/^Java\\/([0-9]+\\.[0-9]+\\.[0-9]+)/", $httpagent, $matches)) {
        return "Azureus/<2.0.7.0";
    } elseif (preg_match("/^Azureus ([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)/", $httpagent, $matches)) {
        return "Azureus/{$matches['1']}";
    } elseif (preg_match("/^BitTorrent\\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        if (substr($peer_id, 0, 6) == "exbc8") {
            return "BitComet/0.56";
        } elseif (substr($peer_id, 0, 6) == "exbc9") {
            return "BitComet/0.57";
        } elseif (substr($peer_id, 0, 4) == "FUTB") {
            return "BitComet/0.57p";
        } elseif (substr($peer_id, 0, 6) == "exbc:") {
            return "BitComet/0.58";
        } elseif (substr($peer_id, 0, 8) == "-BC0059-") {
            return "BitComet/0.59";
        } elseif (substr($peer_id, 0, 8) == "-BC0060-") {
            return "BitComet/0.60";
        } elseif (substr($peer_id, 0, 7) == "exbcL") {
            return "BitLord/1.0";
        } elseif (substr($peer_id, 0, 7) == "exbcL") {
            return "BitLord/1.1";
        } else {
            return "BitTorrent/{$matches['1']}";
        }
    } elseif (ereg("^uTorrent", $httpagent)) {
        if (substr($peer_id, 0, 8) == "-UT1130-") {
            return "uTorrent 1.1.3";
        }
        if (substr($peer_id, 0, 8) == "-UT1140-") {
            return "uTorrent 1.1.4";
        }
        if (substr($peer_id, 0, 8) == "-UT1150-") {
            return "uTorrent 1.1.5";
        }
        if (substr($peer_id, 0, 8) == "-UT1161-") {
            return "uTorrent 1.1.6.1";
        }
        if (substr($peer_id, 0, 8) == "-UT1171-") {
            return "uTorrent 1.1.7.1";
        } else {
            return "uTorrent";
        }
    } elseif (preg_match("/^Python-urllib\\/.+?, BitTorrent\\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        return "BitTorrent/{$matches['1']}";
    } elseif (preg_match("/^Python-urllib\\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        return "G3 Torrent";
    } elseif (preg_match("/^BitTorrent\\/ABC-([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        return "ABC/{$matches['1']}";
    } elseif (preg_match("/^ABC ([0-9]+\\.[0-9]+(\\.[0-9]+)*)\\/ABC-([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        return "ABC/{$matches['1']}";
    } elseif (preg_match("/^ABC\\/ABC-([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        return "ABC/{$matches['1']}";
    } elseif (ereg("^BitTorrent\\/BitSpirit\$", $httpagent)) {
        return "BitSpirit";
    } elseif (preg_match("/^BitsOnWheels( |\\/)([0-9]+\\.[0-9]+).*/", $httpagent, $matches)) {
        return "BitsOnWheels/{$matches['2']}";
    } elseif (preg_match("/BitTorrentPlus\\/(.+)\$/", $httpagent, $matches)) {
        return "BitTorrent Plus!/{$matches['1']}";
    } elseif (preg_match("/^BitTorrent\\/brst(.+)/", $httpagent, $matches)) {
        return "Burst/{$matches['1']}";
    } elseif (preg_match("/^BitTor(rent|nado)\\/T-(.+)\$/", $httpagent, $matches)) {
        return "BitTornado/{$matches['2']}";
    } elseif (preg_match("/^BitTornado\\/T-(.+)\$/", $httpagent, $matches)) {
        return "BitTornado/{$matches['1']}";
    } elseif (preg_match("/^Python-urllib\\/.+?, BitTorrent\\/T-([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        return "BitTornado/{$matches['1']}";
    } elseif (ereg("^Deadman Walking", $httpagent)) {
        return "Deadman Walking";
    } elseif (preg_match("/ed2k_plugin v([0-9]+\\.[0-9]+).*/", $httpagent, $matches)) {
        return "eDonkey/{$matches['1']}";
    } elseif (preg_match("/^eXeem( |\\/)([0-9]+\\.[0-9]+).*/", $httpagent, $matches)) {
        return "eXeem{$matches['1']}{$matches['2']}";
    } elseif (preg_match("/^libtorrent\\/(.+)\$/", $httpagent, $matches)) {
        return "libtorrent/{$matches['1']}";
    } elseif (preg_match("/MLDonkey( |\\/)(.+)\$/i", $httpagent, $matches)) {
        return "MLdonkey{$matches['1']}{$matches['2']}";
    } elseif (ereg("^0P3R4H", $httpagent)) {
        return "OperaBT";
    } elseif (preg_match("/Rufus\\/([0-9]+\\.[0-9]+\\.[0-9]+)/", $httpagent, $matches)) {
        return "Rufus/{$matches['1']}";
    } elseif (preg_match("/BitTorrent\\/S-([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        return "Shadow's/{$matches['1']}";
    } elseif (preg_match("/^RAZA (.+)\$/", $httpagent, $matches)) {
        return "Shareaza/{$matches['1']}";
    } elseif (preg_match("/^Shareaza (.+)\$/", $httpagent, $matches)) {
        return "Shareaza/{$matches['1']}";
    } elseif (preg_match("/^Python-urllib\\/.+?, BitTorrent\\/TurboBT ([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches)) {
        return "TurboBT/{$matches['1']}";
    } elseif (preg_match("/BitTorrent\\/U-([0-9]+\\.[0-9]+\\.[0-9]+)/", $httpagent, $matches)) {
        return "UPnP/{$matches['1']}";
    } elseif (preg_match("/^uTorrent(|(\\/[0-9][0-9][0-9][0-9]))\$/i", $httpagent, $matches)) {
        return "uTorrent{$matches['1']}";
    } elseif (ereg("^DansClient", $httpagent)) {
        return "XanTorrent";
    } elseif (ereg("^XBT Client", $httpagent)) {
        return "XBT Client";
    } elseif (get_user_class() >= UC_UPLOADER && preg_match("/^A\\x02\\x06\\x09/", $peerid, $matches)) {
        return "Az-Hacked";
    } else {
        if ($agent) {
            return getagent($agent);
        }
    }
}
예제 #10
0
파일: common.php 프로젝트: Karpec/gizd
function logclientinfo($agent, $peer_id, $port, $ip, $clientinfo = "", $id)
{
    global $TABLE_PREFIX;
    $client = getagent($agent, $peer_id);
    if (empty($clientinfo)) {
        $clientlist[0] = $client . "[X]" . $port;
        $clientlist[1] = time() . "[X]" . $ip;
        $clientlist = serialize($clientlist);
        $query = "UPDATE `{$TABLE_PREFIX}users` SET `clientinfo`='{$clientlist}' WHERE `id`=" . $id;
        @mysqli_query($GLOBALS["___mysqli_ston"], $query);
    } else {
        $clientlist = unserialize($clientinfo);
        if (!in_array($client . "[X]" . $port, $clientlist)) {
            if (count($clientlist) == 20) {
                unset($clientlist[0]);
                unset($clientlist[1]);
                $newlist = array();
                foreach ($clientlist as $v) {
                    $newlist[] = $v;
                }
                $clientlist = $newlist;
            }
            $clientlist[] = $client . "[X]" . $port;
            $clientlist[] = time() . "[X]" . $ip;
            $clientlist = serialize($clientlist);
            $query = "UPDATE `{$TABLE_PREFIX}users` SET `clientinfo`='{$clientlist}' WHERE `id`=" . $id;
            @mysqli_query($GLOBALS["___mysqli_ston"], $query);
        }
    }
}
예제 #11
0
         }
     }
     sendRandomPeers($info_hash);
     // begin history
     if ($LOG_HISTORY) {
         $resu = mysql_query("SELECT id FROM {$TABLE_PREFIX}users WHERE " . ($PRIVATE_ANNOUNCE ? "pid='{$pid}'" : "cip='{$ip}'") . " ORDER BY lastconnect DESC LIMIT 1");
         // if found at least one user should be 1
         if ($resu && mysql_num_rows($resu) == 1) {
             $curuid = mysql_fetch_assoc($resu);
             // if user has already completed this torrent, mysql will give error because of unique index (uid+infohash)
             // upload/download will be updated on stop event...
             // record should already exist (created on stated event)
             quickQuery("UPDATE {$TABLE_PREFIX}history SET date=UNIX_TIMESTAMP(),active='yes',agent='" . getagent($agent, $peer_id) . "' WHERE uid=" . $curuid["id"] . " AND infohash='{$info_hash}'");
             // record is not present, create it
             if (mysql_affected_rows() == 0) {
                 quickQuery("INSERT INTO {$TABLE_PREFIX}history (uid,infohash,date,active,agent) VALUES (" . $curuid["id"] . ",'{$info_hash}',UNIX_TIMESTAMP(),'yes','" . getagent($agent, $peer_id) . "')");
             }
         }
         mysql_free_result($resu);
     }
     // end history
     break;
     // client sent no event
 // client sent no event
 case "":
     $peer_exists = getPeerInfo($peer_id, $info_hash);
     $where = "WHERE natuser='******'";
     if (!is_array($peer_exists)) {
         $where = start($info_hash, $ip, $port, $peer_id, $left, $downloaded, $uploaded, $pid);
     }
     if ($peer_exists["bytes"] != 0 && $left == 0) {
예제 #12
0
    } elseif (preg_match("/ed2k_plugin v([0-9]+\\.[0-9]+).*/", $httpagent, $matches)) {
        return "eDonkey/{$matches['1']}";
    } elseif (preg_match("/uTorrent\\/([0-9]+)([0-9]+)([0-9]+)([0-9A-Z]+)/", $httpagent, $matches)) {
        return "µTorrent/{$matches['1']}.{$matches['2']}.{$matches['3']}.{$matches['4']}";
    } elseif (ereg("^0P3R4H", $httpagent)) {
        return "Opera BT Client";
    } elseif (preg_match("/CT([0-9]+)([0-9]+)([0-9]+)([0-9]+)/", $peer_id, $matches)) {
        return "cTorrent/{$matches['1']}.{$matches['2']}.{$matches['3']}.{$matches['4']}";
    } elseif (preg_match("/Transmission\\/([0-9]+).([0-9]+)/", $httpagent, $matches)) {
        return "Transmission/{$matches['1']}.{$matches['2']}";
    } elseif (preg_match("/KT([0-9]+)([0-9]+)([0-9]+)([0-9]+)/", $peer_id, $matches)) {
        return "KTorrent/{$matches['1']}.{$matches['2']}.{$matches['3']}.{$matches['4']}";
    } elseif (substr($peer_id, 0, 8) == "-MP130n-") {
        return "MooPolice";
    } elseif (preg_match("/Ares ([0-9]+).([0-9]+).([0-9]+)*/", $httpagent, $matches)) {
        return "Ares/{$matches['1']}.{$matches['2']}.{$matches['3']}";
    } else {
        return "---";
    }
}
if ($CURUSER['class'] < UC_MODERATOR) {
    stderr('Error', 'Permission denied.');
}
$res = mysql_query('SELECT peers.agent, peer_id, userid, username FROM peers LEFT JOIN users ON peers.userid = users.id') or sqlerr(__FILE__, __LINE__);
stdhead('All Clients');
echo '<table align="center" border="3" cellspacing="0" cellpadding="5">' . "\n" . '<tr><td class="colhead">Client</td><td class="colhead">Peer ID</td><td class="colhead">Shown as (getagent func)</td><td class="colhead">Used By</td></tr>' . "\n";
while ($arr = mysql_fetch_assoc($res)) {
    echo '<tr><td align="left">' . safeChar($arr['agent']) . '</td><td align="left">' . safeChar($arr['peer_id']) . '</td>' . '<td align="left">' . safeChar(getagent($arr['agent'], $arr['peer_id'])) . '</td><td align="center"><a href="userdetails.php?id=' . $arr['userid'] . '"><b>' . safeChar($arr['username']) . '</b></a></td></tr>' . "\n";
}
echo "</table>\n";
stdfoot();
예제 #13
0
function dltable($name, $arr, $torrent)
{
    global $CURUSER;
    $s = "<b>" . count($arr) . " {$name}</b>\n";
    if (!count($arr)) {
        return $s;
    }
    $s .= "\n";
    $s .= "<table width=100% class=main border=1 cellspacing=0 cellpadding=5>\n";
    $s .= "<tr><td class=colhead>User/IP</td>" . "<td class=colhead align=center>Connectable</td>" . "<td class=colhead align=right>Uploaded</td>" . "<td class=colhead align=right>Rate</td>" . "<td class=colhead align=right>Downloaded</td>" . "<td class=colhead align=right>Rate</td>" . "<td class=colhead align=right>Ratio</td>" . "<td class=colhead align=right>Complete</td>" . "<td class=colhead align=right>Connected</td>" . "<td class=colhead align=right>Idle</td>" . "<td class=colhead align=left>Client</td></tr>\n";
    $now = time();
    $moderator = isset($CURUSER) && get_user_class() >= UC_MODERATOR;
    $mod = get_user_class() >= UC_MODERATOR;
    foreach ($arr as $e) {
        // user/ip/port
        // check if anyone has this ip
        $unr = sql_query("SELECT id, username, privacy, warned, donor, anonymous FROM users WHERE id={$e['userid']} ORDER BY last_access DESC LIMIT 1") or die;
        $una = mysql_fetch_array($unr);
        if ($una["privacy"] == "strong") {
            continue;
        }
        ++$num;
        $highlight = $CURUSER["id"] == $una["id"] ? " bgcolor=#777777" : "";
        $s .= "<tr{$highlight}>\n";
        // $s .= "<tr>\n";
        if ($una["username"]) {
            if (get_user_class() < UC_MODERATOR && $una['anonymous'] == 'yes' && $e['userid'] != $CURUSER['id']) {
                $s .= "<td class=\"row1\"><i>Anonymous</i></td>\n";
            } else {
                if (get_user_class() >= UC_UPLOADER || $torrent['anonymous'] != 'yes' || $e['userid'] != $torrent['owner']) {
                    $s .= "<td class=\"row1\"><a href=userdetails.php?id={$e['userid']}><b>{$una['username']}</b></a>" . ($una["donor"] == "yes" ? "<img src=" . "/pic/star.gif alt='Donor'>" : "") . ($una["enabled"] == "no" ? "<img src=" . "/pic/disabled.gif alt=\"This account is disabled\" style='margin-left: 2px'>" : ($una["warned"] == "yes" ? "<a href=rules.php#warning class=altlink><img src=/pic/warned.gif alt=\"Warned\" border=0></a>" : ""));
                } elseif (get_user_class() >= UC_UPLOADER || ($torrent['anonymous'] = 'yes')) {
                    $s .= "<td class=\"row1\"><i>Anonymous</i></a></td>\n";
                }
            }
        } else {
            $s .= "<td>(unknown)</td>\n";
        }
        $secs = max(1, $now - $e["st"] - ($now - $e["la"]));
        $revived = $e["revived"] == "yes";
        $s .= "<td align=center>" . ($e[connectable] == "yes" ? "Yes" : "<font color=red>No</font>") . "</td>\n";
        $s .= "<td align=right>" . prefixed($e["uploaded"]) . "</td>\n";
        $s .= "<td align=right><span style=white-space: nowrap;>" . prefixed(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</span></td>\n";
        $s .= "<td align=right>" . prefixed($e["downloaded"]) . "</td>\n";
        if ($e["seeder"] == "no") {
            $s .= "<td align=right><div style=white-space:nowrap;>" . prefixed(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</div></td>\n";
        } else {
            $s .= "<td align=right><div style=white-space:nowrap;>" . prefixed(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e[st])) . "/s</div></td>\n";
        }
        if ($e["downloaded"]) {
            $ratio = floor($e["uploaded"] / $e["downloaded"] * 1000) / 1000;
            $s .= "<td align=\"right\"><font color=" . get_ratio_color($ratio) . ">" . number_format($ratio, 3) . "</font></td>\n";
        } else {
            if ($e["uploaded"]) {
                $s .= "<td align=right>Inf.</td>\n";
            } else {
                $s .= "<td align=right>---</td>\n";
            }
        }
        $s .= "<td align=right>" . sprintf("%.2f%%", 100 * (1 - $e["to_go"] / $torrent["size"])) . "</td>\n";
        $s .= "<td align=right>" . mkprettytime($now - $e["st"]) . "</td>\n";
        $s .= "<td align=right>" . mkprettytime($now - $e["la"]) . "</td>\n";
        $s .= "<td align=left>" . safeChar(getagent($e["agent"], $e["peer_id"])) . (get_user_class() >= UC_ADMINISTRATOR ? "<a href='ban_client.php?agent=" . $e["agent"] . "&peer_id=" . bin2hex(substr($e["peer_id"], 0, 8)) . "&returnto=" . urlencode("details.php?id=" . intval($_GET["id"])) . "'><img src='pic/smilies/thumbsdown.gif' border='0' alt='Ban client?'></a>" : "") . "</td>\n";
        $s .= "</tr>\n";
    }
    $s .= "</table>\n";
    return $s;
}
예제 #14
0
파일: announce.php 프로젝트: Karpec/gizd
             collectBytes($peer_exists, $info_hash, $left, $downloaded, $uploaded, $pid);
         }
     }
     sendRandomPeers($info_hash);
     // begin history
     if ($LOG_HISTORY) {
         $resu = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id FROM {$TABLE_PREFIX}users WHERE " . ($PRIVATE_ANNOUNCE ? "pid='{$pid}'" : "cip='{$ip}'") . " ORDER BY lastconnect DESC LIMIT 1");
         // if found at least one user should be 1
         if ($resu && mysqli_num_rows($resu) == 1) {
             $curuid = mysqli_fetch_assoc($resu);
             // Hit and run v2 - Start
             quickQuery("UPDATE {$TABLE_PREFIX}history SET date=UNIX_TIMESTAMP(),active='yes',completed='yes',agent='" . getagent($agent, $peer_id) . "' WHERE uid=" . $curuid["id"] . " AND infohash='{$info_hash}'");
             // Hit and run v2 - Ends
             // record is not present, create it
             if (mysqli_affected_rows($GLOBALS["___mysqli_ston"]) == 0) {
                 quickQuery("INSERT INTO {$TABLE_PREFIX}history (uid,infohash,date,active,completed,agent,downloaded,uploaded) VALUES (" . $curuid["id"] . ",'{$info_hash}',UNIX_TIMESTAMP(),'yes','yes','" . getagent($agent, $peer_id) . "',{$downloaded},{$uploaded})");
             }
             // Hit and run v2 line over AND old line bellow
         }
         mysqli_free_result($resu) || is_object($resu) && get_class($resu) == "mysqli_result" ? true : false;
     }
     // end history
     break;
     // client sent no event
 // client sent no event
 case "":
     $peer_exists = getPeerInfo($peer_id, $info_hash);
     $where = "WHERE natuser='******'";
     if (!is_array($peer_exists)) {
         $where = start($info_hash, $ip, $port, $peer_id, $left, $downloaded, $uploaded, $pid);
     }
예제 #15
0
파일: sanity.php 프로젝트: Karpec/gizd
function do_sanity($ts = 0)
{
    // Lets try upping the max_execution_time and memory_limit if we can (Code from Pet/FM)
    if (@ini_get("max_execution_time") < 300) {
        @ini_set("max_execution_time", 300);
    }
    if (trim(@ini_get("memory_limit"), "M") < 128) {
        @ini_set("memory_limit", "128M");
    }
    global $clean_interval, $BASEURL, $btit_settings, $XBTT_USE, $db_prefix, $autopruneusers, $email_on_prune, $days_members, $days_not_comfirm, $days_to_email, $PRIVATE_ANNOUNCE, $TORRENTSDIR, $CURRENTPATH, $LIVESTATS, $LOG_HISTORY, $TABLE_PREFIX, $DOXPATH, $DBDT;
    $THIS_BASEPATH = dirname(__FILE__);
    $days = 14;
    $time = time() - $days * 86400;
    mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM {$TABLE_PREFIX}bugs WHERE status != 'na' AND added < {$time}") or sqlerr(__FILE__, __LINE__);
    //delete bots after 48 hours
    mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM {$TABLE_PREFIX}bots WHERE visit < (NOW() - INTERVAL 2880 MINUTE)");
    //end bots
    //delete last up/downloads after 48 hours
    mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM {$TABLE_PREFIX}downloads WHERE date < (NOW() - INTERVAL 2880 MINUTE)");
    //end last up/downloads
    //show images in shoutbox
    if ($btit_settings["endtch"] == TRUE) {
        $shout = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM {$TABLE_PREFIX}chat ORDER BY id DESC LIMIT 1");
        $shoutrow = mysqli_fetch_assoc($shout);
        $fp = $btit_settings["fix_chat"];
        if ($shoutrow["count"] >= $btit_settings["don_chat"]) {
            if ($btit_settings["ran_chat"] == TRUE) {
                do_sqlquery("INSERT INTO {$TABLE_PREFIX}chat (uid, time, name, text) VALUES (0," . time() . ", 'System','[img]{$BASEURL}/images/shouts/shout.php[/img]')");
            } else {
                do_sqlquery("INSERT INTO {$TABLE_PREFIX}chat (uid, time, name, text) VALUES (0," . time() . ", 'System','[img]{$BASEURL}/images/shouts/" . $fp . "[/img]')");
            }
        }
    }
    //show images in shoutbox end
    //happy hour
    $happy_r = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT UNIX_TIMESTAMP(value_s) AS happy , value_i AS happys from {$TABLE_PREFIX}avps where arg='happyhour'") or sqlerr(__FILE__, __LINE__);
    $happy_a = mysqli_fetch_array($happy_r);
    $curDate = time();
    $happyTime = $happy_a["happy"] + 3600;
    if ($happy_a["happys"] == 0) {
        $happyHour = happyHour();
        mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}avps set value_s=" . sqlesc($happyHour) . ", value_i='1' WHERE arg='happyhour' LIMIT 1 ") or sqlerr(__FILE__, __LINE__);
    } elseif ($happy_a["happys"] == 1 && $curDate > $happyTime) {
        mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}avps set value_i='0' WHERE arg='happyhour' LIMIT 1 ");
    }
    $switch = do_sqlquery("SELECT * FROM `{$TABLE_PREFIX}files` WHERE `external`='no'", true);
    $switch_happy = mysqli_fetch_array($switch);
    if ($switch_happy["happy_hour"] == "yes") {
        if (ishappyHour("check") && $happyTime > "0:00") {
            do_sqlquery("ALTER TABLE `{$TABLE_PREFIX}files` CHANGE `happy` `happy` ENUM( 'yes', 'no' ) NULL DEFAULT 'yes'") or sqlerr();
            do_sqlquery("UPDATE `{$TABLE_PREFIX}files` SET `happy`='yes' WHERE `external`='no'", true);
        } else {
            do_sqlquery("ALTER TABLE `{$TABLE_PREFIX}files` CHANGE `happy` `happy` ENUM( 'yes', 'no' ) NULL DEFAULT 'no'") or sqlerr();
            do_sqlquery("UPDATE `{$TABLE_PREFIX}files` SET `happy`='no' WHERE `external`='no'", true);
        }
    }
    // happy hour
    // featured
    if ($btit_settings["auto_feat"] == TRUE) {
        $feat = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT info_hash , leechers , image from {$TABLE_PREFIX}files where image!='' ORDER BY leechers DESC limit 1");
        $resfeat = mysqli_fetch_array($feat);
        do_sqlquery("INSERT INTO {$TABLE_PREFIX}featured (fid,torrent_id) VALUES ('','{$resfeat['info_hash']}')");
    }
    //featured
    //sb
    if ($XBTT_USE) {
        $ressb = do_sqlquery("SELECT uid FROM xbt_files_users as u INNER JOIN xbt_files as x ON u.fid=x.fid WHERE u.left = '0' AND x.flags='0' AND u.active='1'");
        if (mysqli_num_rows($ressb) > 0) {
            while ($arrsb = mysqli_fetch_assoc($ressb)) {
                $x = $arrsb["uid"];
                quickQuery("UPDATE `{$TABLE_PREFIX}users` SET `seedbonus`=`seedbonus`+'" . number_format(($ts > 0 ? time() - $ts : $clean_interval) / 3600 * $GLOBALS["bonus"], 6, ".", "") . "' WHERE `id` = '{$x}'");
            }
        }
    } else {
        $ressb = do_sqlquery("SELECT pid FROM {$TABLE_PREFIX}peers WHERE status = 'seeder'");
        if (mysqli_num_rows($ressb) > 0) {
            while ($arrsb = mysqli_fetch_assoc($ressb)) {
                $x = $arrsb['pid'];
                quickQuery("UPDATE `{$TABLE_PREFIX}users` SET `seedbonus`=`seedbonus`+'" . number_format(($ts > 0 ? time() - $ts : $clean_interval) / 3600 * $GLOBALS["bonus"], 6, ".", "") . "' WHERE `pid`= '{$x}'");
            }
        }
    }
    //sb
    //warn
    $query = do_sqlquery("SELECT * FROM `{$TABLE_PREFIX}users` WHERE warn='yes'");
    while ($conf = mysqli_fetch_assoc($query)) {
        if (mysqli_num_rows($query) > 0) {
            $expire_dat = $conf['warnadded'];
            $expire2 = strtotime($expire_dat);
            $nown = strtotime("now");
            if ($nown >= $expire2) {
                $subj = sqlesc("Your Warning time is expired !!");
                $msg = sqlesc("You are not longer Warned , please be carefull to not make the same mistake again !!");
                send_pm(0, $conf[id], $subj, $msg);
                mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET warn='no' WHERE id='{$conf['id']}'") or sqlerr();
            }
        }
    }
    //warn
    //remove boot after expiration
    require_once load_language("lang_userdetails.php");
    $datetime = gmdate("Y-m-d H:i:s");
    $bootedstats = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM {$TABLE_PREFIX}users WHERE addbooted < '{$datetime}' AND booted='yes'");
    while ($arr = mysqli_fetch_assoc($bootedstats)) {
        if (mysqli_num_rows($bootedstats) > 0) {
            $sub = sqlesc($language["BOOT_SUB"]);
            $mess = sqlesc($language["BOOT_MSG"]);
            send_pm(0, $arr[id], $sub, $mess);
            mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET booted='no' WHERE id='{$arr['id']}'") or sqlerr();
        }
    }
    //remove boot after expiration
    // DT request hack start
    $reqprune = $btit_settings["req_prune"];
    $request = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id FROM {$TABLE_PREFIX}requests WHERE filledby > '0' AND fulfilled < DATE_SUB(NOW(), INTERVAL {$reqprune} DAY)");
    $reqrow = mysqli_fetch_assoc($request);
    $reqid = $reqrow["id"];
    if (mysqli_num_rows($request) > 0) {
        mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM {$TABLE_PREFIX}requests WHERE filledby > 0 AND id = {$reqid}");
        mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM {$TABLE_PREFIX}addedrequests WHERE requestid = {$reqid}");
    }
    // DT request hack end
    if ($autopruneusers) {
        $timeout = $days_members * 60 * 60 * 24;
        $timeout2 = $days_not_comfirm * 60 * 60 * 24;
        if ($GLOBALS["FORUMLINK"] == "smf") {
            do_sqlquery("DELETE u,smfm FROM {$TABLE_PREFIX}users u INNER JOIN {$db_prefix}members smfm ON smfm.ID_MEMBER=u.smf_fid INNER JOIN {$TABLE_PREFIX}users_level ul ON ul.id=u.id_level WHERE (u.id_level = '2' AND UNIX_TIMESTAMP(u.lastconnect)<(UNIX_TIMESTAMP()-{$timeout2}) AND ul.auto_prune='yes') OR (UNIX_TIMESTAMP(lastconnect)<(UNIX_TIMESTAMP()-{$timeout}) AND ul.auto_prune='yes')");
        } else {
            do_sqlquery("DELETE u FROM {$TABLE_PREFIX}users u INNER JOIN {$TABLE_PREFIX}users_level ul ON ul.id=u.id_level WHERE (u.id_level = '2' AND UNIX_TIMESTAMP(u.lastconnect)<(UNIX_TIMESTAMP()-{$timeout2}) AND ul.auto_prune='yes') OR (UNIX_TIMESTAMP(lastconnect)<(UNIX_TIMESTAMP()-{$timeout}) AND ul.auto_prune='yes')");
        }
        if ($email_on_prune) {
            $timeout = $days_to_email * 60 * 60 * 24;
            $res = get_result("SELECT email, lastconnect FROM {$TABLE_PREFIX}users u INNER JOIN {$TABLE_PREFIX}users_level ul ON ul.id=u.id_level WHERE UNIX_TIMESTAMP()>=(UNIX_TIMESTAMP(lastconnect)+{$timeout}-{$clean_interval}/2) AND UNIX_TIMESTAMP()<(UNIX_TIMESTAMP(lastconnect)+{$timeout}+{$clean_interval}/2) AND UNIX_TIMESTAMP(lastconnect)<(UNIX_TIMESTAMP()-{$timeout}) AND ul.auto_prune='yes'", true);
            foreach ($res as $id => $rusers) {
                send_mail($rusers["email"], $language["EMAIL_INACTIVE_SUBJ"], $language["EMAIL_INACTIVE_MSG"] . "\n\n" . $BASEURL . "/index.php");
            }
        }
    }
    // Autoprune torrents
    if ($btit_settings["autotprune"] == TRUE) {
        quickQuery("UPDATE `{$TABLE_PREFIX}files` `f` " . ($XBTT_USE ? "LEFT JOIN `xbt_files` `xf` ON `f`.`bin_hash`=`xf`.`info_hash`" : "") . " SET `f`.`dead_time`=UNIX_TIMESTAMP() WHERE ((" . ($XBTT_USE ? "`xf`.`seeders`>0 OR `xf`.`leechers`>0" : "`f`.`seeds`>0 OR `f`.`leechers`>0") . ") OR `f`.`dead_time`=0) AND `f`.`external`='no'");
        $res = get_result("SELECT `info_hash`, `bin_hash` FROM `{$TABLE_PREFIX}files` WHERE `dead_time`<=" . (time() - $btit_settings["autotprundedays"] * 86400) . " AND `dead_time`!=0 AND `external`='no'");
        if (count($res) > 0) {
            foreach ($res as $row) {
                quickQuery("DELETE FROM `{$TABLE_PREFIX}files` WHERE `info_hash`='" . mysqli_real_escape_string($DBDT, $row["info_hash"]) . "'");
                quickQuery("DELETE FROM `{$TABLE_PREFIX}timestamps` WHERE `info_hash`='" . mysqli_real_escape_string($DBDT, $row["info_hash"]) . "'");
                quickQuery("DELETE FROM `{$TABLE_PREFIX}comments` WHERE `info_hash`='" . mysqli_real_escape_string($DBDT, $row["info_hash"]) . "'");
                quickQuery("DELETE FROM `{$TABLE_PREFIX}ratings` WHERE `infohash`='" . mysqli_real_escape_string($DBDT, $row["info_hash"]) . "'");
                quickQuery("DELETE FROM `{$TABLE_PREFIX}peers` WHERE `infohash`='" . mysqli_real_escape_string($DBDT, $row["info_hash"]) . "'");
                quickQuery("DELETE FROM `{$TABLE_PREFIX}history` WHERE `infohash`='" . mysqli_real_escape_string($DBDT, $row["info_hash"]) . "'");
                if ($XBTT_USE) {
                    quickQuery("UPDATE `xbt_files` SET `flags`=1 WHERE `info_hash`='" . mysqli_real_escape_string($DBDT, $row["bin_hash"]) . "'");
                }
            }
        }
    }
    // Autoprune torrents
    // timed registration
    $expire_datetr = $btit_settings["regi_d"];
    $expire_timetr = $btit_settings["regi_t"];
    $expire_datetrs = $expire_datetr . " " . $expire_timetr . ":00:00";
    $expiretr = strtotime($expire_datetrs);
    $nowtr = strtotime("now");
    if ($nowtr >= $expiretr) {
        do_sqlquery("UPDATE `{$TABLE_PREFIX}settings` SET `value`='true' WHERE `key`='regi'", true);
    }
    // end timed registration
    // Anti Hit and Run V2 based on CobraCRK's Anti Hit&Run Mod v1 Enhanced By IntelPentium4 & fatepower
    // converted ( and improved ) to XBTIT 2 by DiemThuy Nov 2008
    if (!$XBTT_USE) {
        // Get current time
        $timenow = time();
        // Get last time that dosanity() was run
        $timeres = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT last_time FROM {$TABLE_PREFIX}anti_hit_run_tasks WHERE task='sanity'");
        if (mysqli_num_rows($timeres) > 0) {
            $timearr = mysqli_fetch_array($timeres);
            $lastrecordedtime = intval($timearr['last_time']);
        } else {
            $lastrecordedtime = $timenow - $clean_interval;
        }
        // Update Active Seeders' Seeding Clock
        $res = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT pid, infohash FROM {$TABLE_PREFIX}peers WHERE status = 'seeder'");
        if (mysqli_num_rows($res) > 0) {
            while ($arr = mysqli_fetch_assoc($res)) {
                $x = $arr['pid'];
                $t = $arr['infohash'];
                $pl = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id FROM {$TABLE_PREFIX}users WHERE pid='" . $x . "'");
                if (mysqli_num_rows($pl) > 0) {
                    $ccc = mysqli_result($pl, 0, "id");
                } else {
                    $ccc = "Unknown";
                }
                mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}history SET seed = seed+" . $timenow . "-" . $lastrecordedtime . " WHERE uid = {$ccc} AND infohash='{$t}'");
            }
        }
        //Update table anti_hit_run_tasks with new time info.
        $hunden = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT last_time FROM {$TABLE_PREFIX}anti_hit_run_tasks WHERE task='sanity'");
        $manneplutt = mysqli_fetch_row($hunden);
        if (!$manneplutt) {
            mysqli_query($GLOBALS["___mysqli_ston"], "INSERT INTO {$TABLE_PREFIX}anti_hit_run_tasks (task, last_time) VALUES ('sanity',{$timenow})");
        } else {
            $ts = $manneplutt[0];
            mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}anti_hit_run_tasks SET last_time={$timenow} WHERE task='sanity' AND last_time = {$ts}");
        }
        // Rank who has no anti-hit punishment rule should be excluded
        $levels = mysqli_query($GLOBALS["___mysqli_ston"], "select id from {$TABLE_PREFIX}users_level order by id");
        while ($SingleLevel = mysqli_fetch_array($levels)) {
            $hasAntiHitRecord = mysqli_query($GLOBALS["___mysqli_ston"], "select id_level from {$TABLE_PREFIX}anti_hit_run where id_level=" . $SingleLevel["id"]);
            if (mysqli_num_rows($hasAntiHitRecord) == 0) {
                @mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `{$TABLE_PREFIX}history`,`users` set hitchecked= 2 where history.uid=users.id and users.id_level=" . $SingleLevel["id"] . " and completed='yes' and hitchecked='0'");
            }
        }
        $hit_parameters = mysqli_query($GLOBALS["___mysqli_ston"], "select * from {$TABLE_PREFIX}anti_hit_run order by id_level");
        while ($hit = mysqli_fetch_array($hit_parameters)) {
            // Punishment
            $r = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT DISTINCT uid,infohash FROM {$TABLE_PREFIX}history history inner join {$TABLE_PREFIX}users users on history.uid=users.id WHERE users.id_level=" . $hit["id_level"] . " AND active='no' AND completed='yes' AND hit='no' AND hitchecked= 0 AND date < ( UNIX_TIMESTAMP( ) - (86400 * " . $hit["tolerance_days_before_punishment"] . ")) AND history.downloaded>(1048576 * " . $hit["min_download_size"] . ") AND seed<( 3600 * " . $hit["min_seed_hours"] . ") AND (history.uploaded/history.downloaded)<" . $hit["min_ratio"]);
            while ($x = mysqli_fetch_array($r)) {
                @mysqli_query($GLOBALS["___mysqli_ston"], "Update {$TABLE_PREFIX}history SET hit='yes' WHERE uid=" . $x[uid] . " AND infohash='" . $x[infohash] . "' AND hitchecked=0");
                if (mysqli_affected_rows($GLOBALS["___mysqli_ston"]) > 0) {
                    if ($hit["reward"] == 'yes') {
                        $reward = "\n\n[color=red]If you want to get the lost amount back , you must seed for at least " . $hit["min_seed_hours"] . " hour(s) or until the file\\'s ratio becomes greater than " . $hit["min_ratio"] . " then your total upload will incremented by " . $hit["upload_punishment"] . " MB !! \n\n\\ [/color][color=purple]This is a automatic system message , so DO NOT reply ![/color]";
                    } else {
                        $reward = " ";
                    }
                    @mysqli_query($GLOBALS["___mysqli_ston"], "Update {$TABLE_PREFIX}history SET hitchecked= 1 ,punishment_amount=" . $hit["upload_punishment"] . " WHERE uid=" . $x[uid] . " AND infohash='" . $x[infohash] . "' AND hitchecked=0");
                    @mysqli_query($GLOBALS["___mysqli_ston"], "Update {$TABLE_PREFIX}users SET uploaded=(case when uploaded-(1048576 * " . $hit["upload_punishment"] . ")<0 then 0 else uploaded-(1048576 * " . $hit["upload_punishment"] . ") end) WHERE id={$x['uid']}");
                    send_pm(0, $x[uid], sqlesc("Auto Hit an Run warning"), sqlesc("You did Hit and Run on the following torrent :\n\n [url]" . $BASEURL . "/index.php?page=details&id={$x['infohash']}[/url] !\n\n\\We did take away " . $hit["upload_punishment"] . " MB as punishment\n\nBe carefull to not make the mistake once more ! " . $reward . ""));
                    // DT reputation system start
                    $reput = do_sqlquery("SELECT * FROM {$TABLE_PREFIX}reputation_settings WHERE id =1");
                    $setrep = mysqli_fetch_array($reput);
                    $plus = $setrep["rep_hit"];
                    if ($setrep["rep_is_online"] == FALSE) {
                        //do nothing
                    } else {
                        @mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET reputation = reputation - '{$plus}' WHERE id='{$x['uid']}'");
                    }
                    // DT reputation system end
                    // warn at hit and run
                    if ($hit["warn"] == 'yes') {
                        $id = (int) $x[uid];
                        $warnreason = "Auto Hit & Run Warning";
                        $warnaddedby = "System";
                        $added = warn_expiration(mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d') + addslashes($hit["days1"]), date('Y')));
                        quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET warn="yes",warns=warns+1,warnreason="' . $warnreason . '",warnaddedby="' . $warnaddedby . '",warnadded="' . $added . '" WHERE id=' . $id);
                    }
                    // end warn at hit and run
                    // boot at hit and run
                    if ($hit["boot"] == 'yes') {
                        $id = (int) $x[uid];
                        $whybooted = "Auto Hit & Run Ban";
                        $whobooted = "System";
                        $addbooted = booted_expiration(mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d') + addslashes($hit["days2"]), date('Y')));
                        quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET booted="yes", whybooted="' . $whybooted . '",whobooted="' . $whobooted . '",addbooted="' . $addbooted . '" WHERE id=' . $id);
                    }
                    // end boot at hit and run
                    //Dox Hack Start
                    $r = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id, filename, added FROM {$TABLE_PREFIX}dox WHERE added < '" . date('Y-m-d', strtotime('-' . $btit_settings["dox_del"] . ' weeks')) . "'");
                    while ($del = mysqli_fetch_array($r)) {
                        $MANNE = "{$BASEURL}/{$DOXPATH}";
                        @unlink("{$MANNE}/{$del['filename']}");
                        quickQuery("DELETE FROM {$TABLE_PREFIX}dox WHERE id={$del['id']}");
                    }
                    //Dox Hack End
                    // boot after warn at hit and run
                    if ($hit["warnboot"] == 'yes') {
                        $diem = do_sqlquery("SELECT warns FROM {$TABLE_PREFIX}users WHERE id={$x['uid']}");
                        $thuy = mysqli_fetch_array($diem);
                        if ($thuy["warns"] >= $hit["days3"]) {
                        }
                        $id = (int) $x[uid];
                        $whybooted = "Auto Hit & Run Ban after beeing warned";
                        $whobooted = "System";
                        $addbooted = booted_expiration(mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d') + addslashes($hit["days2"]), date('Y')));
                        quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET booted="yes", whybooted="' . $whybooted . '",whobooted="' . $whobooted . '",addbooted="' . $addbooted . '" WHERE id=' . $id);
                    }
                    // end boot after warn at hit and run
                }
            }
            mysqli_free_result($r) || is_object($r) && get_class($r) == "mysqli_result" ? true : false;
            // Reward
            if ($hit["reward"] == 'yes') {
                $rr = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT DISTINCT uid,infohash,punishment_amount FROM {$TABLE_PREFIX}history history inner join {$TABLE_PREFIX}users users on history.uid=users.id WHERE users.id_level=" . $hit["id_level"] . " AND hit='yes' AND completed='yes' AND hitchecked= 1 AND (seed>=( 3600 * " . $hit["min_seed_hours"] . ") or (history.uploaded/history.downloaded)>=" . $hit["min_ratio"] . ")");
                while ($xr = mysqli_fetch_array($rr)) {
                    @mysqli_query($GLOBALS["___mysqli_ston"], "Update {$TABLE_PREFIX}history SET hitchecked= 3 WHERE uid=" . $xr[uid] . " AND infohash='" . $xr[infohash] . "' AND hitchecked=1");
                    if (mysqli_affected_rows($GLOBALS["___mysqli_ston"]) > 0) {
                        @mysqli_query($GLOBALS["___mysqli_ston"], "Update {$TABLE_PREFIX}users SET uploaded=uploaded+(1048576 * " . $xr["punishment_amount"] . ")  WHERE id={$xr['uid']}");
                        send_pm(0, $xr[uid], sqlesc("Thanks (Punishement Removed)"), sqlesc("Thank you very much for seeding back the following torrent:\n\n [url]" . $BASEURL . "/index.php?page=details&id={$xr['infohash']}[/url] !\n\n [color=green]The punishment is now removed and you total upload amount increased by " . $xr["punishment_amount"] . " MB!  [/color]\n\n [color=purple]This is a automatic system message , so DO NOT reply ![/color]"));
                        // DT reputation system start
                        if ($setrep["rep_is_online"] == FALSE) {
                            //do nothing
                        } else {
                            @mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET reputation = reputation + '{$plus}' WHERE id='{$x['uid']}'");
                        }
                        // DT reputation system end
                        // warn at hit and run
                        if ($hit["warn"] == 'yes') {
                            quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET warn="no", warns=warns-1 WHERE id=' . $xr[uid]);
                        }
                        // end warn at hit and run
                        // boot at hit and run
                        if ($hit["boot"] == 'yes') {
                            quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET booted="no" WHERE id=' . $xr[uid]);
                        }
                        // end boot at hit and run
                    }
                }
                mysqli_free_result($rr) || is_object($rr) && get_class($rr) == "mysqli_result" ? true : false;
            }
            // Who are fine should not be punished
            @mysqli_query($GLOBALS["___mysqli_ston"], "Update {$TABLE_PREFIX}history,users SET hitchecked= 1 WHERE history.uid=users.id AND users.id_level = users.id_level=" . $hit["id_level"] . " AND completed='yes' AND date < ( UNIX_TIMESTAMP( ) - (86400 * " . $hit["tolerance_days_before_punishment"] . ")) AND hitchecked= 0");
        }
        mysqli_free_result($levels) || is_object($levels) && get_class($levels) == "mysqli_result" ? true : false;
        mysqli_free_result($hasAntiHitRecord) || is_object($hasAntiHitRecord) && get_class($hasAntiHitRecord) == "mysqli_result" ? true : false;
        mysqli_free_result($hit_parameters) || is_object($hit_parameters) && get_class($hit_parameters) == "mysqli_result" ? true : false;
    }
    // End of Anti Hit and Run
    //Invalid Login System Hack Start
    mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM {$TABLE_PREFIX}bannedip WHERE comment='max_number_of_invalid_logins_reached'");
    //invalid Login System Hack Stop
    //start freeleech
    $queryd = do_sqlquery("SELECT free_expire_date, free FROM `{$TABLE_PREFIX}files` WHERE `external`='no'", true);
    $configd = mysqli_fetch_array($queryd);
    $expire_dated = $configd['free_expire_date'];
    $expired = strtotime($expire_dated);
    $nowd = strtotime("now");
    if ($nowd >= $expired && $configd['free'] == 'yes') {
        do_sqlquery("UPDATE `{$TABLE_PREFIX}files` SET `free`='no',free_expire_date='0000-00-00 00:00:00' WHERE `external`='no'", true);
        do_sqlquery("ALTER TABLE `{$TABLE_PREFIX}files` CHANGE `free` `free` ENUM( 'yes', 'no' ) NULL DEFAULT 'no'", true);
        // xbtt
        if ($XBTT_USE) {
            do_sqlquery("UPDATE xbt_files SET down_multi=0, flags=2");
            do_sqlquery("ALTER TABLE xbt_files CHANGE `down_multi` `down_multi` INT NULL DEFAULT '0'", true);
        }
    }
    // end freeleech
    $query = do_sqlquery("SELECT * FROM `{$TABLE_PREFIX}lottery_config` WHERE `id`=1", true);
    $config = mysqli_fetch_array($query);
    $expire_date = $config['lot_expire_date'];
    $expire = strtotime($expire_date);
    $now = strtotime("now");
    if ($now >= $expire) {
        $number_winners = $config['lot_number_winners'];
        $number_to_win = $config['lot_number_to_win'];
        $minupload = $config['lot_amount'];
        $res = do_sqlquery("SELECT `id`, `user` FROM `{$TABLE_PREFIX}lottery_tickets` ORDER BY RAND(NOW()) LIMIT " . $number_winners . "", true);
        //select number of winners
        $total = mysqli_num_rows(do_sqlquery("SELECT * FROM `{$TABLE_PREFIX}lottery_tickets`", true));
        //select total selled tickets
        $pot = $total * $minupload;
        //selled tickets * ticket price
        $pot += $number_to_win;
        // ticket prize + minimum win
        $win = $pot / $number_winners;
        // prize for each winner
        $subject = sqlesc("You have won a prize with the lottery");
        //subject in pm
        $msg = sqlesc("Congratulations you have won a prize with our Lottery. Your prize has been added to your account. You won " . makesize($win) . "");
        //next 3 rows are the msg for PM
        $sender = $config['sender_id'];
        // Sender id, in my case 0
        //print the winners and send them PM en give them price
        while ($row = mysqli_fetch_array($res)) {
            $ras = do_sqlquery("SELECT `smf_fid`, `id`, `username` FROM `{$TABLE_PREFIX}users` WHERE `id`=" . $row['user'] . "", true);
            $raw = mysqli_fetch_array($ras);
            $rec = sqlesc("{$raw['id']}");
            $lotid = $raw["id"];
            $lotname = $raw["username"];
            do_sqlquery("UPDATE `{$TABLE_PREFIX}users` SET `uploaded`=uploaded+" . $win . " WHERE `id`=" . $row['user'] . "", true);
            $smf = mysqli_fetch_assoc(do_sqlquery("SELECT smf_fid, username FROM `{$TABLE_PREFIX}users` WHERE `id`=" . $row["user"] . "", true));
            send_pm($sender, $rec, $subject, $msg);
            // begin - announce winner in shoutbox
            do_sqlquery("INSERT INTO {$TABLE_PREFIX}chat (uid, time, name, text) VALUES (0," . time() . ", 'System','[color=red]Lottery winner : [/color][url={$BASEURL}/index.php?page=userdetails&id={$lotid}]" . $lotname . " did win " . makesize($win) . "[/url]')");
            // end - announce winner in shoutbox
            do_sqlquery("INSERT INTO `{$TABLE_PREFIX}lottery_winners` (`id`, `win_user`, `windate`, `price`) VALUES ('', '" . $raw['username'] . "', '" . $expire_date . "', '" . $win . "')");
        }
        do_sqlquery("TRUNCATE TABLE `{$TABLE_PREFIX}lottery_tickets`", true);
        do_sqlquery("UPDATE `{$TABLE_PREFIX}lottery_config` SET `lot_status`='closed' WHERE `id`=1", true);
    }
    // lottery auto start
    if ($btit_settings["autolot"] == TRUE) {
        $date_end = lastOfMonth();
        $klaar = $config["lot_status"];
        if ($klaar == 'closed') {
            $expire_date = $date_end;
            $expire_time = 23;
            $val1 = $expire_date . " " . $expire_time . ":59:59";
            $val2 = 1;
            $val3 = 15 * 1024 * 1024 * 1024;
            // Gb
            $val4 = 500 * 1024 * 1024;
            // Mb
            $val5 = 'yes';
            $val6 = 1;
            $val7 = 2;
            do_sqlquery("UPDATE `{$TABLE_PREFIX}lottery_config` SET `lot_expire_date`='" . $val1 . "', `lot_number_winners`='" . $val2 . "', `lot_number_to_win`='" . $val3 . "', `lot_amount`='" . $val4 . "', `lot_status`='" . $val5 . "', `limit_buy`='" . $val6 . "', `sender_id`=" . $val7 . " WHERE `id`=1", true);
        }
        // lottery end
    }
    // SANITY FOR TORRENTS
    $results = do_sqlquery("SELECT info_hash, seeds, leechers, dlbytes, filename FROM {$TABLE_PREFIX}files WHERE external='no'");
    $i = 0;
    while ($row = mysqli_fetch_row($results)) {
        list($hash, $seeders, $leechers, $bytes, $filename) = $row;
        $timeout = time() - intval($GLOBALS["report_interval"] * 2);
        // for testing purpose -- begin
        $resupd = do_sqlquery("SELECT * FROM {$TABLE_PREFIX}peers where lastupdate < " . $timeout . " AND infohash='{$hash}'");
        if (mysqli_num_rows($resupd) > 0) {
            while ($resupdate = mysqli_fetch_array($resupd)) {
                $uploaded = max(0, $resupdate["uploaded"]);
                $downloaded = max(0, $resupdate["downloaded"]);
                $pid = $resupdate["pid"];
                $ip = $resupdate["ip"];
                // update user->peer stats only if not livestat
                if (!$LIVESTATS) {
                    if ($PRIVATE_ANNOUNCE) {
                        quickQuery("UPDATE {$TABLE_PREFIX}users SET uploaded=uploaded+{$uploaded}, downloaded=downloaded+{$downloaded} WHERE pid='{$pid}' AND id>1 LIMIT 1");
                    } else {
                        // ip
                        quickQuery("UPDATE {$TABLE_PREFIX}users SET uploaded=uploaded+{$uploaded}, downloaded=downloaded+{$downloaded} WHERE cip='{$ip}' AND id>1 LIMIT 1");
                    }
                }
                // update dead peer to non active in history table
                if ($LOG_HISTORY) {
                    $resuser = do_sqlquery("SELECT id FROM {$TABLE_PREFIX}users WHERE " . ($PRIVATE_ANNOUNCE ? "pid='{$pid}'" : "cip='{$ip}'") . " ORDER BY lastconnect DESC LIMIT 1");
                    $curu = @mysqli_fetch_row($resuser);
                    quickquery("UPDATE {$TABLE_PREFIX}history SET active='no' WHERE uid={$curu['0']} AND infohash='{$hash}'");
                }
            }
        }
        // for testing purpose -- end
        quickQuery("DELETE FROM {$TABLE_PREFIX}peers where lastupdate < " . $timeout . " AND infohash='{$hash}'");
        quickQuery("UPDATE {$TABLE_PREFIX}files SET lastcycle='" . time() . "' WHERE info_hash='{$hash}'");
        $results2 = do_sqlquery("SELECT status, COUNT(status) from {$TABLE_PREFIX}peers WHERE infohash='{$hash}' GROUP BY status");
        $counts = array();
        while ($row = mysqli_fetch_row($results2)) {
            $counts[$row[0]] = 0 + $row[1];
        }
        quickQuery("UPDATE {$TABLE_PREFIX}files SET leechers=" . (isset($counts["leecher"]) ? $counts["leecher"] : 0) . ",seeds=" . (isset($counts["seeder"]) ? $counts["seeder"] : 0) . " WHERE info_hash=\"{$hash}\"");
        if ($bytes < 0) {
            quickQuery("UPDATE {$TABLE_PREFIX}files SET dlbytes=0 WHERE info_hash=\"{$hash}\"");
        }
    }
    //Auto Seedbox Start
    do_sqlquery("UPDATE {$TABLE_PREFIX}files SET `seedbox`='0' ");
    $sid = do_sqlquery("select * FROM {$TABLE_PREFIX}peers WHERE `ip` =" . $btit_settings["seedip"]);
    while ($sow = mysqli_fetch_array($sid)) {
        do_sqlquery("UPDATE {$TABLE_PREFIX}files SET `seedbox`='1' WHERE `info_hash`='{$sow['infohash']}'");
    }
    //Auto Seedbox End
    // END TORRENT'S SANITY
    //DT Uploader Medals
    global $btit_settings;
    do_sqlquery("UPDATE {$TABLE_PREFIX}users SET `up_med`='0' ");
    $time_B = 86400 * $btit_settings['UPD'];
    $time_E = strtotime(now);
    $time_D = $time_E - $time_B;
    $res = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT uploader,count( * ) AS Count FROM {$TABLE_PREFIX}files WHERE UNIX_TIMESTAMP(data) > " . $time_D . " GROUP by uploader");
    while ($fetch_U = mysqli_fetch_array($res)) {
        if ($fetch_U['Count'] >= $btit_settings['UPB'] and $fetch_U['Count'] < $btit_settings['UPS']) {
            do_sqlquery("UPDATE {$TABLE_PREFIX}users SET `up_med`='1' WHERE `id`='{$fetch_U['uploader']}'");
        }
        if ($fetch_U['Count'] >= $btit_settings['UPS'] and $fetch_U['Count'] < $btit_settings['UPG']) {
            do_sqlquery("UPDATE {$TABLE_PREFIX}users SET `up_med`='2' WHERE `id`='{$fetch_U['uploader']}'");
        }
        if ($fetch_U['Count'] >= $btit_settings['UPG']) {
            do_sqlquery("UPDATE {$TABLE_PREFIX}users SET `up_med`='3' WHERE `id`='{$fetch_U['uploader']}'");
        }
    }
    //DT end Uploader Medals
    // high speed report
    if ($btit_settings["highswitch"] == TRUE) {
        if ($GLOBALS["XBTT_USE"]) {
            $resch = do_sqlquery("SELECT `uid` `id`, `up_rate` FROM `xbt_files_users` WHERE `up_rate` >= (" . $btit_settings["highspeed"] . "*1024) AND `active`=1");
        } else {
            $resch = do_sqlquery("SELECT `p`.`upload_difference`, `p`.`announce_interval`, `u`.`id` FROM `{$TABLE_PREFIX}peers` `p` LEFT JOIN `{$TABLE_PREFIX}users` `u` ON " . ($PRIVATE_ANNOUNCE ? "`p`.`pid`=`u`.`pid`" : "`p`.`ip`=`u`.`cip`") . " WHERE (`p`.`upload_difference`/`p`.`announce_interval`) >= (" . $btit_settings["highspeed"] . "*1024)");
        }
        if (@mysqli_num_rows($resch) > 0) {
            while ($rowch = mysqli_fetch_assoc($resch)) {
                if (!is_null($rowch["id"])) {
                    if ($GLOBALS["XBTT_USE"]) {
                        $transferrate = "Upload speed " . round($rowch["up_rate"] / 1024, 2) . " KB/sec ?!";
                    } else {
                        $transferrate = "Upload speed " . round(round($rowch['upload_difference'] / $rowch['announce_interval']) / 1024, 2) . " KB/sec ?!";
                    }
                    $high = $rowch["id"];
                    if ($btit_settings["highonce"] == TRUE) {
                        $once = do_sqlquery("SELECT `id` FROM `{$TABLE_PREFIX}reports` WHERE `addedby` = 0 AND `votedfor` = {$high} AND `type` = 'user' AND reason LIKE 'Upload speed%'");
                        if (@mysqli_num_rows($once) === FALSE) {
                            do_sqlquery("INSERT INTO `{$TABLE_PREFIX}reports` (`addedby`,`votedfor`,`type`,`reason`) VALUES ('0','{$high}','user', '{$transferrate}')");
                        }
                    }
                    if ($btit_settings["highonce"] == FALSE) {
                        do_sqlquery("INSERT INTO `{$TABLE_PREFIX}reports` (`addedby`,`votedfor`,`type`,`reason`) VALUES ('0','{$high}','user', '{$transferrate}')");
                    }
                }
            }
        }
    }
    // end high speed report
    // DT reputation system start
    $reput = do_sqlquery("SELECT * FROM {$TABLE_PREFIX}reputation_settings WHERE id =1");
    $setrep = mysqli_fetch_array($reput);
    if ($setrep["rep_is_online"] == FALSE or $setrep["rep_en_sys"] == FALSE) {
        //do nothing
    } else {
        // demote
        $rep_sub = sqlesc("You are Demoted!");
        $rep_msg = sqlesc($setrep["rep_dm_text"]);
        $rep_demotelist = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id FROM {$TABLE_PREFIX}users WHERE reputation < " . $setrep["rep_dm"] . " AND id_level = " . $setrep["rep_pr_id"]);
        while ($rep_demote = mysqli_fetch_assoc($rep_demotelist)) {
            mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET id_level=" . $setrep["rep_dm_id"] . " WHERE id=" . $rep_demote["id"]);
            send_pm(0, $rep_demote[id], $rep_sub, $rep_msg);
        }
        // promote
        $rep_subj = sqlesc("You are Promoted!");
        $rep_mesg = sqlesc($setrep["rep_pm_text"]);
        $rep_promotelist = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id FROM {$TABLE_PREFIX}users WHERE reputation > " . $setrep["rep_pr"] . " AND id_level = " . $setrep["rep_dm_id"]);
        while ($rep_promote = mysqli_fetch_assoc($rep_promotelist)) {
            mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET id_level=" . $setrep["rep_pr_id"] . " WHERE id=" . $rep_promote["id"]);
            send_pm(0, $rep_promote[id], $rep_subj, $rep_mesg);
        }
    }
    // DT reputation system start
    // Client Log for XBT
    if ($GLOBALS["XBTT_USE"]) {
        $timeout = time() - intval($GLOBALS["report_interval"] * 2);
        quickQuery("DELETE FROM `xbt_announce_log` WHERE `mtime`<={$timeout}");
        $res = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT `u`.`id`, INET_NTOA(`al`.`ipa`) `ip`, `al`.`port`, LOWER(HEX(`al`.`peer_id`)) `peer_id`, `u`.`clientinfo` FROM `xbt_announce_log` `al` LEFT JOIN `{$TABLE_PREFIX}users` `u` ON `al`.`uid`=`u`.`id` WHERE `al`.`event`=2 GROUP BY `al`.`peer_id` ORDER BY `u`.`id` ASC");
        if (@mysqli_num_rows($res) > 0) {
            $old_clients = array();
            $current_clients = array();
            while ($row = mysqli_fetch_assoc($res)) {
                $client = getagent("", $row["peer_id"]);
                if (!empty($row["clientinfo"])) {
                    if (!array_key_exists($row["id"], $old_clients)) {
                        $old_clients[$row["id"]] = unserialize($row["clientinfo"]);
                    }
                    if (!array_key_exists($row["id"], $current_clients)) {
                        $current_clients[$row["id"]] = unserialize($row["clientinfo"]);
                    }
                } else {
                    if (!array_key_exists($row["id"], $old_clients)) {
                        $old_clients[$row["id"]] = array();
                    }
                    if (!array_key_exists($row["id"], $current_clients)) {
                        $current_clients[$row["id"]] = array();
                    }
                }
                if (!in_array($client . "[X]" . $row["port"], $current_clients[$row["id"]])) {
                    if (count($current_clients[$row["id"]]) == 20) {
                        unset($current_clients[$row["id"]][0]);
                        unset($current_clients[$row["id"]][1]);
                        $newlist = array();
                        foreach ($current_clients[$row["id"]] as $v) {
                            $newlist[] = $v;
                        }
                        $current_clients[$row["id"]] = $newlist;
                    }
                    $current_clients[$row["id"]][] = $client . "[X]" . $row["port"];
                    $current_clients[$row["id"]][] = time() . "[X]" . $row["ip"];
                }
            }
            foreach ($current_clients as $k => $v) {
                $s_old_clients = serialize($old_clients[$k]);
                $s_current_clients = serialize($current_clients[$k]);
                if ($s_old_clients != $s_current_clients) {
                    mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `{$TABLE_PREFIX}users` SET `clientinfo`='" . mysqli_real_escape_string($DBDT, $s_current_clients) . "' WHERE `id`={$k}");
                }
            }
        }
    }
    // Client Log for XBT
    // banbutton
    $timeout = $btit_settings["bandays"] * 86400;
    @mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM `{$TABLE_PREFIX}signup_ip_block` WHERE (UNIX_TIMESTAMP() - `added`) > {$timeout}");
    // end banbutton
    # global language, $clean_interval, $reload_cfg_interval;
    global $language, $clean_interval, $reload_cfg_interval;
    require dirname(__FILE__) . '/khez.php';
    quickQuery('OPTIMIZE TABLE `' . $TABLE_PREFIX . 'khez_configs`;');
    # hacks can start here ==Khez==
    // warn-ban system with acp by DT
    global $XBTT_USE;
    $resset = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM {$TABLE_PREFIX}low_ratio_ban_settings WHERE id ='1'");
    $art = mysqli_fetch_assoc($resset);
    $resban = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM {$TABLE_PREFIX}low_ratio_ban ");
    while ($ban = mysqli_fetch_assoc($resban)) {
        if ($art["wb_sys"] == TRUE) {
            if ($XBTT_USE) {
                $udownloaded = "u.downloaded+IFNULL(x.downloaded,0)";
                $uuploaded = "u.uploaded+IFNULL(x.uploaded,0)";
                $utables = "{$TABLE_PREFIX}users u LEFT JOIN xbt_users x ON x.uid=u.id";
            } else {
                $udownloaded = "u.downloaded";
                $uuploaded = "u.uploaded";
                $utables = "{$TABLE_PREFIX}users u";
            }
            $min_dl = $ban["wb_down"] * 1024 * 1024 * 1024;
            // find bad users 1
            $demotelist = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id FROM {$utables} WHERE {$udownloaded}  > " . $min_dl . " AND {$uuploaded}/{$udownloaded} <= " . $ban["wb_one"] . " AND id_level=" . $ban["wb_rank"] . " AND rat_warn_level = 0 ");
            while ($demote = mysqli_fetch_assoc($demotelist)) {
                // warn bad users 1
                do_sqlquery("UPDATE {$TABLE_PREFIX}users SET rat_warn_level = 1 , rat_warn_time = NOW() WHERE id=" . $demote["id"]);
                // DT reputation system start
                $reput = do_sqlquery("SELECT * FROM {$TABLE_PREFIX}reputation_settings WHERE id =1");
                $setrep = mysqli_fetch_array($reput);
                $plus = $setrep["rep_minrep"];
                if ($setrep["rep_is_online"] == FALSE) {
                    //do nothing
                } else {
                    @mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET reputation = reputation - '{$plus}' WHERE id='{$demote['id']}'");
                }
                // DT reputation system end
                // send pm bad users 1
                $sub = sqlesc("Low Ratio Warning!");
                $msg = sqlesc($art["wb_text_one"]);
                send_pm(0, $demote[id], $sub, $msg);
                // add warn symbol 1
                if ($ban["wb_warn"] == TRUE) {
                    $id = $demote["id"];
                    $warnreason = "Low Ratio Warning";
                    $warnaddedby = "System";
                    $added = warn_expiration(mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d') + addslashes($ban['wb_days_one']), date('Y')));
                    quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET warn="yes",warns=warns+1,warnreason="' . $warnreason . '",warnaddedby="' . $warnaddedby . '",warnadded="' . $added . '" WHERE id=' . $id);
                }
            }
            // time date stuff
            $time_AA = 86400 * $ban['wb_days_one'];
            $time_BB = strtotime(now);
            $time_CC = $time_BB - $time_AA;
            // find bad users 2
            $demotelistt = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id,rat_warn_time FROM {$utables} WHERE {$udownloaded}  > " . $min_dl . " AND {$uuploaded}/{$udownloaded} <= " . $ban["wb_two"] . " AND id_level=" . $ban["wb_rank"] . " AND rat_warn_level = 1 ");
            while ($demotee = mysqli_fetch_assoc($demotelistt)) {
                $time_DD = strtotime($demotee["rat_warn_time"]);
                if ($time_DD <= $time_CC) {
                    // warn bad users 2
                    do_sqlquery("UPDATE {$TABLE_PREFIX}users SET rat_warn_level = 2 , rat_warn_time = NOW() WHERE id=" . $demotee["id"]);
                    // DT reputation system start
                    $reput = do_sqlquery("SELECT * FROM {$TABLE_PREFIX}reputation_settings WHERE id =1");
                    $setrep = mysqli_fetch_array($reput);
                    $plus = $setrep["rep_minrep"];
                    if ($setrep["rep_is_online"] == FALSE) {
                        //do nothing
                    } else {
                        @mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET reputation = reputation - '{$plus}' WHERE id='{$demotee['id']}'");
                    }
                    // DT reputation system end
                    // send pm bad users 2
                    $sub = sqlesc("Low Ratio Warning Two!");
                    $msg = sqlesc($art["wb_text_two"]);
                    send_pm(0, $demotee[id], $sub, $msg);
                    // add warn symbol 2
                    if ($ban["wb_warn"] == TRUE) {
                        $warnreason = "Low Ratio Warning";
                        $warnaddedby = "System";
                        $added = warn_expiration(mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d') + addslashes($ban['wb_days_two']), date('Y')));
                        quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET warn="yes",warns=warns+1,warnreason="' . $warnreason . '",warnaddedby="' . $warnaddedby . '",warnadded="' . $added . '" WHERE id=' . $id);
                    }
                }
            }
            // unwarn user who did improve
            $unwarnone = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id,rat_warn_time FROM {$utables} WHERE {$udownloaded}  > " . $min_dl . " AND {$uuploaded}/{$udownloaded} > " . $ban["wb_one"] . " AND id_level=" . $ban["wb_rank"] . " AND rat_warn_level = 1 ");
            while ($unwarna = mysqli_fetch_assoc($unwarnone)) {
                $iid = $unwarna["id"];
                quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET rat_warn_level=rat_warn_level-1 WHERE id=' . $iid);
            }
            // time date stuff
            $time_EE = 86400 * $ban['wb_days_two'];
            $time_FF = $time_BB - $time_EE;
            // find bad users 3
            $demotelisttt = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id,rat_warn_time FROM {$utables} WHERE {$udownloaded}  > " . $min_dl . " AND {$uuploaded}/{$udownloaded} <= " . $ban["wb_three"] . " AND id_level=" . $ban["wb_rank"] . " AND rat_warn_level = 2 ");
            while ($demoteee = mysqli_fetch_assoc($demotelisttt)) {
                $time_GG = strtotime($demoteee["rat_warn_time"]);
                if ($time_GG <= $time_FF) {
                    // warn bad users 3
                    do_sqlquery("UPDATE {$TABLE_PREFIX}users SET rat_warn_level = 3 , rat_warn_time = NOW() WHERE id=" . $demoteee["id"]);
                    // DT reputation system start
                    $reput = do_sqlquery("SELECT * FROM {$TABLE_PREFIX}reputation_settings WHERE id =1");
                    $setrep = mysqli_fetch_array($reput);
                    $plus = $setrep["rep_minrep"];
                    if ($setrep["rep_is_online"] == FALSE) {
                        //do nothing
                    } else {
                        @mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET reputation = reputation - '{$plus}' WHERE id='{$demoteee['id']}'");
                    }
                    // DT reputation system end
                    // send pm bad users 3
                    $sub = sqlesc("Final Low Ratio Warning!");
                    $msg = sqlesc($art["wb_text_fin"]);
                    send_pm(0, $demoteee[id], $sub, $msg);
                    // add warn symbol 3
                    if ($ban["wb_warn"] == TRUE) {
                        $id = $demoteee["id"];
                        $warnreason = "Low Ratio Warning";
                        $warnaddedby = "System";
                        $added = warn_expiration(mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d') + addslashes($ban['wb_days_fin']), date('Y')));
                        quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET warn="yes",warns=warns+1,warnreason="' . $warnreason . '",warnaddedby="' . $warnaddedby . '",warnadded="' . $added . '" WHERE id=' . $id);
                    }
                }
            }
            // unwarn user who did improve 2
            $unwarntwo = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id,rat_warn_time FROM {$utables} WHERE {$udownloaded}  > " . $min_dl . " AND {$uuploaded}/{$udownloaded} > " . $ban["wb_two"] . " AND id_level=" . $ban["wb_rank"] . " AND rat_warn_level = 2 ");
            while ($unwarnb = mysqli_fetch_assoc($unwarntwo)) {
                $oid = $unwarnb["id"];
                quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET rat_warn_level=rat_warn_level-2 WHERE id=' . $oid);
            }
            // time date stuff
            $time_HH = 86400 * $ban['wb_days_fin'];
            $time_II = $time_BB - $time_HH;
            // find bad users 4
            $demotelistttt = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id,rat_warn_time FROM {$utables} WHERE {$udownloaded}  > " . $min_dl . " AND {$uuploaded}/{$udownloaded} <= " . $ban["wb_fin"] . " AND id_level=" . $ban["wb_rank"] . " AND rat_warn_level = 3 ");
            while ($demoteeee = mysqli_fetch_assoc($demotelistttt)) {
                $time_JJ = strtotime($demoteeee["rat_warn_time"]);
                if ($time_JJ <= $time_II) {
                    // ban bad users 4
                    if ($btit_settings["en_sys"] == TRUE) {
                        do_sqlquery("UPDATE {$TABLE_PREFIX}users SET rat_warn_level = 4 ,rat_warn_time = NOW(), id_level=" . $btit_settings["dm_id"] . " WHERE id=" . $demoteeee["id"]);
                    } else {
                        do_sqlquery("UPDATE {$TABLE_PREFIX}users SET rat_warn_level = 4 ,rat_warn_time = NOW(), bandt='yes' WHERE id=" . $demoteeee["id"]);
                    }
                }
            }
            // unwarn user who did improve last
            $unwarnthree = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id,rat_warn_time FROM {$utables} WHERE {$udownloaded}  > " . $min_dl . " AND {$uuploaded}/{$udownloaded} > " . $ban["wb_three"] . " AND id_level=" . $ban["wb_rank"] . " AND rat_warn_level = 3 ");
            while ($unwarnc = mysqli_fetch_assoc($unwarnthree)) {
                $lid = $unwarnc["id"];
                quickQuery('UPDATE ' . $TABLE_PREFIX . 'users SET rat_warn_level=rat_warn_level-3 WHERE id=' . $lid);
            }
        }
    }
    // warn-ban system with acp end
    //  optimize peers table
    quickQuery("OPTIMIZE TABLE {$TABLE_PREFIX}peers");
    // delete readposts when topic don't exist or deleted  *** should be done by delete, just in case
    quickQuery("DELETE readposts FROM {$TABLE_PREFIX}readposts LEFT JOIN topics ON readposts.topicid = topics.id WHERE topics.id IS NULL");
    // delete readposts when users was deleted *** should be done by delete, just in case
    quickQuery("DELETE readposts FROM {$TABLE_PREFIX}readposts LEFT JOIN users ON readposts.userid = users.id WHERE users.id IS NULL");
    // deleting orphan image in captcha folder (if image code is enabled)
    $CAPTCHA_FOLDER = realpath("{$CURRENTPATH}/../{$CAPTCHA_FOLDER}");
    if ($dir = @opendir($CAPTCHA_FOLDER . "/")) {
        while (false !== ($file = @readdir($dir))) {
            if ($ext = substr(strrchr($file, "."), 1) == "png") {
                unlink("{$CAPTCHA_FOLDER}/{$file}");
            }
        }
        @closedir($dir);
    }
    quickQuery("UPDATE `{$TABLE_PREFIX}users` SET `birthday_bonus`=0 WHERE DAYOFMONTH(`dob`)!=" . date('j'));
    $res = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT `u`.`id`, `u`.`dob`,`l`.`language_url` FROM `{$TABLE_PREFIX}users` `u` LEFT JOIN `language` `l` ON `u`.`language`=`l`.`id` WHERE DAYOFMONTH(`u`.`dob`)=" . date('j') . " AND MONTH(`u`.`dob`)=" . date('n') . " AND `u`.`dob`!=CURDATE() AND `u`.`birthday_bonus`=0 ORDER BY `l`.`language_url` ASC");
    if (@mysqli_num_rows($res) > 0) {
        global $THIS_BASEPATH;
        $firstrun = 1;
        $englang = "language/english";
        $templang = $englang;
        require_once $THIS_BASEPATH . "/" . $englang . "/lang_main.php";
        while ($row = mysqli_fetch_assoc($res)) {
            if ($row["language_url"] != $templang) {
                if ($firstrun != 1) {
                    // Reset the language to English before loading the new language
                    require_once $THIS_BASEPATH . "/" . $englang . "/lang_main.php";
                }
                // Load the new language etc.
                require_once $THIS_BASEPATH . "/" . $row["language_url"] . "/lang_main.php";
                $templang = $row["language_url"];
                $firstrun = 0;
            }
            $dob = explode("-", $row["dob"]);
            $age = userage($dob[0], $dob[1], $dob[2]);
            $bonus = round($age * $btit_settings["birthday_bonus"] * 1073741824);
            $query1 = "UPDATE `{$TABLE_PREFIX}users` SET `uploaded`=`uploaded`+{$bonus}, `birthday_bonus`=1 WHERE `id`=" . $row["id"];
            quickQuery($query1);
            send_pm(0, $row["id"], addslashes($language["HB_SUBJECT"]), addslashes($language["HB_MESSAGE_1"] . makesize($bonus) . $language["HB_MESSAGE_2"] . $btit_settings["birthday_bonus"] . $language["HB_MESSAGE_3"]));
        }
    }
    //timed rank
    $datetimedt = date("Y-m-d H:i:s");
    $rankstats = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM {$TABLE_PREFIX}users WHERE timed_rank < '{$datetimedt}' AND rank_switch='yes'");
    while ($arrdt = mysqli_fetch_assoc($rankstats)) {
        if (mysqli_num_rows($rankstats) > 0) {
            $res6 = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT level FROM {$TABLE_PREFIX}users_level WHERE id ='{$arrdt['old_rank']}'");
            $arr6 = mysqli_fetch_assoc($res6);
            $oldrank = $arr6[level];
            $subj = sqlesc("Your timed rank is expired !");
            $msg = sqlesc("Your timed rank is expired !\n\n Your rank did changed back to " . $oldrank . "\n\n [color=red]This is a automatic system message , so DO NOT reply ![/color]");
            send_pm(0, $arrdt["id"], $subj, $msg);
            mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET rank_switch='no', id_level = old_rank WHERE id='{$arrdt['id']}'") or sqlerr();
        }
    }
    //timed rank end
    //begin invitation system by dodge
    global $INV_EXPIRES;
    $deadtime = $INV_EXPIRES * 86400;
    $user = do_sqlquery("SELECT inviter FROM {$TABLE_PREFIX}invitations WHERE time_invited < DATE_SUB(NOW(), INTERVAL {$deadtime} SECOND)");
    @($arr = mysqli_fetch_assoc($user));
    if (mysqli_num_rows($user) > 0) {
        mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE {$TABLE_PREFIX}users SET invitations=invitations+1 WHERE id = '" . $arr["inviter"] . "'");
        mysqli_query($GLOBALS["___mysqli_ston"], "DELETE FROM {$TABLE_PREFIX}invitations WHERE inviter = '" . $arr["inviter"] . "' AND time_invited < DATE_SUB(NOW(), INTERVAL {$deadtime} SECOND)");
    }
    //end invitation system
    do_updateranks();
    // auto ext update
    $num_torrents_to_update = 5;
    $torrents = get_result("SELECT `announces`, `info_hash` FROM `{$TABLE_PREFIX}files` WHERE `external`='yes' ORDER BY `lastupdate` DESC LIMIT " . $num_torrents_to_update);
    if (count($torrents) > 0) {
        require_once "getscrape.php";
        for ($i = 0; $i < count($torrents); $i++) {
            $announces = @unserialize($torrents[$i]['announces']) ? unserialize($torrents[$i]['announces']) : array();
            if (count($announces) > 0) {
                $keys = array_keys($announces);
                $random = mt_rand(0, count($keys) - 1);
                $url = $keys[$random];
                scrape($url, $torrents[$i]['info_hash']);
            }
        }
    }
    // auto ext update
    // OK We're finished, let's reset max_execution_time and memory_limit back to the php.ini defaults
    @ini_restore("max_execution_time");
    @ini_restore("memory_limit");
}
예제 #16
0
파일: peers.php 프로젝트: fchypzero/cybyd
     $peers[$i]["FLAG"] = "<img src=\"images/flag/" . $row["flagpic"] . "\" alt=\"" . unesc($row["name"]) . "\" />";
 } elseif ($rowuser["flagpic"] != "" && !empty($rowuser["flagpic"])) {
     $peers[$i]["FLAG"] = "<img src=\"images/flag/" . $rowuser["flagpic"] . "\" alt=\"" . unesc($rowuser["name"]) . "\" />";
 } else {
     $peers[$i]["FLAG"] = "<img src=\"images/flag/unknown.gif\" alt=\"" . $language["UNKNOWN"] . "\" />";
 }
 if (!$XBTT_USE) {
     $peers[$i]["PORT"] = $row["port"];
 }
 $stat = floor(($tsize - $row["bytes"]) / $tsize * 100);
 $progress = "<table width=\"100\" cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"progress\" align=\"left\">";
 $progress .= "<img height=\"10\" width=\"" . number_format($stat, 0) . "\" src=\"{$STYLEURL}/images/progress.jpg\" alt=\"\" /></td></tr></table>";
 $peers[$i]["PROGRESS"] = $stat . "%<br />" . $progress;
 $peers[$i]["STATUS"] = $row["status"];
 if (!$XBTT_USE) {
     $peers[$i]["CLIENT"] = htmlspecialchars(getagent(unesc($row["client"]), unesc($row["peer_id"])));
 }
 $dled = makesize($row["downloaded"]);
 $upld = makesize($row["uploaded"]);
 $peers[$i]["DOWNLOADED"] = $dled;
 $peers[$i]["UPLOADED"] = $upld;
 //Peer Ratio
 if (intval($row["downloaded"]) > 0) {
     $ratio = number_format($row["uploaded"] / $row["downloaded"], 2);
 } else {
     $ratio = '&#8734;';
 }
 $peers[$i]["RATIO"] = $ratio;
 //End Peer Ratio
 $peers[$i]["SEEN"] = get_elapsed_time($row["lastupdate"]) . " ago";
 $i++;
예제 #17
0
파일: details.php 프로젝트: klldll/tbdev
function dltable($name, $arr, $torrent)
{
    global $tracker_lang;
    $s = "<b>" . count($arr) . " {$name}</b>\n";
    if (!count($arr)) {
        return $s;
    }
    $s .= "\n";
    $s .= "<table width=\"100%\" class=\"main\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n";
    $s .= "<tr><td class=colhead>{$tracker_lang['user']}</td>" . "<td class=colhead align=center>{$tracker_lang['port_open']}</td>" . "<td class=colhead align=right>{$tracker_lang['uploaded']}</td>" . "<td class=colhead align=right>{$tracker_lang['ul_speed']}</td>" . "<td class=colhead align=right>{$tracker_lang['downloaded']}</td>" . "<td class=colhead align=right>{$tracker_lang['dl_speed']}</td>" . "<td class=colhead align=right>{$tracker_lang['ratio']}</td>" . "<td class=colhead align=right>{$tracker_lang['completed']}</td>" . "<td class=colhead align=right>{$tracker_lang['connected']}</td>" . "<td class=colhead align=right>{$tracker_lang['idle']}</td>" . "<td class=colhead align=left>{$tracker_lang['client']}</td></tr>\n";
    $now = time();
    //$moderator = (isset($CURUSER) && get_user_class() >= UC_MODERATOR); // Redundant
    $mod = get_user_class() >= UC_MODERATOR;
    foreach ($arr as $e) {
        // user/ip/port
        // check if anyone has this ip
        $s .= "<tr>\n";
        if ($e["username"]) {
            $s .= "<td><a href=\"userdetails.php?id={$e['userid']}\"><b>" . get_user_class_color($e["class"], $e["username"]) . "</b></a>" . ($mod ? "&nbsp;[<span title=\"{$e["ip"]}\" style=\"cursor: pointer\">IP</span>]" : "") . "</td>\n";
        } else {
            $s .= "<td>" . ($mod ? $e["ip"] : preg_replace('/\\.\\d+$/', ".xxx", $e["ip"])) . "</td>\n";
        }
        $secs = max(10, $e["la"] - $e["pa"]);
        $s .= "<td align=\"center\">" . ($e['connectable'] == "yes" ? "<span style=\"color: green; cursor: help;\" title=\"{$tracker_lang['peertable_port_open']}\">{$tracker_lang['yes']}</span>" : "<span style=\"color: red; cursor: help;\" title=\"{$tracker_lang['peertable_port_closed']}\">{$tracker_lang['no']}</span>") . "</td>\n";
        $s .= "<td align=\"right\"><nobr>" . mksize($e["uploaded"]) . "</nobr></td>\n";
        $s .= "<td align=\"right\"><nobr>" . mksize($e["uploadoffset"] / $secs) . "/s</nobr></td>\n";
        $s .= "<td align=\"right\"><nobr>" . mksize($e["downloaded"]) . "</nobr></td>\n";
        //if ($e["seeder"] == "no")
        $s .= "<td align=\"right\"><nobr>" . mksize($e["downloadoffset"] / $secs) . "/s</nobr></td>\n";
        /*else
        		$s .= "<td align=\"right\"><nobr>" . mksize($e["downloadoffset"] / max(1, $e["finishedat"] - $e["st"])) . "/s</nobr></td>\n";*/
        if ($e["downloaded"]) {
            $ratio = floor($e["uploaded"] / $e["downloaded"] * 1000) / 1000;
            $s .= "<td align=\"right\"><font color=" . get_ratio_color($ratio) . ">" . number_format($ratio, 3) . "</font></td>\n";
        } else {
            if ($e["uploaded"]) {
                $s .= "<td align=\"right\">Inf.</td>\n";
            } else {
                $s .= "<td align=\"right\">---</td>\n";
            }
        }
        $s .= "<td align=\"right\">" . sprintf("%.2f%%", 100 * (1 - $e["to_go"] / $torrent["size"])) . "</td>\n";
        $s .= "<td align=\"right\">" . mkprettytime($now - $e["st"]) . "</td>\n";
        $s .= "<td align=\"right\">" . mkprettytime($now - $e["la"]) . "</td>\n";
        $s .= "<td align=\"left\">" . htmlspecialchars_uni(getagent($e["agent"], $e["peer_id"])) . "</td>\n";
        $s .= "</tr>\n";
    }
    $s .= "</table>\n";
    return $s;
}