/** * init */ function transfer_init() { global $cfg, $tmpl, $transfer, $transferLabel, $ch; // request-var $transfer = tfb_getRequestVar('transfer'); if (empty($transfer)) { @error("missing params", "", "", array('transfer')); } // validate transfer if (tfb_isValidTransfer($transfer) !== true) { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer); @error("Invalid Transfer", "", "", array($transfer)); } // permission if (!$cfg['isAdmin'] && !IsOwner($cfg["user"], getOwner($transfer))) { AuditAction($cfg["constants"]["error"], "ACCESS DENIED: " . $transfer); @error("Access Denied", "", "", array($transfer)); } // get label $transferLabel = strlen($transfer) >= 39 ? substr($transfer, 0, 35) . "..." : $transfer; // set transfer vars $tmpl->setvar('transfer', $transfer); $tmpl->setvar('transferLabel', $transferLabel); $tmpl->setvar('transfer_exists', transferExists($transfer) ? 1 : 0); }
/** * init */ function transfer_init() { global $cfg, $tmpl, $transfer, $transferLabel, $ch; // request-var $transfer = tfb_getRequestVar('transfer'); if (empty($transfer)) { @error("missing params", "", "", array('transfer')); } if ($cfg["transmission_rpc_enable"] && isHash($transfer)) { require_once 'inc/functions/functions.rpc.transmission.php'; $theTorrent = getTransmissionTransfer($transfer, array('hashString', 'id', 'name')); if (is_array($theTorrent)) { $transferLabel = strlen($theTorrent[name]) >= 39 ? substr($theTorrent[name], 0, 35) . "..." : $theTorrent[name]; $tmpl->setvar('transfer', $theTorrent[hashString]); $tmpl->setvar('transferLabel', $transferLabel); $tmpl->setvar('transfer_exists', 0); return; // We really don't need this. Only the hash is a unique way of finding transfers. So all transfer operations should use the hash. /* //tf compatible... erk $transfer = getTransferFromHash($transfer); if (empty($transfer)) $transfer = $theTorrent[name]; */ } } // validate transfer if (tfb_isValidTransfer($transfer) !== true) { AuditAction($cfg["constants"]["error"], "INVALID TRANSFER: " . $transfer); @error("Invalid Transfer", "", "", array($transfer)); } // permission if (!$cfg['isAdmin'] && !IsOwner($cfg["user"], getOwner($transfer))) { AuditAction($cfg["constants"]["error"], "ACCESS DENIED: " . $transfer); @error("Access Denied", "", "", array($transfer)); } // get label $transferLabel = preg_replace("#\\.torrent\$#", "", $transfer); $transferLabel = strlen($transferLabel) >= 39 ? substr($transferLabel, 0, 35) . "..." : $transferLabel; // set transfer vars $tmpl->setvar('transfer', $transfer); $tmpl->setvar('transferLabel', $transferLabel); $tmpl->setvar('transfer_exists', transferExists($transfer) ? 1 : 0); }
/** * gets savepath of a transfer. * * @param $transfer name of the torrent * @return var with transfer-savepath or empty string */ function getTransferSavepath($transfer) { global $cfg, $db, $transfers; if (isset($transfers['settings'][$transfer]['savepath'])) { return $transfers['settings'][$transfer]['savepath']; } else { $savepath = $db->GetOne("SELECT savepath FROM tf_transfers WHERE transfer = " . $db->qstr($transfer)); if (empty($savepath)) { $savepath = $cfg["enable_home_dirs"] != 0 ? $cfg["path"] . getOwner($transfer) . '/' : $cfg["path"] . $cfg["path_incoming"] . '/'; } $transfers['settings'][$transfer]['savepath'] = $savepath; return $savepath; } }
/** * bulk * * @param $op */ function dispatcher_bulk($op) { global $cfg; // is enabled ? if ($cfg["enable_bulkops"] != 1) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use " . $op); @error("bulkops are disabled", "", ""); } // messages $dispatcherMessages = array(); // op-switch switch ($op) { case "stop": $transferList = getTransferArray(); foreach ($transferList as $transfer) { if (isTransferRunning($transfer)) { if ($cfg['isAdmin'] || IsOwner($cfg["user"], getOwner($transfer))) { $ch = ClientHandler::getInstance(getTransferClient($transfer)); $ch->stop($transfer); if (count($ch->messages) > 0) { $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages); } } } } break; case "resume": $transferList = getTransferArray(); $sf = new StatFile(""); foreach ($transferList as $transfer) { $sf->init($transfer); if (trim($sf->running) == 0 && !isTransferRunning($transfer)) { if ($cfg['isAdmin'] || IsOwner($cfg["user"], getOwner($transfer))) { $ch = ClientHandler::getInstance(getTransferClient($transfer)); $ch->start($transfer, false, false); if (count($ch->messages) > 0) { $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages); } } } } break; case "start": $transferList = getTransferArray(); foreach ($transferList as $transfer) { if (!isTransferRunning($transfer)) { if ($cfg['isAdmin'] || IsOwner($cfg["user"], getOwner($transfer))) { $ch = ClientHandler::getInstance(getTransferClient($transfer)); $ch->start($transfer, false, false); if (count($ch->messages) > 0) { $dispatcherMessages = array_merge($dispatcherMessages, $ch->messages); } } } } break; } // error if messages if (count($dispatcherMessages) > 0) { @error("There were Problems", "", "", $dispatcherMessages); } }
/** * starts a transfer * * @param $transfer name of the transfer * @param $interactive (boolean) : is this a interactive startup with dialog ? * @param $enqueue (boolean) : enqueue ? */ function start($transfer, $interactive = false, $enqueue = false) { global $cfg, $db; // set vars $this->_setVarsForTransfer($transfer); addGrowlMessage($this->client . "-start", $transfer); if (!Transmission::isRunning()) { $msg = "Transmission RPC not reacheable, cannot start transfer " . $transfer; $this->logMessage($this->client . "-start : " . $msg . "\n", true); AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); addGrowlMessage($this->client . "-start", $msg); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error: RPC down'; $sf->write(); // return return false; } // init properties $this->_init($interactive, $enqueue, true, false); /* if (!is_dir($cfg["path"].'.config/transmissionrpc/torrents')) { if (!is_dir($cfg["path"].'.config')) mkdir($cfg["path"].'.config',0775); if (!is_dir($cfg["path"].'.config/transmissionrpc')) mkdir($cfg["path"].'.config/transmissionrpc',0775); mkdir($cfg["path"].'.config/transmissionrpc/torrents',0775); } */ if (!is_dir($cfg['path'] . $cfg['user'])) { mkdir($cfg['path'] . $cfg['user'], 0777); } $this->command = ""; if (getOwner($transfer) != $cfg['user']) { //directory must be changed for different users ? changeOwner($transfer, $cfg['user']); $this->owner = $cfg['user']; // change savepath $this->savepath = $cfg["enable_home_dirs"] != 0 ? $cfg['path'] . $this->owner . "/" : $cfg['path'] . $cfg["path_incoming"] . "/"; $this->command = "re-downloading to " . $this->savepath; } else { $this->command = "downloading to " . $this->savepath; } // no client needed $this->state = CLIENTHANDLER_STATE_READY; // ClientHandler _start() $this->_start(); $hash = getTransferHash($transfer); if (empty($hash) || !isTransmissionTransfer($hash)) { $hash = addTransmissionTransfer($cfg['uid'], $cfg['transfer_file_path'] . $transfer, $cfg['path'] . $cfg['user']); if (is_array($hash) && $hash["result"] == "duplicate torrent") { $this->command = 'torrent-add skipped, already exists ' . $transfer; //log purpose $hash = ""; $sql = "SELECT hash FROM tf_transfers WHERE transfer = " . $db->qstr($transfer); $result = $db->Execute($sql); $row = $result->FetchRow(); if (!empty($row)) { $hash = $row['hash']; } } else { $this->command .= "\n" . 'torrent-add ' . $transfer . ' ' . $hash; //log purpose } } else { $this->command .= "\n" . 'torrent-start ' . $transfer . ' ' . $hash; //log purpose } if (!empty($hash)) { if ($this->sharekill > 100) { // bad sharekill, must be 2.5 for 250% $this->sharekill = round((double) $this->sharekill / 100.0, 2); } $params = array('downloadLimit' => intval($this->drate), 'downloadLimited' => intval($this->drate > 0), 'uploadLimit' => intval($this->rate), 'uploadLimited' => intval($this->rate > 0), 'seedRatioLimit' => (double) $this->sharekill, 'seedRatioMode' => intval($this->sharekill > 0.1)); $res = (int) startTransmissionTransfer($hash, $enqueue, $params); } if (!$res) { $this->command .= "\n" . $rpc->LastError; } $this->updateStatFiles($transfer); // log (for the torrent stats window) $this->logMessage($this->client . "-start : hash={$hash}\ndownload rate=" . $this->drate . ", res={$res}\n", true); }
/** * 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; }
/** * Created by IntelliJ IDEA. * User: mlui * Date: 2/12/2016 * Time: 4:56 PM * * * @param $context * @param int $limit * @param int $offset * @param $username * @return array * @throws InvalidParameterException */ function group_get_list($context, $limit = 20, $offset = 0, $username, $from_guid) { if (!$username) { $user = elgg_get_logged_in_user_entity(); throw new InvalidParameterException('registration:usernamenotvalid'); } else { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } } $loginUser = elgg_get_logged_in_user_entity(); if ($context == "all") { $params = array('type' => 'group', 'full_view' => false, 'no_results' => elgg_echo('groups:none'), 'distinct' => false, 'limit' => $limit, 'offset' => $offset); $groups = elgg_get_entities($params); } else { if ($context == 'mine') { $params = array('type' => 'group', 'container_guid' => $loginUser->guid, 'full_view' => false, 'no_results' => elgg_echo('groups:none'), 'distinct' => false, 'limit' => $limit, 'offset' => $offset); $groups = elgg_get_entities($params); } else { if ($context == 'member') { $dbprefix = elgg_get_config('dbprefix'); $groups = elgg_get_entities_from_relationship(array('type' => 'group', 'relationship' => 'member', 'relationship_guid' => $loginUser->guid, 'inverse_relationship' => false, 'full_view' => false, 'joins' => array("JOIN {$dbprefix}groups_entity ge ON e.guid = ge.guid"), 'order_by' => 'ge.name ASC', 'distinct' => false, 'limit' => $limit, 'offset' => $offset, 'no_results' => elgg_echo('groups:none'))); } else { $params = array('type' => 'group', 'full_view' => false, 'no_results' => elgg_echo('groups:none'), 'distinct' => false, 'limit' => $limit, 'offset' => $offset); $groups = elgg_get_entities($params); } } } $site_url = get_config('wwwroot'); if ($groups) { $return = array(); foreach ($groups as $single) { $group['guid'] = $single->guid; if ($single->name != null) { $group['title'] = $single->name; } else { $group['title'] = ''; } $group['time_create'] = time_ago($single->time_created); if ($single->description != null) { if (strlen($single->description) > 300) { $entityString = substr(strip_tags($single->description), 0, 300); $group['description'] = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $entityString) . '...'; } else { $group['description'] = strip_tags($single->description); } } else { $group['description'] = ''; } $group['access_id'] = $single->access_id; $group['members'] = sizeof($single->getMembers()); $group['is_member'] = $single->isMember($user); $group['permission_public'] = $single->isPublicMembership(); $group['content_access_mode'] = $single->getContentAccessMode(); $icon = getProfileIcon($single, 'medium'); //$single->getIconURL('medium'); if (strpos($icon, 'graphics/defaultmedium.gif') !== FALSE) { $group['icon'] = $icon; } else { $group['icon'] = $site_url . 'services/api/rest/json/?method=group.get_icon&guid=' . $single->guid; } if ($single->getTags() == null) { $group['tags'] = ''; } else { $group['tags'] = implode(",", $single->getTags()); //$single->getTags(); } $group['owner'] = getOwner($single->owner_guid); $return[] = $group; } } else { $msg = elgg_echo('groups:none'); throw new InvalidParameterException($msg); } return $return; }
/** * 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; }
/** * updateStatFile * @param $torrent name of the torrent * @param $alias_file name of the torrent */ function updateStatFile($torrent, $alias_file) { include_once "AliasFile.php"; $the_user = getOwner($torrent); $btclient = getTorrentClient($torrent); $modded = 0; // create AliasFile object $af = AliasFile::getAliasFileInstance($this->cfg["torrent_file_path"] . $alias_file, $the_user, $this->cfg, $btclient); if ($af->percent_done > 0 && $af->percent_done < 100) { // has downloaded something at some point, mark it is incomplete $af->running = "0"; $af->time_left = "Torrent Stopped"; $modded++; } if ($modded == 0) { if ($af->percent_done == 0 || $af->percent_done == "") { // We are going to write a '2' on the front of the stat file so that it will be set back to New Status $af->running = "2"; $af->time_left = ""; $modded++; } } if ($modded == 0) { if ($af->percent_done == 100) { // Torrent was seeding and is now being stopped $af->running = "0"; $af->time_left = "Download Succeeded!"; $modded++; } } if ($modded == 0) { // hmmm this stat-file is quite strange... just rewrite it stopped. $af->running = "0"; $af->time_left = "Torrent Stopped"; } // Write out the new Stat File $af->WriteFile(); }
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; }
function getImages() { /** settings **/ $images_dir = '../images/'; $thumbs_dir = '../thumbs/'; $thumbs_width = 200; $images_per_row = 3; $array = Sort_Directory_Files_By_Last_Modified($images_dir); $info = $array[0]; /** generate photo gallery **/ $image_files = get_files($images_dir); if (count($image_files)) { foreach ($image_files as $index => $file) { $thumbnail_image = $thumbs_dir . $file; if (!file_exists($thumbnail_image)) { $extension = get_file_extension($thumbnail_image); if ($extension) { make_thumb($images_dir . $file, $thumbnail_image, $thumbs_width); } } } } $result = count($info); foreach ($info as $key => $detail) { $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $detail['file']); $out = strlen($withoutExt) > 20 ? substr($withoutExt, 0, 20) . "..." : $withoutExt; echo '<a href="gestimage.php?image=../images/', $detail['file'], '" name="imageClick" type="submit" class="photo-link smoothbox"><img src="', $thumbs_dir, $detail['file'], '" /> <div> <small><b style="font-size:18px ">', $out, '</b></small><br> <small><b style="font-size:18px "> - - - - - - - - - - - - - - - - </b></small><br> <small>', 'Propriétaire: ', getOwner($detail['file']), '</small><br> <small>', 'Date: ', $detail['date'], '</small><br> <small>', 'Commentaire: ', getNbCommentaire($detail['file']), '</small> </div> </a>'; if ($result % 3 == 0) { if ($key % $images_per_row == 0) { echo '<div class="clear"></div>'; } } elseif ($result % 3 == 1) { if ($key % $images_per_row == 1) { echo '<div class="clear"></div>'; } } elseif ($result % 3 == 2) { if ($key % $images_per_row == 2) { echo '<div class="clear"></div>'; } } } echo '<div class="clear"></div>'; }
/** * sets all fields depending on "transfer"-value * * @param $transfer */ function _setVarsForTransfer($transfer) { global $cfg; if (empty($transfer)) { AuditAction($cfg["constants"]["error"], "_setVarsForTransfer empty {$transfer}"); } else { $this->transfer = $transfer; $this->transferFilePath = $cfg["transfer_file_path"] . $transfer; $this->owner = getOwner($transfer); } }
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; }
/** * sets all fields depending on "transfer"-value * * @param $transfer */ function _setVarsForTransfer($transfer) { global $cfg; $this->transfer = $transfer; $this->transferFilePath = $cfg["transfer_file_path"] . $this->transfer; $this->owner = getOwner($transfer); }
} $clientHandler = ClientHandler::getClientHandlerInstance($cfg, $btclient); $clientHandler->startTorrentClient($torrent, 0); // just 2 sec.. sleep(2); } } } break; case "bulkStart": /* bulkStart */ $torrents = getTorrentListFromFS(); foreach ($torrents as $torrent) { $torrentRunningFlag = isTorrentRunning($torrent); if ($torrentRunningFlag == 0) { $owner = getOwner($torrent); if (isset($owner) && $owner == $cfg["user"]) { $btclient = getTorrentClient($torrent); if ($cfg["enable_file_priority"]) { include_once "setpriority.php"; // Process setPriority Request. setPriority($torrent); } $clientHandler = ClientHandler::getClientHandlerInstance($cfg, $btclient); $clientHandler->startTorrentClient($torrent, 0); // just 2 sec.. sleep(2); } } } break;
/** * starts a transfer * * @param $transfer name of the transfer * @param $interactive (boolean) : is this a interactive startup with dialog ? * @param $enqueue (boolean) : enqueue ? */ function start($transfer, $interactive = false, $enqueue = false) { global $cfg; // set vars $this->_setVarsForTransfer($transfer); // log if ($cfg['debuglevel'] > 0) { AuditAction($cfg["constants"]["debug"], $this->client . "-start {$transfer}"); } $this->logMessage($this->client . "-start : " . $transfer . "\n", true); $vuze = VuzeRPC::getInstance(); // do special-pre-start-checks if (!VuzeRPC::isRunning()) { $msg = "VuzeRPC not reacheable, cannot start transfer " . $transfer; AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error: VuzeRPC down'; $sf->write(); // return return false; } // init starting of client $this->_init($interactive, $enqueue, true, false); // only continue if init succeeded (skip start / error) if ($this->state != CLIENTHANDLER_STATE_READY) { if ($this->state == CLIENTHANDLER_STATE_ERROR) { $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")"; array_push($this->messages, $msg); $this->logMessage($msg . "\n", true); } // return return false; } if (getOwner($transfer) != $cfg['user']) { //directory must be changed for different users ? changeOwner($transfer, $cfg['user']); $this->owner = $cfg['user']; // change savepath $this->savepath = $cfg["enable_home_dirs"] != 0 ? $cfg['path'] . $this->owner . "/" : $cfg['path'] . $cfg["path_incoming"] . "/"; $this->command = "re-downloading to " . $this->savepath; } else { $this->command = "downloading to " . $this->savepath; } // build the command-string $content = $cfg['user'] . "\n"; $content .= $this->savepath . "\n"; $content .= $this->rate . "\n"; $content .= $this->drate . "\n"; $content .= $this->maxuploads . "\n"; $content .= $this->superseeder . "\n"; $content .= $this->runtime . "\n"; $content .= $this->sharekill_param . "\n"; $content .= $this->minport . "\n"; $content .= $this->maxport . "\n"; $content .= $this->maxcons . "\n"; $content .= $this->rerequest; // no client needed $this->state = CLIENTHANDLER_STATE_READY; // ClientHandler _start() $this->_start(); $hash = getTransferHash($transfer); $torrents = $vuze->torrent_get_hashids(); if (!array_key_exists(strtoupper($hash), $torrents)) { $req = $vuze->torrent_add_tf($transfer, $content); } else { //resume $id = $torrents[strtoupper($hash)]; $req = $vuze->torrent_start(array($id)); } $this->updateStatFiles($transfer); return is_object($req) && $req->result == "success"; }
if (!isset($cfg['user']) || isset($_REQUEST['cfg'])) { @ob_end_clean(); @header("location: ../../index.php"); exit; } /******************************************************************************/ // common functions require_once 'inc/functions/functions.common.php'; // transfer functions require_once 'inc/functions/functions.transfer.php'; // init template-instance tmplInitializeInstance($cfg["theme"], "page.transferStats.tmpl"); // init transfer transfer_init(); // stat $transferowner = getOwner($transfer); $sf = new StatFile($transfer, $transferowner); // 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
/** * @param $guid * @param $username * @return array * @throws InvalidParameterException */ function bookmark_get_post($guid, $username) { $return = array(); $bookmark = get_entity($guid); if (!elgg_instanceof($bookmark, 'object', 'bookmarks')) { $return['content'] = elgg_echo('bookmark:error:post_not_found'); return $return; } if (!$username) { $user = elgg_get_logged_in_user_entity(); throw new InvalidParameterException('registration:usernamenotvalid'); } else { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } } $loginUser = elgg_get_logged_in_user_entity(); $return['guid'] = $guid; $return['title'] = $bookmark->title; $return['description'] = $bookmark->description; $return['address'] = $bookmark->address; if ($bookmark->tags == null) { $return['tags'] = ''; } else { $return['tags'] = implode(",", $bookmark->tags); } $comments = elgg_get_entities(array('type' => 'object', 'subtype' => 'comment', 'container_guid' => $guid, 'limit' => 0)); $return['owner'] = getOwner($bookmark->owner_guid); $return['access_id'] = $bookmark->access_id; $return['time_created'] = time_ago($bookmark->time_created); $return['like_count'] = likes_count_number_of_likes($guid); $return['like'] = checkLike($guid, $loginUser->guid); $return['comment_count'] = sizeof($comments); return $return; }
<!-- Specific save path --> <?php if ($cfg["showdirtree"]) { ?> <table> <tr> <td aligh="right">Save Path:</td> <td colspan="3"><input type="text" name="savepath" size="45" value="<?php echo $cfg["savepath"]; ?> "></td> </tr> <tr> <td align="right">Or use this path:</td> <td colspan="3"><SELECT width="45" size="6" ONCHANGE="savepath.value= this.options[this.selectedIndex].value;"><?php $arDirTree = dirTree2($cfg["path"] . getOwner($torrent) . '/', $cfg["maxdepth"]); ?> </SELECT></td> </tr> </table> <?php } ?> <!-- Skip hashcheck --> <table> <tr> <td aligh="right">Dont check hashes :</td> <?php if ($torrentExists) { echo '<td colspan="3"><input type="checkbox" name="skiphashcheck"'; if ($cfg["skiphashcheck"] != 0) {
} else { header("location: index.php"); exit; } } // Did the user select the option to remove a torrent from the Queue? if (isset($_REQUEST["dQueue"])) { $alias_file = SecurityClean(getRequestVar('alias_file')); $QEntry = getRequestVar('QEntry'); // Is the Qinfo file still there? if (file_exists($cfg["torrent_file_path"] . "queue/" . $alias_file . ".Qinfo")) { // Yes, then delete it and update the stat file. include_once "AliasFile.php"; // We are going to write a '2' on the front of the stat file so that // it will be set back to New Status $the_user = getOwner($QEntry); // read the alias file // create AliasFile object $af = new AliasFile($cfg["torrent_file_path"] . $alias_file, $the_user); if ($af->percent_done > 0 && $af->percent_done < 100) { // has downloaded something at some point, mark it is incomplete $af->running = "0"; $af->time_left = "Torrent Stopped"; } if ($af->percent_done == 0 || $af->percent_done == "") { $af->running = "2"; $af->time_left = ""; } if ($af->percent_done == 100) { // Torrent was seeding and is now being stopped $af->running = "0";
/** * _repairApp */ function _repairApp() { global $cfg, $db; // output $this->_outputMessage("repairing app...\n"); // sanity-check for transfers-dir if (!is_dir($cfg["transfer_file_path"])) { $this->state = MAINTENANCEANDREPAIR_STATE_ERROR; $msg = "invalid dir-settings. no dir : " . $cfg["transfer_file_path"]; array_push($this->messages, $msg); $this->_outputError($msg . "\n"); return false; } // delete pid-files of clients if ($dirHandle = opendir($cfg["transfer_file_path"])) { while (false !== ($file = readdir($dirHandle))) { if (strlen($file) > 3 && substr($file, -4, 4) == ".pid") { @unlink($cfg["transfer_file_path"] . $file); } } closedir($dirHandle); } // rewrite stat-files $arList = getTransferArray(); foreach ($arList as $transfer) { $sf = new StatFile($transfer, getOwner($transfer)); // output $this->_outputMessage("rewrite stat-file for " . $transfer . " ...\n"); $sf->running = 0; $sf->percent_done = -100.0; $sf->time_left = 'repaired'; $sf->down_speed = 0; $sf->up_speed = 0; $sf->seeds = 0; $sf->peers = 0; $sf->write(); // output $this->_outputMessage("done.\n"); } // set flags in db $this->_outputMessage("reset running-flag in database...\n"); $db->Execute("UPDATE tf_transfers SET running = '0'"); // output $this->_outputMessage("done.\n"); /* done */ $this->_outputMessage("repair app done.\n"); }
/** * gets savepath of a transfer for a given profile. * * @param $transfer name of the torrent * @param $profile name of profile to be used. if not given, attempt * to grab it from request vars is made. * @return var with transfer-savepath or empty string */ function getTransferSavepath($transfer, $profile = NULL) { global $cfg, $db, $transfers; if (isset($transfers['settings'][$transfer]['savepath'])) { return $transfers['settings'][$transfer]['savepath']; } else { $savepath = $db->GetOne("SELECT savepath FROM tf_transfers WHERE transfer = " . $db->qstr($transfer)); if (empty($savepath)) { if ($cfg['transfer_profiles'] <= 0) { $savepath = $cfg["enable_home_dirs"] != 0 ? $cfg["path"] . getOwner($transfer) . '/' : $cfg["path"] . $cfg["path_incoming"] . '/'; } else { require_once 'inc/functions/functions.common.transfer.php'; $savepath = calcTransferSavepath($transfer, $profile); } } $transfers['settings'][$transfer]['savepath'] = $savepath; return $savepath; } }
/** * set transfer setting * * @param $transfer * @param $key * @param $val * @param $options * @return mixed */ function _tset($transfer, $key, $val, $options) { global $cfg; // check transfer if (!transferExists($transfer)) { $this->_outputError("transfer does not exist.\n"); return false; } // check params $settingsKeys = array('uprate' => 'NUMBER', 'downrate' => 'NUMBER', 'completion' => 'BOOL', 'sharekill' => 'NUMBER'); if (!array_key_exists($key, $settingsKeys)) { $this->_outputError("invalid settings-key: " . $key . "\n"); return false; } if (strlen($val) < 1) { $this->_outputError("value for " . $key . " invalid.\n"); return false; } switch ($settingsKeys[$key]) { case 'NUMBER': if (!preg_match('/^[0-9\\-]+$/D', $val)) { $this->_outputError("value for " . $key . " must be a number: " . $val . "\n"); return false; } break; case 'BOOL': $val = strtolower($val); if ($val != 'true' && $val != 'false') { $this->_outputError("value for " . $key . " must be true or false: " . $val . "\n"); return false; } break; } // set user $cfg["user"] = getOwner($transfer); // output $this->_outputMessage("Setting " . $key . " to " . $val . " for " . $transfer . " for user " . $cfg["user"] . "...\n"); // init ch-instance $ch = ClientHandler::getInstance(getTransferClient($transfer)); // load settings, default if settings could not be loaded (fresh transfer) if ($ch->settingsLoad($transfer) !== true) { $ch->settingsDefault(); } // autosend $send = strpos($options, 's') !== false && isTransferRunning($transfer); // set setting switch ($key) { case 'uprate': if ($ch->rate != $val) { $ch->setRateUpload($transfer, $val, $send); break; } else { $this->_outputMessage("no changes.\n"); return false; } case 'downrate': if ($ch->drate != $val) { $ch->setRateDownload($transfer, $val, $send); break; } else { $this->_outputMessage("no changes.\n"); return false; } case 'completion': if (strtolower($ch->runtime) != $val) { $ch->setRuntime($transfer, $val == 'true' ? 'True' : 'False', $send); break; } else { $this->_outputMessage("no changes.\n"); return false; } case 'sharekill': if ($ch->sharekill != $val) { $ch->setSharekill($transfer, $val, $send); break; } else { $this->_outputMessage("no changes.\n"); return false; } } // save $ch->settingsSave(); // output + return if ($send) { $this->_outputMessage("settings saved + changes sent to client.\n"); } else { $this->_outputMessage("settings saved.\n"); } return true; }
/** * _updateStatFile * * @param $transfer */ function _updateStatFile($transfer) { global $transfers; $modded = 0; // create sf object $sf = new StatFile($transfer, getOwner($transfer)); if ($sf->percent_done > 0 && $sf->percent_done < 100) { // has downloaded something at some point, mark it is incomplete $sf->running = "0"; $sf->time_left = "Transfer Stopped"; $modded++; } if ($modded == 0) { if ($sf->percent_done == 0 || $sf->percent_done == "") { // We are going to write a '2' on the front of the stat file so that it will be set back to New Status $sf->running = "2"; $sf->time_left = ""; $modded++; } } if ($modded == 0) { if ($sf->percent_done == 100) { // transfer was done and is now being stopped $sf->running = "0"; $sf->time_left = "Download Succeeded!"; $modded++; } } if ($modded == 0) { // hmmm this stat-file is quite strange... just rewrite it stopped. $sf->running = "0"; $sf->time_left = "Transfer Stopped"; } // Write out the new Stat File $sf->write(); // set transfers-cache cacheTransfersSet(); }
/** * gets savepath of a transfer for a given profile. * * @param $transfer name of the torrent * @param $profile name of profile to be used. if not given, attempt * to grab it from request vars is made. * @return var with transfer-savepath */ function calcTransferSavepath($transfer, $profile = NULL) { global $cfg, $transfers; require_once 'functions.common.trprofile.php'; // meh, my hack if ($profile == NULL) { $profile = tfb_getRequestVar("profile"); } $settings = GetProfileSettings($profile); $savepath = ""; if (isset($settings["savepath"])) { $savepath = $settings["savepath"]; } // no savepath set in profile or profile not set. // so: take default save path. if ($savepath == "") { $savepath = $cfg["enable_home_dirs"] != 0 ? $cfg["path"] . getOwner($transfer) . '/' : $cfg["path"] . $cfg["path_incoming"] . '/'; } else { if ($cfg["enable_home_dirs"] == 0) { $savepath .= $cfg["path_incoming"] . '/'; } } return $savepath; }
/** * stops a bittorrent-client * * @param $torrent name of the torrent * @param $aliasFile alias-file of the torrent * @param $kill kill-param * @param $return return-param */ function doStopTorrentClient($torrent, $aliasFile, $torrentPid = "", $return = "") { // set some vars $this->torrent = $torrent; $this->alias = $aliasFile; // set pidfile if ($this->pidFile == "") { // pid-file not set in subclass. use a default $this->pidFile = $this->cfg["torrent_file_path"] . $this->alias . ".pid"; } // We are going to write a '0' on the front of the stat file so that // the BT client will no to stop -- this will report stats when it dies $this->owner = getOwner($this->torrent); include_once "AliasFile.php"; // read the alias file + create AliasFile object $this->af = AliasFile::getAliasFileInstance($this->cfg["torrent_file_path"] . $this->alias, $this->owner, $this->cfg, $this->handlerName); if ($this->af->percent_done < 100) { // The torrent is being stopped but is not completed dowloading $this->af->percent_done = ($this->af->percent_done + 100) * -1; $this->af->running = "0"; $this->af->time_left = "Torrent Stopped"; } else { // Torrent was seeding and is now being stopped $this->af->percent_done = 100; $this->af->running = "0"; $this->af->time_left = "Download Succeeded!"; } include_once "RunningTorrent.php"; // see if the torrent process is hung. if (!is_file($this->pidFile)) { $runningTorrents = getRunningTorrents(); foreach ($runningTorrents as $key => $value) { $rt = RunningTorrent::getRunningTorrentInstance($value, $this->cfg, $this->handlerName); if ($rt->statFile == $this->alias) { AuditAction($this->cfg["constants"]["error"], "Posible Hung Process " . $rt->processId); // $callResult = exec("kill ".$rt->processId); } } } // Write out the new Stat File $this->af->WriteFile(); // flag the torrent as stopped (in db) // blame me for this dirty shit, i am lazy. of course this should be // hooked into the place where client really dies. stopTorrentSettings($this->torrent); // AuditAction($this->cfg["constants"]["kill_torrent"], $this->torrent); if (!empty($return)) { sleep(3); // set pid if (isset($torrentPid) && $torrentPid != "") { $this->pid = $torrentPid; } else { $this->pid = trim(shell_exec($this->cfg['bin_cat'] . " " . $this->pidFile)); } // kill it $this->callResult = exec("kill " . $this->pid); // try to remove the pid file @unlink($this->pidFile); } }
function repairTorrentflux() { global $cfg, $db; // delete pid-files of torrent-clients if ($dirHandle = opendir($cfg["torrent_file_path"])) { while (false !== ($file = readdir($dirHandle))) { if (substr($file, -1, 1) == "d") { @unlink($cfg["torrent_file_path"] . $file); } } closedir($dirHandle); } // rewrite stat-files include_once "AliasFile.php"; $torrents = getTorrentListFromFS(); foreach ($torrents as $torrent) { $alias = getAliasName($torrent); $owner = getOwner($torrent); $btclient = getTorrentClient($torrent); $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . $alias . ".stat", $owner, $cfg, $btclient); if (isset($af)) { $af->running = 0; $af->percent_done = -100.0; $af->time_left = 'Torrent Stopped'; $af->down_speed = 0; $af->up_speed = 0; $af->seeds = 0; $af->peers = 0; $af->errors = array(); $af->WriteFile(); } } // set flags in db $db->Execute("UPDATE tf_torrents SET running = '0'"); // delete leftovers of tfqmgr.pl (only do this if daemon is not running) $tfqmgrRunning = trim(shell_exec("ps aux 2> /dev/null | " . $cfg['bin_grep'] . " -v grep | " . $cfg['bin_grep'] . " -c tfqmgr.pl")); if ($tfqmgrRunning == "0") { if (file_exists($cfg["path"] . '.tfqmgr/tfqmgr.pid')) { @unlink($cfg["path"] . '.tfqmgr/tfqmgr.pid'); } if (file_exists($cfg["path"] . '.tfqmgr/COMMAND')) { @unlink($cfg["path"] . '.tfqmgr/COMMAND'); } if (file_exists($cfg["path"] . '.tfqmgr/TRANSPORT')) { @unlink($cfg["path"] . '.tfqmgr/TRANSPORT'); } } }
/** Added by MetaClass for porting to PHP: * In Java the method getOwner results in a property 'owner'. * In PHP it does not work that way, @see DoFixture::doAction * This method will make a property 'owner' available, however, * according to PHP's funcion property_exists it will not exist. It can * be accessed through @see DoFixture::get */ function __get($name) { if ($name == 'owner') { return getOwner(); } trigger_error("access to non-exitent member variable: '{$name}'", E_USER_NOTICE); return null; }