📜 ⬆️ ⬇️

Convenient torrentokachalkal managed through the web and android for a dedicated server

Preamble


In this article, I want to tell you how to make a universal torrent-based control via the Internet from both the web interface and the Android application.
Here we will talk about setting up the rtorrent + rutorrent + nginx + php-fpm + transdroid bundle on Debian Wheezy. I will immediately answer the question why not transmission, firstly with a large number of distributions / downloads, it falls, secondly it is poorly customized and does not have plug-ins for automating the search and downloading of new products, and I personally just don’t like it.
In the case of rtorrent, the version from the repository is compiled without xmlrpc-c, so I’m going to have to rebuild it myself, the official project documentation contains only the configuration option with apache, which didn’t fit all the difficulties and their solution will be described below.
I will try as much as possible to comment on all the settings and configs, so that you can understand how the system works, and not engage in a blunt copy-paste.
I hope the owners of their own NAS and dedicated servers will be interesting.

For convenience, I bring all commands from under root, without using sudo.
There will be few pictures, mostly commands and explanations, for the fastest reproduction of the configuration.


Set up required repositories.


In /etc/apt/sources.list add:
#    . deb http://www.deb-multimedia.org stable main non-free #   php  mysql deb http://packages.dotdeb.org wheezy all deb-src http://packages.dotdeb.org wheezy all #  nginx deb http://nginx.org/packages/debian/ wheezy nginx deb-src http://nginx.org/packages/debian/ wheezy nginx 

Install the keys
 apt-get update && apt-get install deb-multimedia-keyring wget http://www.dotdeb.org/dotdeb.gpg -O- |apt-key add - gpg --keyserver hkp://keys.gnupg.net --recv-keys ABF5BD827BD9BF62 gpg -a --export 7BD9BF62 | apt-key add - 

We knock out.
 apt-get update && apt-get upgrade 

We put the necessary packages (I hope I did not forget anything)
 apt-get install build-essential autoconf automake libtool libncurses5-dev libncursesw5-dev libcurl4-openssl-dev screen openssl php5 php5-cli curl libcppunit-dev libsigc++-2.0-dev subversion php5-cgi nginx php5-common php5-fpm php5-gd php-pear checkinstall git 

If the system previously stood rtorrent from the repository, delete it
 apt-get purge rtorrent libtorrent* 

Build the right packages


When assembling all three packages, there may be an error with the version number, I prefer to set the build date, also during the assembly I can swear for the absence of directories, just create them and run them again.
Building and Installing xmlrpc-c

Create a directory where the sources will be
 mkdir ~/svn 

Go into it
 cd ~/svn 

We get fresh weights
 svn co https://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/advanced/ xmlrpc-c 

Go to the resulting directory
 cd xmlrpc-c 

We collect:
 ./configure --disable-cplusplus make checkinstall -D 

Build libtorrent (the points are the same in short)

 cd ~/svn git clone https://github.com/rakshasa/libtorrent cd libtorrent ./autogen.sh ./configure make checkinstall -D 

Build rtorrent

 cd ~/svn git clone https://github.com/rakshasa/rtorrent cd rtorrent ./autogen.sh ./configure --with-xmlrpc-c make checkinstall -D 

We connect the necessary ones, without this, rtorrent will not start in the future.
 echo "include /usr/local/lib" | tee -a /etc/ld.so.conf ldconfig 

We try to run rtorrent , if everything is OK, it will start, but it will complain about the absence of the configuration file, you can exit by Ctrl + Q

Create a user (in my example, this is a p2p user), the home directory of which will be our folder with torrents, make a group for it www-data
 adduser --home /hdd --shell /bin/bash --ingroup www-data p2p 

move into it
 su p2p 

Create a config for rtorrent
 nano ~/.rtorrent.rc 

with this content:
# Necessary for interrelation with rutorrent and transdroid
scgi_port = 127.0.0.1 zhe000
')
#IP of our server, on which rtorrent will work, if there are several such
bind = 192.168.0.2
ip = 192.168.0.2

# minimum number of peers per torrent
min_peers = 1
# maximum number of peers per torrent
max_peers = 100
# maximum download speed. 0 - unlimited
download_rate = 0
# maximum speed of return. 0 - unlimited
upload_rate = 10,000
# Sets the number of hands from the torrent
max_uploads = 50
# catalog for saving downloads or where torrents will be from.
directory = / hdd / torrent / download /
# Where we will store the session
session = /hdd/torrent/.session/
# If there is little free space, stop all downloads. Stop threshold set close_low_diskspace =
schedule = low_diskspace, 5.60, close_low_diskspace = 30000M
# display detailed error content
# the interval between the start of rTorrent and the first start of ruTorrent after that, no useful work is done
# will not be. To avoid this, add a specially trained line to the rTorrent configuration file:
# Path to php and path to initplugins.php contained in the rutorrent scripts
execute = {sh, -c, / usr / bin / php /var/www/rutorrent/php/initplugins.php &}
# Set the port (or several ports) that opens the client for data exchange
# (do not forget to allow firewall)
port_range = 40500-40999
# Each time use a random port from the range.
port_random = yes
# check torrent hash after upload
check_hash = yes
# save session
session_save = yes
# accept encrypted incoming connections, set unencrypted
# outgoing connections, if it returns an error, repeat with encryption,
# prefer cleartext after establishing an encrypted connection
encryption = allow_incoming, enable_retry, prefer_plaintext
# use udp
use_udp_trackers = yes
# Allows DHT to work for torrent-free torrents or for cases
# when all retresers are (do not work).
# May be “disable” (to completely disable DHT),
# "Off" (does not start with DHT), "auto" (Enables DHT if possible),
# or "on" (force DHT). The default DHT value is “off”.
# For the DHT to work properly, the session directory “session” must be defined.
#
dht = auto
#
# UDP port used by DHT.
#
dht_port = 6881
# Forces UTF-8 encoding for xmlrpc.
# Recommended for troubleshooting when using
# in the names of the Cyrillic characters torrents.
# Actual for GUI working via xmlrpc.
encoding_list = utf8

Again, we try to start rtorrent , if any parameter in the config is not correct, we get an error with the line number, fix it, try again, if everything is fine, create an autorun script, return to root, exit command in the terminal, return us from the p2p session in root session.
 wget http://libtorrent.rakshasa.no/raw-attachment/wiki/RTorrentCommonTasks/rtorrentInit.sh mv rtorrentInit.sh /etc/init.d/rtorrent chmod +x /etc/init.d/rtorrent 

go to the autorun script
 nano /etc/init.d/rtorrent 

Change the line user = "p2p" to our user.

We try to run
 /etc/init.d/rtorrent start 

We check that everything started
 ps aux | grep rtorrent 

Should see similar lines
p2p 10443 0.0 0.0 23388 1516? Ss 13:17 0:00 SCREEN -dm -S rtorrent
p2p 10449 0.0 0.3 110904 7120 pts / 2 Ssl + 13:17 0:00 rtorrent


With rtorrent finished, now let's move on to setting the frontends.



Nginx configuration


For simplicity, I will post the contents of my configs, with comments where necessary.
 nano /etc/nginx/nginx.conf 

Lead to mind
# User with the rights of which nginx works
user www-data;
# It is recommended to install by the number of cores
worker_processes 2;
pid /var/run/nginx.pid;
worker_rlimit_nofile 8192;
events {
# Maximum number of server connections per worker process
worker_connections 1024;
# Efficient connection handling method used in Linux 2.6+
use epoll;
}
http {
##
# Basic settings
# We organize cache for the FastCGI server, I use the section in ram
fastcgi_cache_path / tmp / fcgi-cache / levels = 1: 2 keys_zone = one: 10m;
# Use sendfile, but be careful if you need to give large files,
# that sendfile happens to harm
sendfile on;
# Limit the size of the segment sent for one
# blocked recoil
sendfile_max_chunk 128k;
# Recoil buffer which is used for processed data
postpone_output 1460;
# Size hash for domain names.
server_names_hash_bucket_size 64;
# Size of data received by post request
client_max_body_size 15m;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# If errors do not tell the enemy version of nginx
server_tokens off;
include /etc/nginx/mime.types;
default_type application / octet-stream;

# This is an important point, remember we set the line scgi_port at the beginning of the config .rtorrent.rc
# so here in the server row enter the same parameters. Required for running / RPC
upstream backendrtorrent {
server 127.0.0.113000;
}

##
# Setting logs
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##

Compression Settings
gzip on;
gzip_disable "msie6";
ssi on;
##

# Setting up virtual domains
include /etc/nginx/conf.d/*.conf;
include / etc / nginx / sites-enabled / *;
}

 nano /etc/nginx/sites-enabled/000-default 

Lead to mind
server {
# Folder where rutorrent will be located
root / var / www / rutorrent;
# Setting logs, each virtual domain has its own log
#access_log /var/log/nginx/default-access.log;
access_log off;
error_log /var/log/nginx/default-error.log;

# Replacing .htaccess block access to some subdirectories of the engine
location / conf / {
deny all;
}
location / share / {
deny all;
}
# And here is / RPC2, through which our front-ends will manage rtorrent
# Authorization is required, otherwise anyone will manage your rocking chair.
location / RPC2 {
auth_basic "Private ZONE.";
auth_basic_user_file /var/www/rutorrent/.htpasswd;
include / etc / nginx / scgi_params;
scgi_pass backendrtorrent;
}

# We connect all templates for testing, on real hosts we will use only the necessary ones.
include / etc / nginx / templates / default;
include / etc / nginx / templates / php;
}

 nano /etc/nginx/templates/default 

Lead to mind
# Typical settings common to all domains (if you do not want exotic)
##
index index.html index.php;

location / {
# Basic HTTP authentication password protected access to our rutorrent
auth_basic "Private ZONE.";
# auth_basic on;
auth_basic_user_file /var/www/rutorrent/.htpasswd;
}

# We close access to the .htaccess and .htpassword files and do not log unnecessary.
location = /favicon.ico {access_log off; log_not_found off; }
location = / robots.txt {allow all; access_log off; log_not_found off; }
location = /apple-touch-icon.png {access_log off; log_not_found off; }
location = /apple-touch-icon-precomposed.png {access_log off; log_not_found off; }
location ~ / \. {deny all; access_log off; log_not_found off; }

# Complicating the life of script kiddies and block popular scanners by UA
if ($ http_user_agent ~ * (nmap | nikto | wikto | sf | sqlmap | bsqlbf | w3af | acunetix | havij | appscan)) {
return 403;
}

 nano /etc/nginx/templates/php 

Lead to mind
# Passing PHP script processing PHP-FPM
location ~ \ .php $ {
try_files $ uri = 404;
# PHP-FPM listens on a Unix socket, this setting must match
# listen = /tmp/wwwpool.sock in the /etc/php5/fpm/pool.d/www.conf file
fastcgi_pass unix: /tmp/wwwpool.sock;
fastcgi_buffers 8 256k;
fastcgi_buffer_size 128k;
fastcgi_intercept_errors on;
# Use cache zone one
fastcgi_cache one;
# Put the page in the cache, after 3 uses. A smaller number caused me difficult to explain glitches
# on registration forms
fastcgi_cache_min_uses 3;
# Cache the listed answers
fastcgi_cache_valid 200 301 302 304 5m;
# Cache Key Format - using this key, nginx finds the correct page.
fastcgi_cache_key "$ request_method | $ host | $ request_uri";
# If you do not use this option, then in the forums everyone will sit under the name of the first logged in forum
fastcgi_hide_header "Set-Cookie";
# This request will force nginx to cache everything that passes through it.
fastcgi_ignore_headers "Cache-Control" "Expires";
fastcgi_index index.php;
# fastcgi_intercept_errors on; # only for the testing period
# Enable parameters from / etc / nginx / fastcgi_param
include fastcgi_params;
# Path to the script that will be passed to php-fpm
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
fastcgi_ignore_client_abort off;
}

Caching settings can be disabled or use other parameters at my discretion, I took typical ones.
It is also desirable to set the timezone in the php settings, for this in the files /etc/php5/fpm/php.ini and /etc/php5/cli/php.ini
let's set a variable with our zone, in my case it is Kiev time.
 date.timezone = "Europe/Kiev" 

Now let's do the rutorrent engine

 cd /var/www/ wget https://rutorrent.googlecode.com/files/rutorrent-3.5.tar.gz tar -xzf rutorrent-3.5.tar.gz rm rutorrent-3.5.tar.gz cd rutorrent 

You can download plugins one by one from the site
I prefer to download everything at once, and then delete the unnecessary (description of plug-ins is here )
 rmdir plugins wget https://rutorrent.googlecode.com/files/plugins-3.5.tar.gz tar -xzf plugins-3.5.tar.gz rm plugins-3.5.tar.gz 

A little tweak engine config:
In file
 nano conf/config.php 

change the variable to the root of files with torrents.
 $topDirectory = '/hdd/torrent/'; 

We will generate a username and password to access the engine, you can use htpasswd from the delivery of apache,
but we don’t have it, therefore we will generate the improvised means:
 echo -e "your-username:`perl -le 'print crypt("your-password","salt")'`" > /var/www/rutorrent/.htpasswd 

In the username, do not forget to leave a colon at the end.

We change the owner of the directory to our
 chown -R p2p:www-data /var/www/rutorrent 

Restart nginx and php
 service nginx restart service php5-fpm restart 

In the browser, we type our server’s ip, enter the login and password generated earlier, and get into the control panel of our rocking chair.



We finished with the web snout, tweaking and a description of the features are on the official website, I will not repeat, let's move on to a convenient management with android.


Download to phone and / or tablet
http://transdroid.org/latest
http://transdroid.org/latest-search
install and run.

Choose "Add a new server"
Name: Any to choose
Server Type: rTorrent
IP address or domain name: your server ip or domain
Port: 80
Use authorization: put a tick
We indicate our name and password in the corresponding fields.
Folder: no changes
In the advanced settings checkbox to your taste
Operating system: Linux
Ftp address: p2p : password @ ip_server / torrent / download / (indicate access to the ftp folder, about ftp settings below.)
Since we did not use ssl, the rest is unchanged.

After that, you can go to your server and see the current downloads, the rest of the program settings to your taste.



We put the FTP server, very briefly:


 apt-get install proftpd 

In the standard /etc/proftpd/proftpd.conf config we change:
 ServerName "My torrent server"  DefaultRoot ~ #        RootLogin off #     root #      IP  (    ) UseReverseDNS off PassivePorts 40000 40499 #     rtorrent 

More fine-tuning can be viewed in the set of articles on this topic; within this article, such a minimum is enough
 service proftpd restart 



We put a samba


Needed for easy local access, also very briefly.
 apt-get install samba 

We give the config /etc/samba/smb.conf to the form:
Minimum config
; Global server settings
[global]
; General server settings
; The name of the company, as will be seen in the network environment
netbios name = torrent-box
server string =
; Customer work group
workgroup = WORKGROUP
announce version = 5.0
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_KEEPALIVE SO_RCVBUF = 8192 SO_SNDBUF = 8192
passdb backend = tdbsam
security = user
null passwords = true
; File for username alias
username map = / etc / samba / smbusers
name resolve order = hosts wins bcast
wins support = yes
; Logs
log file = /var/log/samba/log.%m
syslog = 0
syslog only = no
; Configure binding to interfaces on which to listen, if not specified listens on all interfaces
interfaces = eth0
; bind interfaces only = true
; Hard disk drive
; Name balls, visible from customers
[torrent]
; Path to the shared disk
path = / hdd /
; Can I view
browseable = yes
read only = no
guest ok = no
create mask = 0644
directory mask = 0755

We generate the password for our user
 smbpasswd -a p2p 

Enable user
 smbpasswd -e p2p 

And so, as a result, we got a working torrent server, with rich management capabilities, access to downloaded files via smb and ftp, from additional amenities I can advise you to use a number of plug-ins for rutorrent, allowing you to automate the downloading of new products. From connected projects, I would like to cancel torrentmonitor from habraiser KorP .
Thank you all for your attention.

Source: https://habr.com/ru/post/183626/


All Articles