Exemplo n.º 1
0
     }
     if (strlen($result) > 0) {
         $htmlMain .= '<br>Deleted pid-leftovers : <pre>' . $result . '</pre><br>';
     } else {
         $htmlMain .= '<br>No pid-leftovers found.<br><br>';
     }
     break;
 case "12":
     // Maintenance-clean : transmission-cache-clean
     $htmlTitle = "Maintenance-transmission-cache-clean";
     $htmlMain .= '<br>';
     $result = "";
     $torrents = getTorrentListFromDB();
     $hashes = array();
     foreach ($torrents as $torrent) {
         array_push($hashes, getTorrentHash($torrent));
     }
     if ($dirHandle = opendir($cfg["path"] . ".transmission/cache/")) {
         while (false !== ($file = readdir($dirHandle))) {
             if ($file[0] == "r") {
                 $thash = substr($file, -40);
                 if (!in_array($thash, $hashes)) {
                     // torrent not in db. delete cache-file.
                     $result .= $file . "\n";
                     @unlink($cfg["path"] . ".transmission/cache/resume." . $thash);
                 }
             }
         }
         closedir($dirHandle);
     }
     if (strlen($result) > 0) {
/**
 * 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;
}
 /**
  * gets current transfer-vals of a torrent. optimized index-page-version
  *
  * @param $torrent
  * @param $afu alias-file-uptotal of the torrent
  * @param $afd alias-file-downtotal of the torrent
  * @return array with downtotal and uptotal
  */
 function getTorrentTransferCurrentOP($torrent, $afu, $afd)
 {
     global $db;
     $retVal = array();
     // transfer from stat-file
     $retVal["uptotal"] = $afu;
     $retVal["downtotal"] = $afd;
     // 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"];
     }
     return $retVal;
 }