コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
/**
 * _dispatcher_processUpload
 *
 * @param $name
 * @param $tmp_name
 * @param $size
 * @param $actionId
 * @param &$uploadMessages
 * @param &$tStack
 * @return bool
 */
function _dispatcher_processUpload($name, $tmp_name, $size, $actionId, &$uploadMessages, &$tStack)
{
    global $cfg;
    $filename = tfb_cleanFileName(stripslashes($name));
    if ($filename === false) {
        // invalid file
        array_push($uploadMessages, "The type of file " . stripslashes($name) . " is not allowed.");
        array_push($uploadMessages, "\nvalid file-extensions: ");
        array_push($uploadMessages, $cfg["file_types_label"]);
        return false;
    } else {
        // file is valid
        if (substr($filename, -5) == ".wget") {
            // is enabled ?
            if ($cfg["enable_wget"] == 0) {
                AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload wget-file " . $filename);
                array_push($uploadMessages, "wget is disabled  : " . $filename);
                return false;
            } else {
                if ($cfg["enable_wget"] == 1) {
                    if (!$cfg['isAdmin']) {
                        AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload wget-file " . $filename);
                        array_push($uploadMessages, "wget is disabled for users : " . $filename);
                        return false;
                    }
                }
            }
        } else {
            if (substr($filename, -4) == ".nzb") {
                // is enabled ?
                if ($cfg["enable_nzbperl"] == 0) {
                    AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload nzb-file " . $filename);
                    array_push($uploadMessages, "nzbperl is disabled  : " . $filename);
                    return false;
                } else {
                    if ($cfg["enable_nzbperl"] == 1) {
                        if (!$cfg['isAdmin']) {
                            AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to upload nzb-file " . $filename);
                            array_push($uploadMessages, "nzbperl is disabled for users : " . $filename);
                            return false;
                        }
                    }
                }
            }
        }
        if ($size <= $cfg["upload_limit"] && $size > 0) {
            //FILE IS BEING UPLOADED
            if (@is_file($cfg["transfer_file_path"] . $filename)) {
                // Error
                array_push($uploadMessages, "the file " . $filename . " already exists on the server.");
                return false;
            } else {
                if (@move_uploaded_file($tmp_name, $cfg["transfer_file_path"] . $filename)) {
                    @chmod($cfg["transfer_file_path"] . $filename, 0644);
                    AuditAction($cfg["constants"]["file_upload"], $filename);
                    if ($cfg["transmission_rpc_enable"] == 2 && $cfg['btclient'] == 'transmissionrpc') {
                        // only if default client is transmissionrpc with deadeyes method (may be deleted later)
                        require_once 'inc/functions/functions.rpc.transmission.php';
                        $hash = addTransmissionTransfer($cfg['uid'], $cfg['transfer_file_path'] . $filename, $cfg['path'] . $cfg['user']);
                        @unlink($cfg['transfer_file_path'] . $filename);
                        if ($actionId > 1) {
                            startTransmissionTransfer($hash);
                            array_push($tStack, $filename);
                        }
                        return true;
                    }
                    // inject
                    injectTransfer($filename);
                    // instant action ?
                    if ($actionId > 1) {
                        array_push($tStack, $filename);
                    }
                    // return
                    return true;
                } else {
                    array_push($uploadMessages, "File not uploaded, file could not be found or could not be moved: " . $cfg["transfer_file_path"] . $filename);
                    return false;
                }
            }
        } else {
            array_push($uploadMessages, "File not uploaded, file size limit is " . $cfg["upload_limit"] . ". file has " . $size);
            return false;
        }
    }
}