/** * download and save a torrent-file * * @return boolean */ function _saveTorrent($url, $title) { global $cfg; $content = SimpleHTTP::getTorrent($url); if (SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK) { // filename $filename = SimpleHTTP::getFilename(); if ($filename != "") { $filename = strpos($filename, ".torrent") !== false ? tfb_cleanFileName($filename) : tfb_cleanFileName($filename . ".torrent"); } if ($filename == "" || $filename === false || transferExists($filename)) { $filename = tfb_cleanFileName($title . ".torrent"); if ($filename === false || transferExists($filename)) { $filename = tfb_cleanFileName($url . ".torrent"); if ($filename === false || transferExists($filename)) { $filename = tfb_cleanFileName(md5($url . strval(@microtime())) . ".torrent"); if ($filename === false || transferExists($filename)) { // Error $msg = "failed to get a valid transfer-filename for " . $url; array_push($this->messages, $msg); AuditAction($cfg["constants"]["error"], "Rssd downloadMetafile-Error : " . $msg); $this->_outputError($msg . "\n"); return false; } } } } // file $file = $this->_dirSave . $filename; // check if file already exists if (@is_file($file)) { // Error $msg = "the file " . $file . " already exists in " . $this->_dirSave; array_push($this->messages, $msg); AuditAction($cfg["constants"]["error"], "Rssd downloadMetafile-Error : " . $msg); $this->_outputError($msg . "\n"); return false; } // write file $handle = false; $handle = @fopen($file, "w"); if (!$handle) { $msg = "cannot open " . $file . " for writing."; array_push($this->messages, $msg); AuditAction($cfg["constants"]["error"], "Rssd downloadMetafile-Error : " . $msg); $this->_outputError($msg . "\n"); return false; } $result = @fwrite($handle, $content); @fclose($handle); if ($result === false) { $msg = "cannot write content to " . $file . "."; array_push($this->messages, $msg); AuditAction($cfg["constants"]["error"], "Rssd downloadMetafile-Error : " . $msg); $this->_outputError($msg . "\n"); return false; } // add to file-array array_push($this->_filesSaved, array('url' => $url, 'title' => $title, 'filename' => $filename, 'file' => $file)); // output $this->_outputMessage("torrent saved : \n url: " . $url . "\n file: " . $file . "\n"); // return return true; } else { // last op was not ok $msgs = SimpleHTTP::getMessages(); $this->_outputError("could not download torrent with title " . $title . " from url " . $url . " : \n" . implode("\n", $msgs)); return false; } }
/** * (internal) Function with which metafiles are downloaded and injected * * @param $url url to download * @param $type */ function _dispatcher_processDownload($url, $type = 'torrent', $ext = '.torrent') { global $cfg; $filename = ""; $downloadMessages = array(); if (!empty($url)) { $arURL = explode("/", $url); $filename = urldecode($arURL[count($arURL) - 1]); // get the file name $filename = str_replace(array("'", ","), "", $filename); $filename = stripslashes($filename); // Check to see if url has something like ?passkey=12345 // If so remove it. if (($point = strrpos($filename, "?")) !== false) { $filename = substr($filename, 0, $point); } $ret = strrpos($filename, "."); if ($ret === false) { $filename .= $ext; } else { if (!strcmp(strtolower(substr($filename, -strlen($ext))), $ext) == 0) { $filename .= $ext; } } $url = str_replace(" ", "%20", $url); // This is to support Sites that pass an id along with the url for downloads. $tmpId = tfb_getRequestVar("id"); if (!empty($tmpId)) { $url .= "&id=" . $tmpId; } // retrieve the file require_once "inc/classes/SimpleHTTP.php"; $content = ""; switch ($type) { default: case 'torrent': $content = SimpleHTTP::getTorrent($url); break; case 'nzb': $content = SimpleHTTP::getNzb($url); break; } if (SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK && strlen($content) > 0) { $fileNameBackup = $filename; $filename = SimpleHTTP::getFilename(); if ($filename != "") { $filename = strpos($filename, $ext) !== false ? tfb_cleanFileName($filename) : tfb_cleanFileName($filename . $ext); } if ($filename == "" || $filename === false || transferExists($filename)) { $filename = tfb_cleanFileName($fileNameBackup); if ($filename === false || transferExists($filename)) { $filename = tfb_cleanFileName($url . $ext); if ($filename === false || transferExists($filename)) { $filename = tfb_cleanFileName(md5($url . strval(@microtime())) . $ext); if ($filename === false || transferExists($filename)) { // Error array_push($downloadMessages, "failed to get a valid transfer-filename for " . $url); } } } } if (empty($downloadMessages)) { // no messages // check if content contains html if ($cfg['debuglevel'] > 0) { if (strpos($content, "<br />") !== false) { AuditAction($cfg["constants"]["debug"], "download-content contained html : " . htmlentities(addslashes($url), ENT_QUOTES)); } } if (is_file($cfg["transfer_file_path"] . $filename)) { // Error array_push($downloadMessages, "the file " . $filename . " already exists on the server."); } else { // write to file $handle = false; $handle = @fopen($cfg["transfer_file_path"] . $filename, "w"); if (!$handle) { array_push($downloadMessages, "cannot open " . $filename . " for writing."); } else { $result = @fwrite($handle, $content); @fclose($handle); if ($result === false) { array_push($downloadMessages, "cannot write content to " . $filename . "."); } } } } } else { $msgs = SimpleHTTP::getMessages(); if (count($msgs) > 0) { $downloadMessages = array_merge($downloadMessages, $msgs); } } if (empty($downloadMessages)) { // no messages AuditAction($cfg["constants"]["url_upload"], $filename); // inject injectTransfer($filename); // instant action ? $actionId = tfb_getRequestVar('aid'); if ($actionId > 1) { $ch = ClientHandler::getInstance(getTransferClient($filename)); switch ($actionId) { case 3: $ch->start($filename, false, true); break; case 2: $ch->start($filename, false, false); break; } if (count($ch->messages) > 0) { $downloadMessages = array_merge($downloadMessages, $ch->messages); } } } } else { array_push($downloadMessages, "Invalid Url : " . $url); } if (count($downloadMessages) > 0) { AuditAction($cfg["constants"]["error"], $cfg["constants"]["url_upload"] . " :: " . $filename); @error("There were Problems", "", "", $downloadMessages); } }
/** * (internal) Function with which metafiles are downloaded and injected * * @param $url url to download * @param $type */ function _dispatcher_processDownload($url, $type = 'torrent', $ext = '.torrent') { global $cfg; $filename = ""; $downloadMessages = array(); $origurl = $url; // Added by deadeyes; copied as later $url gets changed if (!empty($url)) { $hash = false; // Added by deadeyes to detect a magnet link if ($type === 'torrent' && strlen(stristr($url, 'magnet:')) > 0) { $client = getTransferClient('magnet.torrent'); // We have a magnet link :D if ($client == 'transmissionrpc' && $cfg["transmission_rpc_enable"]) { require_once 'inc/functions/functions.rpc.transmission.php'; $hash = addTransmissionTransfer($cfg['uid'], $url, $cfg['path'] . $cfg['user']); if (isHash($hash)) { startTransmissionTransfer($hash); } } if (($client == 'vuzerpc' || $client == 'azureus') && $cfg["vuze_rpc_enable"]) { require_once 'inc/functions/functions.rpc.vuze.php'; $hash = addVuzeMagnetTransfer($cfg['uid'], $url, $cfg['transfer_file_path']); } if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], "Download Magnet ({$client}) : {$hash} " . htmlentities(addslashes($url), ENT_QUOTES)); } } if (!$hash) { // not a magnet torrent.. $arURL = explode("/", $url); $filename = urldecode($arURL[count($arURL) - 1]); // get the file name $filename = str_replace(array("'", ","), "", $filename); $filename = stripslashes($filename); // Check to see if url has something like ?passkey=12345 // If so remove it. if (($point = strrpos($filename, "?")) !== false) { $filename = substr($filename, 0, $point); } $ret = strrpos($filename, "."); if ($ret === false) { $filename .= $ext; } else { if (!strcmp(strtolower(substr($filename, -strlen($ext))), $ext) == 0) { $filename .= $ext; } } $url = str_replace(" ", "%20", $url); // This is to support Sites that pass an id along with the url for downloads. $tmpId = tfb_getRequestVar("id"); if (!empty($tmpId)) { $url .= "&id=" . $tmpId; } // retrieve the file require_once "inc/classes/SimpleHTTP.php"; $content = ""; switch ($type) { default: case 'torrent': $content = SimpleHTTP::getTorrent($url); break; case 'nzb': $content = SimpleHTTP::getNzb($url); break; } if (SimpleHTTP::getState() == SIMPLEHTTP_STATE_OK && strlen($content) > 0) { $fileNameBackup = $filename; $filename = SimpleHTTP::getFilename(); if ($filename != "") { $filename = strpos($filename, $ext) !== false ? tfb_cleanFileName($filename) : tfb_cleanFileName($filename . $ext); } if (empty($filename) || transferExists($filename)) { $filename = substr($cfg['user'], 0, 3) . "_" . date('ymdHis') . "_" . sprintf('%x', crc32($filename)) . $ext; } /* if (($filename == "") || ($filename === false) || (transferExists($filename))) { $filename = tfb_cleanFileName($fileNameBackup); if (($filename === false) || (transferExists($filename))) { $filename = tfb_cleanFileName($url.$ext); if (($filename === false) || (transferExists($filename))) { $filename = tfb_cleanFileName(md5($url.strval(@microtime())).$ext); if (($filename === false) || (transferExists($filename))) { // Error array_push($downloadMessages , "failed to get a valid transfer-filename for ".$url); } } } } */ if (empty($downloadMessages)) { // no messages // check if content contains html if ($cfg['debuglevel'] > 0) { if (strpos($content, "<br />") !== false) { AuditAction($cfg["constants"]["debug"], "download-content contained html : " . htmlentities(addslashes($url), ENT_QUOTES)); } } if (is_file($cfg["transfer_file_path"] . $filename)) { // Error array_push($downloadMessages, "the file " . $filename . " already exists on the server."); } else { // write to file $handle = false; $handle = @fopen($cfg["transfer_file_path"] . $filename, "w"); if (!$handle) { array_push($downloadMessages, "cannot open " . $filename . " for writing."); } else { $result = @fwrite($handle, $content); @fclose($handle); if ($result === false) { array_push($downloadMessages, "cannot write content to " . $filename . "."); } } } } } else { $msgs = SimpleHTTP::getMessages(); if (count($msgs) > 0) { $downloadMessages = array_merge($downloadMessages, $msgs); } } if (empty($downloadMessages) && is_file($cfg["transfer_file_path"] . $filename)) { // no messages AuditAction($cfg["constants"]["url_upload"], $filename); // inject injectTransfer($filename); // instant action ? $actionId = tfb_getRequestVar('aid'); if ($actionId > 1) { $ch = ClientHandler::getInstance(getTransferClient($filename)); switch ($actionId) { case 3: $ch->start($filename, false, true); break; case 2: $ch->start($filename, false, false); break; } if (count($ch->messages) > 0) { $downloadMessages = array_merge($downloadMessages, $ch->messages); } } } } } else { array_push($downloadMessages, "Invalid Url : " . $url); } if (count($downloadMessages) > 0) { AuditAction($cfg["constants"]["error"], $cfg["constants"]["url_upload"] . " :: " . $filename); @error("There were Problems", "", "", $downloadMessages); } }