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; }
public static function sendTorrent($fname, $isStart, $isAddPath, $directory, $label, $saveTorrent, $isFast, $addition = null) { $hash = false; $torrent = is_object($fname) ? $fname : new Torrent($fname); if (!$torrent->errors()) { if ($isFast && ($resume = self::fastResume($torrent, $directory, $isAddPath))) { $torrent = $resume; } $cmd = new rXMLRPCCommand($isStart ? 'load_raw_start' : 'load_raw'); $cmd->addParameter(base64_encode($torrent->__toString()), "base64"); if (!$saveTorrent && is_string($fname)) { @unlink($fname); } $comment = $torrent->comment(); if ($comment) { if (isInvalidUTF8($comment)) { $comment = win2utf($comment); } if (strlen($comment) > 0) { $comment = "VRS24mrker" . rawurlencode($comment); if (strlen($comment) <= 4096) { $cmd->addParameter("d.set_custom2=" . $comment); } } } if ($label && strlen($label) > 0) { $label = rawurlencode($label); if (strlen($label) <= 4096) { $cmd->addParameter("d.set_custom1=" . $label); } } if ($directory && strlen($directory) > 0) { $cmd->addParameter(($isAddPath ? "d.set_directory=\"" : "d.set_directory_base=\"") . $directory . "\""); } if (is_array($addition)) { foreach ($addition as $key => $prm) { $cmd->addParameter($prm, 'string'); } } $req = new rXMLRPCRequest($cmd); if ($req->run() && !$req->fault) { $hash = $torrent->hash_info(); } } return $hash; }
function makeMulticall($cmds, $hash, $add, $prefix) { $cmd = new rXMLRPCCommand($prefix . ".multicall", array($hash, "")); $cmd->addParameters(array_map("getCmd", $cmds)); foreach ($add as $prm) { $cmd->addParameter($prm); } $cnt = count($cmds) + count($add); $req = new rXMLRPCRequest($cmd); if ($req->success()) { $result = array(); for ($i = 0; $i < count($req->val); $i += $cnt) { $result[] = array_slice($req->val, $i, $cnt); } return $result; } return false; }
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 static function getActiveTorrents() { $delta = 2; $cmd = new rXMLRPCCommand("d.multicall", array("started", getCmd("d.get_hash="), getCmd("d.get_connection_current="))); if (rTorrentSettings::get()->iVersion >= 0x805) { $cmd->addParameter(getCmd("d.get_custom=") . "sch_ignore"); $delta = 3; } $req = new rXMLRPCRequest($cmd); $seeds = array(); $leeches = array(); if ($req->run() && !$req->fault) { for ($i = 0; $i < count($req->val); $i += $delta) { $hash = $req->val[$i]; if ($delta == 2 || empty($req->val[$i + 2])) { if ($req->val[$i + 1] == 'leech') { $leeches[$hash] = true; } else { $seeds[$hash] = true; } } } } return array("seeds" => $seeds, "leeches" => $leeches); }
public function startTask($hash, $outPath, $mode = null, $fileno = null, $all = false) { global $rootPath; $ret = false; if (rTorrentSettings::get()->isPluginRegistered('quotaspace')) { require_once dirname(__FILE__) . "/../quotaspace/rquota.php"; $qt = rQuota::load(); if (!$qt->check()) { return false; } } if ($outPath != '' && !rTorrentSettings::get()->correctDirectory($outPath)) { $outPath = ''; } if (!is_null($fileno) && !is_null($mode)) { $req = new rXMLRPCRequest(new rXMLRPCCommand("f.get_frozen_path", array($hash, intval($fileno)))); if ($req->success()) { $filename = $req->val[0]; if ($filename == '') { $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.open", $hash), new rXMLRPCCommand("f.get_frozen_path", array($hash, intval($fileno))), new rXMLRPCCommand("d.close", $hash))); if ($req->success()) { $filename = $req->val[1]; } } if ($outPath == '') { $outPath = dirname($filename); } if (LFS::is_file($filename) && $outPath != '') { $taskNo = time(); $dir = self::formatPath($taskNo); $pathToUnrar = getExternal('unrar'); $pathToUnzip = getExternal('unzip'); $arh = $mode == "zip" ? $pathToUnzip : $pathToUnrar; $c = new rXMLRPCCommand("execute", array("sh", "-c", escapeshellarg($rootPath . '/plugins/unpack/un' . $mode . '_file.sh') . " " . escapeshellarg($arh) . " " . escapeshellarg($filename) . " " . escapeshellarg(addslash($outPath)) . " " . escapeshellarg($dir . "log") . " " . escapeshellarg($dir . "status") . " &")); if ($all) { $c->addParameter("-v"); } $req = new rXMLRPCRequest($c); if ($req->success()) { $ret = array("no" => $taskNo, "name" => $filename, "out" => $outPath); } } } } else { $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.get_base_path", $hash), new rXMLRPCCommand("d.get_custom1", $hash), new rXMLRPCCommand("d.get_name", $hash))); if ($req->success()) { $basename = $req->val[0]; $label = rawurldecode($req->val[1]); $tname = $req->val[2]; if ($basename == '') { $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.open", $hash), new rXMLRPCCommand("d.get_base_path", $hash), new rXMLRPCCommand("d.close", $hash))); if ($req->success()) { $basename = $req->val[1]; } } $req = new rXMLRPCRequest(new rXMLRPCCommand("f.multicall", array($hash, "", getCmd("f.get_path=")))); if ($req->success()) { $rarPresent = false; $zipPresent = false; foreach ($req->val as $no => $name) { if (USE_UNRAR && preg_match("'.*\\.(rar|r\\d\\d|\\d\\d\\d)\$'si", $name) == 1) { $rarPresent = true; } else { if (USE_UNZIP && preg_match("'.*\\.zip\$'si", $name) == 1) { $zipPresent = true; } } } $mode = $rarPresent && $zipPresent ? 'all' : ($rarPresent ? 'rar' : ($zipPresent ? 'zip' : null)); if ($mode) { $taskNo = time(); $dir = self::formatPath($taskNo); $pathToUnrar = getExternal("unrar"); $pathToUnzip = getExternal("unzip"); $arh = $mode == "zip" ? $pathToUnzip : $pathToUnrar; if (is_dir($basename)) { $postfix = "_dir"; if ($outPath == '') { $outPath = $basename; } $basename = addslash($basename); } else { $postfix = "_file"; if ($outPath == '') { $outPath = dirname($basename); } $pathToUnzip = ""; } $outPath = addslash($outPath); if ($this->addLabel && $label != '') { $outPath .= addslash($label); } if ($this->addName && $tname != '') { $outPath .= addslash($tname); } $req = new rXMLRPCRequest(new rXMLRPCCommand("execute", array("sh", "-c", escapeshellarg($rootPath . '/plugins/unpack/un' . $mode . $postfix . '.sh') . " " . escapeshellarg($arh) . " " . escapeshellarg($basename) . " " . escapeshellarg($outPath) . " " . escapeshellarg($dir . "log") . " " . escapeshellarg($dir . "status") . " " . escapeshellarg($pathToUnzip) . " &"))); if ($req->success()) { $ret = array("no" => $taskNo, "name" => $basename, "out" => $outPath); } } else { $ret = array("no" => 0, "name" => $basename, "out" => ""); } } } } return $ret; }