public static function createTorrent($torrent, $hash) { global $saveUploadedTorrents; $torrent = new Torrent($torrent); if ($torrent->errors()) { return self::STE_DELETED; } if ($torrent->hash_info() == $hash) { return self::STE_UPTODATE; } $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.get_directory_base", $hash), new rXMLRPCCommand("d.get_custom1", $hash), new rXMLRPCCommand("d.get_throttle_name", $hash), new rXMLRPCCommand("d.get_connection_seed", $hash), new rXMLRPCCommand("d.is_open", $hash), new rXMLRPCCommand("d.is_active", $hash), new rXMLRPCCommand("d.get_state", $hash), new rXMLRPCCommand("d.stop", $hash), new rXMLRPCCommand("d.close", $hash))); if ($req->success()) { $addition = array(getCmd("d.set_connection_seed=") . $req->val[3], getCmd("d.set_custom") . "=chk-state," . self::STE_UPDATED, getCmd("d.set_custom") . "=chk-time," . time(), getCmd("d.set_custom") . "=chk-stime," . time()); $isStart = $req->val[4] != 0 && $req->val[5] != 0 && $req->val[6] != 0; if (!empty($req->val[2])) { $addition[] = getCmd("d.set_throttle_name=") . $req->val[2]; } if (preg_match('/rat_(\\d+)/', $req->val[3], $ratio)) { $addition[] = getCmd("view.set_visible=") . "rat_" . $ratio; } $label = rawurldecode($req->val[1]); if (rTorrent::sendTorrent($torrent, $isStart, false, $req->val[0], $label, $saveUploadedTorrents, false, true, $addition)) { $req = new rXMLRPCRequest(new rXMLRPCCommand("d.erase", $hash)); if ($req->success()) { return null; } } } return self::STE_ERROR; }
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; }
function getRatiosStat() { $req = new rXMLRPCRequest(new rXMLRPCCommand("d.multicall", array("main", getCmd("d.get_hash=")))); $ret = 'theWebUI.ratiosStat = {'; if ($req->run() && !$req->fault) { $tm = time(); for ($i = 0; $i < count($req->val); $i++) { $st = new rStat("torrents/" . $req->val[$i] . ".csv"); $ratios = $st->getRatios($tm); if ($ret != 'theWebUI.ratiosStat = {') { $ret .= ','; } $ret .= '"' . $req->val[$i] . '": [' . $ratios[0] . ',' . $ratios[1] . ',' . $ratios[2] . ']'; } } return $ret . '}; '; }
function getNFO() { if ($_GET['id']) { $hash = $_GET['id']; $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.get_base_path", $hash), new rXMLRPCCommand("d.get_name", $hash))); if ($req->success()) { $dir = $req->val[0]; if ($h = opendir($dir)) { while (false !== ($file = readdir($h))) { if (preg_match("/\\.nfo\$/", $file)) { return file_get_contents($dir . "/" . $file); } } } } } return false; }
public static function fastResume($torrent, $base, $add_path = true) { $files = array(); $info = $torrent->info; $psize = intval($info['piece length']); $base = trim($base); if ($base == '') { $req = new rXMLRPCRequest(new \model\xmlrpc\rXMLRPCCommand(\config\Conf::$userscgi, 'get_directory')); if ($req->success()) { $base = $req->val[0]; } } if ($psize && \model\xmlrpc\rTorrentSettings::get(\config\Conf::$userscgi)->correctDirectory($base)) { $base = addslash($base); $tsize = 0.0; if (isset($info['files'])) { foreach ($info['files'] as $key => $file) { $tsize += floatval($file['length']); $files[] = $add_path ? $info['name'] . "/" . implode('/', $file['path']) : implode('/', $file['path']); } } else { $tsize = floatval($info['length']); $files[] = $info['name']; } $chunks = intval(($tsize + $psize - 1) / $psize); $torrent->{'libtorrent_resume'}['bitfield'] = intval($chunks); if (!isset($torrent->{'libtorrent_resume'}['files'])) { $torrent->{'libtorrent_resume'}['files'] = array(); } foreach ($files as $key => $file) { $ss = LFS::stat($base . $file); if ($ss === false) { return false; } if (count($torrent->{'libtorrent_resume'}['files']) < $key) { $torrent->{'libtorrent_resume'}['files'][$key]['mtime'] = $ss["mtime"]; } else { $torrent->{'libtorrent_resume'}['files'][$key] = array("priority" => 2, "mtime" => $ss["mtime"]); } } return $torrent; } return false; }
} } if ($setComment) { $torrent->clear_comment(); $comment = trim($comment); if (strlen($comment)) { $torrent->comment($comment); } } if (isset($torrent->{'rtorrent'})) { unset($torrent->{'rtorrent'}); } if (count($req->val) > 9) { $throttle = getCmd("d.set_throttle_name=") . $req->val[9]; } $eReq = new rXMLRPCRequest(new rXMLRPCCommand("d.erase", $hash)); if ($eReq->run() && !$eReq->fault) { $label = rawurldecode($req->val[5]); if (!rTorrent::sendTorrent($torrent, $isStart, false, $req->val[6], $label, false, $req->val[8] == 1, false, array(getCmd("d.set_custom3") . "=1", getCmd("d.set_connection_seed=") . $req->val[7], $throttle))) { $errors[] = array('desc' => "theUILang.errorAddTorrent", 'prm' => $fname); } } else { $errors[] = array('desc' => "theUILang.badLinkTorTorrent", 'prm' => ''); } } else { $errors[] = array('desc' => "theUILang.errorReadTorrent", 'prm' => $fname); } } else { $errors[] = array('desc' => "theUILang.cantFindTorrent", 'prm' => ''); } } else {
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 static function run($cmd, $flags = 0) { $ret = -1; $params = " >/dev/null 2>&1"; if (!($flags & self::FLG_WAIT)) { $params .= " &"; } if ($flags & self::FLG_RUN_AS_WEB) { if (self::FLG_RUN_AS_CMD) { $cmd = '-c "' . $cmd . '"'; } exec('sh ' . $cmd . $params, $output, $ret); } else { $req = new rXMLRPCRequest(rTorrentSettings::get()->iVersion >= 0x900 && !($flags & self::FLG_WAIT) ? new rXMLRPCCommand("execute.nothrow.bg", array("", "sh", $cmd)) : new rXMLRPCCommand("execute_nothrow", array("sh", "-c", $cmd . $params))); if ($req->success() && count($req->val)) { $ret = intval($req->val[0]); } } return $ret; }
<?php if (chdir(dirname(__FILE__))) { if (count($argv) > 3) { $_SERVER['REMOTE_USER'] = $argv[3]; } if (count($argv) > 2 && empty($argv[2])) { require_once "rquota.php"; $qt = rQuota::load(); if (!$qt->check()) { $action = new rXMLRPCRequest(new rXMLRPCCommand("d.stop", $argv[1])); $action->run(); } else { $qt->restoreDL(); } } }
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(); }
<?php $req = new rXMLRPCRequest(rTorrentSettings::get()->getRemoveScheduleCommand("rss")); $req->run();
public function setHandlers() { global $rootPath; if ($this->enabled) { $cmd = rTorrentSettings::get()->getOnFinishedCommand(array('unpack' . getUser(), getCmd('execute') . '={' . getPHP() . ',' . $rootPath . '/plugins/unpack/update.php,$' . getCmd('d.get_directory') . '=,$' . getCmd('d.get_base_filename') . '=,$' . getCmd('d.is_multi_file') . '=,$' . getCmd('d.get_custom1') . '=,$' . getCmd('d.get_name') . '=,' . getCmd('d.get_hash') . '=,' . getUser() . '}')); } else { $cmd = rTorrentSettings::get()->getOnFinishedCommand(array('unpack' . getUser(), getCmd('cat='))); } $req = new rXMLRPCRequest($cmd); return $req->success(); }
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 setHandlers() { global $rootPath; $throttleRulesExist = false; $ratioRulesExist = false; foreach ($this->lst as $item) { if ($item->ratio != '') { $ratioRulesExist = true; } if ($item->channel != '') { $throttleRulesExist = true; } } if ($ratioRulesExist) { eval(getPluginConf('ratio')); $insCmd = ''; for ($i = 0; $i < MAX_RATIO; $i++) { $insCmd .= getCmd('d.views.has=') . 'rat_' . $i . ',,'; } $ratCmd = getCmd('d.set_custom') . '=x-extratio1,"$' . getCmd('execute_capture') . '={' . getPHP() . ',' . $rootPath . '/plugins/extratio/update.php,\\"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#\\",$' . getCmd('d.get_custom1') . '=,ratio,' . getUser() . '}" ; ' . getCmd('branch') . '=$' . getCmd('not') . '=$' . getCmd('d.get_custom') . '=x-extratio1,,' . $insCmd . getCmd('view.set_visible') . '=$' . getCmd('d.get_custom') . '=x-extratio1'; } else { $ratCmd = getCmd('cat='); } if ($throttleRulesExist) { $thrCmd = getCmd('d.set_custom') . '=x-extratio2,"$' . getCmd('execute_capture') . '={' . getPHP() . ',' . $rootPath . '/plugins/extratio/update.php,\\"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#\\",$' . getCmd('d.get_custom1') . '=,channel,' . getUser() . '}" ; ' . getCmd('branch') . '=$' . getCmd('not') . '=$' . getCmd('d.get_custom') . '=x-extratio2,,' . getCmd('d.set_throttle_name') . '=$' . getCmd('d.get_custom') . '=x-extratio2'; } else { $thrCmd = getCmd('cat='); } $req = new rXMLRPCRequest(array(rTorrentSettings::get()->getOnInsertCommand(array('_exratio1' . getUser(), $ratCmd)), rTorrentSettings::get()->getOnInsertCommand(array('_exratio2' . getUser(), $thrCmd)))); return $req->success(); }
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 run($hash, $state = null, $time = null, $successful_time = null) { global $saveUploadedTorrents; if (is_null($state)) { self::getState($hash, $state, $time, $successful_time); } if ($state == self::STE_INPROGRESS && time() - $time > self::MAX_LOCK_TIME) { $state = 0; } if ($state != self::STE_INPROGRESS) { $state = self::STE_INPROGRESS; if (!self::setState($hash, $state)) { return false; } $fname = rTorrentSettings::get()->session . $hash . ".torrent"; if (is_readable($fname)) { $torrent = new Torrent($fname); if (!$torrent->errors()) { if (preg_match('`^http://(?P<tracker>rutracker)\\.org/forum/viewtopic\\.php\\?t=(?P<id>\\d+)$`', $torrent->comment(), $matches) || preg_match('`^http://(?P<tracker>kinozal)\\.tv/details\\.php\\?id=(?P<id>\\d+)$`', $torrent->comment(), $matches)) { if ($matches["tracker"] == "rutracker") { $client = self::makeClient($torrent->comment()); if ($client->status == 200 && preg_match("`ajax.form_token\\s*=\\s*'(?P<form_token>[^']+)';.*topic_id\\s*:\\s*(?P<topic_id>\\d+),\\s*t_hash\\s*:\\s*'(?P<t_hash>[^']+)'`s", $client->results, $matches1)) { $client->setcookies(); $client->fetch("http://rutracker.org/forum/ajax.php", "POST", "application/x-www-form-urlencoded; charset=UTF-8", "action=get_info_hash" . "&topic_id=" . $matches1["topic_id"] . "&t_hash=" . $matches1["t_hash"] . "&form_token=" . $matches1["form_token"]); if ($client->status == 200) { $ret = json_decode($client->results, true); if ($ret && array_key_exists("ih_hex", $ret) && strtoupper($ret["ih_hex"]) == $hash) { self::setState($hash, self::STE_UPTODATE); return true; } } } $client->setcookies(); $client->fetchComplex("http://dl.rutracker.org/forum/dl.php?t=" . $matches["id"]); } else { if ($matches["tracker"] == "kinozal") { $client = self::makeClient("http://kinozal.tv/get_srv_details.php?action=2&id=" . $matches["id"]); if ($client->status == 200 && preg_match('`<li>.*(?P<hash>[0-9A-Fa-f]{40})</li>`', $client->results, $matches1)) { if (strtoupper($matches1["hash"]) == $hash) { self::setState($hash, self::STE_UPTODATE); return true; } } $client->setcookies(); $client->fetchComplex("http://dl.kinozal.tv/download.php?id=" . $matches["id"]); } else { self::setState($hash, self::STE_NOT_NEED); return true; } } if ($client->status == 200) { $torrent = new Torrent($client->results); if (!$torrent->errors()) { if ($torrent->hash_info() != $hash) { $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.get_directory_base", $hash), new rXMLRPCCommand("d.get_custom1", $hash), new rXMLRPCCommand("d.get_throttle_name", $hash), new rXMLRPCCommand("d.get_connection_seed", $hash), new rXMLRPCCommand("d.is_open", $hash), new rXMLRPCCommand("d.is_active", $hash), new rXMLRPCCommand("d.get_state", $hash), new rXMLRPCCommand("d.stop", $hash), new rXMLRPCCommand("d.close", $hash))); if ($req->success()) { $addition = array(getCmd("d.set_connection_seed=") . $req->val[3], getCmd("d.set_custom") . "=chk-state," . self::STE_UPDATED, getCmd("d.set_custom") . "=chk-time," . time(), getCmd("d.set_custom") . "=chk-stime," . time()); $isStart = $req->val[4] != 0 && $req->val[5] != 0 && $req->val[6] != 0; if (!empty($req->val[2])) { $addition[] = getCmd("d.set_throttle_name=") . $req->val[2]; } if (preg_match('/rat_(\\d+)/', $req->val[3], $ratio)) { $addition[] = getCmd("view.set_visible=") . "rat_" . $ratio; } $label = rawurldecode($req->val[1]); if (rTorrent::sendTorrent($torrent, $isStart, false, $req->val[0], $label, $saveUploadedTorrents, false, true, $addition)) { $req = new rXMLRPCRequest(new rXMLRPCCommand("d.erase", $hash)); if ($req->success()) { $state = null; } } } } else { $state = self::STE_UPTODATE; } } else { $state = self::STE_DELETED; } } else { $state = $client->status < 0 ? self::STE_CANT_REACH_TRACKER : self::STE_DELETED; } } else { $state = self::STE_NOT_NEED; } } } if ($state == self::STE_INPROGRESS) { $state == self::STE_ERROR; } if (!is_null($state)) { self::setState($hash, $state); } } return $state != self::STE_CANT_REACH_TRACKER; }
$torrent_dir = rtRemoveLastToken($torrent_dir, '/'); } $lbl_dir = rtGetRelativePath($default_dir, $torrent_dir); if ($lbl_dir == "./") { $lbl_dir = ""; } $label = str_replace("{DIR}", $lbl_dir, $label); } } else { Debug("rXMLRPCRequest() fail"); $is_ok = false; } } // Get info about tracker if ($is_ok && strpos($label, "{TRACKER}") !== false) { $req = new rXMLRPCRequest(array(new rXMLRPCCommand("t.multicall", array($hash, "", getCmd("t.is_enabled="), getCmd("t.get_type="), getCmd("t.get_group="), getCmd("t.get_url="))))); $req->setParseByTypes(); if ($req->run() && !$req->fault) { for ($i = 0; $i < count($req->strings); $i++) { // enabled, type == 1, group == 0 if ($req->i8s[$i * 3] == 0 || $req->i8s[$i * 3 + 1] != 1 || $req->i8s[$i * 3 + 2] != 0) { continue; } $lbl_tracker = parse_url($req->strings[$i], PHP_URL_HOST); // if tracker is not an IP address, then if (preg_match("/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\$/", $domain) != 1) { // get 2-nd level domain only $pos = strpos($lbl_tracker, '.'); if ($pos !== false) { $tmp = substr($lbl_tracker, $pos + 1); if (strpos($tmp, '.') !== 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 function obtain() { $req = new rXMLRPCRequest(new rXMLRPCCommand("system.client_version")); if ($req->run() && count($req->val)) { $this->linkExist = true; $this->version = $req->val[0]; $parts = explode('.', $this->version); $this->iVersion = 0; for ($i = 0; $i < count($parts); $i++) { $this->iVersion = ($this->iVersion << 8) + $parts[$i]; } if ($this->iVersion > 0x806) { $this->mostOfMethodsRenamed = true; $this->aliases = array("d.set_peer_exchange" => "d.peer_exchange.set", "d.set_connection_seed" => "d.connection_seed.set"); } if ($this->iVersion == 0x808) { $req = new rXMLRPCRequest(new rXMLRPCCommand("file.prioritize_toc")); $req->important = false; if ($req->success()) { $this->iVersion = 0x809; } } $this->apiVersion = 0; if ($this->iVersion >= 0x901) { $req = new rXMLRPCRequest(new rXMLRPCCommand("system.api_version")); $req->important = false; if ($req->success()) { $this->apiVersion = $req->val[0]; } } $req = new rXMLRPCRequest(new rXMLRPCCommand("to_kb", floatval(1024))); if ($req->run()) { if (!$req->fault) { $this->badXMLRPCVersion = false; } $req = new rXMLRPCRequest(array(new rXMLRPCCommand("get_directory"), new rXMLRPCCommand("get_session"), new rXMLRPCCommand("system.library_version"), new rXMLRPCCommand("set_xmlrpc_size_limit", 67108863), new rXMLRPCCommand("get_name"), new rXMLRPCCommand("get_port_range"))); if ($req->run() && !$req->fault) { $this->directory = $req->val[0]; $this->session = $req->val[1]; $this->libVersion = $req->val[2]; $this->server = $req->val[4]; $this->portRange = $req->val[5]; $this->port = intval($this->portRange); if ($this->iVersion >= 0x809) { $req = new rXMLRPCRequest(new rXMLRPCCommand("network.listen.port")); $req->important = false; if ($req->success()) { $this->port = intval($req->val[0]); } } if (isLocalMode()) { if (!empty($this->session)) { $this->started = @filemtime($this->session . '/rtorrent.lock'); if ($this->started === false) { $this->started = 0; } } $id = getExternal('id'); $req = new rXMLRPCRequest(new rXMLRPCCommand("execute_capture", array("sh", "-c", $id . " -u ; " . $id . " -G ; echo ~ "))); if ($req->run() && !$req->fault && ($line = explode("\n", $req->val[0])) !== false && count($line) > 2) { $this->uid = intval(trim($line[0])); $this->gid = explode(' ', trim($line[1])); $this->home = trim($line[2]); if (!empty($this->directory) && $this->directory[0] == '~') { $this->directory = $this->home . substr($this->directory, 1); } } else { $this->idNotFound = true; } } $this->store(); } } } }
public function setHandlers() { if (rTorrentSettings::get()->linkExist) { $req = new rXMLRPCRequest($this->hasAuto() ? rTorrentSettings::get()->getScheduleCommand("loginmgr", 1440, getCmd('execute') . '={sh,-c,' . escapeshellarg(getPHP()) . ' ' . escapeshellarg(dirname(__FILE__) . '/update.php') . ' ' . escapeshellarg(getUser()) . ' & exit 0}') : rTorrentSettings::get()->getRemoveScheduleCommand("loginmgr")); $req->success(); } }
public function obtain() { if (function_exists('posix_geteuid') && function_exists('posix_getegid')) { $this->myuid = posix_geteuid(); $this->mygid = posix_getegid(); } else { $randName = '/tmp/rutorrent-' . rand() . '.tmp'; @file_put_contents($randName, ''); $ss = @stat($randName); if ($ss) { $this->mygid = $ss['gid']; $this->myuid = $ss['uid']; @unlink($randName); } } $req = new rXMLRPCRequest(new rXMLRPCCommand("to_kb", floatval(1024))); if ($req->run()) { $this->linkExist = true; if (!$req->fault) { $this->badXMLRPCVersion = false; } $req = new rXMLRPCRequest(array(new rXMLRPCCommand("get_directory"), new rXMLRPCCommand("get_session"), new rXMLRPCCommand("system.client_version"), new rXMLRPCCommand("system.library_version"), new rXMLRPCCommand("set_xmlrpc_size_limit", 67108863))); if ($req->run() && !$req->fault) { $this->directory = $req->val[0]; $this->session = $req->val[1]; $this->version = $req->val[2]; $this->libVersion = $req->val[3]; $parts = explode('.', $this->version); $this->iVersion = 0; for ($i = 0; $i < count($parts); $i++) { $this->iVersion = ($this->iVersion << 8) + $parts[$i]; } if (is_dir($this->session) && isLocalMode()) { $ss = @stat($this->session . 'rtorrent.lock'); if (!$ss) { $ss = @stat($this->session . 'rtorrent.dht_cache'); } if (!$ss) { $ss = @stat($this->session); } if ($ss) { $this->gid = $ss['gid']; $this->uid = $ss['uid']; if (!empty($this->directory) && $this->directory[0] == '~') { if (function_exists('posix_getpwuid')) { $ui = posix_getpwuid($this->uid); $this->directory = $ui["dir"] . substr($this->directory, 1); } else { $req = new rXMLRPCRequest(new rXMLRPCCommand("execute_capture", array("echo", "~"))); if ($req->run() && !$req->fault) { $this->directory = trim($req->val[0]) . substr($this->directory, 1); } } } } } $this->store(); } } }
public function setHandlers() { $startAt = 0; $req = new rXMLRPCRequest(rTorrentSettings::get()->getScheduleCommand("rss", $this->data->interval, getCmd('execute') . '={sh,-c,' . escapeshellarg(getPHP()) . ' ' . escapeshellarg(dirname(__FILE__) . '/update.php') . ' ' . escapeshellarg(getUser()) . ' & exit 0}', $startAt)); if ($req->success()) { $this->setStartTime($startAt); return true; } return false; }
<?php require_once '../../php/xmlrpc.php'; if (!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = file_get_contents("php://input"); } if (isset($HTTP_RAW_POST_DATA) && !preg_match("/(execute|import)\\s*=/i", $HTTP_RAW_POST_DATA)) { $result = rXMLRPCRequest::send($HTTP_RAW_POST_DATA); if (!empty($result)) { $pos = strpos($result, "\r\n\r\n"); if ($pos !== false) { $result = substr($result, $pos + 4); } cachedEcho($result, "text/xml"); } } header("HTTP/1.0 500 Server Error"); cachedEcho("Link to XMLRPC failed. May be, rTorrent is down?", "text/html");
function rtAddTorrent($fname, $isStart, $directory, $label, $dbg = false) { if ($isStart) { $method = 'load_start_verbose'; } else { $method = 'load_verbose'; } if ($dbg) { rtDbg(__FUNCTION__, "1" . $fname); } $torrent = new Torrent($fname); if ($dbg) { rtDbg(__FUNCTION__, "2"); } if ($torrent->errors()) { if ($dbg) { rtDbg(__FUNCTION__, "fail to create Torrent() object"); } return false; } if ($directory && strlen($directory) > 0) { $directory = rtMakeStrParam("d.set_directory=\"" . $directory . "\""); } else { $directory = ""; } $comment = $torrent->comment(); if ($comment && strlen($comment) > 0) { if (isInvalidUTF8($comment)) { $comment = win2utf($comment); } if (strlen($comment) > 0) { $comment = rtMakeStrParam("d.set_custom2=VRS24mrker" . rawurlencode($comment)); if (strlen($comment) > 4096) { $comment = ''; } } } else { $comment = ""; } if ($label && strlen($label) > 0) { $label = rtMakeStrParam("d.set_custom1=\"" . rawurlencode($label) . "\""); } else { $label = ""; } $addition = ""; global $saveUploadedTorrents; $delete_tied = $saveUploadedTorrents ? "" : rtMakeStrParam("d.delete_tied="); $content = '<?xml version="1.0" encoding="UTF-8"?>' . '<methodCall>' . '<methodName>' . $method . '</methodName>' . '<params>' . '<param><value><string>' . $fname . '</string></value></param>' . $directory . $comment . $label . $addition . $delete_tied . '</params></methodCall>'; //if( $dbg ) rtDbg( __FUNCTION__, $content ); $res = rXMLRPCRequest::send($content); if ($dbg && !empty($res)) { rtDbg(__FUNCTION__, $res); } if (!$res || ($res = '')) { return false; } else { return $torrent->hash_info(); } }
function findRemoteEXE($exe, $err, &$remoteRequests) { $st = getSettingsPath() . '/' . rand(); if (!array_key_exists($exe, $remoteRequests)) { $path = realpath(dirname('.')); global $pathToExternals; $cmd = array("sh", addslash($path) . "test.sh", $exe, $st); if (isset($pathToExternals[$exe]) && !empty($pathToExternals[$exe])) { $cmd[] = $pathToExternals[$exe]; } $req = new rXMLRPCRequest(new rXMLRPCCommand("execute", $cmd)); $req->run(); $remoteRequests[$exe] = array("path" => $st, "err" => array()); } $remoteRequests[$exe]["err"][] = $err; }
function findRemoteEXE($exe, $err, &$remoteRequests) { $st = getSettingsPath() . '/'; if (!is_file($st . $exe)) { if (!array_key_exists($exe, $remoteRequests)) { $path = realpath(dirname('.')); $req = new rXMLRPCRequest(new rXMLRPCCommand("execute", array("sh", "-c", escapeshellarg(addslash($path) . "test.sh") . " " . $exe . " " . escapeshellarg($st)))); $req->run(); } $remoteRequests[$exe][] = $err; } }
<?php require_once '../../php/util.php'; require_once '../../php/settings.php'; if (isset($_REQUEST['mode'])) { $output = array(); $modes = explode(';', $_REQUEST['mode']); $theSettings = rTorrentSettings::get(); if (in_array("labels", $modes)) { $req = new rXMLRPCRequest(new rXMLRPCCommand("d.multicall", array("", getCmd("d.get_custom1=")))); $labels = array(); if ($req->run() && !$req->fault) { for ($i = 0; $i < count($req->val); $i++) { $val = trim(rawurldecode($req->val[$i])); if ($val != '') { $labels[$val] = true; } } $output["labels"] = array_keys($labels); } } if (in_array("dirlist", $modes)) { $dh = false; if (isset($_REQUEST['basedir'])) { $dir = rawurldecode($_REQUEST['basedir']); $theSettings->correctDirectory($dir); $dh = @opendir($dir); $dir = addslash($dir); if ($dh && (strpos($dir, $topDirectory) !== 0 || $theSettings->uid >= 0 && !isUserHavePermission($theSettings->uid, $theSettings->gid, $dir, 0x7))) { closedir($dh); $dh = false;
public function setHandlers() { global $rootPath; if ($this->log["addition"] || $this->log["pushbullet_enabled"] && $this->log["pushbullet_addition"]) { $addCmd = getCmd('execute') . '={' . getPHP() . ',' . $rootPath . '/plugins/history/update.php' . ',1,$' . getCmd('d.get_name') . '=,$' . getCmd('d.get_size_bytes') . '=,$' . getCmd('d.get_bytes_done') . '=,$' . getCmd('d.get_up_total') . '=,$' . getCmd('d.get_ratio') . '=,$' . getCmd('d.get_creation_date') . '=,$' . getCmd('d.get_custom') . '=addtime,$' . getCmd('d.get_custom') . '=seedingtime' . ',"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#",$' . getCmd('d.get_custom1') . "=,\$" . getCmd('d.get_custom') . "=x-pushbullet," . getUser() . '}'; } else { $addCmd = getCmd('cat='); } if ($this->log["finish"] || $this->log["pushbullet_enabled"] && $this->log["pushbullet_finish"]) { $finCmd = getCmd('execute') . '={' . getPHP() . ',' . $rootPath . '/plugins/history/update.php' . ',2,$' . getCmd('d.get_name') . '=,$' . getCmd('d.get_size_bytes') . '=,$' . getCmd('d.get_bytes_done') . '=,$' . getCmd('d.get_up_total') . '=,$' . getCmd('d.get_ratio') . '=,$' . getCmd('d.get_creation_date') . '=,$' . getCmd('d.get_custom') . '=addtime,$' . getCmd('d.get_custom') . '=seedingtime' . ',"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#",$' . getCmd('d.get_custom1') . "=,\$" . getCmd('d.get_custom') . "=x-pushbullet," . getUser() . '}'; } else { $finCmd = getCmd('cat='); } if ($this->log["deletion"] || $this->log["pushbullet_enabled"] && $this->log["pushbullet_deletion"]) { $delCmd = getCmd('execute') . '={' . getPHP() . ',' . $rootPath . '/plugins/history/update.php' . ',3,$' . getCmd('d.get_name') . '=,$' . getCmd('d.get_size_bytes') . '=,$' . getCmd('d.get_bytes_done') . '=,$' . getCmd('d.get_up_total') . '=,$' . getCmd('d.get_ratio') . '=,$' . getCmd('d.get_creation_date') . '=,$' . getCmd('d.get_custom') . '=addtime,$' . getCmd('d.get_custom') . '=seedingtime' . ',"$' . getCmd('t.multicall') . '=$' . getCmd('d.get_hash') . '=,' . getCmd('t.get_url') . '=,' . getCmd('cat') . '=#",$' . getCmd('d.get_custom1') . "=,\$" . getCmd('d.get_custom') . "=x-pushbullet," . getUser() . '}'; } else { $delCmd = getCmd('cat='); } $req = new rXMLRPCRequest(array(rTorrentSettings::get()->getOnInsertCommand(array('thistory' . getUser(), $addCmd)), rTorrentSettings::get()->getOnFinishedCommand(array('thistory' . getUser(), $finCmd)), rTorrentSettings::get()->getOnEraseCommand(array('thistory' . getUser(), $delCmd)))); return $req->success(); }
<?php require_once 'rquota.php'; $qt = rQuota::load(); $qt->update(); $tm = getdate(); $startAt = mktime($tm["hours"], (int) ($tm["minutes"] / $quotaUpdateInterval) * $quotaUpdateInterval + $quotaUpdateInterval, 0, $tm["mon"], $tm["mday"], $tm["year"]) - $tm[0]; if ($startAt < 0) { $startAt = 0; } $interval = $quotaUpdateInterval * 60; $req = new rXMLRPCRequest(array(new rXMLRPCCommand("schedule", array('quotaspace' . getUser(), $startAt . "", $interval . "", getCmd('execute') . '={sh,-c,' . escapeshellarg(getPHP()) . ' ' . escapeshellarg($rootPath . '/plugins/quotaspace/update.php') . ' ' . escapeshellarg(getUser()) . ' & exit 0}')), $theSettings->getOnResumedCommand(array('quotapauser' . getUser(), getCmd('execute') . '={sh,' . $rootPath . '/plugins/quotaspace/run.sh' . ',' . getPHP() . ',$' . getCmd("d.get_hash") . '=,$' . getCmd("d.get_complete") . '=,' . getUser() . '}')))); if ($req->success()) { $theSettings->registerPlugin($plugin["name"], $pInfo["perms"]); } else { $jResult .= "plugin.disable(); log('quotaspace: '+theUILang.pluginCantStart);"; }
public static function getTorrentHashFilepath($hash, $fno) { $fno = intval($fno); $req = new \rXMLRPCRequest(new \rXMLRPCCommand("f.get_frozen_path", array($hash, $fno))); $filename = ''; 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, $fno)), new \rXMLRPCCommand("d.close", $hash))); if ($req->success()) { $filename = $req->val[1]; } } } return $filename; }