Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Free Torrent Source (http://www.bvlist.com/forumdisplay.php?f=25)
-   -   problem announce.php (http://www.bvlist.com/showthread.php?t=9612)

unomas 29th October 2013 08:23

problem announce.php
 
upgrade server and php 5.3, announce.php is bad error urgently help

PHP Code:

<?php
include ('include/bittorrent_announce.php');
require_once (
'include/benc.php');
function 
err$msg )
{
    
benc_resp( array('failure reason' => array(type => 'string'value => $msg)) ) ;
    exit() ;
}
function 
benc_resp$d )
{
    
benc_resp_rawbenc(array(type => 'dictionary'value => $d)) ) ;
}
function 
benc_resp_raw$x )
{

    
header"Content-Type: text/plain" ) ;
    
header"Pragma: no-cache" ) ;

    if ( 
$_SERVER["HTTP_ACCEPT_ENCODING"] == "gzip" )
    {
        
header"Content-Encoding: gzip" ) ;
        echo 
gzencode$x9FORCE_GZIP ) ;
    }
    else
        echo 
$x ;
}
foreach (array(
"passkey""info_hash""peer_id""event""ip""localip") as $x) {
    if (isset(
$_GET["$x"]))
        
$GLOBALS[$x] = "" $_GET[$x];
}
foreach (array(
"port""downloaded""uploaded""left") as $x) {
    
$GLOBALS[$x] = $_GET[$x];
}

if (
strpos($passkey"?")) {
    
$tmp substr($passkeystrpos($passkey"?"));
    
$passkey substr($passkey0strpos($passkey"?"));
    
$tmpname substr($tmp1strpos($tmp"=") - 1);
    
$tmpvalue substr($tmpstrpos($tmp"=") + 1);
    
$GLOBALS[$tmpname] = $tmpvalue;

}

foreach (array(
"passkey""info_hash""peer_id""port""downloaded",
    
"uploaded""left") as $x)
    if (!isset(
$x))
        
err("Missing key: $x");
foreach (array(
"info_hash""peer_id") as $x)
    if (
strlen($GLOBALS[$x]) != 20)
        
err("Invalido $x (" strlen($GLOBALS[$x]) . " - " urlencode($GLOBALS[$x]) .
            
")");
if (
strlen($passkey) != 32)
    
err("Invalido passkey (" strlen($passkey) . " - $passkey)");
$ip ip::getip();
$rsize 50;

foreach (array(
"num want""numwant""num_want") as $k) {
    if (isset(
$_GET[$k])) {
        
$rsize $_GET[$k];
        break;
    }
}

// BLOCK ACCESS WITH WEB BROWSERS AND CHEATS!

$agent $_SERVER["HTTP_USER_AGENT"];
if (
ereg("^Mozilla\/"$agent) || ereg("^Opera\/"$agent) || ereg("^Links "$agent) ||
    
ereg("^Lynx\/"$agent))
    
err("torrent no registrados en el tracker");

if (!
$port || $port 0xffff)
    
err("puerto invalido");

if (!isset(
$event))
    
$event "";

$seeder = ($left == 0) ? "yes" "no";

$valid = @mysql_query("SELECT COUNT(*) FROM users WHERE passkey=" sqlesc($passkey)) or
    
err(mysql_error());
$valid = @mysql_fetch_row($valid);

if (
$valid[0] != 1)
    
err("Invalido passkey! Vuelva a descargar el archivo Torrent de $BASEURL");

$res mysql_query("SELECT id, name, category, banned, free, silver, doubleupload, seeders + leechers AS numpeers, UNIX_TIMESTAMP(added) AS ts FROM torrents WHERE " .
    
hash_where("info_hash"$info_hash));

$torrent mysql_fetch_assoc($res);

if (!
$torrent)
    
err("torrent no registrados en el tracker");

$torrentid $torrent["id"];
$torrentname $torrent["name"];
$torrentcategory $torrent["category"];
$fields "seeder, peer_id, ip, port, uploaded, downloaded, userid, last_action,  UNIX_TIMESTAMP(NOW()) AS nowts, UNIX_TIMESTAMP(prev_action) AS prevts, (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_action)) AS announcetime";
$numpeers $torrent["numpeers"];
$limit "";
if (
$numpeers $rsize)
    
$limit "ORDER BY RAND() LIMIT $rsize";
$res mysql_query("SELECT $fields FROM peers WHERE torrent = $torrentid");
    global 
$announce_interval;
    
$resp "d" benc_str("interval") . "i" $announce_interval "e" benc_str("peers") . "l";
unset(
$self);
while (
$row mysql_fetch_assoc($res)) {
    
$row["peer_id"] = hash_pad($row["peer_id"]);

    if (
$row["peer_id"] === $peer_id) {
        
$userid $row["userid"];
        
$self $row;
        continue;
    }
    
$a = @mysql_query("SELECT class FROM users WHERE id = '$userid'");
    
$a = @mysql_fetch_assoc($a);
    
$b = @mysql_query("SELECT hasfreeleech FROM usergroups WHERE id = $a[class]");
    
$b = @mysql_fetch_assoc($b);
    
$hasfreeleech $b['hasfreeleech'];
    
$userclass $a['class'];


    
$resp .= "d" benc_str("ip") . benc_str($row["ip"]) . benc_str("peer id") .
        
benc_str($row["peer_id"]) . benc_str("port") . "i" $row["port"] . "e" "e";
}

$resp .= "ee";
$selfwhere "torrent = $torrentid AND " hash_where("peer_id"$peer_id);

if (!isset(
$self)) {
    
$res mysql_query("SELECT $fields FROM peers WHERE $selfwhere");
    
$row mysql_fetch_assoc($res);
    if (
$row) {
        
$userid $row["userid"];
        
$self $row;
    }
}

///////////// Comentado para que funcione  con php-CGI ////////////////////////////////
/*
if (function_exists('getallheaders'))
    $headers = getallheaders();
else
    $headers = emu_getallheaders();
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($headers["Cookie"]) || isset($headers["Accept-Language"]) || isset($headers["Accept-Charset"]))
    
err("Anti-Cheater=     Usted no puede utilizar este agente");


$announce_wait 900;
if (isset(
$self) && ($self['prevts'] > ($self['nowts'] - $announce_wait)))
    
err('Existe un mínimo de tiempo para anunciar al tracker y es 15 minutos');

if (!isset(
$self)) {
    
$valid = @mysql_fetch_row(@mysql_query("SELECT COUNT(*) FROM peers WHERE torrent=$torrentid AND passkey=" .
        
sqlesc($passkey)));
    if (
$valid[0] >= && $seeder == 'no')
        
err("Límite de conexiones se ha superado Para Este torrent! Usted no puede descargar por un tiempo prudente.");
    if (
$valid[0] >= && $seeder == 'yes')
        
err("Límite de conexiones se ha superado!");

    
$rz mysql_query("SELECT id, uploaded, downloaded, class, parked FROM users WHERE passkey=" .
        
sqlesc($passkey) . " AND enabled = 'yes' ORDER BY last_access DESC LIMIT 1") or
        
err("Tracker error 2");
    if (
$MEMBERSONLY == "yes" && mysql_num_rows($rz) == 0)
        
err("Passkey Desconocido. Vuelva a descargar el archivo Torrent de $BASEURL. a");

    
$az mysql_fetch_assoc($rz);
    
$userid $az["id"];

    if (
$az["class"] == UC_VIP) {
    
mysql_query("UPDATE snatched SET  statusvip  = 'yes' WHERE torrent = '$torrentid' AND finished = 'yes' AND userid = '$userid' AND  statusvip ='no'") or err("Tracker error status vip"); 
    }

    if (
$az["class"] == UC_USER) {
        if (
$waitsystem == "yes") {
            
$gigs $az["uploaded"] / (1024 1024 1024);
            
$elapsed floor((gmtime() - $torrent["ts"]) / 3600);
            
$ratio = (($az["downloaded"] > 0) ? ($az["uploaded"] / $az["downloaded"]) : 1);
            if (
$ratio 0.5 || $gigs 5)
                
$wait 24;
            elseif (
$ratio 0.65 || $gigs 6.5)
                
$wait 12;
            elseif (
$ratio 0.8 || $gigs 8)
                
$wait 6;
            elseif (
$ratio 0.95 || $gigs 9.5)
                
$wait 1;
            else
                
$wait 0;
            if (
$elapsed $wait)
                
err("No Estas autorizado debes Esperar (" . ($wait $elapsed) . "h) - LEE EL FAQ!");
        }
  if (
$az["class"] < UC_VIP)
         {
        if (
$maxdlsystem == "yes") {
            if (
$az["class"] == UC_NEWUSER)
                
$max 2;
             elseif (
$az["class"] == UC_USER)
                
$max 2;
            elseif (
$az["class"] == UC_POWER_USER)
                
$max 4;
            elseif (
$az["class"] == UC_ELITE_USER)
                
$max 8;
            elseif (
$az["class"] == UC_LOVER)
                
$max 16;
            elseif (
$az["class"] == UC_ADICTO)
                
$max 32;
            else
                
$max 0;
            if (
$max 0) {
                
$res mysql_query("SELECT COUNT(*) AS num FROM peers WHERE userid='$userid' AND seeder='no'") or
                    
err("Tracker error 5");
                
$row mysql_fetch_assoc($res);
                if (
$row['num'] >= $max)
                    
err("No Estas autorizado (Estás descargando el número máximo de torrents permitidos - $max)");
            }
        }
       }
    }
} else {
////////////////////////////DENEGACION SEEDBOX POR 3////////////////////////////////
$sqlc mysql_query("SELECT snatched.torrent, snatched.userid as userid, snatched.uploaded as uploaded, snatched.downloaded as downloaded, snatched.finished as finished, torrents.owner as owner, users.class as class FROM snatched LEFT JOIN users ON snatched.userid = users.id LEFT JOIN torrents ON torrents.id = snatched.torrentid WHERE torrent = $torrentid AND userid = $userid");
$upseed mysql_fetch_array($sqlc);
$cuota '1073741824';
$dwseed $upseed['downloaded'] * 2;

if (
$upseed['downloaded'] >= $cuota and $upseed['owner'] != $userid and $upseed['finished'] = yes)
    if (
$upseed['uploaded'] >=  $dwseed and $upseed['class'] < UC_VIP and $upseed['finished'] = yes)
        
err("Tienes Seedbox o Serv. Dedicado, No Puedes Subir Más de 2 Veces la Cantidad de Gigas Descargados. Por Favor Valla a $BASEURL/rules.php Para obtener mas Informacion");
    
if (
$upseed["class"] == UC_VIP) {
    
mysql_query("UPDATE snatched SET  statusvip  = 'yes' WHERE torrent = '$torrentid' AND finished = 'yes' AND userid = '$userid' AND  statusvip ='no'") or err("Tracker error status vip"); 
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

    
$upthis max(0$uploaded $self["uploaded"]);
    
$upspeed = ($upthis $upthis $self["announcetime"] : 0);
    
$downspeed = ($downthis $downthis $self["announcetime"] : 0);
    
$announcetime = ($self["seeder"] == "yes" "seedtime = seedtime + $self[announcetime]"leechtime = leechtime + $self[announcetime]");
    if (
$hasfreeleech == 'no')
        
$downthis max(0$downloaded $self["downloaded"]);
    else
        
$downthis 0;

    if (
$torrent['free'] == 'yes')
        
$downthis 0;

    if (
$torrent['doubleupload'] == 'yes')
        
$upthis *= 2;

    if(
$torrent['silver']=='yes')
        
$downthis $downthis/2;
      
    if (
$upthis || $downthis 0)
        
mysql_query("UPDATE users SET uploaded = uploaded + $upthis, downloaded = downloaded + $downthis WHERE id=$userid") or
            
err("Tracker error 3");
}

$uagent $_SERVER['HTTP_USER_AGENT'];
$bua mysql_query("SELECT agent FROM banned_agent") or err('Tracker error (1)');
while (
$nea mysql_fetch_array($bua)) {
    
$n $nea['agent'];
    
$nr preg_replace("/\//""\/"$n);
    
$neadle "/\b$nr\b/i";
    if (
preg_match($neadle$uagent))
        
err("Cliente Prohibido o Baneado, Por Favor Actualize a la Ultima Version y valla a $BASEURL/rules.php  Para Obtener La Lista de Clientes Permitidos");
}
if (
ereg("^BitTorrent\/S-"$agent))
    
err("Shadow's Experimental Cliente Prohibido. Por favor use uTorrent.");
if (
ereg("^ABC\/ABC"$agent))
    
err("ABC Cliente Prohibido. Por favor use uTorrent.");
if (
ereg("^Python-urllib\/2.4"$agent))
    
err("Cliente Prohibido. Por favor use uTorrent.");

#getoutofmysite($peer_id);
$dt gmtime() - 180;
$dt sqlesc(get_date_time($dt));

$updateset = array();

if (
$event == "stopped") {
    if (isset(
$self)) {
        
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", port = $port, uploaded = uploaded + $upthis, downloaded = downloaded + $downthis, to_go = $left, upspeed = $upspeed, downspeed = $downspeed$announcetime, last_action = '".get_date_time()."', seeder = 'no', connectable='no'', agent = ".sqlesc($agent)." WHERE torrentid = $torrentid AND userid = $userid") or err("SL Err 1");

        
mysql_query("DELETE FROM peers WHERE $selfwhere");
        if (
mysql_affected_rows()) {
            if (
$self["seeder"] == "yes")
                
$updateset[] = "seeders = seeders - 1";
            else
                
$updateset[] = "leechers = leechers - 1";
        }
    }
} else {
    if (
$event == "completed") {
        
mysql_query("UPDATE torrent_hit SET  completed  = 'yes' WHERE id = $torrentid AND uid = $userid");
        
mysql_query("UPDATE snatched SET  finished  = 'yes', completedat = $dt WHERE torrent = $torrentid AND userid = $userid");
        
$updateset[] = "times_completed = times_completed + 1";

    }

    if (isset(
$self)) {
        
$res mysql_query("SELECT uploaded, downloaded FROM snatched WHERE torrent = $torrentid AND userid = $userid");
        
$row mysql_fetch_array($res);
        
$sockres = @pfsockopen($ip$port$errno$errstr5);
        if (!
$sockres)
            
$connectable "yes";
        else {
            
$connectable "yes";
            @
fclose($sockres);
        }
        
$downloaded2 $downloaded $self["downloaded"];
        
$uploaded2 $uploaded $self["uploaded"];
        
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", uploaded = uploaded+$uploaded2, downloaded = downloaded+$downloaded2, port = $port, connectable = '$connectable', agent= " sqlesc($agent) . ", to_go = $left, upspeed = $upspeed, downspeed = $downspeed$announcetime, last_action = $dt, seeder = '$seeder' WHERE torrent = $torrentid AND userid = $userid");
        
$prev_action sqlesc($self['last_action']);

       
mysql_query("UPDATE peers SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', uploaded = $uploaded, downloaded = $downloaded, to_go = $left, last_action = NOW(), prev_action = $prev_action, seeder = '$seeder'" .
            (
$seeder == "yes" && $self["seeder"] != $seeder ", agent = ".sqlesc($agent).", finishedat = " time() :"") . " WHERE $selfwhere");
        if (
mysql_affected_rows() && $self["seeder"] != $seeder) {
            if (
$seeder == "yes") {
                
$updateset[] = "seeders = seeders + 1";
                
$updateset[] = "leechers = leechers - 1";
            } else {
                
$updateset[] = "seeders = seeders - 1";
                
$updateset[] = "leechers = leechers + 1";
            }
        }
    } else {
        if (
$az["parked"] == "yes")
            
err("Error, su cuenta está parked!");

      
#  if (portblacklisted($port))
       #     err("Port $port está en la lista negra.");
        
else {
            
$sockres = @pfsockopen($ip$port$errno$errstr5);
            if (!
$sockres) {
                
$connectable "yes";
                if (
$nc == "yes")
                    
err("ERROR - Su cliente no se puede conectar! Verifique su configuración - puerto o consulte a un administartor o buscar en los foros.");
            } else {
                
$connectable "yes";
                @
fclose($sockres);
            }
        }

        
$res mysql_query("SELECT torrent, userid FROM snatched WHERE torrent = $torrentid AND userid = $userid");
        
$check mysql_fetch_assoc($res);
        if (!
$check)
            
mysql_query("INSERT INTO snatched (torrent, torrentid, userid, peer_id, ip, port, uploaded, downloaded, to_go, startdat, last_action, seeder, agent, torrent_name, torrent_category) VALUES ($torrentid$torrentid$userid, ".sqlesc($peer_id).", ".sqlesc($ip).", $port$uploaded$downloaded$left$dt$dt, '$seeder', " sqlesc($agent) . ", " sqlesc($torrentname) . ", $torrentcategory)");
                   
        
$ret mysql_query("INSERT INTO peers (connectable, torrent, peer_id, ip, port, uploaded, downloaded, to_go, started, last_action, seeder, userid, agent, uploadoffset, downloadoffset, passkey) VALUES ('$connectable', $torrentid, " .
            
sqlesc($peer_id) . ", " sqlesc($ip) . ", $port$uploaded$downloaded$left, NOW(), NOW(), '$seeder', $userid, " sqlesc($agent) . ", $uploaded$downloaded, " sqlesc($passkey) . ")");
        if (
$ret) {
            if (
$seeder == "yes")
                
$updateset[] = "seeders = seeders + 1";
            else
                
$updateset[] = "leechers = leechers + 1";
        }
    }
}

if (
$seeder == "yes") {
    if (
$torrent["banned"] != "yes")
        
$updateset[] = "visible = 'yes'";
    
$updateset[] = "last_action = NOW()";
}

if (
count($updateset))
    
mysql_query("UPDATE torrents SET " join(","$updateset) . " WHERE id = $torrentid");

$select_client mysql_query("SELECT * FROM clientselect WHERE name='" $agent .
    
"'");
if (
mysql_num_rows($select_client) == 0) {
    
$insert = @mysql_query("INSERT INTO clientselect (name) VALUES ('" $agent .
        
"')");
    
$client_id mysql_insert_id();
} else {
    
$client_row = @mysql_fetch_array($select_client);
    
$client_id $client_row['id'];
}

$agent_user_add = @mysql_query("UPDATE users SET clientselect='" $client_id .
    
"' where id='" $userid "'");
benc_resp_raw($resp);


if(!
function_exists("getallheaders")) {
    function 
emu_getallheaders() {
   foreach(
$_SERVER as $name => $value)
       if(
substr($name05) == 'HTTP_')
           
$headers[substr($name5)] = $value;
   return 
$headers;
}
}
?>



All times are GMT +2. The time now is 17:10.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.