예제 #1
0
function _wobi_addWebseedfiles($torrent_file_path, $relative_path, $httplocation, $hash)
{
    $prefix = WOBI_PREFIX;
    $fd = fopen($torrent_file_path, "rb") or die(errorMessage() . "File upload error 1</p>");
    $alltorrent = fread($fd, filesize($torrent_file_path));
    fclose($fd);
    $array = BDecode($alltorrent);
    // Add in Bittornado HTTP seeding spec
    //
    //add information into database
    $info = $array["info"] or die("Invalid torrent file.");
    $fsbase = $relative_path;
    // We need single file only!
    mysql_query("INSERT INTO " . $prefix . "webseedfiles (info_hash,filename,startpiece,endpiece,startpieceoffset,fileorder) values (\"{$hash}\", \"" . mysql_real_escape_string($fsbase) . "\", 0, " . (strlen($array["info"]["pieces"]) / 20 - 1) . ", 0, 0)");
    // Edit torrent file
    //
    $data_array = $array;
    $data_array["httpseeds"][0] = WOBI_URL . "/seed.php";
    //$data_array["url-list"][0] = $httplocation;
    $to_write = BEncode($data_array);
    //write torrent file
    $write_httpseed = fopen($torrent_file_path, "wb");
    fwrite($write_httpseed, $to_write);
    fclose($write_httpseed);
    //add in piecelength and number of pieces
    $query = "UPDATE " . $prefix . "summary SET piecelength=\"" . $info["piece length"] . "\", numpieces=\"" . strlen($array["info"]["pieces"]) / 20 . "\" WHERE info_hash=\"" . $hash . "\"";
    quickQuery($query);
}
예제 #2
0
function ParseTorrent($filename)
{
    require_once "BDecode.php";
    require_once "BEncode.php";
    $TorrentInfo = array();
    global $array;
    //check file type is a torrent
    $torrent = explode(".", $filename);
    $fileend = end($torrent);
    $fileend = strtolower($fileend);
    if ($fileend == "torrent") {
        $parseme = @file_get_contents("{$filename}");
        if ($parseme == FALSE) {
            show_error_msg(T_("ERROR"), T_("PARSE_CONTENTS"), 1);
        }
        if (!isset($parseme)) {
            show_error_msg(T_("ERROR"), T_("PARSE_OPEN"), 1);
        } else {
            $array = BDecode($parseme);
            if ($array === FALSE) {
                show_error_msg(T_("ERROR"), T_("PARSE_DECODE"), 1);
            } else {
                if (!@count($array['info'])) {
                    show_error_msg(T_("ERROR"), T_("PARSE_OPEN"), 1);
                } else {
                    //Get Announce URL
                    $TorrentInfo[0] = $array["announce"];
                    //Get Announce List Array
                    if (isset($array["announce-list"])) {
                        $TorrentInfo[6] = $array["announce-list"];
                    }
                    //Read info, store as (infovariable)
                    $infovariable = $array["info"];
                    // Calculates SHA1 Hash
                    $infohash = sha1(BEncode($infovariable));
                    $TorrentInfo[1] = $infohash;
                    // Calculates date from UNIX Epoch
                    $makedate = date('r', $array["creation date"]);
                    $TorrentInfo[2] = $makedate;
                    // The name of the torrent is different to the file name
                    $TorrentInfo[3] = $infovariable['name'];
                    //Get File List
                    if (isset($infovariable["files"])) {
                        // Multi File Torrent
                        $filecount = "";
                        //Get filenames here
                        $TorrentInfo[8] = $infovariable["files"];
                        foreach ($infovariable["files"] as $file) {
                            $filecount += "1";
                            $multiname = $file['path'];
                            //Not needed here really
                            $multitorrentsize = $file['length'];
                            $torrentsize += $file['length'];
                        }
                        $TorrentInfo[4] = $torrentsize;
                        //Add all parts sizes to get total
                        $TorrentInfo[5] = $filecount;
                        //Get file count
                    } else {
                        // Single File Torrent
                        $torrentsize = $infovariable['length'];
                        $TorrentInfo[4] = $torrentsize;
                        //Get file count
                        $TorrentInfo[5] = "1";
                    }
                    // Get Torrent Comment
                    if (isset($array['comment'])) {
                        $TorrentInfo[7] = $array['comment'];
                    }
                }
            }
        }
    }
    return $TorrentInfo;
}
function addTorrent()
{
    global $dbhost, $dbuser, $dbpass, $database;
    global $_POST, $_FILES;
    require_once "funcsv2.php";
    require_once "BDecode.php";
    require_once "BEncode.php";
    $hash = strtolower($_POST["hash"]);
    $db = mysql_connect($dbhost, $dbuser, $dbpass) or die("<p class=\"error\">Couldn't connect to database. contact the administrator</p>");
    mysql_select_db($database) or die("<p class=\"error\">Can't open the database.</p>");
    if (isset($_FILES["torrent"])) {
        if ($_FILES["torrent"]["error"] != 4) {
            $fd = fopen($_FILES["torrent"]["tmp_name"], "rb") or die("<p class=\"error\">File upload error 1</p>\n");
            is_uploaded_file($_FILES["torrent"]["tmp_name"]) or die("<p class=\"error\">File upload error 2</p>\n");
            $alltorrent = fread($fd, filesize($_FILES["torrent"]["tmp_name"]));
            $array = BDecode($alltorrent);
            if (!$array) {
                echo "<p class=\"error\">There was an error handling your uploaded torrent. The parser didn't like it.</p>";
                endOutput();
                exit;
            }
            $hash = @sha1(BEncode($array["info"]));
            fclose($fd);
            unlink($_FILES["torrent"]["tmp_name"]);
        }
    }
    if (isset($_POST["filename"])) {
        $filename = clean($_POST["filename"]);
    } else {
        $filename = "";
    }
    if (isset($_POST["url"])) {
        $url = clean($_POST["url"]);
    } else {
        $url = "";
    }
    if (isset($_POST["info"])) {
        $info = clean($_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 "<p class=\"error\">Error: Info hash must be exactly 40 hex bytes.</p>";
            endOutput();
        }
        $query = "INSERT INTO BTPHP_namemap (info_hash, filename, url, info) VALUES (\"{$hash}\", \"{$filename}\", \"{$url}\", \"{$info}\")";
        $status = makeTorrent($hash, true);
        quickQuery($query);
        if ($status) {
            echo "<p class=\"error\">Torrent was added successfully.</p>";
        } else {
            echo "<p class=\"error\">There were some errors. Check if this torrent had been added previously.</p>";
        }
    }
    endOutput();
}
예제 #4
0
}
if ($_GET['trackers']) {
    $data = @file_get_contents("trackers.dat");
    $data = BDecode($data);
    $array = array();
    foreach ($data as $url => $value) {
        $array[] = urldecode($url);
    }
    $array = BEncode($array);
    die($array);
}
// This is used in anaupdatesnodes.py
if ($_GET['strackers']) {
    $data = @file_get_contents("strackers.dat");
    $data = BDecode($data);
    $array = array();
    foreach ($data as $url) {
        $array[] = urldecode($url);
    }
    $array = BEncode($array);
    echo $array;
    $random2 = array_rand($data, 1);
    $random = $data[$random2];
    // Checks a random supertracker is alive
    if (ping($random) === FALSE) {
        unset($data[$random2]);
        $data = BEncode($data);
        writedata($data, "strackers.dat");
    }
    die;
}
예제 #5
0
SQL_Query_exec("UPDATE torrents SET hits = hits + 1 WHERE id = {$id}");
require_once "backend/BEncode.php";
require_once "backend/BDecode.php";
//if user dont have a passkey generate one, only if tracker is set to members only
if ($site_config["MEMBERSONLY"]) {
    if (strlen($CURUSER['passkey']) != 32) {
        $rand = array_sum(explode(" ", microtime()));
        $CURUSER['passkey'] = md5($CURUSER['username'] . $rand . $CURUSER['secret'] . $rand * mt_rand());
        SQL_Query_exec("UPDATE users SET passkey='{$CURUSER['passkey']}' WHERE id={$CURUSER['id']}");
    }
}
if ($row["external"] != 'yes' && $site_config["MEMBERSONLY"]) {
    // local torrent so add passkey
    $dict = BDecode(file_get_contents($fn));
    $dict['announce'] = sprintf($site_config["PASSKEYURL"], $CURUSER["passkey"]);
    unset($dict['announce-list']);
    $data = BEncode($dict);
    //header('Content-Disposition: attachment; filename="'.$name.'"');
    header('Content-Disposition: attachment; filename=' . sqlesc($name) . '');
    //header('Content-Length: ' . strlen($data));
    header("Content-Type: application/x-bittorrent");
    print $data;
} else {
    // external torrent so no passkey needed
    //header('Content-Disposition: attachment; filename="'.$name.'"');
    header('Content-Disposition: attachment; filename=' . sqlesc($name) . '');
    header('Content-Length: ' . filesize($fn));
    header("Content-Type: application/x-bittorrent");
    readfile($fn);
}
mysql_close();
예제 #6
0
(at your option) any later version.

Bittytorrent 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 Bittytorrent.  If not, see <http://www.gnu.org/licenses/>. 
*/
require_once $path . '/libs/class.bdecode.php';
require_once $path . '/libs/class.bencode.php';
// To create info hash of torrent
$torrent = new BDECODE($path . '/uploads/torrents/' . $_GET['info_hash'] . '.torrent');
$resultTorrent = $torrent->result;
$hash = sha1(BEncode($resultTorrent['info']));
// var_dump($resultTorrent['info']);
// Calcul the total size of content torrent
if (isset($resultTorrent["info"]) && $resultTorrent["info"]) {
    $upfile = $resultTorrent["info"];
} else {
    $upfile = 0;
}
if (isset($upfile["length"])) {
    $size = (double) $upfile["length"];
} else {
    if (isset($upfile["files"])) {
        // multifiles torrent
        $size = 0;
        foreach ($upfile["files"] as $file) {
            $size += (double) $file["length"];
예제 #7
0
        require_once $path . '/libs/class.bencode.php';
        $fd = fopen($path . '/uploads/torrents/' . $torrent->info_hash . '.torrent', "rb");
        $mainTorrent = fread($fd, filesize($path . '/uploads/torrents/' . $torrent->info_hash . '.torrent'));
        // $array = new BDecode($mainTorrent);
        $torrentDecode = new BDECODE($path . '/uploads/torrents/' . $torrent->info_hash . '.torrent');
        $array = $torrentDecode->result;
        $array["announce"] = $conf['baseurl'] . "/announce?pid=" . $userData->private_id;
        if (isset($array["announce-list"]) && is_array($array["announce-list"])) {
            for ($i = 0; $i < count($array["announce-list"]); $i++) {
                for ($j = 0; $j < count($array["announce-list"][$i]); $j++) {
                    if (in_array($array["announce-list"][$i][$j], $conf['baseurl'] . "/announce")) {
                        if (strpos($array["announce-list"][$i][$j], "announce.php") === false) {
                            $array["announce-list"][$i][$j] = trim(str_replace("/announce", "/announce/" . $userData->private_id, $array["announce-list"][$i][$j]));
                        } else {
                            $array["announce-list"][$i][$j] = trim(str_replace("/announce.php", "/announce.php?pid={$pid}", $array["announce-list"][$i][$j]));
                        }
                    }
                }
            }
        }
        $mainTorrent = BEncode($array);
        fclose($fd);
        header("Content-Type: application/x-bittorrent");
        header('Content-Disposition: attachment; filename="[' . $conf['title'] . '] ' . $torrent->title . '.torrent"');
        print $mainTorrent;
    } else {
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
        // Set 404, no reference to anything on the search engines!
        // $smarty->assign('notFound',true);
    }
}
예제 #8
0
             //single file
             mysql_query("INSERT INTO " . $prefix . "webseedfiles (info_hash,filename,startpiece,endpiece,startpieceoffset,fileorder) values (\"{$hash}\", \"" . mysql_real_escape_string($fsbase) . "\", 0, " . (strlen($array["info"]["pieces"]) / 20 - 1) . ", 0, 0)");
         }
     }
     if ($_POST["getrightseed"] == "enabled" || $_POST["httpseed"] == "enabled") {
         //edit torrent file
         $read_httpseed = fopen("torrents/" . $filename . ".torrent", "rb");
         $binary_data = fread($read_httpseed, filesize("torrents/" . $filename . ".torrent"));
         $data_array = BDecode($binary_data);
         if ($_POST["httpseed"] == "enabled") {
             $data_array["httpseeds"][0] = $website_url . substr($_SERVER['REQUEST_URI'], 0, -15) . "seed.php";
         }
         if ($_POST["getrightseed"] == "enabled") {
             $data_array["url-list"][0] = $_POST["httpftplocation"];
         }
         $to_write = BEncode($data_array);
         fclose($read_httpseed);
         //write torrent file
         $write_httpseed = fopen("torrents/" . $filename . ".torrent", "wb");
         fwrite($write_httpseed, $to_write);
         fclose($write_httpseed);
     }
     //add in piecelength and number of pieces
     $query = "UPDATE " . $prefix . "summary SET piecelength=\"" . $info["piece length"] . "\", numpieces=\"" . strlen($array["info"]["pieces"]) / 20 . "\" WHERE info_hash=\"" . $hash . "\"";
     quickQuery($query);
 }
 if (!isset($_POST["hash"])) {
     //don't display admin link if coming from index.php
     echo "<a href='admin.php'><img src='images/admin.png' border='0' class='icon' alt='Admin Page' title='Admin Page' /></a><a href='admin.php'>Return to Admin Page</a><br>";
 }
 ?>
예제 #9
0
파일: wobi.php 프로젝트: j3k0/Wobi
function _wobi_addTorrent($torrent_file_path, $torrent_file_url, $file_path, $file_url)
{
    require "config.php";
    $tracker_url = WOBI_TRACKER_URL;
    $httpseed = true;
    $tmp1 = explode("/wp-content/", $file_path);
    $relative_path = "../../" . $tmp1[1];
    $getrightseed = false;
    $httpftplocation = $file_url;
    $target_path = "torrents/";
    $autoset = true;
    $filename = "";
    // $file_path; // Extracted from torrent (if $autoset)
    $url = "{$file_url}";
    // Extracted from torrent (if $autoset)
    $hash = "";
    // Extracted from torrent (if $autoset)
    // TODO: Only if not already connected.
    // $db = mysql_connect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Couldn't connect to the database, contact the administrator.</p>");
    // mysql_select_db($database) or die(errorMessage() . "Can't open the database.</p>");
    require_once "funcsv2.php";
    require_once "BDecode.php";
    require_once "BEncode.php";
    // Check for errors, we don't care right?
    $fd = fopen($torrent_file_path, "rb") or die(_wobi_errorMessage() . "File upload error 1</p>\n");
    // is_uploaded_file($torrent_file_path) or die(_wobi_errorMessage() . "File upload error 2</p>\n");
    $alltorrent = fread($fd, filesize($torrent_file_path));
    $array = BDecode($alltorrent);
    if (!$array) {
        $wobi_error = _wobi_errorMessage() . "Error: The parser was unable to load your torrent.  Please re-create and re-upload the torrent.</p>\n";
        return false;
    }
    if (strtolower($array["announce"]) != $tracker_url) {
        $wobi_error = _wobi_errorMessage() . "Error: The tracker announce URL does not match this:<br>{$tracker_url}<br>Please re-create and re-upload the torrent.</p>\n";
        return false;
    }
    if ($httpseed && $relative_path == "") {
        $wobi_error = _wobi_errorMessage() . "Error: HTTP seeding was checked however no relative path was given.</p>\n";
        return false;
    }
    if ($httpseed && $relative_path != "") {
        if (Substr($relative_path, -1) == "/") {
            if (!is_dir($relative_path)) {
                $wobi_error = _wobi_errorMessage() . "Error: HTTP seeding relative path ends in / but is not a valid directory.</p>\n";
                return false;
            }
        } else {
            if (!is_file($relative_path)) {
                $wobi_error = _wobi_errorMessage() . "Error: HTTP seeding relative path is not a valid file.</p>\n";
                return false;
            }
        }
    }
    if ($getrightseed && $httpftplocation == "") {
        $wobi_error = _wobi_errorMessage() . "Error: GetRight HTTP seeding was checked however no URL was given.</p>\n";
        return false;
    }
    if ($getrightseed && (Substr($httpftplocation, 0, 7) != "http://" && Substr($httpftplocation, 0, 6) != "ftp://")) {
        $wobi_error = _wobi_errorMessage() . "Error: GetRight HTTP seeding URL must start with http:// or ftp://</p>\n";
        return false;
    }
    $hash = @sha1(BEncode($array["info"]));
    fclose($fd);
    $target_path = $target_path . basename($torrent_file_path);
    $move_torrent = rename($torrent_file_path, $target_path);
    if ($move_torrent == false) {
        $wobi_error = errorMessage() . "Unable to move {$torrent_file_path} to torrents/</p>\n";
    }
    if (!empty($filename)) {
        // XXX can probably remove this...
        $filename = clean($filename);
    }
    if (!empty($url)) {
        // XXX and this
        $url = clean($url);
    }
    if ($autoset) {
        if (strlen($filename) == 0 && isset($array["info"]["name"])) {
            $filename = $array["info"]["name"];
        }
    }
    //figure out total size of all files in torrent
    $info = $array["info"];
    $total_size = 0;
    if (isset($info["files"])) {
        foreach ($info["files"] as $file) {
            $total_size = $total_size + $file["length"];
        }
    } else {
        $total_size = $info["length"];
    }
    //Validate torrent file, make sure everything is correct
    $filename = mysql_escape_string($filename);
    $filename = htmlspecialchars(clean($filename));
    $url = htmlspecialchars(mysql_escape_string($url));
    if (strlen($hash) != 40 || !verifyHash($hash)) {
        $wobi_error = _wobi_errorMessage() . "Error: Info hash must be exactly 40 hex bytes.</p>\n";
        return false;
    }
    if (Substr($url, 0, 7) != "http://" && $url != "") {
        $wobi_error = _wobi_errorMessage() . "Error: The Torrent URL does not start with http:// Make sure you entered a correct URL.</p>\n";
        return false;
    }
    $query = "INSERT INTO " . $prefix . "namemap (info_hash, filename, url, size, pubDate) VALUES (\"{$hash}\", \"{$filename}\", \"{$url}\", \"{$total_size}\", \"" . date('D, j M Y h:i:s') . "\")";
    $status = makeTorrent($hash, true);
    quickQuery($query);
    chmod($target_path, 0644);
    if ($status) {
        $wobi_error = "<p class=\"success\">Torrent was added successfully.</p>\n";
        require_once "wobi_functions.php";
        _wobi_addWebseedfiles($target_path, $relative_path, $httpftplocation, $hash);
        return true;
    } else {
        $wobi_error = _wobi_errorMessage() . "There were some errors. Check if this torrent has been added previously.</p>\n";
        return false;
    }
}
예제 #10
0
파일: newtorrents.php 프로젝트: j3k0/Wobi
function addTorrent()
{
    require "config.php";
    $tracker_url = $website_url . substr($_SERVER['REQUEST_URI'], 0, -15) . "announce.php";
    $hash = strtolower($_POST["hash"]);
    $db = mysql_connect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Couldn't connect to the database, contact the administrator</p>");
    mysql_select_db($database) or die(errorMessage() . "Can't open the database.</p>");
    require_once "funcsv2.php";
    require_once "BDecode.php";
    require_once "BEncode.php";
    if ($_FILES["torrent"]["error"] != 4) {
        $fd = fopen($_FILES["torrent"]["tmp_name"], "rb") or die(errorMessage() . "File upload error 1</p>\n");
        is_uploaded_file($_FILES["torrent"]["tmp_name"]) or die(errorMessage() . "File upload error 2</p>\n");
        $alltorrent = fread($fd, filesize($_FILES["torrent"]["tmp_name"]));
        $array = BDecode($alltorrent);
        if (!$array) {
            echo errorMessage() . "Error: The parser was unable to load your torrent.  Please re-create and re-upload the torrent.</p>\n";
            endOutput();
            exit;
        }
        if (strtolower($array["announce"]) != $tracker_url) {
            echo errorMessage() . "Error: The tracker announce URL does not match this:<br>{$tracker_url}<br>Please re-create and re-upload the torrent.</p>\n";
            endOutput();
            exit;
        }
        if ($_POST["httpseed"] == "enabled" && $_POST["relative_path"] == "") {
            echo errorMessage() . "Error: HTTP seeding was checked however no relative path was given.</p>\n";
            endOutput();
            exit;
        }
        if ($_POST["httpseed"] == "enabled" && $_POST["relative_path"] != "") {
            if (Substr($_POST["relative_path"], -1) == "/") {
                if (!is_dir($_POST["relative_path"])) {
                    echo errorMessage() . "Error: HTTP seeding relative path ends in / but is not a valid directory.</p>\n";
                    endOutput();
                    exit;
                }
            } else {
                if (!is_file($_POST["relative_path"])) {
                    echo errorMessage() . "Error: HTTP seeding relative path is not a valid file.</p>\n";
                    endOutput();
                    exit;
                }
            }
        }
        if ($_POST["getrightseed"] == "enabled" && $_POST["httpftplocation"] == "") {
            echo errorMessage() . "Error: GetRight HTTP seeding was checked however no URL was given.</p>\n";
            endOutput();
            exit;
        }
        if ($_POST["getrightseed"] == "enabled" && (Substr($_POST["httpftplocation"], 0, 7) != "http://" && Substr($_POST["httpftplocation"], 0, 6) != "ftp://")) {
            echo errorMessage() . "Error: GetRight HTTP seeding URL must start with http:// or ftp://</p>\n";
            endOutput();
            exit;
        }
        $hash = @sha1(BEncode($array["info"]));
        fclose($fd);
        $target_path = "torrents/";
        $target_path = $target_path . basename(clean($_FILES['torrent']['name']));
        $move_torrent = move_uploaded_file($_FILES["torrent"]["tmp_name"], $target_path);
        if ($move_torrent == false) {
            echo errorMessage() . "Unable to move " . $_FILES["torrent"]["tmp_name"] . " to torrents/</p>\n";
        }
    }
    if (isset($_POST["filename"])) {
        $filename = clean($_POST["filename"]);
    } else {
        $filename = "";
    }
    if (isset($_POST["url"])) {
        $url = clean($_POST["url"]);
    } else {
        $url = "";
    }
    if (isset($_POST["autoset"])) {
        if (strcmp($_POST["autoset"], "enabled") == 0) {
            if (strlen($filename) == 0 && isset($array["info"]["name"])) {
                $filename = $array["info"]["name"];
            }
        }
    }
    //figure out total size of all files in torrent
    $info = $array["info"];
    $total_size = 0;
    if (isset($info["files"])) {
        foreach ($info["files"] as $file) {
            $total_size = $total_size + $file["length"];
        }
    } else {
        $total_size = $info["length"];
    }
    //Validate torrent file, make sure everything is correct
    $filename = mysql_escape_string($filename);
    $filename = htmlspecialchars(clean($filename));
    $url = htmlspecialchars(mysql_escape_string($url));
    if (strlen($hash) != 40 || !verifyHash($hash)) {
        echo errorMessage() . "Error: Info hash must be exactly 40 hex bytes.</p>\n";
        endOutput();
    }
    if (Substr($url, 0, 7) != "http://" && $url != "") {
        echo errorMessage() . "Error: The Torrent URL does not start with http:// Make sure you entered a correct URL.</p>\n";
        endOutput();
    }
    $query = "INSERT INTO " . $prefix . "namemap (info_hash, filename, url, size, pubDate) VALUES (\"{$hash}\", \"{$filename}\", \"{$url}\", \"{$total_size}\", \"" . date('D, j M Y h:i:s') . "\")";
    $status = makeTorrent($hash, true);
    quickQuery($query);
    if ($status) {
        echo "<p class=\"success\">Torrent was added successfully.</p>\n";
        echo "<a href=\"newtorrents.php\"><img src=\"images/add.png\" border=\"0\" class=\"icon\" alt=\"Add Torrent\" title=\"Add Torrent\" /></a><a href=\"newtorrents.php\">Add Another Torrent</a><br>\n";
        //rename torrent file to match filename
        rename("torrents/" . clean($_FILES['torrent']['name']), "torrents/" . $filename . ".torrent");
        //make torrent file readable by all
        chmod("torrents/" . $filename . ".torrent", 0644);
        //run RSS generator
        require_once "rss_generator.php";
        //Display information from DumpTorrentCGI.php
        require_once "torrent_functions.php";
    } else {
        echo errorMessage() . "There were some errors. Check if this torrent has been added previously.</p>\n";
        //delete torrent file if it doesn't exist in database
        $query = "SELECT COUNT(*) FROM " . $prefix . "summary WHERE info_hash = '{$hash}'";
        $results = mysql_query($query) or die(errorMessage() . "Can't do SQL query - " . mysql_error() . "</p>");
        $data = mysql_fetch_row($results);
        if ($data[0] == 0) {
            if (file_exists("torrents/" . $_FILES['torrent']['name'])) {
                unlink("torrents/" . $_FILES['torrent']['name']);
            }
        }
        //make torrent file readable by all
        chmod("torrents/" . $filename . ".torrent", 0644);
        endOutput();
    }
}
예제 #11
0
파일: takeupload.php 프로젝트: klldll/tbdev
    if (mysql_errno() == 1062) {
        bark("torrent already uploaded!");
    }
    bark("mysql puked: " . mysql_error());
}
$id = mysql_insert_id();
sql_query('INSERT INTO torrents_descr (tid, descr_hash, descr_parsed) VALUES (' . implode(', ', array_map('sqlesc', array($id, md5($descr), format_comment($descr)))) . ')') or sqlerr(__FILE__, __LINE__);
sql_query("INSERT INTO checkcomm (checkid, userid, torrent) VALUES ({$id}, {$CURUSER['id']}, 1)") or sqlerr(__FILE__, __LINE__);
sql_query("DELETE FROM files WHERE torrent = {$id}");
foreach ($filelist as $file) {
    sql_query("INSERT INTO files (torrent, filename, size) VALUES ({$id}, " . sqlesc($file[0]) . ", " . $file[1] . ")");
}
move_uploaded_file($tmpname, "{$torrent_dir}/{$id}.torrent");
$fp = fopen("{$torrent_dir}/{$id}.torrent", "w");
if ($fp) {
    $dict_str = BEncode($dict);
    @fwrite($fp, $dict_str, strlen($dict_str));
    fclose($fp);
}
write_log("Торрент номер {$id} ({$torrent}) был залит пользователем " . $CURUSER["username"], "5DDB6E", "torrent");
// Этой фигней ваще кто-то пользуется?
/* Email notify */
/*******************

$res = sql_query("SELECT name FROM categories WHERE id=$catid") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_assoc($res);
$cat = $arr["name"];
$res = sql_query("SELECT email FROM users WHERE enabled='yes' AND notifs LIKE '%[cat$catid]%'") or sqlerr(__FILE__, __LINE__);
$uploader = $CURUSER['username'];

$size = mksize($totallen);
예제 #12
0
파일: download.php 프로젝트: klldll/tbdev
sql_query("UPDATE torrents SET hits = hits + 1 WHERE id = " . sqlesc($id));
$name = str_replace(array(',', ';'), '', $name);
require_once "include/BDecode.php";
require_once "include/BEncode.php";
if (strlen($CURUSER['passkey']) != 32) {
    $CURUSER['passkey'] = md5($CURUSER['username'] . get_date_time() . $CURUSER['passhash']);
    sql_query("UPDATE users SET passkey=" . sqlesc($CURUSER[passkey]) . " WHERE id=" . sqlesc($CURUSER[id]));
}
$dict = bdecode(file_get_contents($fn));
//$dict['announce'] = $announce_urls[0]."?passkey=$CURUSER[passkey]";//"$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";
if (!empty($dict['announce-list'])) {
    $dict['announce-list'][][0] = $announce_urls[0] . "?passkey={$CURUSER['passkey']}";
    // Just add one tracker for multitrackers, we are the last
} else {
    $dict['announce'] = $announce_urls[0] . "?passkey={$CURUSER['passkey']}";
}
//"$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";
header("Expires: Tue, 1 Jan 1980 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//header ("X-Powered-by: TBDev Yuna Scatari Edition - http://bit-torrent.kiev.ua");
header("Accept-Ranges: bytes");
header("Connection: close");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"" . $name . "\"");
header("Content-Type: application/x-bittorrent");
ob_implicit_flush(true);
print BEncode($dict);
예제 #13
0
파일: index.php 프로젝트: acfan/ttm
session_start();
if (!isset($_SESSION["id"])) {
    $_SESSION["id"] = mt_rand(0, 10000);
}
//echo $_SESSION["id"];
$src = "";
$file = $_FILES["torrent"];
//var_dump($file);
move_uploaded_file($file["tmp_name"], "torrent/" . $file["name"]);
$name = "torrent/" . $file["name"];
//echo $name;
$an = md5_file($name);
$torrent_content = file_get_contents($name);
$desc = BDecode($torrent_content);
$info = $desc['info'];
$hash = strtoupper(sha1(BEncode($info)));
$src = "magnet:?xt=urn:btih:" . $hash;
$zip = new ZipArchive();
if ($zip->open($an . ".zip", ZipArchive::OVERWRITE) === TRUE) {
    # code...
    $zip->addFile($name);
    $zip->close();
    $_SESSION["name"] = $an . ".zip";
}
?>
	<body>
	<div>
		<h1> 种子转换为神秘代码</h1>
		<form action="" method="POST" enctype="multipart/form-data">
			<input type="file" name="torrent">
			<input type="submit" value="提交">
예제 #14
0
     $array = BDecode($alltorrent);
     if (!isset($array)) {
         err_msg($language["ERROR"], $language["ERR_PARSER"]);
         stdfoot();
         exit;
     }
     if (!$array) {
         err_msg($language["ERROR"], $language["ERR_PARSER"]);
         stdfoot();
         exit;
     }
     if (in_array($array["announce"], $TRACKER_ANNOUNCEURLS) && $DHT_PRIVATE) {
         $array["info"]["private"] = 1;
         $hash = sha1(BEncode($array["info"]));
     } else {
         $hash = sha1(BEncode($array["info"]));
     }
     fclose($fd);
 }
 if (isset($_POST["filename"])) {
     $filename = mysql_real_escape_string(htmlspecialchars($_POST["filename"]));
 } else {
     $filename = mysql_real_escape_string(htmlspecialchars($_FILES["torrent"]["name"]));
 }
 if (isset($_POST["moder"])) {
     $moder = $_POST["moder"];
 }
 if (isset($_POST["tag"])) {
     $tag = mysql_real_escape_string(htmlspecialchars($_POST["tag"]));
 } else {
     $tag = "";
예제 #15
0
 }
 //Update the members uploaded torrent count
 /*if ($ret){
 		SQL_Query_exec("UPDATE users SET torrents = torrents + 1 WHERE id = $userid");*/
 if ($id == 0) {
     unlink("{$torrent_dir}/{$fname}");
     $message = T_("UPLOAD_NO_ID");
     show_error_msg(T_("UPLOAD_FAILED"), $message, 1);
 }
 rename("{$torrent_dir}/{$fname}", "{$torrent_dir}/{$id}.torrent");
 // Edit Torrent Comment
 require_once "backend/BDecode.php";
 require_once "backend/BEncode.php";
 $dict = BDecode(file_get_contents($site_config["torrent_dir"] . "/{$id}.torrent"));
 $dict['comment'] = "Torrent downloaded from " . $site_config['SITENAME'];
 file_put_contents($site_config["torrent_dir"] . "/{$id}.torrent", BEncode($dict));
 // End Edit Torrent Comment
 if (count($filelist)) {
     foreach ($filelist as $file) {
         $dir = '';
         $size = $file["length"];
         $count = count($file["path"]);
         for ($i = 0; $i < $count; $i++) {
             if ($i + 1 == $count) {
                 $fname = $dir . $file["path"][$i];
             } else {
                 $dir .= $file["path"][$i] . "/";
             }
         }
         SQL_Query_exec("INSERT INTO `files` (`torrent`, `path`, `filesize`) VALUES({$id}, " . sqlesc($fname) . ", {$size})");
     }
예제 #16
0
파일: download.php 프로젝트: wilian32/xbtit
        $array["announce"] = $XBTT_URL . "/{$pid}/announce";
        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]));
                    }
                }
            }
        }
    } else {
        $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 = BEncode($array);
    header("Content-Type: application/x-bittorrent");
    header('Content-Disposition: attachment; filename="' . $f . '"');
    print $alltorrent;
}
예제 #17
-1
파일: apms.lib.php 프로젝트: peb317/gbamn
function apms_get_torrent($attach, $path = '')
{
    global $g5;
    $arr = array();
    $torrent = array();
    if ($path) {
        $j = 0;
        for ($i = 0; $i < count($attach); $i++) {
            if (isset($attach[$i]['source']) && $attach[$i]['source'] && $attach[$i]['view']) {
                continue;
            }
            $ext = apms_get_ext($attach[$i]['source']);
            if ($ext != 'torrent') {
                continue;
            }
            $arr[$j] = $path . '/' . $attach[$i]['file'];
            $j++;
        }
    } else {
        if (!$attach['torrent']) {
            return;
        }
        $j = 0;
        for ($i = 0; $i < count($attach); $i++) {
            if ($attach[$i]['ext'] != "6") {
                continue;
            }
            $arr[$j] = G5_DATA_PATH . '/item/' . $attach[$i]['id'] . '/' . $attach[$i]['file'];
            $j++;
        }
    }
    require_once G5_LIB_PATH . '/apms.torrent.lib.php';
    for ($i = 0; $i < count($arr); $i++) {
        $torrent_file = file_get_contents($arr[$i]);
        $torrent_array = BDecode($torrent_file);
        $torrent_hash = sha1(BEncode($torrent_array['info']));
        $torrent[$i]['name'] = $torrent_array['info']['name'];
        $torrent[$i]['magnet'] = 'magnet:?xt=urn:btih:' . $torrent_hash;
        for ($k = 0; $k < count($torrent_array['announce-list']); $k++) {
            $torrent[$i]['tracker'][$k] = $torrent_array['announce-list'][$k][0];
        }
        $torrent[$i]['comment'] = $torrent_array['comment'];
        $torrent[$i]['date'] = $torrent_array['creation date'];
        $torrent[$i]['is_size'] = $torrent_array['info']['length'] ? true : false;
        if ($torrent[$i]['is_size']) {
            $torrent[$i]['info']['name'] = $torrent_array['info']['name'];
            $torrent[$i]['info']['size'] = get_filesize($torrent_array['info']['length']);
        } else {
            $total_size = 0;
            for ($k = 0; $k < count($torrent_array['info']['files']); $k++) {
                for ($l = 0; $l < count($torrent_array['info']['files'][$k]['path']); $l++) {
                    $torrent[$i]['info']['file'][$k]['name'][$l] = $torrent_array['info']['files'][$k]['path'][$l];
                }
                $torrent[$i]['info']['file'][$k]['size'] = get_filesize($torrent_array['info']['files'][$k]['length']);
                $total_size = $total_size + $torrent_array['info']['files'][$k]['length'];
            }
            $torrent[$i]['info']['total_size'] = get_filesize($total_size);
        }
    }
    return $torrent;
}