function write_stat_file() { global $_NAME, $_SIZE, $_COMPLETED, $_PERCENTAGE, $_SPEED, $_STATUS, $_REAL_NAME, $cfg, $_INT_SPEED, $_OWNER; // this is "something else" (wget). use tornado statfile $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . getAliasName($_NAME) . ".stat", $_OWNER, $cfg, 'tornado'); $af->running = $_STATUS; $af->percent_done = $_PERCENTAGE; if ($_COMPLETED == $_SIZE) { $af->time_left = "Download Succeeded!"; $af->down_speed = "0 kB/s"; } else { if ($_INT_SPEED > 0) { // because size is 0 this wont work so lets put a fallback here now //$af->time_left = convert_time( (($_SIZE-$_COMPLETED)/1024)/$_INT_SPEED); $af->time_left = '?'; } else { $af->time_left = "Inf" . $_INT_SPEED; } $af->down_speed = $_SPEED; } $af->up_speed = "N/a"; $af->sharing = "0"; $af->torrentowner = $_OWNER; $af->seeds = "1+0.00"; $af->peers = "1+0.00"; $af->seedlimit = "0"; $af->uptotal = "0"; $af->downtotal = $_COMPLETED; $af->size = $_SIZE; $af->WriteFile(); }
function setPriority($torrent) { global $cfg; // we will use this to determine if we should create a prio file. // if the user passes all 1's then they want the whole thing. // so we don't need to create a prio file. // if there is a -1 in the array then they are requesting // to skip a file. so we will need to create the prio file. $okToCreate = false; if (!empty($torrent)) { $alias = getAliasName($torrent); $fileName = $cfg["torrent_file_path"] . $alias . ".prio"; $result = array(); // b4rt-4 //$files = array_filter($_REQUEST['files'],"getFile"); $files = array(); if (isset($_REQUEST['files'])) { $files = array_filter($_REQUEST['files'], "getFile"); } // b4rt-4 // if there are files to get then process and create a prio file. if (count($files) > 0) { for ($i = 0; $i < getRequestVar('count'); $i++) { if (in_array($i, $files)) { array_push($result, 1); } else { $okToCreate = true; array_push($result, -1); } } $alias = getAliasName($torrent); if ($okToCreate) { $fp = fopen($fileName, "w"); fwrite($fp, getRequestVar('filecount') . ","); fwrite($fp, implode($result, ',')); fclose($fp); } else { // No files to skip so must be wanting them all. // So we will remove the prio file. @unlink($fileName); } } else { // No files selected so must be wanting them all. // So we will remove the prio file. @unlink($fileName); } } }
switch ($torrentAction) { case "0": // Torrents-main $htmlTitle = "Torrents"; break; case "1": // Torrents-Stop include_once "ClientHandler.php"; $htmlTitle = "Torrents-Stop"; $htmlMain .= '<br><strong>Torrents Stopped :</strong><br>'; $htmlMain .= '<pre>'; $torrents = getTorrentListFromFS(); foreach ($torrents as $torrent) { $torrentRunningFlag = isTorrentRunning($torrent); if ($torrentRunningFlag != 0) { $alias = getAliasName($torrent) . ".stat"; $btclient = getTorrentClient($torrent); $clientHandler = ClientHandler::getClientHandlerInstance($cfg, $btclient); $clientHandler->stopTorrentClient($torrent, $alias); $htmlMain .= ' - ' . $torrent . ""; $htmlMain .= "\n"; // just 2 sec.. sleep(2); } } $htmlMain .= '</pre>'; $htmlMain .= '<hr><br>'; break; case "2": // Torrents-Start include_once "ClientHandler.php";
/** * formattedQueueList. dont want to rewrite more tf-mvc-"issues"... * @return html-snip */ function formattedQueueList() { if ($this->isQueueManagerRunning()) { $output = ""; $torrentList = trim($this->getQueuedTorrents()); $torrentAry = explode("\n", $torrentList); foreach ($torrentAry as $torrent) { if ($torrent != "") { $output .= "<tr>"; $output .= "<td><div class=\"tiny\">"; $output .= getOwner($torrent); $output .= "</div></td>"; $output .= "<td><div align=center><div class=\"tiny\" align=\"left\">" . $torrent . "</div></td>"; $output .= "<td><div class=\"tiny\" align=\"center\">" . date(_DATETIMEFORMAT, strval(filemtime($this->cfg["torrent_file_path"] . getAliasName($torrent) . ".stat"))) . "</div></td>"; $output .= "</tr>"; $output .= "\n"; } } if (strlen($output) == 0) { return "<tr><td colspan=3><div class=\"tiny\" align=center>Queue is Empty</div></td></tr>"; } else { return $output; } } else { return ""; } }
function getDirList($dirName) { global $cfg, $db; include_once "AliasFile.php"; $lastUser = ""; $arUserTorrent = array(); $arListTorrent = array(); // sortOrder $sortOrder = getRequestVar("so"); if ($sortOrder == "") { $sortOrder = $cfg["index_page_sortorder"]; } // t-list $arList = getTransferArray($sortOrder); foreach ($arList as $entry) { $output = ""; $displayname = $entry; $show_run = true; $torrentowner = getOwner($entry); $owner = IsOwner($cfg["user"], $torrentowner); $kill_id = ""; $estTime = " "; // alias / stat $alias = getAliasName($entry) . ".stat"; if (substr(strtolower($entry), -8) == ".torrent") { // this is a torrent-client $btclient = getTorrentClient($entry); $af = AliasFile::getAliasFileInstance($dirName . $alias, $torrentowner, $cfg, $btclient); } else { if (substr(strtolower($entry), -4) == ".url") { // this is wget. use tornado statfile $alias = str_replace(".url", "", $alias); $af = AliasFile::getAliasFileInstance($dirName . $alias, $cfg['user'], $cfg, 'tornado'); } else { // this is "something else". use tornado statfile as default $af = AliasFile::getAliasFileInstance($dirName . $alias, $cfg['user'], $cfg, 'tornado'); } } //XFER: add upload/download stats to the xfer array if ($cfg['enable_xfer'] == 1 && $cfg['xfer_realtime'] == 1) { $torrentTotalsCurrent = getTorrentTotalsCurrentOP($entry, $btclient, $af->uptotal, $af->downtotal); $sql = 'SELECT 1 FROM tf_xfer WHERE date = ' . $db->DBDate(time()); $newday = !$db->GetOne($sql); showError($db, $sql); sumUsage($torrentowner, $torrentTotalsCurrent["downtotal"] + 0, $torrentTotalsCurrent["uptotal"] + 0, 'total'); sumUsage($torrentowner, $torrentTotalsCurrent["downtotal"] + 0, $torrentTotalsCurrent["uptotal"] + 0, 'month'); sumUsage($torrentowner, $torrentTotalsCurrent["downtotal"] + 0, $torrentTotalsCurrent["uptotal"] + 0, 'week'); sumUsage($torrentowner, $torrentTotalsCurrent["downtotal"] + 0, $torrentTotalsCurrent["uptotal"] + 0, 'day'); //XFER: if new day add upload/download totals to last date on record and subtract from today in SQL if ($newday) { $newday = 2; $sql = 'SELECT date FROM tf_xfer ORDER BY date DESC'; $lastDate = $db->GetOne($sql); showError($db, $sql); // MySQL 4.1.0 introduced 'ON DUPLICATE KEY UPDATE' to make this easier $sql = 'SELECT 1 FROM tf_xfer WHERE user_id = "' . $torrentowner . '" AND date = "' . $lastDate . '"'; if ($db->GetOne($sql)) { $sql = 'UPDATE tf_xfer SET download = download+' . ($torrentTotalsCurrent["downtotal"] + 0) . ', upload = upload+' . ($torrentTotalsCurrent["uptotal"] + 0) . ' WHERE user_id = "' . $torrentowner . '" AND date = "' . $lastDate . '"'; $db->Execute($sql); showError($db, $sql); } else { showError($db, $sql); $sql = 'INSERT INTO tf_xfer (user_id,date,download,upload) values ("' . $torrentowner . '","' . $lastDate . '",' . ($torrentTotalsCurrent["downtotal"] + 0) . ',' . ($torrentTotalsCurrent["uptotal"] + 0) . ')'; $db->Execute($sql); showError($db, $sql); } $sql = 'SELECT 1 FROM tf_xfer WHERE user_id = "' . $torrentowner . '" AND date = ' . $db->DBDate(time()); if ($db->GetOne($sql)) { $sql = 'UPDATE tf_xfer SET download = download-' . ($torrentTotalsCurrent["downtotal"] + 0) . ', upload = upload-' . ($torrentTotalsCurrent["uptotal"] + 0) . ' WHERE user_id = "' . $torrentowner . '" AND date = ' . $db->DBDate(time()); $db->Execute($sql); showError($db, $sql); } else { showError($db, $sql); $sql = 'INSERT INTO tf_xfer (user_id,date,download,upload) values ("' . $torrentowner . '",' . $db->DBDate(time()) . ',-' . ($torrentTotalsCurrent["downtotal"] + 0) . ',-' . ($torrentTotalsCurrent["uptotal"] + 0) . ')'; $db->Execute($sql); showError($db, $sql); } } } $timeStarted = ""; $torrentfilelink = ""; if (!file_exists($dirName . $alias)) { $af->running = "2"; // file is new $af->size = getDownloadSize($dirName . $entry); $af->WriteFile(); } if (strlen($entry) >= 47) { // needs to be trimmed $displayname = substr($entry, 0, 44); $displayname .= "..."; } if ($cfg["enable_torrent_download"]) { $torrentfilelink = "<a href=\"maketorrent.php?download=" . urlencode($entry) . "\"><img src=\"images/down.gif\" width=9 height=9 title=\"Download Torrent File\" border=0 align=\"absmiddle\"></a>"; } // $hd = getStatusImage($af); $output .= "<tr>"; $detailsLinkString = "<a style=\"font-size:9px; text-decoration:none;\" href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\">"; // ========================================================== led + meta $output .= '<td valign="bottom" align="center">'; // led $hd = getStatusImage($af); if ($af->running == 1) { $output .= "<a href=\"JavaScript:ShowDetails('downloadhosts.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\">"; } $output .= "<img src=\"images/" . $hd->image . "\" width=\"16\" height=\"16\" title=\"" . $hd->title . $entry . "\" border=\"0\" align=\"absmiddle\">"; if ($af->running == 1) { $output .= "</a>"; } // meta $output .= $torrentfilelink; $output .= "</td>"; // ================================================================ name $output .= "<td valign=\"bottom\">"; $output .= $detailsLinkString; $output .= $displayname; $output .= "</a>"; $output .= "</td>"; $output .= "<td align=\"right\"><font class=\"tiny\">" . formatBytesToKBMGGB($af->size) . "</font></td>"; $output .= "<td align=\"center\"><a href=\"message.php?to_user="******"\"><font class=\"tiny\">" . $torrentowner . "</font></a></td>"; $output .= "<td valign=\"bottom\"><div align=\"center\">"; if ($af->running == "2") { $output .= "<i><font color=\"#32cd32\">" . _NEW . "</font></i>"; } elseif ($af->running == "3") { $estTime = "Waiting..."; $qDateTime = ''; if (is_file($dirName . "queue/" . $alias . ".Qinfo")) { $qDateTime = date("m/d/Y H:i:s", strval(filectime($dirName . "queue/" . $alias . ".Qinfo"))); } $output .= "<i><font color=\"#000000\" onmouseover=\"return overlib('" . _QUEUED . ": " . $qDateTime . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">" . _QUEUED . "</font></i>"; } else { if ($af->time_left != "" && $af->time_left != "0") { $estTime = $af->time_left; } $sql_search_time = "Select time from tf_log where action like '%Upload' and file like '" . $entry . "%'"; $result_search_time = $db->Execute($sql_search_time); list($uploaddate) = $result_search_time->FetchRow(); $lastUser = $torrentowner; $sharing = $af->sharing . "%"; $graph_width = 1; $progress_color = "#00ff00"; $background = "#000000"; $bar_width = "4"; $popup_msg = _ESTIMATEDTIME . ": " . $af->time_left; $popup_msg .= "<br>" . _DOWNLOADSPEED . ": " . $af->down_speed; $popup_msg .= "<br>" . _UPLOADSPEED . ": " . $af->up_speed; $popup_msg .= "<br>" . _SHARING . ": " . $sharing; $popup_msg .= "<br>Seeds: " . $af->seeds; $popup_msg .= "<br>Peers: " . $af->peers; $popup_msg .= "<br>" . _USER . ": " . $torrentowner; $eCount = 0; foreach ($af->errors as $key => $value) { if (strpos($value, " (x")) { $curEMsg = substr($value, strpos($value, " (x") + 3); $eCount += substr($curEMsg, 0, strpos($curEMsg, ")")); } else { $eCount += 1; } } $popup_msg .= "<br>" . _ERRORSREPORTED . ": " . strval($eCount); $popup_msg .= "<br>" . _UPLOADED . ": " . date("m/d/Y H:i:s", $uploaddate); if (is_file($dirName . $alias . ".pid")) { $timeStarted = "<br>" . _STARTED . ": " . date("m/d/Y H:i:s", strval(filectime($dirName . $alias . ".pid"))); } // incriment the totals 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($af->up_speed); $cfg["total_download"] = $cfg["total_download"] + GetSpeedValue($af->down_speed); if ($af->percent_done >= 100) { if (trim($af->up_speed) != "" && $af->running == "1") { $popup_msg .= $timeStarted; $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" style=\"font-size:7pt;\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">seeding (" . $af->up_speed . ") " . $sharing . "</a>"; } else { $popup_msg .= "<br>" . _ENDED . ": " . date("m/d/Y H:i:s", strval(filemtime($dirName . $alias))); $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\"><i><font color=red>" . _DONE . "</font></i></a>"; } $show_run = false; } else { if ($af->percent_done < 0) { $popup_msg .= $timeStarted; $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\"><i><font color=\"#989898\">" . _INCOMPLETE . "</font></i></a>"; $show_run = true; } else { $popup_msg .= $timeStarted; if ($af->percent_done > 1) { $graph_width = $af->percent_done; } if ($graph_width == 100) { $background = $progress_color; } $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">"; $output .= "<font class=\"tiny\"><strong>" . $af->percent_done . "%</strong> @ " . $af->down_speed . "</font></a><br>"; $output .= "<table width=\"100\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"; $output .= "<tr><td background=\"themes/" . $cfg["theme"] . "/images/progressbar.gif\" bgcolor=\"" . $progress_color . "\"><img src=\"images/blank.gif\" width=\"" . $graph_width . "\" height=\"" . $bar_width . "\" border=\"0\"></td>"; $output .= "<td bgcolor=\"" . $background . "\"><img src=\"images/blank.gif\" width=\"" . (100 - $graph_width) . "\" height=\"" . $bar_width . "\" border=\"0\"></td>"; $output .= "</tr></table>"; } } } $output .= "</div></td>"; $output .= "<td><div class=\"tiny\" align=\"center\">" . $estTime . "</div></td>"; $output .= "<td><div align=center>"; $torrentDetails = _TORRENTDETAILS; if ($lastUser != "") { $torrentDetails .= "\n" . _USER . ": " . $lastUser; } $output .= "<a href=\"details.php?torrent=" . urlencode($entry); if ($af->running == 1) { $output .= "&als=false"; } $output .= "\"><img src=\"images/properties.png\" width=18 height=13 title=\"" . $torrentDetails . "\" border=0></a>"; if ($owner || IsAdmin($cfg["user"])) { if ($af->percent_done >= 0 && $af->running == 1) { $output .= "<a href=\"index.php?alias_file=" . $alias . "&kill=" . $kill_id . "&kill_torrent=" . urlencode($entry) . "\"><img src=\"images/kill.gif\" width=16 height=16 title=\"" . _STOPDOWNLOAD . "\" border=0></a>"; $output .= "<img src=\"images/delete_off.gif\" width=16 height=16 border=0>"; if ($cfg['enable_multiops'] == 1) { $output .= "<input type=\"checkbox\" name=\"torrent[]\" value=\"" . urlencode($entry) . "\">"; } } else { if ($torrentowner == "n/a") { $output .= "<img src=\"images/run_off.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; } else { if ($af->running == "3") { $output .= "<a href=\"index.php?alias_file=" . $alias . "&dQueue=" . $kill_id . "&QEntry=" . urlencode($entry) . "\"><img src=\"images/queued.gif\" width=16 height=16 title=\"" . _DELQUEUE . "\" border=0></a>"; } else { if (!is_file($cfg["torrent_file_path"] . $alias . ".pid")) { // Allow Avanced start popup? if ($cfg["advanced_start"] != 0) { if ($show_run) { $output .= "<a href=\"#\" onclick=\"StartTorrent('startpop.php?torrent=" . urlencode($entry) . "')\"><img src=\"images/run_on.gif\" width=16 height=16 title=\"" . _RUNTORRENT . "\" border=0></a>"; } else { $output .= "<a href=\"#\" onclick=\"StartTorrent('startpop.php?torrent=" . urlencode($entry) . "')\"><img src=\"images/seed_on.gif\" width=16 height=16 title=\"" . _SEEDTORRENT . "\" border=0></a>"; } } else { // Quick Start if ($show_run) { $output .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?torrent=" . urlencode($entry) . "\"><img src=\"images/run_on.gif\" width=16 height=16 title=\"" . _RUNTORRENT . "\" border=0></a>"; } else { $output .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?torrent=" . urlencode($entry) . "\"><img src=\"images/seed_on.gif\" width=16 height=16 title=\"" . _SEEDTORRENT . "\" border=0></a>"; } } } else { // pid file exists so this may still be running or dieing. $output .= "<img src=\"images/run_off.gif\" width=16 height=16 border=0 title=\"" . _STOPPING . "\">"; } } } if (!is_file($cfg["torrent_file_path"] . $alias . ".pid")) { $deletelink = $_SERVER['PHP_SELF'] . "?alias_file=" . $alias . "&delfile=" . urlencode($entry); $output .= "<a href=\"" . $deletelink . "\" onclick=\"return ConfirmDelete('" . $entry . "')\"><img src=\"images/delete_on.gif\" width=16 height=16 title=\"" . _DELETE . "\" border=0></a>"; if ($cfg['enable_multiops'] == 1) { $output .= "<input type=\"checkbox\" name=\"torrent[]\" value=\"" . urlencode($entry) . "\">"; } } else { // pid file present so process may be still running. don't allow deletion. $output .= "<img src=\"images/delete_off.gif\" width=16 height=16 title=\"" . _STOPPING . "\" border=0>"; if ($cfg['enable_multiops'] == 1) { $output .= "<input type=\"checkbox\" name=\"torrent[]\" value=\"" . urlencode($entry) . "\">"; } } } } else { $output .= "<img src=\"images/locked.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; $output .= "<img src=\"images/locked.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; $output .= "<input type=\"checkbox\" disabled=\"disabled\">"; } $output .= "</div>"; $output .= "</td>"; $output .= "</tr>\n"; // Is this torrent for the user list or the general list? if ($cfg["user"] == getOwner($entry)) { array_push($arUserTorrent, $output); } else { array_push($arListTorrent, $output); } } //XFER: if a new day but no .stat files where found put blank entry into the DB for today to indicate accounting has been done for the new day if ($cfg['enable_xfer'] == 1 && $cfg['xfer_realtime'] == 1) { if (isset($newday) && $newday == 1) { $sql = 'INSERT INTO tf_xfer (user_id,date) values ( "",' . $db->DBDate(time()) . ')'; $db->Execute($sql); showError($db, $sql); } getUsage(0, 'total'); $month_start = date('j') >= $cfg['month_start'] ? date('Y-m-') . $cfg['month_start'] : date('Y-m-', strtotime('-1 Month')) . $cfg['month_start']; getUsage($month_start, 'month'); $week_start = date('Y-m-d', strtotime('last ' . $cfg['week_start'])); getUsage($week_start, 'week'); $day_start = date('Y-m-d'); getUsage($day_start, 'day'); } // Now spit out the junk //XFER: return the junk as a string instead $output = '<table bgcolor="' . $cfg["table_data_bg"] . '" width="100%" bordercolor="' . $cfg["table_border_dk"] . '" border="1" cellpadding="3" cellspacing="0" class="sortable" id="transfer_table">'; if (sizeof($arUserTorrent) > 0) { $output .= "<tr>"; // first $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">"; switch ($sortOrder) { case 'da': // sort by date ascending $output .= '<a href="?so=dd"><font class="adminlink">#</font></a>'; $output .= ' '; $output .= '<a href="?so=dd"><img src="images/s_down.gif" width="9" height="9" border="0"></a>'; break; case 'dd': // sort by date descending $output .= '<a href="?so=da"><font class="adminlink">#</font></a>'; $output .= ' '; $output .= '<a href="?so=da"><img src="images/s_up.gif" width="9" height="9" border="0"></a>'; break; default: $output .= '<a href="?so=dd"><font class="adminlink">#</font></a>'; break; } $output .= "</div></td>"; // name $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">"; switch ($sortOrder) { case 'na': // sort alphabetically by name ascending $output .= '<a href="?so=nd"><font class="adminlink">' . $cfg["user"] . ": " . _TORRENTFILE . '</font></a>'; $output .= ' '; $output .= '<a href="?so=nd"><img src="images/s_down.gif" width="9" height="9" border="0"></a>'; break; case 'nd': // sort alphabetically by name descending $output .= '<a href="?so=na"><font class="adminlink">' . $cfg["user"] . ": " . _TORRENTFILE . '</font></a>'; $output .= ' '; $output .= '<a href="?so=na"><img src="images/s_up.gif" width="9" height="9" border="0"></a>'; break; default: $output .= '<a href="?so=na"><font class="adminlink">' . $cfg["user"] . ": " . _TORRENTFILE . '</font></a>'; break; } $output .= "</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">Size</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _USER . "</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _STATUS . "</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ESTIMATEDTIME . "</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ADMIN . "</div></td>"; $output .= "</tr>\n"; foreach ($arUserTorrent as $torrentrow) { $output .= $torrentrow; } } // "Only Admin can see other user torrents" $boolCond = true; if ($cfg['enable_restrictivetview'] == 1) { $boolCond = IsAdmin(); } if ($boolCond && sizeof($arListTorrent) > 0) { // "Only Admin can see other user torrents" $output .= "<tr>"; // first $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">"; switch ($sortOrder) { case 'da': // sort by date ascending $output .= '<a href="?so=dd"><font class="adminlink">#</font></a>'; $output .= ' '; $output .= '<a href="?so=dd"><img src="images/s_down.gif" width="9" height="9" border="0"></a>'; break; case 'dd': // sort by date descending $output .= '<a href="?so=da"><font class="adminlink">#</font></a>'; $output .= ' '; $output .= '<a href="?so=da"><img src="images/s_up.gif" width="9" height="9" border="0"></a>'; break; default: $output .= '<a href="?so=dd"><font class="adminlink">#</font></a>'; break; } $output .= "</div></td>"; // name $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">"; switch ($sortOrder) { case 'na': // sort alphabetically by name ascending $output .= '<a href="?so=nd"><font class="adminlink">' . _TORRENTFILE . '</font></a>'; $output .= ' '; $output .= '<a href="?so=nd"><img src="images/s_down.gif" width="9" height="9" border="0"></a>'; break; case 'nd': // sort alphabetically by name descending $output .= '<a href="?so=na"><font class="adminlink">' . _TORRENTFILE . '</font></a>'; $output .= ' '; $output .= '<a href="?so=na"><img src="images/s_up.gif" width="9" height="9" border="0"></a>'; break; default: $output .= '<a href="?so=na"><font class="adminlink">' . _TORRENTFILE . '</font></a>'; break; } $output .= "</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">Size</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _USER . "</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _STATUS . "</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ESTIMATEDTIME . "</div></td>"; $output .= "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ADMIN . "</div></td>"; $output .= "</tr>\n"; foreach ($arListTorrent as $torrentrow) { $output .= $torrentrow; } } return $output; }
/** * enqueueTorrent * @param $torrent name of the torrent */ function enqueueTorrent($torrent) { $alias = getAliasName($torrent); $this->writeQinfo($this->cfg["torrent_file_path"] . "queue/" . $alias . ".stat", $this->command); }
/** * gets total transfer-vals of a torrent * * @param $torrent * @return array with downtotal and uptotal */ function getTorrentTransferTotal($torrent) { $retVal = array(); // transfer from stat-file $aliasName = getAliasName($torrent); $owner = getOwner($torrent); $af = AliasFile::getAliasFileInstance($this->cfg["torrent_file_path"] . $aliasName . ".stat", $owner, $this->cfg, $this->handlerName); $retVal["uptotal"] = $af->uptotal + 0; $retVal["downtotal"] = $af->downtotal + 0; return $retVal; }
function getDirList($dirName) { global $cfg, $db; include_once "AliasFile.php"; include_once "RunningTorrent.php"; $runningTorrents = getRunningTorrents(); $arList = array(); $file_filter = getFileFilter($cfg["file_types_array"]); if (is_dir($dirName)) { $handle = opendir($dirName); } else { // nothing to read if (IsAdmin()) { echo "<b>ERROR:</b> " . $dirName . " Path is not valid. Please edit <a href='admin.php?op=configSettings'>settings</a><br>"; } else { echo "<b>ERROR:</b> Contact an admin the Path is not valid.<br>"; } return; } $lastUser = ""; $arUserTorrent = array(); $arListTorrent = array(); while ($entry = readdir($handle)) { if ($entry != "." && $entry != "..") { if (is_dir($dirName . "/" . $entry)) { // don''t do a thing } else { if (ereg($file_filter, $entry)) { $key = filemtime($dirName . "/" . $entry) . md5($entry); $arList[$key] = $entry; } } } } // sort the files by date krsort($arList); foreach ($arList as $entry) { $output = ""; $displayname = $entry; $show_run = true; $torrentowner = getOwner($entry); $owner = IsOwner($cfg["user"], $torrentowner); $kill_id = ""; $estTime = " "; $alias = getAliasName($entry) . ".stat"; $af = new AliasFile($dirName . $alias, $torrentowner); $timeStarted = ""; $torrentfilelink = ""; if (!file_exists($dirName . $alias)) { $af->running = "2"; // file is new $af->size = getDownloadSize($dirName . $entry); $af->WriteFile(); } if (strlen($entry) >= 47) { // needs to be trimmed $displayname = substr($entry, 0, 44); $displayname .= "..."; } // find out if any screens are running and take their PID and make a KILL option foreach ($runningTorrents as $key => $value) { $rt = new RunningTorrent($value); if ($rt->statFile == $alias) { if ($kill_id == "") { $kill_id = $rt->processId; } else { // there is more than one PID for this torrent // Add it so it can be killed as well. $kill_id .= "|" . $rt->processId; } } } // Check to see if we have a pid without a process. if (is_file($cfg["torrent_file_path"] . $alias . ".pid") && empty($kill_id)) { // died outside of tf and pid still exists. @unlink($cfg["torrent_file_path"] . $alias . ".pid"); if ($af->percent_done < 100 && $af->percent_done >= 0) { // The file is not running and the percent done needs to be changed $af->percent_done = ($af->percent_done + 100) * -1; } $af->running = "0"; $af->time_left = "Torrent Died"; $af->up_speed = ""; $af->down_speed = ""; // write over the status file so that we can display a new status $af->WriteFile(); } if ($cfg["enable_torrent_download"]) { $torrentfilelink = "<a href=\"maketorrent.php?download=" . urlencode($entry) . "\"><img src=\"images/down.gif\" width=9 height=9 title=\"Download Torrent File\" border=0 align=\"absmiddle\"></a>"; } $hd = getStatusImage($af); $output .= "<tr><td class=\"tiny\"><img src=\"images/" . $hd->image . "\" width=16 height=16 title=\"" . $hd->title . $entry . "\" border=0 align=\"absmiddle\">" . $torrentfilelink . $displayname . "</td>"; $output .= "<td align=\"right\"><font class=\"tiny\">" . formatBytesToKBMGGB($af->size) . "</font></td>"; $output .= "<td align=\"center\"><a href=\"message.php?to_user="******"\"><font class=\"tiny\">" . $torrentowner . "</font></a></td>"; $output .= "<td valign=\"bottom\"><div align=\"center\">"; if ($af->running == "2") { $output .= "<i><font color=\"#32cd32\">" . _NEW . "</font></i>"; } elseif ($af->running == "3") { $estTime = "Waiting..."; $qDateTime = ''; if (is_file($dirName . "queue/" . $alias . ".Qinfo")) { $qDateTime = date("m/d/Y H:i:s", strval(filectime($dirName . "queue/" . $alias . ".Qinfo"))); } $output .= "<i><font color=\"#000000\" onmouseover=\"return overlib('" . _QUEUED . ": " . $qDateTime . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">" . _QUEUED . "</font></i>"; } else { if ($af->time_left != "" && $af->time_left != "0") { $estTime = $af->time_left; } $sql_search_time = "Select time from tf_log where action like '%Upload' and file like '" . $entry . "%'"; $result_search_time = $db->Execute($sql_search_time); list($uploaddate) = $result_search_time->FetchRow(); $lastUser = $torrentowner; $sharing = $af->sharing . "%"; $graph_width = 1; $progress_color = "#00ff00"; $background = "#000000"; $bar_width = "4"; $popup_msg = _ESTIMATEDTIME . ": " . $af->time_left; $popup_msg .= "<br>" . _DOWNLOADSPEED . ": " . $af->down_speed; $popup_msg .= "<br>" . _UPLOADSPEED . ": " . $af->up_speed; $popup_msg .= "<br>" . _SHARING . ": " . $sharing; $popup_msg .= "<br>Seeds: " . $af->seeds; $popup_msg .= "<br>Peers: " . $af->peers; $popup_msg .= "<br>" . _USER . ": " . $torrentowner; $eCount = 0; foreach ($af->errors as $key => $value) { if (strpos($value, " (x")) { $curEMsg = substr($value, strpos($value, " (x") + 3); $eCount += substr($curEMsg, 0, strpos($curEMsg, ")")); } else { $eCount += 1; } } $popup_msg .= "<br>" . _ERRORSREPORTED . ": " . strval($eCount); $popup_msg .= "<br>" . _UPLOADED . ": " . date("m/d/Y H:i:s", $uploaddate); if (is_file($dirName . $alias . ".pid")) { $timeStarted = "<br>" . _STARTED . ": " . date("m/d/Y H:i:s", strval(filectime($dirName . $alias . ".pid"))); } // incriment the totals 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($af->up_speed); $cfg["total_download"] = $cfg["total_download"] + GetSpeedValue($af->down_speed); if ($af->percent_done >= 100) { if (trim($af->up_speed) != "" && $af->running == "1") { $popup_msg .= $timeStarted; $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" style=\"font-size:7pt;\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">seeding (" . $af->up_speed . ") " . $sharing . "</a>"; } else { $popup_msg .= "<br>" . _ENDED . ": " . date("m/d/Y H:i:s", strval(filemtime($dirName . $alias))); $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\"><i><font color=red>" . _DONE . "</font></i></a>"; } $show_run = false; } else { if ($af->percent_done < 0) { $popup_msg .= $timeStarted; $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\"><i><font color=\"#989898\">" . _INCOMPLETE . "</font></i></a>"; $show_run = true; } else { $popup_msg .= $timeStarted; if ($af->percent_done > 1) { $graph_width = $af->percent_done; } if ($graph_width == 100) { $background = $progress_color; } $output .= "<a href=\"JavaScript:ShowDetails('downloaddetails.php?alias=" . $alias . "&torrent=" . urlencode($entry) . "')\" onmouseover=\"return overlib('" . $popup_msg . "<br>', CSSCLASS);\" onmouseout=\"return nd();\">"; $output .= "<font class=\"tiny\"><strong>" . $af->percent_done . "%</strong> @ " . $af->down_speed . "</font></a><br>"; $output .= "<table width=\"100\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"; $output .= "<tr><td background=\"themes/" . $cfg["theme"] . "/images/progressbar.gif\" bgcolor=\"" . $progress_color . "\"><img src=\"images/blank.gif\" width=\"" . $graph_width . "\" height=\"" . $bar_width . "\" border=\"0\"></td>"; $output .= "<td bgcolor=\"" . $background . "\"><img src=\"images/blank.gif\" width=\"" . (100 - $graph_width) . "\" height=\"" . $bar_width . "\" border=\"0\"></td>"; $output .= "</tr></table>"; } } } $output .= "</div></td>"; $output .= "<td><div class=\"tiny\" align=\"center\">" . $estTime . "</div></td>"; $output .= "<td><div align=center>"; $torrentDetails = _TORRENTDETAILS; if ($lastUser != "") { $torrentDetails .= "\n" . _USER . ": " . $lastUser; } $output .= "<a href=\"details.php?torrent=" . urlencode($entry); if ($af->running == 1) { $output .= "&als=false"; } $output .= "\"><img src=\"images/properties.png\" width=18 height=13 title=\"" . $torrentDetails . "\" border=0></a>"; if ($owner || IsAdmin($cfg["user"])) { if ($kill_id != "" && $af->percent_done >= 0 && $af->running == 1) { $output .= "<a href=\"index.php?alias_file=" . $alias . "&kill=" . $kill_id . "&kill_torrent=" . urlencode($entry) . "\"><img src=\"images/kill.gif\" width=16 height=16 title=\"" . _STOPDOWNLOAD . "\" border=0></a>"; $output .= "<img src=\"images/delete_off.gif\" width=16 height=16 border=0>"; } else { if ($torrentowner == "n/a") { $output .= "<img src=\"images/run_off.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; } else { if ($af->running == "3") { $output .= "<a href=\"index.php?alias_file=" . $alias . "&dQueue=" . $kill_id . "&QEntry=" . urlencode($entry) . "\"><img src=\"images/queued.gif\" width=16 height=16 title=\"" . _DELQUEUE . "\" border=0></a>"; } else { if (!is_file($cfg["torrent_file_path"] . $alias . ".pid")) { // Allow Avanced start popup? if ($cfg["advanced_start"]) { if ($show_run) { $output .= "<a href=\"#\" onclick=\"StartTorrent('startpop.php?torrent=" . urlencode($entry) . "')\"><img src=\"images/run_on.gif\" width=16 height=16 title=\"" . _RUNTORRENT . "\" border=0></a>"; } else { $output .= "<a href=\"#\" onclick=\"StartTorrent('startpop.php?torrent=" . urlencode($entry) . "')\"><img src=\"images/seed_on.gif\" width=16 height=16 title=\"" . _SEEDTORRENT . "\" border=0></a>"; } } else { // Quick Start if ($show_run) { $output .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?torrent=" . urlencode($entry) . "\"><img src=\"images/run_on.gif\" width=16 height=16 title=\"" . _RUNTORRENT . "\" border=0></a>"; } else { $output .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?torrent=" . urlencode($entry) . "\"><img src=\"images/seed_on.gif\" width=16 height=16 title=\"" . _SEEDTORRENT . "\" border=0></a>"; } } } else { // pid file exists so this may still be running or dieing. $output .= "<img src=\"images/run_off.gif\" width=16 height=16 border=0 title=\"" . _STOPPING . "\">"; } } } if (!is_file($cfg["torrent_file_path"] . $alias . ".pid")) { $deletelink = $_SERVER['PHP_SELF'] . "?alias_file=" . $alias . "&delfile=" . urlencode($entry); $output .= "<a href=\"" . $deletelink . "\" onclick=\"return ConfirmDelete('" . $entry . "')\"><img src=\"images/delete_on.gif\" width=16 height=16 title=\"" . _DELETE . "\" border=0></a>"; } else { // pid file present so process may be still running. don't allow deletion. $output .= "<img src=\"images/delete_off.gif\" width=16 height=16 title=\"" . _STOPPING . "\" border=0>"; } } } else { $output .= "<img src=\"images/locked.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; $output .= "<img src=\"images/locked.gif\" width=16 height=16 border=0 title=\"" . _NOTOWNER . "\">"; } $output .= "</div>"; $output .= "</td>"; $output .= "</tr>\n"; // Is this torrent for the user list or the general list? if ($cfg["user"] == getOwner($entry)) { array_push($arUserTorrent, $output); } else { array_push($arListTorrent, $output); } } closedir($handle); // Now spit out the junk echo "<table bgcolor=\"" . $cfg["table_data_bg"] . "\" width=\"100%\" bordercolor=\"" . $cfg["table_border_dk"] . "\" border=1 cellpadding=3 cellspacing=0>"; if (sizeof($arUserTorrent) > 0) { echo "<tr><td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . $cfg["user"] . ": " . _TORRENTFILE . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">Size</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _USER . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _STATUS . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ESTIMATEDTIME . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ADMIN . "</div></td>"; echo "</tr>\n"; foreach ($arUserTorrent as $torrentrow) { echo $torrentrow; } } if (sizeof($arListTorrent) > 0) { echo "<tr><td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _TORRENTFILE . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">Size</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _USER . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _STATUS . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ESTIMATEDTIME . "</div></td>"; echo "<td background=\"themes/" . $cfg["theme"] . "/images/bar.gif\" bgcolor=\"" . $cfg["table_header_bg"] . "\"><div align=center class=\"title\">" . _ADMIN . "</div></td>"; echo "</tr>\n"; foreach ($arListTorrent as $torrentrow) { echo $torrentrow; } } }
function cliWipeTorrent($torrent = "") { global $cfg; if (isset($torrent) && $torrent != "") { echo "Wipe " . $torrent . " ..."; $torrentRunningFlag = isTorrentRunning($torrent); $btclient = getTorrentClient($torrent); $cfg["user"] = getOwner($torrent); $alias = getAliasName($torrent) . ".stat"; if ($torrentRunningFlag == 1) { // stop torrent first $clientHandler = ClientHandler::getClientHandlerInstance($cfg, $btclient); $clientHandler->stopTorrentClient($torrent, $alias); // give the torrent some time to die sleep(6); } deleteTorrentData($torrent); resetTorrentTotals($torrent, true); echo "done\n"; } else { printUsage(); } exit; }
/** * prepares start of a bittorrent-client. * prepares vars and other generic stuff * @param $torrent name of the torrent * @param $interactive (1|0) : is this a interactive startup with dialog ? */ function prepareStartTorrentClient($torrent, $interactive) { if ($this->status < 1) { $this->status = -1; $this->messages .= "Error. ClientHandler in wrong state on prepare-request."; return; } $this->skip_hash_check = ""; if ($interactive == 1) { // interactive, get vars from request vars $this->rate = getRequestVar('rate'); if (empty($this->rate)) { if ($this->rate != "0") { $this->rate = $this->cfg["max_upload_rate"]; } } $this->drate = getRequestVar('drate'); if (empty($this->drate)) { if ($this->drate != "0") { $this->drate = $this->cfg["max_download_rate"]; } } $this->superseeder = getRequestVar('superseeder'); if (empty($this->superseeder)) { $this->superseeder = "0"; } // should be 0 in most cases $this->runtime = getRequestVar('runtime'); if (empty($this->runtime)) { $this->runtime = $this->cfg["torrent_dies_when_done"]; } $this->maxuploads = getRequestVar('maxuploads'); if (empty($this->maxuploads)) { if ($this->maxuploads != "0") { $this->maxuploads = $this->cfg["max_uploads"]; } } $this->minport = getRequestVar('minport'); if (empty($this->minport)) { $this->minport = $this->cfg["minport"]; } $this->maxport = getRequestVar('maxport'); if (empty($this->maxport)) { $this->maxport = $this->cfg["maxport"]; } $this->maxcons = getRequestVar('maxcons'); if (empty($this->maxcons)) { $this->maxcons = $this->cfg["maxcons"]; } $this->rerequest = getRequestVar("rerequest"); if (empty($this->rerequest)) { $this->rerequest = $this->cfg["rerequest_interval"]; } $this->sharekill = getRequestVar('sharekill'); if ($this->runtime == "True") { $this->sharekill = "-1"; } if (empty($this->sharekill)) { if ($this->sharekill != "0") { $this->sharekill = $this->cfg["sharekill"]; } } $this->savepath = getRequestVar('savepath'); $this->skip_hash_check = getRequestVar('skiphashcheck'); } else { // non-interactive, load settings from db and set vars $this->rerequest = $this->cfg["rerequest_interval"]; $this->skip_hash_check = $this->cfg["skiphashcheck"]; $this->superseeder = 0; // load settings $settingsAry = loadTorrentSettings(urldecode($torrent)); $this->rate = $settingsAry["max_upload_rate"]; $this->drate = $settingsAry["max_download_rate"]; $this->runtime = $settingsAry["torrent_dies_when_done"]; $this->maxuploads = $settingsAry["max_uploads"]; $this->minport = $settingsAry["minport"]; $this->maxport = $settingsAry["maxport"]; $this->maxcons = $settingsAry["maxcons"]; $this->sharekill = $settingsAry["sharekill"]; $this->savepath = $settingsAry["savepath"]; // fallback-values if fresh-torrent is started non-interactive or // something else strange happened if ($this->rate == '') { $this->rate = $this->cfg["max_upload_rate"]; } if ($this->drate == '') { $this->drate = $this->cfg["max_download_rate"]; } if ($this->runtime == '') { $this->runtime = $this->cfg["torrent_dies_when_done"]; } if ($this->maxuploads == '') { $this->maxuploads = $this->cfg["max_uploads"]; } if ($this->minport == '') { $this->minport = $this->cfg["minport"]; } if ($this->maxport == '') { $this->maxport = $this->cfg["maxport"]; } if ($this->maxcons == '') { $this->maxcons = $this->cfg["maxcons"]; } if ($this->sharekill == '') { $this->sharekill = $this->cfg["sharekill"]; } } // queue if ($this->cfg["AllowQueing"]) { if (IsAdmin()) { $this->queue = getRequestVar('queue'); if ($this->queue == 'on') { $this->queue = "1"; } else { $this->queue = "0"; } } else { $this->queue = "1"; } } else { $this->queue = "0"; } // $this->torrent = urldecode($torrent); $this->alias = getAliasName($this->torrent); $this->owner = getOwner($this->torrent); if (empty($this->savepath)) { $this->savepath = $this->cfg['path'] . $this->owner . "/"; } // ensure path has trailing slash $this->savepath = checkDirPathString($this->savepath); // The following lines of code were suggested by Jody Steele jmlsteele@stfu.ca // This is to help manage user downloads by their user names // if the user's path doesnt exist, create it if (!is_dir($this->cfg["path"] . "/" . $this->owner)) { if (is_writable($this->cfg["path"])) { mkdir($this->cfg["path"] . "/" . $this->owner, 0777); } else { AuditAction($this->cfg["constants"]["error"], "Error -- " . $this->cfg["path"] . " is not writable."); if (IsAdmin()) { $this->status = -1; header("location: admin.php?op=configSettings"); return; } else { $this->status = -1; $this->messages .= "Error. TorrentFlux settings are not correct (path is not writable) -- please contact an admin."; } } } // create AliasFile object and write out the stat file include_once "AliasFile.php"; $this->af = AliasFile::getAliasFileInstance($this->cfg["torrent_file_path"] . $this->alias . ".stat", $this->owner, $this->cfg, $this->handlerName); //XFER: before a torrent start/restart save upload/download xfer to SQL $torrentTotals = getTorrentTotalsCurrent($this->torrent); saveXfer($this->owner, $torrentTotals["downtotal"] + 0, $torrentTotals["uptotal"] + 0); // update totals for this torrent updateTorrentTotals($this->torrent); // set param for sharekill if ($this->sharekill <= 0) { // nice, we seed forever $this->sharekill_param = 0; } else { // recalc sharekill $totalAry = getTorrentTotals(urldecode($torrent)); $upTotal = $totalAry["uptotal"] + 0; $torrentSize = $this->af->size + 0; $upWanted = $this->sharekill / 100 * $torrentSize; if ($upTotal >= $upWanted) { // we already have seeded at least // wanted percentage. continue to seed // forever is suitable in this case ~~ $this->sharekill_param = 0; } else { // not done seeding wanted percentage $this->sharekill_param = (int) ($this->sharekill - $upTotal / $torrentSize * 100); // the type-cast may have floored the value. (tornado lacks // precision because only (really?) accepting percentage-values) // better to seed more than less so we add a percent in case ;) if ($upWanted % $upTotal != 0) { $this->sharekill_param += 1; } // sanity-check. if ($this->sharekill_param <= -1) { $this->sharekill_param = 0; } } } if ($this->cfg["AllowQueing"]) { if ($this->queue == "1") { $this->af->QueueTorrentFile(); // this only writes out the stat file (does not start torrent) } else { if ($this->setClientPort() === false) { return; } $this->af->StartTorrentFile(); // this only writes out the stat file (does not start torrent) } } else { if ($this->setClientPort() === false) { return; } $this->af->StartTorrentFile(); // this only writes out the stat file (does not start torrent) } $this->status = 2; }
AuditAction($cfg["constants"]["error"], $cfg["constants"]["file_upload"] . " :: " . $ext_msg . $file_name); } } // End File Upload // if a file was set to be deleted then delete it $delfile = SecurityClean(getRequestVar('delfile')); if (!$delfile == '') { $alias_file = SecurityClean(getRequestVar('alias_file')); if ($cfg["user"] == getOwner($delfile) || IsAdmin()) { @unlink($cfg["torrent_file_path"] . $delfile); @unlink($cfg["torrent_file_path"] . $alias_file); // try to remove the QInfo if in case it was queued. @unlink($cfg["torrent_file_path"] . "queue/" . $alias_file . ".Qinfo"); // try to remove the pid file @unlink($cfg["torrent_file_path"] . $alias_file . ".pid"); @unlink($cfg["torrent_file_path"] . getAliasName($delfile) . ".prio"); AuditAction($cfg["constants"]["delete_torrent"], $delfile); header("location: index.php"); exit; } else { AuditAction($cfg["constants"]["error"], $cfg["user"] . " attempted to delete " . $delfile); } } // Did the user select the option to kill a running torrent? $kill = getRequestVar('kill'); if (!$kill == '' && is_numeric($kill)) { include_once "AliasFile.php"; include_once "RunningTorrent.php"; $kill_torrent = getRequestVar('kill_torrent'); $alias_file = SecurityClean(getRequestVar('alias_file')); // We are going to write a '0' on the front of the stat file so that
function sendRss() { global $cfg, $sendAsAttachment, $arList; $content = ""; $run = 0; // build content $content .= "<?xml version='1.0' ?>\n\n"; //$content .= '<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">'."\n"; $content .= "<rss version=\"0.91\">\n"; $content .= "<channel>\n"; $content .= "<title>TorrentFlux Status</title>\n"; // transfer-list foreach ($arList as $entry) { $torrentowner = getOwner($entry); $torrentTotals = getTorrentTotals($entry); // alias / stat $alias = getAliasName($entry) . ".stat"; if (substr(strtolower($entry), -8) == ".torrent") { // this is a torrent-client $btclient = getTorrentClient($entry); $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . $alias, $torrentowner, $cfg, $btclient); } else { if (substr(strtolower($entry), -4) == ".url") { // this is wget. use tornado statfile $alias = str_replace(".url", "", $alias); $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . $alias, $cfg['user'], $cfg, 'tornado'); } else { // this is "something else". use tornado statfile as default $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . $alias, $cfg['user'], $cfg, 'tornado'); } } // increment the totals 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($af->up_speed); $cfg["total_download"] = $cfg["total_download"] + GetSpeedValue($af->down_speed); // xml-string $remaining = str_replace('∞', 'Unknown', $af->time_left); if ($af->running == 1) { $run++; } else { $remaining = "Torrent Not Running"; } $sharing = number_format($torrentTotals['uptotal'] / ($af->size + 0), 2); $content .= "<item>\n"; $content .= "<title>" . $entry . " (" . $remaining . ")</title>\n"; $content .= "<description>Down Speed: " . $af->down_speed . " || Up Speed: " . $af->up_speed . " || Size: " . @formatBytesToKBMGGB($af->size) . " || Percent: " . $af->percent_done . " || Sharing: " . $sharing . " || Remaining: " . $remaining . " || Transfered Down: " . @formatBytesToKBMGGB($torrentTotals['downtotal']) . " || Transfered Up: " . @formatBytesToKBMGGB($torrentTotals['uptotal']) . "</description>\n"; $content .= "</item>\n"; } $content .= "<item>\n"; $content .= "<title>Total (" . $run . ")</title>\n"; $content .= "<description>Down Speed: " . @number_format($cfg["total_download"], 2) . " || Up Speed: " . @number_format($cfg["total_upload"], 2) . " || Free Space: " . @formatFreeSpace($cfg['free_space']) . "</description>\n"; $content .= "</item>\n"; $content .= "</channel>\n"; $content .= "</rss>"; // send content header("Cache-Control: "); header("Pragma: "); header("Content-Type: text/xml"); if ($sendAsAttachment != 0) { header("Content-Length: " . strlen($content)); header('Content-Disposition: attachment; filename="stats.xml"'); } echo $content; }
/** * gets total transfer-vals of a torrent * * @param $torrent * @return array with downtotal and uptotal */ function getTorrentTransferTotal($torrent) { global $db; $retVal = array(); // transfer from db $torrentId = getTorrentHash($torrent); $sql = "SELECT uptotal,downtotal FROM tf_torrent_totals WHERE tid = '" . $torrentId . "'"; $result = $db->Execute($sql); showError($db, $sql); $row = $result->FetchRow(); if (!empty($row)) { $retVal["uptotal"] = $row["uptotal"]; $retVal["downtotal"] = $row["downtotal"]; } else { $retVal["uptotal"] = 0; $retVal["downtotal"] = 0; } // transfer from stat-file $aliasName = getAliasName($torrent); $owner = getOwner($torrent); $af = AliasFile::getAliasFileInstance($this->cfg["torrent_file_path"] . $aliasName . ".stat", $owner, $this->cfg, $this->handlerName); $retVal["uptotal"] += $af->uptotal + 0; $retVal["downtotal"] += $af->downtotal + 0; return $retVal; }
/** * prepares start of a bittorrent-client. * prepares vars and other generic stuff * @param $torrent name of the torrent * @param $interactive (1|0) : is this a interactive startup with dialog ? */ function prepareStartTorrentClient($torrent, $interactive) { if ($this->state < 1) { $this->state = -1; $this->messages .= "Error. ClientHandler in wrong state on prepare-request."; return; } $this->skip_hash_check = ""; if ($interactive == 1) { // interactive, get vars from request vars $this->rate = getRequestVar('rate'); if (empty($this->rate)) { if ($this->rate != "0") { $this->rate = $this->cfg["max_upload_rate"]; } } $this->drate = getRequestVar('drate'); if (empty($this->drate)) { if ($this->drate != "0") { $this->drate = $this->cfg["max_download_rate"]; } } $this->superseeder = getRequestVar('superseeder'); if (empty($this->superseeder)) { $this->superseeder = "0"; } // should be 0 in most cases $this->runtime = getRequestVar('runtime'); if (empty($this->runtime)) { $this->runtime = $this->cfg["torrent_dies_when_done"]; } $this->maxuploads = getRequestVar('maxuploads'); if (empty($this->maxuploads)) { if ($this->maxuploads != "0") { $this->maxuploads = $this->cfg["max_uploads"]; } } $this->minport = getRequestVar('minport'); if (empty($this->minport)) { $this->minport = $this->cfg["minport"]; } $this->maxport = getRequestVar('maxport'); if (empty($this->maxport)) { $this->maxport = $this->cfg["maxport"]; } $this->maxcons = getRequestVar('maxcons'); if (empty($this->maxcons)) { $this->maxcons = $this->cfg["maxcons"]; } $this->rerequest = getRequestVar("rerequest"); if (empty($this->rerequest)) { $this->rerequest = $this->cfg["rerequest_interval"]; } $this->sharekill = getRequestVar('sharekill'); if ($this->runtime == "True") { $this->sharekill = "-1"; } if (empty($this->sharekill)) { if ($this->sharekill != "0") { $this->sharekill = $this->cfg["sharekill"]; } } $this->savepath = getRequestVar('savepath'); $this->skip_hash_check = getRequestVar('skiphashcheck'); } else { // non-interactive, load settings from db and set vars $this->rerequest = $this->cfg["rerequest_interval"]; $this->skip_hash_check = $this->cfg["skiphashcheck"]; $this->superseeder = 0; // load settings $settingsAry = loadTorrentSettings(urldecode($torrent)); $this->rate = $settingsAry["max_upload_rate"]; $this->drate = $settingsAry["max_download_rate"]; $this->runtime = $settingsAry["torrent_dies_when_done"]; $this->maxuploads = $settingsAry["max_uploads"]; $this->minport = $settingsAry["minport"]; $this->maxport = $settingsAry["maxport"]; $this->maxcons = $settingsAry["maxcons"]; $this->sharekill = $settingsAry["sharekill"]; $this->savepath = $settingsAry["savepath"]; // fallback-values if fresh-torrent is started non-interactive or // something else strange happened if ($this->rate == '') { $this->rate = $this->cfg["max_upload_rate"]; } if ($this->drate == '') { $this->drate = $this->cfg["max_download_rate"]; } if ($this->runtime == '') { $this->runtime = $this->cfg["torrent_dies_when_done"]; } if ($this->maxuploads == '') { $this->maxuploads = $this->cfg["max_uploads"]; } if ($this->minport == '') { $this->minport = $this->cfg["minport"]; } if ($this->maxport == '') { $this->maxport = $this->cfg["maxport"]; } if ($this->maxcons == '') { $this->maxcons = $this->cfg["maxcons"]; } if ($this->sharekill == '') { $this->sharekill = $this->cfg["sharekill"]; } } // queue if ($this->cfg["AllowQueing"]) { if (IsAdmin()) { $this->queue = getRequestVar('queue'); if ($this->queue == 'on') { $this->queue = "1"; } else { $this->queue = "0"; } } else { $this->queue = "1"; } } else { $this->queue = "0"; } // $this->torrent = urldecode($torrent); $this->alias = getAliasName($this->torrent); $this->owner = getOwner($this->torrent); if (empty($this->savepath)) { $this->savepath = $this->cfg['path'] . $this->owner . "/"; } // ensure path has trailing slash $this->savepath = checkDirPathString($this->savepath); // check target-directory, create if not present if (!checkDirectory($this->savepath, 0777)) { AuditAction($this->cfg["constants"]["error"], "Error checking " . $this->savepath . "."); $this->state = -1; $this->messages .= "Error. TorrentFlux settings are not correct (path-setting)."; global $argv; if (isset($argv)) { die($this->messages); } else { if (IsAdmin()) { @header("location: admin.php?op=configSettings"); exit; } else { $this->messages .= " please contact an admin."; showErrorPage($this->messages); } } } // create AliasFile object and write out the stat file include_once "AliasFile.php"; $this->af = AliasFile::getAliasFileInstance($this->cfg["torrent_file_path"] . $this->alias . ".stat", $this->owner, $this->cfg, $this->handlerName); // set param for sharekill $this->sharekill = intval($this->sharekill); if ($this->sharekill == 0) { // nice, we seed forever $this->sharekill_param = 0; } elseif ($this->sharekill > 0) { // recalc sharekill // sanity-check. catch "data-size = 0". $transferSize = intval($this->af->size); if ($transferSize > 0) { $totalAry = getTorrentTotals($this->torrent); $upTotal = $totalAry["uptotal"] + 0; $downTotal = $totalAry["downtotal"] + 0; $upWanted = $this->sharekill / 100 * $transferSize; $sharePercentage = $upTotal / $transferSize * 100; if ($upTotal >= $upWanted && $downTotal >= $transferSize) { // we already have seeded at least wanted percentage. // skip start of client // set state $this->state = 1; // message $this->messages = "skipping start of transfer " . $this->torrent . " due to share-ratio (has: " . @number_format($sharePercentage, 2) . " ; set:" . $this->sharekill . ")"; // DEBUG : log the messages AuditAction($this->cfg["constants"]["debug"], $this->messages); // return return; } else { // not done seeding wanted percentage $this->sharekill_param = intval(ceil($this->sharekill - $sharePercentage)); // sanity-check. if ($this->sharekill_param < 1) { $this->sharekill_param = 1; } } } else { $this->messages = "data-size is 0 when recalcing share-kill for " . $this->torrent . ". setting sharekill absolute to " . $this->sharekill; AuditAction($this->cfg["constants"]["error"], $this->messages); $this->sharekill_param = $this->sharekill; } } else { $this->sharekill_param = $this->sharekill; } // set port if start (not queue) if (!($this->cfg["AllowQueing"] && $this->queue == "1")) { if ($this->setClientPort() === false) { return; } } //XFER: before a torrent start/restart save upload/download xfer to SQL $torrentTotals = getTorrentTotalsCurrent($this->torrent); saveXfer($this->owner, $torrentTotals["downtotal"] + 0, $torrentTotals["uptotal"] + 0); // update totals for this torrent updateTorrentTotals($this->torrent); // write stat-file if ($this->cfg["AllowQueing"] && $this->queue == "1") { $this->af->QueueTorrentFile(); } else { $this->af->StartTorrentFile(); } // set state $this->state = 2; }
function showMetaInfo($torrent, $allowSave = false) { global $cfg; if (empty($torrent) || !file_exists($cfg["torrent_file_path"] . $torrent)) { echo _NORECORDSFOUND; } elseif ($cfg["enable_file_priority"]) { $prioFileName = $cfg["torrent_file_path"] . getAliasName($torrent) . ".prio"; require_once 'BDecode.php'; echo '<link rel="StyleSheet" href="dtree.css" type="text/css" /><script type="text/javascript" src="dtree.js"></script>'; $ftorrent = $cfg["torrent_file_path"] . $torrent; $fp = fopen($ftorrent, "rd"); if (!$fp) { // Not able to open file echo _NORECORDSFOUND; } else { $alltorrent = fread($fp, filesize($ftorrent)); fclose($fp); $btmeta = BDecode($alltorrent); $torrent_size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20); if (array_key_exists('files', $btmeta['info'])) { $dirnum = count($btmeta['info']['files']); } else { $dirnum = 0; } if (is_readable($prioFileName)) { $prio = split(',', 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])); } } } } echo "<table><tr>"; echo "<tr><td width=\"110\">Metainfo File:</td><td>" . $torrent . "</td></tr>"; echo "<tr><td>Directory Name:</td><td>" . htmlentities($btmeta['info']['name'], ENT_QUOTES) . "</td></tr>"; echo "<tr><td>Announce URL:</td><td>" . htmlentities($btmeta['announce'], ENT_QUOTES) . "</td></tr>"; if (array_key_exists('comment', $btmeta)) { echo "<tr><td valign=\"top\">Comment:</td><td>" . htmlentities($btmeta['comment'], ENT_QUOTES) . "</td></tr>"; } echo "<tr><td>Created:</td><td>" . date("F j, Y, g:i a", $btmeta['creation date']) . "</td></tr>"; echo "<tr><td>Torrent Size:</td><td>" . $torrent_size . " (" . formatBytesToKBMGGB($torrent_size) . ")</td></tr>"; echo "<tr><td>Chunk size:</td><td>" . $btmeta['info']['piece length'] . " (" . formatBytesToKBMGGB($btmeta['info']['piece length']) . ")</td></tr>"; if (array_key_exists('files', $btmeta['info'])) { echo "<tr><td>Selected size:</td><td id=\"sel\">0</td></tr>"; echo "</table><br>\n"; if ($allowSave) { echo "<form name=\"priority\" action=\"index.php\" method=\"POST\" >"; echo "<input type=\"hidden\" name=\"torrent\" value=\"" . $torrent . "\" >"; echo "<input type=\"hidden\" name=\"setPriorityOnly\" value=\"true\" >"; } echo "<script type=\"text/javascript\">\n"; echo "var sel = 0;\n"; echo "d = new dTree('d');\n"; $tree->draw(-1); echo "document.write(d);\n"; echo "sel = getSizes();\n"; echo "drawSel();\n"; echo "</script>\n"; echo "<input type=\"hidden\" name=\"filecount\" value=\"" . count($btmeta['info']['files']) . "\">"; echo "<input type=\"hidden\" name=\"count\" value=\"" . $dirnum . "\">"; echo "<br>"; if ($allowSave) { echo '<input type="submit" value="Save" >'; echo "<br>"; } echo "</form>"; } else { echo "</table><br>"; echo htmlentities($btmeta['info']['name'] . $torrent_size . " (" . formatBytesToKBMGGB($torrent_size) . ")", ENT_QUOTES); } } } else { $result = shell_exec("cd " . $cfg["torrent_file_path"] . "; " . $cfg["pythonCmd"] . " -OO " . $cfg["btshowmetainfo"] . " " . escapeshellarg($torrent)); echo "<pre>"; echo htmlentities($result, ENT_QUOTES); echo "</pre>"; } }
include_once "setpriority.php"; // Process setPriority Request. setPriority(urldecode($element)); } include_once "ClientHandler.php"; $clientHandler = ClientHandler::getClientHandlerInstance($cfg, $btclient); $clientHandler->startTorrentClient(urldecode($element), 0); // just a sec.. sleep(1); } break; case "torrentDeQueue": /* torrentDeQueue */ if ($torrentRunningFlag == 0) { // set request var $_REQUEST['alias_file'] = getAliasName($element) . ".stat"; // dequeue it include_once "QueueManager.php"; $queueManager = QueueManager::getQueueManagerInstance($cfg); $queueManager->dequeueTorrent($element); // just a sec.. sleep(1); } break; case "torrentResetTotals": /* torrentResetTotals */ resetTorrentTotals(urldecode($element), false); break; default: if ($torrentRunningFlag != 0) { // stop torrent first
/** * injects a atorrent * * @param $torrent * @return boolean */ function injectTorrent($torrent) { global $cfg; include_once "AliasFile.php"; $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . getAliasName($torrent) . ".stat", $cfg['user'], $cfg); $af->running = "2"; // file is new $af->size = getDownloadSize($cfg["torrent_file_path"] . $torrent); $af->WriteFile(); return true; }
if (!ereg("(\\.\\.\\/)", $del)) { avddelete($cfg["path"] . $del); $arTemp = explode("/", $del); if (count($arTemp) > 1) { array_pop($arTemp); $current = implode("/", $arTemp); } AuditAction($cfg["constants"]["fm_delete"], $del); } else { AuditAction($cfg["constants"]["error"], "ILLEGAL DELETE: " . $cfg['user'] . " tried to delete " . $del); } } } @unlink($cfg["torrent_file_path"] . $element); @unlink($cfg["torrent_file_path"] . $alias); @unlink($cfg["torrent_file_path"] . getAliasName($element) . ".prio"); AuditAction($cfg["constants"]["delete_torrent"], $element); } else { AuditAction($cfg["constants"]["error"], $cfg["user"] . " attempted to delete " . $element); } } } else { if ($action == "fileDelete") { $file = getRequestVar("file"); // Lets delete some files if (is_array($file)) { foreach ($file as $key => $element) { $element = urldecode($element); delFile($element); } }