Esempio n. 1
0
 private function uploadTorrent($fileU, $dir, $start_now, $private)
 {
     if ($this->getForceDir() == 1) {
         $dir = $this->getDir();
     }
     $uploadfile = DIR_EXEC . DIR_TORRENTS . time() . basename($fileU['name']);
     if (!is_writable(DIR_EXEC . DIR_TORRENTS)) {
         $this->addMessage($this->_str['err_add_dir']);
         return false;
     }
     if (file_exists($uploadfile)) {
         $this->addMessage($this->_str['err_add_file']);
         return false;
     }
     $res[] = move_uploaded_file($fileU['tmp_name'], $uploadfile);
     chmod($uploadfile, PERM_TORRENTS);
     $message = new xmlrpcmsg("set_directory", array(new xmlrpcval($dir, 'string')));
     $result1 = $this->client->send($message);
     if ($start_now == 'on') {
         $method = 'load_start';
     } else {
         $method = 'load';
     }
     if ($private == 'on') {
         $torrent = new BDECODE($uploadfile);
         $bencode = new BEncodeLib();
         $hash = strtoupper(bin2hex(sha1($bencode->bencode($torrent->result['info']), true)));
         $this->_db->modify('INSERT INTO torrents VALUES(?, ?, 1)', $hash, $this->getIdUser());
     }
     $message = new xmlrpcmsg($method, array(new xmlrpcval($uploadfile, 'string')));
     $result2 = $this->client->send($message);
     if ($result1->errno == 0 && $result2->errno == 0 && $res[0] !== false) {
         $this->addMessage($this->_str['info_add_torrent']);
     } else {
         $this->addMessage($this->_str['err_add_torrent']);
         @unlink($uploadfile);
     }
     $message = new xmlrpcmsg("set_directory", array(new xmlrpcval(DIR_DOWNLOAD, 'string')));
     $result1 = $this->client->send($message);
 }
Esempio n. 2
0
 private function req_result($data)
 {
     $bencoder = new BEncodeLib();
     $this->connect();
     $this->sendmsg($bencoder->bencode($data));
     $result = $bencoder->bdecode($this->recvmsg());
     $this->disconnect();
     if (!is_array($result)) {
         die('Invalid responce from btpd (' . __CLASS__ . ':' . __METHOD__ . ' Line:' . __LINE__ . ')');
     }
     return $result;
 }
Esempio n. 3
0
 public function add_torrent()
 {
     if (!$this->auth->user()) {
         return 'Please login first!';
     }
     if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
         return 'No torrent file uploaded';
     }
     if (!preg_match('/^[0-9a-zA-Z _:-]/', $this->param['name'])) {
         return 'Invalid name';
     }
     $torrent = file_get_contents($_FILES['file']['tmp_name']);
     $bencoder = new BEncodeLib();
     $torrent_info = $bencoder->bdecode($torrent);
     if (!is_array($torrent_info['info'])) {
         return 'Invalis torrent file - no "info" section.';
     }
     $hash = sha1($bencoder->bencode($torrent_info['info']));
     $directory = btpdConfig::DOWNLOAD_PATH . '/download/' . $hash;
     @mkdir(btpdConfig::DOWNLOAD_PATH . '/download/');
     @mkdir($directory);
     if (!is_dir($directory)) {
         return 'Unable create download directory.';
     }
     @symlink($directory, btpdConfig::DOWNLOAD_PATH . '/' . $this->param['name']);
     $result = $this->btpd_add_torrent($torrent, $directory, $this->param['name']);
     if ($result['code'] != 0) {
         $out .= 'Error:' . $this->get_btpd_error($result['code']);
         return $out;
     }
     $out .= 'Torrent added.<BR />';
     if ($this->param['autostart'] == 'on') {
         $result = $this->btpd_start_torrent($result['num']);
         if ($resilt['code'] != 0) {
             $out .= 'Error:' . $this->get_btpd_error($result['code']);
             return $out;
         }
         $out .= 'Torrent ' . $result['num'] . ' Sarted.<br />';
     }
     return $out;
 }