Exemple #1
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";
}
Exemple #2
0
 /**
  * Info
  * @param type $d
  * @return string
  */
 static function benc_dict($d)
 {
     $s = "d";
     $keys = array_keys($d);
     sort($keys);
     foreach ($keys as $k) {
         $v = $d[$k];
         $s .= Bcode::benc_str($k);
         $s .= Bcode::benc($v);
     }
     $s .= "e";
     return $s;
 }
Exemple #3
0
 $db->save_as = $filename;
 $db->search_text = searchfield("{$torrentName} {$dname}");
 $db->nfo = $nfo;
 $db->size = $totallen;
 $db->added = time();
 $db->type = $type;
 $db->userid = USER_ID;
 $db->numfiles = count($filelist);
 $db->category = $_POST['type'];
 $db->youtube = $_POST['youtube'];
 $db->imdb = $_POST['imdb'];
 $db->freeleech = isset($_POST['freeleech']) ? 1 : 0;
 $db->insert();
 $fp = fopen(PATH_TORRENTS . "{$id}.torrent", "w");
 if ($fp) {
     @fwrite($fp, Bcode::benc($dict), strlen(Bcode::benc($dict)));
     fclose($fp);
     $db->query("INSERT INTO {PREFIX}torrents_files (file_torrent, file_name, file_size) VALUES " . file_list($filelist, $id));
     if (isset($_POST['imdb']) && !empty($_POST['imdb'])) {
         $link = $_POST['imdb'];
     } else {
         $link = $descr;
     }
     $m = preg_match("/tt\\d{7}/", $link, $ids);
     if ($m) {
         $link = "http://www.imdb.com/title/" . $ids[0];
         $db = new DB("torrents");
         $db->torrent_imdb = $link;
         $db->update("torrent_id = '" . $db->escape($id) . "'");
         preg_match("#tt(?P<imdbId>[0-9]{7,7})#", $link, $matches);
         if (count($matches) == 0) {