/** * 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->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; } }
/** * 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 */ function calcTransferSavepath($transfer, $profile = NULL) { global $cfg, $transfers; require_once 'functions.common.trprofile.php'; // meh, my hack if ($profile == NULL) { $profile = tfb_getRequestVar("profile"); } $settings = GetProfileSettings($profile); $savepath = ""; if (isset($settings["savepath"])) { $savepath = $settings["savepath"]; } // no savepath set in profile or profile not set. // so: take default save path. if ($savepath == "") { $savepath = $cfg["enable_home_dirs"] != 0 ? $cfg["path"] . getOwner($transfer) . '/' : $cfg["path"] . $cfg["path_incoming"] . '/'; } else { if ($cfg["enable_home_dirs"] == 0) { $savepath .= $cfg["path_incoming"] . '/'; } } return $savepath; }
/** * setVarsFromProfileSettings * * @param $profile */ function transfer_setVarsFromProfileSettings($profile) { global $cfg, $tmpl, $transfer, $transferLabel, $ch; // set generic vars for transfer transfer_setGenericVarsFromCH(); //load custom settings $settings = GetProfileSettings($profile); // set vars for transfer $tmpl->setvar('max_upload_rate', $settings["rate"]); $tmpl->setvar('max_download_rate', $settings["drate"]); $tmpl->setvar('max_uploads', $settings["maxuploads"]); $tmpl->setvar('superseeder', $settings['superseeder']); $tmpl->setvar('die_when_done', $settings["runtime"]); $tmpl->setvar('sharekill', $settings["sharekill"]); $tmpl->setvar('minport', $settings["minport"]); $tmpl->setvar('maxport', $settings["maxport"]); $tmpl->setvar('maxcons', $settings["maxcons"]); $tmpl->setvar('rerequest', $settings["rerequest"]); $tmpl->setvar('savepath', getTransferSavepath($transfer, $profile)); }