Members   Search      Help    Register    Login    Home
Home » Support Forums for PMBT 2.X » Bug Reports for V2.X » phpMyBitTorrent unable to scrape groups of external torrents successfully
phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2878] Tue, 18 August 2009 08:29 Go to next message
BrandeX is currently offline BrandeX  China
Messages: 7
Registered: August 2009
Leecher
Let me repost my question, I don't know that I made the issue clear. Check next post.

[Updated on: Wed, 19 August 2009 09:53]

Report message to a moderator

Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2882 is a reply to message #2878] Tue, 18 August 2009 13:14 Go to previous messageGo to next message
joeroberts is currently offline joeroberts  United States
Messages: 1971
Registered: June 2006
Location: U.S.A
Releaser
Da HacKer
some tracker do not allow you to scrape more then on time in a set time frame.

http://a.imageshack.us/img831/5562/mybikes.png
Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2884 is a reply to message #2882] Tue, 18 August 2009 16:58 Go to previous messageGo to next message
BrandeX is currently offline BrandeX  China
Messages: 7
Registered: August 2009
Leecher
(Reposting my question with pics for better understanding)

In the first screenshot you can see me in the Admin panel, after having clicked "External Trackers" I picked the tracker at the bottom of the list, it only has 1 torrent listed currently. After pressing the "update torrents now" icon next to it, the page reloads and gives the error output displaying the scrape xml coding as shown in the picture. Note that is now says "Found 0 seeds, 0 leechers, 0 completed downloads"
http://i29.tinypic.com/2q3dbvq.png

Now, immediately after this, I go into the regular details page for the torrent (not in admin, the part a user would see), and once again click on the "refresh peer data" icon at the top of the torrent info right away following my attempt to scrape from inside Admin. As you can see it returns 12 seeders and over 1000 completed downloads. The torrent details is then correctly updated and shown on my site.
http://i30.tinypic.com/sflc7n.png
If I do them one by one this way it works...
http://i31.tinypic.com/zxuyv7.png
Is there anyway to fix this issue of being unable to scrape torrents from the Admin control panel? As it is now, if for example did a mass upload of 500 torrents, I have to go and scrape every single one manually to get them to show the correct peer info.
Thanks!

[Updated on: Wed, 19 August 2009 10:07]

Report message to a moderator

icon14.gif  Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2885 is a reply to message #2878] Thu, 20 August 2009 13:21 Go to previous messageGo to next message
BrandeX is currently offline BrandeX  China
Messages: 7
Registered: August 2009
Leecher
Think thread needs a new post, not just an edit to get noticed. Anyways, see new post above Thumbs Up
Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2886 is a reply to message #2878] Thu, 20 August 2009 13:24 Go to previous messageGo to next message
joeroberts is currently offline joeroberts  United States
Messages: 1971
Registered: June 2006
Location: U.S.A
Releaser
Da HacKer
I no long host a open source tracker so It is hard for me to test admin acrape.
If you would allow I can fix this As I got a Idea.
please contact me


http://a.imageshack.us/img831/5562/mybikes.png
Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2887 is a reply to message #2878] Thu, 20 August 2009 13:53 Go to previous messageGo to next message
joeroberts is currently offline joeroberts  United States
Messages: 1971
Registered: June 2006
Location: U.S.A
Releaser
Da HacKer
please try this admin/files/trackers.php
<?php
/*
*-------------------------------phpMyBitTorrent--------------------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*--------------   Created By Antonio Anzivino (aka DJ Echelon)   --------------*
*-------------               http://www.p2pmania.it               -------------*
*------------ Based on the Bit Torrent Protocol made by Bram Cohen ------------*
*-------------              http://www.bittorrent.com             -------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*--   This program is free software; you can redistribute it and/or modify   --*
*--   it under the terms of the GNU General Public License as published by   --*
*--   the Free Software Foundation; either version 2 of the License, or      --*
*--   (at your option) any later version.                                    --*
*--                                                                          --*
*--   This program is distributed in the hope that it will be useful,        --*
*--   but WITHOUT ANY WARRANTY; without even the implied warranty of         --*
*--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          --*
*--   GNU General Public License for more details.                           --*
*--                                                                          --*
*--   You should have received a copy of the GNU General Public License      --*
*--   along with this program; if not, write to the Free Software            --*
*-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              �2005 phpMyBitTorrent Development Team              ------*
*-----------               http://phpmybittorrent.com               -----------*
*------------------------------------------------------------------------------*
*/

if (!eregi("admin.php",$_SERVER["PHP_SELF"])) die ("You can't access this file directly");

function getscrapedata($url) {
        if (!$fp = fopen($url,"rb")) return false; //Warnings are shown
        $page = "";
        while (!feof($fp)) $page .= @fread($fp,10000);
        @fclose($fp);

        echo "<p>"._admtrkrawdata."</p>\n";
        echo "<div style=\"overflow: auto; border: 1px; white-space: nowrap; margin: 0px; padding: 2px; width: 100%; height: 100px;\"><p>".htmlspecialchars($page)."</p></div>\n";

        $scrape = BDecode($page,"Scrape");
        unset($page);

        if (!$scrape) {
                echo "<p>"._admtrkinvalidbencode."</p>\n";
                return false;
        }

        return $scrape;
}

function ResolveTracker($url, &$resp) {
        $server = parse_url($url);

        if (!$server["port"]) $server["port"] = 80;

        $out  = "GET ".$server["path"]." HTTP/1.1\r\n";
        $out .= "Host: ".$server['host']."\r\n";
        $out .= "User-Agent: Azureus 2.4.0.2\r\n";
        $out .= "Connection: Close\r\n\r\n";

        $fp = @fsockopen($server["host"],$server["port"],$errno,$errstr,1.0);
        if (!$fp) return false;

        fwrite($fp,$out);
        $resp = fgets($fp,512);
        fclose($fp);
        //echo $resp;
        if(!ereg("HTTP/1\.[01] 20[0-3] OK",$resp)) return false;
        return true;
}


if ($op == "bantracker" AND isset($id) AND is_numeric($id) AND isset($action)) do {
        $sql = "SELECT url FROM ".$db_prefix."_trackers WHERE id = ".$id." LIMIT 1;";
        $res = $db->sql_query($sql) or btsqlerror($sql);
        if ($db->sql_numrows($res) < 1) {
                $db->sql_freeresult($res);
                break;
        }
        list ($annurl) = $db->sql_fetchrow($res);
        $db->sql_freeresult($res);

        if ($action == "ban") {
                $sql = "UPDATE ".$db_prefix."_trackers SET status = 'blacklisted' WHERE id = '".$id."';";
                $db->sql_query($sql) or btsqlerror($sql);
                $sql = "UPDATE ".$db_prefix."_torrents SET banned = 'yes' WHERE tracker = '".$annurl."';";
                $db->sql_query($sql) or btsqlerror($sql);
        } elseif ($action == "unban") {
                $sql = "UPDATE ".$db_prefix."_trackers SET status = 'active' WHERE id = '".$id."';";
                $db->sql_query($sql) or btsqlerror($sql);
                $sql = "UPDATE ".$db_prefix."_torrents SET banned = 'no' WHERE tracker = '".$annurl."';";
                $db->sql_query($sql) or btsqlerror($sql);
        }
} while (false);
if ($op == "bannewtracker") {
        $annregexp = "/(http[s]?+):\/\/[-\/.:_\\w]*\/announce[^\/\\s]*/";
        if (!preg_match($annregexp, $announce) OR $announce == $announce_url) bterror(_btinvannounce."<b>".$announce. "</b>",_admbannewtracker,false);
        else {
                $sql = "INSERT INTO ".$db_prefix."_trackers (url , status , updated) VALUES ('".addslashes($announce)."', 'blacklisted', NOW( ));";
                $db->sql_query($sql);
        }
}

OpenTable(_admtrackers);
echo "<p>"._admtrackerintro."</p>\n";
echo "<p>&nbsp;</p>\n";

$sql = "SELECT id, url, status, UNIX_TIMESTAMP(updated) AS updated FROM ".$db_prefix."_trackers;";

$res = $db->sql_query($sql) or btsqlerror($sql);
if ($db->sql_numrows($res) < 1) {
        echo "<p><b>"._admnotrackers."</b></p>";
} else {
        echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
        echo "<thead>\n";
        echo "<tr><td><p><b>"._admtrackerurl."</b></p></td><td><p><b>"._admtrkstatus."</b></p></td><td><p><b>"._admtrklastupdate."</b></p></td><td><p><b>"._admtrkassociatedtorrents."<b></p></td><td><p><b>"._btactions."</b></p></td></tr>";
        echo "</thead>\n";

        echo "<tbody>\n";
        while ($tracker = $db->sql_fetchrow($res)) {
                $torrentsql = "SELECT COUNT(id) FROM ".$db_prefix."_torrents WHERE tracker = '".$tracker["url"]."';";
                $torrentres = $db->sql_query($torrentsql) or btsqlerror($torrentsql);
                list ($torrents) = $db->sql_fetchrow($torrentres);
                $db->sql_freeresult($torrentres);

                $act = "ban";
                $alt = _admtrkblacklist;
                $ban = "lock.gif";
                if ($tracker["status"] == "active") $trkstatus = _admtrkstatusactive;
                elseif($tracker["status"] == "dead") $trkstatus = _admtrkstatusdead;
                else {
                        $trkstatus = _admtrkstatusblack;
                        $act = "unban";
                        $alt = _admtrkblacklist;
                        $ban = "unlock.gif";
                }
                echo "<tr><td><p>".$tracker["url"]."</p></td><td><p>".(($op == "scrapenow" AND isset($id) AND $id == $tracker["id"])? "" : $trkstatus)."</p></td><td><p>".(($op == "scrapenow" AND isset($id) AND $id == $tracker["id"]) ? "<b>"._admtrkscraping."</b>" : mkprettytime(time()-$tracker["updated"]))."<p></td><td><p>".$torrents." <a href=\"admin.php?op=listtorrents&id=".$tracker["id"]."\">"._admtrkviewtorrents."</a></p></td><td><p>".adminpic("refresh.png","admin.php?op=scrapenow&id=".$tracker["id"],_admtrkforcescrape).adminpic($ban,"admin.php?op=bantracker&id=".$tracker["id"]."&action=".$act,$alt)."</p></td></tr>\n";
        }
        echo "</tbody>\n";
        echo "</table>\n";
}
$db->sql_freeresult($res);
echo "<p>&nbsp;</p>\n";
CloseTable();


if ($op == "listtorrents" AND isset($id) AND is_numeric($id)) {
        $sql = "SELECT ".$db_prefix."_torrents.*, IF(".$db_prefix."_torrents.numratings < '$minvotes', NULL, ROUND(".$db_prefix."_torrents.ratingsum / ".$db_prefix."_torrents.numratings, 1)) AS rating, ".$db_prefix."_categories.name AS cat_name, ".$db_prefix."_categories.image AS cat_pic, U.username, IF(U.name IS NULL, U.username, U.name) as user_name, U.level as user_level FROM ".$db_prefix."_torrents LEFT JOIN ".$db_prefix."_categories ON category = ".$db_prefix."_categories.id LEFT JOIN ".$db_prefix."_users U ON ".$db_prefix."_torrents.owner = U.id LEFT JOIN ".$db_prefix."_trackers ON ".$db_prefix."_torrents.tracker = ".$db_prefix."_trackers.url WHERE ".$db_prefix."_trackers.id = '".$id."' ORDER BY ".$db_prefix."_torrents.evidence DESC, ".$db_prefix."_torrents.added DESC;";
        $res = $db->sql_query($sql) or btsqlerror($sql);
        torrenttable($res);
        $db->sql_freeresult($res);
}

if ($op == "scrapenow" AND isset($id) AND is_numeric($id)){
        OpenTable(_admtrkscraping);
        do { //I can use break to exit

        @set_time_limit(180);
        @ini_set("memory_limit","64M");
        require_once("include/bdecoder.php");

        $sql = "SELECT url, support FROM ".$db_prefix."_trackers WHERE id = ".$id." LIMIT 1;";
        $res = $db->sql_query($sql) or btsqlerror($sql);
        if ($db->sql_numrows($res) < 1) {
                $db->sql_freeresult($res);
                break;
        }
        list ($annurl,$support) = $db->sql_fetchrow($res);
        $db->sql_freeresult($res);


        echo "<p>"._admtrkscraping."<br />";
        echo "<b>".$annurl."</b><p>\n";
        echo "<p>&nbsp;</p>\n\n";

        $sql = "SELECT info_hash FROM ".$db_prefix."_torrents WHERE tracker = '".$annurl."';";
        $hashres = $db->sql_query($sql);

        if ($db->sql_numrows($hashres) < 1) {
                $db->sql_query("DELETE FROM ".$db_prefix."_trackers WHERE url = '".$annurl."';");
                die("ERROR");
        }
        $infohashes = Array();
        $scrapearray = Array();
        while ($row_hash = $db->sql_fetchrow($hashres)) {
                $infohashes[] = $row_hash["info_hash"];
                $scrapearray[] = Array("info_hash" => $row_hash["info_hash"], "seeders" => 0, "leechers" => 0, "completed" => 0);
        }
        unset($row_hash, $sql);
        $db->sql_freeresult($hashres);

        $scrapeurl = str_replace("announce","scrape",$annurl);

        /*
        0TH ATTEMPT: CHECK FOR TRACKER ONLINE
        1ST ATTEMPT: SELECTIVE SCRAPE
        2ND ATTEMPT: GLOBAL SCRAPE
        3RD ATTEMPT: SINGLE SCRAPE
        */
        if (!ResolveTracker($scrapeurl, $resp)) {
                echo "<p>"._admtrkcannotopen;
                if ($resp) echo" (".htmlspecialchars($resp).")";
                echo "</p>\n";
                $sql = "UPDATE ".$db_prefix."_trackers SET status = 'dead' WHERE url = '".$annurl."';";
                $db->sql_query($sql) or btsqlerror($sql);
                $sql = "UPDATE ".$db_prefix."_torrents SET seeders = 0, leechers = 0, tot_peer = 0 WHERE tracker = '". $annurl . "';";
                $db->sql_query($sql) or btsqlerror($sql);
                break;
        }

        if ($support == "selective") {
                /*
                TRIES SELECTIVE SCRAPE.
                IF WORKS SAVES DATA AND TERMINATES BLOCK (WITH BREAK)
                ELSE TRIES GLOBAL SCRAPE (WHICH IS A *STANDARD*)
                */
                $url = $scrapeurl.((strpos($scrape_url,"?")) ? "&" : "?")."info_hash=".urlencode($infohashes[0]);
                for ($i = 1; $i < count($infohashes); $i++) {
                        $url .= "&info_hash=".urlencode($infohashes[$i]);

                }
                $scrape = getscrapedata($url);
                $scrape_valid = false;

                //Checking if returned scrape is valid scrape data
                if ($scrape) {
                        if (!entry_exists($scrape,"failure reason(String)","Scrape") AND entry_exists($scrape,"files(Dictionary)","Scrape")) {
                                $scrape_valid = true;
                        }
                }

                if ($scrape_valid) {
                        echo "<p>"._admtrkdata."</p>\n";
                        echo "<div style=\"overflow: auto; border: 1px; white-space: nowrap; margin: 0px; padding: 2px; width: 100%; height: 300px;\">";
                        echo str_replace(Array(" ","\n"),Array("&nbsp;","<br />\n"),htmlspecialchars($scrape->dump_mem(true,"UTF-8")));
                        echo "</div>\n";
                        echo "<p>&nbsp;</p>\n";
                } else {
                        $support = "global";
                        $db->sql_query("UPDATE ".$db_prefix."_trackers SET support = 'global' WHERE id = '".$id."';");
                }
        }

        if ($support == "global" AND count($infohashes) > 1) {
                $scrape_valid = false;
                $scrape = getscrapedata($scrapeurl);
                if ($scrape) {
                        if (!entry_exists($scrape,"failure reason(String)","Scrape") AND entry_exists($scrape,"files(Dictionary)","Scrape")) {
                                $scrape_valid = true;
                        }
                }
                if ($scrape_valid) {
                        echo "<p>"._admtrkdata."</p>\n";
                        echo "<div style=\"overflow: auto; border: 1px; white-space: nowrap; margin: 0px; padding: 2px; width: 100%; height: 300px;\">";
                        echo str_replace(Array(" ","\n"),Array("&nbsp;","<br />\n"),htmlspecialchars($scrape->dump_mem(true,"UTF-8")));
                        echo "</div>\n";
                        echo "<p>&nbsp;</p>\n";
                } else {
                        $support = "single";
                        $db->sql_query("UPDATE ".$db_prefix."_trackers SET support = 'single' WHERE id = '".$id."';");
                }
        }

        if ($support == "single" OR count($infohashes) == 1) {
                $rewrite_engine = false; //We'll send output buffer to client
                /*
                SINGLE SCRAPE CREATES A FAKE GLOBAL SCRAPE QUERYING THE TRACKER MULTIPLE TIMES
                THE FAKE SCRAPE IS USED TO MAKE THE NEXT PART OF THE CODE BELIEVE WE DID A SINGLE JOB
                THIS METHOD IS USED ON LARGE TRACKERS AND HAS ONE INCONVENIENT: WITH MANY TORRENTS
                YOUR SERVER COULD GET BANNED FOR HAMMERING
                */

                $scrape = domxml_new_doc("1.0");
                $root = $scrape->create_element("Scrape");
                $root->set_attribute("type","Dictionary");
                $files = $scrape->create_element("files");
                $files->set_attribute("type","Dictionary");
                echo "<div class=\"hide\">";
                foreach ($infohashes as $hash) {
                        $scr = getscrapedata ($scrapeurl.((strpos($scrape_url,"?")) ? "&" : "?")."info_hash=".urlencode($hash));
                        $hash_hex = preg_replace_callback('/./s', "hex_esc", str_pad($hash,20));
						$hash_hex = "a".$hash_hex;
                        if (entry_exists($scr,"files/".$hash_hex."(Dictionary)","Scrape")) {
                                #Create the XML node for fake global scrape
                                $item = $scrape->create_element($hash_hex);
                                $item->set_attribute("type","Dictionary");

                                $complete = $scrape->create_element("complete");
                                $complete->set_attribute("type","Integer");
                                $child = $scrape->create_text_node(entry_read($scr,"files/".$hash_hex."/complete(Integer)","Scrape"));
                                $complete->append_child($child);

                                $incomplete = $scrape->create_element("incomplete");
                                $incomplete->set_attribute("type","Integer");
                                $child = $scrape->create_text_node(entry_read($scr,"files/".$hash_hex."/incomplete(Integer)","Scrape"));
                                $incomplete->append_child($child);

                                $downloaded = $scrape->create_element("downloaded");
                                $downloaded->set_attribute("type","Integer");
                                $child = $scrape->create_text_node(entry_read($scr,"files/".$hash_hex."/downloaded(Integer)","Scrape"));
                                $downloaded->append_child($child);

                                $item->append_child($complete);
                                $item->append_child($incomplete);
                                $item->append_child($downloaded);

                                $files->append_child($item);
                        }
                        unset($scr);

                        ob_flush();
                        sleep(2);
                }

                $root->append_child($files);
                $scrape->append_child($root);
                echo "</div>";
        }

        foreach ($infohashes as $hash) {
                $hash_hex = preg_replace_callback('/./s', "hex_esc", str_pad($hash,20));
						$hash_hex = "a".$hash_hex;
                if (!entry_exists($scrape,"files/".$hash_hex."(Dictionary)","Scrape")) {
                        $seed = $leech = $completed = 0;
                } else {

                        $seed = entry_read($scrape,"files/".$hash_hex."/complete(Integer)","Scrape");
                        $leech = entry_read($scrape,"files/".$hash_hex."/incomplete(Integer)","Scrape");
                        $completed = entry_read($scrape,"files/".$hash_hex."/downloaded(Integer)","Scrape");
                        $name = ((entry_exists($scrape,"files/".$hash_hex."/name(String)","Scrape")) ? entry_read($scrape,"files/".$hash_hex."/name(String)","Scrape") : "");
                }
                if (($seed + $leech) > 0) $visible = "yes";
                else $visible = "no";
                echo "<p>".str_replace(Array("**seed**","**leechers**","**completed**","**name**","**hash**"),Array($seed,$leech,$completed,htmlspecialchars($name),$hash_hex),_admtrksummarystr)."</p>";
                $sql = "UPDATE ".$db_prefix."_torrents SET seeders = ". $seed .", leechers = ".$leech.", tot_peer = ". ($seed + $leech) .", completed = ". $completed .", visible = '".$visible."', last_action = NOW() WHERE info_hash = '".addslashes($hash)."';";
                $db->sql_query($sql) or btsqlerror($sql);
        }
        unset($scrape);
        $db->sql_query("UPDATE ".$db_prefix."_trackers SET updated = NOW(), status = 'active' WHERE id = '".$id."';");


        } while (false);
        CloseTable();
}

OpenTable(_admbannewtracker);
echo "<p>"._admbannewtrackerintro."</p>\n";
echo "<p>&nbsp;</p>\n";
echo "<form action=\"admin.php\" method=\"POST\">\n";
echo "<input type=\"hidden\" name=\"op\" value=\"bannewtracker\" />\n";
echo "<table width=\"50%\" cellpadding=\"0\" cellspacing=\"0\">\n";
echo "<tr><td><p>"._admtrackerurl."</p></td><td><input type=\"text\" name=\"announce\" /></td></tr>\n";
echo "</table>\n";
echo "<p><input type=\"submit\" value=\""._btsend."\" /></p>";
echo "</form>\n";
CloseTable();
?>


http://a.imageshack.us/img831/5562/mybikes.png
Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2888 is a reply to message #2887] Fri, 21 August 2009 03:03 Go to previous messageGo to next message
BrandeX is currently offline BrandeX  China
Messages: 7
Registered: August 2009
Leecher
Not quite right yet if there is more than one torrent in the set, only the last one is successfully scraped. example pic:
http://i29.tinypic.com/260wkmc.png
Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2889 is a reply to message #2888] Sat, 22 August 2009 14:04 Go to previous messageGo to next message
joeroberts is currently offline joeroberts  United States
Messages: 1971
Registered: June 2006
Location: U.S.A
Releaser
Da HacKer
I well look into this more tonight after work.
I don't have much time as I am working on 2.0.4 beta release
So I'm sorry for slow reply


http://a.imageshack.us/img831/5562/mybikes.png
Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2890 is a reply to message #2878] Sat, 22 August 2009 16:23 Go to previous messageGo to next message
BrandeX is currently offline BrandeX  China
Messages: 7
Registered: August 2009
Leecher
No problem Joe, this is a great project and I also look forward to future official updates. Thanks for all the work.
Re: phpMyBitTorrent unable to scrape groups of external torrents successfully [message #2900 is a reply to message #2890] Sat, 29 August 2009 16:10 Go to previous message
joeroberts is currently offline joeroberts  United States
Messages: 1971
Registered: June 2006
Location: U.S.A
Releaser
Da HacKer
OK I had a little time so I did a little fixing
try this one
<?php
/*
*-------------------------------phpMyBitTorrent--------------------------------*
*--- The Ultimate BitTorrent Tracker and BMS (Bittorrent Management System) ---*
*--------------   Created By Antonio Anzivino (aka DJ Echelon)   --------------*
*-------------               http://www.p2pmania.it               -------------*
*------------ Based on the Bit Torrent Protocol made by Bram Cohen ------------*
*-------------              http://www.bittorrent.com             -------------*
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
*--   This program is free software; you can redistribute it and/or modify   --*
*--   it under the terms of the GNU General Public License as published by   --*
*--   the Free Software Foundation; either version 2 of the License, or      --*
*--   (at your option) any later version.                                    --*
*--                                                                          --*
*--   This program is distributed in the hope that it will be useful,        --*
*--   but WITHOUT ANY WARRANTY; without even the implied warranty of         --*
*--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          --*
*--   GNU General Public License for more details.                           --*
*--                                                                          --*
*--   You should have received a copy of the GNU General Public License      --*
*--   along with this program; if not, write to the Free Software            --*
*-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA --*
*--                                                                          --*
*------------------------------------------------------------------------------*
*------              �2005 phpMyBitTorrent Development Team              ------*
*-----------               http://phpmybittorrent.com               -----------*
*------------------------------------------------------------------------------*
*/

if (!eregi("admin.php",$_SERVER["PHP_SELF"])) die ("You can't access this file directly");

function getscrapedata($url) {
        if (!$fp = fopen($url,"rb")) return false; //Warnings are shown
        $page = "";
        while (!feof($fp)) $page .= @fread($fp,10000);
        @fclose($fp);

        echo "<p>"._admtrkrawdata."</p>\n";
        echo "<div style=\"overflow: auto; border: 1px; white-space: nowrap; margin: 0px; padding: 2px; width: 100%; height: 100px;\"><p>".htmlspecialchars($page)."</p></div>\n";

        $scrape = BDecode($page,"Scrape");
        unset($page);

        if (!$scrape) {
                echo "<p>"._admtrkinvalidbencode."</p>\n";
                return false;
        }

        return $scrape;
}

function ResolveTracker($url, &$resp) {
if (preg_match("/thepiratebay.org/i", $url))$url=str_replace('a.tracker.','',$url);
if (preg_match("/thepiratebay.org/i", $url))$url=str_replace('eztv.tracker.','',$url);
if (preg_match("/thepiratebay.org/i", $url))$url=str_replace('tpb.tracker.','',$url);
if (preg_match("/thepiratebay.org/i", $url))$url=str_replace('vtv.tracker.','',$url);
if (preg_match("/thepiratebay.org/i", $url))$url=str_replace('tv.tracker.','',$url);
if (preg_match("/thepiratebay.org/i", $url))$url=str_replace('vip.tracker.','',$url);
if (preg_match("/thepiratebay.org/i", $url))$url=str_replace('open.tracker.','',$url);
if (preg_match("/thepiratebay.org/i", $url))$url=str_replace('tracker.','',$url);
if (preg_match("/denis.stalker.h3q.com/i", $url))return true;
if (preg_match("/tpb.tracker.prq.to/i", $url))$url=str_replace('tpb.tracker.','',$url);
if (preg_match("/tv.tracker.prq.to/i", $url))$url=str_replace('tv.tracker.','',$url);
if (preg_match("/tracker.prq.to/i", $url))$url=str_replace('tracker.','',$url);
if (preg_match("/tracker.guiks.net/i", $url))$url=str_replace('tracker.','',$url);
if (preg_match("/freeexchange.ru/i", $url))$url=str_replace('http://scrape.freeexchange.ru:2710/scrape','http://tracker.freeexchange.ru',$url);
        $server = parse_url($url);
		//die($server['host']);

        if (!$server["port"]) $server["port"] = 80;
        $out  = "GET / HTTP/1.1\r\n";
        $out .= "Host: ".$server['host'].":".$server["port"]."\r\n";
        $out .= "Connection: Close\r\n\r\n";

        $fp = @fsockopen($server["host"],'',$errno,$errstr,1.0);
        $fp2 = @fsockopen($server["host"],'80',$errno,$errstr,1.0);
		$fp3 = @fsockopen($server["host"],$server["port"],$errno,$errstr,1.0);
        if (!$fp) $fp = $fp2;
        if (!$fp) $fp = $fp3;
        if (!$fp) {
                echo $url ."123Debug: Il tracker non risponde";
               return false;
        }

        fwrite($fp,$out);
        $resp = fgets($fp,512);
        fclose($fp);
        echo $resp;
        if(ereg("HTTP/1\.[01] 30[0-3] Found",$resp)) return true;
        if(ereg("HTTP/1\.[01] 20[0-3] OK",$resp)) return true;
       return false;
}


if ($op == "bantracker" AND isset($id) AND is_numeric($id) AND isset($action)) do {
        $sql = "SELECT url FROM ".$db_prefix."_trackers WHERE id = ".$id." LIMIT 1;";
        $res = $db->sql_query($sql) or btsqlerror($sql);
        if ($db->sql_numrows($res) < 1) {
                $db->sql_freeresult($res);
                break;
        }
        list ($annurl) = $db->sql_fetchrow($res);
        $db->sql_freeresult($res);

        if ($action == "ban") {
                $sql = "UPDATE ".$db_prefix."_trackers SET status = 'blacklisted' WHERE id = '".$id."';";
                $db->sql_query($sql) or btsqlerror($sql);
                $sql = "UPDATE ".$db_prefix."_torrents SET banned = 'yes' WHERE tracker = '".$annurl."';";
                $db->sql_query($sql) or btsqlerror($sql);
        } elseif ($action == "unban") {
                $sql = "UPDATE ".$db_prefix."_trackers SET status = 'active' WHERE id = '".$id."';";
                $db->sql_query($sql) or btsqlerror($sql);
                $sql = "UPDATE ".$db_prefix."_torrents SET banned = 'no' WHERE tracker = '".$annurl."';";
                $db->sql_query($sql) or btsqlerror($sql);
        }
} while (false);
if ($op == "bannewtracker") {
        $annregexp = "/(http[s]?+):\/\/[-\/.:_\\w]*\/announce[^\/\\s]*/";
        if (!preg_match($annregexp, $announce) OR $announce == $announce_url) bterror(_btinvannounce."<b>".$announce. "</b>",_admbannewtracker,false);
        else {
                $sql = "INSERT INTO ".$db_prefix."_trackers (url , status , updated) VALUES ('".addslashes($announce)."', 'blacklisted', NOW( ));";
                $db->sql_query($sql);
        }
}

OpenTable(_admtrackers);
echo "<p>"._admtrackerintro."</p>\n";
echo "<p>&nbsp;</p>\n";

$sql = "SELECT id, url, status, UNIX_TIMESTAMP(updated) AS updated FROM ".$db_prefix."_trackers;";

$res = $db->sql_query($sql) or btsqlerror($sql);
if ($db->sql_numrows($res) < 1) {
        echo "<p><b>"._admnotrackers."</b></p>";
} else {
        echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
        echo "<thead>\n";
        echo "<tr><td><p><b>"._admtrackerurl."</b></p></td><td><p><b>"._admtrkstatus."</b></p></td><td><p><b>"._admtrklastupdate."</b></p></td><td><p><b>"._admtrkassociatedtorrents."<b></p></td><td><p><b>"._btactions."</b></p></td></tr>";
        echo "</thead>\n";

        echo "<tbody>\n";
        while ($tracker = $db->sql_fetchrow($res)) {
                $torrentsql = "SELECT COUNT(id) FROM ".$db_prefix."_torrents WHERE tracker = '".$tracker["url"]."';";
                $torrentres = $db->sql_query($torrentsql) or btsqlerror($torrentsql);
                list ($torrents) = $db->sql_fetchrow($torrentres);
                $db->sql_freeresult($torrentres);

                $act = "ban";
                $alt = _admtrkblacklist;
                $ban = "lock.gif";
                if ($tracker["status"] == "active") $trkstatus = _admtrkstatusactive;
                elseif($tracker["status"] == "dead") $trkstatus = _admtrkstatusdead;
                else {
                        $trkstatus = _admtrkstatusblack;
                        $act = "unban";
                        $alt = _admtrkblacklist;
                        $ban = "unlock.gif";
                }
                echo "<tr><td><p>".$tracker["url"]."</p></td><td><p>".(($op == "scrapenow" AND isset($id) AND $id == $tracker["id"])? "" : $trkstatus)."</p></td><td><p>".(($op == "scrapenow" AND isset($id) AND $id == $tracker["id"]) ? "<b>"._admtrkscraping."</b>" : mkprettytime(time()-$tracker["updated"]))."<p></td><td><p>".$torrents." <a href=\"admin.php?op=listtorrents&id=".$tracker["id"]."\">"._admtrkviewtorrents."</a></p></td><td><p>".adminpic("refresh.png","admin.php?op=scrapenow&id=".$tracker["id"],_admtrkforcescrape).adminpic($ban,"admin.php?op=bantracker&id=".$tracker["id"]."&action=".$act,$alt)."</p></td></tr>\n";
        }
        echo "</tbody>\n";
        echo "</table>\n";
}
$db->sql_freeresult($res);
echo "<p>&nbsp;</p>\n";
CloseTable();


if ($op == "listtorrents" AND isset($id) AND is_numeric($id)) {
        $sql = "SELECT ".$db_prefix."_torrents.*, IF(".$db_prefix."_torrents.numratings < '$minvotes', NULL, ROUND(".$db_prefix."_torrents.ratingsum / ".$db_prefix."_torrents.numratings, 1)) AS rating, ".$db_prefix."_categories.name AS cat_name, ".$db_prefix."_categories.image AS cat_pic, U.username, IF(U.name IS NULL, U.username, U.name) as user_name, U.level as user_level FROM ".$db_prefix."_torrents LEFT JOIN ".$db_prefix."_categories ON category = ".$db_prefix."_categories.id LEFT JOIN ".$db_prefix."_users U ON ".$db_prefix."_torrents.owner = U.id LEFT JOIN ".$db_prefix."_trackers ON ".$db_prefix."_torrents.tracker = ".$db_prefix."_trackers.url WHERE ".$db_prefix."_trackers.id = '".$id."' ORDER BY ".$db_prefix."_torrents.evidence DESC, ".$db_prefix."_torrents.added DESC;";
        $res = $db->sql_query($sql) or btsqlerror($sql);
        torrenttable($res);
        $db->sql_freeresult($res);
}

if ($op == "scrapenow" AND isset($id) AND is_numeric($id)){
        OpenTable(_admtrkscraping);
        do { //I can use break to exit

        @set_time_limit(180);
        @ini_set("memory_limit","64M");
        require_once("include/bdecoder.php");

        $sql = "SELECT url, support FROM ".$db_prefix."_trackers WHERE id = ".$id." LIMIT 1;";
        $res = $db->sql_query($sql) or btsqlerror($sql);
        if ($db->sql_numrows($res) < 1) {
                $db->sql_freeresult($res);
                break;
        }
        list ($annurl,$support) = $db->sql_fetchrow($res);
        $db->sql_freeresult($res);


        echo "<p>"._admtrkscraping."<br />";
        echo "<b>".$annurl."</b><p>\n";
        echo "<p>&nbsp;</p>\n\n";

        $sql = "SELECT info_hash FROM ".$db_prefix."_torrents WHERE tracker = '".$annurl."';";
        $hashres = $db->sql_query($sql);

        if ($db->sql_numrows($hashres) < 1) {
                $db->sql_query("DELETE FROM ".$db_prefix."_trackers WHERE url = '".$annurl."';");
                die("ERROR");
        }
        $infohashes = Array();
        $scrapearray = Array();
        while ($row_hash = $db->sql_fetchrow($hashres)) {
                $infohashes[] = $row_hash["info_hash"];
                $scrapearray[] = Array("info_hash" => $row_hash["info_hash"], "seeders" => 0, "leechers" => 0, "completed" => 0);
        }
        unset($row_hash, $sql);
        $db->sql_freeresult($hashres);

        $scrapeurl = str_replace("announce","scrape",$annurl);

        /*
        0TH ATTEMPT: CHECK FOR TRACKER ONLINE
        1ST ATTEMPT: SELECTIVE SCRAPE
        2ND ATTEMPT: GLOBAL SCRAPE
        3RD ATTEMPT: SINGLE SCRAPE
        */
        if (!ResolveTracker($scrapeurl, $resp)) {
                echo "<p>"._admtrkcannotopen;
                if ($resp) echo" (".htmlspecialchars($resp).")";
                echo "</p>\n";
                $sql = "UPDATE ".$db_prefix."_trackers SET status = 'dead' WHERE url = '".$annurl."';";
                $db->sql_query($sql) or btsqlerror($sql);
                $sql = "UPDATE ".$db_prefix."_torrents SET seeders = 0, leechers = 0, tot_peer = 0 WHERE tracker = '". $annurl . "';";
                $db->sql_query($sql) or btsqlerror($sql);
                break;
        }

        if ($support == "selective") {
                /*
                TRIES SELECTIVE SCRAPE.
                IF WORKS SAVES DATA AND TERMINATES BLOCK (WITH BREAK)
                ELSE TRIES GLOBAL SCRAPE (WHICH IS A *STANDARD*)
                */
                $url = $scrapeurl.((strpos($scrape_url,"?")) ? "&" : "?")."info_hash=".urlencode($infohashes[0]);
                for ($i = 1; $i < count($infohashes); $i++) {
                        $url .= "&info_hash=".urlencode($infohashes[$i]);

                }
                $scrape = getscrapedata($url);
                $scrape_valid = false;

                //Checking if returned scrape is valid scrape data
                if ($scrape) {
                        if (!entry_exists($scrape,"failure reason(String)","Scrape") AND entry_exists($scrape,"files(Dictionary)","Scrape")) {
                                $scrape_valid = true;
                        }
                }

                if ($scrape_valid) {
                        echo "<p>"._admtrkdata."</p>\n";
                        echo "<div style=\"overflow: auto; border: 1px; white-space: nowrap; margin: 0px; padding: 2px; width: 100%; height: 300px;\">";
                        echo str_replace(Array(" ","\n"),Array("&nbsp;","<br />\n"),htmlspecialchars($scrape->dump_mem(true,"UTF-8")));
                        echo "</div>\n";
                        echo "<p>&nbsp;</p>\n";
                } else {
                        $support = "global";
                        $db->sql_query("UPDATE ".$db_prefix."_trackers SET support = 'global' WHERE id = '".$id."';");
                }
        }

        if ($support == "global" AND count($infohashes) > 1) {
                $scrape_valid = false;
                $scrape = getscrapedata($scrapeurl);
                if ($scrape) {
                        if (!entry_exists($scrape,"failure reason(String)","Scrape") AND entry_exists($scrape,"files(Dictionary)","Scrape")) {
                                $scrape_valid = true;
                        }
                }
                if ($scrape_valid) {
                        echo "<p>"._admtrkdata."</p>\n";
                        echo "<div style=\"overflow: auto; border: 1px; white-space: nowrap; margin: 0px; padding: 2px; width: 100%; height: 300px;\">";
                        echo str_replace(Array(" ","\n"),Array("&nbsp;","<br />\n"),htmlspecialchars($scrape->dump_mem(true,"UTF-8")));
                        echo "</div>\n";
                        echo "<p>&nbsp;</p>\n";
                } else {
                        $support = "single";
                        $db->sql_query("UPDATE ".$db_prefix."_trackers SET support = 'single' WHERE id = '".$id."';");
                }
        }

        if ($support == "single" OR count($infohashes) == 1) {
                $rewrite_engine = false; //We'll send output buffer to client
                /*
                SINGLE SCRAPE CREATES A FAKE GLOBAL SCRAPE QUERYING THE TRACKER MULTIPLE TIMES
                THE FAKE SCRAPE IS USED TO MAKE THE NEXT PART OF THE CODE BELIEVE WE DID A SINGLE JOB
                THIS METHOD IS USED ON LARGE TRACKERS AND HAS ONE INCONVENIENT: WITH MANY TORRENTS
                YOUR SERVER COULD GET BANNED FOR HAMMERING
                */

                $scrape = domxml_new_doc("1.0");
                $root = $scrape->create_element("Scrape");
                $root->set_attribute("type","Dictionary");
                $files = $scrape->create_element("files");
                $files->set_attribute("type","Dictionary");
                echo "<div >";
                foreach ($infohashes as $hash) {
                        $scr = getscrapedata ($scrapeurl.((strpos($scrape_url,"?")) ? "&" : "?")."info_hash=".urlencode($hash));
                        $hash_hex = preg_replace_callback('/./s', "hex_esc", str_pad($hash,20));
						$hash_hex = "a".$hash_hex;
                        if (entry_exists($scr,"files/".$hash_hex."(Dictionary)","Scrape")) {
                                #Create the XML node for fake global scrape
                                $item = $scrape->create_element($hash_hex);
                                $item->set_attribute("type","Dictionary");

                                $complete = $scrape->create_element("complete");
                                $complete->set_attribute("type","Integer");
                                $child = $scrape->create_text_node(entry_read($scr,"files/".$hash_hex."/complete(Integer)","Scrape"));
                                $complete->append_child($child);

                                $incomplete = $scrape->create_element("incomplete");
                                $incomplete->set_attribute("type","Integer");
                                $child = $scrape->create_text_node(entry_read($scr,"files/".$hash_hex."/incomplete(Integer)","Scrape"));
                                $incomplete->append_child($child);

                                $downloaded = $scrape->create_element("downloaded");
                                $downloaded->set_attribute("type","Integer");
                                $child = $scrape->create_text_node(entry_read($scr,"files/".$hash_hex."/downloaded(Integer)","Scrape"));
                                $downloaded->append_child($child);

                                $item->append_child($complete);
                                $item->append_child($incomplete);
                                $item->append_child($downloaded);

                                $files->append_child($item);
                        }
                        unset($scr);

                       // ob_flush();
                        sleep(2);
                }

                $root->append_child($files);
                $scrape->append_child($root);
                echo "</div>";
                        echo "<div style=\"overflow: auto; border: 1px; white-space: nowrap; margin: 0px; padding: 2px; width: 100%; height: 300px;\">";
                        echo str_replace(Array(" ","\n"),Array("&nbsp;","<br />\n"),htmlspecialchars($scrape->dump_mem(true,"UTF-8")));
                        echo "</div>\n";
        }

        foreach ($infohashes as $hash) {
                $hash_hex = preg_replace_callback('/./s', "hex_esc", str_pad($hash,20));
						$hash_hex = "a".$hash_hex;
                if ($support == "selective" AND !entry_exists($scrape,"files/".$hash_hex."(Dictionary)","Scrape")) {
                        $support = "global";
                        $db->sql_query("UPDATE ".$db_prefix."_trackers SET support = 'global' WHERE id = '".$id."';");
                echo "<meta http-equiv=\"refresh\" content=\"0;url=admin.php?op=scrapenow&id=".$id."\">";
				die;
						}
                if (!entry_exists($scrape,"files/".$hash_hex."(Dictionary)","Scrape")) {
                        $seed = $leech = $completed = 0;
                } else {

                        $seed = entry_read($scrape,"files/".$hash_hex."/complete(Integer)","Scrape");
                        $leech = entry_read($scrape,"files/".$hash_hex."/incomplete(Integer)","Scrape");
                        $completed = entry_read($scrape,"files/".$hash_hex."/downloaded(Integer)","Scrape");
                        $name = ((entry_exists($scrape,"files/".$hash_hex."/name(String)","Scrape")) ? entry_read($scrape,"files/".$hash_hex."/name(String)","Scrape") : "");
                }
                if (($seed + $leech) > 0) $visible = "yes";
                else $visible = "no";
                echo "<p>".str_replace(Array("**seed**","**leechers**","**completed**","**name**","**hash**"),Array($seed,$leech,$completed,htmlspecialchars($name),$hash_hex),_admtrksummarystr)."</p>";
                $sql = "UPDATE ".$db_prefix."_torrents SET seeders = ". $seed .", leechers = ".$leech.", tot_peer = ". ($seed + $leech) .", completed = ". $completed .", visible = '".$visible."', last_action = NOW() WHERE info_hash = '".addslashes($hash)."';";
                $db->sql_query($sql) or btsqlerror($sql);
        }
        unset($scrape);
        $db->sql_query("UPDATE ".$db_prefix."_trackers SET updated = NOW(), status = 'active' WHERE id = '".$id."';");


        } while (false);
        CloseTable();
}

OpenTable(_admbannewtracker);
echo "<p>"._admbannewtrackerintro."</p>\n";
echo "<p>&nbsp;</p>\n";
echo "<form action=\"admin.php\" method=\"POST\">\n";
echo "<input type=\"hidden\" name=\"op\" value=\"bannewtracker\" />\n";
echo "<table width=\"50%\" cellpadding=\"0\" cellspacing=\"0\">\n";
echo "<tr><td><p>"._admtrackerurl."</p></td><td><input type=\"text\" name=\"announce\" /></td></tr>\n";
echo "</table>\n";
echo "<p><input type=\"submit\" value=\""._btsend."\" /></p>";
echo "</form>\n";
CloseTable();
?>


http://a.imageshack.us/img831/5562/mybikes.png
Previous Topic:minor error upon user registration email confirmation (non-fatal)
Next Topic:Problem with Upload
Goto Forum:
  


Current Time: Wed Feb 08 11:27:12 GMT 2012

Total time taken to generate the page: 0.00849 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software