Пример #1
0
 if (isset($_FILES['nfo']) && !empty($_FILES['nfo']['name'])) {
     $nfofile = $_FILES['nfo'];
     if ($nfofile['size'] == 0) {
         throw new Exception("NFO file size to small.");
     }
     if ($nfofile['size'] > 65535) {
         throw new Exception("NFO file size to big.");
     }
     $nfofilename = $nfofile['tmp_name'];
     if (@(!is_uploaded_file($nfofilename))) {
         throw new Exception("NFO file upload failed.");
     }
     $nfo = str_replace("\r\r\n", "\r\n", @file_get_contents($nfofilename));
 }
 $nfo = nfostrip($nfo);
 $dict = Bcode::bdec_file($tmpname, filesize($tmpname));
 if (!isset($dict)) {
     throw new Exception("torrent file not benc coded");
 }
 list($ann, $info) = Bcode::dict_check($dict, "announce(string):info");
 $tmaker = isset($dict['value']['created by']) && !empty($dict['value']['created by']['value']) ? $dict['value']['created by']['value'] : "Unknown";
 list($dname, $plen, $pieces) = Bcode::dict_check($info, "name(string):piece length(integer):pieces(string)");
 if (strlen($pieces) % 20 != 0) {
     throw new Exception("somthing bad happend. and we dont know what.");
 }
 $filelist = array();
 $totallen = Bcode::dict_get($info, "length", "integer");
 if (isset($totallen)) {
     $filelist[] = array($dname, $totallen);
     $type = "single";
 } else {
Пример #2
0
    $torrent_id = $_GET['torrent'];
    $torrent = new DB("torrents");
    $torrent->setColPrefix("torrent_");
    $torrent->select("torrent_id = '" . $torrent_id . "'");
    if (!$torrent->numRows()) {
        throw new Exception("File not found");
    }
    $torrent->nextRecord();
    if (!isset($_GET['passkey'])) {
        $acl = new Acl(USER_ID);
    } else {
        $db = new DB("users");
        $db->setColPrefix("user_");
        $db->select("user_passkey = '" . $db->escape($_GET['passkey']) . "'");
        if (!$db->numRows()) {
            throw new Exception("user not found");
        }
        $db->nextRecord();
        $acl = new Acl($db->id);
    }
    $fn = PATH_TORRENTS . $torrent->id . ".torrent";
    $dict = Bcode::bdec_file($fn, filesize($fn));
    $dict['value']['announce']['value'] = CMS_URL . "announce.php?passkey=" . $acl->passkey;
    $dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
    $dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
    header('Content-Disposition: attachment; filename="' . $torrent->filename . '"');
    header("Content-Type: application/x-bittorrent");
    die(Bcode::benc($dict));
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
Пример #3
0
include "../init.php";
if (isset($_POST['upload'])) {
    try {
        if (!isset($_FILES['torrent'])) {
            throw new Exception("Missing torrent data");
        }
        if (empty($_FILES['torrent']['name'])) {
            throw new Exception("No torrent file selected");
        }
        $file = $_FILES['torrent'];
        $ext = explode(".", $file['name']);
        $ext = end($ext);
        if ($ext != "torrent") {
            throw new Exception("A torrent file has to end with .torrent");
        }
        $filetmp = $_FILES['torrent']['tmp_name'];
        $dict = Bcode::bdec_file($filetmp, filesize($filetmp));
        list($ann, $info) = Bcode::dict_check($dict, "announce(string):info");
        $infohash = strtoupper(sha1($info["string"]));
        $filename = $infohash;
        $file_path = _configs()->paths->torrents . $filename;
        $magnet_link = 'magnet:?xt=urn:btih:' . $infohash . "&tr=" . implode("&tr=", _configs()->trackers);
        if (move_uploaded_file($file['tmp_name'], $file_path . '.torrent')) {
            $array = array("error" => false, "message" => "The torrent has been successfully uploaded", "url" => _configs()->website->url . $filename, "magnet" => $magnet_link);
            die(json_encode($array));
        }
    } catch (Exception $e) {
        $array = array("error" => true, "message" => $e->getMessage());
        die(json_encode($array));
    }
}