public static function sendTorrent($fname, $isStart, $directory = null) { $hash = false; $torrent = is_object($fname) ? $fname : new \model\simple\Torrent($fname); if (!$torrent->errors()) { $raw_value = base64_encode($torrent->__toString()); $filename = is_object($fname) ? $torrent->getFileName() : $fname; if (strlen($raw_value) < self::RTORRENT_PACKET_LIMIT || is_null($filename)) { $cmd = new rXMLRPCCommand(\config\Conf::$userscgi, $isStart ? 'load.raw_start' : 'load.raw'); $cmd->addParameter(""); $cmd->addParameter($raw_value, "base64"); if (!is_null($filename) && !true) { @unlink($filename); } } else { $cmd = new rXMLRPCCommand(\config\Conf::$userscgi, $isStart ? 'load.start' : 'load.normal'); $cmd->addParameter(""); $cmd->addParameter($filename); } if (!is_null($filename) && rTorrentSettings::get(\config\Conf::$userscgi)->iVersion >= 0x805) { $cmd->addParameter(rTorrentSettings::getCmd(\config\Conf::$userscgi, "d.custom.set") . "=x-filename," . rawurlencode(basename($filename))); } $req = new rXMLRPCRequest(\config\Conf::$userscgi); $req->addCommand($cmd); if (!is_null($directory)) { $cmd->addParameter(rTorrentSettings::getCmd(\config\Conf::$userscgi, "d.directory.set=") . "\"" . $directory . "\""); } if ($req->run() && !$req->fault) { $hash = $req->val; } } return $hash; }
protected static function setState($hash, $state) { $req = new rXMLRPCRequest(array(new rXMLRPCCommand(getCmd("d.set_custom"), array($hash, "chk-state", $state . "")), new rXMLRPCCommand(getCmd("d.set_custom"), array($hash, "chk-time", time() . "")))); if ($state == self::STE_UPTODATE) { $req->addCommand(new rXMLRPCCommand(getCmd("d.set_custom"), array($hash, "chk-stime", time() . ""))); } return $req->success(); }
function makeSimpleCall($cmds, $hash) { $req = new rXMLRPCRequest(); foreach ($hash as $h) { foreach ($cmds as $cmd) { $req->addCommand(new rXMLRPCCommand($cmd, $h)); } } return $req->success() ? $req->val : false; }
public function setHandlers() { $theSettings = rTorrentSettings::get(); $pathToXmpp = dirname(__FILE__); $req = new rXMLRPCRequest(); if ($this->message !== '' && isset($this->jabberServer) && isset($this->jabberLogin) && isset($this->jabberPasswd) && isset($this->jabberFor)) { $cmd = $theSettings->getOnFinishedCommand(array('xmpp' . getUser(), getCmd('execute.nothrow.bg') . '={' . getPHP() . ',' . $pathToXmpp . '/notify.php,"$' . getCmd('d.name') . '=","' . getUser() . '"}')); } else { $cmd = $theSettings->getOnFinishedCommand(array('xmpp' . getUser(), getCmd('cat='))); } $req->addCommand($cmd); return $req->success(); }
public function checkLabels($hashes) { $req = new rXMLRPCRequest(); foreach ($hashes as $hash) { $req->addCommand(new rXMLRPCCommand("d.get_custom1", $hash)); $req->addCommand(new rXMLRPCCommand("d.get_state", $hash)); $req->addCommand(new rXMLRPCCommand("d.views", $hash)); $req->addCommand(new rXMLRPCCommand("d.get_throttle_name", $hash)); } if ($req->getCommandsCount() && $req->success()) { $out = new rXMLRPCRequest(); foreach ($hashes as $ndx => $hash) { $label = rawurldecode($req->val[$ndx * 4]); $state = !empty($req->val[$ndx * 4 + 1]); $ratio = null; if (preg_match('`rat_(\\d+)`', $req->val[$ndx * 4 + 2], $matches)) { $ratio = 'rat_' . $matches[1]; } $throttle = $req->val[$ndx * 4 + 3]; $trackers = ''; $req1 = new rXMLRPCRequest(array(new rXMLRPCCommand("t.multicall", array($hash, "", getCmd("t.get_url="))))); if ($req1->success()) { $trackers = implode('#', $req1->val); } $rule = $this->getRule($label, $trackers); if ($rule) { if (!empty($rule->channel) && $rule->channel != $throttle) { if ($state) { $out->addCommand(new rXMLRPCCommand('d.stop', $hash)); } $out->addCommand(new rXMLRPCCommand('d.set_throttle_name', array($hash, $rule->channel))); if ($state) { $out->addCommand(new rXMLRPCCommand('d.start', $hash)); } } if (!empty($rule->ratio) && $rule->ratio != $ratio) { if (!is_null($ratio)) { $out->addCommand(new rXMLRPCCommand('view.set_not_visible', array($hash, $ratio))); $out->addCommand(new rXMLRPCCommand('d.views.remove', array($hash, $ratio))); } $out->addCommand(new rXMLRPCCommand('d.views.push_back_unique', array($hash, $rule->ratio))); $out->addCommand(new rXMLRPCCommand('view.set_visible', array($hash, $rule->ratio))); } } } if ($out->getCommandsCount()) { $out->run(); } } }
function rtExec($cmds, $hash, $dbg) { $req = new rXMLRPCRequest(); if (!is_array($cmds)) { $req->addCommand(new rXMLRPCCommand($cmds, $hash)); if ($dbg) { rtDbg(__FUNCTION__, $cmds); } } else { $s = ''; foreach ($cmds as $cmd) { $s .= $cmd . ", "; $req->addCommand(new rXMLRPCCommand($cmd, $hash)); } if ($dbg) { rtDbg(__FUNCTION__, substr($s, 0, -2)); } } if (!$req->run()) { if ($dbg) { rtDbg(__FUNCTION__, "rXMLRPCRequest() run fail"); } return null; } elseif ($req->fault) { if ($dbg) { rtDbg(__FUNCTION__, "rXMLRPCRequest() fault"); } return null; } else { return $req; } }
} } } } } } } if (count($trackers) > 0) { $announce_list[] = $trackers; } if ($setComment || $setTrackers || $setPrivate) { foreach ($hashes as $hash) { $req = new rXMLRPCRequest(array(new rXMLRPCCommand("get_session"), new rXMLRPCCommand("d.is_open", $hash), new rXMLRPCCommand("d.is_active", $hash), new rXMLRPCCommand("d.get_state", $hash), new rXMLRPCCommand("d.get_tied_to_file", $hash), new rXMLRPCCommand("d.get_custom1", $hash), new rXMLRPCCommand("d.get_directory_base", $hash), new rXMLRPCCommand("d.get_connection_seed", $hash), new rXMLRPCCommand("d.get_complete", $hash))); $throttle = null; if (rTorrentSettings::get()->isPluginRegistered("throttle")) { $req->addCommand(new rXMLRPCCommand("d.get_throttle_name", $hash)); } if ($req->run() && !$req->fault) { $isStart = $req->val[1] != 0 && $req->val[2] != 0 && $req->val[3] != 0; $fname = $req->val[0] . $hash . ".torrent"; if (empty($req->val[0]) || !is_readable($fname)) { if (strlen($req->val[4]) && is_readable($req->val[4])) { $fname = $req->val[4]; } else { $fname = null; } } if ($fname) { $torrent = new Torrent($fname); if (!$torrent->errors()) { if ($setPrivate) {
public function flush() { $req1 = new rXMLRPCRequest(new rXMLRPCCommand("view_list")); if ($req1->run() && !$req1->fault) { $insCmd = getCmd('branch='); $req = new rXMLRPCRequest(); for ($i = 0; $i < MAX_RATIO; $i++) { $insCmd .= getCmd('d.views.has=') . 'rat_' . $i . ',,'; $rat = $this->rat[$i]; if (!in_array("rat_" . $i, $req1->val)) { $req->addCommand(new rXMLRPCCommand("group.insert_persistent_view", array("", "rat_" . $i))); } if ($this->isCorrect($i)) { $req->addCommand(new rXMLRPCCommand("group.rat_" . $i . ".ratio.enable", array(""))); $req->addCommand(new rXMLRPCCommand("group.rat_" . $i . ".ratio.min.set", $rat["min"])); $req->addCommand(new rXMLRPCCommand("group.rat_" . $i . ".ratio.max.set", $rat["max"])); $req->addCommand(new rXMLRPCCommand("group.rat_" . $i . ".ratio.upload.set", floatval($rat["upload"] * 1024 * 1024))); switch ($rat["action"]) { case RAT_STOP: $req->addCommand(new rXMLRPCCommand("system.method.set", array("group.rat_" . $i . ".ratio.command", getCmd("d.stop=") . "; " . getCmd("d.close=")))); break; case RAT_STOP_AND_REMOVE: $req->addCommand(new rXMLRPCCommand("system.method.set", array("group.rat_" . $i . ".ratio.command", getCmd("d.stop=") . "; " . getCmd("d.close=") . "; " . getCmd("view.set_not_visible") . "=rat_" . $i . "; " . getCmd("d.views.remove") . "=rat_" . $i))); break; case RAT_ERASE: $req->addCommand(new rXMLRPCCommand("system.method.set", array("group.rat_" . $i . ".ratio.command", getCmd("d.stop=") . "; " . getCmd("d.close=") . "; " . getCmd("d.erase=")))); break; case RAT_ERASEDATA: $req->addCommand(new rXMLRPCCommand("system.method.set", array("group.rat_" . $i . ".ratio.command", getCmd("d.stop=") . "; " . getCmd("d.close=") . "; " . getCmd("d.set_custom5=") . "1; " . getCmd("d.erase=")))); break; default: $thr = "thr_" . ($rat["action"] - RAT_FIRSTTHROTTLE); $req->addCommand(new rXMLRPCCommand("system.method.set", array("group.rat_" . $i . ".ratio.command", getCmd('cat') . '=$' . getCmd("d.stop") . '=,$' . getCmd("d.set_throttle_name=") . $thr . ',$' . getCmd('d.start=')))); break; } } } if ($this->isCorrect($this->default - 1)) { $req->addCommand(rTorrentSettings::get()->getOnInsertCommand(array('_ratio' . getUser(), $insCmd . getCmd('view.set_visible=') . 'rat_' . ($this->default - 1)))); } else { $req->addCommand(rTorrentSettings::get()->getOnInsertCommand(array('_ratio' . getUser(), getCmd('cat=')))); } return $req->run() && !$req->fault; } return false; }
public function setHandlers() { global $autowatch_interval; $theSettings = rTorrentSettings::get(); $req = new rXMLRPCRequest($theSettings->getOnInsertCommand(array('autolabel' . getUser(), getCmd('cat=')))); $pathToAutoTools = dirname(__FILE__); if ($this->enable_label) { $cmd = $theSettings->getOnInsertCommand(array('_autolabel' . getUser(), getCmd('branch') . '=$' . getCmd('not') . '=$' . getCmd("d.get_custom1") . '=,"' . getCmd('execute') . '={' . getPHP() . ',' . $pathToAutoTools . '/label.php,$' . getCmd("d.get_hash") . '=,' . getUser() . '}"')); } else { $cmd = $theSettings->getOnInsertCommand(array('_autolabel' . getUser(), getCmd('cat='))); } $req->addCommand($cmd); if ($this->enable_move && trim($this->path_to_finished) != '') { if ($theSettings->iVersion < 0x808) { $cmd = $theSettings->getOnFinishedCommand(array('automove' . getUser(), getCmd('d.set_custom') . '=x-dest,"$' . getCmd('execute_capture') . '={' . getPHP() . ',' . $pathToAutoTools . '/move.php,$' . getCmd('d.get_hash') . '=,$' . getCmd('d.get_base_path') . '=,$' . getCmd('d.get_base_filename') . '=,$' . getCmd('d.is_multi_file') . '=,' . getUser() . '}" ; ' . getCmd('branch') . '=$' . getCmd('not') . '=$' . getCmd('d.get_custom') . '=x-dest,,' . getCmd('d.set_directory_base') . '=$' . getCmd('d.get_custom') . '=x-dest')); } else { if ($this->fileop_type == "Move") { $cmd = $theSettings->getOnFinishedCommand(array('automove' . getUser(), getCmd('d.set_directory_base') . '="$' . getCmd('execute_capture') . '={' . getPHP() . ',' . $pathToAutoTools . '/check.php,$' . getCmd('d.get_base_path') . '=,$' . getCmd('d.get_base_filename') . '=,$' . getCmd('d.is_multi_file') . '=,' . getUser() . '}" ; ' . getCmd('execute') . '={' . getPHP() . ',' . $pathToAutoTools . '/move.php,$' . getCmd('d.get_hash') . '=,$' . getCmd('d.get_base_path') . '=,$' . getCmd('d.get_base_filename') . '=,$' . getCmd('d.is_multi_file') . '=,' . getUser() . '}')); } else { $cmd = $theSettings->getOnFinishedCommand(array('automove' . getUser(), getCmd('execute') . '={' . getPHP() . ',' . $pathToAutoTools . '/move.php,$' . getCmd('d.get_hash') . '=,$' . getCmd('d.get_base_path') . '=,$' . getCmd('d.get_base_filename') . '=,$' . getCmd('d.is_multi_file') . '=,' . getUser() . '}')); } } } else { $cmd = $theSettings->getOnFinishedCommand(array('automove' . getUser(), getCmd('cat='))); } $req->addCommand($cmd); if ($this->enable_watch && trim($this->path_to_watch) != '') { $cmd = $theSettings->getAbsScheduleCommand('autowatch', $autowatch_interval, getCmd('execute') . '={sh,-c,' . escapeshellarg(getPHP()) . ' ' . escapeshellarg($pathToAutoTools . '/watch.php') . ' ' . escapeshellarg(getUser()) . ' &}'); } else { $cmd = $theSettings->getRemoveScheduleCommand('autowatch'); } $req->addCommand($cmd); return $req->success(); }
public static function sendMagnet($magnet, $isStart, $isAddPath, $directory, $label, $addition = null) { $hpos = stripos($magnet, 'xt=urn:btih:'); if ($hpos !== false) { $hpos += 12; $fpos = stripos($magnet, '&', $hpos); if ($fpos === false) { $fpos = strlen($magnet); } $hash = strtoupper(substr($magnet, $hpos, $fpos - $hpos)); if (strlen($hash) == 32) { $hash = base32decode($hash); } if (strlen($hash) == 40) { $req = new rXMLRPCRequest(); $cmd = new rXMLRPCCommand($isStart ? 'load_start' : 'load'); $cmd->addParameter($magnet); if ($directory && strlen($directory) > 0) { if (!rTorrentSettings::get()->correctDirectory($directory)) { return false; } $cmd->addParameter(($isAddPath ? getCmd("d.set_directory=") . "\"" : getCmd("d.set_directory_base=") . "\"") . $directory . "\""); $req->addCommand(new rXMLRPCCommand('execute', array('mkdir', '-p', $directory))); } if ($label && strlen($label) > 0) { $label = rawurlencode($label); if (strlen($label) <= 4096) { $cmd->addParameter(getCmd("d.set_custom1=") . $label); } } if (is_array($addition)) { foreach ($addition as $key => $prm) { $cmd->addParameter($prm, 'string'); } } $req->addCommand($cmd); if ($req->success()) { return $hash; } } } return false; }
public function obtain() { $req = new rXMLRPCRequest(array(new rXMLRPCCommand("get_upload_rate"), new rXMLRPCCommand("get_download_rate"))); if ($req->run() && !$req->fault) { $req1 = new rXMLRPCRequest(); if ($req->val[0] == 0) { $req1->addCommand(new rXMLRPCCommand("set_upload_rate", MAX_SPEED)); } if ($req->val[1] == 0) { $req1->addCommand(new rXMLRPCCommand("set_download_rate", MAX_SPEED)); } if (($req->val[0] == 0 || $req->val[1] == 0) && (!$req1->run() || $req1->fault)) { return false; } return $this->correct(); } return false; }
public static function processArray($hashes, $cmd1, $cmd2) { $req = new rXMLRPCRequest(); foreach ($hashes as $hash => $val) { $req->addCommand(new rXMLRPCCommand($cmd1, $hash)); $req->addCommand(new rXMLRPCCommand($cmd2, $hash)); } return $req->run() && !$req->fault; }