Ejemplo n.º 1
0
 /**
  * Upload un torrent
  * 
  * @access public
  * @return View torrent.upload
  *
  */
 public function upload()
 {
     $user = Auth::user();
     // Post et fichier upload
     if (Request::isMethod('post')) {
         // No torrent file uploaded OR an Error has occurred
         if (Input::hasFile('torrent') == false) {
             Session::put('message', 'You must provide a torrent for the upload');
             return View::make('torrent.upload', array('categories' => Category::all(), 'user' => $user));
         } else {
             if (Input::file('torrent')->getError() != 0 && Input::file('torrent')->getClientOriginalExtension() != 'torrent') {
                 Session::put('message', 'An error has occurred');
                 return View::make('torrent.upload', array('categories' => Category::all(), 'user' => $user));
             }
         }
         // Deplace et decode le torrent temporairement
         TorrentTools::moveAndDecode(Input::file('torrent'));
         // Array from decoded from torrent
         $decodedTorrent = TorrentTools::$decodedTorrent;
         // Tmp filename
         $fileName = TorrentTools::$fileName;
         // Info sur le torrent
         $info = Bencode::bdecode_getinfo(getcwd() . '/files/torrents/' . $fileName, true);
         // Si l'announce est invalide ou si le tracker et privée
         if ($decodedTorrent['announce'] != route('announce', ['passkey' => $user->passkey]) && Config::get('other.freeleech') == true) {
             Session::put('message', 'Your announce URL is invalid');
             return View::make('torrent.upload', array('categories' => Category::all(), 'user' => $user));
         }
         // Find the right category
         $category = Category::find(Input::get('category_id'));
         // Create the torrent (DB)
         $torrent = new Torrent(['name' => Input::get('name'), 'slug' => Str::slug(Input::get('name')), 'description' => Input::get('description'), 'info_hash' => $info['info_hash'], 'file_name' => $fileName, 'num_file' => $info['info']['filecount'], 'announce' => $decodedTorrent['announce'], 'size' => $info['info']['size'], 'nfo' => Input::hasFile('nfo') ? TorrentTools::getNfo(Input::file('nfo')) : '', 'category_id' => $category->id, 'user_id' => $user->id]);
         // Validation
         $v = Validator::make($torrent->toArray(), $torrent->rules);
         if ($v->fails()) {
             if (file_exists(getcwd() . '/files/torrents/' . $fileName)) {
                 unlink(getcwd() . '/files/torrents/' . $fileName);
             }
             Session::put('message', 'An error has occured may bee this file is already online ?');
         } else {
             // Savegarde le torrent
             $torrent->save();
             // Compte et sauvegarde le nombre de torrent dans  cette catégorie
             $category->num_torrent = Torrent::where('category_id', '=', $category->id)->count();
             $category->save();
             // Sauvegarde les fichiers que contient le torrent
             $fileList = TorrentTools::getTorrentFiles($decodedTorrent);
             foreach ($fileList as $file) {
                 $f = new TorrentFile();
                 $f->name = $file['name'];
                 $f->size = $file['size'];
                 $f->torrent_id = $torrent->id;
                 $f->save();
                 unset($f);
             }
             return Redirect::route('torrent', ['slug' => $torrent->slug, 'id' => $torrent->id])->with('message', trans('torrent.your_torrent_is_now_seeding'));
         }
     }
     return View::make('torrent.upload', array('categories' => Category::all(), 'user' => $user));
 }
 public function __construct($binary = null)
 {
     parent::__construct();
     if ($binary) {
         $this->setBinary($binary);
     }
 }
 public function __construct($text = null)
 {
     parent::__construct();
     if ($text) {
         $this->setText($text);
     }
 }
 public function __construct()
 {
     parent::__construct();
     $this->getTorrent()->setCreated_by(self::DEFAULT_CREATED_BY);
     $this->getTorrent()->setCreation_date(time());
 }
Ejemplo n.º 5
0
 public function deleteTorrent($id)
 {
     TorrentFile::where('torrent_id', '=', $id)->delete();
     Torrent::where('id', '=', $id)->delete();
     return Redirect::to('/')->with('success', 'Torrent deleted.');
 }
Ejemplo n.º 6
0
#!/usr/bin/php
<?php 
ini_set("log_errors", 1);
ini_set("extension", "mongo.so");
ini_set("error_log", "/tmp/php-error.log");
require_once '/var/www/torrentcloud/models/FileDB.php';
require_once '/var/www/torrentcloud/models/TorrentDB.php';
require_once '/var/www/torrentcloud/models/Torrent.php';
require_once '/var/www/torrentcloud/models/Helper.php';
require_once '/var/www/torrentcloud/models/File.php';
require_once '/var/www/torrentcloud/models/TorrentFile.php';
require_once '/var/www/torrentcloud/models/getid3/getid3.php';
$fileDB = new FileDB();
$torrentDB = new TorrentDB();
$torrentHash = getenv('TR_TORRENT_HASH');
$torrentData = $torrentDB->get($torrentHash);
$torrent = new Torrent($torrentData);
foreach ($torrent->files as $file) {
    $name = basename($file['name']);
    $extension = pathinfo($name, PATHINFO_EXTENSION);
    $path = $torrent->downloadDir . '/' . $file['name'];
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $MIME_type = finfo_file($finfo, $path);
    $fileData = array(FileDB::TORRENT_HASH => $torrent->hashString, FileDB::NAME => $name, FileDB::EXTENSION => $extension, FileDB::SIZE => $file['length'], FileDB::PATH => $path, FileDB::MIME_TYPE => $MIME_type);
    $torrentFile = new TorrentFile($fileData);
    $torrentFile->analyze();
    $fileDB->add($torrentFile);
}