Esempio n. 1
0
 /**
  * Regenerate a torrent's file list from its meta data,
  * update the database record and clear relevant cache keys
  *
  * @param int $TorrentID
  */
 public static function regenerate_filelist($TorrentID)
 {
     $QueryID = G::$DB->get_query_id();
     G::$DB->query("\n\t\t\tSELECT tg.ID,\n\t\t\t\ttf.File\n\t\t\tFROM torrents_files AS tf\n\t\t\t\tJOIN torrents AS t ON t.ID = tf.TorrentID\n\t\t\t\tJOIN torrents_group AS tg ON tg.ID = t.GroupID\n\t\t\tWHERE tf.TorrentID = {$TorrentID}");
     if (G::$DB->has_results()) {
         list($GroupID, $Contents) = G::$DB->next_record(MYSQLI_NUM, false);
         if (Misc::is_new_torrent($Contents)) {
             $Tor = new BencodeTorrent($Contents);
             $FilePath = isset($Tor->Dec['info']['files']) ? Format::make_utf8($Tor->get_name()) : '';
         } else {
             $Tor = new TORRENT(unserialize(base64_decode($Contents)), true);
             $FilePath = isset($Tor->Val['info']->Val['files']) ? Format::make_utf8($Tor->get_name()) : '';
         }
         list($TotalSize, $FileList) = $Tor->file_list();
         foreach ($FileList as $File) {
             $TmpFileList[] = self::filelist_format_file($File);
         }
         $FileString = implode("\n", $TmpFileList);
         G::$DB->query("\n\t\t\t\tUPDATE torrents\n\t\t\t\tSET Size = {$TotalSize}, FilePath = '" . db_string($FilePath) . "', FileList = '" . db_string($FileString) . "'\n\t\t\t\tWHERE ID = {$TorrentID}");
         G::$Cache->delete_value("torrents_details_{$GroupID}");
     }
     G::$DB->set_query_id($QueryID);
 }
Esempio n. 2
0
    $Properties['Image'] = $Matches[1] . '.jpg';
}
ImageTools::blacklisted($Properties['Image']);
//******************************************************************************//
//--------------- Make variables ready for database input ----------------------//
// Shorten and escape $Properties for database input
$T = array();
foreach ($Properties as $Key => $Value) {
    $T[$Key] = "'" . db_string(trim($Value)) . "'";
    if (!$T[$Key]) {
        $T[$Key] = null;
    }
}
//******************************************************************************//
//--------------- Generate torrent file ----------------------------------------//
$Tor = new BencodeTorrent($TorrentName, true);
$PublicTorrent = $Tor->make_private();
// The torrent is now private.
$TorEnc = db_string($Tor->encode());
$InfoHash = pack('H*', $Tor->info_hash());
$DB->query("\n\tSELECT ID\n\tFROM torrents\n\tWHERE info_hash = '" . db_string($InfoHash) . "'");
if ($DB->has_results()) {
    list($ID) = $DB->next_record();
    $DB->query("\n\t\tSELECT TorrentID\n\t\tFROM torrents_files\n\t\tWHERE TorrentID = {$ID}");
    if ($DB->has_results()) {
        $Err = '<a href="torrents.php?torrentid=' . $ID . '">The exact same torrent file already exists on the site!</a>';
    } else {
        // A lost torrent
        $DB->query("\n\t\t\tINSERT INTO torrents_files (TorrentID, File)\n\t\t\tVALUES ({$ID}, '{$TorEnc}')");
        $Err = '<a href="torrents.php?torrentid=' . $ID . '">Thank you for fixing this torrent</a>';
    }
Esempio n. 3
0
<?php

$ExtraTorrentsInsert = array();
foreach ($ExtraTorrents as $ExtraTorrent) {
    $Name = $ExtraTorrent['Name'];
    $ExtraTorrentsInsert[$Name] = $ExtraTorrent;
    $ThisInsert =& $ExtraTorrentsInsert[$Name];
    $ExtraTor = new BencodeTorrent($Name, true);
    if (isset($ExtraTor->Dec['encrypted_files'])) {
        $Err = 'At least one of the torrents contain an encrypted file list which is not supported here';
        break;
    }
    if (!$ExtraTor->is_private()) {
        $ExtraTor->make_private();
        // The torrent is now private.
        $PublicTorrent = true;
    }
    // File list and size
    list($ExtraTotalSize, $ExtraFileList) = $ExtraTor->file_list();
    $ExtraDirName = isset($ExtraTor->Dec['info']['files']) ? Format::make_utf8($ExtraTor->get_name()) : '';
    $ExtraTmpFileList = array();
    foreach ($ExtraFileList as $ExtraFile) {
        list($ExtraSize, $ExtraName) = $ExtraFile;
        check_file($Type, $ExtraName);
        // Make sure the file name is not too long
        if (mb_strlen($ExtraName, 'UTF-8') + mb_strlen($ExtraDirName, 'UTF-8') + 1 > MAX_FILENAME_LENGTH) {
            $Err = "The torrent contained one or more files with too long of a name: <br />{$ExtraDirName}/{$ExtraName}";
            break;
        }
        // Add file and size to array
        $ExtraTmpFileList[] = Torrents::filelist_format_file($ExtraFile);
Esempio n. 4
0
 /**
  * Convert a stored torrent into a binary file that can be loaded in a torrent client
  *
  * @param mixed $TorrentData bencoded torrent without announce URL (new format) or TORRENT object (old format)
  * @return bencoded string
  */
 public static function get_file(&$TorrentData, $AnnounceURL)
 {
     if (Misc::is_new_torrent($TorrentData)) {
         return BencodeTorrent::add_announce_url($TorrentData, $AnnounceURL);
     }
     $Tor = new TORRENT(unserialize(base64_decode($TorrentData)), true);
     $Tor->set_announce_url($AnnounceURL);
     unset($Tor->Val['announce-list']);
     unset($Tor->Val['url-list']);
     unset($Tor->Val['libtorrent_resume']);
     return $Tor->enc();
 }