// We are done! how long did we take?
    $time_end = microtime(true);
    $diff = duration($time_end - $time_start);
    // make path URL friendly to support non-standard characters
    $downpath = urlencode($tfile);
    // Depending if we were successful, display the required information
    if ($success) {
        $onLoad = "completed( '" . $downpath . "', " . $alert . ", '" . $diff . "' );";
    } else {
        $onLoad = "failed( '" . $downpath . "', " . $alert . " );";
    }
}
// This is the torrent download prompt
if (!empty($_GET["download"])) {
    $tfile = $_GET["download"];
    if (isValidTransfer($tfile) === true) {
        // Does the file exist?
        if (file_exists($tpath . $tfile)) {
            // filenames in IE containing dots will screw up the filename
            if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
                $headerName = preg_replace('/\\./', '%2e', $tfile, substr_count($tfile, '.') - 1);
            } else {
                $headerName = $tfile;
            }
            // Prompt the user to download the file.
            if (substr(strtolower($tfile), -8) == ".torrent") {
                header("Content-type: application/x-bittorrent\n");
            } else {
                header("Content-type: application/octet-stream\n");
            }
            header("Content-disposition: attachment; filename=\"" . $headerName . "\"\n");
示例#2
0
                     setPriority($torrent);
                 }
                 $clientHandler = ClientHandler::getClientHandlerInstance($cfg, $btclient);
                 $clientHandler->startTorrentClient($torrent, 0);
                 // just 2 sec..
                 sleep(2);
             }
         }
     }
     break;
     /* ---------------------------------------------------- selected torrents */
 /* ---------------------------------------------------- selected torrents */
 default:
     foreach ($_POST['torrent'] as $key => $element) {
         // is valid transfer ?
         if (isValidTransfer(urldecode($element)) !== true) {
             AuditAction($cfg["constants"]["error"], "Invalid Transfer for " . $action . " : " . $cfg["user"] . " tried to " . $action . " " . $element);
             showErrorPage("Invalid Transfer for " . htmlentities($action, ENT_QUOTES) . " : <br>" . htmlentities($element, ENT_QUOTES));
         }
         // process
         $alias = getAliasName($element) . ".stat";
         $settingsAry = loadTorrentSettings(urldecode($element));
         $torrentRunningFlag = isTorrentRunning(urldecode($element));
         $btclient = $settingsAry["btclient"];
         switch ($action) {
             case "torrentStart":
                 /* torrentStart */
                 if ($torrentRunningFlag == 0) {
                     if ($cfg["enable_file_priority"]) {
                         include_once "setpriority.php";
                         // Process setPriority Request.
/**
 * deletes a torrent
 *
 * @param $torrent name of the torrent
 * @param $alias_file alias-file of the torrent
 * @return boolean of success
 */
function deleteTorrent($torrent, $alias_file)
{
    global $cfg;
    $delfile = $torrent;
    // check if valid transfer
    if (isValidTransfer($delfile) !== true) {
        AuditAction($cfg["constants"]["error"], "Invalid File for Delete : " . $cfg["user"] . " tried to delete " . $delfile);
        global $argv;
        if (isset($argv)) {
            die("Invalid File for Delete : " . $delfile);
        } else {
            showErrorPage("Invalid File for Delete : <br>" . htmlentities($delfile, ENT_QUOTES));
        }
    }
    //$alias_file = getRequestVar('alias_file');
    $torrentowner = getOwner($delfile);
    if ($cfg["user"] == $torrentowner || IsAdmin()) {
        include_once "AliasFile.php";
        // we have more meta-files than .torrent. handle this.
        if (substr(strtolower($torrent), -8) == ".torrent") {
            // this is a torrent-client
            $btclient = getTorrentClient($delfile);
            $af = AliasFile::getAliasFileInstance($cfg['torrent_file_path'] . $alias_file, $torrentowner, $cfg, $btclient);
            // update totals for this torrent
            updateTorrentTotals($delfile);
            // remove torrent-settings from db
            deleteTorrentSettings($delfile);
            // client-proprietary leftovers
            include_once "ClientHandler.php";
            $clientHandler = ClientHandler::getClientHandlerInstance($cfg, $btclient);
            $clientHandler->deleteTorrentCache($torrent);
        } else {
            if (substr(strtolower($torrent), -4) == ".url") {
                // this is wget. use tornado statfile
                $alias_file = str_replace(".url", "", $alias_file);
                $af = AliasFile::getAliasFileInstance($cfg['torrent_file_path'] . $alias_file, $cfg['user'], $cfg, 'tornado');
            } else {
                // this is "something else". use tornado statfile as default
                $af = AliasFile::getAliasFileInstance($cfg['torrent_file_path'] . $alias_file, $cfg['user'], $cfg, 'tornado');
            }
        }
        if ($cfg['enable_xfer'] != 0) {
            //XFER: before torrent deletion save upload/download xfer data to SQL
            $torrentTotals = getTorrentTotalsCurrent($delfile);
            saveXfer($torrentowner, $torrentTotals["downtotal"] + 0, $torrentTotals["uptotal"] + 0);
        }
        // torrent+stat
        @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);
        return true;
    } else {
        AuditAction($cfg["constants"]["error"], $cfg["user"] . " attempted to delete " . $delfile);
        return false;
    }
}