/**
 * gets savepath of a transfer for a given profile.
 *
 * @param $transfer name of the torrent
 * @param $profile name of profile to be used. if not given, attempt
 *	to grab it from request vars is made.
 * @return var with transfer-savepath or empty string
 */
function getTransferSavepath($transfer, $profile = NULL)
{
    global $cfg, $db, $transfers;
    if (isset($transfers['settings'][$transfer]['savepath'])) {
        return $transfers['settings'][$transfer]['savepath'];
    } else {
        $savepath = $db->GetOne("SELECT savepath FROM tf_transfers WHERE transfer = " . $db->qstr($transfer));
        if (empty($savepath)) {
            if ($cfg['transfer_profiles'] <= 0) {
                $savepath = $cfg["enable_home_dirs"] != 0 ? $cfg["path"] . getOwner($transfer) . '/' : $cfg["path"] . $cfg["path_incoming"] . '/';
            } else {
                require_once 'inc/functions/functions.common.transfer.php';
                $savepath = calcTransferSavepath($transfer, $profile);
            }
        }
        $transfers['settings'][$transfer]['savepath'] = $savepath;
        return $savepath;
    }
}
Пример #2
0
 /**
  * Start Transfer
  *
  * @param $transfer
  * @param $options
  * @param array $extra
  * @return mixed
  */
 function _transferStart($transfer, $options = '', $extra = array())
 {
     global $cfg;
     // check transfer
     if (!transferExists($transfer)) {
         $this->_outputError("transfer does not exist.\n");
         return false;
     }
     // check running
     if (isTransferRunning($transfer)) {
         $this->_outputError("transfer already running.\n");
         return false;
     }
     // parse options
     $optionsSet = $this->_parseOptions(array('p' => 1), $options, $extra);
     if ($optionsSet === false) {
         return false;
     }
     $profile = isset($optionsSet['p']) ? $optionsSet['p'][0] : null;
     // set user
     $cfg["user"] = getOwner($transfer);
     // output
     $this->_outputMessage("Starting " . $transfer . " for user " . $cfg["user"] . (!empty($profile) ? " using profile " . $profile : '') . " ...\n");
     $ch = ClientHandler::getInstance(getTransferClient($transfer));
     // load and apply profile, if specified (just ignore
     // it if profiles are disabled, no error)
     if ($cfg['transfer_profiles'] >= 1 && !empty($profile)) {
         $ch->settingsDefault($transfer);
         $settings = GetProfileSettings($profile);
         if (empty($settings) || $settings === false) {
             $this->_outputError("profilename " . $profile . " is no valid profile.\n");
             return false;
         }
         $ch->rate = $settings['rate'];
         $ch->drate = $settings['drate'];
         $ch->maxuploads = $settings['maxuploads'];
         $ch->superseeder = $settings['superseeder'];
         $ch->runtime = $settings['runtime'];
         $ch->sharekill = $settings['sharekill'];
         $ch->minport = $settings['minport'];
         $ch->maxport = $settings['maxport'];
         $ch->maxcons = $settings['maxcons'];
         $ch->rerequest = $settings['rerequest'];
         $ch->savepath = calcTransferSavepath($transfer, $profile);
         // TODO CONFIRM ALL GOES WELL AFTER THIS
         $ch->settingsSave();
     }
     // force start, don't queue
     $ch->start($transfer, false, false);
     if ($ch->state == CLIENTHANDLER_STATE_OK) {
         /* hooray */
         $this->_outputMessage("done.\n");
         return true;
     } else {
         $this->_outputError("failed: " . implode("\n", $ch->messages) . "\n");
         return false;
     }
 }