Ejemplo n.º 1
0
function FetchTorrent($url)
{
    global $cfg, $db;
    ini_set("allow_url_fopen", "1");
    ini_set("user_agent", $_SERVER["HTTP_USER_AGENT"]);
    $domain = parse_url($url);
    if (strtolower(substr($domain["path"], -8)) != ".torrent") {
        // Check know domain types
        if (strpos(strtolower($domain["host"]), "mininova") !== false) {
            // Sample (http://www.mininova.org/rss.xml):
            // http://www.mininova.org/tor/2254847
            // <a href="/get/2281554">FreeLinux.ISO.iso.torrent</a>
            // If received a /tor/ get the required information
            if (strpos($url, "/tor/") !== false) {
                // Get the contents of the /tor/ to find the real torrent name
                $html = FetchHTML($url);
                // Check for the tag used on mininova.org
                if (preg_match("/<a href=\"\\/get\\/[0-9].[^\"]+\">(.[^<]+)<\\/a>/i", $html, $html_preg_match)) {
                    // This is the real torrent filename
                    $cfg["save_torrent_name"] = $html_preg_match[1];
                }
                // Change to GET torrent url
                $url = str_replace("/tor/", "/get/", $url);
            }
            // Now fetch the torrent file
            $html = FetchHTML($url);
            // This usually gets triggered if the original URL was /get/ instead of /tor/
            if (!isset($cfg["save_torrent_name"]) || strlen($cfg["save_torrent_name"]) == 0) {
                // Get the name of the torrent, and make it the filename
                if (preg_match("/name([0-9][^:]):(.[^:]+)/i", $html, $html_preg_match)) {
                    $filelength = $html_preg_match[1];
                    $filename = $html_preg_match[2];
                    $cfg["save_torrent_name"] = substr($filename, 0, $filelength) . ".torrent";
                } else {
                    $cfg["save_torrent_name"] = "unknown.torrent";
                }
            }
            // Make sure we have a torrent file
            if (strpos($html, "d8:") === false) {
                // We don't have a Torrent File... it is something else
                AuditAction($cfg["constants"]["error"], "BAD TORRENT for: " . $url . "\n" . $html);
                $html = "";
            }
            return $html;
        } elseif (strpos(strtolower($domain["host"]), "isohunt") !== false) {
            // Sample (http://isohunt.com/js/rss.php):
            // http://isohunt.com/download.php?mode=bt&id=8837938
            // http://isohunt.com/btDetails.php?ihq=&id=8464972
            $referer = "http://" . $domain["host"] . "/btDetails.php?id=";
            // If the url points to the details page, change it to the download url
            if (strpos(strtolower($url), "/btdetails.php?") !== false) {
                $url = str_replace("/btDetails.php?", "/download.php?", $url) . "&mode=bt";
                // Need to make it grab the torrent
            }
            // Grab contents of details page
            $html = FetchHTML($url, $referer);
            // Get the name of the torrent, and make it the filename
            if (preg_match("/name([0-9][^:]):(.[^:]+)/i", $html, $html_preg_match)) {
                $filelength = $html_preg_match[1];
                $filename = $html_preg_match[2];
                $cfg["save_torrent_name"] = substr($filename, 0, $filelength) . ".torrent";
            } else {
                $cfg["save_torrent_name"] = "unknown.torrent";
            }
            // Make sure we have a torrent file
            if (strpos($html, "d8:") === false) {
                // We don't have a Torrent File... it is something else
                AuditAction($cfg["constants"]["error"], "BAD TORRENT for: " . $url . "\n" . $html);
                $html = "";
            }
            return $html;
        } elseif (strpos(strtolower($url), "details.php?") !== false) {
            // Sample (http://www.bitmetv.org/rss.php?passkey=123456):
            // http://www.bitmetv.org/details.php?id=18435&hit=1
            $referer = "http://" . $domain["host"] . "/details.php?id=";
            $html = FetchHTML($url, $referer);
            // Sample (http://www.bitmetv.org/details.php?id=18435)
            // download.php/18435/SpiderMan%20Season%204.torrent
            if (preg_match("/(download.php.[^\"]+)/i", $html, $html_preg_match)) {
                $torrent = str_replace(" ", "%20", substr($html_preg_match[0], 0, -1));
                $url2 = "http://" . $domain["host"] . "/" . $torrent;
                $html2 = FetchHTML($url2);
                // Make sure we have a torrent file
                if (strpos($html2, "d8:") === false) {
                    // We don't have a Torrent File... it is something else
                    AuditAction($cfg["constants"]["error"], "BAD TORRENT for: " . $url . "\n" . $html2);
                    $html2 = "";
                }
                return $html2;
            } else {
                return "";
            }
        } elseif (strpos(strtolower($url), "download.asp?") !== false) {
            // Sample (TF's TorrenySpy Search):
            // http://www.torrentspy.com/download.asp?id=519793
            $referer = "http://" . $domain["host"] . "/download.asp?id=";
            $html = FetchHTML($url, $referer);
            // Get the name of the torrent, and make it the filename
            if (preg_match("/name([0-9][^:]):(.[^:]+)/i", $html, $html_preg_match)) {
                $filelength = $html_preg_match[1];
                $filename = $html_preg_match[2];
                $cfg["save_torrent_name"] = substr($filename, 0, $filelength) . ".torrent";
            } else {
                $cfg["save_torrent_name"] = "unknown.torrent";
            }
            if (!empty($html)) {
                // Make sure we have a torrent file
                if (strpos($html, "d8:") === false) {
                    // We don't have a Torrent File... it is something else
                    AuditAction($cfg["constants"]["error"], "BAD TORRENT for: " . $url . "\n" . $html);
                    $html = "";
                }
                return $html;
            } else {
                return "";
            }
        }
    }
    $html = FetchHTML($url);
    // Make sure we have a torrent file
    if (strpos($html, "d8:") === false) {
        // We don't have a Torrent File... it is something else
        AuditAction($cfg["constants"]["error"], "BAD TORRENT for: " . $url . "\n" . $html);
        $html = "";
    } else {
        // Get the name of the torrent, and make it the filename
        if (preg_match("/name([0-9][^:]):(.[^:]+)/i", $html, $html_preg_match)) {
            $filelength = $html_preg_match[1];
            $filename = $html_preg_match[2];
            $cfg["save_torrent_name"] = substr($filename, 0, $filelength) . ".torrent";
        } else {
            $cfg["save_torrent_name"] = "unknown.torrent";
        }
    }
    return $html;
}
 function makeRequest($request, $useAlt = false)
 {
     $rtnVal = false;
     if (isset($_SESSION['lastOutBoundURI'])) {
         $refererURI = $_SESSION['lastOutBoundURI'];
     } else {
         $refererURI = "http://" . $this->mainURL;
     }
     if ($useAlt) {
         $request = "http://" . $this->altURL . $request;
     } else {
         $request = "http://" . $this->mainURL . $request;
     }
     $this->htmlPage = FetchHTML($request, $refererURI);
     $rtnVal = true;
     return $rtnVal;
 }