/** * File Prio Form * * @param $transfer * @param $withForm * @return string */ function getFilePrioForm($transfer, $withForm = false) { global $cfg; $prioFileName = $cfg["transfer_file_path"] . $transfer . ".prio"; require_once 'inc/classes/BDecode.php'; $retVal = ""; // theme-switch if (strpos($cfg["theme"], '/') === false) { $retVal .= '<link rel="StyleSheet" href="themes/' . $cfg["theme"] . '/css/dtree.css" type="text/css" />'; $retVal .= '<script type="text/javascript">var dtree_path_images = "themes/' . $cfg["theme"] . '/images/dtree/";</script>'; } else { $retVal .= '<link rel="StyleSheet" href="themes/tf_standard_themes/css/dtree.css" type="text/css" />'; $retVal .= '<script type="text/javascript">var dtree_path_images = "themes/tf_standard_themes/images/dtree/";</script>'; } $retVal .= '<script type="text/javascript" src="js/dtree.js"></script>'; $ftorrent = $cfg["transfer_file_path"] . $transfer; $fp = @fopen($ftorrent, "rd"); $alltorrent = @fread($fp, @filesize($ftorrent)); @fclose($fp); $btmeta = @BDecode($alltorrent); $torrent_size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20); $dirnum = array_key_exists('files', $btmeta['info']) ? count($btmeta['info']['files']) : 0; if (@is_readable($prioFileName)) { $prio = explode(',', @file_get_contents($prioFileName)); $prio = array_splice($prio, 1); } else { $prio = array(); for ($i = 0; $i < $dirnum; $i++) { $prio[$i] = -1; } } $tree = new dir("/", $dirnum, isset($prio[$dirnum]) ? $prio[$dirnum] : -1); if (array_key_exists('files', $btmeta['info'])) { foreach ($btmeta['info']['files'] as $filenum => $file) { $depth = count($file['path']); $branch =& $tree; for ($i = 0; $i < $depth; $i++) { if ($i != $depth - 1) { $d =& $branch->findDir($file['path'][$i]); if ($d) { $branch =& $d; } else { $dirnum++; $d =& $branch->addDir(new dir($file['path'][$i], $dirnum, isset($prio[$dirnum]) ? $prio[$dirnum] : -1)); $branch =& $d; } } else { $branch->addFile(new file($file['path'][$i] . " (" . $file['length'] . ")", $filenum, $file['length'], $prio[$filenum])); } } } } $retVal .= "<table><tr>"; $retVal .= "<tr><td width=\"110\">Metainfo File:</td><td>" . $transfer . "</td></tr>"; $retVal .= "<tr><td>Directory Name:</td><td>" . $btmeta['info']['name'] . "</td></tr>"; $retVal .= "<tr><td>Announce URL:</td><td>" . $btmeta['announce'] . "</td></tr>"; if (array_key_exists('comment', $btmeta)) { $retVal .= "<tr><td valign=\"top\">Comment:</td><td>" . tfb_htmlencode($btmeta['comment']) . "</td></tr>"; } $retVal .= "<tr><td>Created:</td><td>" . date("F j, Y, g:i a", $btmeta['creation date']) . "</td></tr>"; $retVal .= "<tr><td>Torrent Size:</td><td>" . $torrent_size . " (" . @formatBytesTokBMBGBTB($torrent_size) . ")</td></tr>"; $retVal .= "<tr><td>Chunk size:</td><td>" . $btmeta['info']['piece length'] . " (" . @formatBytesTokBMBGBTB($btmeta['info']['piece length']) . ")</td></tr>"; if (array_key_exists('files', $btmeta['info'])) { $retVal .= "<tr><td>Selected size:</td><td id=\"sel\">0</td></tr>"; $retVal .= "</table><br>\n"; if ($withForm) { $retVal .= "<form name=\"priority\" action=\"dispatcher.php?action=setFilePriority&riid=_referer_\" method=\"POST\" >"; $retVal .= "<input type=\"hidden\" name=\"transfer\" value=\"" . $transfer . "\" >"; } $retVal .= "<script type=\"text/javascript\">\n"; $retVal .= "var sel = 0;\n"; $retVal .= "d = new dTree('d');\n"; $retVal .= $tree->draw(-1); $retVal .= "document.write(d);\n"; $retVal .= "sel = getSizes();\n"; $retVal .= "drawSel();\n"; $retVal .= "</script>\n"; $retVal .= "<input type=\"hidden\" name=\"filecount\" value=\"" . count($btmeta['info']['files']) . "\">"; $retVal .= "<input type=\"hidden\" name=\"count\" value=\"" . $dirnum . "\">"; $retVal .= "<br>"; if ($withForm) { $retVal .= '<input type="submit" value="Save" >'; $retVal .= "<br>"; $retVal .= "</form>"; } } else { $retVal .= "</table><br>"; $retVal .= $btmeta['info']['name'] . $torrent_size . " (" . @formatBytesTokBMBGBTB($torrent_size) . ")"; } // return return $retVal; }
if ($format_af_size == "") { $format_af_size = " "; } } // =============================================================== downtotal $format_downtotal = ""; if ($settings[2] != 0) { $format_downtotal = formatBytesTokBMBGBTB($transferTotals["downtotal"]); if ($format_downtotal == "") { $format_downtotal = " "; } } // ================================================================= uptotal $format_uptotal = ""; if ($settings[3] != 0) { $format_uptotal = formatBytesTokBMBGBTB($transferTotals["uptotal"]); if ($format_uptotal == "") { $format_uptotal = " "; } } // ================================================================== status // ================================================================ progress if ($settings[5] != 0) { if ((int) $percentDone >= 100 && $sf->size != 0 && trim($sf->up_speed) != "") { //finished $graph_width = -1; $percentage = @number_format($transferTotals["uptotal"] / $sf->size * 100, 2) . '%'; } else { if ($percentDone >= 1) { //leeching $graph_width = $percentDone;
// 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(); } // totals $afu = $sf->uptotal; $afd = $sf->downtotal; $totalsCurrent = $ch->getTransferCurrentOP($transfer, $ch->hash, $afu, $afd); $totals = $ch->getTransferTotalOP($transfer, $ch->hash, $afu, $afd); // owner $tmpl->setvar('transferowner', $transferowner); // size $transferSize = floatval($sf->size); $tmpl->setvar('size', @formatBytesTokBMBGBTB($transferSize)); // sharing $tmpl->setvar('sharing', $totals["downtotal"] > 0 ? @number_format($totals["uptotal"] / $totals["downtotal"] * 100, 2) : "0"); // totals $tmpl->setvar('downTotal', @formatFreeSpace($totals["downtotal"] / 1048576)); $tmpl->setvar('upTotal', @formatFreeSpace($totals["uptotal"] / 1048576)); // more if ($sf->running == 1) { // running $tmpl->setvar('running', 1); // current totals $tmpl->setvar('downTotalCurrent', formatFreeSpace($totalsCurrent["downtotal"] / 1048576)); $tmpl->setvar('upTotalCurrent', formatFreeSpace($totalsCurrent["uptotal"] / 1048576)); // seeds + peers $tmpl->setvar('seeds', $sf->seeds); $tmpl->setvar('peers', $sf->peers);
/** * process header * * @return boolean */ function _processHeader() { // output $this->_outputMessage("starting download...\n"); // flush buffer $this->_buffer = ""; // read until we find the Length-string which indicates dl-start $ctr = 0; while ($ctr < 64 && !@feof($this->_wget)) { // read $this->_buffer .= @fread($this->_wget, 256); // check for error if (preg_match("/.*error.*/i", $this->_buffer)) { $this->_outputError("error in response.\n"); // return return false; } // check for Length if (preg_match("/.*Length:\\s(.+\\d)\\s(\\[|\\()/i", $this->_buffer, $matches)) { // set size $this->_size = str_replace(',', '', $matches[1]); // set size in stat-file $this->_sf->size = $this->_size; // return return true; } // wait for 0.25 seconds usleep(250000); // increment counter $ctr++; } // there were problems $this->_outputMessage("problems when processing header...\n"); // set size from sf $this->_outputMessage("try to set size from stat-file...\n"); if (!empty($this->_sf->size)) { $this->_outputMessage("set size from stat-file :" . formatBytesTokBMBGBTB($this->_sf->size) . "\n"); $this->_size = $this->_sf->size; // return return true; } // give up, then we got no size $this->_outputError("failed to get size for download.\n"); // set size to 0 $this->_size = 0; // set size in stat-file $this->_sf->size = $this->_size; // return 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; }
/** * setFileVars */ function transfer_setFileVars() { global $cfg, $tmpl, $transfer, $transferLabel, $ch; // set vars for transfer $transferFilesList = array(); switch ($ch->type) { case "torrent": require_once "inc/classes/BDecode.php"; $tFile = $cfg["transfer_file_path"] . $transfer; if ($fd = @fopen($tFile, "rd")) { $alltorrent = @fread($fd, @filesize($tFile)); $btmeta = @BDecode($alltorrent); @fclose($fd); } $transferSizeSum = 0; if (isset($btmeta) && is_array($btmeta) && isset($btmeta['info'])) { if (array_key_exists('files', $btmeta['info'])) { foreach ($btmeta['info']['files'] as $filenum => $file) { $name = is_array($file['path']) ? implode("/", $file['path']) : $file['path']; $size = isset($file['length']) && is_numeric($file['length']) ? $file['length'] : 0; $transferSizeSum += $size; array_push($transferFilesList, array('name' => $name, 'size' => $size != 0 ? formatBytesTokBMBGBTB($size) : 0)); } } else { $size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20); $transferSizeSum += $size; array_push($transferFilesList, array('name' => $btmeta["info"]["name"], 'size' => formatBytesTokBMBGBTB($size))); } } if (empty($transferFilesList)) { $tmpl->setvar('transferFilesString', "Empty"); $tmpl->setvar('transferFileCount', count($btmeta['info']['files'])); } else { $tmpl->setloop('transferFilesList', $transferFilesList); $tmpl->setvar('transferFileCount', count($transferFilesList)); } $tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0); return; case "wget": $ch = ClientHandler::getInstance('wget'); $ch->setVarsFromFile($transfer); $transferSizeSum = 0; if (!empty($ch->url)) { require_once "inc/classes/SimpleHTTP.php"; $size = SimpleHTTP::getRemoteSize($ch->url); $transferSizeSum += $size; array_push($transferFilesList, array('name' => $ch->url, 'size' => formatBytesTokBMBGBTB($size))); } if (empty($transferFilesList)) { $tmpl->setvar('transferFilesString', "Empty"); $tmpl->setvar('transferFileCount', 0); } else { $tmpl->setloop('transferFilesList', $transferFilesList); $tmpl->setvar('transferFileCount', count($transferFilesList)); } $tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0); return; case "nzb": require_once "inc/classes/NZBFile.php"; $nzb = new NZBFile($transfer); $transferSizeSum = 0; if (empty($nzb->files)) { $tmpl->setvar('transferFilesString', "Empty"); $tmpl->setvar('transferFileCount', 0); } else { foreach ($nzb->files as $file) { $transferSizeSum += $file['size']; array_push($transferFilesList, array('name' => $file['name'], 'size' => formatBytesTokBMBGBTB($file['size']))); } $tmpl->setloop('transferFilesList', $transferFilesList); $tmpl->setvar('transferFileCount', $nzb->filecount); } $tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0); return; } }
/** * updateStatFiles * * @param $transfer string torrent name * @return boolean */ function updateStatFiles($transfer = "") { global $cfg, $db; $vuze = VuzeRPC::getInstance(); // do special-pre-start-checks if (!VuzeRPC::isRunning()) { return; } $tfs = $vuze->torrent_get_tf(); if (empty($tfs)) { return; } $sql = "SELECT hash, transfer, sharekill FROM tf_transfers WHERE type='torrent' AND client IN ('vuzerpc','azureus')"; if ($transfer != "") { //only update one transfer... $sql .= " AND transfer=" . $db->qstr($transfer); } else { //or a set of hashes $hashes = array("''"); foreach ($tfs as $hash => $t) { $hashes[] = "'" . strtolower($hash) . "'"; } $sql .= " AND hash IN (" . implode(',', $hashes) . ")"; } $recordset = $db->Execute($sql); $hashes = array(); $sharekills = array(); while (list($hash, $transfer, $sharekill) = $recordset->FetchRow()) { $hash = strtoupper($hash); $hashes[$hash] = $transfer; $sharekills[$hash] = $sharekill; } //convertTimeText require_once "inc/functions/functions.core.php"; foreach ($tfs as $hash => $t) { if (!isset($hashes[$hash])) { continue; } $transfer = $hashes[$hash]; $sf = new StatFile($transfer); $sf->running = $t['running']; if ($sf->running) { if ($t['eta'] > 0 || $t['eta'] < -1) { $sf->time_left = convertTimeText($t['eta']); } $sf->percent_done = $t['percentDone']; if ($t['status'] != 9 && $t['status'] != 5) { $sf->peers = $t['peers']; //(temp) force creation of pid file to fix first ones file_put_contents($cfg["transfer_file_path"] . '/' . $transfer . ".pid", "rpc"); } if ($t['seeds'] >= 0) { $sf->seeds = $t['seeds']; } if ($t['peers'] >= 0) { $sf->peers = $t['peers']; } if ((double) $t['speedDown'] > 0.0) { $sf->down_speed = formatBytesTokBMBGBTB($t['speedDown']) . "/s"; } if ((double) $t['speedUp'] > 0.0) { $sf->up_speed = formatBytesTokBMBGBTB($t['speedUp']) . "/s"; } if ($t['status'] == 8) { //seeding //$sf->percent_done = 100 + $t['sharing']; $sf->down_speed = ""; } if ($t['status'] == 9) { //seeding queued //$sf->percent_done = 100 + $t['sharing']; $sf->up_speed = ""; $sf->down_speed = ""; } } else { $sf->down_speed = ""; $sf->up_speed = ""; $sf->peers = ""; if ($t['eta'] < -1) { $sf->time_left = 'Done in ' . convertTimeText($t['eta']); } elseif ($sf->percent_done >= 100 && strpos($sf->time_left, 'Done') === false && strpos($sf->time_left, 'Finished') === false) { $sf->time_left = "Done!"; $sf->percent_done = 100; } if ($sf->percent_done < 100 && $sf->percent_done > 0) { //$sf->percent_done = 0 - $sf->percent_done; $sf->stop(); } } $sf->downtotal = $t['downTotal']; $sf->uptotal = $t['upTotal']; if (!$sf->size) { $sf->size = $t['size']; } if ($sf->seeds = -1) { } $sf->seeds = ''; $sf->write(); } //SHAREKILLS foreach ($tfs as $hash => $t) { if (isset($sharekills[$hash])) { if (($t['status'] == 8 || $t['status'] == 9) && $t['sharing'] > $sharekills[$hash]) { $transfer = $hashes[$hash]; if (!$vuze->torrent_stop_tf($hash)) { $msg = "transfer " . $transfer . " does not exist in vuze."; $this->logMessage($msg . "\n", true); AuditAction($cfg["constants"]["debug"], $this->client . "-stop : error {$hash} {$transfer}."); } else { // flag the transfer as stopped (in db) // log AuditAction($cfg["constants"]["stop_transfer"], $this->client . "-stat. : sharekill stopped {$transfer}"); stopTransferSettings($transfer); } } } } }
function gOOGLE($htmlLine) { $tmpVal = substr($htmlLine, strpos($htmlLine, "<a")); $tmpVal = trim($tmpVal); if (strlen($tmpVal) > 0) { $this->Data = $htmlLine; $tmpVal2 = substr($tmpVal, strpos($tmpVal, "href=\"") + strlen("href=\"")); $this->torrentFile = substr($tmpVal2, 0, strpos($tmpVal2, "\"")); $html = FetchHTMLNoWaitNoFollow($this->torrentFile); // Make sure we have a torrent file if (strpos($html, "d8:") === false) { // We don't have a Torrent File... it is something else $this->torrentFile = ""; } else { $array = BDecode($html); $this->torrentSize = formatBytesTokBMBGBTB($array["info"]["piece length"] * (strlen($array["info"]["pieces"]) / 20)); $this->torrentName = $array['info']['name']; $this->fileCount = count($array['info']['files']); $this->torrentDisplayName = $array['info']['name']; if (array_key_exists('comment', $array)) { $this->torrentDisplayName .= " [" . $array['comment'] . "]"; } } /* $this->Seeds = $this->cleanLine($tmpListArr["4"]); // Seeds $this->Peers = $this->cleanLine($tmpListArr["5"]); // Peers */ if ($this->Peers == '') { $this->Peers = "N/A"; if (empty($this->Seeds)) { $this->Seeds = "N/A"; } } if ($this->Seeds == '') { $this->Seeds = "N/A"; } if (strlen($this->torrentDisplayName) > 50) { $this->torrentDisplayName = substr($this->torrentDisplayName, 0, 50) . "..."; } } }
$entry_iso = utf8_decode($entry); } if ($cfg['enable_dirstats'] == 1) { $path = $dirName . $entry; $stat = stat($path); $ssz = 0.0; if ($islink == 0) { $ssz += is_dir($path) ? dirsize($path) : sprintf("%.0f", $stat['size']); if (($ssz < 0 || $stat['blocks'] > 2000000) && !isWinOS()) { $ssz = @trim(1024.0 * shell_exec('du -ksL ' . tfb_shellencode($dirName . $entry))); } } elseif (!isWinOS()) { $ssz += @trim(1024.0 * shell_exec('du -ksL ' . tfb_shellencode($slink))); $date = ""; } $size = formatBytesTokBMBGBTB(sprintf("%.0f", $ssz)); if (strstr($size, "G")) { $size = "<b>{$size}</b>"; } $timeStamp = $stat['mtime']; $date = date($cfg['_DATETIMEFORMAT'], $timeStamp); if ($timeStamp + 86400 * 2 > time()) { $isrecent = 1; } } if (is_dir($dirName . $entry)) { // sfv if ($cfg['enable_sfvcheck'] == 1 && false !== ($sfv = findSFV($dirName . $entry))) { $show_sfv = 1; $sfvdir = $sfv['dir']; $sfvsfv = $sfv['sfv'];
/* sub-dir */ $aclWrite = hasPermission($dir, $cfg["user"], 'w') ? 1 : 0; } // symbolic links if (!is_link($dirName . $entry)) { $islink = 0; } else { if (!($slink = readlink($dirName . $entry))) { $slink = ""; } $islink = 1; } // dirstats if ($cfg['enable_dirstats'] == 1) { if ($islink == 0) { $size = is_dir($dirName . $entry) ? formatBytesTokBMBGBTB(dirsize($dirName . $entry)) : formatBytesTokBMBGBTB(filesize($dirName . $entry)); $timeStamp = filemtime($dirName . $entry); $date = date("m-d-Y h:i a", $timeStamp); } else { $size = 0; $date = ""; } } else { $size = 0; $date = ""; } if (is_dir($dirName . $entry)) { // sfv if ($cfg['enable_sfvcheck'] == 1 && false !== ($sfv = findSFV($dirName . $entry))) { $show_sfv = 1; $sfvdir = $sfv['dir'];
function updateStatFiles($bShowMissing = false) { global $cfg, $db, $client; $rpc = Transmission::getInstance($cfg); // check if running and get all session variables in cache if (!$rpc->session_get()) { echo "unable to connect to transmission-daemon\n"; return; } $tfs = $rpc->torrent_get_tf(); if (empty($tfs)) { echo "no loaded torrents\n"; return; } $sql = "SELECT hash, transfer, sharekill FROM tf_transfers WHERE type='torrent' AND client = 'transmissionrpc'"; $hashes = array("''"); foreach ($tfs as $hash => $t) { $hashes[] = "'" . strtolower($hash) . "'"; } $sql .= " AND hash IN (" . implode(',', $hashes) . ")"; $recordset = $db->Execute($sql); $hashes = array(); $sharekills = array(); while (list($hash, $transfer, $sharekill) = $recordset->FetchRow()) { $hash = strtolower($hash); $hashes[$hash] = $transfer; $sharekills[$hash] = $sharekill; } $max_ul = 1024.0 * $cfg['max_upload_rate']; $max_dl = 1024.0 * $cfg['max_download_rate']; //SHAREKILLS Checks $nbUpdate = 0; foreach ($tfs as $hash => $t) { if (!isset($sharekills[$hash])) { continue; } if (($t['status'] == 8 || $t['status'] == 9) && $t['sharing'] > $sharekills[$hash]) { $transfer = $hashes[$hash]; $nbUpdate++; if (stopTransmissionTransferCron($hash)) { AuditAction($cfg["constants"]["debug"], $client . ": stop error {$transfer}."); } else { AuditAction($cfg["constants"]["stop_transfer"], $this->client . "-stat. : sharekill stopped {$transfer}"); // flag the transfer as stopped (in db) stopTransferSettings($transfer); } } } echo " stopped {$nbUpdate} torrents.\n"; $nbUpdate = 0; $missing = array(); foreach ($tfs as $hash => $t) { if (!isset($hashes[$hash])) { if ($bShowMissing) { $missing[$t['rpcid']] = $t['name']; } continue; } $transfer = $hashes[$hash]; //file_put_contents($cfg["path"].'.Transmission/'."updateStatFiles4.log",serialize($t)); $sf = new StatFile($transfer); $sf->running = $t['running']; if (empty($sf->transferowner)) { $uid = getTransferOwnerID($hash); if ($uid > 0) { $sf->transferowner = GetUsername($uid); echo "transfer '{$transfer}' owner fixed to " . $sf->transferowner . " \n"; $sf->write(); } } if ($sf->running) { $sharebase = (int) $sharekills[$hash]; //$sharekill = (int) round(floatval($t['seedRatioLimit']) * 100); if ($sharebase > 0 && (int) $sf->seedlimit == 0) { AuditAction($cfg["constants"]["debug"], $client . ": changed empty .stat sharekill " . $sf->seedlimit . " to {$sharebase} (from db), {$transfer}."); $sf->seedlimit = $sharebase; } $max_ul = max($t['urate'], $max_ul); $max_dl = max($t['drate'], $max_dl); $max_share = max($sharebase, $sharekill); if ($t['eta'] > 0 || $t['eta'] < -1) { $sf->time_left = convertTimeText($t['eta']); } $sf->percent_done = $t['percentDone']; $sf->sharing = round($t['sharing'], 1); if ($t['status'] != 9 && $t['status'] != 5) { $sf->peers = $t['peers']; $sf->seeds = $t['seeds']; } if ($t['seeds'] >= 0) { $sf->seeds = $t['seeds']; } if ($t['peers'] >= 0) { $sf->peers = $t['peers']; } if ((double) $t['speedDown'] >= 0.0) { $sf->down_speed = formatBytesTokBMBGBTB($t['speedDown']) . "/s"; } if ((double) $t['speedUp'] >= 0.0) { $sf->up_speed = formatBytesTokBMBGBTB($t['speedUp']) . "/s"; } if ($t['status'] == 8) { $sf->percent_done = 100 + $t['sharing']; $sf->down_speed = " "; if (trim($sf->up_speed) == '') { $sf->up_speed = " "; } } if ($t['status'] == 9) { $sf->percent_done = 100 + $t['sharing']; $sf->up_speed = " "; $sf->down_speed = " "; } } else { //Stopped or finished... $sf->down_speed = ""; $sf->up_speed = ""; $sf->peers = ""; $sf->time_left = "0"; if ($t['eta'] < -1) { $sf->time_left = "Done in " . convertTimeText($t['eta']); } elseif ($sf->percent_done >= 100 && strpos($sf->time_left, 'Done') === false && strpos($sf->time_left, 'Finished') === false) { $sf->percent_done = 100; $sf->time_left = "Done!"; } if ($sf->sharing == 0) { $sf->sharing = round($t['sharing'], 1); } if (is_file($cfg["transfer_file_path"] . '/' . $transfer . ".pid")) { unlink($cfg["transfer_file_path"] . '/' . $transfer . ".pid"); } //if ($sf->percent_done < 100 && $sf->percent_done > 0) // $sf->percent_done = 0 - $sf->percent_done; } $sf->downtotal = $t['downTotal']; $sf->uptotal = $t['upTotal']; if ($sf->size == 0) { $sf->size = $t['size']; } if ($sf->seeds = -1) { } $sf->seeds = ''; if ($sf->write()) { $nbUpdate++; } } $nb = count($tfs); echo " updated {$nbUpdate}/{$nb} stat files.\n"; //fix globall sharekill to maximum of torrents sharekill, other torrent with lower sharekill will be stopped by this cron /* if (isset($max_share)) { $sharekill = getTransmissionShareKill(); if ($max_share > $sharekill) { //set vuze global sharekill to max sharekill value $rpc->session_set( array('seedRatioLimit' => round($max_share / 100, 2)) ); if ($cfg['debuglevel'] > 0) { $msg = $client.": changed vuze global sharekill from $sharekill to $max_share."; AuditAction($cfg["constants"]["debug"], $msg); echo $msg."\n"; } } } if ($max_ul > 0) { $vzmaxul = getTransmissionSpeedLimitUpload(); if ($cfg['max_upload_rate'] > 0 && $max_ul > 0) { $max_ul = min($max_ul, 1024.0 * $cfg['max_upload_rate']); } if ($vzmaxul != $max_ul) { $max_ul = $max_ul / 1024; $rpc->session_set( array('speed-limit-up' => $max_ul) ); if ($cfg['debuglevel'] > 0) { $msg = $client.": tranmission global speed-limit-up from $vzmaxul to $max_ul."; AuditAction($cfg["constants"]["debug"], $msg); echo $msg."\n"; } } } */ if ($bShowMissing) { return $missing; } }
/** * File Prio Form * * @param $transfer * @param $withForm * @return string */ function getFilePrioForm($transfer, $withForm = false) { /* global $cfg; $prioFileName = $cfg["transfer_file_path"].$transfer.".prio"; require_once('inc/classes/BDecode.php'); $retVal = ""; // theme-switch if ((strpos($cfg["theme"], '/')) === false) { $retVal .= '<link rel="StyleSheet" href="themes/'.$cfg["theme"].'/css/dtree.css" type="text/css" />'; $retVal .= '<script type="text/javascript">var dtree_path_images = "themes/'.$cfg["theme"].'/images/dtree/";</script>'; } else { $retVal .= '<link rel="StyleSheet" href="themes/tf_standard_themes/css/dtree.css" type="text/css" />'; $retVal .= '<script type="text/javascript">var dtree_path_images = "themes/tf_standard_themes/images/dtree/";</script>'; } $retVal .= '<script type="text/javascript" src="js/dtree.js"></script>'; $ftorrent = $cfg["transfer_file_path"].$transfer; $fp = @fopen($ftorrent, "rd"); $alltorrent = @fread($fp, @filesize($ftorrent)); @fclose($fp); $btmeta = @BDecode($alltorrent); $torrent_size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20); $dirnum = (array_key_exists('files',$btmeta['info'])) ? count($btmeta['info']['files']) : 0; if (@is_readable($prioFileName)) { $prio = explode(',', @file_get_contents($prioFileName)); $prio = array_splice($prio,1); } else { $prio = array(); for ($i=0; $i<$dirnum; $i++) $prio[$i] = -1; } */ global $cfg; require_once 'inc/classes/BDecode.php'; $retVal = ""; // theme-switch if (strpos($cfg["theme"], '/') === false) { $retVal .= '<link rel="StyleSheet" href="themes/' . $cfg["theme"] . '/css/dtree.css" type="text/css" />'; $retVal .= '<script type="text/javascript">var dtree_path_images = "themes/' . $cfg["theme"] . '/images/dtree/";</script>'; } else { $retVal .= '<link rel="StyleSheet" href="themes/tf_standard_themes/css/dtree.css" type="text/css" />'; $retVal .= '<script type="text/javascript">var dtree_path_images = "themes/tf_standard_themes/images/dtree/";</script>'; } $retVal .= '<script type="text/javascript" src="js/dtree.js"></script>'; $isTransmissionTorrent = false; if ($cfg["transmission_rpc_enable"]) { require_once 'inc/functions/functions.rpc.transmission.php'; $isTransmissionTorrent = isTransmissionTransfer($transfer); } $files = array(); if ($isTransmissionTorrent) { $allFilesResponse = getTransmissionTransfer($transfer, array('files')); $allFiles = $allFilesResponse['files']; $wantedFilesResponse = getTransmissionTransfer($transfer, array('wanted')); $wantedFiles = $wantedFilesResponse['wanted']; $dirnum = count($allFiles); // make sure this is in here otherwhise you will loose alot of time debugging your code on what is missing (the filetree selection is not displayed) $tree = new dir("/", $dirnum, -1); foreach ($allFiles as $file) { $fileparts = explode("/", $file[name]); $filesize = $file[length]; $fileprops = array('length' => $filesize, 'path' => $fileparts); array_push($files, $fileprops); } $filescount = count($files); foreach ($files as $filenum => $file) { $depth = count($file['path']); $branch =& $tree; for ($i = 0; $i < $depth; $i++) { if ($i != $depth - 1) { $d =& $branch->findDir($file['path'][$i]); if ($d) { $branch =& $d; } else { $dirnum++; $d =& $branch->addDir(new dir($file['path'][$i], $dirnum, -1)); $branch =& $d; } } else { $branch->addFile(new file($file['path'][$i] . " (" . $file['length'] . ")", $filenum, $file['length'], $wantedFiles[$filenum] == 1 ? 1 : -1)); } } } $aTorrent = getTransmissionTransfer($transfer, array("pieceCount", "pieceSize", "totalSize", "dateCreated", "downloadDir", "comment")); #$torrent_size = $aTorrent[pieceSize] * $aTorrent[pieceCount]; $torrent_size = $aTorrent['totalSize']; $torrent_chunksize = $aTorrent['pieceSize']; $torrent_directoryname = $aTorrent['downloadDir']; $torrent_announceurl = $aTorrent['comment']; $torrent_creationdate = $aTorrent['dateCreated']; $torrent_filescount = $filescount; } else { $prioFileName = $cfg["transfer_file_path"] . $transfer . ".prio"; $ftorrent = $cfg["transfer_file_path"] . $transfer; $fp = @fopen($ftorrent, "rd"); $alltorrent = @fread($fp, @filesize($ftorrent)); @fclose($fp); $btmeta = @BDecode($alltorrent); $torrent_size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20); $dirnum = array_key_exists('files', $btmeta['info']) ? count($btmeta['info']['files']) : 0; if (@is_readable($prioFileName)) { $prio = explode(',', @file_get_contents($prioFileName)); $prio = array_splice($prio, 1); } else { $prio = array(); for ($i = 0; $i < $dirnum; $i++) { $prio[$i] = -1; } } $tree = new dir("/", $dirnum, isset($prio[$dirnum]) ? $prio[$dirnum] : -1); if (array_key_exists('files', $btmeta['info'])) { foreach ($btmeta['info']['files'] as $filenum => $file) { $depth = count($file['path']); $branch =& $tree; for ($i = 0; $i < $depth; $i++) { if ($i != $depth - 1) { $d =& $branch->findDir($file['path'][$i]); if ($d) { $branch =& $d; } else { $dirnum++; $d =& $branch->addDir(new dir($file['path'][$i], $dirnum, isset($prio[$dirnum]) ? $prio[$dirnum] : -1)); $branch =& $d; } } else { $branch->addFile(new file($file['path'][$i] . " (" . $file['length'] . ")", $filenum, $file['length'], $prio[$filenum])); } } } } $torrent_chunksize = $btmeta[info]['piece length']; $torrent_directoryname = $btmeta[info][name]; $torrent_announceurl = $btmeta[announce]; $torrent_creationdate = $btmeta['creation date']; $torrent_filescount = count($btmeta['info']['files']); } $retVal .= "<table><tr>"; $retVal .= "<tr><td width=\"110\">Metainfo File:</td><td>" . $transfer . "</td></tr>"; $retVal .= "<tr><td>Directory Name:</td><td>" . $torrent_directoryname . "</td></tr>"; $retVal .= "<tr><td>Announce URL:</td><td>" . $torrent_announceurl . "</td></tr>"; if (array_key_exists('comment', $btmeta)) { $retVal .= "<tr><td valign=\"top\">Comment:</td><td>" . tfb_htmlencode($btmeta['comment']) . "</td></tr>"; } $retVal .= "<tr><td>Created:</td><td>" . ($torrent_creationdate == 0 ? 'n/a' : date("F j, Y, g:i a", $torrent_creationdate)) . "</td></tr>"; $retVal .= "<tr><td>Torrent Size:</td><td>" . $torrent_size . " (" . @formatBytesTokBMBGBTB($torrent_size) . ")</td></tr>"; $retVal .= "<tr><td>Chunk size:</td><td>" . $torrent_chunksize . " (" . @formatBytesTokBMBGBTB($torrent_chunksize) . ")</td></tr>"; if (array_key_exists('files', $btmeta['info']) || count($files) > 0) { $retVal .= "<tr><td>Selected size:</td><td id=\"sel\">0</td></tr>"; $retVal .= "</table><br>\n"; if ($withForm) { $retVal .= "<form name=\"priority\" action=\"dispatcher.php?action=setFilePriority&riid=_referer_\" method=\"POST\" >"; $retVal .= "<input type=\"hidden\" name=\"transfer\" value=\"" . $transfer . "\" >"; } $retVal .= "<script type=\"text/javascript\">\n"; $retVal .= "var sel = 0;\n"; $retVal .= "d = new dTree('d');\n"; $retVal .= $tree->draw(-1); $retVal .= "document.write(d);\n"; $retVal .= "sel = getSizes();\n"; $retVal .= "drawSel();\n"; $retVal .= "</script>\n"; $retVal .= "<input type=\"hidden\" name=\"filecount\" value=\"" . $torrent_filescount . "\">"; $retVal .= "<input type=\"hidden\" name=\"count\" value=\"" . $dirnum . "\">"; $retVal .= "<br>"; if ($withForm) { $retVal .= '<input type="submit" value="Save" >'; $retVal .= "<br>"; $retVal .= "</form>"; } } else { $retVal .= "</table><br>"; $retVal .= $btmeta['info']['name'] . $torrent_size . " (" . @formatBytesTokBMBGBTB($torrent_size) . ")"; } // return return $retVal; }
function transmissionSetVars($transfer, $tmpl) { //require_once('inc/functions/functions.rpc.transmission.php'); require_once 'functions.rpc.transmission.php'; $options = array("eta", "percentDone", "rateDownload", "rateUpload", "downloadedEver", "uploadedEver", "percentDone", "sizeWhenDone", "peers", "trackerStats"); $returnArr = getTransmissionTransfer($transfer, $options); $tmpl->setvar('transferowner', getTransmissionTransferOwner($transfer)); $tmpl->setvar('size', @formatBytesTokBMBGBTB($returnArr['sizeWhenDone'])); // sharing $tmpl->setvar('sharing', $returnArr["downloadedEver"] > 0 ? @number_format($returnArr["uploadedEver"] / $returnArr["downloadedEver"] * 100, 2) : "0"); // totals $tmpl->setvar('downTotal', @formatFreeSpace($returnArr["downloadedEver"] / 1048576)); $tmpl->setvar('upTotal', @formatFreeSpace($returnArr["uploadedEver"] / 1048576)); // port + cons //$tmpl->setvar('size', @formatBytesTokBMBGBTB($transferSize)); $isRunning = true; // TODO make this actually detect if torrent is running if ($isRunning) { $tmpl->setvar('running', 1); // current totals $tmpl->setvar('downTotalCurrent', formatFreeSpace($totalsCurrent["downtotal"] / 1048576)); $tmpl->setvar('upTotalCurrent', formatFreeSpace($totalsCurrent["uptotal"] / 1048576)); // seeds + peers $seeds = getTransmissionSeederCount($transfer); $tmpl->setvar('seeds', $seeds == "" ? "Could not be retrieved" : $seeds . " (might be incorrect)"); $tmpl->setvar('peers', sizeof($returnArr['peers'])); // port + cons $transfer_pid = getTransferPid($transfer); $tmpl->setvar('port', netstatPortByPid($transfer_pid)); $tmpl->setvar('cons', netstatConnectionsByPid($transfer_pid)); // TODO: this is probably incorrect // up speed $tmpl->setvar('up_speed', trim($returnArr['rateUpload']) != "" ? formatBytesTokBMBGBTB($returnArr['rateUpload']) . '/s' : '0.0 kB/s'); // down speed $tmpl->setvar('down_speed', trim($returnArr['rateDownload']) != "" ? formatBytesTokBMBGBTB($returnArr['rateDownload']) . '/s' : '0.0 kB/s'); // sharekill $tmpl->setvar('sharekill', $ch->sharekill != 0 ? $ch->sharekill . '%' : '∞'); } else { // running $tmpl->setvar('running', 0); // current totals $tmpl->setvar('downTotalCurrent', ""); $tmpl->setvar('upTotalCurrent', ""); // seeds + peers $tmpl->setvar('seeds', ""); $tmpl->setvar('peers', ""); // port + cons $tmpl->setvar('port', ""); $tmpl->setvar('cons', ""); // up speed $tmpl->setvar('up_speed', ""); // down speed $tmpl->setvar('down_speed', ""); // sharekill $tmpl->setvar('sharekill', ""); } if ($returnArr['eta'] < 0) { $tmpl->setvar('time_left', 'n/a'); } else { $tmpl->setvar('time_left', convertTime($returnArr['eta'])); } // graph width $tmpl->setvar('graph_width1', $returnArr['percentDone'] * 100); $tmpl->setvar('graph_width2', 100 - $returnArr['percentDone'] * 100); $tmpl->setvar('percent_done', $returnArr['percentDone'] * 100); // language vars global $cfg; $tmpl->setvar('_USER', $cfg['_USER']); $tmpl->setvar('_SHARING', $cfg['_SHARING']); $tmpl->setvar('_ID_CONNECTIONS', $cfg['_ID_CONNECTIONS']); $tmpl->setvar('_ID_PORT', $cfg['_ID_PORT']); $tmpl->setvar('_DOWNLOADSPEED', $cfg['_DOWNLOADSPEED']); $tmpl->setvar('_UPLOADSPEED', $cfg['_UPLOADSPEED']); $tmpl->setvar('_PERCENTDONE', $cfg['_PERCENTDONE']); $tmpl->setvar('_ESTIMATEDTIME', $cfg['_ESTIMATEDTIME']); return $tmpl; }
} $tmpl->setloop('link_list', $link_list); $mainGenre = tfb_getRequestVar('mainGenre'); $subCats = $sEngine->getSubCategories($mainGenre); if (empty($mainGenre) && array_key_exists("subGenre", $_REQUEST) || count($subCats) <= 0) { $tmpl->setvar('no_genre', 1); $tmpl->setvar('performSearch', array_key_exists("LATEST", $_REQUEST) && $_REQUEST["LATEST"] == "1" ? $sEngine->getLatest() : $sEngine->performSearch($searchterm)); } else { $mainGenreName = $sEngine->GetMainCatName($mainGenre); $tmpl->setvar('mainGenreName', $mainGenreName); $list_cats = array(); foreach ($subCats as $subId => $subName) { array_push($list_cats, array('subId' => $subId, 'subName' => $subName)); } $tmpl->setloop('list_cats', $list_cats); } $tmpl->setvar('ext_request', $sEngine->lastRequest); $tmpl->setvar('ext_method', $sEngine->method); $tmpl->setvar('ext_postquery', $sEngine->postquery); $tmpl->setvar('res_size', formatBytesTokBMBGBTB(strlen($sEngine->htmlPage))); $tmpl->setvar('sEngine_msg', $sEngine->msg); } } // $tmpl->setvar('_SEARCH', $cfg['_SEARCH']); // tmplSetTitleBar("Torrent " . $cfg['_SEARCH']); tmplSetFoot(); tmplSetIidVars(); // parse template $tmpl->pparse();