| 1 | [[libtorrentMirror]] |
| 2 | |
| 3 | = Using XMLRPC with rtorrent = |
| 4 | |
| 5 | Since version 0.7.5, rtorrent has a built-in XMLRPC interface (if enabled). Recommendations for secure usage will come later, just make sure you are aware of the implications of opening the XMLRPC port. See [wiki:RTorrentCommands] for an incomplete list of commands. |
| 6 | |
| 7 | == Installation & Configuration == |
| 8 | |
| 9 | What you need: |
| 10 | |
| 11 | * http://python.ca/scgi/ for Apache, Lighttpd should have this built-in. |
| 12 | * http://xmlrpc-c.sourceforge.net/ 1.00 or later, 1.07 or later for 64bit integer support. |
| 13 | * rtorrent 0.7.5 or later. |
| 14 | |
| 15 | Configure rtorrent with the --with-xmlrpc-c flag and add the following to: |
| 16 | |
| 17 | {{{ |
| 18 | httpd.conf: SCGIMount /RPC2 127.0.0.1:5000 |
| 19 | rtorrent.rc: scgi_port = localhost:5000 |
| 20 | }}} |
| 21 | |
| 22 | For lighttpd: |
| 23 | {{{ |
| 24 | rtorrent.rc: scgi_local = /home/user/rtorrent/rpc.socket |
| 25 | |
| 26 | lighttpd.conf: |
| 27 | server.modules += ( "mod_scgi" ) |
| 28 | scgi.server = ( |
| 29 | "/RPC2" => |
| 30 | ( "127.0.0.1" => |
| 31 | ( |
| 32 | "socket" => "/home/user/rtorrent/rpc.socket", |
| 33 | "check-local" => "disable", |
| 34 | "disable-time" => 0, # don't disable scgi if connection fails |
| 35 | ) |
| 36 | ) |
| 37 | ) |
| 38 | }}} |
| 39 | |
| 40 | For nxing: |
| 41 | |
| 42 | Compile the latest nginx version with the modified mod_scgi found [http://libtorrent.rakshasa.no/downloads/mod_scgi-b466baa5fcdb.tar.gz here]. Note that you must use the linked version as it contained bug fixes and modifications to make it work properly. |
| 43 | |
| 44 | {{{ |
| 45 | location /RPC2 { |
| 46 | scgi_pass 127.0.0.1:5000; |
| 47 | include scgi_vars; |
| 48 | scgi_var SCRIPT_NAME /RPC2; |
| 49 | } |
| 50 | }}} |
| 51 | |
| 52 | If any of your downloads have non-ascii characters in the filenames, you must also set the following in rtorrent.rc to force rtorrent to use the UTF-8 encoding. The XMLRPC standard requires UTF-8 replies, and rtorrent presently has no facilities to convert between encodings so it might generate invalid replies otherwise. |
| 53 | {{{ |
| 54 | encoding_list = UTF-8 |
| 55 | }}} |
| 56 | |
| 57 | The web server will now route xmlrpc requests to rtorrent, which is listening |
| 58 | only on connections from the local machine or on the local socket file. Also make sure the /RPC2 |
| 59 | location is properly protected. |
| 60 | |
| 61 | To make it accessible from anywhere, use "scgi_port = :5000". This is |
| 62 | however not recommend as rtorrent has no access control, which means the |
| 63 | http server is responsible for handling that. Anyone who can send |
| 64 | rtorrent xmlrpc commands is likely to have the ability to execute code |
| 65 | with the privileges of the user running rtorrent. |
| 66 | |
| 67 | You may also use "scgi_local = /foo/bar" to create a local domain |
| 68 | socket, which supports file permissions. Set the rw permissions of the |
| 69 | directory the socket will reside in to only allow the necessary |
| 70 | processes. '''This is the recommended way of using XMLRPC with |
| 71 | rtorrent, though not all http servers support local domain sockets for scgi.''' |
| 72 | |
| 73 | == Usage == |
| 74 | |
| 75 | Access the XMLRPC interface using any XMLRPC-capable client. For example, |
| 76 | using the xmlrpc utility that comes with xmlrpc-c: |
| 77 | |
| 78 | {{{ |
| 79 | > # To list all the xmlrpc methods rtorrent supports. |
| 80 | > xmlrpc localhost system.listMethods |
| 81 | |
| 82 | > # Get max upload rate. |
| 83 | > xmlrpc localhost get_upload_rate |
| 84 | |
| 85 | > # Set upload rate, exact 100000 bytes. |
| 86 | > xmlrpc localhost set_upload_rate i/100000 |
| 87 | |
| 88 | > # Set upload rate, 100kb. |
| 89 | > xmlrpc localhost set_upload_rate 100k |
| 90 | |
| 91 | > # See list of downloads in "main" view |
| 92 | > xmlrpc localhost download_list |
| 93 | |
| 94 | > # See list of downloads in "started" view |
| 95 | > xmlrpc localhost download_list started |
| 96 | |
| 97 | > # Get uploaded bytes for specific download by info-hash |
| 98 | > xmlrpc localhost d.get_up_total e66e7012b8346271009110ac38f91bc0ad8ce281 |
| 99 | |
| 100 | > # Change the directory for a specific download. |
| 101 | > xmlrpc localhost d.set_directory 91A2DF0C9288BC4C5D03EC8D8C26B4CF95A4DBEF foo/bar/ |
| 102 | |
| 103 | > # Size of the first file in a specific download. |
| 104 | > xmlrpc localhost f.get_size_bytes 91A2DF0C9288BC4C5D03EC8D8C26B4CF95A4DBEF i/0 |
| 105 | }}} |
| 106 | |
| 107 | It supports both single strings akin to what the option file accepts, |
| 108 | and proper xmlrpc integer, string and lists. |
| 109 | |
| 110 | See the man page and the rtorrent/src/command_* source files for more details on what |
| 111 | parameters some of the commands take. |
| 112 | |
| 113 | === Targets === |
| 114 | |
| 115 | As we saw above, commands that requires a file or tracker can be called in several different ways. (rTorrent 0.8.1+) |
| 116 | |
| 117 | {{{ |
| 118 | > xmlrpc localhost f.get_size_bytes 91A2DF0C9288BC4C5D03EC8D8C26B4CF95A4DBEF i/3 |
| 119 | > xmlrpc localhost f.get_size_bytes 91A2DF0C9288BC4C5D03EC8D8C26B4CF95A4DBEF "3" |
| 120 | > xmlrpc localhost f.get_size_bytes 91A2DF0C9288BC4C5D03EC8D8C26B4CF95A4DBEF:f3 |
| 121 | > xmlrpc localhost p.get_url 91A2DF0C9288BC4C5D03EC8D8C26B4CF95A4DBEF:p0 |
| 122 | }}} |
| 123 | |
| 124 | The first and second example passes the index of the file as a integer and string respectively. The third example uses a more compact syntax that contains both the info hash, type and index in the same string. |