/**
 * deletes data of a transfer
 *
 * @param $transfer name of the transfer
 * @return array
 */
function deleteTransferData($transfer)
{
    global $cfg, $transfers;
    $msgs = array();
    $isTransmissionTorrent = false;
    if ($cfg["transmission_rpc_enable"] == 2 && isHash($transfer)) {
        require_once 'inc/classes/Transmission.class.php';
        $trans = new Transmission();
        require_once 'inc/functions/functions.rpc.transmission.php';
        $theTorrent = getTransmissionTransfer($transfer, array('hashString', 'id', 'name'));
        $isTransmissionTorrent = is_array($theTorrent);
    }
    if ($isTransmissionTorrent) {
        $response = $trans->remove($theTorrent['id'], true);
        if ($response[result] != "success") {
            @error("Delete of torrent failed", "", "", $response[result]);
        }
    } else {
        if ($cfg['isAdmin'] || IsOwner($cfg["user"], getOwner($transfer))) {
            // only torrent
            if (substr($transfer, -8) != ".torrent") {
                return $msgs;
            }
            // delete data
            $datapath = getTransferDatapath($transfer);
            if ($datapath != "" && $datapath != ".") {
                $targetPath = getTransferSavepath($transfer) . $datapath;
                if (tfb_isValidPath($targetPath)) {
                    if (@is_dir($targetPath) || @is_file($targetPath)) {
                        avddelete($targetPath);
                        AuditAction($cfg["constants"]["fm_delete"], $targetPath);
                    }
                } else {
                    $msg = "ILLEGAL DELETE: " . $cfg["user"] . " attempted to delete data of " . $transfer;
                    AuditAction($cfg["constants"]["error"], $msg);
                    array_push($msgs, $msg);
                }
            }
        } else {
            $msg = "ILLEGAL DELETE: " . $cfg["user"] . " attempted to delete data of " . $transfer;
            AuditAction($cfg["constants"]["error"], $msg);
            array_push($msgs, $msg);
        }
    }
    return $msgs;
}
Example #2
0
 public function removeTorrent($hashString)
 {
     $torrentToRemove = $this->torrentDB->get($hashString);
     if (empty($torrentToRemove)) {
         return array("status" => false, "message" => "This torrent could not be found!");
     } else {
         $userKey = array_search($this->user->username, $torrentToRemove->users);
         if (!is_null($userKey)) {
             $oldSpaceUsed = round($torrentToRemove->totalSize / count($torrentToRemove->users));
             $this->user->spaceUsed -= $oldSpaceUsed;
             unset($torrentToRemove->users[$userKey]);
             $newUserCount = count($torrentToRemove->users);
             if ($newUserCount == 0) {
                 $newSpaceUsed = 0;
             } else {
                 $newSpaceUsed = round($torrentToRemove->totalSize / $newUserCount);
             }
             $this->redistributeTorrentUsersSpace($torrentToRemove, $oldSpaceUsed - $newSpaceUsed);
             $torrentToRemove->userSpace = $newSpaceUsed;
         } else {
             return array("status" => false, "message" => "You are not an owner of this torrent!");
         }
         $this->user->removeTorrent($torrentToRemove);
         $torrentToRemove->updateUsers();
         if (count($torrentToRemove->users) == 0) {
             $transmission = new Transmission(TRANSMISSION_URL, TRANSMISSION_USER, TRANSMISSION_PASS);
             $this->torrentDB->remove($torrentToRemove->hashString);
             $this->fileDB->removeTorrentFiles($torrentToRemove);
             $transmission->remove($torrentToRemove->hashString);
         }
         return array("status" => true, "torrentHash" => $torrentToRemove->hashString);
     }
 }