Example #1
0
function scrape($url, $infohash = "")
{
    global $db;
    if (isset($url)) {
        $u = urldecode($url);
        $extannunce = str_replace("announce", "scrape", $u);
        $purl = parse_url($extannunce);
        $port = isset($purl["port"]) ? $purl["port"] : "80";
        $path = isset($purl["path"]) ? $purl["path"] : "/scrape.php";
        $an = ($purl["scheme"] != "http" ? $purl["scheme"] . "://" : "") . $purl["host"];
        $fd = @fsockopen($an, $port, $errno, $errstr, 60);
        if ($fd) {
            if ($infohash != "") {
                $ihash = array();
                $ihash = explode("','", $infohash);
                $info_hash = "";
                foreach ($ihash as $myihash) {
                    $info_hash .= "&info_hash=" . escapeURL($myihash);
                }
                $info_hash = substr($info_hash, 1);
                fputs($fd, "GET " . $path . "?" . $info_hash . " HTTP/1.0\r\nHost: somehost.net\r\n\r\n");
            } else {
                fputs($fd, "GET " . $path . " HTTP/1.0\r\nHost: somehost.net\r\n\r\n");
            }
            $stream = "";
            while (!feof($fd)) {
                $stream .= fgets($fd, 4096);
                if (strlen($stream) > 100000) {
                    $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')"));
                    write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (response too big)", "");
                    @fclose($fd);
                    return;
                }
            }
        } else {
            $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')"));
            write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not connectable)", "");
            return;
        }
        @fclose($fd);
        $stream = utf8::trim(stristr($stream, "d5:files"));
        if (strpos($stream, "d5:files") === false) {
            // if host answer but stream is not valid encoded file try old metod
            // will work only with standard http
            $ihash = array();
            $ihash = explode("','", $infohash);
            $info_hash = "";
            foreach ($ihash as $myihash) {
                $info_hash .= "&info_hash=" . escapeURL($myihash);
            }
            $info_hash = substr($info_hash, 1);
            $fd = fopen($extannunce . ($infohash != "" ? "?{$info_hash}" : ""), "rb");
            if ($fd) {
                while (!feof($fd)) {
                    $stream .= fread($fd, 4096);
                    if (strlen($stream) > 100000) {
                        $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')"));
                        write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (response too big)", "");
                        @fclose($fd);
                        return;
                    }
                }
            } else {
                $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')"));
                write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not connectable)", "");
                return;
            }
        }
        $array = bencdec::decode($stream);
        if (!isset($array)) {
            $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')"));
            write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not bencode data)", "");
            return;
        }
        if ($array == false) {
            $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')"));
            write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (not bencode data)", "");
            return;
        }
        if (!isset($array["files"])) {
            $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')"));
            write_log("FAILED update external " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " torrent from " . $url . " tracker (not bencode data)", "");
            return;
        }
        $files = $array["files"];
        if (!is_array($files)) {
            $ret = $db->query("UPDATE namemap SET lastupdate = NOW() WHERE announce_url = '" . $url . "'" . ($infohash == "" ? "" : " AND namemap.info_hash IN ('" . $infohash . "')"));
            write_log("FAILED update external torrent " . ($infohash == "" ? "" : "(infohash: " . $infohash . ")") . " from " . $url . " tracker (probably deleted torrent(s))", "");
            return;
        }
        foreach ($files as $hash => $data) {
            $seeders = (int) $data["complete"];
            $leechers = (int) $data["incomplete"];
            if (isset($data["downloaded"])) {
                $completed = (int) $data["downloaded"];
            } else {
                $completed = "0";
            }
            $torrenthash = bin2hex(stripslashes($hash));
            $ret = $db->query("UPDATE namemap SET lastupdate = NOW(), lastsuccess = NOW() WHERE announce_url = '" . $url . "'" . ($hash == "" ? "" : " AND namemap.info_hash = '" . $torrenthash . "'"));
            $ret = $db->query("UPDATE summary INNER JOIN namemap ON namemap.info_hash = summary.info_hash SET summary.seeds = " . $seeders . ", summary.leechers = " . $leechers . ", summary.finished = " . $completed . " WHERE summary.info_hash = '" . $torrenthash . "' AND namemap.announce_url = '" . $url . "'");
            if ($db->affected_rows == 1) {
                write_log("SUCCESS update external torrent from " . $url . " tracker (infohash: " . $torrenthash . ")", "");
            }
        }
    }
}
Example #2
0
$result = $db->query("SELECT * FROM namemap WHERE info_hash = '" . $infohash . "'");
$row = $result->fetch_assoc();
if ($row["external"] == "yes" || !$PRIVATE_ANNOUNCE) {
    $fd = fopen($filepath, "rb");
    $alltorrent = fread($fd, filesize($filepath));
    fclose($fd);
    header("Content-Type: application/x-bittorrent");
    header('Content-Disposition: attachment; filename="' . AddSlashes($f) . '"');
    print $alltorrent;
} else {
    $fd = fopen($filepath, "rb");
    $alltorrent = fread($fd, filesize($filepath));
    //uTorrent v3.x.x fix
    $alltorrent = preg_replace("/file-mediali(.*?)ee(.*?):/i", "file-mediali0ee\$2:", $alltorrent);
    $alltorrent = preg_replace("/file-durationli(.*?)ee(.*?):/i", "file-durationli0ee\$2:", $alltorrent);
    $array = bencdec::decode($alltorrent);
    fclose($fd);
    $array["announce"] = $BASEURL . "/announce.php?pid=" . $pid;
    if (isset($array["announce-list"]) && is_array($array["announce-list"])) {
        for ($i = 0; $i < count($array["announce-list"]); $i++) {
            if (in_array($array["announce-list"][$i][0], $TRACKER_ANNOUNCEURLS)) {
                if (strpos($array["announce-list"][$i][0], "announce.php") === false) {
                    $array["announce-list"][$i][0] = trim(str_replace("/announce", "/" . $pid . "/announce", $array["announce-list"][$i][0]));
                } else {
                    $array["announce-list"][$i][0] = trim(str_replace("/announce.php", "/announce.php?pid=" . $pid . "", $array["announce-list"][$i][0]));
                }
            }
        }
    }
    $alltorrent = bencdec::encode($array);
    header("Content-Type: application/x-bittorrent");
Example #3
0
     obj[id1].style.display = 'block';
    }
    else {
     obj[id].style.display = 'block';
     obj[id1].style.display = 'none';
    }
}
</script>
<?php 
require_once CLASS_PATH . 'class.Bencode.php';
if (file_exists($row["url"])) {
    print "\n    <tr>\n    <td align='right' class='header' valign='top'>\n    <a name='#expand' href='#expand' onclick=\"javascript:ShowHide('files', 'msgfile');\">Show/Hide Files: </td>\n    <td align='left' class='lista'>\n    <div name='files' style='display:none' id='files'>\n        <table class='lista'>\n        <tr>\n        <td align='center' class='header'>" . FILE_NAME . "</td>\n        <td align='center' class='header'>" . SIZE . "</td>\n        </tr>";
    $ffile = fopen($row["url"], "rb");
    $content = fread($ffile, filesize($row["url"]));
    fclose($ffile);
    $content = bencdec::decode($content);
    $numfiles = 0;
    if (isset($content["info"]) && $content["info"]) {
        $thefile = $content["info"];
        if (isset($thefile["length"])) {
            $numfiles++;
            print "\n<tr>\n<td align='left' class='lista'>" . security::html_safe($thefile["name"]) . "</td>\n<td align='right' class='lista'>" . misc::makesize((int) $thefile["length"]) . "</td></tr>\n";
        } elseif (isset($thefile["files"])) {
            foreach ($thefile["files"] as $singlefile) {
                print "\n<tr>\n<td align='left' class='lista'>" . security::html_safe(implode("/", $singlefile["path"])) . "</td>\n<td align='right' class='lista'>" . misc::makesize((int) $singlefile["length"]) . "</td></tr>\n";
                $numfiles++;
            }
        } else {
            print "\n<tr>\n<td colspan='2'>No Data...</td></tr>\n";
            // can't be but...
        }
Example #4
0
 $fd = fopen($_FILES["torrent"]["tmp_name"], "rb") or die(FILE_UPLOAD_ERROR_1);
 is_uploaded_file($_FILES["torrent"]["tmp_name"]) or die(FILE_UPLOAD_ERROR_2);
 $length = filesize($_FILES["torrent"]["tmp_name"]);
 if ($length) {
     $alltorrent = fread($fd, $length);
 } else {
     err_msg(ERROR, FILE_UPLOAD_ERROR_3);
     print "</td></tr></table>";
     block_end();
     stdfoot();
     exit;
 }
 //uTorrent v3.x.x fix
 $alltorrent = preg_replace("/file-mediali(.*?)ee(.*?):/i", "file-mediali0ee\$2:", $alltorrent);
 $alltorrent = preg_replace("/file-durationli(.*?)ee(.*?):/i", "file-durationli0ee\$2:", $alltorrent);
 $array = bencdec::decode($alltorrent, bencdec::OPTION_EXTENDED_VALIDATION);
 if (!isset($array)) {
     echo "<font color='red'>" . ERR_PARSER . "</FONT>";
     endOutput();
     exit;
 }
 if (!$array) {
     echo "<font color='red'>" . ERR_PARSER . "</FONT>";
     endOutput();
     exit;
 }
 if (in_array($array["announce"], $TRACKER_ANNOUNCEURLS) && $DHT_PRIVATE) {
     $array["info"]["private"] = 1;
     $hash = sha1(bencdec::encode($array["info"]));
 } else {
     $hash = sha1(bencdec::encode($array["info"]));