Пример #1
0
 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;
 }
Пример #2
0
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 . '}; ';
}
Пример #3
0
 public static function getSource($hash)
 {
     $req = new rXMLRPCRequest(array(new rXMLRPCCommand("get_session"), new rXMLRPCCommand("d.get_tied_to_file", $hash)));
     if ($req->run() && !$req->fault) {
         $fname = $req->val[0] . $hash . ".torrent";
         if (empty($req->val[0]) || !is_readable($fname)) {
             if (strlen($req->val[1]) && is_readable($req->val[1])) {
                 $fname = $req->val[1];
             } else {
                 $fname = null;
             }
         }
         if ($fname) {
             $torrent = new Torrent($fname);
             if (!$torrent->errors()) {
                 return $torrent;
             }
         }
     }
     return false;
 }
Пример #4
0
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;
}
Пример #5
0
 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();
         }
     }
 }
Пример #6
0
 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();
             }
         }
     }
 }
Пример #7
0
 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();
         }
     }
 }
Пример #8
0
             }
             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 {
     $errors[] = array('desc' => "theUILang.badLinkTorTorrent", 'prm' => '');
Пример #9
0
<?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();
        }
    }
}
Пример #10
0
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;
    }
}
Пример #11
0
 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;
 }
Пример #12
0
 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;
 }
Пример #13
0
 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);
 }
Пример #14
0
 public static function checkTask($taskNo)
 {
     $ret = false;
     $dir = self::formatPath($taskNo);
     $logPath = $dir . "log";
     $statusPath = $dir . "status";
     if (is_file($statusPath) && is_readable($statusPath)) {
         $status = @file_get_contents($statusPath);
         if ($status === false) {
             $status = -1;
         } else {
             $status = trim($status);
         }
         if (preg_match('/^\\d*$/', $status) != 1) {
             $status = -1;
         }
         $errors = @file($logPath);
         if ($errors === false) {
             $errors = array();
         } else {
             $errors = array_map('trim', $errors);
         }
         $ret = array("no" => $taskNo, "status" => $status, "errors" => $errors);
         $req = new rXMLRPCRequest(array(new rXMLRPCCommand("execute", array("rm", $statusPath)), new rXMLRPCCommand("execute", array("rm", $logPath))));
         $req->run();
     }
     return $ret;
 }
Пример #15
0
<?php

$req = new rXMLRPCRequest(rTorrentSettings::get()->getRemoveScheduleCommand("rss"));
$req->run();
Пример #16
0
<?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;
Пример #17
0
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;
    }
}