Example #1
0
 public function getTransmission()
 {
     if (null === $this->transmission) {
         $client = new Client($this->params->getRpcHost(), $this->params->getRpcPort());
         if ($this->params->doAuthentication()) {
             $client->authenticate($this->params->getRpcUser(), $this->params->getRpcPass());
         }
         $transmission = new Transmission($this->params->getRpcHost(), $this->params->getRpcPort());
         $transmission->setClient($client);
         $this->transmission = $transmission;
     }
     return $this->transmission;
 }
 function testGet()
 {
     $this->mockTransmission->torrentGet();
 }
 /**
  * @test
  */
 public function shouldRemoveDownloadWithRemovingLocalData()
 {
     $client = $this->getMock('Transmission\\Client');
     $client->expects($this->once())->method('call')->with('torrent-remove', array('ids' => array(1), 'delete-local-data' => true))->will($this->returnCallback(function () {
         return (object) array('result' => 'success');
     }));
     $torrent = new Torrent();
     $torrent->setId(1);
     $transmission = new Transmission();
     $transmission->setClient($client);
     $transmission->remove($torrent, true);
 }
Example #4
0
 public function processAction(Request $request)
 {
     // Initialize filesystem Manager
     $filesystem = new Filesystem();
     // init var
     $user_username = "";
     $user_password = "";
     $transmission_dir = "";
     $transmission_tmp = "";
     $transmission_hostname = "127.0.0.1";
     $transmission_port = "9091";
     $transmission_authentication = "";
     $transmission_username = "";
     $transmission_password = "";
     // Load Core if INSTALL doesn't exist
     if (!$filesystem->exists('../INSTALL')) {
         return $this->redirect($this->generateUrl('app_feather_login'));
     } else {
         // Check transmissions settings
         if ($request->isMethod('POST')) {
             if ($request->request->get('_transmission_lostinfo') == true) {
                 $transmission_hostname = "127.0.0.1";
                 $transmission_port = "9091";
                 $transmission_authentication = true;
                 $transmission_username = "******";
                 $transmission_password = "******";
             } else {
                 if ($request->request->get('_transmission_hostname')) {
                     $transmission_hostname = $request->request->get('_transmission_hostname');
                 }
                 if ($request->request->get('_transmission_port')) {
                     $transmission_port = $request->request->get('_transmission_port');
                 }
                 if ($request->request->get('_transmission_authentication') == true) {
                     $transmission_username = $request->request->get('_transmission_username');
                     $transmission_password = $request->request->get('_transmission_password');
                 }
             }
             // Set username and password value
             $user_username = $request->request->get('_user_username');
             $user_password = $request->request->get('_user_password');
             // Set dir and tmp value
             $transmission_dir = $request->request->get('_transmission_dir');
             $transmission_tmp = $transmission_dir . "/tmp";
             // Turn on/off authentication transmission
             if ($transmission_authentication == true) {
                 // Initialize client infos
                 $client = new Client($transmission_hostname, $transmission_port);
                 $client->authenticate($transmission_username, $transmission_password);
                 // Intialize transmission
                 $transmission = new Transmission();
                 $transmission->setClient($client);
             } else {
                 $transmission = new Transmission();
             }
             // Instance of basepath
             $this->basepath = $this->container->get('kernel')->getRootdir() . "/config";
             // Instance of form setting
             $this->_user_username = $user_username;
             $this->_user_password = $user_password;
             $this->_transmission_dir = $transmission_dir;
             $this->_transmission_tmp = $transmission_tmp;
             $this->_transmission_hostname = $transmission_hostname;
             $this->_transmission_port = $transmission_port;
             if ($transmission_authentication == true) {
                 $this->_transmission_authentication = "true";
             } else {
                 $this->_transmission_authentication = "false";
             }
             $this->_transmission_username = $transmission_username;
             $this->_transmission_password = $transmission_password;
             // Create download repository
             if (!is_dir($this->_transmission_dir)) {
                 if (!@mkdir($this->_transmission_dir)) {
                     // Return flashbag info_box
                     $session = $request->getSession();
                     $session->getFlashBag()->add('error', 'Vous n\'avez pas les permissions suffisantes pour créer ce dossier de téléchargement. Veuiller en choisir un autre ou vous autoriser les droit de création!');
                     return $this->redirect($this->generateUrl('app_feather_install_step'));
                 } else {
                     $filesystem->mkdir($this->_transmission_dir, $mode = 0777);
                 }
                 if (!is_dir($this->_transmission_tmp)) {
                     $filesystem->mkdir($this->_transmission_tmp, $mode = 0777);
                 }
             }
             // Redirect to the next step if all checkpoints is green
             return $this->processexecAction();
         } else {
             // Return flashbag info_box
             $session = $request->getSession();
             $session->getFlashBag()->add('error', 'Merci de saisir correctements les informations.');
             return $this->redirect($this->generateUrl('app_feather_install_step'));
         }
     }
 }
Example #5
0
 public function stopAction($id)
 {
     // Convert string($id) to integer
     $id = intval($id);
     // Checking authentication parameter
     $transmission_authentication = $this->container->getParameter('transmission_authentication');
     // Get download and  temporary path
     $transmission_dir = $this->container->getParameter('transmission_dir');
     $transmission_tmp = $this->container->getParameter('transmission_tmp');
     // Checking if transmission authentication is enabled
     if ($transmission_authentication == true) {
         $this->username = $this->container->getParameter('transmission_username');
         $this->password = $this->container->getParameter('transmission_password');
         // Initialize Client
         if (!isset($client)) {
             $client = new Client();
             $client->authenticate($this->username, $this->password);
         }
     }
     // Initialize Transmission Connector
     $transmission = new Transmission();
     $transmission->setClient($client);
     // Configuring many var of transmission and save as session
     $session = $transmission->getSession();
     $session->setDownloadDir($transmission_dir);
     $session->setIncompleteDir($transmission_tmp);
     $session->setIncompleteDirEnabled(true);
     $session->save();
     // Remove torrent with get id
     $transmission->get($id)->stop();
     // Sleep 2 seconds for update transmission infos
     sleep(2);
     // Return redirect uri to the core controller
     return $this->redirect($this->generateUrl('app_feather_core'));
 }
 /**
  * Gets torrents based on id, if no id is set then returns all torrents
  *
  * @param bool|false $allFields
  * @param array $ids
  * @param array $chosenFields
  *
  * @return mixed
  */
 public function torrentGet($allFields = false, array $ids = [], array $chosenFields = [])
 {
     $payload = ["method" => "torrent-get", "arguments" => []];
     if (count($chosenFields) == 0) {
         $payload["arguments"]['fields'] = $allFields ? Transmission::allGetFields() : Transmission::$basicGetFields;
     } else {
         $payload["arguments"]['fields'] = $chosenFields;
     }
     if (count($ids) != 0) {
         $payload["arguments"]['ids'] = $ids;
     }
     return $this->client->request($payload);
 }