/** * _dispatcher_processUpload * * @param $name * @param $tmp_name * @param $size * @param $actionId * @param &$uploadMessages * @param &$tStack * @return bool */ function _dispatcher_processUpload($name, $tmp_name, $size, $actionId, &$uploadMessages, &$tStack) { global $cfg; $filename = tfb_cleanFileName(stripslashes($name)); if ($filename === false) { // invalid file array_push($uploadMessages, "The type of file " . stripslashes($name) . " is not allowed."); array_push($uploadMessages, "\nvalid file-extensions: "); array_push($uploadMessages, $cfg["file_types_label"]); return false; } else { // file is valid if (substr($filename, -5) == ".wget") { // is enabled ? if ($cfg["enable_wget"] == 0) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload wget-file " . $filename); array_push($uploadMessages, "wget is disabled : " . $filename); return false; } else { if ($cfg["enable_wget"] == 1) { if (!$cfg['isAdmin']) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload wget-file " . $filename); array_push($uploadMessages, "wget is disabled for users : " . $filename); return false; } } } } else { if (substr($filename, -4) == ".nzb") { // is enabled ? if ($cfg["enable_nzbperl"] == 0) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload nzb-file " . $filename); array_push($uploadMessages, "nzbperl is disabled : " . $filename); return false; } else { if ($cfg["enable_nzbperl"] == 1) { if (!$cfg['isAdmin']) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload nzb-file " . $filename); array_push($uploadMessages, "nzbperl is disabled for users : " . $filename); return false; } } } } } if ($size <= $cfg["upload_limit"] && $size > 0) { //FILE IS BEING UPLOADED if (@is_file($cfg["transfer_file_path"] . $filename)) { // Error array_push($uploadMessages, "the file " . $filename . " already exists on the server."); return false; } else { if (@move_uploaded_file($tmp_name, $cfg["transfer_file_path"] . $filename)) { @chmod($cfg["transfer_file_path"] . $filename, 0644); AuditAction($cfg["constants"]["file_upload"], $filename); // inject injectTransfer($filename); // instant action ? if ($actionId > 1) { array_push($tStack, $filename); } // return return true; } else { array_push($uploadMessages, "File not uploaded, file could not be found or could not be moved: " . $cfg["transfer_file_path"] . $filename); return false; } } } else { array_push($uploadMessages, "File not uploaded, file size limit is " . $cfg["upload_limit"] . ". file has " . $size); return false; } } }
/** * Inject Transfer * * @param $transferFile * @param $username * @param $options * @param array $extra * @return mixed */ function _inject($transferFile, $username, $options = '', $extra = array()) { global $cfg; // check file if (!@is_file($transferFile)) { $this->_outputError("transfer-file " . $transferFile . " is no file.\n"); return false; } // check username if (!IsUser($username)) { $this->_outputError("username " . $username . " is no valid user.\n"); return false; } // parse options $optionsSet = $this->_parseOptions(array('d' => 0, 's' => 0, 'p' => 1), $options, $extra); if ($optionsSet === false) { return false; } $profile = isset($optionsSet['p']) ? $optionsSet['p'][0] : null; $this->_outputMessage("Inject " . $transferFile . " for user " . $username . (!empty($profile) ? " using profile " . $profile : '') . " ...\n"); // set user $cfg["user"] = $username; // set filename $transfer = basename($transferFile); $transfer = tfb_cleanFileName($transfer); // only inject valid transfers $msgs = array(); if ($transfer !== false) { $targetFile = $cfg["transfer_file_path"] . $transfer; if (@is_file($targetFile)) { array_push($msgs, "transfer " . $transfer . ", already exists."); } else { $this->_outputMessage("copy " . $transferFile . " to " . $targetFile . " ...\n"); if (@copy($transferFile, $targetFile)) { // chmod @chmod($cfg["transfer_file_path"] . $transfer, 0644); // make owner entry AuditAction($cfg["constants"]["file_upload"], $transfer); // inject $this->_outputMessage("injecting " . $transfer . " ...\n"); injectTransfer($transfer); // delete source-file if (isset($optionsSet['d'])) { $this->_outputMessage("deleting source-file " . $transferFile . " ...\n"); @unlink($transferFile); } // start if (isset($optionsSet['s'])) { // build args for _transferStart $newOptions = $this->_buildOptions('p', $optionsSet); // Pass-thru option 'p'. return $this->_transferStart($transfer, $newOptions[0], $newOptions[1]); } else { return true; } } else { array_push($msgs, "File could not be copied: " . $transferFile); } } } else { array_push($msgs, "The type of file you are injecting is not allowed."); array_push($msgs, "valid file-extensions: "); array_push($msgs, $cfg["file_types_label"]); } if (count($msgs) == 0) { $this->_outputMessage("done.\n"); return true; } else { $this->_outputError("failed: " . implode("\n", $msgs) . "\n"); return false; } }
/** * This method gets the list of transfer * * @return array */ function getTransferListArray() { global $cfg, $db, $transfers; $kill_id = ""; $lastUser = ""; $arUserTransfers = array(); $arListTransfers = array(); // settings $settings = convertIntegerToArray($cfg["index_page_settings"]); // sortOrder $sortOrder = tfb_getRequestVar("so"); if ($sortOrder == "") { $sortOrder = $cfg["index_page_sortorder"]; } if ($cfg["transmission_rpc_enable"] == 2) { require_once 'inc/functions/functions.rpc.transmission.php'; // New method for transmission-daemon transfers $result = getUserTransmissionTransfers($cfg['uid']); foreach ($result as $aTorrent) { if ($aTorrent['status'] == 4 || $aTorrent['status'] == 8) { if (!isset($cfg["total_upload"])) { $cfg["total_upload"] = 0; } if (!isset($cfg["total_download"])) { $cfg["total_download"] = 0; } $cfg["total_upload"] = $cfg["total_upload"] + GetSpeedValue($aTorrent['rateUpload'] / 1000); $cfg["total_download"] = $cfg["total_download"] + GetSpeedValue($aTorrent['rateDownload'] / 1000); } array_push($arUserTransfers, $aTorrent); } } $arList = getTransferArray($sortOrder); foreach ($arList as $transfer) { // init some vars $displayname = $transfer; $show_run = true; $transferowner = getOwner($transfer); $owner = IsOwner($cfg["user"], $transferowner); // stat $sf = new StatFile($transfer, $transferowner); // settings if (isset($transfers['settings'][$transfer])) { $settingsAry = $transfers['settings'][$transfer]; } else { $settingsAry = array(); if (substr(str_replace('.imported', '', $transfer), -8) == ".torrent") { // this is a t-client $settingsAry['type'] = "torrent"; $settingsAry['client'] = $cfg["btclient"]; } else { if (substr($transfer, -5) == ".wget") { // this is wget. $settingsAry['type'] = "wget"; $settingsAry['client'] = "wget"; } else { if (substr($transfer, -4) == ".nzb") { // this is nzbperl. $settingsAry['type'] = "nzb"; $settingsAry['client'] = "nzbperl"; } else { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer); @error("Invalid Transfer", "", "", array($transfer)); } } } $settingsAry['hash'] = ""; $settingsAry["savepath"] = $cfg["enable_home_dirs"] != 0 ? $cfg["path"] . $transferowner . '/' : $cfg["path"] . $cfg["path_incoming"] . '/'; $settingsAry['datapath'] = ""; } // cache running-flag in local var. we will access that often $transferRunning = $sf->running; // cache percent-done in local var. ... $percentDone = $sf->percent_done; // --------------------------------------------------------------------- //XFER: update1: add upload/download stats to the xfer array if ($cfg['enable_xfer'] == 1 && $cfg['xfer_realtime'] == 1) { @Xfer::update1($transfer, $transferowner, $settingsAry['client'], $settingsAry['hash'], $sf->uptotal, $sf->downtotal); } // --------------------------------------------------------------------- // injects if (!file_exists($cfg["transfer_file_path"] . $transfer . ".stat")) { $transferRunning = 2; $sf->running = "2"; $sf->size = getTransferSize($transfer); injectTransfer($transfer); } // use default client if client is not set if (!isset($settingsAry['client'])) { $settingsAry['client'] = $cfg['btclient']; } // totals-preparation // if downtotal + uptotal + progress > 0 if ($settings[2] + $settings[3] + $settings[5] > 0) { $ch = ClientHandler::getInstance($settingsAry['client']); $transferTotals = $ch->getTransferTotalOP($transfer, $settingsAry['hash'], $sf->uptotal, $sf->downtotal); } // --------------------------------------------------------------------- // preprocess stat-file and get some vars $estTime = ""; $statusStr = ""; switch ($transferRunning) { case 2: // new $statusStr = 'New'; break; case 3: // queued $statusStr = 'Queued'; $estTime = 'Waiting'; break; default: // running + stopped // increment the totals if (!isset($cfg["total_upload"])) { $cfg["total_upload"] = 0; } if (!isset($cfg["total_download"])) { $cfg["total_download"] = 0; } $cfg["total_upload"] += GetSpeedValue($sf->up_speed); $cfg["total_download"] += GetSpeedValue($sf->down_speed); // $estTime if ($transferRunning == 0) { $estTime = $sf->time_left; } else { if ($sf->time_left != "" && $sf->time_left != "0") { if ($cfg["display_seeding_time"] == 1 && $sf->percent_done >= 100) { $estTime = $sf->seedlimit > 0 && !empty($sf->up_speed) && intval($sf->up_speed[0]) > 0 ? convertTimeText(($sf->seedlimit / 100 * $sf->size - $sf->uptotal) / GetSpeedInBytes($sf->up_speed)) : '-'; } else { $estTime = $sf->time_left; } } } // $lastUser $lastUser = $transferowner; // $show_run + $statusStr if ($percentDone >= 100) { $statusStr = $transferRunning == 1 && trim($sf->up_speed) != "" ? 'Seeding' : 'Done'; $show_run = false; } else { if ($percentDone < 0) { $statusStr = 'Stopped'; $show_run = true; } else { $statusStr = 'Leeching'; } } break; } // --------------------------------------------------------------------- // fill temp array $transferAry = array(); // ================================================================ name array_push($transferAry, $transfer); // =============================================================== owner if ($settings[0] != 0) { array_push($transferAry, $transferowner); } // ================================================================ size if ($settings[1] != 0) { array_push($transferAry, @formatBytesTokBMBGBTB($sf->size)); } // =========================================================== downtotal if ($settings[2] != 0) { array_push($transferAry, @formatBytesTokBMBGBTB($transferTotals["downtotal"])); } // ============================================================= uptotal if ($settings[3] != 0) { array_push($transferAry, @formatBytesTokBMBGBTB($transferTotals["uptotal"])); } // ============================================================== status if ($settings[4] != 0) { array_push($transferAry, $statusStr); } // ============================================================ progress if ($settings[5] != 0) { $percentage = ""; if ($percentDone >= 100 && trim($sf->up_speed) != "") { $percentage = @number_format($transferTotals["uptotal"] / $sf->size * 100, 2) . '%'; } else { if ($percentDone >= 1) { $percentage = $percentDone . '%'; } else { if ($percentDone < 0) { $percentage = round($percentDone * -1 - 100, 1) . '%'; } else { $percentage = '0%'; } } } array_push($transferAry, $percentage); } // ================================================================ down if ($settings[6] != 0) { $down = ""; if ($transferRunning == 1) { $down = trim($sf->down_speed) != "" ? $sf->down_speed : '0.0 kB/s'; } array_push($transferAry, $down); } // ================================================================== up if ($settings[7] != 0) { $up = ""; if ($transferRunning == 1) { $up = trim($sf->up_speed) != "" ? $sf->up_speed : '0.0 kB/s'; } array_push($transferAry, $up); } // =============================================================== seeds if ($settings[8] != 0) { $seeds = $transferRunning == 1 ? $sf->seeds : ""; array_push($transferAry, $seeds); } // =============================================================== peers if ($settings[9] != 0) { $peers = $transferRunning == 1 ? $sf->peers : ""; array_push($transferAry, $peers); } // ================================================================= ETA if ($settings[10] != 0) { array_push($transferAry, $estTime); } // ============================================================== client if ($settings[11] != 0) { switch ($settingsAry['client']) { case "tornado": array_push($transferAry, "B"); break; case "transmission": array_push($transferAry, "T"); break; case "transmissionrpc": array_push($transferAry, "Tr"); break; case "mainline": array_push($transferAry, "M"); break; case "azureus": array_push($transferAry, "A"); break; case "vuzerpc": array_push($transferAry, "V"); break; case "wget": array_push($transferAry, "W"); break; case "nzbperl": array_push($transferAry, "N"); break; default: array_push($transferAry, "U"); } } // --------------------------------------------------------------------- // Is this transfer for the user list or the general list? if ($owner) { array_push($arUserTransfers, $transferAry); } else { array_push($arListTransfers, $transferAry); } } //XFER: update 2 if ($cfg['enable_xfer'] == 1 && $cfg['xfer_realtime'] == 1) { @Xfer::update2(); } // ------------------------------------------------------------------------- // build output-array $retVal = array(); if (sizeof($arUserTransfers) > 0) { foreach ($arUserTransfers as $torrentrow) { array_push($retVal, $torrentrow); } } $boolCond = true; if ($cfg['enable_restrictivetview'] == 1) { $boolCond = $cfg['isAdmin']; } if ($boolCond && sizeof($arListTransfers) > 0) { foreach ($arListTransfers as $torrentrow) { array_push($retVal, $torrentrow); } } return $retVal; }
continue; } // status-image $hd = getStatusImage($sf); // --------------------------------------------------------------------- //XFER: update1: add upload/download stats to the xfer array if ($cfg['enable_xfer'] == 1 && $cfg['xfer_realtime'] == 1) { @Xfer::update1($transfer, $transferowner, $settingsAry['client'], $settingsAry['hash'], $sf->uptotal, $sf->downtotal); } // --------------------------------------------------------------------- // injects new if (!file_exists($cfg["transfer_file_path"] . $transfer . ".stat")) { $transferRunning = 2; $sf->running = "2"; $sf->size = getTransferSize($transfer); injectTransfer($transfer); } // totals-preparation // if downtotal + uptotal + progress > 0 if ($settings[2] + $settings[3] + $settings[5] > 0) { $ch = ClientHandler::getInstance($settingsAry['client']); $transferTotals = $ch->getTransferTotalOP($transfer, $settingsAry['hash'], $sf->uptotal, $sf->downtotal); } // --------------------------------------------------------------------- // preprocess stat-file and get some vars $estTime = " "; $statusStr = " "; $show_run = true; switch ($transferRunning) { case 2: // new
/** * Function with which metafiles are uploaded and injected * * @deprecated */ function compat_tf_processUpload() { global $cfg; $filename = ""; $uploadMessages = array(); if (isset($_FILES['upload_file']) && !empty($_FILES['upload_file']['name'])) { $filename = stripslashes($_FILES['upload_file']['name']); $filename = tfb_cleanFileName($filename); if ($filename === false) { // invalid file array_push($uploadMessages, "The type of file you are uploading is not allowed."); array_push($uploadMessages, "\nvalid file-extensions: "); array_push($uploadMessages, $cfg["file_types_label"]); } else { // file is valid if (substr($filename, -5) == ".wget") { // is enabled ? if ($cfg["enable_wget"] == 0) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload wget-file " . $filename); @error("wget is disabled", "", ""); } else { if ($cfg["enable_wget"] == 1) { if (!$cfg['isAdmin']) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload wget-file " . $filename); @error("wget is disabled for users", "", ""); } } } } else { if (substr($filename, -4) == ".nzb") { // is enabled ? if ($cfg["enable_nzbperl"] == 0) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload nzb-file " . $filename); @error("nzbperl is disabled", "", ""); } else { if ($cfg["enable_nzbperl"] == 1) { if (!$cfg['isAdmin']) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload nzb-file " . $filename); @error("nzbperl is disabled for users", "", ""); } } } } } if ($_FILES['upload_file']['size'] <= $cfg["upload_limit"] && $_FILES['upload_file']['size'] > 0) { //FILE IS BEING UPLOADED if (@is_file($cfg["transfer_file_path"] . $filename)) { // Error array_push($uploadMessages, "the file " . $filename . " already exists on the server."); } else { if (@move_uploaded_file($_FILES['upload_file']['tmp_name'], $cfg["transfer_file_path"] . $filename)) { @chmod($cfg["transfer_file_path"] . $filename, 0644); AuditAction($cfg["constants"]["file_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) { $uploadMessages = array_merge($uploadMessages, $ch->messages); } } } else { array_push($uploadMessages, "File not uploaded, file could not be found or could not be moved: " . $cfg["transfer_file_path"] . $filename); } } } else { array_push($uploadMessages, "File not uploaded, file size limit is " . $cfg["upload_limit"] . ". file has " . $_FILES['upload_file']['size']); } } } if (count($uploadMessages) > 0) { AuditAction($cfg["constants"]["error"], $cfg["constants"]["file_upload"] . " :: " . $filename); @error("There were Problems", "", "", $uploadMessages); } }