/**
 * init
 */
function transfer_init()
{
    global $cfg, $tmpl, $transfer, $transferLabel, $ch;
    // request-var
    $transfer = tfb_getRequestVar('transfer');
    if (empty($transfer)) {
        @error("missing params", "", "", array('transfer'));
    }
    // validate transfer
    if (tfb_isValidTransfer($transfer) !== true) {
        AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer);
        @error("Invalid Transfer", "", "", array($transfer));
    }
    // permission
    if (!$cfg['isAdmin'] && !IsOwner($cfg["user"], getOwner($transfer))) {
        AuditAction($cfg["constants"]["error"], "ACCESS DENIED: " . $transfer);
        @error("Access Denied", "", "", array($transfer));
    }
    // get label
    $transferLabel = strlen($transfer) >= 39 ? substr($transfer, 0, 35) . "..." : $transfer;
    // set transfer vars
    $tmpl->setvar('transfer', $transfer);
    $tmpl->setvar('transferLabel', $transferLabel);
    $tmpl->setvar('transfer_exists', transferExists($transfer) ? 1 : 0);
}
예제 #2
0
/**
 * init
 */
function transfer_init()
{
    global $cfg, $tmpl, $transfer, $transferLabel, $ch;
    // request-var
    $transfer = tfb_getRequestVar('transfer');
    if (empty($transfer)) {
        @error("missing params", "", "", array('transfer'));
    }
    if ($cfg["transmission_rpc_enable"] && isHash($transfer)) {
        require_once 'inc/functions/functions.rpc.transmission.php';
        $theTorrent = getTransmissionTransfer($transfer, array('hashString', 'id', 'name'));
        if (is_array($theTorrent)) {
            $transferLabel = strlen($theTorrent[name]) >= 39 ? substr($theTorrent[name], 0, 35) . "..." : $theTorrent[name];
            $tmpl->setvar('transfer', $theTorrent[hashString]);
            $tmpl->setvar('transferLabel', $transferLabel);
            $tmpl->setvar('transfer_exists', 0);
            return;
            // We really don't need this. Only the hash is a unique way of finding transfers. So all transfer operations should use the hash.
            /*
            			//tf compatible... erk
            			$transfer = getTransferFromHash($transfer);
            			if (empty($transfer))
            				$transfer = $theTorrent[name];
            */
        }
    }
    // validate transfer
    if (tfb_isValidTransfer($transfer) !== true) {
        AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer);
        @error("Invalid Transfer", "", "", array($transfer));
    }
    // permission
    if (!$cfg['isAdmin'] && !IsOwner($cfg["user"], getOwner($transfer))) {
        AuditAction($cfg["constants"]["error"], "ACCESS DENIED: " . $transfer);
        @error("Access Denied", "", "", array($transfer));
    }
    // get label
    $transferLabel = preg_replace("#\\.torrent\$#", "", $transfer);
    $transferLabel = strlen($transferLabel) >= 39 ? substr($transferLabel, 0, 35) . "..." : $transferLabel;
    // set transfer vars
    $tmpl->setvar('transfer', $transfer);
    $tmpl->setvar('transferLabel', $transferLabel);
    $tmpl->setvar('transfer_exists', transferExists($transfer) ? 1 : 0);
}
/**
 * (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);
    }
}
예제 #4
0
 /**
  * set transfer setting
  *
  * @param $transfer
  * @param $key
  * @param $val
  * @param $options
  * @return mixed
  */
 function _tset($transfer, $key, $val, $options)
 {
     global $cfg;
     // check transfer
     if (!transferExists($transfer)) {
         $this->_outputError("transfer does not exist.\n");
         return false;
     }
     // check params
     $settingsKeys = array('uprate' => 'NUMBER', 'downrate' => 'NUMBER', 'completion' => 'BOOL', 'sharekill' => 'NUMBER');
     if (!array_key_exists($key, $settingsKeys)) {
         $this->_outputError("invalid settings-key: " . $key . "\n");
         return false;
     }
     if (strlen($val) < 1) {
         $this->_outputError("value for " . $key . " invalid.\n");
         return false;
     }
     switch ($settingsKeys[$key]) {
         case 'NUMBER':
             if (!preg_match('/^[0-9\\-]+$/D', $val)) {
                 $this->_outputError("value for " . $key . " must be a number: " . $val . "\n");
                 return false;
             }
             break;
         case 'BOOL':
             $val = strtolower($val);
             if ($val != 'true' && $val != 'false') {
                 $this->_outputError("value for " . $key . " must be true or false: " . $val . "\n");
                 return false;
             }
             break;
     }
     // set user
     $cfg["user"] = getOwner($transfer);
     // output
     $this->_outputMessage("Setting " . $key . " to " . $val . " for " . $transfer . " for user " . $cfg["user"] . "...\n");
     // init ch-instance
     $ch = ClientHandler::getInstance(getTransferClient($transfer));
     // load settings, default if settings could not be loaded (fresh transfer)
     if ($ch->settingsLoad($transfer) !== true) {
         $ch->settingsDefault();
     }
     // autosend
     $send = strpos($options, 's') !== false && isTransferRunning($transfer);
     // set setting
     switch ($key) {
         case 'uprate':
             if ($ch->rate != $val) {
                 $ch->setRateUpload($transfer, $val, $send);
                 break;
             } else {
                 $this->_outputMessage("no changes.\n");
                 return false;
             }
         case 'downrate':
             if ($ch->drate != $val) {
                 $ch->setRateDownload($transfer, $val, $send);
                 break;
             } else {
                 $this->_outputMessage("no changes.\n");
                 return false;
             }
         case 'completion':
             if (strtolower($ch->runtime) != $val) {
                 $ch->setRuntime($transfer, $val == 'true' ? 'True' : 'False', $send);
                 break;
             } else {
                 $this->_outputMessage("no changes.\n");
                 return false;
             }
         case 'sharekill':
             if ($ch->sharekill != $val) {
                 $ch->setSharekill($transfer, $val, $send);
                 break;
             } else {
                 $this->_outputMessage("no changes.\n");
                 return false;
             }
     }
     // save
     $ch->settingsSave();
     // output + return
     if ($send) {
         $this->_outputMessage("settings saved + changes sent to client.\n");
     } else {
         $this->_outputMessage("settings saved.\n");
     }
     return true;
 }
예제 #5
0
 /**
  * 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;
     }
 }
예제 #6
0
/**
 * (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);
    }
}