/** * get log of a Transfer * * @param $transfer * @return string */ function getTransferLog($transfer) { global $cfg; $emptyLog = "log empty"; // sanity-check if (!isset($transfer) || tfb_isValidTransfer($transfer) !== true) { return "invalid transfer"; } // log-file $transferLogFile = $cfg["transfer_file_path"] . $transfer . ".log"; // check if (!file_exists($transferLogFile)) { return $emptyLog; } // open $handle = false; $handle = @fopen($transferLogFile, "r"); if (!$handle) { return $emptyLog; } // read $data = ""; while (!@feof($handle)) { $data .= @fgets($handle, 8192); } @fclose($handle); if ($data == "") { return $emptyLog; } // return return $data; }
/** * 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); }
/** * 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); }
/** * process a request */ function instance_processRequest() { global $cfg, $db; // type-switch switch ($this->_type) { case "all": if (!($this->_format == "txt" && $this->_header == 0)) { $this->_transferHeads = getTransferListHeadArray(); } $this->_indent = " "; // xfer-init if ($cfg['xfer_realtime'] == 0) { $cfg['xfer_realtime'] = 1; // set xfer-newday Xfer::setNewday(); } $this->_transferList = getTransferListArray(); $this->_initServerStats(); $this->_initXferStats(); $this->_initUserStats(); break; case "server": $this->_indent = ""; $this->_transferList = getTransferListArray(); $this->_initServerStats(); break; case "xfer": $this->_indent = ""; // xfer-init if ($cfg['xfer_realtime'] == 0) { $cfg['xfer_realtime'] = 1; // set xfer-newday Xfer::setNewday(); } $this->_transferList = getTransferListArray(); $this->_initXferStats(); break; case "transfers": $this->_indent = ""; $this->_transferList = getTransferListArray(); if (!($this->_format == "txt" && $this->_header == 0)) { $this->_transferHeads = getTransferListHeadArray(); } break; case "transfer": // transfer-id if (empty($this->_transferID)) { @error("missing params", "stats.php", "", array('i')); } // validate transfer if (tfb_isValidTransfer($this->_transferID) !== true) { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $this->_transferID); @error("Invalid Transfer", "", "", array($this->_transferID)); } $this->_indent = ""; $this->_transferDetails = getTransferDetails($this->_transferID, false); break; case "users": $this->_indent = ""; $this->_initUserStats(); break; case "usage": $this->_sendUsage(); } // action switch ($this->_format) { case "xml": $this->_sendXML(); case "rss": $this->_sendRSS(); case "txt": $this->_sendTXT(); } }
/** * sendMetafile * * @param $mfile */ function dispatcher_sendMetafile($mfile) { global $cfg; // is enabled ? if ($cfg["enable_metafile_download"] != 1) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to download a metafile"); @error("metafile download is disabled", "", ""); } if (tfb_isValidTransfer($mfile) === true) { // Does the file exist? if (@file_exists($cfg["transfer_file_path"] . $mfile)) { // filenames in IE containing dots will screw up the filename $headerName = strstr($_SERVER['HTTP_USER_AGENT'], "MSIE") ? preg_replace('/\\./', '%2e', $mfile, substr_count($mfile, '.') - 1) : $mfile; // Prompt the user to download file. if (substr($mfile, -8) == ".torrent") { @header("Content-type: application/x-bittorrent\n"); } else { @header("Content-type: application/octet-stream\n"); } @header("Content-disposition: attachment; filename=\"" . $headerName . "\"\n"); @header("Content-transfer-encoding: binary\n"); @header("Content-length: " . @filesize($cfg["transfer_file_path"] . $mfile) . "\n"); // write the session to close so you can continue to browse on the site. @session_write_close(); // Send the file $fp = @fopen($cfg["transfer_file_path"] . $mfile, "r"); @fpassthru($fp); @fclose($fp); AuditAction($cfg["constants"]["fm_download"], $mfile); exit; } else { AuditAction($cfg["constants"]["error"], "File Not found for download: " . $mfile); @error("File Not found for download", "", "", array($mfile)); } } else { AuditAction($cfg["constants"]["error"], "ILLEGAL DOWNLOAD: " . $mfile); @error("Invalid File", "", "", array($mfile)); } }
/** * This method gets transfers in an array * * @param $sortOrder * @return array */ function getTransferArray($sortOrder = '') { global $cfg; $retVal = array(); $handle = @opendir($cfg["transfer_file_path"]); if (!$handle) { AuditAction($cfg["constants"]["error"], "error when opening transfers-dir " . $cfg["transfer_file_path"]); return $retVal; } while ($transfer = @readdir($handle)) { if ($transfer[0] != ".") { switch (substr($transfer, -4)) { case 'stat': case '.log': case '.pid': case '.cmd': case 'prio': break; default: $transferName = str_replace('.imported', '', $transfer); if (tfb_isValidTransfer($transferName)) { $datecrc = date('YmdHi', filemtime($cfg['transfer_file_path'] . $transfer)) . '_' . sprintf('%x', crc32($transfer)); $retVal[$datecrc] = $transfer; } else { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transferName); } break; } } } @closedir($handle); // sort transfer-array $sortId = $sortOrder != "" ? $sortOrder : $cfg["index_page_sortorder"]; switch ($sortId) { case 'da': // sort by date ascending ksort($retVal); break; case 'dd': // sort by date descending krsort($retVal); break; case 'na': // sort alphabetically by name ascending natcasesort($retVal); break; case 'nd': // sort alphabetically by name descending natcasesort($retVal); $retVal = array_reverse($retVal, true); break; } return $retVal; }
/** * pieTransferScrape */ function image_pieTransferScrape() { global $cfg; // transfer-id $transfer = tfb_getRequestVar('transfer'); if (empty($transfer)) { Image::paintNoOp(); } // validate transfer if (tfb_isValidTransfer($transfer) !== true) { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer); Image::paintNoOp(); } // get scrape-data require_once 'inc/functions/functions.common.php'; $scrape = @trim(getTorrentScrapeInfo($transfer)); if (!empty($scrape) && preg_match("/(\\d+) seeder\\(s\\), (\\d+) leecher\\(s\\).*/i", $scrape, $reg)) { $seeder = $reg[1]; $leecher = $reg[2]; // draw image Image::paintPie3D(202, 160, 100, 50, 200, 100, 20, Image::stringToRGBColor($cfg["body_data_bg"]), array($seeder + 1.0E-5, $leecher + 1.0E-5), image_getColors(), array('Seeder : ' . $seeder, 'Leecher : ' . $leecher), 58, 130, 2, 14); } else { // output image Image::paintNoOp(); } }