Пример #1
0
        break;
    case "getchunks":
        $req = new rXMLRPCRequest(array(new rXMLRPCCommand("d.get_bitfield", $hash[0]), new rXMLRPCCommand("d.get_chunk_size", $hash[0]), new rXMLRPCCommand("d.get_size_chunks", $hash[0])));
        if (rTorrentSettings::get()->apiVersion >= 4) {
            $req->addCommand(new rXMLRPCCommand("d.chunks_seen", $hash[0]));
        }
        if ($req->success()) {
            $result = array("chunks" => $req->val[0], "size" => $req->val[1], "tsize" => $req->val[2]);
            if (rTorrentSettings::get()->apiVersion >= 4) {
                $result["seen"] = $req->val[3];
            }
        }
        break;
    default:
        if (isset($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");
            }
        }
        break;
}
if (is_null($result)) {
    header("HTTP/1.0 500 Server Error");
    cachedEcho(isset($req) && $req->fault ? "Warning: XMLRPC call is failed." : "Link to XMLRPC failed. May be, rTorrent is down?", "text/html");
} else {
    cachedEcho(json_encode($result), "application/json");
Пример #2
0
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();
    }
}