/** * resets totals of a torrent * * @param $torrent name of the torrent * @param $delete boolean if to delete torrent-file * @return boolean of success */ function resetTorrentTotals($torrent, $delete = false) { global $cfg, $db; if (!isset($torrent) || !preg_match('/^[a-zA-Z0-9._]+$/', $torrent)) { return false; } // vars $torrentId = getTorrentHash($torrent); $alias = getAliasName($torrent); $owner = getOwner($torrent); // delete torrent if ($delete == true) { deleteTorrent($torrent, $alias); // delete the stat file. shouldnt be there.. but... @unlink($cfg["torrent_file_path"] . $alias . ".stat"); } else { // reset in stat-file include_once "AliasFile.php"; $af = AliasFile::getAliasFileInstance($cfg["torrent_file_path"] . $alias . ".stat", $owner, $cfg); if (isset($af)) { $af->uptotal = 0; $af->downtotal = 0; $af->WriteFile(); } } // reset in db $sql = "DELETE FROM tf_torrent_totals WHERE tid = '" . $torrentId . "'"; $db->Execute($sql); showError($db, $sql); return true; }
function cliDeleteTorrent($torrent = "") { global $cfg; if (isset($torrent) && $torrent != "") { echo "Deleting " . $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(8); } deleteTorrent($torrent, $alias); echo "done\n"; } else { printUsage(); } exit; }
default: if ($torrentRunningFlag != 0) { // stop torrent first $clientHandler = ClientHandler::getClientHandlerInstance($cfg, $btclient); $clientHandler->stopTorrentClient(urldecode($element), $alias); // give the torrent some time to die sleep(8); } // if it was running... hope the thing is down... rock on switch ($action) { case "torrentWipe": /* torrentWipe */ deleteTorrentData(urldecode($element)); resetTorrentTotals(urldecode($element), true); break; case "torrentData": /* torrentData */ deleteTorrentData(urldecode($element)); case "torrent": /* torrent */ deleteTorrent(urldecode($element), $alias); } } } } /* redirect */ if (isset($_SERVER["HTTP_REFERER"])) { header("location: " . $_SERVER["HTTP_REFERER"]); } else { header("location: index.php"); }
// ============================================================================= // Do they want us to get a torrent via a URL? $url_upload = getRequestVar('url_upload'); if (!$url_upload == '') { indexProcessDownload($url_upload); } // ============================================================================= // Handle the file upload if there is one if (!empty($_FILES['upload_file']['name'])) { indexProcessUpload(); } // ============================================================================= // if a file was set to be deleted then delete it $delfile = getRequestVar('delfile'); if (!$delfile == '') { deleteTorrent($delfile, getRequestVar('alias_file')); header("location: index.php"); exit; } // ============================================================================= // Did the user select the option to kill a running torrent? $killTorrent = getRequestVar('kill_torrent'); if (!$killTorrent == '') { $return = getRequestVar('return'); include_once "ClientHandler.php"; $clientHandler = ClientHandler::getClientHandlerInstance($cfg, getTorrentClient($killTorrent)); $clientHandler->stopTorrentClient($killTorrent, getRequestVar('alias_file'), getRequestVar('kill'), $return); if (!empty($return)) { header("location: " . $return . ".php?op=queueSettings"); } else { header("location: index.php");