btoverlord
a program to manage bittorrent uploads/downloads from multiple users using a single rtorrent instance
Usage
--download=file.torrent: check file.torrent against a list of allowed trackers. If file.torrent's announce-list contains only allowed trackers, an accept script is run. If it does not, a reject script is run. Both scripts are passed the path to file.torrent followed by either 'none' or a list of bad trackers. The accept script is intended to move the torrent to a directory that rtorrent is watching for new torrents. The reject script can be written to remove bad trackers from the actual torrent or to simply tell the user that the specified torrent cannot be downloaded.
--status: prints the current state, amount uploaded, amount downloaded, share ratio, and percent completed for each of the current user's torrents.
--get-finished: copies the data from all of the current user's torrents to a specified (finished_directory in btoverlord.conf) directory, such as ~/torrents. Note that ~ is the $HOME of the current user, not necessarily the user running rtorrent.
--get-single=NAME: same as --get-finished, except only NAME is copied.
--purge: stop all of the user's torrents with a share ratio > 1.0. Note that this only stops and removes the actual .torrents, and marks them as inactive inside rtorrent; the rtorrent user has to remove the actual data.
-r=NAME: same as --purge, except this only removes the torrent named "NAME" (as shown by --status)
Setup (and how it works)
Copy the entire btoverlord directory to /usr/local/ and create a symbolic link:
cp -R btoverlord /usr/local/
Add:
#define PYTHON "/path/to/your/python/interpreter"
#define FULLPATH "/path/to/where/you/installed/btoverlord/main.py"
to the top of python-setuid.c
Compile python-setuid.c with "gcc python-setuid.c -o /usr/local/bin/btoverlord"
btoverlord must be setuid (and optionally, depending on your setup, setgid) to the user that runs rtorrent. This give btoverlord write access to rtorrent's directories, while preventing the user running btoverlord from having this access; tracker filtering would be pointless if everyone could write to rtorrent's torrent watch directory. btoverlord will also need write access to any torrents which are added to it. One way to accomplish this is chgrp'ing the torrents to rtorrent's group, chmod'ing them g+w, and placing them in a directory where the rtorrent group has write access (so they can be moved). Another solution is to only setuid btoverlord (use 4755 instead of 6755 below) and make sure the primary group of the user running btoverlord has write access to torrents. Change btoverlord's ownership to the user/group that runs rtorrent, and setuid/setgid the file so that it can access rtorrent's directories.
chown rtorrent_user:rtorrent_group /usr/local/bin/btoverlord
chmod 6755 /usr/local/bin/btoverlord
Copy /usr/local/btoverlord/btoverlord.conf to /etc/btoverlord/btoverlord.conf and edit it according to your setup:
mkdir /etc/btoverlord/
cp /usr/local/btoverlord/btoverlord.conf /etc/btoverlord/btoverlord.conf
nano /etc/btoverlord/btoverlord.conf
btoverlord needs read access to the config file. chmod/chown if needed.
Use btoverlord --download <torrent> to begin downloading a torrent. This adds the current user's uid to an "owner" field in the torrent and then calls torrent_accept_script (if all trackers are acceptable) or torrent_reject_script (if the torrent's announce-list contains trackers that are not explicitly allowed in btoverlord.conf).
torrent_accept_script should mv the torrent into rtorrent's torrent watchdir. Note that the directory <torrent> is in will have to be owned by rtorrent's user or group, and the user or group will have to have write access for this to work.
torrent_reject_script can be the same as accept_script if you do not wish to filter trackers. If you want to allow only certain trackers, make a torrent_reject_script that notifies the user that the torrent he has submitted contains a tracker that is not allowed, so the torrent will not be downloaded.
The rtorrent user and/or group (depending on whether the binary is setgid and the permissions on the finished_directory) must have write access to each user's finished_directory in order for --get-finished to work.
