Welcome to Geeklog, Anonymous Sunday, December 22 2024 @ 08:56 am EST

Geeklog Forums

Bitorrent tracker using static pages


Status: offline

exdeath

Forum User
Junior
Registered: 02/13/04
Posts: 23
OK, i got a hold of PHPBTTracker and i've instaled on a diferent database. The tracker runs on PHP and mysql and its managed trough diferent pages: newtorrents (adds a new torrent), deleter(deletes torrent), and mystats (displays the status of the tracker. I'm thinking of using the code from this different pages on status pages so that i can control the tracker trough my site. I'm a newb when it comes to php, but i've been reading some documentation about php and the use of php on static pages. So, here is the code for the 3 pages:
newtorrents:
Text Formatted Code
<HTML><HEAD><TITLE>Add Torrents</title></head>
<BODY BGCOLOR="#000000" TEXT="#ffffff">
<CENTER>
<?php

//// Configuration

// function_exists("sha1") or die('<FONT COLOR="red">SHA1 function not available. You need PHP 4.3.0 or better.</font></body></html>');



require_once ("config.php");
require_once ("funcsv2.php");
require_once ("BDecode.php");
require_once ("BEncode.php");
if (isset($_POST["username"]))
{
        $hash = strtolower($_POST["hash"]);

        $db = mysql_connect($dbhost, $_POST["username"], $_POST["password"]) or die("<FONT COLOR="red">Couldn't connect to database. Incorrect username/password?</font>");
        mysql_select_db($database) or die("Can't open the database.");


        if (isset($_FILES["torrent"]))
        {
           if ($_FILES["torrent"]["error"] != 4)       
           {
                $fd = fopen($_FILES["torrent"]["tmp_name"], "rb") or die("File upload error 1n");
                is_uploaded_file($_FILES["torrent"]["tmp_name"]) or die("File upload error 2n");
                $alltorrent = fread($fd, filesize($_FILES["torrent"]["tmp_name"]));
       
                $array = BDecode($alltorrent);
                if (!isset($array))
                {
                        echo "<FONT COLOR="red">There was an error handling your uploaded torrent. The parser didn't like it.</font>";
                        endOutput();
                        exit;
                }
                if (!$array)
                {
                        echo "<FONT COLOR="red">There was an error handling your uploaded torrent. The parser didn't like it.</font>";
                        endOutput();
                        exit;
                }
                $hash = sha1(BEncode($array["info"]));
                fclose($fd);


                unlink($_FILES["torrent"]["tmp_name"]);
           }
        }

        if (isset($_POST["filename"]))
                $filename=$_POST["filename"];
        else
                $filename = "";
       
        if (isset($_POST["url"]))
                $url = $_POST["url"];
        else
                $url = "";

        if (isset($_POST["info"]))
                $info = $_POST["info"];
        else
                $info = "";

        if (isset($_POST["autoset"]))
        if (strcmp($_POST["autoset"], "enabled") == 0)
        {
                if (strlen($filename) == 0 && isset($array["info"]["name"]))
                        $filename = $array["info"]["name"];
                if (strlen($info) == 0 && isset($array["info"]["piece length"]))
                {
                        $info = $array["info"]["piece length"] / 1024 * (strlen($array["info"]["pieces"]) / 20) /1024;
                        $info = round($info, 2) . " MB";
                        if (isset($array["comment"]))
                                $info .= " - ".$array["comment"];
                }
        }
       
        $filename = mysql_escape_string($filename);
        $url = mysql_escape_string($url);
        $info = mysql_escape_string($info);

        if ((strlen($hash) != 40) || !verifyHash($hash))
        {
                echo("<FONT COLOR="red">Error: Info hash must be exactly 40 hex bytes.</font>");
                endOutput();
        }

        $query = "INSERT INTO namemap (info_hash, filename, url, info) VALUES ("$hash", "$filename", "$url", "$info")";
        $status = makeTorrent($hash, true);
        quickQuery($query);
        if ($status)
                echo "Torrent was added successfully.<BR><BR><BR><BR><BR>";
        else
                echo "There were some errors. Check if this torrent had been added previously.<BR><BR><BR><BR><BR>";

}
else
        echo "Specify information to proceed. <br>Information fields (except URL) can be loaded from the<br>torrent automatically using the checkbox below..<BR><BR><BR>";


endOutput();


function endOutput()
{
?>
</center>
<FORM ENCTYPE="multipart/form-data" METHOD="POST">
<TABLE ALIGN="center">
<TR><TD>Database Username:</td><TD><INPUT TYPE=text NAME="username" SIZE=20></td></tr>
<TR><TD>Database Password:</td><TD><INPUT TYPE=password NAME="password" SIZE=20></td></tr>
<TR><TD>Torrent file:</td><TD><?php

if (function_exists("sha1"))
        echo '<INPUT TYPE="file" NAME="torrent">';
else
        echo '<I>File uploading not available - no SHA1 function.</i>';

?></td></tr>
<TR><TD>Info Hash:</td><TD><INPUT TYPE=text NAME="hash" SIZE=40></td></tr>
<TR><TD>File name (optional): </td><TD><INPUT TYPE=text name="filename" size=50 maxlength=200></td></tr>
<TR><TD>Torrent's URL (optional): </td><TD><INPUT TYPE=text name="url" size=50 maxlength=200></td></tr>
<TR><TD>Short description(optional): </td><TD><INPUT TYPE=text name="info" size=50 maxlength=200></td></tr>
<?php if (function_exists("sha1")) echo '<TR><TD ALIGN=CENTER COLSPAN=2><INPUT TYPE="checkbox" NAME="autoset" VALUE="enabled" CHECKED> Fill in fields using data from the torrent file.</td></tr>'; ?>
<TR><TD ALIGN=RIGHT><INPUT TYPE=submit VALUE="Create"></td><TD ALIGN=LEFT><INPUT TYPE=reset VALUE="Clear settings"></td></tr>
</table>
</body></html>
<?php exit; }
?>
 


Deleter
Text Formatted Code
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Torrent deletion script</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"></head>
<BODY BGCOLOR="#6060c0" TEXT="#ffffff" LINK="#ffffff" VLINK="#ffffff">
<H1>Login</h1>
<FORM METHOD=POST>
Username: <INPUT TYPE="text" NAME="username"><BR>
Password: <INPUT TYPE="password" NAME="password"><BR>
<BR>

<?php

require_once("config.php");
require_once("funcsv2.php");

// Gotta login first.
if (isset($_POST["username"]) && isset($_POST["password"]))
{

        $db = mysql_connect($dbhost, $_POST["username"], $_POST["password"]) or die("Cannot connect to database. Check your username and password.");
        mysql_select_db($database) or die("Error selecting database.");

        foreach ($_POST as $left => $right)
        {
                if (strlen($left) == 41 && $left[0] == 'x')
                {
                        if (!stristr($right,'y'))
                                continue;
                        $hash = substr($left, 1);
                        @mysql_query("DELETE FROM summary WHERE info_hash="$hash"");
                        @mysql_query("DELETE FROM namemap WHERE info_hash="$hash"");
                        @mysql_query("DELETE FROM namemap WHERE hash="$hash"");
                        @mysql_query("DROP TABLE x$hash");
                }

        }


}
else
{
        $db = mysql_pconnect($dbhost, $dbuser, $dbpass) or die("Tracker error: can't connect to database - ".mysql_error());
        mysql_select_db($database) or die("Tracker error: can't open database $database - ".mysql_error());
        $GLOBALS["maydelete"] = false;
}



?>
<H1>Torrents</h1>
<TABLE BORDER=0 CELLPADDING="5" CELLSPACING="1" BGCOLOR="#000000" WIDTH="100%"><TR><TD BGCOLOR="#202090">Name/Info Hash</td><TD BGCOLOR="#202090">Seeders</td><TD BGCOLOR="#202090">Leechers</td><TD BGCOLOR="#202090">Completed D/Ls</td><TD BGCOLOR="#202090">Bytes Transfered</td><TD BGCOLOR="#202090">Delete?</td></tr><TR><TD COLSPAN=6 BGCOLOR="#6060c0"></td></tr>
<?php


$values[0] = 'BGCOLOR="#6060a0"';
$values[1] = 'BGCOLOR="#505090"';

$results = mysql_query("SELECT summary.info_hash, summary.seeds, summary.leechers, format(summary.finished,0), format(summary.dlbytes/1073741824,3),namemap.filename FROM summary LEFT JOIN namemap ON summary.info_hash = namemap.info_hash ORDER BY namemap.filename")
or die(mysql_error());

$i=0;
while ($data = mysql_fetch_row($results))
{
        $writeout = $values[$i % 2];
        $hash = $data[0];
        if (is_null($data[5]))
                $data[5] = $data[0];
        if (strlen($data[5]) == 0)
                $data[5] = $data[0];
               
        echo "<TR>n";
        echo "t<TD $writeout>".$data[5]."</td>n";
        for ($j=1; $j < 4; $j++)
                echo "t<TD $writeout ALIGN="center">$data[$j]</td>n";
        echo "t<TD $writeout>$data[4] GiB</td>n";
       
        echo "t<TD $writeout><INPUT TYPE=checkbox NAME="x$hash" VALUE="y"></td>n";
        echo "</tr>n";
        $i++;
}

?>
</table>
Warning: there is no confirmation for deleting files. Clicking this button is final.<BR>
<INPUT TYPE="submit" VALUE="Apply"></form>
</body></html>
 


and mystats
Text Formatted Code
<?php

/*

Although I consider this whole tracker to be GPL code, I EXPECT you to
modify the script. If nothing else, you should re-theme it, maybe add links
to your own site... Whatever.

This script is yours to tinker with.

*/


$scriptname = $_SERVER["PHP_SELF"];


?>
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>PHPBT Tracker Statistics</title>
<META NAME="Author" CONTENT="DeHackEd">
<!-- I usually idle in the official BitTorrent tech support/development IRC channel -->
</head>
<BODY BGCOLOR="#ffffff" TEXT="#333333" LINK="#333333" VLINK="#333333">
<FONT FACE="Arial" SIZE="6">PHPBTTracker Statistics</font>
<BR>
<BR>
<TABLE BORDER=0>
<TR>
<?php if (!isset($_GET["activeonly"])) echo "<TD><FONT FACE="Arial" SIZE="3"><A HREF="$scriptname?activeonly=yes">Show only active torrents</a></font></td>"; if (!isset($_GET["seededonly"])) echo "<TD ALIGN=RIGHT><FONT FACE="Arial" SIZE="3"><A HREF="$scriptname?seededonly=yes">Show only seeded torrents</a></font></td>" ?>
</tr>
<TR>
<TD ALIGN=RIGHT COLSPAN=2>
<TABLE border="0" cellpadding="5" cellspacing="1" bgcolor="#000000" WIDTH="100%">

<!-- Column Headers -->
<TR><TD BGCOLOR="#999999">Name/Info Hash</td><TD BGCOLOR="#999999">Seeders</td>
<TD BGCOLOR="#999999">Leechers</td><TD BGCOLOR="#999999">Completed D/Ls</td><TD BGCOLOR="#999999">Bytes
Transfered</td><TD BGCOLOR="#999999">Speed</td></tr>
<TR>
        <TD COLSPAN=6 BGCOLOR="#ffffff"></td>
</tr>

<?php

function doCrash($msg)
{
        echo "</TABLE></table><FONT COLOR='red' SIZE='+2'>Script error: $msg</font></body></html>";
        exit(1);
}

$values[0] = 'BGCOLOR="#ffffff"';
$values[1] =  'BGCOLOR="#dddddd"';

require_once ("config.php");
require_once ("funcsv2.php");

if ($GLOBALS["persist"])
        $db = mysql_pconnect($dbhost, $dbuser, $dbpass) or doCrash("Tracker error: can't connect to database - ".mysql_error());
else
        $db = mysql_connect($dbhost, $dbuser, $dbpass) or doCrash("Tracker error: can't connect to database - ".mysql_error());
mysql_select_db($database) or doCrash("Tracker error: can't open database $database - ".mysql_error());

/* Rewrite, part 1: encode "WHERE" statement only. */

if (isset($_GET["seededonly"]))
        $where = " WHERE seeds > 0";
else if (isset($_GET["activeonly"]))
        $where = " WHERE leechers+seeds > 0";
else
        $where = " ";

$query = "SELECT summary.info_hash, summary.seeds, summary.leechers, format(summary.finished,0), format(summary.dlbytes/1073741824,3),namemap.filename, namemap.url, namemap.info, summary.speed FROM summary LEFT JOIN namemap ON summary.info_hash = namemap.info_hash $where ORDER BY namemap.filename";
$results = mysql_query($query) or doCrash("Can't do SQL query - ".mysql_error());
$i = 0;

while ($data=mysql_fetch_row($results))
{
        // NULLs are such a pain at times. isset($nullvar) == false
        if (is_null($data[5]))
                $data[5] = $data[0];
        if (is_null($data[6]))
                $data[6] = "";
        if (is_null($data[7]))
                $data[7]="";
        if (strlen($data[5]) == 0)
                $data[5]=$data[0];
        $myhash = $data[0];
        echo "<TR>n";
        $writeout = $values[$i % 2];
        echo "t<TD $writeout>";
        if (strlen($data[6]) > 0)
                echo "<A HREF="${data[6]}">${data[5]}</a>";
        else
                echo $data[5];
        if (strlen($data[7]) > 0)
                echo " (${data[7]})";

        for ($j=1; $j < 4; $j++)
                echo "t<TD $writeout ALIGN="center">$data[$j]</td>n";
        echo "t<TD $writeout>$data[4] GiB</td>n";

        // The SPEED column calcultions.
        if ($data[8] < 0)
                $speed = "Zero";
        else if ($data[8] > 2097152)
                $speed = round($data[8]/1048576,2) . " MB/sec";
        else
                $speed = round($data[8] / 1024, 2) . " KB/sec";

        echo "t<TD $writeout>$speed</td>n";


        echo "</tr>n";
        $i++;
}

if ($i == 0)
        echo "<TR><TD $values[0] COLSPAN=6 ALIGN=CENTER>No data</td></tr>";

?>
</table></td></tr>
<TR><TD ALIGN=LEFT><FONT FACE="Arial" SIZE="1">PHP Tracker using MySQL.
</font></td><TD ALIGN=RIGHT><FONT FACE="Arial" SIZE="1">Ki = 1024, Mi = 1024 Ki, Gi = 1024 Mi</font></td></tr></table>
<BR><BR><FONT FACE="Arial" SIZE="6">Notes</font>
<?php
if ($GLOBALS["NAT"])
        echo "<UL><LI><FONT FACE="Arial" SIZE="4">This tracker does NAT checking when users connect. If you receive a probe to port 6881, it's probably just me.</li></ul>";
else
        echo '<UL><LI><FONT FACE="Arial" SIZE="4">NAT checking has been disabled on this
tracker.</li></ul>';
?>
</body></html>
 

So far i've cut all the "?>" and "$echotext = "Hello"; $echotext .= " World"; $echotext .= "!"; return $echotext; [/code] as it was said in another post.
Anyway this is what i got so far on mystats
Text Formatted Code
$scriptname = $_SERVER["PHP_SELF"];

$echotext ="<TABLE BORDER=0>
<TR>"
if (!isset($_GET["activeonly"])) $echotext .= "<TD><FONT FACE="Arial" SIZE="3"><A HREF="$scriptname?activeonly=yes">Show only active torrents</a></font></td>"; if (!isset($_GET["seededonly"])) $echotext .="<TD ALIGN=RIGHT><FONT FACE="Arial" SIZE="3"><A HREF="$scriptname?seededonly=yes">Show only seeded torrents</a></font></td>"
$echotext .="</tr>
<TR>
<TD ALIGN=RIGHT COLSPAN=2>
<TABLE border="0" cellpadding="5" cellspacing="1" bgcolor="#000000" WIDTH="100%">

<!-- Column Headers -->
<TR><TD BGCOLOR="#999999">Name/Info Hash</td><TD BGCOLOR="#999999">Seeders</td>
<TD BGCOLOR="#999999">Leechers</td><TD BGCOLOR="#999999">Completed D/Ls</td><TD BGCOLOR="#999999">Bytes
Transfered</td><TD BGCOLOR="#999999">Speed</td></tr>
<TR>
        <TD COLSPAN=6 BGCOLOR="#ffffff"></td>
</tr>"

function doCrash($msg)
{
        $echotext .="</table></table><FONT COLOR='red' SIZE='+2'>Script error: $msg</font></body></html>";
        exit(1);
}

$values[0] = 'BGCOLOR="#ffffff"';
$values[1] =  'BGCOLOR="#dddddd"';

require_once ("/path to tracker/config.php");
require_once ("/path to tracker/funcsv2.php");

if ($GLOBALS["persist"])
        $db = mysql_pconnect($dbhost, $dbuser, $dbpass) or doCrash("Tracker error: can't connect to database - ".mysql_error());
else
        $db = mysql_connect($dbhost, $dbuser, $dbpass) or doCrash("Tracker error: can't connect to database - ".mysql_error());
mysql_select_db($database) or doCrash("Tracker error: can't open database $database - ".mysql_error());

/* Rewrite, part 1: encode "WHERE" statement only. */

if (isset($_GET["seededonly"]))
        $where = " WHERE seeds > 0";
else if (isset($_GET["activeonly"]))
        $where = " WHERE leechers+seeds > 0";
else
        $where = " ";

$query = "SELECT summary.info_hash, summary.seeds, summary.leechers, format(summary.finished,0), format(summary.dlbytes/1073741824,3),namemap.filename, namemap.url, namemap.info, summary.speed FROM summary LEFT JOIN namemap ON summary.info_hash = namemap.info_hash $where ORDER BY namemap.filename";
$results = mysql_query($query) or doCrash("Can't do SQL query - ".mysql_error());
$i = 0;

while ($data=mysql_fetch_row($results))
{
        // NULLs are such a pain at times. isset($nullvar) == false
        if (is_null($data[5]))
                $data[5] = $data[0];
        if (is_null($data[6]))
                $data[6] = "";
        if (is_null($data[7]))
                $data[7]="";
        if (strlen($data[5]) == 0)
                $data[5]=$data[0];
        $myhash = $data[0];
        $echotext .= "<TR>n";
        $writeout = $values[$i % 2];
        $echotext .="t<TD $writeout>";
        if (strlen($data[6]) > 0)
                $echotext .="<A HREF="${data[6]}">${data[5]}</a>";
        else
                $echotext .="$data[5]";
        if (strlen($data[7]) > 0)
                $echotext .=" (${data[7]})";

        for ($j=1; $j < 4; $j++)
                $echotext .="t<TD $writeout ALIGN="center">$data[$j]</td>n";
        echo "t<TD $writeout>$data[4] GiB</td>n";

        // The SPEED column calcultions.
        if ($data[8] < 0)
                $speed = "Zero";
        else if ($data[8] > 2097152)
                $speed = round($data[8]/1048576,2) . " MB/seg";
        else
                $speed = round($data[8] / 1024, 2) . " KB/seg";

        $echotext .="t<TD $writeout>$speed</td>n";


        $echotext .="</tr>n";
        $i++;
}

if ($i == 0)
        $echotext .="<TR><TD $values[0] COLSPAN=6 ALIGN=CENTER>No data</td></tr>";
return $echotext;


 
I got an error on line 5 :
I'm assuming if i return html tags the page should be properly formated, right?
And i've also read about the limitations of static pages when it comes to php programs. Can code like this be used on the staticpages?
Thanks for your help
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Well, it's hard to tell what line 5 is and you didn't quote the error message either ... But from a quick glimpse, I'd say this code should work.

bye, Dirk
 Quote

Status: offline

exdeath

Forum User
Junior
Registered: 02/13/04
Posts: 23
The error is:
Parse error: parse error in path_to_public_html/staticpages/index.php(78) : eval()'d code

Line 5:
Text Formatted Code
if (!isset($_GET["activeonly"])) $echotext .= "<TD><FONT FACE="Arial" SIZE="3"><A HREF="$scriptname?activeonly=yes">Show only active torrents</a></font></td>"; if (!isset($_GET["seededonly"])) $echotext .="<TD ALIGN=RIGHT><FONT FACE="Arial" SIZE="3"><A HREF="$scriptname?seededonly=yes">Show only seeded torrents</a></font></td>"
 
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
$echotext .= "...

I believe the problem is there. You are using doublequotes to open the block of text, but then are not escaping the following doublequotes. Try escaping the inner quotes with backslashes.
 Quote

Status: offline

exdeath

Forum User
Junior
Registered: 02/13/04
Posts: 23
I don't follow, would you be so kind to exemplefy?
 Quote

Status: offline

exdeath

Forum User
Junior
Registered: 02/13/04
Posts: 23
Did it!
Code for Mystats:
Text Formatted Code
$scriptname = $_SERVER["PHP_SELF"];

$echotext ='<TR><TD BGCOLOR="#999999">Name/Info Hash</TD><TD BGCOLOR="#999999">Seeders</TD>
<TD BGCOLOR="#999999">Leechers</TD><TD BGCOLOR="#999999">Completed D/Ls</TD><TD BGCOLOR="#999999">Bytes
Transfered</TD><TD BGCOLOR="#999999">Speed</TD></TR>';
$echotext .='<TR><TD COLSPAN=6 BGCOLOR="#ffffff"></TD></TR>';

function doCrash($msg)
{
        $echotext .="</TABLE></TABLE><FONT COLOR='red' SIZE='+2'>Script error: $msg</FONT></BODY></HTML>";
        exit(1);
}

$values[0] = 'BGCOLOR="#ffffff"';
$values[1] =  'BGCOLOR="#dddddd"';

require_once ("path to/public_html//tracker/config.php");
require_once ("path to/public_html/tracker/funcsv2.php");

if ($GLOBALS["persist"])
        $db = mysql_pconnect($dbhost, $dbuser, $dbpass) or doCrash("Tracker error: can't connect to database - ".mysql_error());
else
        $db = mysql_connect($dbhost, $dbuser, $dbpass) or doCrash("Tracker error: can't connect to database - ".mysql_error());
mysql_select_db($database) or doCrash("Tracker error: can't open database $database - ".mysql_error());

/* Rewrite, part 1: encode "WHERE" statement only. */

if (isset($_GET["seededonly"]))
        $where = " WHERE seeds > 0";
else if (isset($_GET["activeonly"]))
        $where = " WHERE leechers+seeds > 0";
else
        $where = " ";

$query = "SELECT summary.info_hash, summary.seeds, summary.leechers, format(summary.finished,0), format(summary.dlbytes/1073741824,3),namemap.filename, namemap.url, namemap.info, summary.speed FROM summary LEFT JOIN namemap ON summary.info_hash = namemap.info_hash $where ORDER BY namemap.filename";
$results = mysql_query($query) or doCrash("Can't do SQL query - ".mysql_error());
$i = 0;

while ($data=mysql_fetch_row($results))
{
        // NULLs are such a pain at times. isset($nullvar) == false
        if (is_null($data[5]))
                $data[5] = $data[0];
        if (is_null($data[6]))
                $data[6] = "";
        if (is_null($data[7]))
                $data[7]="";
        if (strlen($data[5]) == 0)
                $data[5]=$data[0];
        $myhash = $data[0];
        $echotext .= "<TR>\n";
        $writeout = $values[$i % 2];
        $echotext .="\t<TD $writeout>";
        if (strlen($data[6]) > 0)
                $echotext .="<A HREF=\"${data[6]}\">${data[5]}</A>";
        else
                $echotext .="$data[5]";
        if (strlen($data[7]) > 0)
                $echotext .=" (${data[7]})";

        for ($j=1; $j < 4; $j++)
                $echotext .="\t<TD $writeout ALIGN=\"center\">$data[$j]</TD>\n";
        $echotext .="\t<TD $writeout>$data[4] GiB</TD>\n";

        // The SPEED column calcultions.
        if ($data[8] < 0)
                $speed = "Zero";
        else if ($data[8] > 2097152)
                $speed = round($data[8]/1048576,2) . " MB/seg";
        else
                $speed = round($data[8] / 1024, 2) . " KB/seg";

        $echotext .="\t<TD $writeout>$speed</TD>\n";


        $echotext .="</TR>\n";
        $i++;
}

if ($i == 0)
        $echotext .="<TR><TD $values[0] COLSPAN=6 ALIGN=CENTER>No data</TD></TR>";
return $echotext;

 


I'm having a problem though, the standart "Last Updated " shows up on the top of the page: here
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Your script is not returning valid HTML - it's missing the table tags.

bye, Dirk
 Quote

Status: offline

exdeath

Forum User
Junior
Registered: 02/13/04
Posts: 23
Text Formatted Code
$echotext ='<b> Estado do Tracker:</b><p>';<br />$scriptname = $_SERVER["PHP_SELF"];<br /><br />$echotext .='';<br />$echotext .='Nome/InformaçãoSementes<br /> Leechers    DL   Transferencias  <br />  Velocidade  ';<br /><br />function doCrash($msg)<br />{<br />        $echotext .="Script error: $msg";<br />        exit(1);<br />}<br /><br />$values[0] = 'BGCOLOR="#ffffff"';<br />$values[1] =  'BGCOLOR="#dddddd"';<br /><br />require_once ("/path to tracker/config.php");<br />require_once ("/path to tracker/funcsv2.php");<br /><br />if ($GLOBALS["persist"])<br />        $db = mysql_pconnect($dbhost, $dbuser, $dbpass) or doCrash("Tracker error: can't connect to database - ".mysql_error());<br />else<br />        $db = mysql_connect($dbhost, $dbuser, $dbpass) or doCrash("Tracker error: can't connect to database - ".mysql_error());<br />mysql_select_db($database) or doCrash("Tracker error: can't open database $database - ".mysql_error());<br /><br />/* Rewrite, part 1: encode "WHERE" statement only. */<br /><br /><br />$query = "SELECT summary.info_hash, summary.seeds, summary.leechers, format(summary.finished,0), format(summary.dlbytes/1073741824,3),namemap.filename, namemap.url, namemap.info, summary.speed FROM summary LEFT JOIN namemap ON summary.info_hash = namemap.info_hash $where ORDER BY namemap.filename";<br />$results = mysql_query($query) or doCrash("Can't do SQL query - ".mysql_error());<br />$i = 0;<br /><br />while ($data=mysql_fetch_row($results))<br />{<br />        // NULLs are such a pain at times. isset($nullvar) == false<br />        if (is_null($data[5]))<br />                $data[5] = $data[0];<br />        if (is_null($data[6]))<br />                $data[6] = "";<br />        if (is_null($data[7]))<br />                $data[7]="";<br />        if (strlen($data[5]) == 0)<br />                $data[5]=$data[0];<br />        $myhash = $data[0];<br />        $echotext .= "n";<br />        $writeout = $values[$i % 2];<br />        $echotext .="t";<br />        if (strlen($data[6]) > 0)<br />                $echotext .="<A HREF="${data[6]}">${data[5]}</A>";<br />        else<br />                $echotext .="$data[5]";<br />        if (strlen($data[7]) > 0)<br />                $echotext .=" (${data[7]})";<br /><br />        for ($j=1; $j
                $echotext .="t$data[$j]n";<br />        $echotext .="t$data[4] GiBn";<br /><br />        // The SPEED column calcultions.<br />        if ($data[8]
                $speed = "Zero";<br />        else if ($data[8] > 2097152)<br />                $speed = round($data[8]/1048576,2) . " MB/seg";<br />        else<br />                $speed = round($data[8] / 1024, 2) . " KB/seg";<br /><br />        $echotext .="t$speedn";<br /><br /><br />        $echotext .="n";<br />        $i++;<br />}<br /><br />     if ($i == 0)<br />   $echotext .="No data";<br /><br />$echotext .='<p><b><a href="Put a forum adress where you posted links for you torrents">Download Torrents</a></b>';<br /><br />return $echotext;<br /><br />

The code for mystats is done and corrected the error you pointed.


Text Formatted Code
<br />//function_exists("sha1") or die('SHA1 function not available. You need PHP 4.3.0 or better;<br /><br />$echotext ='';<br /><br />require_once ("/path to tracker/config.php");<br />require_once ("/path to tracker/funcsv2.php");<br />require_once ("/path to tracker/BDecode.php");<br />require_once ("/path to tracker/BEncode.php");<br />if (isset($_POST["username"]))<br />{<br />        $hash = strtolower($_POST["hash"]);<br /><br />       $db = mysql_connect($dbhost, $_POST["username"], $_POST["password"]) or die("Couldn't connect to database. Incorrect username/password?");<br />    mysql_select_db($database) or die("Can't open the database.");<br /><br /><br />        if (isset($_FILES["torrent"]))<br />     {<br />    if ($_FILES["torrent"]["error"] != 4)        <br />     {<br />              $fd = fopen($_FILES["torrent"]["tmp_name"], "rb") or die("File upload error 1n");<br />            is_uploaded_file($_FILES["torrent"]["tmp_name"]) or die("File upload error 2n");<br />             $alltorrent = fread($fd, filesize($_FILES["torrent"]["tmp_name"]));<br />  <br />          $array = BDecode($alltorrent);<br />            if (!isset($array))<br />               {<br />                 $echotext .='Houve um erro ao ler o torrent.';<br />                    endOutput();<br />                      exit;<br />             }<br />         if (!$array)<br />              {<br />                 $echotext .='Houve um erro ao ler o torrent.';<br />                    endOutput();<br />                      exit;<br />             }<br />         $hash = sha1(BEncode($array["info"]));<br />          fclose($fd);<br /><br /><br />          unlink($_FILES["torrent"]["tmp_name"]);<br />         }<br />      }<br /><br />   if (isset($_POST["filename"]))<br />              $filename=$_POST["filename"];<br />       else<br />              $filename = "";<br />   <br />  if (isset($_POST["url"]))<br />              $url = $_POST["url"];<br />  else<br />              $url = "";<br /><br />  if (isset($_POST["info"]))<br />              $info = $_POST["info"];<br /> else<br />              $info = "";<br /><br /> if (isset($_POST["autoset"]))<br />      if (strcmp($_POST["autoset"], "enabled") == 0)<br />     {<br />         if (strlen($filename) == 0 && isset($array["info"]["name"]))<br />                  $filename = $array["info"]["name"];<br />           if (strlen($info) == 0 && isset($array["info"]["piece length"]))<br />              {<br />                 $info = $array["info"]["piece length"] / 1024 * (strlen($array["info"]["pieces"]) / 20) /1024;<br />                      $info = round($info, 2) . " MB";<br />                  if (isset($array["comment"]))<br />                              $info .= " - ".$array["comment"];<br />          }<br /> }<br />         $filename = mysql_escape_string($filename);<br />       $url = mysql_escape_string($url);<br /> $info = mysql_escape_string($info);<br /><br /> if ((strlen($hash) != 40) || !verifyHash($hash))<br />  {<br />         $echotext .='("Error: Info hash must be exactly 40 hex bytes.")';<br />         endOutput();<br />      }<br /><br />   $query = "INSERT INTO namemap (info_hash, filename, url, info) VALUES ("$hash", "$filename", "$url", "$info")";<br />   $status = makeTorrent($hash, true);<br />       quickQuery($query);<br />       if ($status)<br />              $echotext .="Torrent was added successfully.<BR><BR><BR><BR><BR>";<br />        else<br />              $echotext .="There were some errors. Check if this torrent had been added previously.<BR><BR><BR><BR><BR>";<br /><br />}<br />else<br />        $echotext .= "Specify information to proceed. <br>Information fields (except URL) can be loaded from the<br>torrent automatically using the checkbox below..<BR><BR><BR>";<br /><br /><br />endOutput();<br /><br /><br />function endOutput()<br />{<br /><br />$echotext .='<br /><br /><br />Database Username:<br />Database Password:<br />Torrent file:';<br /><br />if (function_exists("sha1"))<br />   $echotext .='';<br />else<br /> $echotext .='<I>File uploading not available - no SHA1 function.</I>';<br /><br />$echotext .='<br />Info Hash:<br />File name (optional): <br />Torrent URL (optional): <br />Short description(optional): ';<br />if (function_exists("sha1")) $echotext .=' Fill in fields using data from the torrent file.';<br /><br />$echotext .='';<br /><br />return $echotext;<br /><br />

I have a Parse error: parse error in /home/exdeath/public_html/staticpages/index.php(78) : eval()'d code on line 125, it is the eturn $echotext; line. Any ideas?

For some reason the forum is replacing the code tags for pre tags
 Quote

All times are EST. The time is now 08:56 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content